OpenAPI 模式模型上下文协议服务器
一个模型上下文协议 (MCP) 服务器,用于向 Claude 等大型语言模型 (LLM) 公开 OpenAPI 架构信息。该服务器允许 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
- Windows:
$env:AppData\Claude\claude_desktop_config.json
克劳德代码集成
要将此 MCP 服务器与 Claude Code CLI 一起使用,请按照以下步骤操作:
- 将 OpenAPI Schema 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
- 验证 MCP 服务器是否已注册
# List all configured servers
claude mcp list
# Get details for your OpenAPI schema server
claude mcp get openapi-schema
- 如果需要,删除服务器
claude mcp remove openapi-schema
- 使用 Claude Code 中的工具配置完成后,您可以通过询问有关 OpenAPI 模式的问题在 Claude Code 会话中调用该工具。
尖端:
- 使用
-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.