GraphQL MCP Server

GraphQL MCP Server

A generic MCP server that converts .graphql query files into tools for Claude, enabling interaction with any GraphQL API without coding.

Category
Visit Server

README

GraphQL MCP Server

Turn any GraphQL API into Claude Code tools with zero coding

A generic Model Context Protocol (MCP) server that automatically converts your .graphql query files into tools Claude can use. Works with any GraphQL API - GitHub, Shopify, Hasura, or your own.

What It Does

  • Point it at any GraphQL endpoint (GitHub, Shopify, Hasura, etc.)
  • Drop .graphql query files in a folder
  • Automatically exposes them as Claude Code tools

No MCP coding required - just write GraphQL queries and configure the endpoint.

Why Use This?

Token Savings

GraphQL lets you request only the fields you need, dramatically reducing response size:

API Type Response Size Tokens Used Savings
REST 168 KB ~42,000 -
GraphQL (minimal) 500 bytes ~125 99.7%
GraphQL (targeted) 5 KB ~1,250 97%

Convenience

Instead of writing custom MCP server code for each API, just:

  1. Configure the endpoint
  2. Write GraphQL queries
  3. Done

Installation

Clone and build from source:

git clone https://github.com/Chakit22/graphql-mcp-server.git
cd graphql-mcp-server
npm install
npm run build

Quick Start

1. Create a project directory

mkdir my-graphql-mcp
cd my-graphql-mcp
mkdir operations

2. Create config.json

{
  "endpoint": "https://api.github.com/graphql",
  "operationsDir": "./operations",
  "headers": {
    "Authorization": "Bearer YOUR_TOKEN_HERE"
  },
  "name": "my-mcp-server",
  "version": "1.0.0"
}

3. Create GraphQL query files

Create operations/GetRepository.graphql:

# @description Get repository information

query GetRepository($owner: String!, $name: String!) {
  repository(owner: $owner, name: $name) {
    name
    description
    stargazerCount
    url
  }
}

4. Configure Claude Code

Add to ~/.config/claude-code/mcp_settings.json:

{
  "mcpServers": {
    "my-graphql-mcp": {
      "command": "node",
      "args": ["/path/to/graphql-mcp-server/dist/index.js"],
      "env": {
        "GRAPHQL_MCP_CONFIG": "/path/to/my-graphql-mcp/config.json"
      }
    }
  }
}

5. Restart Claude Code

The MCP server will automatically load your GraphQL operations as tools.

Configuration Reference

config.json

Field Type Required Description
endpoint string Yes GraphQL API endpoint URL
operationsDir string Yes Path to directory containing .graphql files
headers object No HTTP headers (e.g., Authorization)
name string No MCP server name (default: "graphql-mcp-server")
version string No MCP server version (default: "1.0.0")

Environment Variables

  • GRAPHQL_MCP_CONFIG: Path to config file (default: ./config.json)

Writing GraphQL Operations

Basic Query

# @description Brief description shown in Claude

query OperationName($param1: String!, $param2: Int) {
  field1
  field2
}

Features

  • @description comment: Appears in Claude's tool list
  • Variables: Automatically become tool parameters
  • Type support: String, Int, Float, Boolean, ID, arrays
  • Required params: Variables ending with ! are required

Example: Search Query

# @description Search repositories by keyword

query SearchRepos($query: String!, $limit: Int!) {
  search(query: $query, type: REPOSITORY, first: $limit) {
    repositoryCount
    edges {
      node {
        ... on Repository {
          name
          url
          stargazerCount
        }
      }
    }
  }
}

Examples

SpaceX API (No Auth Required - Try This First!)

Perfect for testing - works immediately without API keys.

Config:

{
  "endpoint": "https://spacex-production.up.railway.app/",
  "operationsDir": "./operations",
  "name": "spacex-mcp"
}

Available Operations:

  • GetRockets - Get all SpaceX rockets
  • GetLaunches - Get recent launches

πŸ“ Full example: examples/spacex/

GitHub API

Config:

{
  "endpoint": "https://api.github.com/graphql",
  "operationsDir": "./operations",
  "headers": {
    "Authorization": "Bearer ghp_YOUR_TOKEN"
  }
}

Available Operations:

  • GetRepository - Get repo details
  • SearchRepositories - Search repos by keyword

πŸ“ Full example: examples/github/

Shopify API

Config:

{
  "endpoint": "https://YOUR_STORE.myshopify.com/admin/api/2024-01/graphql.json",
  "operationsDir": "./operations",
  "headers": {
    "X-Shopify-Access-Token": "YOUR_TOKEN"
  }
}

Available Operations:

  • GetProducts - Get products with pagination

πŸ“ Full example: examples/shopify/

Hasura / Self-Hosted

Config:

{
  "endpoint": "http://localhost:8080/v1/graphql",
  "operationsDir": "./operations",
  "headers": {
    "x-hasura-admin-secret": "YOUR_SECRET"
  }
}

How It Works

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Claude  │────▢│  MCP Server  │────▢│ GraphQL API    β”‚
β”‚   Code   β”‚     β”‚  (this tool) β”‚     β”‚ (any endpoint) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                        β”‚
                        β–Ό
                 Loads *.graphql
                 from operations/
  1. MCP server reads all .graphql files from operationsDir
  2. Registers each as a Claude Code tool
  3. When Claude calls a tool:
    • Sends GraphQL query to configured endpoint
    • Passes variables from Claude
    • Returns response to Claude

Development

# Install dependencies
npm install

# Build TypeScript
npm run build

# Run in dev mode (with auto-reload)
npm run dev

# Run built version
npm start

Troubleshooting

"Configuration file not found"

  • Check GRAPHQL_MCP_CONFIG environment variable
  • Ensure config.json exists in current directory or specified path

"No .graphql files found"

  • Check operationsDir path in config
  • Ensure .graphql or .gql files exist in that directory

"HTTP 401 Unauthorized"

  • Check headers.Authorization in config
  • Verify your API token is valid

"GraphQL errors in response"

  • Test your query directly against the API first
  • Check variable types match the schema
  • Verify required fields are present

Requirements

  • Node.js 16+
  • A GraphQL API endpoint
  • Valid authentication credentials (if required by API)

License

MIT

Contributing

Contributions welcome! Please open an issue or PR.

Related Projects

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured