Skip to main content

openapi-to-mcp

Convert any OpenAPI 3.x spec file into a live, working MCP (Model Context Protocol) server that AI agents can connect to and use as tools.

What it does

This CLI tool parses an OpenAPI 3.x specification and generates a standalone Python script acting as an MCP server. This allows AI assistants (like Claude, Cursor, or Copilot) to understand and interact with your existing REST APIs by converting your OpenAPI endpoints into MCP tools.

How it works

  1. Parse: Reads your OpenAPI specification (YAML or JSON).
  2. Generate: Uses Jinja2 templates to construct a complete, standalone Python file containing the MCP server logic.
  3. Run: Provides an option to immediately start the generated MCP server using the stdio or sse transport.

Installation

pip install mcp-from-openapi

For development:

git clone https://github.com/vinayakrastogi/openAPI-to-MCP-converter.git
cd openAPI-to-MCP-converter
pip install -e .

Commands

1. Inspect endpoints in a spec (dry-run)

Prints a table of all discovered endpoints, their tool names, and parameters without generating any files.

openapi-to-mcp inspect --spec examples/math_api.yaml

2. Generate a standalone MCP server

Outputs a ready-to-run Python file (e.g., output/math_api_mcp_server.py).

openapi-to-mcp generate \
  --spec examples/math_api.yaml \
  --base-url http://127.0.0.1:8000

3. Generate and immediately run

Creates the MCP server file and starts it immediately.

openapi-to-mcp run \
  --spec examples/math_api.yaml \
  --base-url http://127.0.0.1:8000

4. Run with Authentication

Injects authentication headers into every request made by the MCP server.

# Bearer token style:
openapi-to-mcp run \
  --spec examples/pet_api.yaml \
  --base-url https://api.example.com \
  --auth-header "Authorization: Bearer mytoken"

# API key style:
openapi-to-mcp run \
  --spec examples/pet_api.yaml \
  --base-url https://api.example.com \
  --auth-header "X-Api-Key: abc123"

CLI Reference

openapi-to-mcp <command> [options]

Commands:
  inspect   Parse a spec and display endpoints (dry-run, no files written)
  generate  Parse a spec and write a standalone MCP server file
  run       Generate AND immediately start the MCP server

Common Options:
  --spec,       -s  FILE    Path to the OpenAPI YAML or JSON spec file [required]
  --base-url,   -u  URL     Base URL of the live API (overrides servers[0].url)
  --auth-header,-a  HEADER  Auth header injected into every request
  --transport,  -t          MCP transport: stdio (default) or sse
  --name,       -n  NAME    Server name (defaults to spec info.title)
  --output,     -o  FILE    Output path for the generated server file

Connecting to AI Agents

Claude Desktop

Add the following to ~/Library/Application Support/Claude/claude_desktop_config.json:

{
  "mcpServers": {
    "my-api": {
      "command": "python",
      "args": ["/absolute/path/to/output/math_api_mcp_server.py"]
    }
  }
}

Cursor / VS Code (Copilot MCP)

Add the following to .cursor/mcp.json or your workspace MCP config:

{
  "servers": {
    "my-api": {
      "type": "stdio",
      "command": "python",
      "args": ["/absolute/path/to/output/math_api_mcp_server.py"]
    }
  }
}

Supported OpenAPI Features

Feature Status
OpenAPI 3.x (YAML & JSON) Supported
Path parameters (in: path) Supported
Query parameters (in: query) Supported
Request bodies (application/json) Supported
$ref schema resolution Supported
operationId as tool name Supported
Fallback tool name from method + path Supported
Auth header injection Supported
servers[0].url as base URL Supported
stdio transport Supported
SSE transport Supported
Header parameters Parsed, not injected (use --auth-header)
OAuth flows Not Supported (v2 roadmap)
multipart/form-data bodies Not Supported (v2 roadmap)

Metadata

Release files for mcp-from-openapi 0.1.0

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

Source distribution (sdist)

Source distribution for mcp-from-openapi 0.1.0
File Size Uploaded Provenance
mcp_from_openapi-0.1.0.tar.gz 13.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for mcp-from-openapi 0.1.0
File Interpreter ABI Platform
mcp_from_openapi-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 29.3 kB

Release files / mcp_from_openapi-0.1.0.tar.gz

Download URL mcp_from_openapi-0.1.0.tar.gz
Size 13.6 kB
Tags Source
SHA-256 checksum
How to use checksums
b5c74989062f50ee547e40c4347bc7411af83511c6e02131984ab88b0617e910
BLAKE2b-256 checksum
How to use checksums
6751ab729721a79a108b67a2a8cfc00d513a68354b33ac5e987cd63dcc33990b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.5

Release files / mcp_from_openapi-0.1.0-py3-none-any.whl

Download URL mcp_from_openapi-0.1.0-py3-none-any.whl
Size 15.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b27aa1c989fc0c375dfd0bfaf1dab596f46fcfb4eb4a952fbf682b757fee0384
BLAKE2b-256 checksum
How to use checksums
710c008ea8ebd13d455430d70f58ba99cd1f9e6ca446b360415d41df2f3eeeca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.5

Security for mcp-from-openapi 0.1.0

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.0 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