G

GraphQL模型上下文工具箱

@kailashAppDev/graphql-mcp-toolkit
0 Stars 325 次浏览 kailashAppDev 更新于 2026-08-23

一种模型上下文协议服务器,通过提供模式内省和查询执行功能,使大型语言模型能够与GraphQL API进行交互。

MCP 服务配置

复制以下 JSON 到 OPClaw 或其他 MCP 客户端的配置文件中即可使用

{
  "mcpServers": {
    "mcp-graphql": {
      "args": [
        "mcp-graphql",
        "--endpoint",
        "http://localhost:3000/graphql"
      ],
      "command": "npx"
    }
  }
}

该服务需要配置环境变量:enable-mutations、endpoint、headers、name、schema

服务介绍

mcp-graphql

smithery badge

一个模型上下文协议服务器,使大型语言模型能够与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

可用工具

服务器提供两个主要工具:

  1. introspect-schema: 此工具检索 GraphQL 模式。如果您无法访问模式作为资源,请首先使用此工具。
    这将使用本地模式文件或内省查询。

  2. 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,并锁定工具调用,以便客户端仅输入特定的查询字段和/或变量。您可以参考此实现。

相关 MCP 服务