MCP Swagger Server

MCP Swagger Server

Automatically converts REST APIs with Swagger/OpenAPI documentation into MCP tools, making any documented API accessible to MCP-compatible clients. Supports authentication, SSL handling, and flexible configuration for seamless API integration.

Category
访问服务器

README

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

Installation

Global Installation

npm install -g mcp-swagger

From Source

git clone https://github.com/HainanZhao/mcp-swagger.git
cd mcp-swagger
npm install
npm run build

Usage

Command Line Options

mcp-swagger [options]

Options:
  -u, --swagger-url <url>      URL to swagger documentation
  -f, --swagger-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

Examples

Load from URL with custom prefix

mcp-swagger --swagger-url https://api.example.com/swagger.json --tool-prefix example --ignore-ssl

Load from local file

mcp-swagger --swagger-file ./api-docs.json --tool-prefix local-api

With authentication

mcp-swagger --swagger-url https://api.example.com/swagger.json --auth-header "Bearer your-token-here"

Override base URL

mcp-swagger --swagger-file ./swagger.json --base-url https://staging.api.com --tool-prefix staging

Configuration

The server can be configured through command-line arguments or environment variables:

CLI Option Environment Variable Description
--swagger-url SWAGGER_URL URL to swagger documentation
--swagger-file SWAGGER_FILE Path to local swagger file
--tool-prefix TOOL_PREFIX Custom prefix for generated tools
--base-url BASE_URL Override base URL for API calls
--ignore-ssl IGNORE_SSL=true Ignore SSL certificate errors
--auth-header AUTH_HEADER Authentication header

MCP Integration

Add to your Agent configuration (e.g. claude_desktop_config.json or ~/.gemini/settings.json):

{
  "mcpServers": {
    "swagger-api": {
      "command": "mcp-swagger",
      "args": [
        "--swagger-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_users
  • GET /v1/users/{id}myapi_get_v1_users_by_id
  • POST /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
string string
integer number
boolean boolean
array array
object object

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 filtering
  • example_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-ssl flag
  • Network 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 build

Testing

# Test with sample swagger file
npm run test

Linting

npm run lint

Troubleshooting

Common Issues

  1. SSL Certificate Errors

    • Use --ignore-ssl flag for internal APIs with self-signed certificates
  2. Tool Name Conflicts

    • Use --tool-prefix to add unique prefixes to avoid naming conflicts
  3. Base URL Issues

    • Use --base-url to override the base URL from swagger documentation
  4. 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

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

Support

For issues and questions:

  • Create an issue on GitHub
  • Check the troubleshooting section above
  • Review the sample configurations

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选