Swagger MCP

Swagger MCP

Automatically converts Swagger/OpenAPI specifications into MCP servers, enabling AI agents to interact with any REST API through natural language by exposing endpoints as AI-friendly tools.

Category
访问服务器

README

Swagger MCP

Automatically convert a Swagger/OpenAPI specification into an MCP server for use with Windsurf, Cursor, or other tools.

Quickstart

swagger-mcp uses pipx

Install from PyPI using pipx (recommended):

brew install pipx
pipx ensurepath
pipx install --force swagger-mcp

Alternatively, install from source:

git clone https://github.com/context-labs/swagger-mcp.git
cd swagger-mcp
pipx install -e . --force

Confirm the installation succeeded:

which swagger-mcp
which swagger-mcp-sample-server

Spin up a sample "products and product categories" API on your local machine on port 9000:

swagger-mcp-sample-server

Visit http://localhost:9000/docs to confirm the sample server is running.

We'll use this sample server to show how to configure an MCP server in Windsurf.

Make sure the sample server is running before following the Windsurf or Cursor instructions below.

Windsurf

Start an MCP Server in Windsurf (Windsurf Settings -> Settings -> Cascade -> Manage Plugins -> View Raw Config):

{
  "mcpServers": {
    "product-mcp": {
      "command": "swagger-mcp",
      "args": [
        "--spec",
        "http://localhost:9000/openapi.json",
        "--name",
        "Product-MCP",
        "--server-url",
        "http://localhost:9000"
      ]
    }
  }
}

That's it! Your API is now accessible through Windsurf, Cursor, or other tools as a set of AI-friendly tools.

Ask your AI agent to list, create, update, and delete products and categories.

Demo

Cursor (>=v0.46)

Support for Cursor is still in beta as Cursor MCP integration matures. Windsurf is currently the preferred experience. To add a custom MCP server in Cursor, go to Settings -> Cursor Settings -> Tools & Integrations -> Add Custom MCP.

{
  "mcpServers": {
    "product mcp": {
      "command": "swagger-mcp",
      "args": [
        "--spec",
        "http://localhost:9000/openapi.json",
        "--name",
        "Product-MCP",
        "--server-url",
        "http://localhost:9000",
        "--cursor"
      ]
    }
  }
}

Please Note: In Cursor, you may need to replace the command swagger-mcp with the full path to the swagger-mcp executable, which you can find by running which swagger-mcp.

Also note the --cursor flag. This is for Cursor compatibility.

Again, MCP integration is currently in beta in Cursor as of v0.46 and may not work as expected. Currently, Windsurf is a better experience in general.

See other examples in Other Fun Servers.

Additional Options

  1. You can pass a JSON file, YAML file, or URL for the --spec option:

    • /path/to/openapi.json
    • /path/to/openapi.yaml
    • https://api.example.com/openapi.json
  2. Filter endpoints: Only include endpoints where the path matches the regex pattern:

{
  "mcpServers": {
    "product mcp": {
      "command": "swagger-mcp",
      "args": [
        "--spec",
        "http://localhost:9000/openapi.json",
        "--name",
        "product-mcp",
        "--server-url",
        "http://localhost:9000",
        "--include-pattern",
        "category"
      ]
    }
  }
}
  1. Filter endpoints: Exclude endpoints where the path matches the regex pattern:
{
  "mcpServers": {
    "product mcp": {
      "command": "swagger-mcp",
      "args": [
        "--spec",
        "http://localhost:9000/openapi.json",
        "--name",
        "product-mcp",
        "--server-url",
        "http://localhost:9000",
        "--exclude-pattern",
        "product"
      ]
    }
  }
}
  1. Authentication
{
  "mcpServers": {
    "product mcp": {
      "command": "swagger-mcp",
      "args": [
        "--spec",
        "http://localhost:9000/openapi.json",
        "--name",
        "product-mcp",
        "--server-url",
        "http://localhost:9000",
        "--bearer-token",
        "your-token-here",
      ]
    }
  }
}
  1. Custom headers
{
  "mcpServers": {
    "product mcp": {
      "command": "swagger-mcp",
      "args": [
        "--spec",
        "http://localhost:9000/openapi.json",
        "--name",
        "product-mcp",
        "--server-url",
        "http://localhost:9000",
        "--header",
        "X-Some-Header:your-value",
        "--header",
        "X-Some-Other-Header:your-value",
      ]
    }
  }
}
  1. Server URLs If the OpenAPI spec already contains a specific server URL, you don't have to provide it as a command line argument. But if you do, the command line --server-url overrides all endpoints.

  2. Constant Values

If you want to always automatically provide a value for a parameter, you can use the --const option. You can include as many --const options as you need.

{
  "mcpServers": {
    "product mcp": {
      "command": "swagger-mcp",
      "args": [
        "--spec",
        "http://localhost:9000/openapi.json",
        "--name",
        "product-mcp",
        "--server-url",
        "http://localhost:9000",
        "--const",
        "parameter-name:your-value",
        "--const",
        "parameter-name2:your-value2"
      ]
    }
  }
}

