A tool to convert OpenAPI specs to MCP server with tools
Project description
OpenAPI2MCP
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):
- It parses OpenAPI specifications to extract API endpoints
- Converts these endpoints into MCP tools with appropriate parameters
- Creates an MCP server that exposes these tools
- Handles authentication with the API
- 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.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Install development dependencies (
pip install -e ".[dev]") - Make your changes
- Run tests (
pytest) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
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 openapi2mcp-0.1.0.tar.gz.
File metadata
- Download URL: openapi2mcp-0.1.0.tar.gz
- Upload date:
- Size: 16.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ac272f5b46a9622b7ba9110a68ee2e34f060d289817b9e6481241a0770e9f79
|
|
| MD5 |
9251c22e17da2fd1b3ee3d4ccc3b9f7b
|
|
| BLAKE2b-256 |
ea1d6930b4a1684f3634fa62c5f93573509e841a802d6750e4a393c490a02ac4
|
File details
Details for the file openapi2mcp-0.1.0-py3-none-any.whl.
File metadata
- Download URL: openapi2mcp-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
77c4531f93e491b1d7795df9c0004918682a8d92d4e886f2d574c74766017500
|
|
| MD5 |
3389c412910de8289ce1651611cdd831
|
|
| BLAKE2b-256 |
a411e58f8c7a0bc7e5675c084bac8464c3453f53ad11e56e6d962a19ced9cd14
|