MCP GraphQL工具
用于与GraphQL服务器一起工作的MCP。
MCP 服务配置
复制以下 JSON 到 OPClaw 或其他 MCP 客户端的配置文件中即可使用
{
"mcpServers": {
"mcp-graphql": {
"args": [
"mcp-graphql",
"--endpoint",
"http://localhost:3000/graphql"
],
"command": "npx"
}
}
}
可用工具 (2 个)
该服务在 MCP 协议中暴露的工具,AI 可按需调用
introspect-schema 2 个参数
Introspect the GraphQL schema, use this tool before doing a query to get the schema information if you do not have it available as a resource already.
该工具无需必填参数,直接调用即可
query-graphql 4 个参数 需填 1 项
Query a GraphQL endpoint with the given query and variables
必填参数:query
服务介绍
mcp-graphql
这是一个模型上下文协议(MCP)服务器,它使大型语言模型(LLMs)能够与GraphQL API进行交互。此实现提供了模式内省和查询执行功能,允许模型动态地发现和使用GraphQL API。
用法
使用正确的端点运行 mcp-graphql,它将自动尝试内省您的查询。
命令行参数
| 参数 | 描述 | 默认值 |
|---|---|---|
--endpoint |
GraphQL 端点 URL | http://localhost:4000/graphql |
--headers |
包含请求头的 JSON 字符串 | {} |
--enable-mutations |
启用变异操作(默认禁用) | false |
--name |
MCP 服务器名称 | mcp-graphql |
--schema |
本地 GraphQL 模式文件路径(可选) | - |
示例
# Basic usage with a local GraphQL server
npx mcp-graphql --endpoint http://localhost:3000/graphql
# Using with custom headers
npx mcp-graphql --endpoint https://api.example.com/graphql --headers '{"Authorization":"Bearer token123"}'
# Enable mutation operations
npx mcp-graphql --endpoint http://localhost:3000/graphql --enable-mutations
# Using a local schema file instead of introspection
npx mcp-graphql --endpoint http://localhost:3000/graphql --schema ./schema.graphql
可用工具
服务器提供两个主要工具:
-
introspect-schema: 此工具检索 GraphQL 模式。如果您没有访问模式资源的权限,请首先使用此工具。
这会使用本地模式文件或内省查询。 -
query-graphql: 对端点执行 GraphQL 查询。默认情况下,除非指定了
--enable-mutations,否则禁用变异操作。
资源
- graphql-schema: 服务器将 GraphQL 模式作为客户端可以访问的资源公开。这要么是本地模式文件,要么基于内省查询。
安装
通过 Smithery 安装
要通过 Smithery 自动为 Claude Desktop 安装 GraphQL MCP 服务器:
npx -y @smithery/cli install mcp-graphql --client claude
手动安装
可以手动安装到 Claude:
{
"mcpServers": {
"mcp-graphql": {
"command": "npx",
"args": ["mcp-graphql", "--endpoint", "http://localhost:3000/graphql"]
}
}
}
安全注意事项
默认情况下,禁用变异操作作为一种安全措施,以防止 LLM 修改您的数据库或服务数据。在生产环境中启用变异操作前请仔细考虑。
为自己的服务器自定义
这是一个非常通用的实现,它允许完全内省,并允许您的用户执行任何操作(包括变异)。如果您需要更具体的实现,建议创建自己的 MCP 并锁定工具调用,以便客户端只能输入特定的查询字段和/或变量。您可以将此作为参考。