OpenAPI模式解析服务

一个为大型语言模型(LLMs)提供OpenAPI规范解析和探索功能的服务器,支持加载、查询和搜索API规范。

  • by hannesj
  • JavaScript
  • 本地部署
  • 50 星标
  • 更新于
在 GitHub 查看 hannesj/mcp-openapi-schema

使用说明

OpenAPI模式模型上下文协议服务器

一个模型上下文协议(MCP)服务器,将OpenAPI模式信息暴露给像Claude这样的大型语言模型(LLM)。该服务器允许LLM通过一组专用工具探索和理解OpenAPI规范。

特性

  • 加载通过命令行参数指定的任何OpenAPI模式文件(JSON或YAML)
  • 探索API路径、操作、参数和架构
  • 查看详细的请求和响应模式
  • 查找组件定义和示例
  • 搜索整个API规范
  • 获取YAML格式的响应,以更好地理解LLM

用法

命令行

使用特定的架构文件运行MCP服务器:

# Use the default openapi.yaml in current directory
npx -y mcp-openapi-schema

# Use a specific schema file (relative path)
npx -y mcp-openapi-schema ../petstore.json

# Use a specific schema file (absolute path)
npx -y mcp-openapi-schema /absolute/path/to/api-spec.yaml

# Show help
npx -y mcp-openapi-schema --help

Claude桌面集成

要将此MCP服务器与Claude Desktop一起使用,请编辑您的 claude_desktop_config.json 配置文件:

{
  "mcpServers": {
    "OpenAPI Schema": {
      "command": "npx",
      "args": ["-y", "mcp-openapi-schema", "/ABSOLUTE/PATH/TO/openapi.yaml"]
    }
  }
}

配置文件的位置:

  • macOS/Linux: ~/Library/Application Support/Claude/claude_desktop_config.json
  • 窗户: $env:AppData\Claude\claude_desktop_config.json

Claude代码集成

要将此MCP服务器与Claude Code CLI一起使用,请执行以下步骤:

  1. 将OpenAPI模式MCP服务器添加到Claude代码中

    # Basic syntax
    claude mcp add openapi-schema npx -y mcp-openapi-schema
    
    # Example with specific schema
    claude mcp add petstore-api npx -y mcp-openapi-schema ~/Projects/petstore.yaml
    
  2. 验证MCP服务器是否已注册

    # List all configured servers
    claude mcp list
    
    # Get details for your OpenAPI schema server
    claude mcp get openapi-schema
    
  3. 如果需要,请删除服务器

    claude mcp remove openapi-schema
    
  4. 使用Claude Code中的工具

    配置后,您可以在Claude Code会话中通过询问有关OpenAPI模式的问题来调用该工具。

提示:

  • 使用 -s 或 --scope 旗与 project (默认)或 global 指定配置的存储位置
  • 为具有不同名称的不同API添加多个MCP服务器

MCP工具

服务器为LLM与OpenAPI模式交互提供了以下工具:

  • list-endpoints:列出所有API路径及其HTTP方法,其中包含嵌套对象结构中的摘要
  • get-endpoint:获取有关特定终结点的详细信息,包括参数和响应
  • get-request-body:获取特定终结点和方法的请求体架构
  • get-response-schema:获取特定终结点、方法和状态代码的响应架构
  • get-path-parameters:获取特定路径的参数
  • list-components:列出所有架构组件(架构、响应、参数等)
  • get-component:获取特定组件的详细定义
  • list-security-schemes:列出所有可用的安全方案
  • get-examples:获取特定组件或终结点的示例
  • search-schema:跨路径、操作和架构搜索

例子

要尝试的示例查询:

What endpoints are available in this API?
Show me the details for the POST /pets endpoint.
What parameters does the GET /pets/{petId} endpoint take?
What is the request body schema for creating a new pet?
What response will I get from the DELETE /pets/{petId} endpoint?
What schemas are defined in this API?
Show me the definition of the Pet schema.
What are the available security schemes for this API?
Are there any example responses for getting a pet by ID?
Search for anything related to "user" in this API.