Convert OpenAPI specs into MCP (Model Context Protocol) servers
Project description
oapi2mcp
Convert any OpenAPI 3.x specification into a working MCP (Model Context Protocol) server — zero configuration, zero code.
Quick Start
# Run directly with uvx — no install needed
uvx oapi2mcp --spec http://localhost:3000/openapi.json
# Or install with pip
pip install oapi2mcp
oapi2mcp --spec http://localhost:3000/openapi.json
That's it. Every endpoint in your OpenAPI spec is now available as an MCP tool.
How It Works
- Parses your OpenAPI 3.x spec (local file or remote URL)
- Resolves all
$refreferences recursively - Converts every operation into an MCP tool with a proper
inputSchema - Serves tools over stdio, SSE, or streamable-http
- Forwards tool calls to the upstream API via HTTP
Configuration
CLI Options
oapi2mcp --spec <SPEC> [--transport TRANSPORT] [--host HOST] [--port PORT] [--base-url URL]
| Option | Default | Description |
|---|---|---|
--spec |
required | URL or local path to OpenAPI spec (JSON) |
--transport |
stdio |
Transport: stdio, sse, streamable-http |
--host |
127.0.0.1 |
Host for SSE/streamable-http |
--port |
8000 |
Port for SSE/streamable-http |
--base-url |
auto | Override base URL for upstream API calls |
Base URL Resolution
Base URL is resolved in this priority order:
OPENAPI_BASE_URLenvironment variable--base-urlCLI flag- Inferred from spec URL (strip last path segment)
servers[0].urlfrom the spec itself
Authentication
Set environment variables to inject auth headers into upstream requests:
# Bearer token (default)
export API_KEY=your-token-here
# API key header
export API_KEY=your-key-here
export API_AUTH_TYPE=api-key
MCP Client Integration
Claude Desktop
Add to your claude_desktop_config.json:
{
"mcpServers": {
"my-api": {
"command": "uvx",
"args": ["oapi2mcp", "--spec", "https://api.example.com/openapi.json"],
"env": {
"API_KEY": "your-token"
}
}
}
}
SSE / Streamable HTTP
# SSE transport
oapi2mcp --spec https://api.example.com/openapi.json --transport sse --port 8000
# Streamable HTTP transport
oapi2mcp --spec https://api.example.com/openapi.json --transport streamable-http --port 8000
Features
- Recursive
$refresolution — handles nested references in components - Collision detection — renames body properties that conflict with path/query/header params
- Fallback
operationId— auto-generates from method + path when missing - Error wrapping — upstream HTTP errors surface as MCP errors with diagnostics
- 3 transports — stdio (default), SSE, and streamable-http
Requirements
- Python >= 3.10
- An OpenAPI 3.x spec in JSON format
Disclaimer
This project was generated with the assistance of AI. While it has been tested, it may contain bugs or unexpected behavior. Use at your own risk. The author assumes no responsibility or liability for any damages or losses arising from the use of this software.
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file oapi2mcp-0.1.0.tar.gz.
File metadata
- Download URL: oapi2mcp-0.1.0.tar.gz
- Upload date:
- Size: 4.3 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b7e978ffcee4f05a18b777aefef8589b4393f282b6aba5308e33ca72bfacf94
|
|
| MD5 |
c0c8c26eaee043a28d7d958ef230b306
|
|
| BLAKE2b-256 |
013ab1eeb89b275d572eba701c84c7ec53fda9fce38b897d4b093f15fb3d6a77
|
File details
Details for the file oapi2mcp-0.1.0-py3-none-any.whl.
File metadata
- Download URL: oapi2mcp-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
503a33d0b2521baf3f9526d3613b3f93b731e9e88fb60f1e6a35ca6b276d986e
|
|
| MD5 |
0588ae6969b66efe855c5e356e8177da
|
|
| BLAKE2b-256 |
6f3e26daa290dbe259265ffd7097ee6c723b57af1417c059fbd7e36853ca56f6
|