Next.js MCP Server
Enables MCP-compatible clients to inspect Next.js codebases, analyze App Router and Pages Router structure, discover API routes, and audit build performance through controlled tools.
README
Next.js MCP Server
A production-ready Next.js MCP Server template for the Model Context Protocol.
This template lets Claude Desktop, Cursor, Windsurf, and other MCP-compatible clients inspect a Next.js codebase, analyze App Router and Pages Router structure, discover API routes, and audit build performance through controlled MCP tools.
Built as a starter template for developers and teams that want a secure baseline before adding custom AI-powered development workflows to a Next.js application.
The template follows production engineering practices and can be used as a starting point for enterprise Next.js AI integrations using the Model Context Protocol.
Who this is for
This repository is useful for:
- Next.js developers building AI-assisted development workflows,
- teams that want Claude or Cursor to inspect Next.js projects safely,
- platform engineers building internal MCP tooling,
- agencies creating reusable MCP server templates for client projects,
- developers learning how to host an MCP server inside the Next.js App Router.
Features
- Next.js App Router MCP server
- TypeScript-first implementation
- HTTP MCP endpoint at
/api/mcp - Public health endpoint at
/api/health - API key authentication with
x-api-keyandAuthorization: Bearer - In-memory rate limiting for MCP requests
- Structured Pino logging
- Zod-based environment validation
- MCP tools for Next.js project analysis, API route inspection, and performance audits
- Jest test suite
- GitHub Actions CI workflow
- Docker support
- Claude Desktop and Cursor configuration examples
Architecture
Claude Desktop / Cursor / Windsurf
│
│ HTTP POST /api/mcp
│ x-api-key or Authorization: Bearer <MCP_API_KEY>
▼
Next.js App Router
│
├── app/api/mcp/route.ts
│ ├── API key validation
│ ├── rate limiting
│ └── MCP transport
│
├── app/api/health/route.ts
│ └── health report
│
▼
MCP Server
│
├── analyze_nextjs_project
├── inspect_api_routes
└── audit_performance_budget
│
▼
Local Next.js project filesystem
See the larger diagram in docs/architecture.md.
Source Code
The complete production-ready Next.js MCP Server template is available on GitHub.
Repository:
https://github.com/kamolc4/nextjs-mcp-server
The repository includes:
- Complete TypeScript source code
- Next.js App Router MCP endpoint
- Health checks
- Authentication middleware
- Rate limiting
- MCP tools
- GitHub Actions CI
- Jest test suite
- MIT License
- Claude Desktop and Cursor configuration
- Production deployment examples
Fork the repository or download it as a ZIP to start building immediately.
Available MCP tools
| Tool | Purpose |
|---|---|
analyze_nextjs_project |
Analyze a Next.js project and return router type, Next.js version, dependencies, scripts, and project metadata. |
inspect_api_routes |
Scan App Router and Pages Router routes, including API routes and dynamic segments. |
audit_performance_budget |
Read .next/build-manifest.json after a build and identify heavy pages that exceed a JavaScript budget. |
Quick start
1. Clone and install
# Clone repository
git clone https://github.com/kamolc4/nextjs-mcp-server.git
cd nextjs-mcp-server
# Install dependencies
npm ci
2. Configure environment
cp .env.example .env.local
Edit .env.local:
MCP_API_KEY=replace-with-a-long-random-secret
MCP_SERVER_NAME=nextjs-mcp-server
MCP_SERVER_VERSION=1.0.0
NODE_ENV=development
LOG_LEVEL=info
NEXTJS_PROJECT_PATH=/absolute/path/to/your/nextjs/project
ALLOWED_ORIGINS=*
RATE_LIMIT_RPM=60
Generate a strong API key:
openssl rand -hex 32
3. Run locally
npm run dev
The Next.js app starts at:
http://localhost:3000
4. Check health
curl http://localhost:3000/api/health
5. List MCP tools
curl -X POST http://localhost:3000/api/mcp \
-H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
-H 'x-api-key: replace-with-your-mcp-api-key' \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}'
Connect to Claude Desktop
Build and start the server:
npm run build
npm start
Then add an MCP server entry in your Claude Desktop configuration:
{
"mcpServers": {
"nextjs": {
"url": "http://localhost:3000/api/mcp",
"headers": {
"Authorization": "Bearer replace-with-your-mcp-api-key"
}
}
}
}
Restart Claude Desktop after editing the configuration.
Connect to Cursor
In Cursor, add a new MCP server using the HTTP endpoint:
{
"name": "nextjs",
"url": "http://localhost:3000/api/mcp",
"headers": {
"Authorization": "Bearer replace-with-your-mcp-api-key"
}
}
Then restart Cursor or reload the MCP server list.
Configuration
| Variable | Description | Required |
|---|---|---|
MCP_API_KEY |
Shared secret required for /api/mcp. Minimum 16 characters. |
Required |
MCP_SERVER_NAME |
MCP server name exposed to clients. | Optional |
MCP_SERVER_VERSION |
MCP server version exposed to clients. | Optional |
NODE_ENV |
Runtime environment: development, production, or test. |
Optional |
LOG_LEVEL |
Pino log level: debug, info, warn, or error. |
Optional |
NEXTJS_PROJECT_PATH |
Project root that MCP tools inspect. Defaults to current working directory. | Optional |
ALLOWED_ORIGINS |
Reserved for production CORS hardening. | Optional |
RATE_LIMIT_RPM |
Maximum MCP requests per minute per client. | Optional |
Security notes
This template is safer than a minimal demo, but you should harden it before production use.
Recommended production changes:
- Store
MCP_API_KEYin a managed secret manager. - Rotate
MCP_API_KEYregularly. - Restrict
NEXTJS_PROJECT_PATHto the project directory you intend to expose. - Avoid exposing secrets,
.envfiles, deployment credentials, or private project directories through custom tools. - Add per-user or per-workspace authorization if multiple users will access the server.
- Add audit logs for every tool call.
- Use HTTPS in production.
- Tune rate limits for your expected load.
- Review every new tool before allowing write access to project files.
Security Review
Verify this server with MCPForge:
https://www.mcpforge.tech/verify
MCPForge can help review:
- exposed tools,
- authentication behavior,
- health checks,
- compatibility with MCP clients,
- risk level of filesystem access,
- security posture before publishing or deployment.
After verification, you can link your public report from this README:
[](https://www.mcpforge.tech/verified/nextjs-mcp-server)
Read the complete guide on MCPForge:
https://www.mcpforge.tech/blog/next-js-mcp-server
Starter template on MCPForge Code Hub:
https://www.mcpforge.tech/code/next-js-mcp-server-template
Deployment
A common production setup:
- Deploy this service to Vercel, Railway, Render, Fly.io, AWS, GCP, Azure, or a private Kubernetes cluster.
- Configure environment variables in the hosting provider.
- Set
MCP_API_KEYto a long random value. - Set
NEXTJS_PROJECT_PATHto the project path that tools should inspect. - Verify
/api/healthbefore connecting MCP clients. - Verify
/api/mcpwith a valid API key. - Run a public or private verification with MCPForge.
Docker
docker compose up --build
Production build
npm run build
npm start
Local development commands
npm run lint
npm run typecheck
npm test
npm run build
API endpoints
| Method | Path | Description |
|---|---|---|
GET |
/api/health |
Public health check endpoint. |
POST |
/api/mcp |
MCP endpoint protected by API key authentication. |
GET |
/api/mcp |
MCP endpoint for compatible HTTP transports. |
Testing
npm test
npm run test:watch
npm run test:coverage
The test suite covers:
/api/healthresponse shape,- missing API key on
/api/mcp, - invalid API key on
/api/mcp, - valid
x-api-keyauthentication, - valid
Authorization: Bearerauthentication, - MCP
tools/list, - config validation defaults,
- rate limit behavior.
Releases
Latest stable release:
v1.0.0
See the Releases page for the full changelog.
Contributing
Contributions are welcome.
If you want to improve this Next.js MCP Server template, open an issue or submit a pull request.
Related MCP Server Templates
Looking for other production-ready MCP Server templates?
- GitHub MCP Server
- Slack MCP Server
- Stripe MCP Server
- Notion MCP Server
- Shopify MCP Server
- HubSpot MCP Server
- PostgreSQL MCP Server
- Linear MCP Server
Browse the complete collection:
https://www.mcpforge.tech/code
License
MIT — see LICENSE.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
Neon Database
MCP server for interacting with Neon Management API and databases
E2B
Using MCP to run code via e2b.
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.