MCP HubMCP Hub
jazelly

next-mcp-server

by: jazelly

Help LLMs to understand your Next apps better

85created 24/03/2025
Visit
Next.js
LLM

📌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

    The Router Analyzer scans your Next.js app directory structure and extracts information about all API routes, including:

    • API paths
    • HTTP methods (GET, POST, PUT, DELETE, etc.)
    • Request parameters
    • Status codes
    • Request and response schemas

Installation

npm install next-mcp-server

Or if you're using pnpm:

pnpm add next-mcp-server

Usage

Command Line

You can run the MCP server directly:

npm run build
node dist/index.js

Docker

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

For cursor usage, define a mcp.json under ~/.cursor or [projectDir]/.cursor:

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

The url may vary based on your .env settings within the project.

Output

The tool generates detailed information about each route:

[
  {
    "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": "Get test data",
        "parameters": [],
        "statusCodes": [200]
      },
      {
        "method": "POST",
        "path": "/api/test",
        "functionSignature": "export async function POST(request: Request)",
        "description": "Create test data",
        "parameters": [],
        "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 after npm i:

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

To run the playground:

pnpm --filter playground dev

How It Works

The tool:

  1. Scans your Next.js app directory structure for route files.
  2. Analyzes each route file to extract HTTP methods, paths, parameters, etc.
  3. Extracts documentation from comments.
  4. Returns a structured representation of all your API routes.

Restrictions

  1. Because it accesses the filesystem by path, it will not work if hosted over a network.
  2. Supports only Next.js App router projects.

License

MIT