Skip to main content

GraphQL-MCP

PyPI version Python versions License: MIT

Documentation | PyPI | GitHub


Instantly expose any GraphQL API as MCP tools for AI agents and LLMs.

GraphQL MCP works with any Python GraphQL library—Strawberry, Ariadne, Graphene, graphql-core, or graphql-api. If you already have a GraphQL API, you can expose it as MCP tools in minutes.

Don't want to run anything? Bridge is a hosted MCP proxy built on graphql-mcp. Paste any public GraphQL URL into your MCP client and every query and mutation shows up as a tool — no code, no deploy.

Features

  • Universal Compatibility - Works with any GraphQL library that produces a graphql-core schema
  • Automatic Tool Generation - GraphQL queries and mutations become MCP tools instantly
  • Remote GraphQL Support - Connect to any existing GraphQL endpoint
  • Type-Safe - Preserves GraphQL types and documentation
  • Built-in Inspector - Web interface for testing MCP tools
  • Multiple Transports - HTTP, SSE, and streamable-HTTP support

Installation

pip install graphql-mcp

Quick Start

Already using Strawberry? Expose it as MCP tools:

import strawberry
from graphql_mcp.server import GraphQLMCP
import uvicorn

@strawberry.type
class Query:
    @strawberry.field
    def hello(self, name: str = "World") -> str:
        return f"Hello, {name}!"

schema = strawberry.Schema(query=Query)

# Expose as MCP tools
server = GraphQLMCP(schema=schema._schema, name="My API")
app = server.http_app()

if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=8002)

That's it! Your Strawberry GraphQL API is now available as MCP tools.

With Ariadne

Using Ariadne? Same simple integration:

from ariadne import make_executable_schema, QueryType
from graphql_mcp.server import GraphQLMCP

type_defs = """
    type Query {
        hello(name: String = "World"): String!
    }
"""

query = QueryType()

@query.field("hello")
def resolve_hello(_, info, name="World"):
    return f"Hello, {name}!"

schema = make_executable_schema(type_defs, query)

# Expose as MCP tools
server = GraphQLMCP(schema=schema, name="My API")
app = server.http_app()

With Graphene

Graphene user? Works seamlessly:

import graphene
from graphql_mcp.server import GraphQLMCP

class Query(graphene.ObjectType):
    hello = graphene.String(name=graphene.String(default_value="World"))

    def resolve_hello(self, info, name):
        return f"Hello, {name}!"

schema = graphene.Schema(query=Query)

# Expose as MCP tools
server = GraphQLMCP(schema=schema.graphql_schema, name="My API")
app = server.http_app()

For new projects, we recommend graphql-api for its decorator-based approach:

from graphql_api import GraphQLAPI, field
from graphql_mcp.server import GraphQLMCP

class API:
    @field
    def hello(self, name: str = "World") -> str:
        return f"Hello, {name}!"

api = GraphQLAPI(root_type=API)
server = GraphQLMCP.from_api(api)
app = server.http_app()

Remote GraphQL APIs

Already have a GraphQL API running? Connect to it directly:

from graphql_mcp.server import GraphQLMCP

# Connect to any GraphQL endpoint
server = GraphQLMCP.from_remote_url(
    url="https://api.github.com/graphql",
    bearer_token="your_token",
    name="GitHub API"
)

app = server.http_app()

Works with:

  • GitHub GraphQL API
  • Shopify GraphQL API
  • Hasura
  • Any public or private GraphQL endpoint

Examples

The examples/ directory contains four runnable servers:

Example What it demonstrates Live
Hello World Minimal MCP server with a single query Try it
Task Manager CRUD, enums, mutations, UUID/datetime scalars Try it
Nested API Nested tools, @mcp directive, Pydantic models, async resolvers Try it
Remote API Wrap a public GraphQL API via from_remote_url() Try it

See the examples documentation for detailed walkthroughs.

Documentation

Visit the official documentation for comprehensive guides, examples, and API reference.

Key Topics

How It Works

GraphQL MCP automatically:

  • Analyzes your GraphQL schema
  • Generates MCP tools from queries and mutations
  • Maps GraphQL types to MCP tool schemas: non-null arguments are required, nullable arguments are optional and accept null, and an omitted optional argument is left out of the operation so the server default applies
  • Converts naming to snake_case (e.g., addBook → add_book)
  • Preserves all documentation and type information
  • Supports the @mcp directive to customize how fields and arguments are exposed to MCP — see below

Customizing MCP Exposure with @mcp

A unified @mcp directive lets schema authors override how each field or argument surfaces as an MCP tool. It accepts three optional arguments:

Arg Type Effect
name String Override the MCP tool/argument name (replaces the default snake_case derivation).
description String Override the MCP description (replaces the GraphQL field/argument description).
hidden Boolean When true, skip the field or argument from MCP registration entirely.

Valid on FIELD_DEFINITION and ARGUMENT_DEFINITION.

SDL example

directive @mcp(
  name: String
  description: String
  hidden: Boolean
) on FIELD_DEFINITION | ARGUMENT_DEFINITION

