通过Claude Code实现GitHub自动化的MCP服务器。8个工具,零上下文切换。
______________________________________________________________________
特性
| 特性 | 描述 |
|---|---|
| 8个MCP工具 | PR、CI、漂移、回滚、提交、同步和一般PR创建 |
| 整洁架构 | 具有DI的域、应用程序和基础架构层 |
| 速率限制 | 自动GitHub API速率限制跟踪和节流 |
| 使用回退重试 | 瞬态故障的指数回退(429,5xx) |
| 内存缓存 | 基于TTL的缓存(5分钟),用于频繁访问的数据 |
| 双模式 | 以stdio(Claude)或SSE(HTTP)服务器运行 |
| Docker支持 | 使用Docker或Docker compose构建和运行 |
| 分支配置 | 通过以下方式定制每个回购分支 repos.json |
技术栈
语言和框架
基础设施和工具
我为什么建造这个
我管理多个仓库,厌倦了:
- 手动检查PR状态
- 忘记哪些树枝在飘动
- 上下文切换到GitHub以获取CI状态
现在我问克劳德:“有任何失败的CI运行吗?”并立即得到答案。
______________________________________________________________________
工具
| 工具 | 说明 |
|---|---|
repo_list_status | 所有具有打开PR、CI状态、最后活动的存储库 |
repo_list_prs | 跨存储库打开拉取请求 |
repo_check_ci | 任何分支的GitHub操作状态 |
repo_trigger_rollback | 执行回滚策略(重新运行、还原、工作流) |
repo_recent_commits | 最近使用过滤器的提交 |
repo_check_drift | 检测prod/dev分支差异 |
repo_create_sync_pr | 创建PR以将prod同步到dev |
repo_create_pr | 在任意两个分支之间创建PR |
工具示例
列出存储库状态
"Show me the status of all my repositories"
"Which repos have failing CI?"
"List repos with open PRs"检查拉取请求
"Show me all open PRs"
"List PRs in my-org/api"
"Any PRs waiting for review?"CI/CD监控
"Any failing CI runs on main?"
"Check CI status for my-org/api"
"Show me recent workflow runs for feature-branch"漂移检测
"Check drift between main and develop"
"Are any of my repos out of sync?"
"Show drift for my-org/api"同步和公关创建
"Create a sync PR for my-org/api"
"Preview sync PR for my-repo (dry run)"
"Create a PR from feature/auth to develop"回滚操作
"Rerun the last failed workflow on my-org/api"
"What rollback options are available?"
"Trigger rollback workflow for production"______________________________________________________________________
设置
1.获取GitHub Token
创建 个人访问令牌 使用这些范围:
repo-完全访问存储库workflow-执行工作流read:user-读取用户资料
2.创建 .env
cp .env.example .env
# Add your token
GITHUB_TOKEN=ghp_xxxx或者,创建 ~/.mcp-repo-monitor/.env 用于用户范围的配置。
______________________________________________________________________
配置
回答。
创建 ~/.mcp-repo-monitor/repos.json 要自定义每个存储库的分支名称,请执行以下操作:
{
"default": {
"prod_branch": "main",
"dev_branch": "develop"
},
"repositories": {
"my-org/api": {
"prod_branch": "production",
"dev_branch": "main"
}
}
}| 字段 | 描述 |
|---|---|
default.prod_branch | 生产分支名称(默认值: main) |
default.dev_branch | 开发分支名称(默认值: develop) |
repositories. | 覆盖特定分支 owner/repo |
命令行标志
./mcp-repo-monitor --help
--mode string Server mode: stdio or sse (default "stdio")
--addr string Address for SSE server (default ":8080")
--log-level string Log level: debug, info, warn, error (default "info")______________________________________________________________________
用法
本土的
make build # Build binary
make run # Run stdio mode
make run-sse # Run SSE server on :8080
make inspect # MCP Inspector UI
make test # Run all tests码头工人
make docker-build
make docker-run______________________________________________________________________
Claude代码集成
选项1:本机二进制
添加到您的克劳德代码设置(~/.claude/settings.json):
{
"mcpServers": {
"repo-monitor": {
"command": "/path/to/mcp-repo-monitor/bin/mcp-repo-monitor"
}
}
}选项2:Docker
{
"mcpServers": {
"repo-monitor": {
"command": "docker",
"args": ["run", "-i", "--rm", "--env-file", "/path/to/.env", "mcp-repo-monitor"]
}
}
}选项3:使用调试日志记录
{
"mcpServers": {
"repo-monitor": {
"command": "/path/to/mcp-repo-monitor/bin/mcp-repo-monitor",
"args": ["--log-level=debug"]
}
}
}______________________________________________________________________
建筑
Go的简洁架构:
internal/
├── domain/ # Entities & business logic
│ ├── entity/ # Repository, PR, Commit, Workflow, Branch
│ └── service/ # DriftDetector, RollbackService
├── application/ # Use cases
│ ├── port/ # GitHubClient interface
│ └── usecase/ # 8 use cases
└── infrastructure/ # External services
├── cache/ # In-memory TTL caching
├── github/ # go-github client with rate limiting & retry
├── logging/ # Structured JSON logging (slog)
└── mcp/ # MCP server, handlers, presenters| 方面 | 选择 |
|---|---|
| 建筑 | DI清洁架构 |
| 语言 | 转到1.23 |
| GitHub客户端 | google/go github v60 |
| MCP框架 | mark3labs/mcp go |
| 认证 | OAuth2通过golang.org/x/OAuth2发布 |
| 缓存 | 内存TTL(默认5分钟) |
______________________________________________________________________
故障排除
“GITHUB_TOKEN环境变量是必需的”
确保您的令牌已设置:
cat .env
# Or user config
cat ~/.mcp-repo-monitor/.env“repos.JSON中的JSON无效”
验证JSON语法:
cat ~/.mcp-repo-monitor/repos.json | jq .速率限制错误
当速率限制较低时,客户端会自动等待。对于频繁使用:
- 使用具有更高限制的令牌(GitHub Pro/Enterprise)
- 缓存减少了对重复查询的API调用
- 检查日志:
--log-level=debug
MCP连接问题
- 验证二进制文件是否独立运行:
echo '{"jsonrpc":"2.0","method":"initialize","id":1}' | ./bin/mcp-repo-monitor- 检查克劳德代码日志是否有错误
- 确保设置中的路径是绝对的
______________________________________________________________________
验尸
| ID | 日期 | 严重性 | 标题 |
|---|---|---|---|
| PM-001 | 2026-02-03 | 关键 | 同步PR中的反向分支比较 |
______________________________________________________________________
贡献
- 克隆该仓库
- 创建功能分支(
git checkout -b feature/amazing-feature) - 提交您的更改(
git commit -m 'feat: add amazing feature') - 推到分支(
git push origin feature/amazing-feature) - 打开拉取请求
许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
______________________________________________________________________
