Skip to content

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:

  1. Writing SQL schemas manually
  2. Running CLI commands with correct flags
  3. 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
bash
# Build and run
./gradlew :mcp:java:build
java -jar mcp/java/build/libs/java-1.0.0-SNAPSHOT-all.jar

Learn more →

Python MCP Server ​

Lightweight wrapper using CLI subprocess.

  • Easy to install (pip install)
  • Quick setup
  • Uses existing CLI
bash
# Install and run
cd mcp/python
pip install -e .
apigen-mcp

Learn more →

Tools Available ​

Both implementations provide the same tools:

ToolDescription
generate_from_sqlGenerate complete API from SQL schema
preview_sqlPreview generated code without writing files
parse_sqlParse SQL and return table structure
list_languagesList supported programming languages
list_databasesList supported database types

Resources Available ​

Static resources for reference:

Resource URIDescription
apigen://languagesSupported languages with descriptions
apigen://databasesSupported database types
apigen://field-typesAvailable field types
apigen://example/sqlExample SQL schema

Configuration ​

Claude Desktop ​

Add to claude_desktop_config.json:

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.json

Comparison ​

FeatureJava MCPPython MCP
IntegrationNativeSubprocess
Startup TimeSlower (JVM)Faster
PerformanceBetterGood
DependenciesJava 25+Python 3.10+, Java CLI
Best ForProductionQuick setup

Next Steps ​

Released under the MIT License.