Graphql

io.github.Docat0209由 GitHub 账号 Docat0209 发布v0.1.4更新于 Oct 27, 2026

Turn any GraphQL API into MCP tools. Zero config, zero code.

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

概览

AI 生成的概览

通过内省 GraphQL 端点架构,把每个查询和变更自动变成 MCP 工具,让助手直接调用。

可以做什么
  • 通过内省发现 GraphQL 端点的查询与变更,并把每个操作暴露为独立工具
  • 用扁平化的简单参数调用查询和变更,无需嵌套输入对象
  • 通过包含/排除规则和工具名前缀限制暴露哪些操作
  • 自动裁剪数组、限制嵌套深度和总长度,控制过大的响应
  • 将内省架构缓存到本地以加快启动,并可强制刷新
  • 标记或屏蔽 delete、remove、drop、purge 等破坏性变更
适用场景
适合让助手直接使用某个 GraphQL API 而无需自己编写服务器,例如公开的国家信息 API 或需要令牌的 GitHub GraphQL API。适用于以读取为主的探索,配合安全设置也可进行受控的变更操作。
运行要求
通过 npx(Node.js)在本地以 stdio 进程运行,另有 SSE 传输选项。需要 GraphQL 端点地址及访问该端点的网络。认证可选,通过命令行参数传入:Bearer 令牌、API 密钥(放在请求头或查询参数)或自定义请求头。
安装前请注意
Bearer 令牌和 API 密钥以命令行参数形式提供,可能留在 shell 历史或客户端配置文件中。变更操作会作为工具暴露,可能修改或删除数据;默认模式只给出警告,建议使用安全模式排除破坏性操作。工具调用会把数据发送到所配置的第三方端点,可选的架构缓存文件会在本地保存端点地址。

安装

在 SourceWeft 中

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

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

其他 MCP 客户端

参照 仓库 中的启动说明。

README

graphql-to-mcp

[npm version] [npm downloads] [License: MIT]

Turn any GraphQL API into MCP tools — zero config, zero code.

Point graphql-to-mcp at a GraphQL endpoint and it auto-generates one MCP tool per query/mutation via introspection. Works with Claude Desktop, Cursor, Windsurf, and any MCP client.

Quick Start

Try it now — no install needed:

bash
npx graphql-to-mcp https://countries.trevorblades.com/graphql

Or add to Claude Desktop / Cursor config:

json
{  "mcpServers": {    "countries": {      "command": "npx",      "args": ["-y", "graphql-to-mcp", "https://countries.trevorblades.com/graphql"]    }  }}

That's it. Claude can now query countries, continents, and languages.

Features

  • Zero config — just provide a GraphQL endpoint URL
  • Auto-introspection — discovers all queries and mutations automatically
  • Flat parameter schemas — nested input objects are flattened for better LLM accuracy
  • Smart truncation — large responses are intelligently pruned (array slicing + depth limiting)
  • Auth support — Bearer tokens, API keys (header or query)
  • Retry logic — automatic retries on 429/5xx with exponential backoff
  • Include/exclude filters — expose only the operations you want
  • Schema caching — skip re-introspection with --schema-cache for faster startup
  • Mutation safety — auto-detect destructive mutations (delete*, remove*, etc.) and warn or block them

Usage

CLI

bash
# Public API (no auth)npx graphql-to-mcp https://countries.trevorblades.com/graphql
# With bearer tokennpx graphql-to-mcp https://api.github.com/graphql --bearer ghp_xxxxx
# With API keynpx graphql-to-mcp https://api.example.com/graphql --api-key "X-API-Key:your-key:header"
# Filter operationsnpx graphql-to-mcp https://api.example.com/graphql --include "get*" --exclude "internal*"
# With prefix (avoid name collisions when using multiple APIs)npx graphql-to-mcp https://api.example.com/graphql --prefix myapi
# Cache schema locally for faster restartsnpx graphql-to-mcp https://api.example.com/graphql --schema-cache ./schema.json
# Force re-introspection (ignore cache)npx graphql-to-mcp https://api.example.com/graphql --schema-cache ./schema.json --force-refresh
# Block destructive mutations (delete*, remove*, etc.)npx graphql-to-mcp https://api.example.com/graphql --mutation-safety safe

Claude Desktop / Cursor Config

