GitHub GraphQL API MCP

by wanzunz

Integrations

  • Uses .env files to securely store GitHub access tokens needed for API authentication.

  • Enables querying GitHub's GraphQL API to retrieve repository information, issues, pull requests, user profiles, and project dependencies with precise data control to reduce token consumption.

  • Provides schema exploration and query execution capabilities for GitHub's GraphQL API, allowing for precise data retrieval through query customization.

GitHub GraphQL API MCP

English |中文|日本语|西班牙语|法国人

一个基于 MCP(模型控制协议)的工具,用于查询和使用 GitHub GraphQL API。该项目提供了一个服务器,允许您通过 MCP 客户端工具(例如 Claude AI)探索 GitHub GraphQL 模式并执行 GraphQL 查询。

为什么要使用 GitHub GraphQL API

GitHub GraphQL API 与传统 REST API 相比具有显著优势:

  • 精确的数据检索:GraphQL 允许客户端精确指定他们需要的字段,避免多余的数据
  • 减少令牌消耗:通过仅请求必要字段,API 响应大小显著减少,从而降低 AI 模型令牌消耗
  • 相关数据的单次请求:一次查询可以检索多个相关资源,从而减少请求次数
  • 自文档化:通过其内置的文档系统,您可以直接查询和了解 API 模式,而无需外部文档
  • 强类型系统:提供类型检查,减少错误

该项目利用这些优势提供工具,帮助您有效地探索 GitHub GraphQL API 模式并执行优化查询,为 AI 助手提供高效的 GitHub 数据检索功能。

应用场景

基本功能

该工具可以轻松实现以下常见操作:

  1. 仓库基本信息查询:获取仓库名称、描述、star数、分支列表等基本信息
  2. 问题数据检索:查询特定存储库的问题列表、详细信息或评论内容
  3. 用户资料访问:检索用户的个人资料、贡献统计数据和其他公共信息
  4. Pull Request Status View :获取PR基本状态、评论内容、合并信息
  5. 项目依赖查询:检索项目依赖包列表和版本信息

探索性高级功能

借助 GraphQL 灵活的查询能力,你还可以尝试实现以下高级分析功能:

  1. 存储库贡献趋势分析:通过汇总提交数据、评估项目活动来分析代码更新频率和贡献者参与度
  2. 问题管理与分类:根据自定义条件整理问题数据,发现需要优先处理的问题,提高项目管理效率
  3. 代码审查模式分析:分析 PR 评论和审查流程,识别常见问题模式,优化代码审查工作流程
  4. 贡献者网络可视化:建立项目贡献者之间的合作关系,发现关键贡献者和专业领域
  5. 依赖健康评估:评估项目依赖的更新频率和潜在的安全问题,提供依赖管理建议

特征

  • 查询 GitHub GraphQL 模式根类型(查询/变异)
  • 获取特定类型的详细文档
  • 查询特定字段的文档和参数
  • 直接执行 GitHub GraphQL API 查询,精确检索所需数据,减少令牌消耗
  • 双语支持(英语/中文)

先决条件

  • Python 3.10 或更高版本
  • GitHub 个人访问令牌(用于访问 GitHub API)
  • Poetry(推荐的依赖管理工具)

安装

  1. 克隆存储库:
git clone https://github.com/wanzunz/github_graphql_api_mcp.git cd github_graphql_api_mcp
  1. 使用 Poetry 安装依赖项:
# If you haven't installed Poetry yet, install it first: # curl -sSL https://install.python-poetry.org | python3 - # Install dependencies using Poetry poetry install # Activate the virtual environment poetry shell

如果你不使用 Poetry,你可以使用传统方法:

# Create and activate a virtual environment python -m venv .venv source .venv/bin/activate # Linux/MacOS # or .venv\Scripts\activate # Windows # Install dependencies pip install -e .
  1. 配置环境变量:

创建一个.env文件并添加您的 GitHub 个人访问令牌:

GITHUB_TOKEN="your_github_token_here"

您可以通过复制.env.example文件来创建它:

cp .env.example .env

然后编辑.env文件,将your_github_token_here替换为你的实际 GitHub 令牌。

用法

启动服务器

确保你已经激活了 Poetry 虚拟环境( poetry shell ),然后:

跑步
python github_graphql_api_mcp_server.py

服务器启动后,您可以通过 MCP 客户端(例如 Claude AI)连接到它。

