Skip to main content

A Model Context Protocol bridge to OpenAPI servers

Project description

MCP-OpenAPI

A Model Context Protocol server that exposes HTTP methods from an OpenAPI spec as tools.

[!WARNING] This is a proof of concept, yet to be fully tested and documented.

Usage

Each MCP-OpenAPI server exposes operations from a single OpenAPI spec. You could run multiple instances to expose multiple specs.

This package is available on PyPI @ [mcp-openapi][pypi]. You can start a server with uvx mcp-openapi --openapi-url https://httpbin.org/spec.json (sse | stdio).

An example Claude config (while running fastapi dev tests/todos.py with port 8000):

{
  "mcpServers": {
    "todos": {
    "command": "uvx",
    "args": [
        "mcp-openapi",
        "--openapi-url=http://localhost:8000/openapi.json",
        "stdio"
      ]
    }
  }
}

The OpenAPI url can also be passed as an environment variable, MCP_OPENAPI_URL.

When running as SSE, you can configure the server with:

  • --fastmcp-sse-host - the host to serve the MCP server on
  • --fastmcp-sse-port - the port to serve the MCP server on

There are additional global options:

  • --fastmcp-debug - enable debug mode for the MCP server
  • --fastmcp-log-level - the log level for the MCP server

These can also be configured via environment variables using the FASTMCP_ prefix, e.g. FASTMCP_LOG_LEVEL=DEBUG.

How it works

  1. The MCP-OpenAPI server is initialised with an OpenAPI spec URL.
  2. The server fetches and parses the OpenAPI spec, and registers each path-operation as a tool.
  3. A FastMCP server is started with the registered tools.
  4. When a client requests a tool, the MCP server makes a HTTP request to the API and returns the response.

Supported OpenAPI/Swagger versions

Swagger 2.0 OpenAPI 3.0 OpenAPI 3.1
:x: :heavy_check_mark: :heavy_check_mark:

This package supports OpenAPI 3.0 and 3.1 specs, in JSON and YAML formats.

We're using openapi-parser under the hood, which seems to be pretty comprehensive, and supports resolving references to external specs.

Future configuration options

[!INFO] These are still to be implemented.

Restricting endpoints

By default, all endpoints are exposed as tools. You can restrict which endpoints are exposed:

  • By path patterns,
  • By HTTP method,
  • Explicitly listing the individual operations to expose,
  • Selecting routes using OpenAPI tags.

Handling API authentication

MCP-OpenAPI makes API requests to the target API - it can use a global auth token:

  • --auth-token - a bearer token, or basic credentials in base64 format, used depending on the OpenAPI spec.

It would be nice to be able to make requests using varying authentication tokens (e.g. per client user), but without having the LLM see the tokens. TBD.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_openapi-0.0.2.tar.gz (63.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_openapi-0.0.2-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file mcp_openapi-0.0.2.tar.gz.

File metadata

  • Download URL: mcp_openapi-0.0.2.tar.gz
  • Upload date:
  • Size: 63.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for mcp_openapi-0.0.2.tar.gz
Algorithm Hash digest
SHA256 2aa47237e62df243e647b92c839adad3c5c2838f77ea043953f285c8e76d0e54
MD5 e146a4229a4477b5fcb6baf82862df23
BLAKE2b-256 09796a80c298e62d3325a8fe2a0759c031e5f9736cf1a2182ae635c12c2a2501

See more details on using hashes here.

Provenance

The following attestation bundles were made for mcp_openapi-0.0.2.tar.gz:

Publisher: release.yml on rmasters/mcp-openapi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mcp_openapi-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: mcp_openapi-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for mcp_openapi-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3974b70774b4f89eb410600416b6f715666f8cb52b40ca20cf06fbe81485c134
MD5 a06e704c2f6f5bf720ddfd3d6c180e20
BLAKE2b-256 e3831468897f04a3c820b029b29a0b4f39af610773297dd350fbc25fbc43ea2b

See more details on using hashes here.

Provenance

The following attestation bundles were made for mcp_openapi-0.0.2-py3-none-any.whl:

Publisher: release.yml on rmasters/mcp-openapi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page