Swagger Prompts MCP
Fetches and parses remote Swagger 2.0 / OpenAPI 3.x documents to produce Chinese-language API prompts: it resolves all $ref references, extracts a single endpoint by path and HTTP method (with parameters, request body and responses) or a single named schema as JSON Schema, automatically prepends the path prefix from servers[0].url or basePath, and can download the raw Swagger JSON to a local file, optionally with Bearer token, basic auth or custom headers.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Swagger Prompts MCP 解析 https://petstore.swagger.io/v2/swagger.json 中的 GET /pet/{petId} 接口"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Swagger Prompts MCP
一个专业的 Swagger/OpenAPI 接口解析工具,支持 MCP 服务器和 CLI 两种使用方式。
✨ 特性
🚀 快速解析 - 秒级解析大型 Swagger/OpenAPI 文档
📝 中文提示 - 生成完整的中文 API 文档提示词
🔗 引用解析 - 自动解析所有
$ref引用🌍 路径前缀 - 自动识别并添加
servers[0].url路径前缀📦 双重模式 - 支持 MCP 服务器和独立 CLI 工具
🎯 智能提示 - 生成适合 AI 模型的 JSON Schema 格式
🔐 认证支持 - 支持 Bearer Token 和基本认证(用户名/密码)
💾 本地下载 - 一键下载 Swagger JSON 到本地文件
Related MCP server: mcp-swagger
📦 安装
全局安装(推荐)
pnpm add -g swagger-prompts-mcp
npm install -g swagger-prompts-mcp项目内安装
pnpm add swagger-prompts-mcp
npm install swagger-prompts-mcp🚀 快速开始
1. CLI 命令行工具
解析 API 接口
# 基础用法
swagger-prompts parse-endpoint \
-u https://petstore.swagger.io/v2/swagger.json \
-p /pet/{petId} \
-m get
# 带认证
swagger-prompts parse-endpoint \
-u https://api.example.com/swagger.json \
-p /users \
-m get \
-h "Authorization=Bearer token"
# 保存到文件
swagger-prompts parse-endpoint \
-u https://petstore.swagger.io/v2/swagger.json \
-p /pet \
-m post \
-o pet-api.md解析 Schema
swagger-prompts parse-schema \
-u https://petstore.swagger.io/v2/swagger.json \
-s Pet下载 Swagger JSON
# 基础下载(自动生成文件名)
swagger-prompts download \
-u https://petstore.swagger.io/v2/swagger.json
# 指定保存路径
swagger-prompts download \
-u https://petstore.swagger.io/v2/swagger.json \
-o ./api-docs.json
# 带认证下载
swagger-prompts download \
-u https://api.example.com/swagger.json \
--username admin \
--password secret123 \
-o ./private-api.json2. MCP 服务器
Claude Code 配置
编辑 MCP 客户端配置文件:
{
"mcpServers": {
"swagger-prompts": {
"command": "node",
"args": ["/path/to/swagger-prompts-mcp/dist/index.js"]
}
}
}在 Claude Code 中使用
解析 https://petstore.swagger.io/v2/swagger.json 中的 GET /pet/{petId} 接口解析 https://petstore.swagger.io/v2/swagger.json 中的 Pet Schema下载 https://petstore.swagger.io/v2/swagger.json 到本地文件📖 使用指南
CLI 命令详解
parse-endpoint - 解析 API 接口
swagger-prompts parse-endpoint [options]
选项:
-u, --url <url> Swagger/OpenAPI 文档 URL(必需)
-p, --path <path> API 接口路径(必需)
-m, --method <method> HTTP 方法:get|post|put|patch|delete|head|options(必需)
-o, --output <file> 输出文件路径(可选,默认输出到控制台)
-h, --header <header...> 自定义请求头,格式:Key=Value(可选)
-t, --timeout <ms> 请求超时时间,毫秒(默认:30000)parse-schema - 解析 Schema
swagger-prompts parse-schema [options]
选项:
-u, --url <url> Swagger/OpenAPI 文档 URL(必需)
-s, --schema <name> Schema 名称(必需)
-o, --output <file> 输出文件路径(可选)
-h, --header <header...> 自定义请求头(可选)
-t, --timeout <ms> 请求超时时间,毫秒(默认:30000)download - 下载 Swagger JSON
swagger-prompts download [options]
选项:
-u, --url <url> Swagger/OpenAPI 文档 URL(必需)
-o, --output <file> 保存文件路径(可选,不提供则自动生成)
--username <username> 认证用户名(可选)
--password <password> 认证密码(可选)
-h, --header <header...> 自定义请求头(可选)
-t, --timeout <ms> 请求超时时间,毫秒(默认:30000)路径前缀处理
工具会自动处理路径前缀:
OpenAPI 3.0 - 从
servers[0].url提取路径前缀Swagger 2.0 - 从
basePath提取路径前缀
例如:
servers[0].url:http://test.com/api/v1用户请求路径:
/users生成路径:
/api/v1/users
MCP 工具调用
parseApiEndpoint
{
"name": "parseApiEndpoint",
"arguments": {
"url": "https://petstore.swagger.io/v2/swagger.json",
"path": "/pet/{petId}",
"method": "get",
"headers": {
"Authorization": "Bearer token"
}
}
}parseSchema
{
"name": "parseSchema",
"arguments": {
"url": "https://petstore.swagger.io/v2/swagger.json",
"schemaName": "Pet"
}
}downloadSwaggerJson
{
"name": "downloadSwaggerJson",
"arguments": {
"url": "https://petstore.swagger.io/v2/swagger.json",
"savePath": "./api-docs.json"
}
}带认证的下载
{
"name": "downloadSwaggerJson",
"arguments": {
"url": "https://api.example.com/swagger.json",
"username": "admin",
"password": "secret123",
"savePath": "./private-api.json"
}
}📋 示例
示例 1:解析宠物商店 API
# 获取宠物信息接口
swagger-prompts parse-endpoint \
-u https://petstore.swagger.io/v2/swagger.json \
-p /pet/{petId} \
-m get
# 添加新宠物接口
swagger-prompts parse-endpoint \
-u https://petstore.swagger.io/v2/swagger.json \
-p /pet \
-m post \
-o add-pet.md示例 2:带认证的 API
# 使用 API Key
swagger-prompts parse-endpoint \
-u https://api.example.com/v1/swagger.json \
-p /protected/data \
-m get \
-h "X-API-Key=your-api-key"
# 使用 Bearer Token
swagger-prompts parse-endpoint \
-u https://api.example.com/v1/swagger.json \
-p /user/profile \
-m get \
-h "Authorization=Bearer your-token"示例 3:批量处理
#!/bin/bash
# 批量解析多个接口
URL="https://api.example.com/swagger.json"
# 解析多个接口
swagger-prompts parse-endpoint -u $URL -p /users -m get -o users-get.md
swagger-prompts parse-endpoint -u $URL -p /users -m post -o users-post.md
swagger-prompts parse-endpoint -u $URL -p /users/{id} -m get -o users-get-by-id.md
# 解析常用 Schema
swagger-prompts parse-schema -u $URL -s User -o user-schema.md
swagger-prompts parse-schema -u $URL -s Error -o error-schema.md🔧 开发
环境要求
Node.js >= 18
pnpm >= 10
开发设置
# 克隆仓库
git clone git@github.com:SublimeCT/swagger-prompts-mcp.git
cd swagger-prompts-mcp
# 安装依赖
pnpm install
# 开发模式
pnpm dev
# 构建
pnpm build
# 测试
pnpm test
# 代码格式化
pnpm lint项目结构
src/
├── index.ts # MCP 服务器入口
├── cli.ts # CLI 工具入口
├── core/ # 核心模块
│ ├── api-parser.ts # API 解析器
│ └── prompt-generator.ts # 提示词生成器
├── types/ # 类型定义
│ ├── api.ts # API 相关类型
│ ├── openapi.ts # OpenAPI 类型
│ ├── prompt.ts # 提示词类型
│ ├── swagger.ts # Swagger 类型
│ └── index.ts # 类型导出
└── utils/ # 工具函数
├── downloadSwagger.ts # 下载 Swagger JSON
├── fetchSwagger.ts # 获取文档
├── parseApiEndpoints.ts # 解析 API 接口
├── parseOpenApiEndpoints.ts # 解析 OpenAPI 接口
├── parseSchema.ts # 解析 Schema
└── schema-utils.ts # Schema 工具🤝 贡献
欢迎贡献代码!请查看 贡献指南 了解详情。
📄 许可证
本项目采用 MIT 许可证。
🙏 致谢
FastMCP - MCP 服务器框架
json-schema-ref-parser - JSON Schema 引用解析
Commander.js - CLI 框架
🔗 相关链接
Made with ❤️ by the community
Available Tools
3 toolsdownloadSwaggerJsonB
下载 Swagger/OpenAPI JSON 文档到本地文件,支持用户名密码认证
Inputs: url (required), headers, timeout, password, +2 more.
parseApiEndpointARead-only
解析 Swagger/OpenAPI 文档中的单个接口,生成 JSON Schema 格式的中文提示词
Inputs: url (required), path (required), method (required), headers, +1 more.
parseSchemaBRead-only
递归解析 Swagger/OpenAPI 文档中的指定 Schema,生成完整的 JSON Schema 结构
Inputs: url (required), schemaName (required), headers, timeout.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 3 tools
The three tools have clearly distinct purposes: downloading a Swagger/OpenAPI document, parsing a single endpoint into a prompt, and recursively parsing a schema. The naming and descriptions make it easy to choose the correct tool for each task.
All tool names use consistent camelCase with a verb+noun structure: parseApiEndpoint, parseSchema, and downloadSwaggerJson. There is no mixing of conventions or vague verbs.
Three tools is a well-scoped set for a focused Swagger/OpenAPI prompt-generation server. Each tool serves a clear role without unnecessary surface area.
The set covers downloading a document, parsing one endpoint, and parsing a schema, but lacks obvious operations for listing or enumerating all endpoints and generating prompts across the whole document. Agents can partially work around this by inspecting the downloaded JSON, but it remains a notable gap.
Maintenance
Related MCP Connectors
Publish your API docs so AI assistants can look up endpoints and call your API correctly.
MCP server for AI access to Swagger by SmartBear.
Validate OpenAPI and JSON Schema, convert specs, curl to code, JSONPath, and free test data.
List, compare, and call 68 LLMs with live pricing through one Chinese API gateway.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables Trae IDE to parse and query Swagger/Knife4j API documentation by converting JSON format interface documents into a searchable text format, allowing developers to efficiently retrieve API information through natural language queries.1ISC
- AlicenseAqualityDmaintenanceExposes Swagger/OpenAPI API documentation to AI models, enabling exploration, search, and interaction with endpoints, schemas, and execution of API calls.1427 npm2MIT
- FlicenseNot gradedqualityDmaintenanceEnables AI to scan and query local OpenAPI/Swagger documentation, listing API groups and endpoints, and generating TypeScript type definitions for specific endpoints.-
- AlicenseNot gradedqualityDmaintenanceAutomatically parses Swagger/OpenAPI documentation, generates frontend code (Vue3, React, etc.), and enables API testing through natural language commands.MIT