Skip to main content

Add your description here

Project description

MCP GraphQL

An MCP (Model Control Protocol) server that enables interaction with GraphQL APIs.

Description

MCP GraphQL is a tool that implements the Model Control 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 pip
pip install mcp_graphql

# Or 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

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)
  • --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))

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
  • Pagination support for large result sets

Development

Setting up the development environment

# Create virtual environment
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install development dependencies
pip install -e ".[dev]"

Running tests

pytest

Linting

ruff check .

License

[Include license information here]

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.2.0.tar.gz (7.7 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.2.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for mcp_graphql-0.2.0.tar.gz
Algorithm Hash digest
SHA256 93764c2f1306a29636091380734fabaafc58b836c6ac4ef21b804dd8839f4229
MD5 0b001daae3f9ba4df1483c5577bc71b2
BLAKE2b-256 5f57520047211af91e58a5a8e16badd7b289b663e3a9a24c0fb6b4c4e3e03761

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mcp_graphql-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5bdb35ae998712fc124cf5c44d4f9e81fea3a55a599b8ec125d98e26f896d597
MD5 fb2ff37f46c02e53861d376c879fb0ef
BLAKE2b-256 2474537a82b647a5b6f6d8e09a8d2e2d61750979e2ff549515dec7a20269fd05

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