Skip to main content
Glama
rishav0004

GitHub MCP Server (Custom)

by rishav0004

GitHub MCP Server(自定义)

一个自定义的 Model Context Protocol (MCP) 服务器,为 AI 代理提供对 GitHub 的完整 CRUD 访问:仓库、问题、拉取请求、分支、评论、审查和合并。使用官方 Python mcp SDK(FastMCP)和通过 httpx 的 GitHub REST API 构建。

共 23 个工具 — 完整列表见 server.py。亮点:

领域

工具

仓库

list_repos, get_repo

问题

list_issues, get_issue, create_issue, update_issue, close_issue, add_issue_comment, list_issue_comments

分支

list_branches, get_branch, create_branch, delete_branch

拉取请求

list_pull_requests, get_pull_request, create_pull_request, update_pull_request, merge_pull_request, list_pr_files

审查

list_pr_reviews, create_pr_review

提交

list_commits, get_commit

设置

  1. 安装依赖

    pip install -r requirements.txt
  2. 创建 GitHub 令牌

    前往 https://github.com/settings/tokens 并创建以下任一类型:

    • 一个具有 repo 范围的经典 PAT,或

    • 一个细粒度 PAT,将 Contents、Issues、Pull requests 和 Metadata 设置为读取和写入,范围限定为你希望代理访问的仓库。

  3. 将令牌设置为环境变量

    export GITHUB_TOKEN=ghp_your_token_here
  4. 独立运行(可选健全性检查)

    python server.py

    它将等待 MCP 客户端通过 stdio 连接——这是预期的,它不是 Web 服务器。

Related MCP server: github-mcp

将其连接到 Claude Desktop

将此添加到你的 claude_desktop_config.json(Windows 上为 %APPDATA%\Claude\claude_desktop_config.json,macOS 上为 ~/Library/Application Support/Claude/claude_desktop_config.json):

{
  "mcpServers": {
    "github": {
      "command": "python",
      "args": ["/absolute/path/to/server.py"],
      "env": {
        "GITHUB_TOKEN": "ghp_your_token_here"
      }
    }
  }
}

重启 Claude Desktop,GitHub 工具将出现在工具选择器中。

将其连接到你自己的代理管道(例如 Jira → GitHub → Teams 项目)

由于这是一个标准的 MCP stdio 服务器,任何兼容 MCP 的客户端或 SDK 都可以将其作为子进程启动,并通过 stdin/stdout 与之通信——包括使用 MCP C# SDK 的 .NET 主机,或者如果你的编排器是多语言的,可以使用 Python/TypeScript SDK。将客户端指向:

command: python
args: ["/absolute/path/to/server.py"]
env: { "GITHUB_TOKEN": "<token>" }

扩展它

要添加新工具,只需向 server.py 添加一个新的 @mcp.tool() 装饰函数,该函数调用 _request(method, path, ...) 来访问 GitHub REST API。文档字符串将成为显示给模型的工具描述,类型提示将成为输入模式——因此请确保两者准确。

注意事项

  • 所有写操作(create_*、update_*、delete_*、merge_*)都会在 GitHub 上产生真实更改——没有干运行模式。建议先在临时仓库上进行测试,尤其是 merge_pull_request 和 delete_branch。

  • 速率限制遵循 GitHub 的标准 REST API 限制(截至撰写本文时,经过身份验证的请求为每小时 5,000 次)——服务器不进行自己的节流。

  • 来自 GitHub 的错误(身份验证失败、404、合并冲突等)会以 RuntimeError 的形式抛出,并包含 API 的响应正文,以便调用代理获得可读的消息来做出反应。

Related MCP Connectors

Related MCP Servers

  • F
    license
    Not graded
    quality
    Not graded
    maintenance
    Enables LLMs to interact with GitHub repositories, issues, pull requests, and workflows through the Model Context Protocol. It provides a comprehensive set of tools for repository management, issue tracking, code search, and CI/CD automation.
    -
  • A
    license
    C
    quality
    D
    maintenance
    Enables AI assistants to directly operate GitHub repositories, such as listing issues, through the Model Context Protocol.
    2
    140 npm
    2
    Apache 2.0
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables AI assistants to interact with GitHub repositories, issues, pull requests, and content via the Model Context Protocol.
    1
    MIT