Convert OpenAPI specifications to MCP (Model Context Protocol) servers. This tool automatically generates MCP tools from your OpenAPI spec, allowing AI assistants like Claude to interact with your APIs.
- π Automatic Tool Generation - Converts OpenAPI operations to MCP tools
- π Multiple Input Sources - Load specs from local files or URLs
- π Format Support - JSON, YAML, and TOML formats
- π§ Flexible Configuration - Override base URLs, add headers, set timeouts
- π Zero Configuration - Works out of the box with sensible defaults
- π» Easy Integration - Compatible with Claude Desktop, VS Code, and any MCP client
npm install -g @longcipher/openapi-mcpbun add -g @longcipher/openapi-mcpgit clone https://github.com/longcipher/openapi-mcp.git
cd openapi-mcp
bun install
bun run build# From a local file
openapi-mcp ./api.yaml
# From a URL
openapi-mcp https://petstore3.swagger.io/api/v3/openapi.json
# With custom base URL
openapi-mcp ./api.yaml --base-url https://api.example.com/v2
# With authentication header
openapi-mcp ./api.yaml --header "Authorization: Bearer token123"
# With verbose logging
openapi-mcp ./api.yaml --verboseUsage: openapi-mcp [options] <source>
Convert OpenAPI specifications to MCP servers
Arguments:
source OpenAPI spec file path or URL (supports JSON, YAML, TOML)
Options:
-V, --version output the version number
-b, --base-url <url> Override the base URL for API requests
-H, --header <header...> Add custom headers (format: 'Name: Value')
-t, --timeout <ms> Request timeout in milliseconds (default: "30000")
-n, --name <name> Server name (default: "openapi-mcp")
-v, --verbose Enable verbose logging
-h, --help display help for command
Add to your Claude Desktop configuration (~/Library/Application Support/Claude/claude_desktop_config.json on macOS):
{
"mcpServers": {
"petstore": {
"command": "openapi-mcp",
"args": [
"https://petstore3.swagger.io/api/v3/openapi.json"
]
},
"my-api": {
"command": "openapi-mcp",
"args": [
"/path/to/my-api.yaml",
"--base-url", "https://api.myservice.com",
"--header", "Authorization: Bearer ${API_TOKEN}"
],
"env": {
"API_TOKEN": "your-token-here"
}
}
}
}Add to your VS Code settings or .vscode/mcp.json:
{
"mcp": {
"servers": {
"petstore": {
"command": "openapi-mcp",
"args": ["https://petstore3.swagger.io/api/v3/openapi.json"]
}
}
}
}You can run without installing globally:
{
"mcpServers": {
"my-api": {
"command": "npx",
"args": [
"-y",
"@longcipher/openapi-mcp",
"https://example.com/api.yaml"
]
}
}
}- All HTTP methods: GET, POST, PUT, DELETE, PATCH, OPTIONS, HEAD
- Operation IDs are converted to snake_case tool names
- Fallback to
{method}_{path}when operationId is missing
- Path parameters - Automatically substituted in URLs
- Query parameters - Added as URL query string
- Header parameters - Added as request headers
- Request body - Sent as JSON or form data
- Primitive types (string, number, integer, boolean)
- Arrays and objects
- Enums
- Format hints (email, date-time, etc.)
- Required field validation
openapi-mcp examples/petstore.yamlThis exposes tools like:
add_pet- Add a new pet to the storefind_pets_by_status- Find pets by their statusget_pet_by_id- Get a pet by its IDdelete_pet- Delete a pet
openapi-mcp examples/httpbin.jsonThis exposes tools like:
http_get- Make a GET requesthttp_post- Make a POST requestget_ip- Get your IP addressget_uuid- Generate a UUID
- Bun v1.0 or later
# Clone the repository
git clone https://github.com/longcipher/openapi-mcp.git
cd openapi-mcp
# Install dependencies
bun install
# Build
bun run build
# Run tests
bun test
# Lint & format
bun run lint
bun run formatopenapi-mcp/
βββ src/
β βββ index.ts # Main entry point
β βββ cli.ts # CLI implementation
β βββ logger.ts # Logging utilities
β βββ errors.ts # Error definitions
β βββ loader/ # Spec loading module
β β βββ types.ts # OpenAPI type definitions
β β βββ parser.ts # Format detection & parsing
β β βββ file-loader.ts # Local file loading
β β βββ url-loader.ts # URL loading
β β βββ index.ts # Module exports
β βββ adapter/ # OpenAPI to MCP adapter
β β βββ types.ts # MCP type definitions
β β βββ openapi-adapter.ts
β β βββ index.ts
β βββ server/ # MCP server implementation
β βββ mcp-server.ts
β βββ index.ts
βββ tests/ # Test files
βββ examples/ # Example OpenAPI specs
βββ docs/ # Documentation
- Load - Reads OpenAPI spec from file or URL
- Parse - Detects format (JSON/YAML/TOML) and validates the spec
- Convert - Transforms OpenAPI operations into MCP tool definitions
- Serve - Starts an MCP server over STDIO transport
- Execute - When a tool is called, makes the actual HTTP request
"Tool not found" error
- Check that the operationId matches (converted to snake_case)
- Run with
--verboseto see available tools
Connection timeouts
- Increase timeout with
--timeout 60000(60 seconds) - Check network connectivity to the API
Authentication errors
- Add auth headers with
--header "Authorization: Bearer token" - Ensure the token is valid and not expired
Invalid spec error
- Ensure the spec is valid OpenAPI 3.0.x
- Check for syntax errors in YAML/JSON/TOML
Run with verbose logging to see detailed information:
openapi-mcp ./api.yaml --verboseContributions are welcome! Please feel free to submit a Pull Request.
Apache License 2.0 - see LICENSE for details.