swagger-mcp-server

swagger-mcp-server

3.2

If you are the rightful owner of swagger-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

This is a Model Context Protocol (MCP) server designed to parse Swagger/OpenAPI specification files and provide tools for querying and analyzing API endpoints.

Swagger MCP Server

這是一個 Model Context Protocol (MCP)服務,用於解析 Swagger/OpenAPI 規格文件,並提供工具來查詢和分析 API 端點。

功能

  • 支持通過文件路徑或 URL 獲取 Swagger/OpenAPI 文檔
  • 支持 Swagger 2.0 和 OpenAPI 3.0 格式
  • 提供 API 端點列表查詢,支持指定深度和過濾條件
  • 提供 API 端點詳細信息查詢
  • 提供符合 MCP 規範的工具接口,支持與 Claude 或其他 AI 助手的集成

安裝

# 使用bun安裝依賴
bun install

使用方法

從本地文件啟動

bun run src/index.ts --file examples/petstore.json

從 URL 啟動

bun run src/index.ts --url https://petstore.swagger.io/v2/swagger.json

MCP 工具

listEndpoints

獲取 API 端點列表,支持指定深度和過濾條件。

參數:

  • depth:查詢深度級別,例如深度為 1 只返回第一級路徑
  • filter:前綴過濾條件,只返回符合指定前綴的端點

示例:

{
  "depth": 2,
  "filter": "/pets"
}

getEndpointDetail

獲取特定 API 端點的詳細信息。

參數:

  • path:API 端點的完整路徑
  • method:HTTP 方法(GET, POST, PUT, DELETE 等)

示例:

{
  "path": "/pets",
  "method": "get"
}

MCP 資源

swagger-info

獲取 Swagger 文檔的信息。

URI 格式:swagger-info://{type}

類型:

  • general:獲取一般信息,如標題、版本、描述等
  • paths:獲取路徑信息
  • schemas:獲取數據模型信息

示例:

swagger-info://general
swagger-info://paths
swagger-info://schemas

開發

構建

bun run build

運行測試

bun test

許可證

MIT