这是一个通过Model Context Protocol(MCP)处理 Swagger/OpenAPI 规范的服务器,能加载规范、支持多种认证方式,还可自动生成MCP工具,为实时通信提供支持,同时具备 TypeScript 支持。
⚠️ 重要提示
这是一个个人服务器,请勿将其暴露到公共互联网。若底层 API 需要身份验证,同样不应将 MCP 服务器暴露到公共互联网。
git clone https://github.com/dcolley/swagger-mcp.git
cd swagger-mcp
yarn install
.env文件:cp .env.example .env
swagger.json)。config.json中更新服务器设置:{
"server": {
"host": "localhost",
"port": 3000
},
"swagger": {
"url": "url-or-path/to/your/swagger.json",
"apiBaseUrl": "https://api.example.com", // 如果Swagger中未指定,则作为备用URL
"defaultAuth": { // 如果Swagger中未指定身份验证方案,则作为备用设置
"type": "apiKey",
"apiKey": "your-api-key",
"name": "Authorization",
"value": "Bearer ${ apiKey }"
}
}
}
yarn dev
yarn build
GET /api-docs
GET /api-docs/{name}
POST /api-docs
DELETE /api-docs/{name}
配置示例:
{
"defaultAuth": {
"type": "basic",
"username": "your-username",
"password": "your-password"
}
}
配置示例:
{
"defaultAuth": {
"type": "bearer",
"token": "your-bearer-token"
}
}
配置示例:
{
"defaultAuth": {
"type": "apiKey",
"key": "your-api-key",
"name": "X-API-Key",
"value": "${ key }"
}
}
配置示例:
{
"defaultAuth": {
"type": "oauth2",
"clientId": "your-client-id",
"clientSecret": "your-client-secret",
"accessTokenUrl": "https://example.com/oauth/token",
"authorizationUrl": "https://example.com/oauth/authorize"
}
}
| 属性 | 详情 |
|---|---|
NEXT_PUBLIC_API_BASE_URL |
默认情况下,API 基础 URL |
NEXT_PUBLIC_SWAGGER_URL |
默认 Swagger 规范的 URL |
yarn test
yarn test:dev
yarn test:cov