OpenAPI MCP Server
Dynamically exposes any OpenAPI/Swagger API as tools for AI assistants, automatically generating MCP tools from OpenAPI specs with authentication support.
README
OpenAPI MCP Server
A Model Context Protocol (MCP) server that dynamically exposes OpenAPI/Swagger APIs as tools for AI assistants.
Overview
This MCP server automatically generates tools from OpenAPI specifications, allowing AI assistants to interact with any API that has an OpenAPI/Swagger definition. Each API endpoint becomes a callable tool with proper parameter handling and authentication support.
Features
- Dynamic Tool Generation: Automatically creates MCP tools from OpenAPI operations
- Multiple Authentication Methods: Supports Bearer tokens, custom headers, and API keys
- Flexible Spec Loading: Load OpenAPI specs from local files or URLs
- Full HTTP Method Support: GET, POST, PUT, DELETE, PATCH operations
- Parameter Handling: Supports path, query, header parameters and request bodies
- Error Handling: Comprehensive error reporting and logging
Installation
- Clone this repository
- Create a virtual environment (recommended):
python -m venv myenv source myenv/bin/activate # On Windows: myenv\Scripts\activate - Install dependencies:
pip install -r requirements.txt
Why Use a Virtual Environment?
Using a virtual environment is strongly recommended because:
- Isolation: Keeps project dependencies separate from system Python packages
- Version Control: Ensures consistent package versions across different machines
- Clean Development: Prevents conflicts between different projects' dependencies
- Easy Cleanup: Simply delete the virtual environment folder to remove all packages
Virtual Environment Commands
Creating and activating:
# Create virtual environment
python -m venv myenv
# Activate on macOS/Linux
source myenv/bin/activate
# Activate on Windows
myenv\Scripts\activate
# Activate on Windows (PowerShell)
myenv\Scripts\Activate.ps1
Deactivating:
deactivate
Verifying activation:
# Check if virtual environment is active
which python # On macOS/Linux
where python # On Windows
# Should show path to your virtual environment's Python
Usage
Basic Usage
Run the server with a local OpenAPI spec file:
python openapi-mcp-server.py petstore.yaml
Or using environment variables:
export OPENAPI_SPEC_PATH=petstore.yaml
python openapi-mcp-server.py
Configuration
The server can be configured using environment variables:
OPENAPI_SPEC_PATH: Path or URL to the OpenAPI specificationOPENAPI_BASE_URL: Override the base URL from the spec (optional)API_KEY: Bearer token for API authentication (optional)
Authentication
The server supports multiple authentication methods:
- Bearer Token: Set via
API_KEYenvironment variable - Custom Headers: Pass auth parameters in tool calls:
_auth_profileId: For X-IHR-Profile-ID header_auth_sessionId: For X-IHR-Session-ID header_auth_token: For Authorization Bearer token
MCP Integration
To use this server with an MCP client, add it to your MCP configuration:
{
"mcpServers": {
"openapi": {
"command": "python",
"args": ["/path/to/openapi-mcp-server.py"],
"env": {
"OPENAPI_SPEC_PATH": "/path/to/your-api-spec.yaml",
"OPENAPI_BASE_URL": "https://api.example.com",
"API_KEY": "your-api-key"
}
}
}
}
How It Works
- Spec Loading: The server loads and parses the OpenAPI specification
- Tool Generation: Each API operation becomes an MCP tool with:
- Name from
operationId - Description from operation
descriptionorsummary - Input schema generated from parameters and request body
- Name from
- Tool Execution: When a tool is called:
- Path parameters are substituted
- Query parameters are added to the URL
- Headers are set (including auth)
- Request body is sent as JSON
- Response is returned as formatted JSON
Example Tools
For a typical OpenAPI spec, the server might generate tools like:
getPetById: Fetch a pet by IDaddPet: Add a new pet to the storeupdatePet: Update an existing petdeletePet: Delete a pet
Each tool will have appropriate parameters based on the API definition.
Development
Testing
The repository includes several utility scripts:
test-mcp-server.py: Test the MCP server functionalityinspect-mcp-api.py: Inspect available MCP APIscheck-mcp-install.py: Verify MCP installationmcp-openapi-generator-python.py: Generate Python code from OpenAPI specs
Logging
The server includes comprehensive logging. Set the log level via the standard Python logging configuration.
Requirements
- Python 3.7+
- Dependencies listed in
requirements.txt:- mcp>=0.1.0
- httpx>=0.25.0
- pyyaml>=6.0
- pydantic>=2.0.0
License
[Specify your license here]
Contributing
[Add contribution guidelines if applicable]
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。