GitHub - drestrepom/mcp_graphql (original) (raw)

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

Requirements

Installation

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:

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

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

Development

Setting up the development environment

Create virtual environment using uv

uv venv

Install dependencies

uv sync

Linting

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.