MCP-GraphQL模式服务
一个MCP服务器,向类似Claude的大型语言模型(LLM)暴露GraphQL模式信息。该服务器允许大型语言模型通过一组专用工具探索和理解大型GraphQL模式,而无需将整个模式加载到上下文中。
服务介绍
GraphQL 模式模型上下文协议服务器
这是一个模型上下文协议 (MCP) 服务器,它将 GraphQL 模式信息暴露给像 Claude 这样的大型语言模型 (LLMs)。这个服务器允许 LLM 通过一组专门的工具来探索和理解 GraphQL 模式。
特性
- 通过命令行参数加载任何指定的 GraphQL 模式文件
- 探索查询、变更和订阅字段
- 查找详细的类型定义
- 使用模式匹配搜索类型和字段
- 获取简化后的字段信息,包括类型和参数
- 过滤掉内部的 GraphQL 类型以获得更清晰的结果
使用方法
命令行
使用特定的模式文件运行 MCP 服务器:
# Use the default schema.graphqls in current directory
npx -y mcp-graphql-schema
# Use a specific schema file (relative path)
npx -y mcp-graphql-schema ../schema.shopify.2025-01.graphqls
# Use a specific schema file (absolute path)
npx -y mcp-graphql-schema /absolute/path/to/schema.graphqls
# Show help
npx -y mcp-graphql-schema --help
Claude 桌面集成
要将此 MCP 服务器与 Claude 桌面版一起使用,请编辑您的 claude_desktop_config.json 配置文件:
{
"mcpServers": {
"GraphQL Schema": {
"command": "npx",
"args": ["-y", "mcp-graphql-schema", "/ABSOLUTE/PATH/TO/schema.graphqls"]
}
}
}
配置文件的位置:
- macOS/Linux:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
$env:AppData\Claude\claude_desktop_config.json
Claude 代码集成
要将此 MCP 服务器与 Claude Code CLI 一起使用,请按照以下步骤操作:
-
将 GraphQL 模式 MCP 服务器添加到 Claude Code
# 基本语法 claude mcp add graphql-schema npx -y mcp-graphql-schema # 具体示例 claude mcp add shopify-graphql-schema npx -y mcp-graphql-schema ~/Projects/work/schema.shopify.2025-01.graphqls -
验证 MCP 服务器是否已注册
# 列出所有配置的服务器 claude mcp list # 获取您的 GraphQL 模式服务器的详细信息 claude mcp get graphql-schema -
如果需要,移除服务器
claude mcp remove graphql-schema -
在 Claude Code 中使用该工具
一旦配置完成,您可以通过询问关于 GraphQL 模式的相关问题,在 Claude Code 会话中调用该工具。
提示:
- 使用
-s或--scope标志并指定project(默认)或global来确定配置存储位置 - 可以使用不同的名称为不同的模式添加多个 MCP 服务器(例如,主 API 模式,Shopify 模式)
MCP 工具
服务器提供了以下工具供 LLM 与 GraphQL 模式交互:
list-query-fields: 列出所有可用的 GraphQL 查询根级字段get-query-field: 以 SDL 格式获取特定查询字段的详细定义list-mutation-fields: 列出所有可用的 GraphQL 变更根级字段get-mutation-field: 以 SDL 格式获取特定变更字段的详细定义list-subscription-fields: 列出所有可用的 GraphQL 订阅根级字段(如果模式中存在)get-subscription-field: 获取特定订阅字段的详细定义(如果模式中存在)list-types: 列出在 GraphQL 模式中定义的所有类型(不包括内部类型)get-type: 以 SDL 格式获取特定 GraphQL 类型的详细定义get-type-fields: 获取特定 GraphQL 对象类型的简化字段及其类型列表search-schema: 通过名称模式(不区分大小写的正则表达式)搜索模式中的类型或字段
示例
可以尝试的示例查询:
What query fields are available in this GraphQL schema?
Show me the details of the "user" query field.
What mutation operations can I perform in this schema?
List all types defined in this schema.
Show me the definition of the "Product" type.
List all fields of the "Order" type.
Search for types and fields related to "customer".