json
{  "mcpServers": {    "github": {      "command": "npx",      "args": [        "-y", "graphql-to-mcp",        "https://api.github.com/graphql",        "--bearer", "ghp_xxxxx",        "--prefix", "github"      ]    }  }}

Programmatic

typescript
import { createServer } from "graphql-to-mcp";
const server = await createServer({  endpoint: "https://api.example.com/graphql",  auth: { type: "bearer", token: "xxx" },  include: ["getUser", "listUsers"],});

How It Works

  1. Introspect — Fetches the GraphQL schema via introspection query
  2. Flatten — Nested InputObject types are flattened into simple key-value parameters (e.g., input.name → input_name)
  3. Generate — Each query/mutation becomes an MCP tool with a flat JSON Schema
  4. Execute — When an LLM calls a tool, the flat args are reconstructed into proper GraphQL variables and sent to your endpoint

Why Flat Schemas?

LLMs are significantly better at filling flat key-value parameters than deeply nested JSON objects. By flattening InputObject types, we get:

  • Higher accuracy in parameter filling
  • Fewer hallucinated nested structures
  • Better compatibility across different LLM providers

Options

OptionDescriptionDefault
--bearer <token>Bearer token auth—
--api-key <name:value:in>API key auth—
-H, --header <name:value>Custom header (repeatable)—
--include <pattern>Include only matching operationsall
--exclude <pattern>Exclude matching operationsnone
--prefix <name>Tool name prefix—
--timeout <ms>Request timeout30000
--max-retries <n>Retry on 429/5xx3
--transport <stdio|sse>MCP transportstdio
--schema-cache <path>Save/load introspection cache—
--force-refreshIgnore cache, re-introspectfalse
--mutation-safety <mode>warn | safe | unrestrictedwarn

Smart Truncation

GraphQL APIs can return large payloads that overwhelm LLM context windows. graphql-to-mcp automatically:

  • Slices arrays to 20 items (with metadata showing total count)
  • Prunes depth beyond 5 levels (with object/array summaries)
  • Hard truncates at 50K characters as a safety net

Schema Caching

Introspection queries can be slow on large schemas. Use --schema-cache to save the introspection result locally:

bash
# First run: introspects and saves to cachenpx graphql-to-mcp https://api.example.com/graphql --schema-cache ./schema.json
# Subsequent runs: loads from cache (instant startup)npx graphql-to-mcp https://api.example.com/graphql --schema-cache ./schema.json
# Force re-introspection when the API schema changesnpx graphql-to-mcp https://api.example.com/graphql --schema-cache ./schema.json --force-refresh

The cache file stores the endpoint URL and timestamp. If you point at a different endpoint, it automatically re-introspects.

Mutation Safety

By default, graphql-to-mcp detects destructive mutations and adds warnings to their descriptions. This helps LLMs understand the risk before executing them.

Detected patterns: delete*, remove*, drop*, clear*, truncate*, destroy*, purge*, reset* (case-insensitive).

ModeBehavior
warn (default)Adds "DESTRUCTIVE:" prefix to dangerous mutation descriptions
safeCompletely excludes dangerous mutations from the tool list
unrestrictedNo filtering or warnings (previous behavior)
bash
# Safe mode: only expose read queries + non-destructive mutationsnpx graphql-to-mcp https://api.example.com/graphql --mutation-safety safe
# Unrestricted: expose everything (use with caution)npx graphql-to-mcp https://api.example.com/graphql --mutation-safety unrestricted

Use with REST APIs Too

Pair with mcp-openapi to give Claude access to both REST and GraphQL APIs:

json
{  "mcpServers": {    "github-graphql": {      "command": "npx",      "args": ["-y", "graphql-to-mcp", "https://api.github.com/graphql", "--bearer", "ghp_xxx", "--prefix", "gh"]    },    "petstore-rest": {      "command": "npx",      "args": ["-y", "mcp-openapi", "https://petstore3.swagger.io/api/v3/openapi.json"]    }  }}

Related

  • mcp-openapi — Same zero-config approach for REST/OpenAPI APIs

License

MIT

来源:README.md,提交 3c6934d

工具

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

版本历史

1
  1. v0.1.4最新Sep 16, 2026

评分

已满足适用检查项的 50%

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

  • 近 30 天内可连通25 分

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

  • 已声明认证方式10 分

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

  • 已列出工具15 分

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

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