swagger-to-mcp
Enables any OpenAPI/Swagger specification to be turned into an MCP server that exposes the defined API endpoints as callable tools.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@swagger-to-mcpgenerate an MCP server from my openapi.yaml spec"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Generic OpenAPI / Swagger MCP Server & Code Generator
Turn any OpenAPI (v3.0 / v3.1) or Swagger (v2.0) specification file (JSON or YAML) into a fully functional Model Context Protocol (MCP) server.
This project supports two operating modes:
Dynamic Runtime Mode (
main.py): Drop yourswagger.jsonoropenapi.yamlinto the root directory, configure.env, and immediately serve all API endpoints as LLM tools via MCP.Code Generator Mode (
generator.py): Run a simple command to parse any OpenAPI spec and generate standalone, static, readable Python code containing explicit MCP tools with complete docstrings.
🚀 Features
Universal Support: Parses OpenAPI 2.0 (Swagger) and OpenAPI 3.0 / 3.1 specs in JSON or YAML.
Reference Resolution: Resolves
$refschema pointer references (#/definitions/...or#/components/schemas/...).Rich LLM Docstrings: Formats endpoint summaries, descriptions, path/query/header parameters, and JSON request body structures into clean Markdown for LLMs.
Flexible Authentication:
Bearer Token / JWT
API Keys (Custom Header or Query Parameter)
Basic Authentication
Custom JSON Headers
Dual Operating Modes: Dynamic execution vs. standalone code generation.
Related MCP server: mcpify
📦 Setup & Installation
1. Prerequisites
Python >= 3.11
uv (recommended) or standard
pip
2. Install Dependencies
pip install -e .or with uv:
uv sync⚙️ Configuration (.env)
Copy .env.example to .env:
cp .env.example .envVariable | Description | Default / Example |
| Path to OpenAPI/Swagger spec file | Auto-detects |
| Override Base URL of target API | Spec's host/servers URL |
| Bearer Token / JWT for | Optional |
| API Key value | Optional |
| Header name for API Key |
|
| Query parameter name for API Key | Optional (e.g. |
| Basic Auth username | Optional |
| Basic Auth password | Optional |
🎯 Mode 1: Dynamic Runtime MCP Server (main.py)
Simply place your spec file (e.g., swagger.json) in the project directory and launch:
python main.pymain.py will:
Load and dereference
swagger.jsonoropenapi.yaml.Discover all paths and HTTP operations.
Automatically register each endpoint as an MCP tool with full descriptions.
Listen on
stdiofor MCP client connections (Claude Desktop, Cursor, Smithery, etc.).
🛠️ Mode 2: Standalone Code Generator (generator.py)
Generate a clean, standalone Python script from any spec file:
python generator.py --spec swagger.json --output my_api_mcp.py --name "my-api-service"Options:
--spec,-s: Path to spec file (swagger.json,openapi.yaml). Default:swagger.json.--output,-o: Output Python file path. Default:generated_mcp.py.--name,-n: FastMCP server name identifier. Default:openapi-mcp.
Once generated, run your generated server directly:
python my_api_mcp.py💻 Integration with Claude Desktop / Cursor / Inspector
Add the server to your MCP client configuration (e.g., claude_desktop_config.json):
{
"mcpServers": {
"my-openapi-service": {
"command": "python",
"args": [
"c:/path/to/reward-rally-mcp/main.py"
],
"env": {
"SWAGGER_PATH": "c:/path/to/your/swagger.json",
"BASE_URL": "https://api.yourdomain.com",
"BEARER_TOKEN": "your_api_token_here"
}
}
}
}🔬 Testing
Run syntax compilation checks:
python -m py_compile main.py generator.py spec_parser.pyThis server cannot be deployed
Maintenance
Related MCP Connectors
MCP server for AI access to Swagger by SmartBear.
Create hosted MCP servers from any OpenAPI spec. Requires a free Kaiva Bridge account.
- typeshipOAuthdev.typeship
Generate a typed SDK, CLI, and MCP server from any OpenAPI or GraphQL spec, and keep them current.
An MCP server that provides an API to LLMs to manage their JumpCloud resources.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceAutomatically converts Swagger/OpenAPI specifications into MCP servers, enabling AI agents to interact with any REST API through natural language by exposing endpoints as AI-friendly tools.3-
- AlicenseNot gradedqualityCmaintenanceTurns any OpenAPI specification into a fully working MCP server with a single command, enabling AI agents to call APIs without writing any glue code.3 npmMIT
- AlicenseNot gradedqualityDmaintenanceAutomatically generates MCP server tools from OpenAPI specifications, enabling LLMs to interact with any API defined by an OpenAPI spec through natural language.9 npmMIT
- AlicenseNot gradedqualityDmaintenanceConverts any OpenAPI/Swagger spec into an MCP server, exposing REST API endpoints as tools for Claude.MIT