Skip to main content

oapi2mcp

Convert any OpenAPI 3.x specification into a working MCP (Model Context Protocol) server — zero configuration, zero code.

PyPI Python License: MIT

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

  1. Parses your OpenAPI 3.x spec (local file or remote URL)
  2. Resolves all $ref references recursively
  3. Converts every operation into an MCP tool with a proper inputSchema
  4. Serves tools over stdio, SSE, or streamable-http
  5. 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:

  1. OPENAPI_BASE_URL environment variable
  2. --base-url CLI flag
  3. Inferred from spec URL (strip last path segment)
  4. servers[0].url from 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 $ref resolution — 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

MIT

Metadata

Release files for oapi2mcp 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for oapi2mcp 0.1.1
File Size Uploaded Provenance Actions
oapi2mcp-0.1.1.tar.gz 4.3 MB Without provenance Details for oapi2mcp-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for oapi2mcp 0.1.1
File Interpreter ABI Platform Actions
oapi2mcp-0.1.1-py3-none-any.whl Python 3 none any Details for oapi2mcp-0.1.1-py3-none-any.whl

Total release size: 4.3 MB

Release files / oapi2mcp-0.1.1.tar.gz

Download URL oapi2mcp-0.1.1.tar.gz
Size 4.3 MB
Tags Source
SHA-256 checksum
How to use checksums
13916565e04dfa8affb14a4cda8a9d8034cef8f9c04c8d0599cdf995dff0c2e3
BLAKE2b-256 checksum
How to use checksums
ee2bca821f043f033b3459420ff3e67cd5647d6ad00da0d23a25ac4f9d9632b4
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / oapi2mcp-0.1.1-py3-none-any.whl

Download URL oapi2mcp-0.1.1-py3-none-any.whl
Size 8.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0e8a1a34e24f727f0741b0ead8a9218e8670ab8b224b4a70e32a754477a0dba2
BLAKE2b-256 checksum
How to use checksums
123e48c125f15bb9af79d2dd54bdf10e8adb8f2f645c13a89cb61b25977a09ef
Upload date
Uploaded using Trusted Publishing?
What is 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}

Security for oapi2mcp 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page