Supported Features

  • All HTTP methods (GET, POST, PUT, DELETE, etc.)
  • Path parameters
  • Query parameters
  • Textual Multi-Part Request Body Fields
  • JSON Request body
  • Bearer Token Authentication
  • Custom Headers
  • Constant Values

Limitations

  • Endpoints that have recursive schema references are not yet supported.
  • Cursor MCP integration is very early and frankly broken. I try to address some of these with cursor mode --cursor, but it's still not great. Until Cursor MCP support gets better, you'll be happier with Windsurf.
  • We will never support automatic OAuth workflow execution. If the OAuth workflow creates a bearer token, you must obtain this token yourself by performing OAuth out-of-band, and provide this bearer token as a command line argument.
  • We do not support Swagger/OpenAPI specifications spread across multiple files (i.e.; fragments, extensions, etc.).
  • We do not support path variable substitution in server URLs (but we do support path variables in endpoints).
  • In general, we do not support all Swagger/OpenAPI features. The Swagger/OpenAPI standard is vast, and support for more obscure features will be added as needed / requested.

Help

  • If you have trouble spinning up a server, try the following command: REAL_LOGGER=true swagger-mcp-parse-dry-run ... and provide all the same arguments you would use to spin up a server. Include this information in any issue you file.
  • If you find a Swagger API specification that is not supported and you can't use any of the available parameters for a workaround, please file an issue. We will add support for it as needed / requested.

Command Line Options

  • --spec (required): Path or URL to your OpenAPI/Swagger specification
  • --name (required): Name for your MCP server (shows up in Windsurf/Cursor)
  • --server-url: Base URL for API calls (overrides servers defined in spec)
  • --bearer-token: Bearer token for authenticated requests
  • --additional-headers: JSON string of additional headers to include in all requests
  • --include-pattern: Regex pattern to include only specific endpoint paths (e.g., "/api/v1/.*")
  • --exclude-pattern: Regex pattern to exclude specific endpoint paths (e.g., "/internal/.*")
  • --header: key:value pair of an extra header to include with all requests. Can be included multiple times to specify multiple headers.
  • --const: key:value pair of a constant value to always use for a parameter, if the parameter is present on the endpoint (can be a path variable, query parameter, top-level request body property, or multi-part non-file form data field). Can be included multiple times to specify multiple const values.
  • --cursor: Run in cursor mode

Authentication

For APIs requiring authentication:

{
  "mcpServers": {
    "product mcp": {
      "command": "swagger-mcp",
      "args": [
        "--spec",
        "http://localhost:9000/openapi.json",
        "--name",
        "product-mcp",
        "--server-url",
        "http://localhost:9000",
        "--bearer-token",
        "your-token-here",
        "--cursor"
      ]
    }
  }
}
{
  "mcpServers": {
    "product mcp": {
      "command": "swagger-mcp",
      "args": [
        "--spec",
        "http://localhost:9000/openapi.json",
        "--name",
        "product-mcp",
        "--server-url",
        "http://localhost:9000",
        "--header",
        "X-API-Key:your-key",
        "--cursor"
      ]
    }
  }
}

Other Fun Servers

Countries

{
  "mcpServers": {
    "countries": {
      "command": "swagger-mcp",
      "args": [
        "--spec",
        "https://restcountries.com/openapi/rest-countries-3.1.yml",
        "--name",
        "countries",
        "--server-url",
        "https://restcountries.com/",
        "--const",
        "fields:name"
      ]
    }
  }
}

Petstore

{
  "mcpServers": {
    "petstore": {
      "command": "swagger-mcp",
      "args": [
        "--spec",
        "https://petstore.swagger.io/v2/swagger.json",
        "--name",
        "petstore",
        "--server-url",
        "https://petstore.swagger.io/v2",
        "--header",
        "X-API-Key:special-key",
      ]
    }
  }
}

For Developers

Installation

For development, install with development dependencies:

# Clone the repository
git clone https://github.com/context-labs/swagger-mcp.git
cd swagger-mcp

# Install in development mode with dev dependencies
pip install -e ".[dev]"

For a global installation on your local machine, use:

bash scripts/install-global.sh

Unit Tests

pytest swagger_mcp/tests/unit -v

Integration Tests

pytest swagger_mcp/tests/integration -v --capture=no --log-cli-level=INFO

MCP Inspector (For interactive exploration of the MCP Server)

You'll have to do a global installation of your latest code first (bash scripts/install-global.sh), then you can run the inspector script.

You'll see the server type STDIO and the command swagger-mcp pre-filled.

bash scripts/inspector.sh

Click "Connect" and then "List Tools" to begin interacting with your MCP Server.

MCP Inspector

Logging

To run the server with logs enabled, set the REAL_LOGGER environment variable to true:

REAL_LOGGER=true swagger-mcp --spec http://localhost:9000/openapi.json --name product-mcp --server-url http://localhost:9000

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选