Skip to main content

OpenAPI2MCP

License: MIT Python Versions

OpenAPI2MCP is a Python tool that serves as a Model Context Protocol (MCP) server with tools generated from OpenAPI specification files (JSON or YAML). It allows LLMs and AI applications that support MCP to interact with any API that has an OpenAPI specification.

Features

  • 🔄 Convert OpenAPI specifications to MCP tools
  • 🛠️ Serve MCP endpoints with tools from OpenAPI specs
  • 🔐 OAuth authentication support for API calls
  • 📡 Server-Sent Events (SSE) support for real-time communication
  • 💻 Command-line interface for easy usage
  • 🧩 Programmatic API for integration into other applications

Installation

pip install openapi2mcp

Quick Start

Convert an OpenAPI spec to MCP tools:

openapi2mcp convert --spec-file openapi.yaml --output tools.json

Start an MCP server with tools from an OpenAPI spec:

openapi2mcp serve --spec-file openapi.yaml --port 8000

Use environment variables for OAuth authentication:

API_CLIENT_ID=your_client_id
API_CLIENT_SECRET=your_client_secret
API_TOKEN_URL=https://example.com/oauth/token

Documentation

Examples

The examples directory contains sample code to help you get started:

How It Works

OpenAPI2MCP bridges the gap between APIs defined with OpenAPI specifications and AI systems that support the Model Context Protocol (MCP):

  1. It parses OpenAPI specifications to extract API endpoints
  2. Converts these endpoints into MCP tools with appropriate parameters
  3. Creates an MCP server that exposes these tools
  4. Handles authentication with the API
  5. Executes tool calls by making appropriate API requests

This allows AI models and applications to interact with any API through the standardized MCP interface.

+---------------------+     +---------------------+     +---------------------+
|                     |     |                     |     |                     |
|   OpenAPI Spec      |     |   OpenAPI2MCP       |     |   MCP-Compatible    |
|   (JSON/YAML)       +---->+   Server            +---->+   LLM/Client        |
|                     |     |                     |     |                     |
+---------------------+     +---------------------+     +---------------------+
                             |        ^
                             |        |
                             v        |
+---------------------+     +---------------------+
|                     |     |                     |
|   OAuth             |     |   API Endpoint      |
|   Authentication    +---->+   (e.g. GitHub API) |
|                     |     |                     |
+---------------------+     +---------------------+

Why Use OpenAPI2MCP?

  • Universal API Access: Connect any OpenAPI-defined API to MCP-compatible LLMs
  • Tool Discovery: LLMs can dynamically discover what capabilities are available
  • Authentication Handling: Securely manage API credentials
  • Standard Interface: Consistent way to interact with diverse APIs
  • Easy Integration: Simple setup process for both local and production use

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Install development dependencies (pip install -e ".[dev]")
  4. Make your changes
  5. Run tests (pytest)
  6. Commit your changes (git commit -m 'Add some amazing feature')
  7. Push to the branch (git push origin feature/amazing-feature)
  8. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Metadata

Release files for openapi2mcp 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 openapi2mcp 0.1.1
File Size Uploaded Provenance
openapi2mcp-0.1.1.tar.gz 20.3 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 37.7 kB

Release files / openapi2mcp-0.1.1.tar.gz

Download URL openapi2mcp-0.1.1.tar.gz
Size 20.3 kB
Tags Source
SHA-256 checksum
How to use checksums
f340696101bb962944f42aef7e68514aa7f36ec7e70d27777e016e410d159588
BLAKE2b-256 checksum
How to use checksums
f2f0776b03bfce19d3c781fa3c450d0c3d59226882a8caa8feb969c19d87ba41
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.9

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

Download URL openapi2mcp-0.1.1-py3-none-any.whl
Size 17.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b1a6a75e1106b9fa35d16aab6d06841ab7d9f170f5a5e9a77fc38572ecba3cd1
BLAKE2b-256 checksum
How to use checksums
b570b933c54ae9e34bb70c5c0cca3679bad5642d61a5988ea2946389fd906e63
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.9

Security for openapi2mcp 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