Skip to main content

Automatic MCP server generator for OpenAPI applications - converts OpenAPI endpoints to MCP tools for LLM integration

Project description

OpenAPI-MCP

A zero-configuration tool for integrating Model Context Protocol (MCP) servers with any OpenAPI-compliant application.

PyPI version Python Versions

Features

  • Magical integration - Instantly create an MCP server from any OpenAPI specification with zero configuration
  • Automatic discovery - All API endpoints are automatically converted to MCP tools
  • Documentation preservation - API documentation is automatically converted to MCP tool descriptions
  • Framework agnostic - Works with any API framework that supports OpenAPI (FastAPI, Flask, Django, etc.)
  • Zero manual setup - No need to create MCP tools manually, everything is done automatically

Installation

We recommend using uv, a fast Python package installer:

uv add openapi-mcp

Alternatively, you can install with pip:

pip install openapi-mcp

For detailed installation instructions and alternative methods, see INSTALL.md.

Basic Usage

The simplest way to use OpenAPI-MCP is to point it at your OpenAPI specification:

from openapi_mcp import create_mcp_server, serve_mcp

# Just point it at your OpenAPI spec and it does everything automatically
serve_mcp(
    create_mcp_server("https://your-api.com/openapi.json"),
    host="127.0.0.1", 
    port=8000
)

# That's it! Your MCP server is now running with all API endpoints available as tools

If you're using FastAPI, it's even easier:

from fastapi import FastAPI
from openapi_mcp import add_mcp_server

# Your FastAPI app
app = FastAPI()

# Add some endpoints
@app.get("/hello/{name}")
async def hello(name: str):
    """Say hello to someone"""
    return {"message": f"Hello, {name}!"}

# One line to add an MCP server - everything is automatic!
add_mcp_server(app, mount_path="/mcp")

# That's it! Your auto-generated MCP server is now available at `https://app.base.url/mcp`

OpenAPI-MCP is framework-agnostic and works with any API that has an OpenAPI specification:

# Flask with OpenAPI spec
from flask import Flask
from openapi_mcp import create_mcp_server, serve_mcp

# Use your existing OpenAPI specification from any framework
openapi_url = "http://your-flask-app.com/swagger.json"  # URL to your OpenAPI spec

# Create the MCP server from the OpenAPI spec
mcp_server = create_mcp_server(openapi_url)

# Serve the MCP server
serve_mcp(mcp_server, host="127.0.0.1", port=8000)

How It Works

  1. OpenAPI-MCP reads your OpenAPI specification
  2. It automatically discovers all endpoints and their parameters
  3. It automatically converts each endpoint into an MCP tool
  4. It automatically generates descriptions, schemas, and examples for each tool
  5. It automatically handles HTTP requests to your API when tools are called

No manual tool creation, no boilerplate code, no configuration needed!

Examples

OpenAPI Specification Example:

from openapi_mcp import create_mcp_server, serve_mcp

# Just point it at any OpenAPI specification URL
mcp_server = create_mcp_server("https://api.example.com/openapi.json")

# Start the server
if __name__ == "__main__":
    serve_mcp(mcp_server, host="127.0.0.1", port=8000)

Framework-Specific Examples

FastAPI Example:

from fastapi import FastAPI
from openapi_mcp import add_mcp_server

app = FastAPI(title="Simple API")

@app.get("/hello/{name}")
async def hello(name: str):
    """Say hello to someone"""
    return {"message": f"Hello, {name}!"}

# Just one line to add an MCP server - no configuration needed!
add_mcp_server(app, mount_path="/mcp")

Express.js (Node.js) Example:

For Express.js or other non-Python frameworks, you can run OpenAPI-MCP as a standalone service:

# Using the command-line tool with an OpenAPI specification
openapi-mcp serve https://your-express-app.com/api-docs/swagger.json

This will start an MCP server that proxies requests to your Express.js API based on the OpenAPI specification.

Connecting to the MCP Server

Once your MCP server is running, you can connect to it with any MCP client, such as Claude:

  1. Run your application
  2. In Claude, use the URL of your MCP server endpoint (e.g., http://localhost:8000/mcp)
  3. Claude will discover all available tools and resources automatically

Advanced Options (Optional)

While OpenAPI-MCP is designed to work automatically with zero configuration, there are a few optional settings available if you need more control:

from openapi_mcp import create_mcp_server, serve_mcp

# Create the MCP server with optional customizations
mcp_server = create_mcp_server(
    "https://your-api.com/openapi.json",
    name="My Custom API MCP",                        # Custom name for the MCP server
    base_url="https://your-api.com",                 # Base URL for API requests
    describe_all_responses=True,                     # Include error response schemas in tool descriptions
    describe_full_response_schema=True,              # Include detailed response schemas
)

# You can also register custom functions directly with the MCP server
from mcp.types import ToolDefinition

def get_server_time() -> str:
    """Get the current server time."""
    from datetime import datetime
    return datetime.now().isoformat()

# Register the function as a tool
mcp_server.register_tool(
    ToolDefinition(
        name="get_server_time",
        description="Get the current server time.",
        implementation=get_server_time
    )
)

# Serve the MCP server
serve_mcp(mcp_server, host="127.0.0.1", port=8000)

Development and Contributing

If you're interested in contributing to OpenAPI-MCP:

# Clone the repository
git clone https://github.com/tadata-org/openapi-mcp.git
cd openapi-mcp

# Create a virtual environment and install dependencies with uv
uv venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
uv add -e ".[dev]"

# Run tests
uv run pytest

For more details about contributing, see CONTRIBUTING.md.

Requirements

  • Python 3.10+
  • uv

License

MIT License. Copyright (c) 2024 Tadata Inc.

About

Developed and maintained by Tadata Inc.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openapi_mcp-0.1.0.tar.gz (56.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

openapi_mcp-0.1.0-py3-none-any.whl (14.6 kB view details)

Uploaded Python 3

File details

Details for the file openapi_mcp-0.1.0.tar.gz.

File metadata

  • Download URL: openapi_mcp-0.1.0.tar.gz
  • Upload date:
  • Size: 56.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.5

File hashes

Hashes for openapi_mcp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d7b6e8fa941e5a124b4241dfce4f3c646fb84d6d03a6677f927914b514e51f22
MD5 13c28dccd0d16d0b8655460a4a576856
BLAKE2b-256 7c0290aba79e9520cb0cc92ac59ea4dda4005af6fe32de15052a10535d79d250

See more details on using hashes here.

File details

Details for the file openapi_mcp-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: openapi_mcp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.5

File hashes

Hashes for openapi_mcp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 070be4844e67efd4afcd549e765baa48928623b00d047affa82a0b901ca9ad40
MD5 4e4786909c76a2da62496e945bec529d
BLAKE2b-256 409d14805f0c52b4f6faccabd20d253e4697bf55097850b298360cd8a60d1be5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page