Logo MCP GraphQL

MCP GraphQL

Cộng đồng
drestrepom

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

Nhà phát hànhdrestrepom
Kho mãmcp_graphql
Ngôn ngữPython
Bản fork
3
Sao
19
Công cụ có sẵn
0
Phương thức truyền tảistdio
Danh mục
Liên kết
  • Kết nối công cụ với quy trình làm việc AI

    MCP GraphQL cung cấp các khả năng MCP mà ứng dụng khách và tác nhân AI tương thích có thể sử dụng.

  • 0 công cụ có sẵn

    Xem các thao tác có thể gọi bên dưới, kèm tên và mô tả nếu máy chủ cung cấp.

  • Cấu hình sẵn để sao chép

    Dùng các đoạn cấu hình cài đặt mẫu để thiết lập máy chủ này trong ứng dụng khách MCP bạn muốn dùng.

  • Chỉ số quan tâm đến mã nguồn mở

    19 sao và 3 bản fork từ kho mã được liên kết.

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:

bash
pip install mcp-graphql

Installation from source code

bash
git clone https://github.com/your-username/mcp_graphql.git
cd mcp_graphql
pip install .

Usage

As a command line tool

Using uvx:

bash
uvx mcp-graphql --api-url="https://api.example.com/graphql" --auth-token="your-token"

Using pip installation:

bash
mcp-graphql --api-url="https://api.example.com/graphql" --auth-token="your-token"

or

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

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

Example with predefined queries file:

bash
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):

bash
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:

  1. Too much depth – drilling deep into nested objects (especially lists) can return a large amount of data and overflow the LLM context window.
  2. 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:

bash
mcp-graphql --api-url="https://api.example.com/graphql" --max-depth 2

For production workloads you should supply your own queries:

bash
# 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.:

graphql
# queries.gql
query GetUser($id: ID!) {
  user(id: $id) {
    id
    name
    email
  }
}

query ListPosts {
  posts {
    id
    title
  }
}

As a library

python
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:

python
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:

python
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:

json
"mcpServers": {
  "graphql": {
    "command": "uvx",
    "args": ["mcp-graphql", "--api-url", "https://api.example.com/graphql"]
  }
}
json
"mcpServers": {
  "graphql": {
    "command": "docker",
    "args": ["run", "-i", "--rm", "mcp/graphql", "--api-url", "https://api.example.com/graphql"]
  }
}
json
"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

bash
# Create virtual environment using uv
uv venv

# Install dependencies
uv sync

Linting

bash
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:

bash
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.

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.

Cài đặt

TypingMind
Yêu cầu:

Node.js 18+

{
  "mcpServers": {
    "drestrepom-mcp_graphql": {
      "command": "",
      "args": []
    }
  }
}

Dùng MCP MCP GraphQL với nhiều mô hình AI

TypingMind kết nối các công cụ MCP ở cấp không gian làm việc, nên sau khi kết nối MCP GraphQL, bạn có thể dùng với nhiều mô hình AI khác nhau trong TypingMind thay vì phải thiết lập riêng cho từng mô hình. MCP này chạy cục bộ thông qua trình kết nối MCP của TypingMind trên thiết bị của bạn.

Hướng dẫn thiết lập để dùng trình kết nối cục bộ

Dùng cách này khi máy chủ MCP cần truy cập các tệp, ứng dụng hoặc tài nguyên riêng tư trên máy tính của bạn.

1

Mở cài đặt MCP

Trong TypingMind, vào Cài đặt, Cài đặt nâng cao, rồi đến Giao thức ngữ cảnh mô hình và chọn Cài trình kết nối.

  1. Mở TypingMind trong trình duyệt của bạn.
  2. Nhấp vào biểu tượng Cài đặt.
  3. Vào Cài đặt nâng cao.
  4. Mở mục Giao thức ngữ cảnh mô hình.
  5. Nhấp vào Cài trình kết nối rồi chọn Thiết bị này.
Màn hình thiết lập trình kết nối MCP của TypingMind với tùy chọn Thiết bị này được chọn
2

Chạy lệnh trình kết nối

Chọn Thiết bị này, sao chép lệnh từ TypingMind và chạy trong Terminal. Giữ tiến trình chạy trong khi bạn dùng MCP.

  1. Sao chép lệnh thiết lập hiển thị trong TypingMind.
  2. Mở Terminal trên macOS hoặc Windows Terminal trên Windows.
  3. Dán và chạy lệnh.
  4. Xác nhận cài đặt gói nếu Terminal hỏi bạn có muốn tiếp tục không.
  5. Giữ tiến trình trong cửa sổ Terminal chạy trong khi dùng các công cụ MCP.
