这是一个用于与 GitHub Enterprise API 集成的 MCP(模型上下文协议)服务器。该服务器提供了一个 MCP 接口,可以轻松地从 GitHub Enterprise 中获取存储库信息、问题、PR 等信息到 Cursor。
该项目主要设计用于 GitHub Enterprise Server 环境,但也适用于:
注意:一些特定于企业的功能(如许可证信息和企业统计信息)在 GitHub.com 或 GitHub Enterprise Cloud 上可能无法使用。
构建 Docker 镜像:
docker build -t github-enterprise-mcp .
使用环境变量运行 Docker 容器:
docker run -p 3000:3000 \
-e GITHUB_TOKEN="your_github_token" \
-e GITHUB_ENTERPRISE_URL="https://github.your-company.com/api/v3" \
-e DEBUG=true \
github-enterprise-mcp
注意:Dockerfile 默认配置为使用
--transport http。如果需要更改此设置,可以通过覆盖命令来实现:
docker run -p 3000:3000 \
-e GITHUB_TOKEN="your_github_token" \
-e GITHUB_ENTERPRISE_URL="https://github.your-company.com/api/v3" \
-e DEBUG=true \
github-enterprise-mcp node dist/index.js --transport http --debug
在项目根目录下创建一个 .env 文件,包含所需的环境变量:
GITHUB_ENTERPRISE_URL=https://github.your-company.com/api/v3
GITHUB_TOKEN=your_github_token
DEBUG=true
使用 Docker Compose 启动容器:
docker-compose up -d
检查日志:
docker-compose logs -f
停止容器:
docker-compose down
推荐用于主动开发,具有自动重新编译和服务器重启功能:
克隆仓库并安装所需包:
git clone https://github.com/ddukbg/github-enterprise-mcp.git
cd github-enterprise-mcp
npm install
运行开发服务器:
export GITHUB_TOKEN="your_github_token"
export GITHUB_ENTERPRISE_URL="https://github.your-company.com/api/v3"
npm run dev
这将:
如下所述使用 URL 模式连接到 Cursor
这是最稳定且推荐用于本地开发或测试的方法:
克隆仓库并安装所需包:
git clone https://github.com/ddukbg/github-enterprise-mcp.git
cd github-enterprise-mcp
npm install
构建项目:
npm run build
chmod +x dist/index.js
运行服务器:
export GITHUB_TOKEN="your_github_token"
export GITHUB_ENTERPRISE_URL="https://github.your-company.com/api/v3"
node dist/index.js --transport http --debug
使用 URL 模式连接到 Cursor:
.cursor/mcp.json 文件中:{
"mcpServers": {
"github-enterprise": {
"url": "http://localhost:3000/sse"
}
}
}
这种方法对于本地开发很有用:
# 克隆仓库后
git clone https://github.com/ddukbg/github-enterprise-mcp.git
cd github-enterprise-mcp
# 安装所需包
npm install
# 构建
npm run build
chmod +x dist/index.js
# 全局链接
npm link
# 作为全局命令运行
export GITHUB_TOKEN="your_github_token"
export GITHUB_ENTERPRISE_URL="https://github.your-company.com/api/v3"
github-enterprise-mcp --transport=http --debug
如果包已发布到公共 npm 注册表:
npx @ddukbg/github-enterprise-mcp --token=your_github_token --github-enterprise-url=https://github.your-company.com/api/v3
将以下内容添加到你的 claude_desktop_config.json 文件中:
{
"mcpServers": {
"github-enterprise": {
"command": "npx",
"args": ["-y", "@ddukbg/github-enterprise-mcp", "--token=YOUR_GITHUB_TOKEN", "--github-enterprise-url=YOUR_GITHUB_ENTERPRISE_URL"]
}
}
}
替换 YOUR_GITHUB_TOKEN 和 YOUR_GITHUB_ENTERPRISE_URL 为你实际的值。
为了在 Cursor 中获得最可靠的运行,建议使用 URL 模式:
在单独的终端窗口中启动服务器:
cd /path/to/github-enterprise-mcp
GITHUB_ENTERPRISE_URL="https://github.your-company.com/api/v3" GITHUB_TOKEN="your_github_token" node dist/index.js --transport http
配置 Cursor 的 MCP 设置:
.cursor/mcp.json 文件:{
"mcpServers": {
"github-enterprise": {
"url": "http://localhost:3000/sse"
}
}
}
重启 Cursor 以应用更改
也可以配置 Cursor 使用命令模式,尽管 URL 模式更可靠:
npx@ddukbg/github-enterprise-mcpGITHUB_ENTERPRISE_URL:你的 GitHub Enterprise API URLGITHUB_TOKEN:你的 GitHub 个人访问令牌或者,你可以手动编辑你的 .cursor/mcp.json 文件以包括:
{
"mcpServers": {
"github-enterprise": {
"command": "npx",
"args": [
"@ddukbg/github-enterprise-mcp"
],
"env": {
"GITHUB_ENTERPRISE_URL": "https://github.your-company.com/api/v3",
"GITHUB_TOKEN": "your_github_token"
}
}
}
}
此 MCP 服务器支持英语和韩语。你可以通过以下方式配置语言:
# 设置语言为韩语
export LANGUAGE=ko
# 或在 .env 文件中
LANGUAGE=ko
# 设置语言为韩语
node dist/index.js --language ko
默认语言是英语,除非另有指定。
--debug:启用调试日志--github-enterprise-url <URL>:设置 GitHub Enterprise API URL--token <TOKEN>:设置 GitHub 个人访问令牌--language <LANG>:设置语言(en 或 ko,默认:en)此 MCP 服务器提供了以下工具:
| 工具名称 | 描述 | 参数 | 所需 PAT 权限 |
|---|---|---|---|
list-repositories | 检索用户或组织的存储库列表 | owner: 用户名/组织名称<br>isOrg: 是否为组织<br>type: 存储库类型<br>sort: 排序标准<br>page: 页码<br>perPage: 每页项数 | repo |
get-repository | 获取详细的存储库信息 | owner: 存储库所有者<br>repo: 存储库名称 | repo |
list-branches | 列出存储库的分支 | owner: 存储库所有者<br>repo: 存储库名称<br>protected_only: 是否仅显示受保护的分支<br>page: 页码<br>perPage: 每页项数 | repo |
get-content | 检索文件或目录的内容 | owner: 存储库所有者<br>repo: 存储库名称<br>path: 文件/目录路径<br>ref: 分支/提交(可选) | repo |
list-pull-requests | 列出存储库中的拉取请求 | owner: 存储库所有者<br>repo: 存储库名称<br>state: PR 状态过滤器<br>sort: 排序标准<br>direction: 排序方向<br>page: 页码<br>per_page: 每页项数 | repo |
get-pull-request | 获取拉取请求的详细信息 | owner: 存储库所有者<br>repo: 存储库名称<br>pull_number: 拉取请求编号 | repo |
create-pull-request | 创建新的拉取请求 | owner: 存储库所有者<br>repo: 存储库名称<br>title: PR 标题<br>head: 头部分支<br>base: 基础分支<br>body: PR 描述<br>draft: 作为草稿 PR 创建 | repo |
merge-pull-request | 合并拉取请求 | owner: 存储库所有者<br>repo: 存储库名称<br>pull_number: 拉取请求编号<br>merge_method: 合并方法<br>commit_title: 提交标题<br>commit_message: 提交消息 | repo |
list-issues | 列出存储库中的问题 | owner: 存储库所有者<br>repo: 存储库名称<br>state: 问题状态过滤器<br>sort: 排序标准<br>direction: 排序方向<br>page: 页码<br>per_page: 每页项数 | repo |
get-issue | 获取问题的详细信息 | owner: 存储库所有者<br>repo: 存储库名称<br>issue_number: 问题编号 | repo |
list-issue-comments | 列出问题或拉取请求上的评论 | owner: 存储库所有者<br>repo: 存储库名称<br>issue_number: 问题/PR 编号<br>page: 页码<br>per_page: 每页项数 | repo |
create-issue | 创建新的问题 | owner: 存储库所有者<br>repo: 存储库名称<br>title: 问题标题<br>body: 问题正文内容<br>labels: 标签名称数组<br>assignees: 用户登录名数组<br>milestone: 里程碑 ID | repo |
create-repository | 创建新的存储库 | name: 存储库名称<br>description: 存储库描述<br>private: 是否私有<br>auto_init: 初始化带有 README<br>gitignore_template: 添加 .gitignore<br>license_template: 添加许可证<br>org: 组织名称 | repo |
update-repository | 更新存储库设置 | owner: 存储库所有者<br>repo: 存储库名称<br>description: 新描述<br>private: 更改隐私<br>default_branch: 更改默认分支<br>has_issues: 启用/禁用问题<br>has_projects: 启用/禁用项目<br>has_wiki: 启用/禁用维基<br>archived: 归档/取消归档 | repo |
delete-repository | 删除存储库 | owner: 存储库所有者<br>repo: 存储库名称<br>confirm: 确认(必须为 true) | delete_repo |
list-workflows | 列出 GitHub Actions 工作流 | owner: 存储库所有者<br>repo: 存储库名称<br>page: 页码<br>perPage: 每页项数 | actions:read |
list-workflow-runs | 列出工作流运行 | owner: 存储库所有者<br>repo: 存储库名称<br>workflow_id: 工作流 ID/文件名<br>branch: 按分支筛选<br>status: 按状态筛选<br>page: 页码<br>perPage: 每页项数 | actions:read |
trigger-workflow | 触发工作流 | owner: 存储库所有者<br>repo: 存储库名称<br>workflow_id: 工作流 ID/文件名<br>ref: Git 引用<br>inputs: 工作流输入 | actions:write |
get-license-info | 获取 GitHub Enterprise 许可证信息 | - | 需要 site_admin(管理员)账户 |
get-enterprise-stats | 获取 GitHub Enterprise 系统统计信息 | - | 需要 site_admin(管理员)账户 |
注意:对于特定于企业的工具(
get-license-info和get-enterprise-stats),需要具有 site administrator 特权的用户。建议使用经典个人访问令牌,因为细粒度令牌可能不支持这些企业级权限。
一旦设置了 MCP 服务器并配置了 Cursor 以连接到它,你就可以直接在 Cursor 的 AI 聊天中使用 GitHub Enterprise 工具。这里有一些示例:
mcp_github_enterprise_list_repositories(owner="octocat")
mcp_github_enterprise_get_repository(owner="octocat", repo="hello-world")
mcp_github_enterprise_list_pull_requests(owner="octocat", repo="hello-world", state="open")
# 列出问题
mcp_github_enterprise_list_issues(owner="octocat", repo="hello-world", state="all")
# 获取问题详细信息
mcp_github_enterprise_get_issue(owner="octocat", repo="hello-world", issue_number=1)
# 获取问题/PR 评论
mcp_github_enterprise_list_issue_comments(owner="octocat", repo="hello-world", issue_number=1)
# 创建新问题
mcp_github_enterprise_create_issue(
owner="octocat",
repo="hello-world",
title="发现了一个 bug",
body="这里是关于这个 bug 的描述",
labels=["bug", "重要"]
)
mcp_github_enterprise_get_content(owner="octocat", repo="hello-world", path="README.md")
# 创建新存储库
mcp_github_enterprise_create_repository(
name="新项目",
description="这是一个新项目",
private=true,
auto_init=true
)
# 更新存储库设置
mcp_github_enterprise_update_repository(
owner="octocat",
repo="hello-world",
description="更新后的描述",
has_issues=true
)
这些功能特别设计用于 GitHub Enterprise Server 环境,并需要管理员权限:
# 列出 GitHub Enterprise 实