Logo von Openapi MCP Codegen

Openapi MCP Codegen

Organisation
cnoe-io

OpenAPI to MCP Server Code Generator

Herausgebercnoe-io
Repositoryopenapi-mcp-codegen
SprachePython
Forks
8
Sterne
42
Verfügbare Tools
0
Transporttypstdio
LizenzApache-2.0
Links
  • Tools mit KI-Workflows verbinden

    Openapi MCP Codegen stellt MCP-Funktionen bereit, die kompatible KI-Clients und Agenten nutzen können.

  • 0 verfügbare Tools

    Sehen Sie sich unten die aufrufbaren Aktionen an, einschließlich Namen und Beschreibungen, sofern der Server diese bereitstellt.

  • Konfiguration zum Kopieren

    Nutzen Sie die Installationsbeispiele, um diesen Server in Ihrem bevorzugten MCP-Client zu konfigurieren.

  • Open-Source-Kennzahlen

    42 Sterne und 8 Forks im verlinkten Repository.

🚀 OpenAPI to MCP Server Code Generator

Python License Conventional Commits Ruff Linter Super Linter Unit Tests Dependabot Updates

Overview

This tool generates Model Context Protocol (MCP) servers from OpenAPI specifications, creating Python packages that can be used by AI assistants to interact with APIs. The core architecture transforms OpenAPI specs into structured MCP servers with tools, models, and client code.

Quick Start

  • Install uv
  • Generate server (and optionally agent/eval):
    bash
    uvx --from git+https://github.com/cnoe-io/openapi-mcp-codegen.git openapi_mcp_codegen \
      --spec-file examples/petstore/openapi_petstore.json \
      --output-dir examples/petstore \
      --generate-agent \
      --generate-eval

✨ Features

  • ⚡ Automatic MCP server generation from OpenAPI specs
  • 📝 Supports JSON and YAML formats
  • 🛠️ Tool modules for each API endpoint
  • 🤖 API client code generation
  • 📋 Logging & error handling setup
  • ⚙️ Configuration files (pyproject.toml, .env.example)
  • 📚 Comprehensive documentation generation
  • 🚀 --generate-agent flag – additionally produces a LangGraph React agent (with A2A server, Makefile, README and .env.example) alongside the generated MCP server
  • 📊 --generate-eval: adds interactive eval mode and automated evaluation suite
  • 🧠 --generate-system-prompt: generates a SYSTEM prompt for the agent using your configured LLM
  • 🔌 Optional SLIM transport support is available (see Experimental section)

How It Works

  • You provide an OpenAPI spec (JSON or YAML).
  • The generator parses paths, operations, and schemas, then renders Jinja2 templates into a structured Python MCP server.
  • Optionally, it generates an accompanying LangGraph agent and A2A server wrapper that can call the generated MCP tools.
  • Also supports tracing and evaluation using LangFuse.

Development

Local Development Commands

bash
# Setup venv
uv venv && source .venv/bin/activate

# Initial setup (requires uv CLI)
uv sync

CLI Options

  • --generate-agent
    • Produces a LangGraph React agent that wraps the generated MCP server
    • Includes A2A server, Makefile, README, and .env.example
  • --generate-eval
    • Adds:
      • eval_mode.py (interactive dataset builder that stores traces in eval/dataset.yaml)
      • eval/evaluate_agent.py (LangFuse-powered evaluation using correctness, hallucination, and trajectory accuracy)
  • --generate-system-prompt
    • Uses your configured LLM to create a SYSTEM prompt tailored to the generated tools
  • --enhance-docstring-with-llm
    • Optionally rewrites tool docstrings using an LLM
  • --enable-slim
    • Bridges the generated A2A Starlette application to SLIM via AgntcyFactory and generates a docker-compose file to bring up the services

Generated Architecture

🏗️ Architecture

The generated architecture includes an MCP server in STDIO mode and two built-in utility tools: get_current_time and iso8601_to_unix.

Example: Petstore A2A LangGraph agent + MCP Server

  1. Generate the agent + evals
uvx --from git+https://github.com/cnoe-io/openapi-mcp-codegen.git openapi_mcp_codegen \
  --spec-file examples/petstore/openapi_petstore.json \
  --output-dir examples/petstore \
  --generate-agent \
  --generate-eval
  1. Configure your agent + LLM (see LLM provider docs) and Langfuse docs on deploying using docker-compose and creating API keys.
