mcp-generator-cli
v1.2.0
Published
CLI tool to automatically generate MCP servers from repository endpoints
Downloads
119
Maintainers
Readme
MCP Generator CLI
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-cliLocal Installation
npm install --save-dev mcp-generator-cliUsing 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 --verbose2. Initialize Configuration
mcp-generator init3. 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-runinit
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,@Pathannotations - 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 /usersPython/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 install2. Configure Environment
cp .env.example .env
# Edit .env with your API base URL3. Run Development Server
npm run dev4. 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
No endpoints found
- Ensure your code follows standard framework patterns
- Use
--verboseflag to see detection details - Check include/exclude patterns
Language detection failed
- Explicitly specify language with
--languageflag - Ensure project files exist (package.json, pom.xml, etc.)
- Explicitly specify language with
Generation failed
- Check file permissions in output directory
- Verify configuration file syntax
- Use
--dry-runto test without creating files
Debug Mode
Enable detailed logging:
mcp-generator generate --verboseValidation
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