在 Claude Desktop 中配置

您可以在 Claude 桌面应用中配置此 MCP 服务器,实现一键启动:

  1. 打开 Claude 桌面应用程序
  2. 进入设置,找到 MCP 服务器配置部分
  3. 添加如下配置(根据你的实际路径修改):
{ "mcpServers": { "github_mcp": { "command": "<your Python interpreter path>", "args": [ "--directory", "<project path>", "run", "github_graphql_api_mcp_server.py" ] } } }

配置示例:

{ "mcpServers": { "github_mcp": { "command": "/usr/bin/python3", "args": [ "--directory", "/home/user/projects/github_graphql_api_mcp/", "run", "github_graphql_api_mcp_server.py" ] } } }

如果您使用 conda 或其他环境管理工具:

{ "mcpServers": { "github_mcp": { "command": "/opt/miniconda3/bin/python", "args": [ "--directory", "/Users/username/github/github_graphql_api_mcp/", "run", "github_graphql_api_mcp_server.py" ] } } }

配置完成后,您可以直接从 Claude 桌面应用程序启动 MCP 服务器,而无需手动启动。

可用工具

该服务器提供以下工具:

  1. print_type_field :查询 GitHub GraphQL 模式根类型的字段
  2. graphql_schema_root_type :获取根类型的文档(查询/变异)
  3. graphql_schema_type :查询特定类型的文档
  4. call_github_graphql :执行 GitHub GraphQL API 查询

使用示例

使用 MCP 客户端连接到服务器后,您可以:

  1. 查询根类型文档:
    Use the graphql_schema_root_type tool, parameter type_name="QUERY"
  2. 查询特定类型的字段:
    Use the print_type_field tool, parameters type_name="QUERY", type_fields_name="repository"
  3. 查询特定类型的文档:
    Use the graphql_schema_type tool, parameter type_name="Repository"
  4. 执行 GraphQL 查询:
    Use the call_github_graphql tool, parameter: graphql=""" query { viewer { login name } } """
示例截图

以下是使用 GitHub GraphQL API MCP 与 Claude 的示例:

笔记

  • 使用前请确保你的 GitHub 令牌具有适当的权限
  • 令牌存储在.env文件中,该文件不应提交到版本控制系统
  • 查询应符合 GitHub API 使用限制

执照

该项目根据 MIT 许可证获得许可 - 这是一个非常宽松的许可证,允许用户自由使用、修改、分发和商业化该软件,只要他们保留版权声明和许可声明。

请参阅MIT 许可证以了解详细条款。

-
security - not tested
F
license - not found
-
quality - not tested

remote-capable server

The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.

该服务器允许您探索 GitHub GraphQL 模式并通过 MCP 客户端工具执行 GraphQL 查询,从而能够从 GitHub 高效检索数据并减少令牌消耗。

  1. 为什么要使用 GitHub GraphQL API
    1. 应用场景
      1. 基本功能
      2. 探索性高级功能
    2. 特征
      1. 先决条件
        1. 安装
          1. 用法
            1. 启动服务器
            2. 在 Claude Desktop 中配置
            3. 可用工具
            4. 使用示例
          2. 笔记
            1. 执照

              Related MCP Servers

              • A
                security
                A
                license
                A
                quality
                MCP Server for the GitHub API, enabling file operations, repository management, search functionality, and more.
                Last updated -
                17
                22,912
                44,357
                JavaScript
                MIT License
              • A
                security
                F
                license
                A
                quality
                Provides tools for mapping and analyzing GitHub repositories. It allows users to set a GitHub Personal Access Token and retrieve detailed information about a specified repository, including its structure and summary statistics.
                Last updated -
                2
                16
                TypeScript
              • A
                security
                A
                license
                A
                quality
                An MCP server for gitingest. It allows MCP clients like Claude Desktop, Cursor, Cline etc to quickly extract information about Github repositories including repository summaries, project directory structure, file contents, etc
                Last updated -
                3
                8
                Python
                MIT License
                • Apple
              • A
                security
                F
                license
                A
                quality
                An MCP server that enables integration with GitHub Enterprise API, allowing users to access repository information, manage issues, pull requests, workflows, and other GitHub features through Cursor.
                Last updated -
                16
                33
                13
                TypeScript
                • Linux
                • Apple

              View all related MCP servers

              ID: isnddb3ty9