BM

blurrah/mcp-graphql

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

407 stars 62 forks 质量 68 趋势 19MIT

GraphQL 的模型上下文协议服务器

概览

一个模型上下文协议服务器,使LLM能够与GraphQL API交互。该实现提供了模式内省和查询执行能力,使模型能够动态发现并使用GraphQL API。 用正确的端点运行mcp-graphql,它会自动尝试内省你的查询。 自1.0.0版本起,命令行参数已被环境变量取代。 - :服务器将GraphQL模式作为资源暴露给客户端访问。这可以是本地模式文件、托管在URL上的模式文件,或基于内省查询。 1. :该工具检索GraphQL模式。如果你无法访问该模式作为资源,请先使用该模式。它使用本地模式文件、托管在URL下的模式文件或内省查询。 2. : 对端点执行 GraphQL 查询。默认情况下,除非 ALLOW_MUTATIONS 设置为 true,否则变异是被禁用的。

概述(AI 翻译)

一个模型上下文协议服务器,使LLM能够与GraphQL API交互。该实现提供了模式内省和查询执行能力,使模型能够动态发现并使用GraphQL API。

用途

用正确的端点运行mcp-graphql,它会自动尝试内省你的查询。

环境变量(1.0.0 中的破坏性变更)

注: 自1.0.0版本起,命令行参数已被环境变量取代。

环境变量 描述 默认
ENDPOINT GraphQL 端点 URL http://localhost:4000/graphql
HEADERS 包含请求头部的JSON字符串 {}
ALLOW_MUTATIONS 启用变异操作(默认禁用) false
NAME MCP服务器名称 mcp-graphql
SCHEMA 指向本地GraphQL模式文件或URL(可选)的路径 -

示例

资源

  • graphql-schema:服务器将GraphQL模式作为资源暴露给客户端访问。这可以是本地模式文件、托管在URL上的模式文件,或基于内省查询。

可用工具

本页由 AI 翻译,技术细节请以原文为准。

README

以下为原文 README 节选,完整内容请查看原文。

mcp-graphql

A Model Context Protocol server that enables LLMs to interact with GraphQL APIs. This implementation provides schema introspection and query execution capabilities, allowing models to discover and use GraphQL APIs dynamically.

Usage

Run mcp-graphql with the correct endpoint, it will automatically try to introspect your queries.

Environment Variables (Breaking change in 1.0.0)

Note: As of version 1.0.0, command line arguments have been replaced with environment variables.

Environment Variable Description Default
ENDPOINT GraphQL endpoint URL http://localhost:4000/graphql
HEADERS JSON string containing headers for requests {}
ALLOW_MUTATIONS Enable mutation operations (disabled by default) false
NAME Name of the MCP server mcp-graphql
SCHEMA Path to a local GraphQL schema file or URL (optional) -

Examples

# Basic usage with a local GraphQL server
ENDPOINT=http://localhost:3000/graphql npx mcp-graphql

# Using with custom headers
ENDPOINT=https://api.example.com/graphql HEADERS='{"Authorization":"Bearer token123"}' npx mcp-graphql

# Enable mutation operations
ENDPOINT=http://localhost:3000/graphql ALLOW_MUTATIONS=true npx mcp-graphql

# Using a local schema file instead of introspection
ENDPOINT=http://localhost:3000/graphql SCHEMA=./schema.graphql npx mcp-graphql

# Using a schema file hosted at a URL
ENDPOINT=http://localhost:3000/graphql SCHEMA=https://example.com/schema.graphql npx mcp-graphql

Resources

  • graphql-schema: The server exposes the GraphQL schema as a resource that clients can access. This is either the local schema file, a schema file hosted at a URL, or based on an introspection query.

Available Tools

The server provides two main tools:

  1. introspect-schema: This tool retrieves the GraphQL schema. Use this first if you don’t have access to the schema as a resource. This uses either the local schema file, a schema file hosted at a URL, or an introspection query.

  2. query-graphql: Execute GraphQL queries against the endpoint. By default, mutations are disabled unless ALLOW_MUTATIONS is set to true.

Installation

Installing via Smithery

To install GraphQL MCP Server for Claude Desktop automatically via Smithery:

npx -y @smithery/cli install mcp-graphql --client claude

Installing Manually

It can be manually installed to Claude:

{
    "mcpServers": {
        "mcp-graphql": {
            "command": "npx",
            "args": ["mcp-graphql"],
            "env": {
在 GitHub 查看完整 README

安装

npx mcp-graphql
新手?先看 mcpskill.org 教程 →

配置

{ "mcpServers": { "mcp-graphql": { "command": "npx", "args": ["mcp-graphql"], "env": { "ENDPOINT": "http://localhost:3000/graphql" } } } }