type Query {
  getUserById(
    userId: ID! @mcp(name: "id", description: "User UUID")
    debugToken: String @mcp(hidden: true)
  ): User @mcp(name: "fetch_user", description: "Fetch a user by ID.")

  internalMetrics: Metrics @mcp(hidden: true)
}

Python (graphql-api) example

from typing import Annotated
from graphql_api import GraphQLAPI, field
from graphql_mcp import GraphQLMCP, mcp

class API:
    @field
    @mcp(name="fetch_user", description="Fetch a user by ID.")
    def get_user_by_id(
        self,
        user_id: Annotated[str, mcp(name="id", description="User UUID")],
        debug_token: Annotated[str, mcp(hidden=True)] = "",
    ) -> str:
        return f"user:{user_id}"

    @field
    @mcp(hidden=True)
    def internal_metrics(self) -> str:
        return "secret"

api = GraphQLAPI(root_type=API, directives=[mcp])
server = GraphQLMCP.from_api(api)

When an argument is renamed, the MCP tool exposes the new name but the outbound GraphQL query still uses the original argument name — translation happens automatically. Two fields renamed to the same MCP name will raise a ValueError at registration time.

Migrating from @mcpHidden: the previous mcp_hidden directive has been removed. Replace @mcpHidden with @mcp(hidden: true) and the mcp_hidden Python export with mcp(hidden=True).

MCP Inspector

Built-in web interface for testing and debugging MCP tools:

MCP Inspector Interface

The inspector is enabled by default — visit /graphql in your browser. See the MCP Inspector documentation for details.

Compatibility

GraphQL MCP works with any Python GraphQL library that produces a graphql-core schema:

  • Strawberry - Modern, type-hint based GraphQL
  • Ariadne - Schema-first GraphQL
  • Graphene - Code-first GraphQL
  • graphql-api - Decorator-based GraphQL (recommended)
  • graphql-core - Reference implementation
  • Any GraphQL library using graphql-core schemas

Ecosystem Integration

Configuration

# Full configuration example
server = GraphQLMCP(
    schema=your_schema,
    name="My API",
    graphql_http=False,         # Disable GraphQL HTTP endpoint (enabled by default)
    allow_mutations=True,       # Allow mutation tools (default)
)

# Serve with custom configuration
app = server.http_app(
    transport="streamable-http",  # or "http" (default) or "sse"
    stateless_http=True,         # Don't maintain client state
)

See the documentation for advanced configuration, authentication, and deployment guides.

License

MIT License - see LICENSE file for details.

Metadata

Release files for graphql-mcp 2.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for graphql-mcp 2.3.0
File Size Uploaded
graphql_mcp-2.3.0.tar.gz 546.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for graphql-mcp 2.3.0
File Interpreter ABI Platform
graphql_mcp-2.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 601.1 kB

Release files / graphql_mcp-2.3.0.tar.gz

Download URL graphql_mcp-2.3.0.tar.gz
Size 546.8 kB
Tags Source
SHA-256 checksum
How to use checksums
4d7c824f63a73cd46d91795c97b02028f5c761e6ce58730545b7b8444731a098
BLAKE2b-256 checksum
How to use checksums
fabc07f9ffddbfe057af5287253e66bafa96acad809c859277571556ef1f0b1c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.17 {"installer":{"name":"uv","version":"0.12.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / graphql_mcp-2.3.0-py3-none-any.whl

Download URL graphql_mcp-2.3.0-py3-none-any.whl
Size 54.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4a2acbd805338fe34e8d6e7e88b1cf9790086c01996f7cb9311f072fe6f77778
BLAKE2b-256 checksum
How to use checksums
222b1d540dddc15c7c7e7eeaf0f8236765c6d4da76a44529c51ac03681dfc70f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.17 {"installer":{"name":"uv","version":"0.12.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

2.3.1

2 release files

This release

2.3.0 This release

2 release files

2.2.0

2 release files

2.1.6

2 release files

2.1.5

2 release files

2.1.4

2 release files

2.1.3

2 release files

2.1.2

2 release files

2.1.1

2 release files

2.1.0

2 release files

2.0.0

2 release files

1.7.9

2 release files

1.7.8

2 release files

1.7.7

2 release files

1.7.6

2 release files

1.7.4

2 release files

1.7.1

2 release files

1.7.0

2 release files

1.6.1

2 release files

1.6.0

2 release files

1.5.5

2 release files

1.5.3

2 release files

1.5.2

2 release files

1.5.1

2 release files

1.5.0

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3.22

2 release files

1.3.21

2 release files

1.3.20

2 release files

1.3.19

2 release files

1.3.18

2 release files

1.3.17

2 release files

1.3.16

2 release files

1.3.15

2 release files

1.3.13

2 release files

1.3.12

2 release files

1.3.11

2 release files

1.3.10

2 release files

1.3.9

2 release files

1.3.8

2 release files

1.3.7

2 release files

1.3.6

2 release files

1.3.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page