在 Next.js App Router 中实现 MCP 服务器,HTTP MCP 端点位于 /api/mcp,公开健康检查端点位于 /api/health
nextjs-mcp-server — Next.js 启动器模板
作者 kamolc4
一个基于 Next.js App Router 的 MCP 服务器模板,通过受 API Key 保护的 HTTP 端点,让 Claude Desktop、Cursor 等 MCP 客户端调用工具分析 Next.js 项目的路由结构、API 路由与构建性能。
看看你的网站会是什么样
浏览真实页面截图,比较内容排版与手机效果。点击下方缩略图切换,放大查看整页细节。
全部页面与视图 3
截图用于了解视觉与布局,交互效果请以实际项目为准。
值得关注的模板亮点
从已有项目资料中,快速了解它的特点。
提供三个 MCP 工具:analyze_nextjs_project、inspect_api_routes、audit_performance_budget
使用 x-api-key 或 Authorization: Bearer 进行 API Key 认证,并对 MCP 请求做内存限流
包含 Pino 结构化日志、Zod 环境变量校验、Jest 测试套件与 GitHub Actions CI 工作流
提供 Claude Desktop 与 Cursor 的 MCP 服务器配置示例,以及 Docker 支持
模板详细介绍
该模板在 Next.js App Router 中实现了一个 Model Context Protocol(MCP)服务器,对外暴露 HTTP 端点 /api/mcp,并附带公开的健康检查端点 /api/health。它面向希望让 Claude Desktop、Cursor、Windsurf 等 MCP 兼容客户端安全查看 Next.js 代码库的开发者,提供三个 MCP 工具:analyze_nextjs_project 返回项目使用的路由类型、Next.js 版本、依赖、脚本与项目元数据;inspect_api_routes 扫描 App Router 与 Pages Router 的路由,包括 API 路由与动态段;audit_performance_budget 在构建后读取 .next/build-manifest.json,找出超过 JavaScript 预算的页面。
在安全与工程实践方面,README 说明模板包含基于 x-api-key 与 Authorization: Bearer 的 API Key 认证、针对 MCP 请求的内存限流、Pino 结构化日志、基于 Zod 的环境变量校验、Jest 测试套件、GitHub Actions CI 工作流以及 Docker 支持,并提供 Claude Desktop 与 Cursor 的配置示例。
README 同时明确指出,该模板虽然比最小演示更安全,但在生产使用前仍需加固,并列出建议措施,例如将 MCP_API_KEY 存入托管密钥管理服务、定期轮换密钥、限制 NEXTJS_PROJECT_PATH 的暴露范围、避免通过自定义工具暴露密钥或私有目录、为多用户场景增加按用户或工作区的授权、为每次工具调用增加审计日志、在生产环境使用 HTTPS、调整限流阈值,以及在允许写入项目文件前审查每个新工具。README 未提供关于性能基准、并发上限或具体框架版本号的说明。
适合你的项目吗?
适用场景
- 让 Claude Desktop 或 Cursor 通过 MCP 工具查看某个 Next.js 项目使用的路由类型、版本、依赖与脚本
- 扫描 Next.js 项目的 App Router 与 Pages Router 路由,包括 API 路由和动态段
- 在构建后读取 .next/build-manifest.json,找出超过 JavaScript 预算的页面
- 作为团队或机构在 Next.js 应用中添加自定义 AI 辅助开发工作流前的安全基线模板
适合人群
- 构建 AI 辅助开发工作流的 Next.js 开发者
- 希望让 Claude 或 Cursor 安全查看 Next.js 项目的团队
- 构建内部 MCP 工具的平台工程师
- 为客户项目制作可复用 MCP 服务器模板的机构
- 想学习如何在 Next.js App Router 中托管 MCP 服务器的开发者
上手与定制指南
结合仓库当前版本的说明,按下面的资料检查内容、配置与运行要求。
- 1
克隆仓库后使用 npm ci 安装依赖,并将 .env.example 复制为 .env.local 进行配置
- 2
必须设置 MCP_API_KEY(至少 16 个字符),可用 openssl rand -hex 32 生成;NEXTJS_PROJECT_PATH 指定工具要检查的项目根目录,默认当前工作目录
- 3
本地运行使用 npm run dev,应用监听 http://localhost:3000;可通过 curl 访问 /api/health 检查健康状态
- 4
连接 Claude Desktop 或 Cursor 前先执行 npm run build 与 npm start,并在客户端配置中填写 /api/mcp 地址与 Bearer 令牌
- 5
README 建议生产部署前加固:将密钥存入托管密钥管理服务、定期轮换、限制 NEXTJS_PROJECT_PATH、增加按用户授权与审计日志、使用 HTTPS 并调整限流
授权与来源资料
使用条件与限制
免费使用 · 保留许可声明本次收录的是公开仓库中采用 MIT 许可的免费版本;免费范围为该版本代码,不代表外部服务或第三方素材免费。
使用时需要遵守
- 允许免费使用、修改、商用和分发该版本代码。
- 分发代码副本或实质性部分时,保留原作者版权声明和完整 MIT 许可声明。
- 代码按现状提供;担保与责任限制以原许可证及适用法律为准。
额外费用与待核对事项
- 演示图片、字体、图标及其他第三方素材需按各自许可核对,不能仅凭代码的 MIT 许可判断。
- 域名、托管、数据库、支付或 AI 等外部服务可能另外收费。
- 必须设置 MCP_API_KEY(至少 16 个字符)才能访问 /api/mcp 端点,否则无法使用 MCP 功能。
- NEXTJS_PROJECT_PATH 用于指定 MCP 工具检查的项目根目录,默认使用当前工作目录,需按需配置。
- 模板虽比最小演示更安全,但生产使用前仍需自行加固,README 明确不建议直接用于生产。
- 生产环境建议将 MCP_API_KEY 存入托管密钥管理服务,而非明文环境变量。
- 建议限制 NEXTJS_PROJECT_PATH 仅暴露预期项目目录,避免工具访问敏感路径。
- 多用户访问场景需自行添加按用户或按工作区的授权机制。
- 生产环境需自行配置 HTTPS,模板本身不提供。
- README 推荐使用第三方服务 MCPForge 进行安全验证,涉及外部服务。
- 部署需自行选择并配置 Vercel、Railway、Render、Fly.io、AWS、GCP、Azure 或 Kubernetes 等托管环境。
查看原文依据
Permission is hereby granted, free of charge
许可证原文
| `MCP_API_KEY` | Shared secret required for `/api/mcp`. Minimum 16 characters. | Required |
README 原文
| `NEXTJS_PROJECT_PATH` | Project root that MCP tools inspect. Defaults to current working directory. | Optional |
README 原文
This template is safer than a minimal demo, but you should harden it before production use.
README 原文
- Store `MCP_API_KEY` in a managed secret manager.
README 原文
- Restrict `NEXTJS_PROJECT_PATH` to the project directory you intend to expose.
README 原文
- Add per-user or per-workspace authorization if multiple users will access the server.
README 原文
- Use HTTPS in production.
README 原文
Verify this server with MCPForge:
README 原文
https://github.com/kamolc4/nextjs-mcp-server/blob/main/LICENSEhttps://github.com/kamolc4/nextjs-mcp-server/blob/main/README.md1. Deploy this service to Vercel, Railway, Render, Fly.io, AWS, GCP, Azure, or a private Kubernetes cluster.
README 原文
DeepSeek 根据仓库许可证和 README 整理 ·2026-10-14。结果仅覆盖已读取资料,依赖、图片、字体及后续条款变更以各自原文为准。
项目核对记录与介绍依据
模板资料
- 来源平台
- GitHub
- 资料与维护参考分
- 资料较完整 · 80 / 100
- 技术栈
- Next.js · React
- 网站类型
- 启动器
这个分数如何计算
本站按许可资料(最高30分)、演示链接(12分)、预览图(10分)、Star数(15分)、记录的维护时间(15分)、描述完整度(8分)、功能记录(5分)和分类资料(5分)计算。它不是代码、安全或性能测试,也不是 Google 评分;有链接不代表已实测可用。
这个项目需要核对什么
- 记录的仓库更新时间
- 2026-07-05
- 截图检查日期
- 2026-10-14
已收录演示链接。请用你的内容与屏幕尺寸检查;有演示不代表表单、认证或支付已经可用。
目录记录的主要技术栈是 Next.js。请通过依赖清单和锁文件核对实际版本与托管要求。这些说明基于收录资料,不代表代码审计或部署实测。
查看具体选型方法 →介绍的制作与核对状态
介绍由 AI 辅助整理目录与仓库资料。仓库作者不等于这篇介绍的审核者。
审核声明: codex-user-requested-batch-review-20261015 · 2026-10-15
查看当时使用的来源资料
SHA-256: 74a9aacf09334d6b31d8b91b9c48c9e9bcb13fb5f2f83b67f7163c9a6bceb3ff
2026-10-14T22:24:09.923Z
来源文件 / 仓库# Next.js MCP Server
[](https://github.com/kamolc4/nextjs-mcp-server/actions/workflows/ci.yml)
[](https://www.mcpforge.tech/verified/nextjs-mcp-server)
[](LICENSE)
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-key` and `Authorization: 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
```text
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](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
```bash
# Clone repository
git clone https://github.com/kamolc4/nextjs-mcp-server.git
cd nextjs-mcp-server
# Install dependencies
npm ci
```
### 2. Configure environment
```bash
cp .env.example .env.local
```
Edit `.env.local`:
```bash
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:
```bash
openssl rand -hex 32
```
### 3. Run locally
```bash
npm run dev
```
The Next.js app starts at:
```text
http://localhost:3000
```
### 4. Check health
```bash
curl http://localhost:3000/api/health
```
### 5. List MCP tools
```bash
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:
```bash
npm run build
npm start
```
Then add an MCP server entry in your Claude Desktop configuration:
```json
{
"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:
```json
{
"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_KEY` in a managed secret manager.
- Rotate `MCP_API_KEY` regularly.
- Restrict `NEXTJS_PROJECT_PATH` to the project directory you intend to expose.
- Avoid exposing secrets, `.env` files, 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:
```md
[](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:
1. Deploy this service to Vercel, Railway, Render, Fly.io, AWS, GCP, Azure, or a private Kubernetes cluster.
2. Configure environment variables in the hosting provider.
3. Set `MCP_API_KEY` to a long random value.
4. Set `NEXTJS_PROJECT_PATH` to the project path that tools should inspect.
5. Verify `/api/health` before connecting MCP clients.
6. Verify `/api/mcp` with a valid API key.
7. Run a public or private verification with MCPForge.
### Docker
```bash
docker compose up --build
```
### Production build
```bash
npm run build
npm start
```
## Local development commands
```bash
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
```bash
npm test
npm run test:watch
npm run test:coverage
```
The test suite covers:
- `/api/health` response shape,
- missing API key on `/api/mcp`,
- invalid API key on `/api/mcp`,
- valid `x-api-key` authentication,
- valid `Authorization: Bearer` authentication,
- 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](LICENSE).
看看同类模板
对比同技术栈与用途的模板,找到更适合的视觉与内容结构。

ai-website-cloner-template
Clone any website with one command using AI coding agents
Next.js · 启动器

Next.js SaaS Starter
Next.js SaaS Starter 是 Next.js 官方维护的 SaaS 起点模板,定位介于学习资源和可直接部署的脚手架之间。
Next.js · SaaS

Next.js Commerce
Next.js Commerce 是 Vercel 团队维护的电商启动模板,基于 Next.js App Router 构建,采用服务端渲染、React Server Components、Server Actions …
Next.js · 电商

Next-js-Boilerplate
Next-js-Boilerplate 是一个面向 Next.js 16、Tailwind CSS 4 和 TypeScript 的启动器,核心定位是开发者体验优先。
Next.js · 启动器

tailwind-nextjs-starter-blog
tailwind-nextjs-starter-blog 是一个面向个人技术博客的 Next.js 与 Tailwind CSS 启动模板,其 v2 版本基于 App Router 与 React Server Comp…
Next.js · 博客

next-forge
Production-grade Turborepo template for Next.js apps.
Next.js · 启动器