cat > .env << 'EOF'
# Petstore API
PETSTORE_API_URL=http://0.0.0.0:10000
PETSTORE_TOKEN=foo

# LLM provider (configure per your provider)
LLM_PROVIDER=openai
OPENAI_API_KEY=<your-openai-api-key>
OPENAI_ENDPOINT=https://api.openai.com/v1
OPENAI_MODEL_NAME=gpt-5

# Langfuse (optional)
LANGFUSE_HOST=http://localhost:3000
LANGFUSE_PUBLIC_KEY=<your-langfuse-public-key>
LANGFUSE_SECRET_KEY=<your-langfuse-secret-key>
EOF

Also export the variables into your shell:

bash
# Exports each line of the .env ignoring lines starting with #
export $(grep -v '^#' .env | xargs)
  1. Go to the agent directory and run the mock server:
cd examples/petstore
uv run python petstore_mock_server.py
  1. In a new terminal from the root of the git repo:
cd examples/petstore
make run-a2a
  1. In a new terminal from the root of the git repo (install Docker first):
cd examples/petstore
make run-a2a-client

You now have an agent and client deployed, e.g. ask List my available pets. You can see tracing in LangFuse (http://localhost:3000) if enabled. Follow the next steps to evaluate your agent:

  1. In a new terminal start the agent in eval mode. This will output the list of tools and prompt you to evaluate each one and build the dataset in eval/dataset.yaml
make run-a2a-eval-mode
  1. Once you are done building the dataset, launch the evaluation:
make eval

This creates a new dataset in LangFuse and triggers an evaluation run.

Extension: SLIM

This section requires host.docker.internal to be accessible. See this GitHub issue if you encounter any problems.

  1. If you generated with --enable-slim, you can also run the A2A server over SLIM and auto-start a local SLIM dataplane via docker-compose:
export PETSTORE_API_URL=http://host.docker.internal:10000  # Needed so that the MCP server can talk to the mock API server running on the host
make run-a2a-and-slim

This docker-compose:

  • Runs two containers: one A2A over HTTP and one A2A bridged to SLIM,
  • starts a slim-dataplane service defined in slim-config.yaml,
  • wires Langfuse into both containers (assuming host.docker.internal is accessible, alternatively add the langfuse components to the generate docker-compose file and update the LANGFUSE_HOST environment variable to http://langfuse-web:3000).
  1. To connect to the SLIM-bridged agent from the client in a new terminal run:
make run-slim-client

A2A Inspector Tool

The A2A Inspector is a utility for inspecting and debugging A2A servers. It provides a visual interface to explore agent cards and invoke the agent. Follow the instructions on the project page to build and run the inspector, which should be available at localhost:8080. You can then connect to the agent running on localhost:8000/.well-known/agent.json.

Project-Specific Conventions

Configuration Files

  • Each example requires config.yaml with metadata such as authorization headers
  • Generated pyproject.toml includes agent-specific dependencies
  • .env.example templates include agent-specific environment variables

Code Generation Patterns

  • Operation IDs become Python function names (snake_case conversion)
  • OpenAPI parameters map to function arguments with type hints
  • Generated tools follow pattern: async def operation_id(params) -> Any
  • API client uses httpx with configurable base URLs and headers

Integration Points

External Dependencies

  • MCP Protocol: Uses mcp>=1.9.0 for FastMCP server implementation
  • uv Package Manager: Required for dependency management and execution
  • Jinja2: Template engine for code generation
  • Ruff: Code formatting and linting (auto-applied to generated code)

Key Files for Understanding

  • openapi_mcp_codegen/mcp_codegen.py: Core generation logic and template rendering
  • openapi_mcp_codegen/templates/: Template structure mirrors output structure
  • examples/petstore/: Complete working example with OpenAPI spec and config
  • tests/test_mcp_codegen.py: Integration tests showing expected generation flow

Experimental

SLIM Support

Use --enable-slim to build an agent that can run its A2A server over the SLIM transport.

  • When generated with --enable-slim, docker-compose also brings up a slim-dataplane service and connects the agent over SLIM.
  • The agent A2A server runs over SLIM via AgntcyFactory.
  • Use make run-a2a-and-slim to start both HTTP A2A and the SLIM bridge stack, including the slim-dataplane.
  • To connect to the SLIM-bridged agent from the client:
    make run-slim-client
  • Reference:

A2A proxy

--with-a2a-proxy flag

  • Generates a minimal WebSocket upstream server intended to sit behind an external a2a-proxy.
  • Deploy the external a2a-proxy separately and configure it to connect to the WS upstream (ws://host:port). The proxy exposes an A2A HTTP API (e.g., /a2a/v1) for clients.
  • When combined with --generate-agent, a Makefile target may be provided (e.g. make run-with-proxy) to start the WS upstream locally.
  • This pathway is experimental and subject to change. Use for evaluation and prototyping only.

Common Debugging Patterns

  • Generated code includes extensive logging via Python's logging module
  • Template variables accessible via Jinja2 context in render_template()
  • Use --dry-run flag to preview generation without writing files

🎯 Enhanced Documentation with OpenAPI Overlay

Overview

This tool now supports LLM-enhanced documentation using the OpenAPI Overlay Specification 1.0.0. Generate AI-friendly MCP servers with optimized docstrings for better agent comprehension.

Quick Start: Enhanced Generation

bash
# One-command enhanced MCP server generation
python -m openapi_mcp_codegen.enhance_and_generate \
    examples/argo-workflows/openapi_argo_workflows.json \
    examples/argo-workflows/mcp_server \
    examples/argo-workflows/config.yaml \
    --save-overlay overlay.yaml \
    --save-enhanced-spec enhanced_openapi.json

This command will:

  1. Generate overlay with AI-friendly descriptions (using LLM if available)
  2. Apply overlay to create enhanced OpenAPI spec
  3. Generate MCP server with optimized docstrings

Enhancement Pipeline

Key Features

1. LLM-Enhanced Descriptions

  • OpenAI-compatible format (<250 characters)
  • Plain text - no markdown or special formatting
  • Use case context - "Use when: "
  • Action-oriented - starts with clear verbs

2. Smart Parameter Handling

  • Automatic detection of complex schemas
  • Dictionary mode for schemas with >10 nested parameters
  • Clean function signatures - no more 1000+ parameter functions
  • Result: 98% code size reduction for complex operations

3. OpenAPI Overlay Standard

  • Industry standard overlay specification 1.0.0
  • Reusable across tools and platforms
  • Version-controlled documentation enhancements
  • Non-destructive to original OpenAPI spec

Configuration

The title field in config.yaml now controls the package name:

yaml
title: argo_workflows              # → mcp_argo_workflows
description: Argo Workflows MCP Server
author: Your Name
email: you@example.com
version: 0.1.0
license: Apache-2.0

headers:
  Authorization: Bearer {token}
  Accept: application/json

Overlay Generation Options

bash
# Generate overlay only (with LLM)
python -m openapi_mcp_codegen.overlay_generator \
    spec.json overlay.yaml --use-llm

# Apply existing overlay
python -m openapi_mcp_codegen.overlay_applier \
    spec.json overlay.yaml enhanced_spec.json

# Full pipeline
python -m openapi_mcp_codegen.enhance_and_generate \
    spec.json output/ config.yaml \
    --save-overlay overlay.yaml \
    --format yaml

Example: Before vs After

Before Enhancement

yaml
GET /api/v1/workflows:
  description: "Get workflows"

After LLM Enhancement

yaml
GET /api/v1/workflows:
  description: "List all workflows in a namespace. Use when: you need to discover running workflows or check workflow status. Required: namespace"

Generated Function

python
async def workflow_service_list_workflows(
    path_namespace: str,
    param_listOptions_labelSelector: str = None
) -> Any:
    """
    List all workflows in a namespace

    OpenAPI Description:
        List all workflows in a namespace. Use when: you need to
        discover running workflows or check workflow status.

    Args:
        path_namespace (str): Kubernetes namespace to scope the operation
        param_listOptions_labelSelector (str): Filter by labels
    """

Performance Impact

MetricBeforeAfterImprovement
Function Size (complex)5,735 lines82 lines98.6% ↓
Parameter Count1,000+7 params99.3% ↓
Description Length300+ chars<250 charsOpenAI compliant ✅
Tool Selection AccuracyBaseline+35%Better agent performance

File Management

Store in version control:

  • ✅ openapi.json - Original OpenAPI spec
  • ✅ config.yaml - Configuration
  • 🤔 overlay.yaml - Optional (can regenerate, but useful for review/edits)

Auto-generated (don't store):

  • ❌ enhanced_openapi.json - Derived from original + overlay
  • ❌ mcp_server/ - Generated code output

LLM Provider Setup

bash
# Set LLM API keys
export OPENAI_API_KEY=your-key
export ANTHROPIC_API_KEY=your-key
export LLM_PROVIDER=openai  # or anthropic

# The overlay generator will automatically use LLM if keys are set
# Falls back to rule-based generation if no LLM available

Advanced: Custom Overlays

You can manually edit overlay.yaml for fine-tuned control:

yaml
overlay: 1.0.0
info:
  title: Custom Enhancements
  version: 1.0.0

actions:
  - target: $.paths['/api/v1/workflows'].get.description
    update: "Your custom description here"

  - target: $.paths['/api/v1/workflows'].get.parameters[0].description
    update: "Custom parameter description"

Then apply and regenerate:

bash
python -m openapi_mcp_codegen.overlay_applier \
    original_spec.json overlay.yaml enhanced_spec.json

python -m openapi_mcp_codegen \
    --spec-file enhanced_spec.json \
    --output-dir mcp_server

📚 Additional Resources

Openapi MCP Codegen MCP mit mehreren KI-Modellen nutzen

TypingMind bindet MCP-Tools auf Arbeitsbereichsebene ein. Sobald Openapi MCP Codegen verbunden ist, können Sie die Integration mit verschiedenen KI-Modellen in TypingMind verwenden, statt sie für jedes Modell separat einzurichten. Diese MCP-Integration läuft lokal über den TypingMind-MCP-Konnektor auf Ihrem Gerät.

Einrichtungsanleitung für den lokalen Konnektor

Nutzen Sie diese Option, wenn der MCP-Server Zugriff auf lokale Dateien, Apps oder private Ressourcen auf Ihrem Computer benötigt.

1

MCP-Einstellungen öffnen

Gehen Sie in TypingMind zu „Einstellungen“, „Erweiterte Einstellungen“ und dann „Model Context Protocol“ und wählen Sie „Konnektor-Setup“.

  1. Öffnen Sie TypingMind in Ihrem Browser.
  2. Klicken Sie auf das Symbol „Optionen“.
  3. Gehen Sie zu „Erweiterte Einstellungen“.
  4. Öffnen Sie den Abschnitt „Model Context Protocol“.
  5. Klicken Sie auf „Konnektor-Setup“ und wählen Sie „Dieses Gerät“.
Einrichtungsbildschirm des TypingMind-MCP-Konnektors mit ausgewählter Option „Dieses Gerät“
2

Konnektor-Befehl ausführen

Wählen Sie „Dieses Gerät“, kopieren Sie den Befehl aus TypingMind und führen Sie ihn im Terminal aus. Lassen Sie den Prozess laufen, solange Sie MCP verwenden.

  1. Kopieren Sie den in TypingMind angezeigten Einrichtungsbefehl.
  2. Öffnen Sie unter macOS Terminal bzw. unter Windows Windows Terminal.
  3. Fügen Sie den Befehl ein und führen Sie ihn aus.
  4. Bestätigen Sie die Paketinstallation, wenn Sie im Terminal zum Fortfahren aufgefordert werden.
  5. Lassen Sie das Terminalfenster geöffnet und den Prozess darin laufen, solange Sie MCP-Tools verwenden.
3

Openapi MCP Codegen als Server hinzufügen

Wenn der Konnektorstatus „Bereit“ anzeigt, klicken Sie auf „Server ändern“ und fügen Sie die MCP-Server-Konfiguration ein.

  1. Warten Sie, bis der Konnektorstatus „Bereit“ anzeigt.
  2. Klicken Sie auf „Server ändern“.
  3. Fügen Sie die MCP-Server-Konfiguration für Openapi MCP Codegen ein.
  4. Speichern Sie die Serverliste.
  5. Aktualisieren Sie die Ansicht, um bei Bedarf zu prüfen, ob der Konnektor weiterhin bereit ist.
MCP-Einstellungen in TypingMind mit aktivem Server und der Schaltfläche „Server ändern“
{
  "mcpServers": {
    "openapi-mcp-codegen": {
      "command": "npx",
      "args": [
        "-y",
        "<mcp-server-package>"
      ]
    }
  }
}
4

Verbindung modellübergreifend nutzen

Speichern Sie die Serverliste, öffnen Sie „Plugins“ und aktivieren Sie die MCP-Tools von Openapi MCP Codegen. Wählen Sie dann ein beliebiges unterstütztes KI-Modell in TypingMind und verwenden Sie die Tools im Chat oder weisen Sie sie einem KI-Agenten zu.

  1. Öffnen Sie die Seite „Plugins“ in TypingMind.
  2. Aktivieren Sie die MCP-Tools von Openapi MCP Codegen.
  3. Starten Sie einen Chat und wählen Sie das KI-Modell, das Sie verwenden möchten.
  4. Nutzen Sie die MCP-Tools im Chat oder weisen Sie sie einem KI-Agenten zu.
  5. Wechseln Sie bei Bedarf zu einem anderen KI-Modell, ohne die MCP-Verbindung erneut herzustellen.
TypingMind-Chat mit aktivierten MCP-Tools und einem ausgewählten KI-Modell
Können Sie mir mit Openapi MCP Codegen bei dieser Aufgabe helfen?
Openapi MCP Codegen
Gerne. Ich habe es gelesen.
Das habe ich mit Openapi MCP Codegen gefunden.

Häufig gestellte Fragen

Wofür wird der MCP-Server Openapi MCP Codegen verwendet?

Openapi MCP Codegen ist ein MCP-Server, über den kompatible KI-Clients auf externe Tools und Kontext zugreifen können. In TypingMind können Sie diesen MCP-Server einmal hinzufügen und seine Tools in Ihrem KI-Arbeitsbereich verfügbar machen.

Kann ich Openapi MCP Codegen MCP mit mehreren KI-Modellen in TypingMind verwenden?

Ja. TypingMind bindet MCP-Tools auf Arbeitsbereichsebene ein. So können Sie Openapi MCP Codegen mit verschiedenen KI-Modellen wie Claude, ChatGPT, Gemini oder anderen in TypingMind konfigurierten Modellen verwenden, ohne den MCP-Server für jedes Modell separat einzurichten.

Warum Openapi MCP Codegen MCP mit TypingMind nutzen?

TypingMind ist eine der besten Oberflächen für LLM-Chats, da es mehrere KI-Modelle, Prompts, Plugins, KI-Agenten, API-Schlüssel und MCP-Tools in einem Arbeitsbereich vereint. Sobald Openapi MCP Codegen verbunden ist, können Sie die zugehörigen MCP-Tools mit Ihren bevorzugten Modellen nutzen und Ihre Chat-Abläufe in TypingMind übersichtlich organisieren.

Wie verbinde ich Openapi MCP Codegen MCP mit TypingMind?

Openapi MCP Codegen wird über den lokalen MCP-Konnektor von TypingMind angebunden. Das ist die beste Wahl, wenn der MCP-Server auf lokale Dateien, Desktop-Apps, Befehlszeilentools oder private Ressourcen auf Ihrem Computer zugreifen muss.

Welche Tools stellt Openapi MCP Codegen MCP in TypingMind bereit?

Openapi MCP Codegen stellt MCP-Funktionen bereit, die Sie auf der Plugins-Seite in TypingMind aktivieren und im Chat verwenden oder KI-Agenten zuweisen können.

Muss ich meine API-Schlüssel mit TypingMind teilen, um Openapi MCP Codegen MCP zu verwenden?

Nein. TypingMind arbeitet vorrangig lokal, sodass Sie die Kontrolle über Ihre Modellanbieter, API-Schlüssel, Prompts und MCP-Konfiguration behalten. Falls Openapi MCP Codegen eine Authentifizierung erfordert, fügen Sie beim Erstellen der Verbindung die erforderlichen Header, OAuth-Einstellungen oder die lokale Konfiguration für diesen MCP-Server hinzu.

Ähnliche MCP-Server

Alle

Jetzt eigenen KI-Arbeitsbereich einrichten

Abonnieren Sie unseren Newsletter und erfahren Sie mehr über neue Funktionen und kommende Gewinnspiele 👇