Converts OpenAPI specifications into MCP tools, enabling AI clients to interact with external APIs seamlessly.
OpenAPI2MCP that allows AI clients to call any OpenAPI-compatible REST API through the MCP interface. This tool converts OpenAPI specifications into MCP tools, enabling AI clients to interact with external APIs seamlessly.
git clone https://github.com/oil-oil/openapi2mcp.git
cd openapi2mcp
pnpm install
pnpm run build
Configure your MCP client by adding the following to your configuration file:
{
"mcpServers": {
"openapi2mcp": {
"command": "npx",
"args": ["-y", "openapi2mcp"],
"env": {
"TRANSPORT_TYPE": "stdio",
"API_BASE_URL": "https://petstore3.swagger.io/api/v3",
"OPENAPI_SPEC_URL": "https://petstore3.swagger.io/api/v3/openapi.json",
"HEADER.Authorization": "Bearer your-token-here",
"HEADER.Content-Type": "application/json"
}
}
}
}
First, start the SSE server:
pnpm start:sse
Then configure your MCP client:
{
"mcpServers": {
"openapi2mcp": {
"url": "http://localhost:3000/sse?base_url=https://petstore3.swagger.io/api/v3&openapi_spec=https://petstore3.swagger.io/api/v3/openapi.json&headers.Content-Type=application%2Fjson&message_path=/custom/message"
}
}
}
Available SSE Parameters:
base_url
- API base URL (required)openapi_spec
- OpenAPI specification URL (required)message_path
- Custom message endpoint path (optional, default: /message
)headers.*
- Custom headers (optional)merge_api
- Enable API merging (optional, default: false
)cache_enabled
, cache_ttl
, etc.Once configured, you can test your setup by asking your AI client:
Some AI clients (like Cursor) have limitations on the number of MCP tools they can handle effectively. The API merging feature intelligently combines related API endpoints into unified tools, significantly reducing the total number of tools while maintaining full functionality.
When enabled, the OpenAPI2MCP groups API endpoints by resource path and merges them into comprehensive tools. For example, instead of having separate tools for each HTTP method, you get a single tool that handles multiple operations through an object-based parameter structure.
Without Merging (8 individual tools):
get_pet_petId
- GET /pet/{petId}post_pet_petId
- POST /pet/{petId}delete_pet_petId
- DELETE /pet/{petId}get_pet_findByStatus
- GET /pet/findByStatusget_pet_findByTags
- GET /pet/findByTagspost_pet
- POST /petput_pet
- PUT /petpost_pet_petId_uploadImage
- POST /pet/{petId}/uploadImageWith Merging Enabled (3 unified tools):
pet_operations
- Handles /pet
operations:
{
"operation": {
"get": { "status": "available" },
"post": { "body": { "name": "doggie", "photoUrls": ["url1"] } },
"put": { "body": { "id": 1, "name": "doggie" } }
}
}
pet_item_operations
- Handles /pet/{petId}
operations:
{
"operation": {
"get": { "petId": "1" },
"post": { "petId": "1", "name": "doggie" },
"delete": { "petId": "1" }
}
}
pet_item_uploadImage_operations
- Handles /pet/{petId}/uploadImage
:
{
"operation": {
"post": { "petId": "1", "body": { "additionalMetadata": "test" } }
}
}
The OpenAPI caching feature provides efficient caching for parsed OpenAPI specifications and generated tools in SSE mode, significantly improving performance by avoiding repeated parsing and tool generation when connecting to the same API.
First connection (cache miss):
[Fresh] Loaded OpenAPI 3.0: Swagger Petstore v1.0.17
[Fresh] Found 19 API endpoints
[Cache] Cached OpenAPI spec: https://petstore3.swagger.io/api/v3/openapi.json (expires in 3600s)
Subsequent connections (cache hit):
[Cache] Cache hit for OpenAPI spec: https://petstore3.swagger.io/api/v3/openapi.json
[Cache] Using cached OpenAPI 3.0: Swagger Petstore v1.0.17
[Cache] Found 19 API endpoints, 19 tools
You can monitor cache performance through the health endpoint:
curl http://localhost:3000/health
Variable | Description | Default | Required |
---|---|---|---|
TRANSPORT_TYPE | Transport mode: stdio , http , sse | stdio | No |
SSE_PORT | Port for HTTP/SSE server | 3000 | No |
API_BASE_URL | Base URL for API requests | - | No** |
OPENAPI_SPEC_URL | URL to fetch OpenAPI spec | - | Yes* |
OPENAPI_SPEC_PATH | Local path to OpenAPI spec file | - | Yes* |
*Either OPENAPI_SPEC_URL
or OPENAPI_SPEC_PATH
is required.
**API_BASE_URL
is optional when OpenAPI specification contains servers
field. The first server URL will be used automatically.
Variable | Description | Default | Required |
---|---|---|---|
VERIFY_SSL | Enable SSL certificate verification | true | No |
TIMEOUT | Request timeout in milliseconds | 30000 | No |
HEADER.* | Custom headers | - | No |
HEADERS | JSON string of headers (legacy) | - | No |
Variable | Description | Default | Required |
---|---|---|---|
MERGE_API | Enable API merging to reduce tool count | false | No |
Variable | Description | Default | Required |
---|---|---|---|
CACHE_ENABLED | Enable OpenAPI specification caching | true | No |
CACHE_TTL | Cache time-to-live in seconds | 3600 | No |
CACHE_MAX_SIZE | Maximum number of cached entries | 200 | No |
CACHE_CHECK_INTERVAL | Cache cleanup interval in seconds | 300 | No |
{
"mcpServers": {
"openapi2mcp": {
"command": "npx",
"args": ["-y", "openapi2mcp"],
"env": {
"TRANSPORT_TYPE": "stdio",
"API_BASE_URL": "https://petstore3.swagger.io/api/v3",
"OPENAPI_SPEC_URL": "https://petstore3.swagger.io/api/v3/openapi.json",
"HEADER.Authorization": "Bearer your-token-here",
"HEADER.Content-Type": "application/json",
"HEADER.X-API-Key": "your-api-key"
}
}
}
}
http://localhost:3000/sse?base_url=https://petstore3.swagger.io/api/v3&openapi_spec=https://petstore3.swagger.io/api/v3/openapi.json&headers.Authorization=Bearer%20your-token&headers.Content-Type=application%2Fjson
Note: Headers in URL parameters must be URL encoded (spaces: %20, slashes: %2F)
{
"mcpServers": {
"openapi2mcp": {
"command": "npx",
"args": ["-y", "openapi2mcp"],
"env": {
"TRANSPORT_TYPE": "stdio",
"API_BASE_URL": "https://petstore3.swagger.io/api/v3",
"OPENAPI_SPEC_URL": "https://petstore3.swagger.io/api/v3/openapi.json",
"HEADERS": "{\"Authorization\":\"Bearer your-token\",\"Content-Type\":\"application/json\"}"
}
}
}
}
pnpm run dev
# Run tests
pnpm test
# Build project
pnpm run build
# Build image
docker build -t openapi2mcp .
# Run with environment variables
docker run -e TRANSPORT_TYPE=http \
-e API_BASE_URL=https://petstore3.swagger.io/api/v3 \
-e OPENAPI_SPEC_URL=https://petstore3.swagger.io/api/v3/openapi.json \
-e HEADER.Authorization="Bearer token" \
-p 3000:3000 \
openapi2mcp
An interactive task loop server for Cursor IDE, designed to perform task-based operations for modern web application development.
Generate mermaid diagram and chart with AI MCP dynamically.
A secure MCP server for executing terminal commands with controlled directory access and command permissions.
Control emulators by opening/closing apps, capturing screenshots, and interacting with the screen.
A service framework supporting the Model Context Protocol (MCP) to integrate enterprise systems and AI platforms via RESTful, gRPC, and Dubbo protocols.
A starter project for building Model Context Protocol (MCP) servers with the mcp-framework.
A collection of demo files for MCP servers and clients, illustrating various transport protocols and server capabilities using Python.
A TypeScript boilerplate for building MCP servers with streamable HTTP and OAuth proxy support.
Server for advanced AI-driven video editing, semantic search, multilingual transcription, generative media, voice cloning, and content moderation.
Query A/B test data using the Hackle API.