3

Thêm MCP GraphQL làm máy chủ

Khi trạng thái trình kết nối là Sẵn sàng, nhấp vào Sửa máy chủ và dán cấu hình máy chủ MCP.

  1. Đợi đến khi trạng thái trình kết nối hiển thị Sẵn sàng.
  2. Nhấp vào Sửa máy chủ.
  3. Dán cấu hình máy chủ MCP của MCP GraphQL.
  4. Lưu danh sách máy chủ.
  5. Làm mới nếu bạn muốn xác nhận trình kết nối vẫn sẵn sàng.
Cài đặt MCP của TypingMind hiển thị máy chủ đang hoạt động và nút Sửa máy chủ
{
  "mcpServers": {
    "drestrepom-mcp_graphql": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-graphql"
      ]
    }
  }
}
4

Dùng kết nối với nhiều mô hình

Lưu danh sách máy chủ, mở Plugin, bật các công cụ MCP của MCP GraphQL, sau đó chọn bất kỳ mô hình AI nào được hỗ trợ trong TypingMind và dùng các công cụ trong cuộc trò chuyện hoặc gán chúng cho một tác nhân AI.

  1. Mở trang Plugin trong TypingMind.
  2. Bật các công cụ MCP của MCP GraphQL.
  3. Bắt đầu cuộc trò chuyện và chọn mô hình AI bạn muốn dùng.
  4. Dùng các công cụ MCP trong cuộc trò chuyện hoặc gán chúng cho một tác nhân AI.
  5. Chuyển sang mô hình AI khác bất cứ khi nào cần mà không phải kết nối lại MCP.
Cuộc trò chuyện TypingMind dùng các công cụ MCP đã bật với một mô hình AI được chọn
Bạn có thể dùng MCP GraphQL giúp tôi làm việc này không?
MCP GraphQL
Được. Tôi đã đọc.
Đây là kết quả tôi tìm được bằng MCP GraphQL.

Câu hỏi thường gặp

Máy chủ MCP MCP GraphQL dùng để làm gì?

MCP GraphQL là máy chủ MCP cho phép các ứng dụng AI tương thích kết nối với công cụ và ngữ cảnh bên ngoài. Trong TypingMind, bạn chỉ cần thêm máy chủ MCP này một lần để các công cụ của nó có sẵn trong không gian làm việc AI của bạn.

Bạn có thể dùng MCP MCP GraphQL với nhiều mô hình AI trong TypingMind không?

Có. TypingMind kết nối các công cụ MCP ở cấp không gian làm việc, nên bạn có thể dùng MCP GraphQL với nhiều mô hình AI như Claude, ChatGPT, Gemini hoặc các mô hình khác đã cấu hình trong TypingMind mà không cần thiết lập máy chủ MCP riêng cho từng mô hình.

Vì sao nên dùng MCP MCP GraphQL với TypingMind?

TypingMind là một trong những giao diện trò chuyện với LLM tốt nhất vì tập hợp nhiều mô hình AI, prompt, plugin, tác nhân AI, khóa API và công cụ MCP vào một không gian làm việc. Khi kết nối MCP GraphQL, bạn có thể dùng các công cụ MCP của dịch vụ này với những mô hình ưa thích, đồng thời giữ quy trình trò chuyện gọn gàng trong TypingMind.

Làm cách nào để kết nối MCP MCP GraphQL với TypingMind?

MCP GraphQL hoạt động thông qua trình kết nối MCP cục bộ của TypingMind. Đây là lựa chọn phù hợp nhất khi máy chủ MCP cần truy cập tệp cục bộ, ứng dụng máy tính, công cụ dòng lệnh hoặc tài nguyên riêng trên máy tính của bạn.

MCP MCP GraphQL cung cấp những công cụ nào trong TypingMind?

MCP GraphQL cung cấp các chức năng MCP mà bạn có thể bật từ trang Plugin của TypingMind để dùng trong trò chuyện hoặc gán cho tác nhân AI.

Bạn có cần chia sẻ khóa API với TypingMind để dùng MCP MCP GraphQL không?

Không. TypingMind ưu tiên xử lý cục bộ và cho phép bạn kiểm soát nhà cung cấp mô hình, khóa API, prompt và cấu hình MCP. Nếu MCP GraphQL yêu cầu xác thực, hãy thêm các header, cài đặt OAuth hoặc cấu hình cục bộ cần thiết cho máy chủ MCP đó khi tạo kết nối.

Máy chủ MCP liên quan

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