Mcp Graphql Bridge

io.github.murilojrpereira由 GitHub 账号 murilojrpereira 发布v2.1.0更新于 Oct 24, 2026

Bridges any GraphQL API to Claude Code — auto-generates MCP tools via schema introspection.

已验证STDIO仅桌面数据库开发者工具

概览

AI 生成的概览

通过内省 GraphQL 架构,将每个查询和变更暴露为独立的 MCP 工具,从而把任意 GraphQL API 接入助手。

可以做什么
启动时它会内省 GraphQL 架构(或读取本地的 schema-introspection.json),为每个查询注册一个工具(query ),为每个变更注册一个工具(mutation ),并始终注册通用的 execute_graphql 回退工具和 get_type_details 探索工具。各操作工具支持 __fields 选择集,以及按调用传入的 bearer_token 和 custom_headers 覆盖参数。工具注册数量可设上限,也可禁用变更。
适用场景
当助手需要读取或写入某个特定 GraphQL API 时使用,尤其适合字段众多、逐个手写查询不便的大型架构。既可用于对公共演示 API 的零配置试用,也可用于需要认证的企业 API。
运行要求
需要 Node.js >= 20 和 npm 包 mcp-graphql-bridge(或从源码构建),以本地 stdio 进程运行。GRAPHQL_API_URL 和 GRAPHQL_INTROSPECTION_URL 指定端点,默认指向公共演示 API;GRAPHQL_TOKEN 和 GRAPHQL_INTROSPECTION_TOKEN 提供 Bearer 凭据。可选:GRAPHQL_MAX_TOOLS、GRAPHQL_INCLUDE_MUTATIONS、GRAPHQL_MAX_RETRIES,以及 HTTP 传输所需的 MCP_AUTH_TOKEN。
安装前请注意
GRAPHQL_TOKEN 和 GRAPHQL_INTROSPECTION_TOKEN 是发送给目标 API 的机密。变更默认启用,可能写入、修改或删除数据;只读使用请设置 GRAPHQL_INCLUDE_MUTATIONS=false。工具支持按调用传入 bearer_token 和 custom_headers 覆盖参数,因此每次请求都可提供凭据。目标主机由 GRAPHQL_API_URL 固定,不能按调用更改。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Mcp Graphql Bridge,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

mcp-graphql-bridge

[npm version] [CI] [License: MIT] [Node.js >= 20]

A generic MCP (Model Context Protocol) server that bridges any GraphQL API to Claude Code. It introspects your GraphQL schema and exposes each query and mutation as an individual tool, letting Claude interact with your API directly.

How it works

On startup the server will:

  1. Look for a schema-introspection.json file in the working directory (fast, no network call)
  2. If not found, run live introspection against GRAPHQL_INTROSPECTION_URL
  3. Register one tool per query (query__<name>) and one per mutation (mutation__<name>)
  4. Always register a generic execute_graphql fallback tool and a get_type_details explorer tool

Requirements

  • Node.js >= 20

Setup

Step 1: Install

Option A: Install from npm (recommended)
bash
npm install -g mcp-graphql-bridge
Option B: Clone and build from source
bash
git clone https://github.com/murilojrpereira/mcp-graphql-bridge.gitcd mcp-graphql-bridgenpm installnpm run build

Step 2: Configure environment variables

VariableRequiredDescription
GRAPHQL_API_URLNoEndpoint used for queries and mutations. Defaults to a public demo API (countries.trevorblades.com) if unset — replace with your own for real use.
GRAPHQL_INTROSPECTION_URLNoEndpoint used for schema introspection. Defaults to GRAPHQL_API_URL if unset.
GRAPHQL_TOKENNoBearer token for GraphQL authentication (used for query/mutation execution). Omit for public APIs.
GRAPHQL_INTROSPECTION_TOKENNoBearer token for schema introspection, if it requires different credentials than execution (e.g. a separate schema registry). Defaults to GRAPHQL_TOKEN if unset.
MCP_AUTH_TOKENNoBearer token required by the hosted /mcp HTTP endpoint when MCP_TRANSPORT=http
GRAPHQL_MAX_TOOLSNoMaximum number of query/mutation tools to register. Queries are prioritized over mutations when truncating. Default 128.
GRAPHQL_INCLUDE_MUTATIONSNoSet to false to exclude every mutation field entirely, for a read-only deployment. Default true.
GRAPHQL_MAX_RETRIESNoRetries (0–5) for 429/502/503/504 responses, honoring Retry-After when present. Default 0 (disabled).

