GitHub Enterprise MCP 服务器

用于与 GitHub Enterprise API 集成的 MCP(模型上下文协议)服务器。该服务器提供 MCP 接口,方便用户在 Cursor 中轻松访问 GitHub Enterprise 的仓库信息、问题、PR 等。
兼容性
该项目主要针对 GitHub Enterprise Server 环境设计,但也适用于:
注意:某些企业特定功能(如许可证信息和企业统计信息)不适用于 GitHub.com 或 GitHub Enterprise Cloud。
Related MCP server: GitHub MCP Server Plus
主要特点
入门
先决条件
Node.js 18 或更高版本
访问 GitHub Enterprise 实例
个人访问令牌(PAT)
Docker 安装和设置
选项 1:使用 Docker 运行
构建 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
选项 2:使用 Docker Compose
在项目根目录中创建一个包含所需环境变量的.env文件:
GITHUB_ENTERPRISE_URL=https://github.your-company.com/api/v3
GITHUB_TOKEN=your_github_token
DEBUG=true
使用 Docker Compose 启动容器:
检查日志:
停止容器:
安装和设置
本地开发(使用并发模式)
对于具有自动重新编译和服务器重启功能的主动开发,建议使用此方法:
克隆存储库并安装所需的包:
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,如下所述
生产的安装和设置
选项 1:使用 URL 模式(推荐用于本地开发)
此方法最稳定,推荐用于本地开发或测试:
克隆存储库并安装所需的包:
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:
{
"mcpServers": {
"github-enterprise": {
"url": "http://localhost:3000/sse"
}
}
}
选项 2:作为全局命令安装(npm 链接)
此方法对于本地开发很有用:
# After cloning the repository
git clone https://github.com/ddukbg/github-enterprise-mcp.git
cd github-enterprise-mcp
# Install required packages
npm install
# Build
npm run build
chmod +x dist/index.js
# Link globally
npm link
# Run as a global command
export GITHUB_TOKEN="your_github_token"
export GITHUB_ENTERPRISE_URL="https://github.your-company.com/api/v3"
github-enterprise-mcp --transport=http --debug
选项 3:使用 npx(包发布时)
如果该包已发布到公共 npm 注册表:
npx @ddukbg/github-enterprise-mcp --token=your_github_token --github-enterprise-url=https://github.your-company.com/api/v3
与AI工具集成
克劳德桌面
将以下内容添加到您的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 。
光标
推荐: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 并转到**“设置”**
导航至AI > MCP 服务器
编辑你的.cursor/mcp.json文件:
{
"mcpServers": {
"github-enterprise": {
"url": "http://localhost:3000/sse"
}
}
}
重新启动 Cursor 以应用更改
替代方案:命令模式
或者,您可以将 Cursor 配置为使用命令模式,尽管 URL 模式更可靠:
打开 Cursor 并转到**“设置”**
导航至AI > MCP 服务器
点击**“添加 MCP 服务器”**
输入以下详细信息:
或者,您可以手动编辑.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 服务器支持英语和韩语。您可以使用以下方式配置语言:
环境变量
# Set language to Korean
export LANGUAGE=ko
# Or in .env file
LANGUAGE=ko
命令行参数
# Set language to Korean
node dist/index.js --language ko
如果未指定,默认语言为英语。
HTTP 模式中的附加选项
--debug :启用调试日志记录
--github-enterprise-url <URL> :设置 GitHub Enterprise API URL
--token <TOKEN> :设置 GitHub 个人访问令牌
--language <LANG> :设置语言(en 或 ko,默认值:en)
可用的 MCP 工具
该 MCP 服务器提供以下工具:
工具名称 | 描述 | 参数 | 所需的 PAT 权限 |
list-repositories
| 检索用户或组织的存储库列表 | owner :用户名/组织名称isOrg :是否为组织type :存储库类型sort :排序条件page :页码perPage :每页项目数
| repo
|
get-repository
| 获取详细的存储库信息 | owner :存储库所有者repo :存储库名称
| repo
|
list-branches
| 列出存储库的分支 | owner :仓库所有者repo :仓库名称protected_only :是否仅显示受保护的分支page :页码perPage :每页项目数
| repo
|
get-content
| 检索文件或目录内容 | owner :存储库所有者repo :存储库名称path :文件/目录路径ref :分支/提交(可选)
| repo
|
list-pull-requests
| 列出存储库中的拉取请求 | owner :仓库所有者repo :仓库名称state :PR 状态 filter sort :排序标准direction :排序方向page :页码per_page :每页项目数
| repo
|
get-pull-request
| 获取拉取请求详细信息 | owner :仓库所有者repo :仓库名称pull_number :拉取请求编号
| repo
|
create-pull-request
| 创建新的拉取请求 | owner :仓库所有者repo :仓库名称title :PR 标题head :头部分支base :基础分支body :PR 描述draft :创建为草稿 PR
| repo
|
merge-pull-request
| 合并拉取请求 | owner :仓库所有者repo :仓库名称pull_number :拉取请求编号merge_method :合并方法commit_title :提交标题commit_message :提交消息
| repo
|
list-issues
| 列出存储库中的问题 | owner :仓库所有者repo :仓库名称state :问题状态 filter sort :排序标准direction :排序方向page :页码per_page :每页项目数
| repo
|
get-issue
| 获取问题详细信息 | owner :存储库所有者repo :存储库名称issue_number :发行编号
| repo
|
list-issue-comments
| 列出对问题或拉取请求的评论 | owner :存储库所有者repo :存储库名称issue_number :问题/PR 编号page :页码per_page :每页项目数
| repo
|
create-issue
| 创建新问题 | owner :存储库所有者repo :存储库名称title :问题标题body :问题正文内容labels :标签名称数组assignees :用户登录数组milestone :里程碑 ID
| repo
|
create-repository
| 创建新的存储库 | name :仓库名称description :仓库描述private :是否私有auto_init :使用 README 初始化gitignore_template :添加 .gitignore license_template :添加许可证org :组织名称
| repo
|
update-repository
| 更新存储库设置 | owner :存储库所有者repo :存储库名称description :新描述private :更改隐私default_branch :更改默认分支has_issues :启用/禁用问题has_projects :启用/禁用项目has_wiki :启用/禁用 wiki archived :存档/取消存档
| repo
|
delete-repository
| 删除存储库 | owner :仓库所有者repo :仓库名称confirm :确认(必须为真)
| delete_repo
|
list-workflows
| 列出 GitHub Actions 工作流程 | owner :存储库所有者repo :存储库名称page :页码perPage :每页项目数
| actions:read
|
list-workflow-runs
| 列出工作流程运行 | owner :存储库所有者repo :存储库名称workflow_id :工作流 ID/文件名branch :按分支过滤status :按状态过滤page :页码perPage :每页项目数
| actions:read
|
trigger-workflow
| 触发工作流 | owner :存储库所有者repo :存储库名称workflow_id :工作流 ID/文件名ref :Git 参考inputs :工作流输入
| actions:write
|
get-license-info
| 获取 GitHub Enterprise 许可证信息 | - | 需要 site_admin(管理员)帐户 |
get-enterprise-stats
| 获取 GitHub Enterprise 系统统计信息 | - | 需要 site_admin(管理员)帐户 |
注意:对于企业专用工具( get-license-info和get-enterprise-stats ),需要具有站点管理员权限的用户。建议使用经典个人访问令牌 (Classic Personal Access Token),因为细粒度令牌可能不支持这些企业级权限。
使用 Cursor 中的工具
设置好 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")
管理问题
# List issues
mcp_github_enterprise_list_issues(owner="octocat", repo="hello-world", state="all")
# Get issue details
mcp_github_enterprise_get_issue(owner="octocat", repo="hello-world", issue_number=1)
# Get issue/PR comments
mcp_github_enterprise_list_issue_comments(owner="octocat", repo="hello-world", issue_number=1)
# Create a new issue
mcp_github_enterprise_create_issue(
owner="octocat",
repo="hello-world",
title="Found a bug",
body="Here is a description of the bug",
labels=["bug", "important"]
)
使用存储库内容
mcp_github_enterprise_get_content(owner="octocat", repo="hello-world", path="README.md")
存储库管理
# Create a new repository
mcp_github_enterprise_create_repository(
name="new-project",
description="This is a new project",
private=true,
auto_init=true
)
# Update repository settings
mcp_github_enterprise_update_repository(
owner="octocat",
repo="hello-world",
description="Updated description",
has_issues=true
)
用户管理(仅限企业)
这些功能专为 GitHub Enterprise Server 环境设计,需要管理权限:
# List all users in the GitHub Enterprise instance
mcp_github_enterprise_list_users(filter="active", per_page=100)
# Get a specific user's details
mcp_github_enterprise_get_user(username="octocat")
# Create a new user (Enterprise only)
mcp_github_enterprise_create_user(
login="newuser",
email="newuser@example.com",
name="New User",
company="ACME Inc."
)
# Update a user's information (Enterprise only)
mcp_github_enterprise_update_user(
username="octocat",
email="updated-email@example.com",
location="San Francisco"
)
# Suspend a user (Enterprise only)
mcp_github_enterprise_suspend_user(
username="octocat",
reason="Violation of terms of service"
)
# Unsuspend a user (Enterprise only)
mcp_github_enterprise_unsuspend_user(username="octocat")
# List organizations a user belongs to
mcp_github_enterprise_list_user_orgs(username="octocat")
API 改进
贡献
欢迎贡献代码!欢迎提交 Pull 请求。
执照
国际学习中心