graphql-mcp
MCP server that exposes GraphQL operations as typed tools for AI models, with schema exploration, validation, execution, hot reload, OAuth, prompts, MCP Apps widgets, and OpenTelemetry support.
README
Experimental PoC
graphql-mcp
An MCP (Model Context Protocol) server that exposes GraphQL operations as tools for AI models. Point it at any GraphQL endpoint and a schema, and it turns your operations into typed MCP tools — with schema exploration tools, hot reload, OAuth resource-server auth, MCP prompts, MCP Apps widgets, and OpenTelemetry built in.
Configuration is plain TypeScript — no YAML, no env-var templating; read
process.env directly in your config file.
Quick start
npm install graphql-mcp # or pnpm add / vp add
Create graphql-mcp.config.ts:
import { defineConfig } from "graphql-mcp";
export default defineConfig({
endpoint: "http://localhost:4000/graphql",
schema: { source: "local", path: "./schema.graphql" },
operations: { source: "local", paths: ["./operations"] },
tools: {
introspect: { enabled: true },
search: { enabled: true },
validate: { enabled: true },
execute: { enabled: true },
},
});
Run it:
graphql-mcp # stdio transport (default)
graphql-mcp path/to/config.ts # explicit config path
Local schema files, operation files, prompt files, and the config file itself
are watched: edits hot reload without dropping connected sessions (config
changes trigger a validated in-process restart; SIGHUP forces one).
How operations become tools
Every named GraphQL operation in your operation files becomes one MCP tool:
- The tool name is the operation name; leading
#comments become the tool description (otherwise one is generated from schema descriptions plus the tree-shaken SDL of the types the operation touches). - The input schema is derived from the operation's variables (non-null
variables are required; input objects, enums, lists, and custom scalars are
fully expanded).
#comments before individual variables override their descriptions. - Queries are annotated read-only and idempotent; mutations destructive.
Mutations are skipped unless
overrides.mutationModeisexplicitorall. - Fields marked
@privateare stripped from the query sent downstream and filtered out of the structured result the model sees (the full response is preserved in_meta.structuredContentfor the host client).
Operation sources: local (watched .graphql files/directories), manifest
(a local apollo-persisted-query-manifest v1 JSON file), or none.
Schema tools
Four individually toggleable tools under tools:
| Tool | What it does |
|---|---|
introspect |
Returns the SDL for a named type, recursing to a depth; optional token-cheap minified encoding. |
search |
Full-text search over type names, descriptions, and fields; returns tree-shaken SDL along scored paths from the root types. |
validate |
Validates an operation against the schema without executing it. |
execute |
Executes an ad hoc operation written by the model (mutations only when mutationMode: "all"). |
Each accepts an optional hint appended to its description.
Transports
stdio(default) — for local MCP clients.http— streamable HTTP on/mcpwith per-session state (or stateless viastatefulMode: false), CORS, Host/Origin validation against DNS rebinding, a/healthendpoint (?live/?ready), and graceful shutdown.
OAuth 2.1 resource server
Nest auth under the HTTP transport to require bearer tokens:
transport: {
type: "http",
port: 8000,
auth: {
servers: ["https://auth.example.com"], // OIDC/OAuth discovery + JWKS
audiences: ["my-api"],
scopes: ["read:graphql"],
scopeMode: "require_all",
},
},
overrides: {
requiredScopes: { DeleteUser: ["admin"] }, // per-operation step-up
},
The server publishes RFC 9728 protected-resource metadata at
/.well-known/oauth-protected-resource, answers challenges with
WWW-Authenticate (including insufficient_scope), and passes validated
tokens through to the GraphQL endpoint (disable with
disableAuthTokenPassthrough).
Prompts and MCP Apps
prompts: { directory: "./prompts" }serves Markdown files with YAML frontmatter (name,description,arguments) as MCP prompts, with{{arg}}substitution and hot reload.apps: { directory: "./apps" }serves MCP Apps: each subdirectory with an.application-manifest.jsoncontributes aui://widget/...HTML resource and entrypoint tools backed by GraphQL operations, including prefetch operations, extra inputs/outputs, CSP and widget settings, and OpenAI-Apps-SDK/MCP-Apps targeting via?appTarget=or client capabilities.
Telemetry
telemetry: {
serviceName: "my-graphql-mcp",
exporters: {
metrics: { otlp: { protocol: "http/protobuf" } },
tracing: { otlp: { endpoint: "http://collector:4318/v1/traces" } },
},
},
Emits graphql_mcp.operation.count / graphql_mcp.operation.duration
metrics and per-tool-call spans, with configurable attribute omission,
export interval, and sampler.
Config reference
Top-level keys (all optional except schema):
| Key | Purpose |
|---|---|
endpoint |
Target GraphQL URL (default http://localhost:4000/graphql). |
schema |
{ source: "local", path, watch? } — the SDL file to serve from. |
operations |
local paths, manifest file, or none. |
transport |
{ type: "stdio" } or { type: "http", address?, port?, statefulMode?, hostValidation?, auth? }. |
tools |
Enable/configure introspect, search, validate, execute. |
overrides |
mutationMode, descriptions, annotations, requiredScopes, enableOutputSchema, disableTypeDescription, disableSchemaDescription. |
headers / forwardHeaders |
Static headers and client headers forwarded to GraphQL. |
cors, healthCheck |
HTTP transport policies. |
serverInfo, instructions |
MCP identity and initialize instructions. |
customScalars |
Inline map of scalar name to JSON Schema, or a path to a JSON file. |
prompts, apps |
Prompt and MCP App directories. |
logging |
level, optional path (rotating file logs), rotation. |
telemetry |
OpenTelemetry metrics/tracing via OTLP. |
The config is validated with helpful errors; unknown keys are rejected. See examples/graphql-mcp.config.ts for a commented full example.
Development
vp install # install dependencies
vp check # format, lint, type check
vp test # run the test suite
vp pack # build dist/ (library + CLI)
Acknowledgements
The behavior of this server is a TypeScript reimplementation inspired by the MIT-licensed Apollo MCP Server (Rust), excluding its GraphOS-specific functionality.
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。