
get-routers-info
路由分析器扫描你的 Next.js 应用目录结构,并提取所有 API 路由的信息,包括:
npm install next-mcp-server
或者如果你使用的是 pnpm:
pnpm add next-mcp-server
你可以直接运行 mcp 服务器:
npm run build
node dist/index.js
docker build -t mcp/next -f Dockerfile .
docker run mcp/next -d
对于光标使用,定义一个 mcp.json 在 ~/.cursor 或 [项目目录]/.cursor
{
"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": [2_01, 400]
}
]
}
]
要运行测试:
npm run test
要在本地运行 mcp 服务器:
npm run build
node dist/index.js
在 npm i 后从 node_modules 运行:
node node_modules/next-mcp-server/dist/index.js
要运行示例环境:
pnpm --filter playground dev
该工具:
MIT