npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

mcp-generator-cli

v1.2.0

Published

CLI tool to automatically generate MCP servers from repository endpoints

Downloads

119

Readme

MCP Generator CLI

npm version License: MIT TypeScript

A powerful CLI tool that automatically scans your repository for API endpoints and generates a complete Model Context Protocol (MCP) server. Supports Node.js, Java, and Python applications with popular frameworks.

🚀 Features

  • Multi-Language Support: Node.js (Express, Fastify, NestJS), Java (Spring Boot, JAX-RS), Python (Flask, FastAPI, Django)
  • Automatic Detection: Smart framework and endpoint detection
  • Complete MCP Server: Generates fully functional MCP server with tools and resources
  • TypeScript Support: Full type safety and IntelliSense
  • Docker Ready: Includes Dockerfile and docker-compose.yml
  • Configurable: Extensive configuration options and custom templates
  • CLI Interface: Easy-to-use command-line interface with validation

📦 Installation

Global Installation

npm install -g mcp-generator-cli

Local Installation

npm install --save-dev mcp-generator-cli

Using npx (No Installation Required)

npx mcp-generator-cli generate --help

🎯 Quick Start

1. Generate MCP Server

# Generate from current directory
mcp-generator generate

# Generate from specific path
mcp-generator generate --path ./my-api --output ./mcp-server

# Generate with specific language
mcp-generator generate --language nodejs --verbose

2. Initialize Configuration

mcp-generator init

3. Validate Repository

mcp-generator validate --path ./my-api

📋 Commands

generate

Generate an MCP server from your repository.

mcp-generator generate [options]

Options:

  • -p, --path <path> - Repository path (default: current directory)
  • -o, --output <output> - Output directory (default: ./mcp-server)
  • -l, --language <language> - Target language: nodejs|java|python|auto (default: auto)
  • -c, --config <config> - Configuration file path
  • -v, --verbose - Enable verbose logging
  • --dry-run - Show what would be generated without creating files

Examples:

# Basic generation
mcp-generator generate

# Custom output directory
mcp-generator generate -o ./my-mcp-server

# Specify language explicitly
mcp-generator generate -l java -v

# Use custom configuration
mcp-generator generate -c ./my-config.json

# Dry run to see what would be generated
mcp-generator generate --dry-run

init

Initialize configuration file with defaults.

mcp-generator init [options]

Options:

  • -p, --path <path> - Configuration file path (default: ./mcp-generator.config.json)

validate

Validate repository for MCP generation compatibility.

mcp-generator validate [options]

Options:

  • -p, --path <path> - Repository path (default: current directory)
  • -v, --verbose - Enable verbose output

🔧 Configuration

Configuration File Structure

Create mcp-generator.config.json:

{
  "serverName": "my-api-mcp-server",
  "serverVersion": "1.0.0",
  "description": "MCP server for My API",
  "tools": [
    {
      "name": "custom_tool",
      "description": "Custom tool implementation",
      "inputSchema": {
        "type": "object",
        "properties": {
          "input": {
            "type": "string",
            "description": "Input parameter"
          }
        },
        "required": ["input"]
      },
      "enabled": true
    }
  ],
  "resources": [
    {
      "name": "custom_resource",
      "description": "Custom resource",
      "mimeType": "application/json",
      "enabled": true
    }
  ],
  "excludePatterns": [
    "**/test/**",
    "**/*.test.*"
  ],
  "includePatterns": [
    "**/*.js",
    "**/*.ts",
    "**/*.java",
    "**/*.py"
  ]
}

Environment Variables

