
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
mcp-swagger
Advanced tools
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.
npm install -g mcp-swagger
git clone https://github.com/HainanZhao/mcp-swagger.git
cd mcp-swagger
npm install
npm run build
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 number
mcp-swagger --doc-url https://api.example.com/swagger.json --tool-prefix example --ignore-ssl
mcp-swagger --doc-file ./api-docs.json --tool-prefix local-api
mcp-swagger --doc-url https://api.example.com/swagger.json --auth-header "Bearer your-token-here"
mcp-swagger --doc-file ./swagger.json --base-url https://staging.api.com --tool-prefix staging
The server can be configured through command-line arguments or environment variables:
CLI Option | Environment Variable | Description |
---|---|---|
--doc-url | SWAGGER_DOC_URL | URL to swagger documentation |
--doc-file | SWAGGER_DOC_FILE | Path to local swagger file |
--tool-prefix | SWAGGER_TOOL_PREFIX | Custom prefix for generated tools |
--base-url | SWAGGER_BASE_URL | Override base URL for API calls |
--ignore-ssl | SWAGGER_IGNORE_SSL=true | Ignore SSL certificate errors |
--auth-header | SWAGGER_AUTH_HEADER | Authentication header |
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-swagger
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"
}
}
}
}
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"
]
}
}
}
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.
Tools are named using the following pattern:
{prefix}_{method}_{path_segments}
by_{parameter_name}
Examples:
GET /v1/users/
→ myapi_get_v1_users
GET /v1/users/{id}
→ myapi_get_v1_users_by_id
POST /v1/users/
→ myapi_post_v1_users
Swagger Type | JSON Schema Type |
---|---|
string | string |
integer | number |
boolean | boolean |
array | array |
object | object |
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 nameThe server includes comprehensive error handling:
--ignore-ssl
flagnpm run build
# Test with sample swagger file
npm run test
npm run lint
SSL Certificate Errors
--ignore-ssl
flag for internal APIs with self-signed certificatesTool Name Conflicts
--tool-prefix
to add unique prefixes to avoid naming conflictsBase URL Issues
--base-url
to override the base URL from swagger documentationAuthentication Failures
--auth-header
The server logs important information to stderr:
MIT License - see LICENSE file for details.
For issues and questions:
FAQs
MCP server that converts REST APIs with Swagger documentation into MCP tools
We found that mcp-swagger demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.