GitHub MCP Server
GitHub MCP Server
一个通过安全、结构化的工具,让 AI 助手与 GitHub 对话的项目。
简单说:这个项目不是让 AI 去猜 GitHub 是怎么运作的,而是给 AI 一个清晰的操作菜单——比如“列出我的仓库”“显示未关闭的 issue”或“读取某个文件”。AI 选出正确的操作,这个服务器去调用 GitHub,再把结果以一种干净、AI 能理解的格式返回。
它解决了什么问题?
聊天机器人擅长语言,但它们通常无法自动实时访问你的 GitHub 账户。
这个项目搭起了一座 桥梁:
你用日常语言提出请求(例如“显示 microsoft/vscode 中未关闭的 issue”)。
一个 AI 模型(通过 Groq)决定该调用哪个 GitHub 工具。
MCP 服务器 针对真实的 GitHub API 执行该工具。
返回的结果经过清洗,成为(normalize)之后交给 AI。
AI 再用通俗的语言把结果解释给你。
MCP 是指 Model Context Protocol(模型上下文协议)。你可以把它理解成一个标准的「插口」:任何兼容的 AI 客户端都能够连上这个服务器并使用它的工具集。
Related MCP server: GitHub MCP Server
整体架构(Big picture)
You
↓
AI Agent (client/agent.py) ← talks to Groq LLM
↓
MCP Server (notebooks/server.py) ← menu of GitHub tools
↓
GitHub Client ← HTTP calls with your token
↓
GitHub REST API
↓
GitHub设计原则(重要)
所有工具保持在“薄薄”的一层:
检查输入(仓库名字是否合法?)。
调用 GitHub 客户端。
把结果归一化 成稳定的结构。
把干净的规范数据返回给Agent。
其余复杂的 GitHub 细节都保存在 client 层内部——而不是散落在各工具之间。
项目文件夹(各部分用途)
路径 | 作用 |
| 主 MCP Server —— agent 行为启动的生产环境入口 |
| 供 Agent 使用的稳定数据结构(Pydantic 模型) |
| 把 GitHub 拉的原始 JSON 转换成上面的稳定的结构 |
| 危险工具的 确认 / dry-run / 白名单机制 |
| list 工具 的分页helper( |
| 只向 stderr 写 JSON(不泄露 secrets) |
| 过去/实验性的副本 —— 推荐使用 |
| 学习用 Notebook(怎么一层层做出来的) |
| 通过 stdio 与 MCP server 相连的聊天 Agent |
| 验证 AI 是否会为样例问题选择 正确 工具 |
| 你的私密密钥(千万不要提交) |
| 显示需要哪些 key 的模板 |
| 要安装的 Python 包清单 |
| 给小白看的一步步搭建指南 |
工具能做什么
服务器提供很多 GitHub 操作。简单的分组如下:
只读(安全探索)
列出你的 Repos
读取某个 repo 的详情
列出 / 获取 issue 和 pull request
抓取 PR Diffs
列出分支、commits、labels
代码库内搜索代码
读取文件内容
列出 GitHub Actions 工作流的最新 run 列表
写操作(会改变 GitHub)
创建 issue、评论、PR、分支、labels
更新 issue、添加/移除 labels
重新打开 issue
破坏性操作(有风险——受保护)
默认这些需要 extra 二次确认:
merge_pull_requestdelete_filecreate_repositorycreate_or_update_fileclose_issue
对于这几个,Agent 的常规流程是:
先用
dry_run=true调用 → 只做预览再用
confirm=true调用 → 真正操作
你可以通过环境变量把这些操作再收紧或放开(详见后文)。
统一返回结构
GitHub 原始返回很大、且经常变。本项目则返回稳定格式。
列表类工具的结果长得像这样:
{
"count": 20,
"items": [ ... ],
"page": 1,
"per_page": 20,
"has_next": true,
"has_prev": false,
"next_page": 2,
"prev_page": null,
"last_page": 5
}如果要取下一页,直接重新调用相同工具,并带上 page=2(用 page=next_page 也可)。
单个 issue 的示例:
{
"number": 42,
"title": "Bug in login",
"state": "open",
"author": "some-user",
"labels": ["bug"],
"comments": 3,
"html_url": "https://github.com/...",
"is_pull_request": false
}另外:get_issues 会自动过滤 pull request(因为 GitHub 的 issues API 会把 PR 混在一起返回)。
安全特性
特性 | 说明 |
| 运行破坏性操作前必须显式确认(默认模式) |
| 显示“如果不干预会发生什么”;不会改动 GitHub |
| MCP 根据注解,告诉客户端这个工具有风险 |
Allowlist | 可选:定义一个白名单,只有名单内的破坏性工具才被允许 |
Mode |
|
可选的环境变量:
GITHUB_MCP_DESTRUCTIVE_MODE=confirm
GITHUB_MCP_DESTRUCTIVE_ALLOWLIST=merge_pull_request,delete_file日志与调试
服务器只会把 JSON 日志输出到 stderr。
为什么用 stderr?因为 MCP 是通过 stdout 跑协议通讯的。如果把日志打到 stdout,就等于在 AI 通讯线上塞垃圾。
日志会有这些类型字段:
请求方法与路径
HTTP 状态码
耗费时长
剩余 rate limit
不打印这些:
你的 GitHub Token
Authorization 头
形似机密的值(PAT、Bearer token 等
日志例子:
{"ts":"2026-08-23T12:00:00+00:00","level":"INFO","event":"github_request","method":"GET","path":"/repos/microsoft/vscode/issues","status_code":200,"duration_ms":120.5}Agent 模块(client/agent.py)
agent.py 处理逻辑是:
用子进程启动 MCP Server(跑了
notebooks/server.py)。问服务器要可用工具清单。
把用户的 prompt + 工具信息发给 Groq。
若 Groq 想调用某个工具,则通过 MCP 让 server 执行对应调用。
最后把工具结果返回给 Groq,形成最终答案。
常用命令(在项目根目录,在虚拟环境内):
# See all registered tools
python client/agent.py --list-tools
# Only show which tool the AI would pick (no GitHub write)
python client/agent.py --dry-run "list my github repos"
# One real question, then exit
python client/agent.py --once "show open issues for microsoft/vscode"
# Interactive chat
python client/agent.py
# Check tool-picking quality on many sample prompts
python client/test_tool_picking.py循环/限制(可选)——
python client/agent.py --max-rounds 5 --once "..."或直接在 .env 中:
AGENT_MAX_TOOL_ROUNDS=8
AGENT_MAX_TOOL_CALLS=16
AGENT_MAX_CONSECUTIVE_ERRORS=3环境变量
MCP 服务器(必填)
变量 | 用途 |
| Personal Access Token,让服务器能调 GitHub API |
| 你的 GitHub 用户名(在启动时校验) |
| 一个默认 repo 名(在启动时校验) |
Agent (聊天 / 工具选择,必填)
变量 | 用途 |
| Groq LLM 的 API Key |
可选
变量 | 用处 |
| 默认 |
|
|
| 逗号分隔的破坏性工具白名单 |
| 每轮 user 消息最多 Agent工具轮数 |
| 每条 user 命令允许的工具调用次数 |
| 连续 N 次工具错误后停止 |
复制 .env.example → .env 填上真实信息。更完整请看 SETUP.md。
技术栈(相关)
Python 3.13+(开发于 3.13)
MCP(
mcpPython 包)—— 给 tool 协议的实现httpx —— 用来请求 GitHub 的 HTTP Client
Pydantic —— Schema 定义 / 数据校验
python-dotenv —— 加载
.env文件OpenAI 兼容 Client → 用于调用 Groq(作为 Agent)
Jupyter(可选用)—— 学习用的 Notebook
如何安装和启动
阅读友好的引导:
👉 SETUP.md —— 安装 Python、创建密钥、配置 .env,然后运行你的第一条命令。
如果你本身懂 Python,简短版:
cd "path\to\Github-MCP-server"
python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -r requirements.txt
copy .env.example .env
# edit .env with your tokens
python client/agent.py --list-tools
python client/agent.py --once "list my github repos"推荐学习路径
先读完这个 README(你已经看到这里)。
按 SETUP.md 部署环境,直到可以
--list-tools.看 docs/ARCHITECTURE_HLD_LLD.md:理解 HLD 与 LLD 的流配置。
先尝试
--dry-run和--once,配合简单的只读问题。进入 50 个场景手工测试计划 : tests/MANUAL_TESTING_50_SCENARIOS.md
自动跑:
python client/run_manual_scenarios.py
打开
notebooks/01_github_mcp_server.ipynb让你看清每一层是怎么搭的。最后才碰 带
dry_run+confirm的写入/破坏性工具。
奇奇怪怪问题(速查)
问题 | 可能解决 |
模块缺失 | 激活 |
Groq模型404 | 设置 |
环境变量没设 | 在 |
破坏性工具被拦 | 正常预期——先用 |
Agent 在 Windows 退出时卡住 | 已知 stdio 的某些坑(一次性 command 运行后强杀即可) |
安全提醒
永远请不要把
.env提交上去。不要把 GitHub 或 Groq token 发进 chat、截图、公开 issue。
尽量只用需要的最小 scope 的 GitHub token。
若没法信任环境,保持
GITHUB_MCP_DESTRUCTIVE_MODE=confirm(或deny)。不要公开分享
server_1.py旧实验里的 debug token(会泄漏)——用server.py。
授权 / 版权
这是一个 GitHub MCP 服务器与 agent 相关的“个人 / 学习用的生成式 AI”项目。如果要公开发布,请根据你的需求调整 owner 和许可证。
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- AlicenseNot gradedqualityBmaintenanceEnables AI agents to manage GitHub repositories, branches, issues, pull requests, releases, and actions through natural language.1155MIT
- FlicenseNot gradedqualityBmaintenanceEnables AI assistants to perform GitHub operations such as creating repositories, issues, pull requests, and more through natural language.
- FlicenseBqualityDmaintenanceEnables AI assistants to inspect local Git repositories and interact with the GitHub API for reading commits, diffs, files, issues, comments, pull requests, and project boards.10121
- FlicenseBqualityCmaintenanceEnables AI clients to interact with GitHub repositories, issues, pull requests, and code search through the GitHub REST API.12
Related MCP Connectors
Connect AI assistants to GitHub - manage repos, issues, PRs, and workflows through natural language.
Connect AI assistants to your GitHub-hosted Obsidian vault to seamlessly access, search, and analy…
Git-backed platform for skills, tools, and context for AI agents
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/Arnab1999india/github-mcp-server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server