OpenAPI规范查询工具

MCP(Model Context Protocol)服务器,使LLMs能够通过自然对话探索OpenAPI规范,查询端点、参数、请求体和响应模式。

  • by abumalick
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 abumalick/openapi-mcp

使用说明

@abumalick/openapi mcp

MCP(模型上下文协议)服务器,使LLM能够探索OpenAPI规范。加载任何OpenAPI规范,并通过自然对话查询其端点、参数、请求体和响应模式。

安装

npm install -g @abumalick/openapi-mcp

配置

您可以在启动时使用以下命令预加载OpenAPI规范 --spec 或 -s 带格式的标志 alias=url.

OpenCode

添加到您的OpenCode配置(~/.opencode/config.json):

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "openapi": {
      "type": "local",
      "command": ["npx", "-y", "@abumalick/openapi-mcp"],
      "enabled": true
    }
  }
}

预装规格:

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "openapi": {
      "type": "local",
      "command": [
        "npx", "-y", "@abumalick/openapi-mcp",
        "--spec", "petstore=https://petstore3.swagger.io/api/v3/openapi.yaml",
        "--spec", "myapi=https://api.example.com/openapi.json"
      ],
      "enabled": true
    }
  }
}

更多了解 在OpenCode中配置MCP服务器.

克劳德桌面版

添加到您的Claude桌面配置(~/Library/Application Support/Claude/claude_desktop_config.json 在macOS上):

{
  "mcpServers": {
    "openapi": {
      "command": "npx",
      "args": ["-y", "@abumalick/openapi-mcp"]
    }
  }
}

预装规格:

{
  "mcpServers": {
    "openapi": {
      "command": "npx",
      "args": [
        "-y", "@abumalick/openapi-mcp",
        "--spec", "petstore=https://petstore3.swagger.io/api/v3/openapi.yaml"
      ]
    }
  }
}

工作流示例

使用预加载的规范,LLM可以立即查询它们:

User: What specs are available?
Assistant: [calls openapi_list_specs] -> shows petstore is loaded

User: What endpoints are available for pets?
Assistant: [calls openapi_list_endpoints with alias="petstore", tag="pet"]

User: Show me details about the GET /pet/{petId} endpoint
Assistant: [calls openapi_get_endpoint with alias="petstore", method="GET", path="/pet/{petId}"]

在没有预加载的情况下,首先加载规范:

User: Load the Petstore API spec
Assistant: [calls openapi_load with source="https://petstore3.swagger.io/api/v3/openapi.yaml", alias="petstore"]

工具

openapi_list_spec

列出当前加载的所有OpenAPI规范。使用此功能查看可用内容。

{}

退货:

{
  "specs": [
    { "alias": "petstore", "title": "Swagger Petstore", "version": "1.0.0", "endpointCount": 19 }
  ]
}

openapi_load

从URL或文件路径加载OpenAPI规范。仅在未预加载规范时才需要。

{
  "source": "https://api.example.com/openapi.yaml",
  "alias": "example"
}

openapi_list_endpoints

列出具有可选筛选的端点。

{
  "alias": "example",
  "tag": "users",
  "search": "create"
}

openapi_get_端点

获取详细的端点信息。

{
  "alias": "example",
  "method": "POST",
  "path": "/users"
}

支持的OpenAPI版本

  • OpenAPI 3.0.x
  • OpenAPI 3.1.x

注意:Swagger 2.0规范应首先转换为OpenAPI 3.x格式。

发展

# Install dependencies
npm install

# Build
npm run build

# Run tests
npm test

# Development mode
npm run dev

许可证

麻省理工学院