OpenAPI-MCP is a dockerized server that transforms standard OpenAPI/Swagger specifications into Model Context Protocol (MCP) toolsets. This enables AI agents to interact with any API that has OpenAPI documentation without requiring custom code - simply provide the API specification and your agent can access the API through the MCP interface.
The easiest way to run OpenAPI-MCP is using the pre-built Docker image:
docker pull ckanthony/openapi-mcp:latest
Then run the container with your API specification:
docker run -p 8080:8080 --rm \
-e API_KEY="your_actual_key" \
ckanthony/openapi-mcp:latest \
--spec https://petstore.swagger.io/v2/swagger.json \
--api-key-env API_KEY \
--api-key-name api_key \
--api-key-loc header
If you have a local OpenAPI specification file:
.env
file with your API key in the same directorydocker run -p 8080:8080 --rm \
-v $(pwd)/my-api:/app/spec \
--env-file $(pwd)/my-api/.env \
ckanthony/openapi-mcp:latest \
--spec /app/spec/openapi.json \
--api-key-env API_KEY \
--api-key-name X-API-Key \
--api-key-loc header
Here's a step-by-step example using the Weatherbit API:
Get a Weatherbit API key from Weatherbit.io
Create an environment file for your API key:
# Create a directory and .env file
mkdir -p weatherbit
echo "API_KEY=your_weatherbit_api_key" > weatherbit/.env
Download the Weatherbit OpenAPI specification:
curl -o weatherbit/weatherbitio-swagger.json https://raw.githubusercontent.com/ckanthony/openapi-mcp/main/example/weather/weatherbitio-swagger.json
Run the OpenAPI-MCP container:
docker run -p 8080:8080 --rm \
-v $(pwd)/weatherbit:/app/spec \
--env-file $(pwd)/weatherbit/.env \
ckanthony/openapi-mcp:latest \
--spec /app/spec/weatherbitio-swagger.json \
--api-key-env API_KEY \
--api-key-name key \
--api-key-loc query
Your MCP server is now running at http://localhost:8080
and ready to be used with compatible MCP clients like Cursor.
Flag | Description | Default |
---|---|---|
--spec |
Required. Path or URL to OpenAPI specification | none |
--port |
Port to run the MCP server on | 8080 |
--api-key-env |
Environment variable containing the API key | none |
--api-key-name |
Name of the API key parameter | none |
--api-key-loc |
Location of API key: header , query , path , or cookie |
none |
--include-tag |
Tag to include (can be repeated) | none |
--exclude-tag |
Tag to exclude (can be repeated) | none |
--include-op |
Operation ID to include (can be repeated) | none |
--exclude-op |
Operation ID to exclude (can be repeated) | none |
--base-url |
Override the target API server base URL | none |
You can set custom headers for all API requests by setting the REQUEST_HEADERS
environment variable:
docker run -p 8080:8080 --rm \
-e API_KEY="your_key" \
-e REQUEST_HEADERS='{"X-Custom": "Value"}' \
ckanthony/openapi-mcp:latest \
--spec https://api.example.com/openapi.json \
--api-key-env API_KEY \
--api-key-name api_key \
--api-key-loc header
You can include or exclude specific operations:
docker run -p 8080:8080 --rm \
-e API_KEY="your_key" \
ckanthony/openapi-mcp:latest \
--spec https://api.example.com/openapi.json \
--api-key-env API_KEY \
--api-key-name api_key \
--api-key-loc header \
--include-tag weather \
--exclude-op getForecastDaily
This will only expose operations with the "weather" tag, except for the "getForecastDaily" operation.
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "openapi-mcp" '{"command":"docker","args":["run","--rm","-p","8080:8080","ckanthony/openapi-mcp:latest","--spec","https://petstore.swagger.io/v2/swagger.json"]}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"openapi-mcp": {
"command": "docker",
"args": [
"run",
"--rm",
"-p",
"8080:8080",
"ckanthony/openapi-mcp:latest",
"--spec",
"https://petstore.swagger.io/v2/swagger.json"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"openapi-mcp": {
"command": "docker",
"args": [
"run",
"--rm",
"-p",
"8080:8080",
"ckanthony/openapi-mcp:latest",
"--spec",
"https://petstore.swagger.io/v2/swagger.json"
]
}
}
}
3. Restart Claude Desktop for the changes to take effect