使用说明
Swagger MCP Agent(可译为):Swagger MCP 代理
该 Swagger MCP Agent(可译为“Swagger MCP 代理”) 是一个定制(品) 模型上下文协议(MCP) 集成了Swagger/OpenAPI规范与AI助手的服务器。
它允许MCP兼容的客户端(如VSCode MCP、Claude Desktop或Cursor)理解并与您的API文档进行交互。
使用这个代理,您可以:
- 导航API端点
- 检查请求和响应模式
- 通过参数或关键词搜索终端节点
- 生成示例API调用
- 协助API的集成与开发
🚀 功能
- Swagger/OpenAPI 支持 将API规范加载并解析到MCP资源中。
- MCP 工具 – 暴露辅助工具以搜索和导航终端节点。
- TypeScript 支持 – 使用现代TypeScript编写,以确保类型安全。
- 开发者友好型 – 与MCP Inspector、VSCode MCP、Claude Desktop及其他MCP客户端兼容。
📦 安装
克隆仓库并安装依赖项:
git clone https://github.com/chryzxc/swagger-mcp-server.git
cd swagger-mcp-server
# Install dependencies
npm install
▶️ 运行服务器
你可以直接使用(相关工具或命令)来运行MCP服务器 TSX(注:TSX通常指多伦多证券交易所,但在此上下文中可能仅作为缩写或特定术语使用,直接翻译为“TSX”或根据具体语境翻译为相应含义) 或者先建设。
直接运行
npx tsx /src/main.ts
添加 config.json 在根目录下
{
"SWAGGER_URL": "https://some-domain/api-docs-json",
"SWAGGER_BASIC_AUTH_USER": "",
"SWAGGER_BASIC_AUTH_PASS": ""
}
构建并运行
npm run build
node dist/main.js
运行检查器
npm run inspector
⚙️ MCP 客户端配置
将Swagger MCP服务器添加到您的MCP客户端配置中。
VSCode 示例(.vscode/settings.json)
{
"mcp.servers": {
"swagger-agent": {
"command": "node",
"args": ["E:/Projects/swagger-mcp-server/dist/main.js"],
"env": {
"SWAGGER_BASIC_AUTH_USER": "",
"SWAGGER_BASIC_AUTH_PASS": "",
"SWAGGER_URL": "http://localhost:3333/api-docs-json"
},
"type": "stdio"
}
}
}
💡 根据您本地项目的实际位置调整路径。
🛠️ 使用方法
配置完成后,您的MCP客户端即可与您的Swagger规范进行交互。示例:
> "List all available endpoints"
> "What are the required fields in user endpoint"
> "Show the request parameters for /users/{id}"
> "Find endpoints related to users"
> "Give me the body payload schema for /orders"
> "Give me the response schema for /orders"
> "What are the endpoints that requires `userId` field"
Swagger MCP Agent 将获取并分析您的规范,并返回结构化的响应。
📝 许可证
麻省理工学院许可证 © 2025 Christian Villablanca
