Back to MCP directory
publicPublicdnsLocal runtime

Next.js API Scanner

Next.js MCP Server是一个用于分析和提取Next.js应用API路由信息的工具。

article

README

🚀 Next.js MCP 服务器

Next.js MCP 服务器是一款用于 Next.js 应用的工具,它能扫描应用目录结构,提取 API 路由的详细信息,为开发者提供便利。

🚀 快速开始

本工具可以帮助你分析 Next.js 应用中的 API 路由信息,以下将为你介绍其特性、安装、使用方法等内容。

✨ 主要特性

  • get-routers-info:路由分析器会扫描你的 Next.js 应用目录结构,并提取所有 API 路由的信息,包括:
    • API 路径
    • HTTP 方法(GET、POST、PUT、DELETE 等)
    • 请求参数
    • 状态码
    • 请求和响应模式

📦 安装指南

你可以选择使用 npm 或 pnpm 进行安装:

npm install next-mcp-server

或者如果你使用 pnpm:

pnpm add next-mcp-server

💻 使用示例

命令行

你可以直接运行 mcp 服务器:

npm run build
node dist/index.js

Docker

docker build -t mcp/next -f Dockerfile .
docker run mcp/next -d

Cursor 使用

对于 cursor 的使用,可以在 ~/.cursor[projectDir]/.cursor 下定义一个 mcp.json 文件:

{
  "mcpServers": {
    "next.js": {
      "url": "http://localhost:4857/sse"
    }
  }
}

这里的 url 可能会根据你的项目中的 .env 设置而有所不同。

输出示例

该工具生成了每个路由的详细信息:

[
  {
    "filePath": "/path/to/your/app/api/test/route.ts",
    "implementationPath": "/path/to/your/app/api/test/route.ts",
    "apiPath": "/api/test",
    "handlers": [
      {
        "method": "GET",
        "path": "/api/test",
        "functionSignature": "export async function GET(request: Request)",
        "description": "获取测试数据",
        "parameters": [],
        "statusCodes": [200]
      },
      {
        "method": "POST",
        "path": "/api/test",
        "functionSignature": "export async function POST(request: Request)",
        "description": "创建测试数据",
        "parameters": [],
        "requestBodySchema": "{ name: string }",
        "statusCodes": [201, 400]
      }
    ]
  }
]

📚 详细文档

开发相关

运行测试

npm run test

在本地运行 mcp 服务器

npm run build
node dist/index.js 

从 node_modules 运行(在 npm i 后)

node node_modules/next-mcp-server/dist/index.js

运行 playground

pnpm --filter playground dev

工作原理

该工具的工作流程如下:

  1. 扫描你的 Next.js 应用目录结构以查找路由文件
  2. 分析每个路由文件以提取 HTTP 方法、路径、参数等信息
  3. 从注释中提取文档信息
  4. 返回所有 API 路由的结构化表示

限制

  1. 由于通过路径访问文件系统的性质,如果 hosted 在网络上将无法工作
  2. 只支持 Next.js App 路由项目

📄 许可证

本项目采用 MIT 许可证。

help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client