MCP Swagger CLI is a command-line tool that generates runnable MCP servers from Swagger/OpenAPI specifications. It maps API operations to MCP Tools, schemas to MCP Resources, and provides a complete, ready-to-use MCP server implementation.
- Parse OpenAPI 3.x and Swagger 2.0 specifications
- Generate MCP Tools from API operations (GET, POST, PUT, DELETE, etc.)
- Generate MCP Resources from API schemas
- Multiple transport support: stdio and SSE/HTTP
- Automatic type conversion from JSON Schema to Python types
- CLI with progress feedback and validation
pip install mcp-swagger-cliuv pip install mcp-swagger-cligit clone https://github.com/mcp-swagger/mcp-swagger-cli.git
cd mcp-swagger-cli
pip install -e .Generate an MCP server from a Swagger/OpenAPI specification:
mcp-swagger create https://petstore.swagger.io/v2/swagger.json -o ./my_mcp_servermcp-swagger create ./api_spec.yaml \
--output ./my_server \
--name my_api \
--transport stdio \
--base-url https://api.example.com \
--api-key-env MY_API_KEY \
--api-key-header Authorization \
--api-key-prefix BearerBefore generating, validate your OpenAPI spec:
mcp-swagger validate-spec https://petstore.swagger.io/v2/swagger.jsonDisplay information about a specification without generating:
mcp-swagger info https://petstore.swagger.io/v2/swagger.jsonCreate an MCP server from a Swagger/OpenAPI specification.
Usage: mcp-swagger create <spec> [OPTIONS]
Arguments:
spec URL or file path to Swagger/OpenAPI specification
Options:
-o, --output PATH Output directory for generated MCP server
-n, --name TEXT Name for the generated MCP server
-t, --transport TEXT Transport type (stdio or sse)
-b, --base-url TEXT Base URL for API requests
--validate / --no-validate Validate specification before generating
-f, --force Overwrite output directory if it exists
-v, --verbose Enable verbose output
--api-key-env TEXT Environment variable name to read API key from at runtime
--api-key-header TEXT HTTP header name for API key (default: Authorization)
--api-key-prefix TEXT Prefix for API key in header (e.g., 'Bearer', 'Token', 'Bot', or empty)
-H, --header TEXT Custom HTTP header as 'Name: Value' (repeatable)
-T, --tag TEXT Filter operations by tag (repeatable)
--path-filter TEXT Filter operations by path substring (repeatable)
--max-operations INT Warn and abort if filtered operation count exceeds this number
--help Show this message and exit.
Large APIs like Stripe or Discord can generate unmanageably large servers. Use --path-filter or --tag to scope generation:
# Filter by path substring (Discord guild endpoints only)
mcp-swagger create ./discord.json -o ./server --path-filter /guilds --path-filter /channels
# Filter by tag
mcp-swagger create ./api.json -o ./server --tag payments --tag customers
# Abort if too many operations
mcp-swagger create ./api.json -o ./server --max-operations 50Note: Some APIs (e.g. Stripe) use a single
defaulttag for all operations. Use--path-filterinstead of--tagfor these.
Validate a Swagger/OpenAPI specification.
Usage: mcp-swagger validate-spec <spec> [OPTIONS]
Arguments:
spec URL or file path to Swagger/OpenAPI specification
Options:
-v, --verbose Show detailed validation results
--help Show this message and exit.
Show information about a Swagger/OpenAPI specification.
Usage: mcp-swagger info <spec> [OPTIONS]
Arguments:
spec URL or file path to Swagger/OpenAPI specification
Options:
--help Show this message and exit.
After generating an MCP server, follow these steps to use it:
cd my_mcp_server
pip install -e .Stdio Transport (recommended for Claude Desktop):
my_mcp_serverSSE Transport (for remote access):
my_mcp_server --sse 8000Add to your Claude Desktop config:
{
"mcpServers": {
"my_mcp_server": {
"command": "my_mcp_server",
"args": []
}
}
}MCP Swagger CLI parses your OpenAPI/Swagger specification and generates:
-
MCP Tools - Each API operation becomes an MCP tool with:
- Tool name from
operationId(or generated) - Description from
summary/description - Parameters from path/query/header parameters
- Request body support
- Tool name from
-
MCP Resources - Each schema becomes an MCP resource:
schema://api/schemas- List of all schemasschema://api/{schema_name}- Individual schema definitionsapi://operations- List of all operations
-
Transport - Supports:
stdio- Standard I/O (local, default)sse- Server-Sent Events over HTTP
See the examples directory for sample specifications and usage.
# Install dev dependencies
pip install -e ".[dev]"
# Run tests
pytest tests/ -vmcp-swagger-cli/
├── mcp_swagger_cli/
│ ├── __init__.py
│ ├── cli.py # CLI commands
│ ├── generator.py # Server generation logic
│ ├── parser.py # OpenAPI parsing
│ ├── exceptions.py # Custom exceptions
│ └── templates/ # Jinja2 templates
├── tests/ # Test suite
├── pyproject.toml # Project configuration
└── README.md # This file
- Python 3.10+
- typer (CLI framework)
- httpx (HTTP client)
- prance (OpenAPI parser)
- jinja2 (template engine)
MIT License - see LICENSE for details.
Contributions are welcome! Please read our contributing guidelines first.
- MCP Python SDK - Official MCP Python implementation
- FastMCP - High-level MCP framework
- OpenAPI Specification - OpenAPI standard