Dynamically generates MCP tools from Swagger/OpenAPI documentation (versions 2.0, 3.0, 3.1), enabling direct access to any REST API defined in a Swagger specification with support for various authentication methods.
@yuuzu/swagger-mcp
基於 TypeScript SDK MCP 的 Swagger/OpenAPI MCP 服務器。此工具能夠從 Swagger/OpenAPI 文檔動態生成 MCP 工具,讓 Claude Desktop 可以直接調用 REST API。
功能特色
✅ 支援所有 Swagger/OpenAPI 版本(2.0、3.0、3.1)
✅ 從 URL 或本地文件載入 Swagger 文檔
✅ 動態生成 MCP 工具
✅ 優化的工具命名格式:使用
method-path-group-endpoint
格式(如:post-api-auth-signin
)✅ 支援多種認證方式(Bearer Token、API Key、Basic Auth)
✅ 自動參數驗證(使用 Zod)
✅ 請求/回應日誌記錄
✅ 自動重新載入 Swagger 文檔
✅ 完整的錯誤處理
系統需求
Node.js >= 20.14
安裝
設定
1. 環境變數設定
複製 .env.sample
並重新命名為 .env
:
編輯 .env
檔案,設定您的 Swagger 文檔來源和認證資訊:
2. Claude Desktop 設定
在 Claude Desktop 的設定檔中加入 SwaggerMcp 服務器:
Windows: %APPDATA%\Claude\claude_desktop_config.json
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Linux: ~/.config/Claude/claude_desktop_config.json
使用方式
重新啟動 Claude Desktop
在對話中,您可以看到從 Swagger 文檔生成的工具
使用工具時,Claude 會自動調用對應的 API
範例對話
環境變數說明
必要設定
變數 | 說明 | 範例 |
或
| Swagger 文檔來源 |
|
認證設定
變數 | 說明 | 預設值 |
| 認證類型:bearer、apikey、basic、none | none |
| 認證 token 或憑證 | - |
| 認證標頭名稱 | Authorization |
| API Key 標頭名稱(apikey 類型) | X-API-Key |
進階設定
變數 | 說明 | 預設值 |
| 覆蓋 Swagger 中的 base URL( 重要 :如果 Swagger 使用相對 URL,必須設定此項) | - |
| 請求超時時間(毫秒) | 30000 |
| Swagger 文檔重新載入間隔(毫秒) | 3600000 |
| 日誌等級:debug、info、warn、error | info |
| 啟用請求/回應日誌 | false |
API_BASE_URL 設定說明
某些 Swagger 文檔使用相對 URL 作為服務器地址(例如 /api
)。在這種情況下,您需要設定 API_BASE_URL
來指定完整的 API 基礎 URL:
支援的認證方式
Bearer Token
API Key
Basic Auth
開發
開發模式
執行測試
程式碼檢查
專案結構
疑難排解
無法載入 Swagger 文檔
確認 URL 或檔案路徑正確
檢查網路連線
確認 Swagger 文檔格式正確
認證失敗
確認 AUTH_TYPE 設定正確
檢查 token 是否過期
確認認證標頭名稱正確
工具未出現在 Claude Desktop
確認 SwaggerMcp 服務器正在執行
檢查 Claude Desktop 設定檔路徑
重新啟動 Claude Desktop
授權
MIT License
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
A service that dynamically generates MCP tools from Swagger/OpenAPI documentation, allowing Claude Desktop to directly invoke REST APIs through natural language.
Related MCP Servers
- -securityAlicense-qualityAn MCP server that enables dynamic tool registration and execution based on API definitions, providing seamless integration with services like Claude.ai and Cursor.ai.Last updated -11MIT License
- -securityFlicense-qualitySo I tried out this cool tool I saw in a LinkedIn post https://openapitools.com All you need is your API schema (OpenAPI/Swagger), and it automatically generates an MCP schema for you. You can then drop it straight into Claude Desktop (or Cursor, LangChain, etc.) and instantly start chatting withLast updated -1
- AsecurityAlicenseAqualityA tool that creates MCP (Model Context Protocol) servers from OpenAPI/Swagger specifications, enabling AI assistants to interact with your APIs.Last updated -3925MIT License
- AsecurityAlicenseAqualityMCP server that provides tools for exploring and testing APIs through Swagger/OpenAPI documentation.Last updated -5215MIT License