@abhishekkumar00019/swagger-mcp
@abhishekkumar00019/swagger-mcp
一个动态的 Model Context Protocol (MCP) 服务器,可即时将任何 Swagger 2.0 或 OpenAPI 3.x 规范转换为可调用的 MCP 工具。
只需指向任何 OpenAPI/Swagger JSON 或 YAML 规范 URL,每个 API 端点就会自动成为 Claude、Copilot、ChatGPT、Cursor、Windsurf 及其他支持 MCP 的客户端的交互式工具。
✨ 功能特性
🔄 动态工具生成 — 启动时自动解析 Swagger 2.0 和 OpenAPI 3.x 规范。
🛠️ 零样板代码 — 提供规范 URL,每个端点即可立即作为 MCP 工具暴露。
🔐 灵活的认证支持 — 通过环境变量或 CLI 参数轻松配置 Bearer Token、API Key 和 Basic Auth。
🌐 智能 Base URL 解析 — 按配置 → 规范服务器定义 → 规范来源 URL 的顺序自动推导 base URL。
🔁 热重载 — 使用
_swagger_mcp_reload工具在运行时实时重新获取并解析规范。📝 丰富的 Schema 与描述 — 将 OpenAPI 参数和请求体转换为严格的 JSON schema,以实现精确的 LLM 工具调用。
⏱️ 可配置超时与自定义请求头 — 轻松设置自定义请求头和请求超时阈值。
Related MCP server: Swagger to MCP
🚀 快速开始
选项 A:通过 npx 直接使用(无需安装)
SWAGGER_MCP_SPEC_URL=https://petstore.swagger.io/v2/swagger.json npx @abhishekkumar00019/swagger-mcp选项 B:全局 NPM 安装
npm install -g @abhishekkumar00019/swagger-mcp
SWAGGER_MCP_SPEC_URL=https://petstore.swagger.io/v2/swagger.json swagger-mcp选项 C:本地仓库搭建
克隆并安装依赖:
git clone https://github.com/itachiuchihadev/swagger-mcp.git cd swagger-mcp npm install构建项目:
npm run build本地运行:
SWAGGER_MCP_SPEC_URL=https://petstore.swagger.io/v2/swagger.json node dist/index.js
⚙️ MCP 客户端配置
以下是使用 npx @abhishekkumar00019/swagger-mcp 的主流 MCP 客户端示例配置。
1. Claude Desktop
添加到你的 claude_desktop_config.json:
macOS:
~/Library/Application Support/Claude/claude_desktop_config.jsonWindows:
%APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"swagger-mcp": {
"command": "npx",
"args": ["-y", "@abhishekkumar00019/swagger-mcp"],
"env": {
"SWAGGER_MCP_SPEC_URL": "https://petstore.swagger.io/v2/swagger.json",
"SWAGGER_MCP_BEARER_TOKEN": "your-api-token-here"
}
}
}
}2. Claude Code(CLI)
直接通过 Claude Code CLI 添加:
claude mcp add swagger-mcp -- npx -y @abhishekkumar00019/swagger-mcp --spec-url https://petstore.swagger.io/v2/swagger.json或者添加到项目根目录的 .mcp.json:
{
"mcpServers": {
"swagger-mcp": {
"command": "npx",
"args": ["-y", "@abhishekkumar00019/swagger-mcp"],
"env": {
"SWAGGER_MCP_SPEC_URL": "https://petstore.swagger.io/v2/swagger.json"
}
}
}
}3. GitHub Copilot / VS Code
添加到工作区或 VS Code 全局设置中的 .vscode/mcp.json:
{
"server": {
"swagger-mcp": {
"command": "npx",
"args": ["-y", "@abhishekkumar00019/swagger-mcp"],
"env": {
"SWAGGER_MCP_SPEC_URL": "https://petstore.swagger.io/v2/swagger.json",
"SWAGGER_MCP_API_KEY": "your-api-key"
}
}
}
}4. Cursor
添加到 .cursor/mcp.json,或在 Cursor 设置 → 功能 → MCP 中配置:
{
"mcpServers": {
"swagger-mcp": {
"command": "npx",
"args": ["-y", "@abhishekkumar00019/swagger-mcp"],
"env": {
"SWAGGER_MCP_SPEC_URL": "https://petstore.swagger.io/v2/swagger.json"
}
}
}
}5. Windsurf
添加到 ~/.codeium/windsurf/mcp_config.json:
{
"mcpServers": {
"swagger-mcp": {
"command": "npx",
"args": ["-y", "@abhishekkumar00019/swagger-mcp"],
"env": {
"SWAGGER_MCP_SPEC_URL": "https://petstore.swagger.io/v2/swagger.json"
}
}
}
}6. Roo Code / Cline(VS Code 扩展)
添加到 cline_mcp_settings.json(或 roo_code_mcp_settings.json):
{
"mcpServers": {
"swagger-mcp": {
"command": "npx",
"args": ["-y", "@abhishekkumar00019/swagger-mcp"],
"env": {
"SWAGGER_MCP_SPEC_URL": "https://petstore.swagger.io/v2/swagger.json"
}
}
}
}7. ChatGPT 和 OpenAI(自定义 GPT / 助手 / API)
直接导入 OpenAPI 规范(原生自定义 GPT Actions):
ChatGPT 自定义 GPT 原生支持 OpenAPI 规范。你可以直接在自定义 GPT 构建器的 Actions 部分导入你的 Swagger/OpenAPI JSON/YAML 规范 URL,无需中间服务器。
通过 MCP HTTP/SSE 网关:
如果通过 HTTP/SSE 桥接(例如使用 supergateway 或 mcp-remote)将 ChatGPT 或 OpenAI 代理连接到这个 MCP 服务器,请使用 SSE 代理启动 swagger-mcp:
npx supergateway --stdio "npx -y @abhishekkumar00019/swagger-mcp --spec-url https://petstore.swagger.io/v2/swagger.json" --port 80008. Zed Editor
添加到 ~/.config/zed/settings.json:
{
"context_servers": {
"swagger-mcp": {
"command": {
"path": "npx",
"args": ["-y", "@abhishekkumar00019/swagger-mcp"]
},
"env": {
"SWAGGER_MCP_SPEC_URL": "https://petstore.swagger.io/v2/swagger.json"
}
}
}
}🔧 配置参考
所有配置参数都可以通过环境变量或 CLI 参数提供。SWAGGER_MCP_SPEC_URL 是唯一必需的参数。
环境变量 | CLI 参数 | 必需 | 默认值 | 描述 |
|
| 是 | — | Swagger/OpenAPI 规范 URL |
|
| 否 | 自动推导 | 覆盖目标 API 的 base URL |
|
| 否 | — | 用于 |
|
| 否 | — | API Key 请求头的值 |
|
| 否 |
| API Key 的自定义请求头名称 |
|
| 否 | — | Basic Auth 的用户名 |
|
| 否 | — | Basic Auth 的密码 |
|
| 否 |
| HTTP 请求超时时间(毫秒) |
|
| 否 |
| 额外的 HTTP 请求头(JSON 字符串) |
🔑 认证示例
可以同时设置多种认证方式:
# Bearer Token
SWAGGER_MCP_BEARER_TOKEN=sk-your-token-here
# API Key (Custom Header)
SWAGGER_MCP_API_KEY=your-api-key
SWAGGER_MCP_API_KEY_HEADER=X-Custom-Key
# Basic Auth
SWAGGER_MCP_BASIC_USER=admin
SWAGGER_MCP_BASIC_PASS=secret123[!NOTE] 如果同时指定了 Bearer 和 Basic Auth,Basic Auth 将覆盖
Authorization请求头。如果需要多个请求头,请将 Bearer Token 与 API Key 请求头结合使用。
🏷️ 工具命名策略
来自 OpenAPI 规范的端点将按以下优先级顺序转换为 MCP 工具:
优先级 | 来源 | 示例 |
第 1 位 | 规范中定义的 |
|
第 2 位 | 标签 + 方法 + 路径 |
|
第 3 位 | 方法 + 路径 |
|
🧰 内置元工具
工具 | 描述 |
| 实时重新获取并解析 Swagger 规范。在开发或更新 API 时无需重启服务器即可生效。 |
📁 项目结构
swagger-mcp/
├── package.json
├── tsconfig.json
├── src/
│ ├── index.ts # Entry point & CLI argument parser
│ ├── server.ts # MCP server initialization & tool registration
│ ├── swagger-parser.ts # OpenAPI 2.0/3.x spec fetcher & parser
│ ├── tool-builder.ts # Converts OpenAPI operations -> JSON Schema tools
│ ├── request-handler.ts # Proxies MCP tool calls to HTTP endpoints
│ ├── auth.ts # Authentication header builder
│ ├── config.ts # Environment & CLI configuration manager
│ └── types.ts # Shared TypeScript interfaces
└── dist/ # Compiled JavaScript output📄 许可证
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.
No tool schema history has been recorded yet.
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
Point Gecko at an OpenAPI spec; get first-call-correct, auth-hidden agent tools.
MCP server for AI access to Swagger by SmartBear.
The OpenRouter for tools. One MCP connection gives any AI agent 254 hosted tools, pay per call.
Pay-per-use tool marketplace for AI agents. Search, price-check, and call APIs via MCP.
Related MCP Servers
- -licenseNot gradedqualityNot gradedmaintenanceDynamically generates MCP tools from Swagger/OpenAPI specifications by extracting swagger.json files at runtime. Enables natural language interaction with any REST API that has Swagger documentation.-
- AlicenseNot gradedqualityNot gradedmaintenanceAutomatically converts Swagger/OpenAPI specifications into dynamic MCP tools, enabling interaction with any REST API through natural language by loading specs from local files or URLs.-
- FlicenseNot gradedqualityDmaintenanceDynamically converts any API with an OpenAPI v3 specification into MCP tools for AI assistants. It supports multiple authentication methods including OAuth2, Bearer tokens, and API keys for flexible integration.-
- AlicenseNot gradedqualityCmaintenanceConverts any OpenAPI/Swagger API specification into MCP tools that AI assistants can use to interact with the API.377MIT
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/itachiuchihadev/swagger_mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server