Integrations
Generates API client code that uses Axios as the HTTP client, allowing for simple integration with Swagger/OpenAPI definitions
Generates React Query hooks from Swagger/OpenAPI definitions, providing data fetching capabilities with built-in caching for React applications
Parses Swagger/OpenAPI documents (v2 and v3) to extract API operations and schema definitions that can be used for generating TypeScript types and API clients
Swagger MCP 服务器
一个基于Model Context Protocol (MCP)的服务器,用于解析Swagger/OpenAPI文档并生成TypeScript类型和API客户端代码。
功能特点
- 解析Swagger/OpenAPI文档,支持v2和v3规范
- 生成TypeScript类型定义
- 生成不同框架的API客户端代码(Axios、Fetch、React Query等)
- 通过MCP协议提供这些功能,便于与大型语言模型集成
- 优化的大型文档处理:
- 内存和文件系统缓存机制
- 懒加载解析策略
- 增量解析与部分结果返回
- 进度反馈
- 自动识别不同格式的Swagger UI URLs
快速开始
安装依赖
启动服务器
服务器默认使用标准输入/输出通信。
使用MCP工具
可以通过标准输入/输出与MCP服务器通信。以下是一些示例:
可用工具
1. Swagger/OpenAPI解析工具
标准解析工具 (parse-swagger)
优化解析工具 (parse-swagger-optimized)
适用于完整解析,带有高级选项:
轻量级解析工具 (parse-swagger-lite)
为大型文档优化,快速但只返回基本信息:
2. TypeScript类型生成工具
标准类型生成器 (generate-typescript-types)
优化类型生成器 (generate-typescript-types-optimized)
3. API客户端生成工具
标准API客户端生成器 (generate-api-client)
优化API客户端生成器 (generate-api-client-optimized)
4. 文件写入工具
处理大型API文档
对于大型API文档,推荐使用以下配置:
- 使用优化版工具,启用缓存和懒加载
- 使用标签或路径前缀过滤,只获取需要的API操作
- 仅在必要时包含模式定义
- 设置合理的缓存有效期,避免频繁重新解析
示例:
支持的客户端框架
目前支持以下API客户端框架:
- Axios: 功能全面的Promise基HTTP客户端
- Fetch: 浏览器原生API,无需额外依赖
- React Query: 用于React应用的数据获取和缓存库,提供hooks和缓存功能
示例 - 生成React Query客户端:
缓存管理
API文档缓存存储在 .api-cache
目录中。如果需要清除缓存:
- 删除
.api-cache
目录 - 或者设置
useCache: false
参数
配置选项
可在 swagger-mcp-config.json
中自定义服务器设置:
开发与调试
启动调试服务器:
然后使用MCP Inspector连接:
或者直接方式(但可能导致输出混乱):
项目路线图
参见 road.md 文件了解开发计划和进度。
安装
通过Smithery安装
要通过Smithery为Claude Desktop自动安装swagger-mcp-server:
构建
可用的MCP工具
parse-swagger
- 解析Swagger/OpenAPI文档,返回API操作信息parse-swagger-optimized
- 解析Swagger/OpenAPI文档(优化版)parse-swagger-lite
- 轻量级解析Swagger/OpenAPI文档,专为大型文档优化generate-typescript-types
- 从Swagger/OpenAPI文档生成TypeScript类型定义generate-typescript-types-optimized
- 从Swagger/OpenAPI文档生成TypeScript类型定义(优化版)generate-api-client
- 从Swagger/OpenAPI文档生成API客户端代码generate-api-client-optimized
- 从Swagger/OpenAPI文档生成API客户端代码(优化版)file-writer
- 将内容写入文件系统
This server cannot be installed
local-only server
The server can only run on the client's local machine because it depends on local resources.
A server based on Model Context Protocol that parses Swagger/OpenAPI documents and generates TypeScript types and API client code for different frameworks (Axios, Fetch, React Query).
Related MCP Servers
- -securityAlicense-qualityAn MCP server that exposes HTTP methods defined in an OpenAPI specification as tools, enabling interaction with APIs via the Model Context Protocol.Last updated -2PythonMIT License
- AsecurityAlicenseAqualityA Model Context Protocol server that extracts embedded data (such as i18n translations or key/value configurations) from TypeScript/JavaScript source code into structured JSON configuration files.Last updated -2142JavaScriptMIT License
- -securityFlicense-qualityA server that enables Large Language Models to discover and interact with REST APIs defined by OpenAPI specifications through the Model Context Protocol.Last updated -7432JavaScript
- -securityAlicense-qualityA server that enables interaction with any API that has a Swagger/OpenAPI specification through Model Context Protocol (MCP), automatically generating tools from API endpoints and supporting multiple authentication methods.Last updated -11TypeScriptApache 2.0