Expose GraphQL APIs as MCP Tools
MCP server that auto-exposes every GraphQL query as its own MCP tool via schema introspection, with configurable auth.
1.0.0Add to Favorites
Why it matters
Seamlessly interact with GraphQL APIs by automatically exposing each query as a distinct MCP tool. This asset dynamically generates tools from your GraphQL schema, simplifying data extraction and integration.
Outcomes
What it gets done
Dynamically generate MCP tools from GraphQL schemas.
Map GraphQL query parameters to tool inputs automatically.
Support customizable authentication methods for secure API access.
Enable predefined queries for controlled data retrieval.
Source
Get it from source
Spark does not host a copy of it.
Open sourceReports
Agent outcome reports
No reports yet
Capabilities
Tools your agent gets
Execute a GraphQL query against the configured API with dynamically generated parameters.
Overview
GraphQL MCP Server automatically turns each query of a target GraphQL API into an MCP tool via schema introspection, with configurable authentication and query-depth limits. Use it to query arbitrary GraphQL APIs without custom wrappers; for production, predefine specific queries rather than relying on unconstrained auto-generation, and note mutations aren't yet supported.
What it does
GraphQL MCP Server implements the Model Context Protocol to expose any GraphQL API as a set of MCP tools. It introspects the target API's GraphQL schema and creates a separate tool for each query, generating each tool's JSON input schema directly from that query's parameters - no manual schema definition or wrapper code required. When a tool is called, its arguments are converted into a GraphQL query, the query runs against the configured endpoint, and the JSON result is returned - handling the GraphQL-to-JSON type conversions automatically.
Two ways to build the exposed tool set: automatic introspection, which walks the schema up to a configurable --max-depth (default 5) for quick exploration, or a --queries-file/--queries input of hand-written, named GraphQL operations, where every named operation becomes its own MCP tool with no manual boilerplate. Mutations are not supported yet - only queries - with mutation support and improved error handling and validation listed as planned features.
When to use - and when NOT to
Use it when an AI assistant needs to query an arbitrary GraphQL API - a CMS, GitHub's GraphQL API, an e-commerce catalog - and hand-writing a wrapper tool per query isn't worth it. Point it at the API URL and credentials and the available operations appear as tools automatically via introspection.
Avoid relying on unconstrained automatic introspection for production workloads: drilling into nested objects and lists at depth can return large amounts of data and overflow the model's context window, and you lose control over exactly which fields come back. For production, predefine the exact queries you need via --queries-file or --queries instead. It also isn't a fit where GraphQL mutations are required, since only queries are currently supported.
Inputs and outputs
Every generated tool's inputs mirror its underlying GraphQL query's parameters, with a JSON schema derived automatically from that query's definition. Its output is the JSON result of executing that query against the configured API endpoint. Authentication is configured once at server start, not per call: a bearer token, HTTP Basic credentials, or a JSON object of custom headers (for example combining Authorization and X-API-Key in one request) passed via --auth-token, --auth-type, or --auth-headers.
Capabilities
- Exposes each GraphQL query - auto-discovered or predefined - as its own MCP tool, with an auto-generated JSON input schema
- Configurable authentication: Bearer tokens, Basic auth, or arbitrary custom headers in JSON form
- Adjustable introspection depth (
--max-depth) to bound automatically generated queries and control token usage - Runs as a CLI (
mcp-graphqlorpython -m mcp_graphql), or is importable as a Python library (make_server,serve) for embedding GraphQL tool-calling inside a custom low-level MCP server, including stateful and stateless Streamable HTTP implementations - MIT licensed
How to install
uvx mcp-graphql --api-url="https://api.example.com/graphql" --auth-token="your-token"
Or via pip: pip install mcp-graphql. Configure Claude Desktop with uvx:
{
"mcpServers": {
"graphql": {
"command": "uvx",
"args": ["mcp-graphql", "--api-url", "https://api.example.com/graphql"]
}
}
}
A Docker image (mcp/graphql) is available too, wired up the same way:
{
"mcpServers": {
"graphql": {
"command": "docker",
"args": ["run", "-i", "--rm", "mcp/graphql", "--api-url", "https://api.example.com/graphql"]
}
}
}
Requires Python 3.11+ when installed via uv or pip. MCP_AUTH_TOKEN can be set as an environment-variable alternative to --auth-token.
Who it's for
Developers who want an AI assistant to query arbitrary GraphQL APIs on the fly, without writing per-query integration code - both people happy with auto-introspected tools for quick exploration, and teams who need tighter, production-ready control via a predefined queries file. The make_server/serve Python library entry points also suit developers embedding GraphQL tool-calling inside their own low-level MCP server instead of running the packaged CLI directly. Contributors extending the server locally can run it with hot-reloading and inspect its tools through the Model Context Protocol Inspector (@modelcontextprotocol/inspector) via npx.
Source README
MCP GraphQL
An MCP (Model Context Protocol) server that enables interaction with GraphQL APIs.
Description
MCP GraphQL is a tool that implements the Model Context Protocol (MCP) to provide a standardized interface for interacting with GraphQL APIs. It automatically exposes each GraphQL query as a separate MCP tool, allowing MCP-compatible clients to seamlessly communicate with GraphQL services.
Features
- Each GraphQL query is exposed as a distinct MCP tool
- Tool parameters automatically match the corresponding GraphQL query parameters
- JSON schema for tool inputs is dynamically generated from GraphQL query parameters
- No schema definition required - simply provide the API URL and credentials
- Currently supports GraphQL queries (mutations support planned for future releases)
- Configurable authentication (Bearer, Basic, custom headers)
- Automatic handling of complex GraphQL types
Requirements
- Python 3.11 or higher
Installation
Using uv (recommended)
When using uv no specific installation is needed. We will
use uvx to directly run mcp-graphql.
Using pip
Alternatively you can install mcp-graphql via pip:
pip install mcp-graphql
Installation from source code
git clone https://github.com/your-username/mcp_graphql.git
cd mcp_graphql
pip install .
Usage
As a command line tool
Using uvx:
uvx mcp-graphql --api-url="https://api.example.com/graphql" --auth-token="your-token"
Using pip installation:
mcp-graphql --api-url="https://api.example.com/graphql" --auth-token="your-token"
or
python -m mcp_graphql --api-url="https://api.example.com/graphql" --auth-token="your-token"
Available options
--api-url: GraphQL API URL (required)--auth-token: Authentication token (optional, can also be set viaMCP_AUTH_TOKENenvironment variable)--auth-type: Authentication type, default is "Bearer" (optional)--auth-headers: Custom authentication headers in JSON format (optional)--queries-file: Path to a .gql file containing predefined GraphQL queries (optional)--queries: Predefined GraphQL queries passed directly as a string (optional)--max-depth: Maximum depth when auto-generating queries (default: 5)
Example with custom headers:
mcp-graphql --api-url="https://api.example.com/graphql" --auth-headers='{"Authorization": "Bearer token", "X-API-Key": "key"}'
Example with predefined queries file:
mcp-graphql --api-url="https://api.example.com/graphql" --queries-file="./queries.gql"
Example passing queries directly as a string (use single quotes to avoid shell conflicts):
mcp-graphql --api-url="https://api.example.com/graphql" --queries='query Hello { hello }'
About automatic query generation
If neither --queries-file nor --queries is supplied, mcp-graphql will
automatically build a query by introspecting the GraphQL schema and selecting
all scalar fields up to a configurable depth. This is convenient for
quickly exploring an API, but it has two main drawbacks:
- Too much depth - drilling deep into nested objects (especially lists) can return a large amount of data and overflow the LLM context window.
- Lack of control - you cannot precisely choose which fields are included, so tokens may be wasted on irrelevant information.
The --max-depth option mitigates the first issue by limiting the recursion
depth (default = 5). Even so, the best practice is to define the exact
queries you need through --queries-file or --queries. In doing so:
- You control exactly which fields are returned and avoid unnecessary lists.
- Every named operation in your file/string is automatically exposed as an MCP tool with no manual boilerplate.
Example using --max-depth to limit the auto-generated query to depth 2:
mcp-graphql --api-url="https://api.example.com/graphql" --max-depth 2
For production workloads you should supply your own queries:
# Using a file
mcp-graphql --api-url="https://api.example.com/graphql" \
--queries-file="./queries.gql"
# Or as a string
mcp-graphql --api-url="https://api.example.com/graphql" \
--queries='query UserMini { viewer { id name } }'
The queries.gql file should contain one or more named operations, e.g.:
# queries.gql
query GetUser($id: ID!) {
user(id: $id) {
id
name
email
}
}
query ListPosts {
posts {
id
title
}
}
As a library
import asyncio
from pathlib import Path
from mcp_graphql import make_server, serve
auth_headers = {"Authorization": "Bearer your-token"}
api_url = "https://api.example.com/graphql"
queries_file = Path("queries.gql") # optional, set to None to expose all queries
asyncio.run(serve(api_url, auth_headers, queries_file=queries_file))
Passing the queries directly as a string from code:
queries_str = """
query Hello($name: String!) {
hello(name: $name)
}
"""
asyncio.run(serve(api_url, auth_headers, queries=queries_str, max_depth=3))
Create low level MCP server:
server = make_server(api_url, auth_headers, queries=queries_str, max_depth=3)
For low level server with Streamable HTTP implementations, see:
Configuration
Configure for Claude.app
Add to your Claude settings:
"mcpServers": {
"graphql": {
"command": "uvx",
"args": ["mcp-graphql", "--api-url", "https://api.example.com/graphql"]
}
}
"mcpServers": {
"graphql": {
"command": "docker",
"args": ["run", "-i", "--rm", "mcp/graphql", "--api-url", "https://api.example.com/graphql"]
}
}
"mcpServers": {
"graphql": {
"command": "python",
"args": ["-m", "mcp_graphql", "--api-url", "https://api.example.com/graphql"]
}
}
How It Works
MCP GraphQL automatically:
- Introspects the provided GraphQL API
- Creates an MCP tool for each available GraphQL query
- Generates JSON schema for tool inputs based on query parameters
- Handles type conversions between GraphQL and JSON
When a tool is called, the server:
- Converts the tool call parameters to a GraphQL query
- Executes the query against the API
- Returns the results to the MCP client
Planned Features
- Support for GraphQL mutations (with appropriate safeguards)
- Improved error handling and validation
- Additional optimizations based on specific GraphQL API implementations
Development
Setting up the development environment
# Create virtual environment using uv
uv venv
# Install dependencies
uv sync
Linting
ruff check .
Running the server in development mode
When working locally you can start the MCP GraphQL server with hot-reloading and inspect its tools using the Model Context Protocol Inspector:
npx "@modelcontextprotocol/inspector" uv run -n --project $PWD mcp-graphql --api-url http://localhost:3010/graphql
Replace http://localhost:3010/graphql with the URL of your local GraphQL endpoint if it differs.
FAQ
Common questions
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.