For schemas with hundreds of fields (GitHub's GraphQL API has 284 root fields — 32 queries, 252 mutations), GRAPHQL_MAX_TOOLS and GRAPHQL_INCLUDE_MUTATIONS are what keep registration bounded and predictable. If the cap truncates the schema, stderr logs exactly how many queries/mutations were registered vs. available.

No configuration is required to try the server — with nothing set, it starts against the public demo API above and logs that it's doing so. See docs/architecture.md for the full token model and why the GraphQL endpoint is fixed per deployment rather than a per-request parameter.

You can set these in a .env file at the project root:

env
GRAPHQL_API_URL=https://your-api.example.com/graphqlGRAPHQL_INTROSPECTION_URL=https://your-api.example.com/graphqlGRAPHQL_TOKEN=your-bearer-token

Or pass them directly via the claude mcp add command (see below).

Step 3: (Optional) Pre-generate schema snapshot

By default the server introspects your schema live on startup — no file needed, and it automatically retries at a shallower query depth if your API rejects the full-depth attempt (some APIs, especially CDN-fronted ones, enforce a query depth limit). Use this step only if your API has introspection disabled entirely in production, or you want faster startup times:

bash
curl -s -X POST https://your-api.example.com/graphql \  -H "Content-Type: application/json" \  -H "Authorization: Bearer your-bearer-token" \  -d '{"query":"{ __schema { queryType { fields { name description args { name description defaultValue type { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name } } } } } } } } type { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name } } } } } } } } } mutationType { fields { name description args { name description defaultValue type { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name } } } } } } } } type { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name } } } } } } } } } } }"}' \  > schema-introspection.json

If your API rejects this with a depth/complexity-limit error, shrink the ofType { ... } nesting (each level resolves one more NonNull/List wrapper — most real-world types need 2-3 levels; only doubly-wrapped lists like [[Int!]!]! need more).

Adding to Claude Code

Option A: User scope (just for you)

If installed from npm:

bash
claude mcp add --transport stdio \  --env GRAPHQL_API_URL=https://your-api.example.com/graphql \  --env GRAPHQL_INTROSPECTION_URL=https://your-api.example.com/graphql \  --env GRAPHQL_TOKEN=your-bearer-token \  graphql-bridge -- mcp-graphql-bridge

If cloned from source:

bash
claude mcp add --transport stdio \  --env GRAPHQL_API_URL=https://your-api.example.com/graphql \  --env GRAPHQL_INTROSPECTION_URL=https://your-api.example.com/graphql \  --env GRAPHQL_TOKEN=your-bearer-token \  graphql-bridge -- node /absolute/path/to/mcp-graphql-bridge/dist/index.js

Important: Make sure to use mcp-graphql-bridge/dist/index.js (the compiled output), not mcp-graphql-bridge/index.js. The TypeScript source must be built first with npm run build, and the entry point is in the dist/ folder.

Option B: Project scope (shared with your team via .mcp.json)

bash
claude mcp add --transport stdio --scope project \  --env GRAPHQL_API_URL=https://your-api.example.com/graphql \  --env GRAPHQL_INTROSPECTION_URL=https://your-api.example.com/graphql \  --env GRAPHQL_TOKEN=your-bearer-token \  graphql-bridge -- mcp-graphql-bridge

Note: Use absolute paths. All --env and --transport flags must come before the server name.

Verify the connection

bash
claude mcp list

Then in a Claude Code session, run /mcp to see available servers and tools.

MCP Registry

This server is published to the official MCP Registry as io.github.murilojrpereira/mcp-graphql-bridge, so MCP clients that browse the registry can discover and install it from there.

Examples

Two worked walkthroughs — a small public schema with no configuration needed, then a large, real enterprise-scale schema requiring auth and tool-count limits.

Example 1: Countries API (small schema, no auth)

This is the zero-config default — nothing to install or configure beyond the server itself.

  1. Add the server with no environment variables at all:

    bash
    claude mcp add --transport stdio graphql-countries -- mcp-graphql-bridge
  2. Restart Claude Code (or run /mcp to confirm graphql-countries is connected). You should see tools like query__country, query__countries, and query__continents.

  3. Ask Claude:

    Using graphql-countries, find the country with code "BR", then list its continent's other countries.

    Claude calls query__country({ code: "BR", __fields: "{ name continent { code name } }" }), then query__continent or query__countries({ __fields: "{ name }" }) filtered by the result.

  4. Try an invalid code to see error passthrough:

    Look up the country with code "ZZZ".

    Returns the GraphQL API's own error text — the bridge passes it through rather than masking it.

Example 2: GitHub GraphQL API (large schema, auth + tool limits)

GitHub's GraphQL API has 284 root fields (32 queries, 252 mutations) — far more than the GRAPHQL_MAX_TOOLS default of 128, and it needs a token for every request, including introspection (unlike GitHub's REST API, which allows some anonymous reads).

  1. Add the server, scoped to read-only access:

    bash
    export GH_TOKEN=ghp_your_personal_access_token  # or: source a gitignored .env file first
    claude mcp add --transport stdio graphql-github \  --env GRAPHQL_API_URL=https://api.github.com/graphql \  --env GRAPHQL_INTROSPECTION_URL=https://api.github.com/graphql \  --env GRAPHQL_TOKEN=$GH_TOKEN \  --env GRAPHQL_INCLUDE_MUTATIONS=false \  graphql-bridge -- mcp-graphql-bridge

    GRAPHQL_INCLUDE_MUTATIONS=false registers all 32 (read-only) queries and zero mutations — comfortably under the cap, and a meaningfully safer default for an AI agent than exposing all 252 write operations.

  2. Ask Claude:

    Using graphql-github, look up the repository facebook/react and tell me its star count.

    Claude calls query__repository({ owner: "facebook", name: "react", __fields: "{ name stargazerCount }" }).

  3. To also reach mutations, drop GRAPHQL_INCLUDE_MUTATIONS=false and raise the cap (GRAPHQL_MAX_TOOLS=400), understanding that this exposes write access to your GitHub account scoped to whatever permissions your token has.

