Automatically converts REST APIs with Swagger/OpenAPI documentation into MCP tools, enabling interaction with any Swagger-documented API through dynamically generated tools that handle path, query, and body parameters.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@MCP Swagger Serverget the list of users from the API"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
MCP Swagger Server
An MCP (Model Context Protocol) server that automatically converts REST APIs with Swagger/OpenAPI documentation into MCP tools, making them accessible to MCP-compatible clients.
Features
π Automatic Tool Generation: Converts Swagger/OpenAPI endpoints to MCP tools
π SSL Certificate Handling: Option to ignore SSL certificate errors for internal APIs
π·οΈ Custom Tool Prefixes: Organize tools with custom prefixes for better organization
π‘ Stdio Transport: Uses stdio format as the default transport mechanism
π Flexible Input: Supports both URL and local file swagger documentation
π§ Parameter Support: Handles path, query, and body parameters
π Type Mapping: Maps Swagger types to JSON Schema types for proper validation
Related MCP server: OpenAPI to MCP Server
Installation
Global Installation
npm install -g mcp-swaggerFrom Source
git clone https://github.com/HainanZhao/mcp-swagger.git
cd mcp-swagger
npm install
npm run buildUsage
Command Line Options
mcp-swagger [options]
Options:
-u, --doc-url <url> URL to swagger documentation
-f, --doc-file <file> Path to local swagger file
-p, --tool-prefix <prefix> Custom prefix for generated tools
-b, --base-url <url> Override base URL for API calls
--ignore-ssl Ignore SSL certificate errors
-a, --auth-header <header> Authentication header (e.g., "Bearer token")
-h, --help Display help information
-V, --version Display version numberExamples
Load from URL with custom prefix
mcp-swagger --doc-url https://api.example.com/swagger.json --tool-prefix example --ignore-sslLoad from local file
mcp-swagger --doc-file ./api-docs.json --tool-prefix local-apiWith authentication
mcp-swagger --doc-url https://api.example.com/swagger.json --auth-header "Bearer your-token-here"Override base URL
mcp-swagger --doc-file ./swagger.json --base-url https://staging.api.com --tool-prefix stagingConfiguration
The server can be configured through command-line arguments or environment variables:
CLI Option | Environment Variable | Description |
|
| URL to swagger documentation |
|
| Path to local swagger file |
|
| Custom prefix for generated tools |
|
| Override base URL for API calls |
|
| Ignore SSL certificate errors |
|
| Authentication header |
Using Environment Variables
You can set environment variables to avoid passing command-line arguments repeatedly:
# Set environment variables
export SWAGGER_DOC_URL="https://api.example.com/swagger.json"
export SWAGGER_TOOL_PREFIX="myapi"
export SWAGGER_BASE_URL="https://staging.api.com"
export SWAGGER_IGNORE_SSL="true"
export SWAGGER_AUTH_HEADER="Bearer your-token-here"
# Run the server (will use environment variables)
mcp-swaggerEnvironment Variables in MCP Configuration
You can also use environment variables in your MCP client configuration:
{
"mcpServers": {
"swagger-api": {
"command": "mcp-swagger",
"env": {
"SWAGGER_DOC_URL": "https://example.com/swagger.json",
"SWAGGER_TOOL_PREFIX": "example",
"SWAGGER_IGNORE_SSL": "true"
}
}
}
}MCP Integration
Add to your Agent configuration (e.g. claude_desktop_config.json or ~/.gemini/settings.json):
{
"mcpServers": {
"swagger-api": {
"command": "mcp-swagger",
"args": [
"--doc-url",
"https://example.com/swagger.json",
"--tool-prefix",
"example",
"--ignore-ssl"
]
}
}
}Other MCP Clients
The server uses the standard MCP stdio transport, so it should work with any MCP-compatible client. Start the server and connect via stdin/stdout.
Generated Tools
Tool Naming Convention
Tools are named using the following pattern:
{prefix}_{method}_{path_segments}Path parameters are converted to
by_{parameter_name}
Examples:
GET /v1/users/βmyapi_get_v1_usersGET /v1/users/{id}βmyapi_get_v1_users_by_idPOST /v1/users/βmyapi_post_v1_users
Parameter Mapping
Path parameters: Included in the URL path
Query parameters: Added as URL query string
Body parameters: Sent as JSON request body
Header parameters: Added to request headers
Type Mapping
Swagger Type | JSON Schema Type |
|
|
|
|
|
|
|
|
|
|
Sample Swagger Document
The server has been tested with the following sample swagger document structure:
{
"swagger": "2.0",
"info": {
"title": "API Documentation",
"version": "1.0"
},
"host": "api.example.com",
"basePath": "/api",
"paths": {
"/v1/hosts/": {
"get": {
"summary": "Get a list of hosts",
"parameters": [
{
"name": "filter_by",
"in": "query",
"type": "string",
"description": "Filter criteria"
}
]
}
},
"/v1/hosts/{name}": {
"get": {
"summary": "Get host by name",
"parameters": [
{
"name": "name",
"in": "path",
"required": true,
"type": "string"
}
]
}
}
}
}This would generate tools like:
example_get_v1_hosts- List hosts with optional filteringexample_get_v1_hosts_by_name- Get specific host by name
Error Handling
The server includes comprehensive error handling:
SSL Certificate Errors: Can be ignored with
--ignore-sslflagNetwork Errors: Returned as error responses with details
Invalid Swagger: Validation errors are reported during startup
Missing Parameters: Parameter validation based on swagger schema
HTTP Errors: API response errors are captured and returned
Development
Building
npm run buildTesting
# Test with sample swagger file
npm run testLinting
npm run lintTroubleshooting
Common Issues
SSL Certificate Errors
Use
--ignore-sslflag for internal APIs with self-signed certificates
Tool Name Conflicts
Use
--tool-prefixto add unique prefixes to avoid naming conflicts
Base URL Issues
Use
--base-urlto override the base URL from swagger documentation
Authentication Failures
Provide proper authentication header with
--auth-header
Debug Mode
The server logs important information to stderr:
Swagger document loading status
Number of tools generated
Tool generation details
License
MIT License - see LICENSE file for details.
Contributing
Fork the repository
Create a feature branch
Make your changes
Add tests if applicable
Submit a pull request
Support
For issues and questions:
Create an issue on GitHub
Check the troubleshooting section above
Review the sample configurations