next-mcp-server
by: jazelly
Help LLMs to understand your Next apps better
📌Overview
Purpose: The Next.js MCP Server is designed to analyze and provide detailed insights into the API routes of a Next.js application.
Overview: This framework serves as a powerful tool for scanning the directory structure of a Next.js application, extracting comprehensive details about all API routes, including their specifications. It enhances developers' understanding of their API architecture and simplifies documentation tasks.
Key Features:
-
get-routers-info: This feature scans the Next.js app directory to extract vital information about all API routes, such as API paths, HTTP methods, request parameters, status codes, and request/response schemas, thereby offering a complete view of the API specifications and functionalities.
-
Output Generation: The tool generates structured JSON output for each route, detailing file paths, method handlers, descriptions, and expected status codes. This enables easy integration into documentation processes or further API analysis.
Next.js MCP Server
Features
get-routers-info
: Scans your Next.js app directory structure to extract information about all API routes, including:- API paths
- HTTP methods (GET, POST, PUT, DELETE, etc.)
- Request parameters
- Status codes
- Request and response schemas
Installation
Install with npm:
npm install next-mcp-server
Or if you're using pnpm:
pnpm add next-mcp-server
Usage
Command Line
Run the mcp server directly:
npm run build
node dist/index.js
Docker
Build and run the Docker container:
docker build -t mcp/next -f Dockerfile .
docker run mcp/next -d
Define a mcp.json
under ~/.cursor
or [projectDir]/.cursor
to configure usage:
{
"mcpServers": {
"next.js": {
"url": "http://localhost:4857/sse"
}
}
}
Output
The tool generates detailed information about each route:
[
{
"filePath": "/path/to/your/app/api/test/route.ts",
"apiPath": "/api/test",
"handlers": [
{
"method": "GET",
"description": "Get test data",
"statusCodes": [200]
},
{
"method": "POST",
"description": "Create test data",
"requestBodySchema": "{ name: string }",
"statusCodes": [201, 400]
}
]
}
]
Development
To run tests:
npm run test
To run the mcp server locally:
npm run build
node dist/index.js
To run it from node_modules:
node node_modules/next-mcp-server/dist/index.js
To run the playground:
pnpm --filter playground dev
How It Works
- Scans your Next.js app directory structure for route files.
- Analyzes each route file to extract HTTP methods, paths, parameters, etc.
- Extracts documentation from comments.
- Returns a structured representation of all your API routes.
Restrictions
- Will not work if hosted over a network due to filesystem access limitations.
- Only supports Next.js App router projects.
License
MIT