Skip to main content

MCP server for GraphQL

Project description

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 via MCP_AUTH_TOKEN environment variable)
  • --auth-type: Authentication type, default is "Bearer" (optional)
  • --auth-headers: Custom authentication headers in JSON format (optional)

Example with custom headers:

mcp-graphql --api-url="https://api.example.com/graphql" --auth-headers='{"Authorization": "Bearer token", "X-API-Key": "key"}'

As a library

import asyncio
from mcp_graphql import serve

auth_headers = {"Authorization": "Bearer your-token"}
api_url = "https://api.example.com/graphql"

asyncio.run(serve(api_url, auth_headers))

Configuration

Configure for Claude.app

Add to your Claude settings:

Using uvx
"mcpServers": {
  "graphql": {
    "command": "uvx",
    "args": ["mcp-graphql", "--api-url", "https://api.example.com/graphql"]
  }
}
Using docker
"mcpServers": {
  "graphql": {
    "command": "docker",
    "args": ["run", "-i", "--rm", "mcp/graphql", "--api-url", "https://api.example.com/graphql"]
  }
}
Using pip installation
"mcpServers": {
  "graphql": {
    "command": "python",
    "args": ["-m", "mcp_graphql", "--api-url", "https://api.example.com/graphql"]
  }
}

How It Works

MCP GraphQL automatically:

  1. Introspects the provided GraphQL API
  2. Creates an MCP tool for each available GraphQL query
  3. Generates JSON schema for tool inputs based on query parameters
  4. Handles type conversions between GraphQL and JSON

When a tool is called, the server:

  1. Converts the tool call parameters to a GraphQL query
  2. Executes the query against the API
  3. 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 .

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contributing

Contributions are welcome. Please feel free to submit a Pull Request or open an Issue.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_graphql-0.3.2.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_graphql-0.3.2-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file mcp_graphql-0.3.2.tar.gz.

File metadata

  • Download URL: mcp_graphql-0.3.2.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.10

File hashes

Hashes for mcp_graphql-0.3.2.tar.gz
Algorithm Hash digest
SHA256 40b4c6a83f05cff28ba01a2891fd850f98ec767dc8e0c26aa32799fd09ee4507
MD5 ea3fb94699375f51b914f3da54269263
BLAKE2b-256 b8ca6a543719cdeed4ede23257274bba59629b6818eeedc029410e98b63119a1

See more details on using hashes here.

File details

Details for the file mcp_graphql-0.3.2-py3-none-any.whl.

File metadata

File hashes

Hashes for mcp_graphql-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9fcf9c8ec53531288bae0bdf84b56dc0f0a69293c3e8c224cd1ec38ff57664c2
MD5 e9e1872c0f7a38ddc76077ec9af0a063
BLAKE2b-256 c7e85a65912e63dafe2b19955dfa2b35ddb64e2de384830c2c3868645b04a355

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page