The generated MCP server supports these environment variables:

  • API_BASE_URL - Base URL for your API (default: http://localhost:3000)
  • NODE_ENV - Environment (development/production)
  • PORT - Port for health checks (optional)

🌍 Supported Languages & Frameworks

Node.js

  • Express.js - Route detection via app.get(), app.post(), etc.
  • Fastify - Route detection via decorators and route objects
  • NestJS - Decorator-based routing (@Get, @Post, etc.)
  • Koa - Router-based routing
  • Next.js - API routes detection
  • Hapi - Route configuration detection

Java

  • Spring Boot - @GetMapping, @PostMapping, @RequestMapping
  • Spring MVC - Traditional Spring MVC annotations
  • JAX-RS - @GET, @POST, @Path annotations
  • Jersey - JAX-RS implementation
  • Quarkus - Modern Java framework
  • Micronaut - JVM-based framework

Python

  • Flask - @app.route() decorators
  • FastAPI - @app.get(), @app.post() decorators
  • Django - URL patterns in urls.py
  • Starlette - ASGI framework routing
  • Tornado - RequestHandler classes
  • aiohttp - Async HTTP framework
  • Sanic - Async Python framework

📁 Generated Structure

mcp-server/
├── server.ts              # Main MCP server
├── tools.ts               # Tool implementations
├── resources.ts           # Resource implementations
├── package.json           # Dependencies
├── tsconfig.json          # TypeScript config
├── mcp-config.json        # MCP configuration
├── Dockerfile             # Docker image
├── docker-compose.yml     # Docker compose
├── .dockerignore          # Docker ignore
├── .env.example           # Environment template
└── README.md             # Generated documentation

🔍 Endpoint Detection Examples

Node.js/Express

// Detected endpoints
app.get('/users/:id', getUserById);           // GET /users/{id}
app.post('/users', createUser);               // POST /users
router.put('/users/:id', updateUser);        // PUT /users/{id}

Java/Spring Boot

// Detected endpoints
@GetMapping("/users/{id}")                    // GET /users/{id}
@PostMapping("/users")                        // POST /users
@RequestMapping(value = "/users", method = RequestMethod.PUT)  // PUT /users

Python/Flask

# Detected endpoints
@app.route('/users/<int:id>', methods=['GET'])     # GET /users/{id}
@app.route('/users', methods=['POST'])             # POST /users

🐳 Docker Usage

The generated MCP server includes Docker support:

# Build and run with Docker Compose
cd mcp-server
docker-compose up --build

# Build Docker image manually
docker build -t my-mcp-server .

# Run Docker container
docker run -e API_BASE_URL=http://host.docker.internal:3000 my-mcp-server

🧪 Testing Generated Server

1. Install Dependencies

cd mcp-server
npm install

2. Configure Environment

cp .env.example .env
# Edit .env with your API base URL

3. Run Development Server

npm run dev

4. Build for Production

npm run build
npm start

🔧 Advanced Usage

Custom Templates

You can provide custom templates for generated files:

{
  "customTemplates": {
    "server.ts": "path/to/custom-server-template.ts",
    "tools.ts": "path/to/custom-tools-template.ts"
  }
}

Filtering Endpoints

Use patterns to include/exclude specific files:

{
  "includePatterns": [
    "**/controllers/**",
    "**/routes/**"
  ],
  "excludePatterns": [
    "**/test/**",
    "**/migrations/**"
  ]
}

Multiple API Versions

Generate separate MCP servers for different API versions:

mcp-generator generate --path ./api/v1 --output ./mcp-v1
mcp-generator generate --path ./api/v2 --output ./mcp-v2

🐛 Troubleshooting

Common Issues

  1. No endpoints found

    • Ensure your code follows standard framework patterns
    • Use --verbose flag to see detection details
    • Check include/exclude patterns
  2. Language detection failed

    • Explicitly specify language with --language flag
    • Ensure project files exist (package.json, pom.xml, etc.)
  3. Generation failed

    • Check file permissions in output directory
    • Verify configuration file syntax
    • Use --dry-run to test without creating files

Debug Mode

Enable detailed logging:

mcp-generator generate --verbose

Validation

Always validate your repository first:

mcp-generator validate --verbose

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • Model Context Protocol for the MCP specification
  • All the amazing open-source frameworks this tool supports
  • The developer community for feedback and contributions

Made with ❤️ by David Butbul