请改用官方 GitHub MCP 服务器:https://github.com/github/github-mcp-server
这是一个提供与 GitHub API 交互工具的 Model Context Protocol (MCP) 服务器。此服务器允许 LLM 代理通过标准化接口管理 GitHub 存储库、问题、拉取请求、分支、文件和发布。
github-mcp-server 实现了 Model Context Protocol (MCP),使 LLM 和外部系统之间能够通过以下方式进行标准化通信:
它充当 AI 模型和 GitHub API 之间的桥梁,提供一组遵循一致模式并处理身份验证、验证、错误处理和速率限制的工具。
关键功能包括:
核心系统架构:
<details> <summary>点击展开 Mermaid 图表</summary>flowchart TB
subgraph API["API 层"]
direction LR
MCP["MCP 协议"]
Val["验证"]
Rate["速率限制"]
MCP --> Val --> Rate
end
subgraph Features["功能模块"]
direction LR
Repo["存储库管理"]
Branch["分支管理"]
Issue["问题管理"]
PR["拉取请求管理"]
File["文件管理"]
Release["发布管理"]
Repo <--> Branch
Repo <--> Issue
Repo <--> PR
Repo <--> File
Branch <--> PR
end
subgraph Services["服务层"]
direction LR
GitHub["GitHub 服务"]
Mapper["响应映射器"]
RateLimiter["速率限制器"]
GitHub <--> RateLimiter
GitHub <--> Mapper
end
Rate --> Repo
Rate --> Branch
Rate --> Issue
Rate --> PR
Rate --> File
Rate --> Release
Repo --> GitHub
Branch --> GitHub
Issue --> GitHub
PR --> GitHub
File --> GitHub
Release --> GitHub
classDef layer fill:#2d3748,stroke:#4299e1,stroke-width:3px,rx:5,color:#fff
classDef component fill:#1a202c,stroke:#a0aec0,stroke-width:2px,rx:3,color:#fff
classDef api fill:#3182ce,stroke:#90cdf4,stroke-width:2px,rx:3,color:#fff
classDef features fill:#319795,stroke:#81e6d9,stroke-width:2px,rx:3,color:#fff
classDef services fill:#2f855a,stroke:#9ae6b4,stroke-width:2px,rx:3,color:#fff
class API,Features,Services layer
class MCP,Val,Rate api
class Repo,Branch,Issue,PR,File,Release features
class GitHub,Mapper,RateLimiter services
</details>
核心组件包括:
克隆仓库:
git clone https://github.com/cyanheads/github-mcp-server.git
cd github-mcp-server
安装依赖项:
npm install
在项目根目录中创建一个 .env 文件,并添加您的 GitHub 令牌:
GITHUB_TOKEN=your_github_personal_access_token
LOG_LEVEL=info
SERVER_NAME=github-mcp-server
构建项目:
npm run build
启动服务器:
node build/index.js
服务器可以通过环境变量进行配置:
| 环境变量 | 描述 | 默认值 |
|---|---|---|
GITHUB_TOKEN | GitHub 个人访问令牌(必需) | - |
LOG_LEVEL | 日志级别(debug, info, warn, error, fatal) | info |
SERVER_NAME | MCP 服务器名称 | github-mcp-server |
SERVER_VERSION | MCP 服务器版本 | 0.1.0 |
API_TIMEOUT_MS | API 调用超时时间(毫秒) | 10000 |
RATE_LIMITING_ENABLED | 是否启用速率限制 | true |
RATE_LIMITING_MIN_REMAINING | 在节流之前剩余的最小请求数量 | 100 |
RATE_LIMITING_RESET_BUFFER_MS | 添加到速率限制重置时间的时间缓冲 | 5000 |
添加到您的 MCP 客户端设置:
{
"mcpServers": {
"github": {
"command": "node",
"args": ["/path/to/github-mcp-server/build/index.js"],
"env": {
"GITHUB_TOKEN": "your_github_personal_access_token",
"LOG_LEVEL": "info",
"SERVER_NAME": "github-mcp-server"
}
}
}
}
该项目遵循原子特征导向的架构模式:
/src
/configuration // 应用程序配置
/dependencyInjection // 工具注册和 DI 容器
/features // 按领域组织的功能模块
/repositoryManagement
/resources // 读操作
/modifications // 写操作
/branchManagement
/issueManagement
/pullRequestManagement
/fileManagement
/releaseManagement
/services // 外部服务集成
/githubAccess // GitHub API 客户端和实用工具
/types // 核心类型定义
/utilities // 辅助函数和实用工具
每个功能域被分为:
每个操作都包含在自己的目录中,包括:
GitHub MCP 服务器提供了一整套与 GitHub 交互的工具:
| 工具 | 描述 |
|---|---|
get_repository | 获取特定存储库的详细信息<br>参数:owner, repo |
list_repositories | 列出认证用户的存储库<br>参数:type(可选),sort(可选) |
create_repository | 创建一个新的 GitHub 存储库<br>参数:name, description(可选),private(可选) |
| 工具 | 描述 |
|---|---|
list_branches | 列出存储库中的分支<br>参数:owner, repo, protected(可选),per_page(可选) |
create_branch | 创建一个新的分支<br>参数:owner, repo, branch, sha |
delete_branch | 删除一个分支<br>参数:owner, repo, branch |
| 工具 | 描述 |
|---|---|
create_issue | 在存储库中创建一个新的问题<br>参数:owner, repo, title, body(可选),labels(可选) |
list_issues | 列出存储库中的问题<br>参数:owner, repo, state(可选),labels(可选) |
| 工具 | 描述 |
|---|---|
create_pull_request | 创建一个新的拉取请求<br>参数:owner, repo, title, head, base, body(可选) |
merge_pull_request | 合并一个拉取请求<br>参数:owner, repo, pull_number, commit_title(可选),commit_message(可选),merge_method(可选) |
update_pull_request | 更新现有的拉取请求<br>参数:owner, repo, pull_number, title(可选),body(可选),state(可选),base(可选),maintainer_can_modify(可选) |
list_pull_requests | 列出存储库中的拉取请求<br>参数:owner, repo, state(可选),head(可选),base(可选),sort(可选),direction(可选) |
| 工具 | 描述 |
|---|---|
update_file | 在存储库中创建或更新一个文件<br>参数:owner, repo, path, message, content, sha(可选),branch(可选) |
| 工具 | 描述 |
|---|---|
create_release | 创建一个新的发布<br>参数:owner, repo, tag_name, name(可选),body(可选),draft(可选),prerelease(可选) |
项目遵循严格的命名约定和目录结构:
action.entity.type.ts(例如,create.repository.operation.ts)npm run build - 构建项目npm run watch - 监视更改并重新构建npm run inspector - 运行 MCP 检查工具npm run clean - 清理构建工件npm run rebuild - 清理并重新构建项目npm run tree - 生成目录树表示服务器实现了全面的错误处理策略:
欢迎贡献!请随意提交拉取请求。
git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)