GraphQL to MCP Server

1

Add it to Claude Code

Run this in a terminal.

Run in terminal
claude mcp add graphql-to-mcp -- npx -y graphql-to-mcp "<endpoint-url>"
README.md

Turn any GraphQL API into MCP tools with zero config and zero code.

graphql-to-mcp

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:

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

Or add to Claude Desktop / Cursor config:

{
  "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

# Public API (no auth)
npx graphql-to-mcp https://countries.trevorblades.com/graphql

# With bearer token
npx graphql-to-mcp https://api.github.com/graphql --bearer ghp_xxxxx

# With API key
npx graphql-to-mcp https://api.example.com/graphql --api-key "X-API-Key:your-key:header"

# Filter operations
npx 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 restarts
npx 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

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

Programmatic

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.nameinput_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

Option Description Default
--bearer <token> Bearer token auth
--api-key <name:value:in> API key auth
-H, --header <name:value> Custom header (repeatable)
--include Include only matching operations all
--exclude Exclude matching operations none
--prefix <name> Tool name prefix
--timeout <ms> Request timeout 30000
--max-retries <n> Retry on 429/5xx 3
--transport <stdio|sse> MCP transport stdio
--schema-cache Save/load introspection cache
--force-refresh Ignore cache, re-introspect false
--mutation-safety <mode> warn | safe | unrestricted warn

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 truncate

Tools (1)

dynamic-graphql-operationsDynamically generated tools based on the GraphQL schema introspection of the provided endpoint.

Configuration

claude_desktop_config.json
{"mcpServers": {"my-api": {"command": "npx", "args": ["-y", "graphql-to-mcp", "https://api.example.com/graphql"]}}}

Try it

Fetch the list of all countries and their capital cities from the GraphQL API.
Get the details for the user with ID 123 using the GraphQL mutation.
List all available queries and mutations provided by the connected GraphQL endpoint.
Find the top 5 repositories for the organization 'facebook' using the GitHub GraphQL API.

Frequently Asked Questions

What are the key features of GraphQL to MCP?

Auto-introspection of GraphQL queries and mutations. Flat parameter schemas for improved LLM accuracy. Smart response truncation for large payloads. Automatic retry logic with exponential backoff. Mutation safety modes to prevent destructive operations.

What can I use GraphQL to MCP for?

Connecting Claude to public GraphQL APIs like Countries or GitHub. Rapidly prototyping LLM-based interfaces for internal GraphQL services. Managing complex API interactions without writing custom integration code. Safely exploring and testing GraphQL mutations via natural language.

How do I install GraphQL to MCP?

Install GraphQL to MCP by running: npx graphql-to-mcp <endpoint-url>

What MCP clients work with GraphQL to MCP?

GraphQL to MCP works with any MCP-compatible client including Claude Desktop, Claude Code, Cursor, and other editors with MCP support.

Turn this server into reusable context

Keep GraphQL to MCP docs, env vars, and workflow notes in Conare so your agent carries them across sessions.

Need the old visual installer? Open Conare IDE.
Open Conare