Sponsored by Deepsite.site

OpenAPI to Model Context Protocol (MCP)

Created By
gujord9 months ago
The OpenAPI to Model Context Protocol (MCP) proxy server bridges the gap between AI agents and external APIs by dynamically translating OpenAPI specifications into standardized MCP tools. This simplifies the integration process, significantly reducing development time and complexity associated with custom API wrappers.
Content

OpenAPI to Model Context Protocol (MCP)

License: MIT Repo Size Last Commit Open Issues

OpenAPI-MCP

The OpenAPI to Model Context Protocol (MCP) proxy server bridges the gap between AI agents and external APIs by dynamically translating OpenAPI specifications into standardized MCP tools. This simplifies integration, eliminating the need for custom API wrappers.


Why MCP?

The Model Context Protocol (MCP), developed by Anthropic, standardizes communication between Large Language Models (LLMs) and external tools. By acting as a universal adapter, MCP enables AI agents to interface with external APIs seamlessly.


Key Features

  • OpenAPI Integration: Parses and registers OpenAPI operations as callable tools.
  • OAuth2 Support: Handles machine authentication via Client Credentials flow.
  • Dry Run Mode: Simulates API calls without execution for inspection.
  • JSON-RPC 2.0 Support: Fully compliant request/response structure.
  • Auto Metadata: Derives tool names, summaries, and schemas from OpenAPI.
  • Sanitized Tool Names: Ensures compatibility with MCP name constraints.
  • Query String Parsing: Supports direct passing of query parameters as a string.
  • Enhanced Parameter Handling: Automatically converts parameters to correct data types.
  • Extended Tool Metadata: Includes detailed parameter information for better LLM understanding.
  • FastMCP Transport: Optimized for stdio, works out-of-the-box with agents.

Quick Start

Installation

git clone https://github.com/gujord/OpenAPI-MCP.git
cd OpenAPI-MCP
pip install -r requirements.txt

Environment Configuration

VariableDescriptionRequiredDefault
OPENAPI_URLURL to the OpenAPI specificationYes-
SERVER_NAMEMCP server nameNoopenapi_proxy_server
OAUTH_CLIENT_IDOAuth client IDNo-
OAUTH_CLIENT_SECRETOAuth client secretNo-
OAUTH_TOKEN_URLOAuth token endpoint URLNo-
OAUTH_SCOPEOAuth scopeNoapi

How It Works

  1. Parses OpenAPI spec using httpx and PyYAML if needed.
  2. Extracts operations and generates MCP-compatible tools with proper names.
  3. Authenticates using OAuth2 (if credentials are present).
  4. Builds input schemas based on OpenAPI parameter definitions.
  5. Handles calls via JSON-RPC 2.0 protocol with automatic error responses.
  6. Supports extended parameter information for improved LLM understanding.
  7. Handles query string parsing for easier parameter passing.
  8. Performs automatic type conversion based on OpenAPI schema definitions.
  9. Supports dry_run to inspect outgoing requests without invoking them.
sequenceDiagram
    participant LLM as LLM (Claude/GPT)
    participant MCP as OpenAPI-MCP Proxy
    participant API as External API

    Note over LLM, API: Communication Process
    
    LLM->>MCP: 1. Initialize (initialize)
    MCP-->>LLM: Metadata and tool list
    
    LLM->>MCP: 2. Request tools (tools_list)
    MCP-->>LLM: Detailed tool list from OpenAPI specification
    
    LLM->>MCP: 3. Call tool (tools_call)
    
    alt With OAuth2
        MCP->>API: Request OAuth2 token
        API-->>MCP: Access Token
    end
    
    MCP->>API: 4. Execute API call with proper formatting
    API-->>MCP: 5. API response (JSON)
    
    alt Type Conversion
        MCP->>MCP: 6. Convert parameters to correct data types
    end
    
    MCP-->>LLM: 7. Formatted response from API
    
    alt Dry Run Mode
        LLM->>MCP: Call with dry_run=true
        MCP-->>LLM: Display request information without executing call
    end

Built-in Tools

These tools are always available:

  • initialize – Returns server metadata and protocol version.
  • tools_list – Lists all registered tools (from OpenAPI and built-in) with extended metadata.
  • tools_call – Calls any tool by name with arguments.

Advanced Usage

Query String Passing

You can pass query parameters as a string in the kwargs parameter:

{
  "jsonrpc": "2.0",
  "method": "tools_call",
  "params": {
    "name": "get_pets",
    "arguments": {
      "kwargs": "status=available&limit=10"
    }
  },
  "id": 1
}

Parameter Type Conversion

The server automatically converts parameter values to the appropriate type based on the OpenAPI specification:

  • String parameters remain as strings
  • Integer parameters are converted using int()
  • Number parameters are converted using float()
  • Boolean parameters are converted from strings like "true", "1", "yes", "y" to True

LLM Orchestrator Configuration

Cursor (~/.cursor/mcp.json)

{
  "mcpServers": {
    "petstore3": {
      "command": "full_path_to_openapi_mcp/venv/bin/python",
      "args": ["full_path_to_openapi_mcp/src/server.py"],
      "env": {
        "SERVER_NAME": "petstore3",
        "OPENAPI_URL": "https://petstore3.swagger.io/api/v3/openapi.json"
      },
      "transport": "stdio"
    }
  }
}

Cursor

Windsurf (~/.codeium/windsurf/mcp_config.json)

{
  "mcpServers": {
    "petstore3": {
      "command": "full_path_to_openapi_mcp/venv/bin/python",
      "args": ["full_path_to_openapi_mcp/src/server.py"],
      "env": {
        "SERVER_NAME": "petstore3",
        "OPENAPI_URL": "https://petstore3.swagger.io/api/v3/openapi.json"
      },
      "transport": "stdio"
    }
  }
}

Windsurf

Claude Desktop (~/Library/Application Support/Claude/claude_desktop_config.json)

{
    "mcpServers": {
        "petstore3": {
            "command": "full_path_to_openapi_mcp/venv/bin/python",
            "args": ["full_path_to_openapi_mcp/src/server.py"],
            "env": {
                "SERVER_NAME": "petstore3",
                "OPENAPI_URL": "https://petstore3.swagger.io/api/v3/openapi.json"
            },
            "transport": "stdio"
        }
    }
}

Contributing

  • Fork this repo
  • Create a new branch
  • Submit a pull request with a clear description

License

MIT License


If you find it useful, give it a ⭐ on GitHub!

Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
Serper MCP ServerA Serper MCP Server
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
Playwright McpPlaywright MCP server
DeepChatYour AI Partner on Desktop
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
ChatWiseThe second fastest AI chatbot™
WindsurfThe new purpose-built IDE to harness magic
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
CursorThe AI Code Editor
Tavily Mcp
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
Amap Maps高德地图官方 MCP Server
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.