GitHub MCP服务器v4.0
基于Go的MCP服务器,将GitHub连接到Claude Desktop,允许从Claude的界面直接操作存储库。
工具: 26个综合工具(85项业务)| 架构: 混合(本地Git+GitHub API+管理控制)
v4.0的新增功能
- 整合工具设计:仅26个工具的85个操作-防止AI因工具数量限制而混淆
- 操作参数模式:每个工具接受一个
operation用于选择特定操作的参数 --toolsets旗帜:启动服务器,仅显示选定的工具组(git,github,admin,files)- 真正的自动备份:在以下情况下,在HIGH/CRITICAL操作之前写入JSON备份
enable_auto_backup: true - 四层安全系统:带有确认标记的风险分类(低/中/高/关键)
- 22行政业务:存储库设置、分支保护、webhooks、协作者、团队
- 审计日志:基于JSON的操作跟踪,具有自动旋转功能
需要令牌权限
最低要求
repo - Full control of private repositories (essential)可选(用于完整功能)
security_events - For dismissing security alerts
workflow - For re-running GitHub Actions workflows
admin:repo_hook - Enhanced webhook management
admin:org - For team management in organizations生成令牌
- 首选
- 点击“生成新令牌(经典)”
- 选择所需的范围
- 复制生成的令牌
安装
# Install dependencies
go mod tidy
# Compile (using included script)
.\compile.bat # Windows
./build-mac.bat # macOS cross-compile
# Or compile manually
go build -o github-mcp-server-v4.exe ./cmd/github-mcp-server/测试
# Run all tests
go test ./...
# Run tests with verbose output
go test ./... -v
# Run tests for a specific package
go test ./pkg/git/ -v
go test ./pkg/safety/ -vClaude桌面配置
多配置文件(推荐)
{
"mcpServers": {
"github-personal": {
"command": "C:\\path\\to\\github-mcp-server-v4.exe",
"args": ["--profile", "personal"],
"env": {
"GITHUB_TOKEN": "ghp_your_personal_token"
}
},
"github-work": {
"command": "C:\\path\\to\\github-mcp-server-v4.exe",
"args": ["--profile", "work"],
"env": {
"GITHUB_TOKEN": "ghp_your_work_token"
}
}
}
}基本配置(单个令牌)
{
"mcpServers": {
"github-mcp": {
"command": "C:\\path\\to\\github-mcp-server-v4.exe",
"args": [],
"env": {
"GITHUB_TOKEN": "your_token_here"
}
}
}
}工具集筛选(可选)
仅暴露特定的工具组以减少攻击面:
{
"args": ["--toolsets", "git,github"]
}可用组: git (14个工具), github (4个工具), admin (4个工具), files (4个工具)。默认值为 all.
可用工具(26)
工具使用 operation 参数以在一个名称下公开多个操作。这将工具数量从85个减少到26个,防止了AI模型混淆。
Git信息(2个工具)
| 工具 | 操作 |
|---|---|
git_info | status, file_sha, last_commit, file_content, changed_files, validate_repo, list_files, context, validate_clean |
git_set_workspace | 为所有Git操作设置工作目录 |
Git基础版(3个工具)
| 工具 | 说明 |
|---|---|
git_init | 初始化一个新的Git仓库 |
git_add | 提交阶段文件 |
git_commit | 提交分阶段更改 |
Git高级版(9个工具)
| 工具 | 操作 |
|---|---|
git_history | log, diff |
git_branch | checkout, checkout_remote, list, merge, rebase, backup |
git_sync | push, pull, force_push, push_upstream, sync, pull_strategy |
git_conflict | status, resolve, detect, safe_merge |
git_stash | list, push, pop, apply, drop, clear |
git_remote | list, add, remove, show, fetch |
git_tag | list, create, delete, push, show |
git_clean | untracked, untracked_dirs, ignored, all |
git_reset | 撤销提交(软/混合/硬) |
混合动力(3种工具)
| 工具 | 说明 |
|---|---|
gh_create_file | 创建文件-Git-first,GitHub API回退 |
gh_update_file | 更新文件-Git-first,GitHub API回退 |
gh_push_files | 在一次调用中写入多个文件+git添加/提交/推送 |
GitHub API(1个工具)
| 工具 | 操作 |
|---|---|
github_repo | list_repos, create_repo, list_prs, create_pr |
仪表板(1个工具)
| 工具 | 操作 |
|---|---|
github_dashboard | full, notifications, issues, prs_review, security, workflows, mark_read |
响应(1个工具)
| 工具 | 操作 |
|---|---|
github_respond | comment_issue, comment_pr, review_pr |
维修(1个工具)
| 工具 | 操作 |
|---|---|
github_repair | close_issue, merge_pr, rerun_workflow, dismiss_alert |
管理员(4个工具)
| 工具 | 操作 | 风险 |
|---|---|---|
github_admin_repo | get_settings, update_settings, archive, delete | 低→ 关键 |
github_branch_protection | get, update, delete | 低→ 关键 |
github_webhooks | list, create, update, delete, test | 低→ 高 |
github_collaborators | list, check, add, update_permission, remove, list_invitations, accept_invitation, cancel_invitation, list_teams, add_team | 低→ 高 |
文件操作(1个工具)
| 工具 | 操作 |
|---|---|
github_files | list, download, download_repo, pull_repo |
安全系统
四级风险分类
| 级别 | 描述 | 行为(中等模式) |
|---|---|---|
| 低 | 只读 | 直接执行 |
| 中等 | 可逆变化 | 可选的模拟运行 |
| 高 | 影响协作 | 需要确认令牌 |
| 关键的 | 不可逆 | 令牌+备份建议 |
安全使用复合密钥 tool:operation (例如。, github_webhooks:delete)风险分类。
安全模式
| 模式 | 确认来源 | 推荐使用 |
|---|---|---|
strict | 中级+ | 关键生产环境 |
moderate | HIGH+ | 通用(默认) |
permissive | 关键 | 地方发展 |
disabled | 从不 | 不推荐 |
安全配置
创建 safety.json 在可执行文件旁边(可选):
{
"mode": "moderate",
"enable_audit_log": true,
"require_confirmation_above": 3,
"audit_log_path": "./mcp-admin-audit.log",
"audit_log_max_size_mb": 10,
"audit_log_max_backups": 5
}如果 safety.json 不存在,默认为 中等模式 启用审计日志记录。
Git免费模式
在未安装Git的系统上,服务器:
- 自动检测Git缺失
- 过滤器
git_*列表中的工具 - 保持所有API、管理、仪表板和文件操作工具的可操作性
- 如果尝试使用Git工具,则返回友好错误
这 github_files 工具(list, download, download_repo, pull_repo)允许仅使用GitHub API克隆和更新存储库,而不使用Git。
安全
- 在所有Git操作中防止命令注入
- 路径穿越防御
- webhook URL中的SSRF预防
- 用于破坏性操作的加密确认令牌
- 所有行政操作的审计日志记录
有关漏洞报告,请参阅我们的 安全策略.
系统要求
- 去:1.25.0或更高
- Git:可选(自动检测;文件/API工具在没有它的情况下工作)
github.com/google/go-githubv81.0.0golang.org/x/oauth2v0.36.0- GitHub代币:最小值
repo许可
项目状态
- 26个综合工具,涉及85项业务
- 混合本地Git+GitHub API系统
- 带有确认令牌和自动备份的4层安全系统
- 多配置文件支持
- 完整的测试套件
- 生产就绪(v4.0)
更新日志:参见 更改日志.md 查看完整的变更历史。
贡献
我们欢迎捐款!请看 贡献.md 作为指导方针。
许可证
MIT许可证——见 许可证 了解详情。
