API文档检索工具

基于MCP协议的Swagger/OpenAPI文档检索工具,可智能清理和优化文档结构,减少令牌消耗,并为智能IDE提供标准化格式的API文档。

  • by bluechenchenchen
  • JavaScript
  • 本地部署
  • 2 星标
  • 更新于
在 GitHub 查看 bluechenchenchen/api-mcp-server

使用说明

api mcp服务器

英语| 简体中文

API MCP Server

A Swagger/OpenAPI Documentation Retrieval Tool Based on MCP (Model Context Protocol)



这是一个基于MCP(模型上下文协议)的Swagger/OpenAPI文档检索工具。它可以从指定的URL获取和解析Swagger/OpenAPI文档,智能地清理和优化文档以减少令牌消耗,并以标准化的格式将其提供给智能IDE(如Cursor)。该工具支持多种传输方法,使IDE可以轻松地检索和理解API文档,从而实现界面建议、自动实现和代码生成等智能功能。

✨ 特性

  • 智能文档处理

    • 从远程URL获取Swagger/OpenAPI文档
    • 支持Swagger 2.0和OpenAPI 3.x格式
    • 智能清理和优化文档结构以减少令牌消耗
    • 提取关键API信息,包括端点、参数、响应格式等。
  • IDE友好设计

    • API标准化描述格式
    • 自动生成示例请求和响应
    • 智能参数提示和类型推理
    • 支持代码自动完成和生成
  • 多种运输方式

    • stdio:命令行工具的标准输入/输出模式
    • http:支持RESTful接口的http服务器模式
    • sse:用于实时通信的服务器发送事件模式

入门指南

MacOS/Linux

{
  "mcpServers": {
    "api-mcp-server": {
      "command": "npx",
      "args": [
        "-y",
        "api-mcp-server",
        "--transport",
        "stdio",
        "--doc-url",
        "xxx"
      ]
    }
  }
}

视窗

{
  "mcpServers": {
    "api-mcp-server": {
      "command": "cmd",
      "args": [
        "/c",
        "npx",
        "-y",
        "api-mcp-server",
        "--transport",
        "stdio",
        "--doc-url",
        "xxx"
      ]
    }
  }
}

命令行参数

  • --transport <stdio|http|sse>:选择传输方式(默认:stdio)
  • --port <number>:HTTP/SSE服务器端口(默认值:3000)
  • --doc-url <url>:Swagger/OpenAPI文档URL(必填)

使用示例

1.基本用法

# Using stdio mode (default)
npx -y api-mcp-server --doc-url https://api.example.com/swagger.json

# Using HTTP mode
npx -y api-mcp-server --transport http --doc-url https://api.example.com/swagger.json

# Using SSE mode with custom port
npx -y api-mcp-server --transport sse --port 3001 --doc-url https://api.example.com/swagger.json

💻 发展

# Clone the repository
git clone https://github.com/bluechenchenchen/api-mcp-server.git

# Install dependencies
pnpm install

# Run in development mode
pnpm dev

# Build
pnpm build

调试

使用@modelcontextprotocol/检查器

npx @modelcontextprotocol/inspector

运行示例

pnpm example

📋 需求

  • Node.js>=16.0.0
  • npm>=6.0.0或pnpm>=6.0.0

📄 许可证

麻省理工学院