MCP Server Overview
APiGen includes a Model Context Protocol (MCP) server that enables AI assistants to generate API code conversationally.
What is MCP?
MCP (Model Context Protocol) is a standard protocol developed by Anthropic for connecting AI assistants to external tools and data sources. It allows AI models like Claude to:
- Call tools (functions) with specific parameters
- Access resources (data) from external systems
- Maintain context across conversations
Why MCP for Code Generation?
Traditional code generation requires:
- Writing SQL schemas manually
- Running CLI commands with correct flags
- Understanding all available options
With MCP, you can simply describe what you need:
"Generate a REST API for a blog system with users, posts, and comments using Python FastAPI"
The AI assistant understands the request and calls the appropriate APiGen tools.
Available Implementations
Java MCP Server
Native integration with the codegen engine.
- Direct access to all generators
- No subprocess overhead
- Full type safety
# Build and run
./gradlew :mcp:java:build
java -jar mcp/java/build/libs/java-1.0.0-SNAPSHOT-all.jarPython MCP Server
Lightweight wrapper using CLI subprocess.
- Easy to install (
pip install) - Quick setup
- Uses existing CLI
# Install and run
cd mcp/python
pip install -e .
apigen-mcpTools Available
Both implementations provide the same tools:
| Tool | Description |
|---|---|
generate_from_sql | Generate complete API from SQL schema |
preview_sql | Preview generated code without writing files |
parse_sql | Parse SQL and return table structure |
list_languages | List supported programming languages |
list_databases | List supported database types |
Resources Available
Static resources for reference:
| Resource URI | Description |
|---|---|
apigen://languages | Supported languages with descriptions |
apigen://databases | Supported database types |
apigen://field-types | Available field types |
apigen://example/sql | Example SQL schema |
Configuration
Claude Desktop
Add to claude_desktop_config.json:
{
"mcpServers": {
"apigen": {
"command": "java",
"args": ["-jar", "/path/to/apigen/mcp/java/build/libs/java-1.0.0-SNAPSHOT-all.jar"]
}
}
}Other MCP Clients
Any MCP-compatible client can connect using:
- Transport: stdio (standard input/output)
- Protocol: JSON-RPC 2.0
- Version: 2024-11-05
Example Conversation
User: Create a REST API for a task management system with users, projects, and tasks. Use TypeScript with NestJS.
AI Assistant (using APiGen MCP):
I'll generate that for you. Let me first parse the schema and then generate the code.
[Calls parse_sql tool]
Found 3 tables:
- users (4 columns)
- projects (5 columns)
- tasks (7 columns)
[Calls generate_from_sql tool with language=typescript-nestjs]
Generated 24 files:
- src/users/users.entity.ts
- src/users/users.dto.ts
- src/users/users.controller.ts
- src/users/users.service.ts
- src/projects/...
- src/tasks/...
- prisma/schema.prisma
- package.json
- tsconfig.jsonComparison
| Feature | Java MCP | Python MCP |
|---|---|---|
| Integration | Native | Subprocess |
| Startup Time | Slower (JVM) | Faster |
| Performance | Better | Good |
| Dependencies | Java 25+ | Python 3.10+, Java CLI |
| Best For | Production | Quick setup |
Next Steps
- Java MCP Setup - Native server configuration
- Python MCP Setup - Python wrapper configuration
- Tools Reference - Detailed tool documentation