Available tools

ToolDescription
query__<name>One tool per GraphQL query field
mutation__<name>One tool per GraphQL mutation field
execute_graphqlGeneric fallback — run any query or mutation (mutations rejected if GRAPHQL_INCLUDE_MUTATIONS=false)
get_type_detailsExplore fields of a specific GraphQL type

All per-operation tools accept a special __fields argument where you can provide a custom GraphQL selection set (e.g. { id name status }). If omitted, only scalar fields are returned.

Per-call auth override: every tool (including execute_graphql) also accepts bearer_token and custom_headers arguments. If provided, they override GRAPHQL_TOKEN/no-auth for that single request only, letting Claude switch credentials per call without restarting the server.

Security

  • The target API is fixed per deployment, never a per-request parameter. Individual tool calls can override credentials (bearer_token, custom_headers) but never the destination host — GRAPHQL_API_URL is set once at deployment time. A shared server that let callers redirect it to an arbitrary destination would be a Server-Side Request Forgery (SSRF) primitive; this design rules that out by construction.
  • Configured and per-call secrets are redacted from every response before it reaches the calling LLM.
  • GRAPHQL_INCLUDE_MUTATIONS=false excludes every mutation field from registration for a genuinely read-only deployment — a meaningful trust boundary GraphQL's type system already encodes, rather than relying on token scope alone. This is enforced for execute_graphql too: it parses the query and rejects any mutation when this flag is off, rather than only omitting the convenience mutation__* tools while leaving the generic fallback able to run anything.
  • MCP_AUTH_TOKEN gates the HTTP transport's /mcp endpoint for public-routable deployments; requests are capped at 10MB.

See docs/architecture.md for the full design rationale and SECURITY.md to report a vulnerability.

Docker

Build the image

bash
docker build -t mcp-graphql-bridge .

Add to Claude Code via Docker

bash
claude mcp add --transport stdio \  --env GRAPHQL_API_URL=https://your-api.example.com/graphql \  --env GRAPHQL_INTROSPECTION_URL=https://your-api.example.com/graphql \  --env GRAPHQL_TOKEN=your-bearer-token \  graphql-bridge -- docker run -i --rm \  -e GRAPHQL_API_URL -e GRAPHQL_INTROSPECTION_URL -e GRAPHQL_TOKEN \  mcp-graphql-bridge

Note: The -i flag (no -t) is required — it keeps stdin open for the MCP stdio protocol.

HTTP deployment

For hosted MCP access, run the HTTP transport instead of stdio:

bash
docker build -f Dockerfile.http -t mcp-graphql-bridge-http .docker run --rm -p 8080:8080 \  -e GRAPHQL_API_URL=https://your-api.example.com/graphql \  -e GRAPHQL_INTROSPECTION_URL=https://your-api.example.com/graphql \  -e GRAPHQL_TOKEN=your-bearer-token \  mcp-graphql-bridge-http

Health checks are available at /health; MCP requests are served at /mcp.

For public-routable deployments, set MCP_AUTH_TOKEN and configure clients to send Authorization: Bearer <token> to /mcp.

See docs/deployment.md for AWS, Cloudflare, and other container hosting options.

Development

bash
npm run dev   # watch mode: rebuilds and restarts on file changesnpm run build # one-off TypeScript compilenpm start     # run the compiled server

See CONTRIBUTING.md for contribution guidelines and the maintainer release process.

Troubleshooting

Error: Cannot find module '.../index.js'

If you see an error like:

Error: Cannot find module '/path/to/mcp-graphql-bridge/index.js'

You are pointing to the wrong file. The TypeScript source must be compiled first, and the entry point is in the dist/ folder:

Correct path: /path/to/mcp-graphql-bridge/dist/index.js Wrong path: /path/to/mcp-graphql-bridge/index.js

Fix:

  1. Ensure you ran npm run build (creates the dist/ folder)
  2. Update your MCP configuration to use the full path ending in /dist/index.js

Schema introspection fails

If the server starts but shows "Schema introspection failed", your GraphQL API may have introspection disabled in production. Use the curl command in step 3 of Setup to pre-generate a schema-introspection.json file.

Tools not appearing in Claude Code

  1. Run claude mcp list to verify the server is registered
  2. Run /mcp in a Claude Code session to see available tools
  3. Check that your GraphQL API's environment variables are set correctly (GRAPHQL_API_URL, GRAPHQL_INTROSPECTION_URL, GRAPHQL_TOKEN) — these are optional and default to a public demo API, so if tools still aren't appearing with your own API configured, check its credentials and endpoint URLs

来源:README.md,提交 5eafd78

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

1
  1. v2.1.0最新Sep 16, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分