MCP开放API模式服务器
一个暴露 OpenAPI 模式信息给像 Claude 这样的大型语言模型 (LLM) 的 MCP 服务器。该服务器允许 LLM 通过一组专用工具浏览和理解大型 OpenAPI 模式,而无需将整个模式加载到上下文中。
服务介绍
OpenAPI 模式模型上下文协议服务器
一个模型上下文协议 (MCP) 服务器,它将 OpenAPI 模式信息暴露给像 Claude 这样的大型语言模型 (LLMs)。该服务器允许 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 Desktop 集成
要与 Claude Desktop 一起使用此 MCP 服务器,请编辑您的 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
Claude Code 集成
要与 Claude Code CLI 一起使用此 MCP 服务器,请按照以下步骤操作:
-
将 OpenAPI 模式 MCP 服务器添加到 Claude Code
# 基本语法 claude mcp add openapi-schema npx -y mcp-openapi-schema # 特定模式的示例 claude mcp add petstore-api npx -y mcp-openapi-schema ~/Projects/petstore.yaml -
验证 MCP 服务器是否已注册
# 列出所有配置的服务器 claude mcp list # 获取您的 OpenAPI 模式服务器的详细信息 claude mcp get openapi-schema -
如果需要,移除服务器
claude mcp remove openapi-schema -
在 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.