GitHub企业MCP服务
一个MCP服务器,它能够与GitHub Enterprise API集成,允许用户通过Cursor访问仓库信息、管理问题、拉取请求、工作流以及其他GitHub功能。
MCP 服务配置
复制以下 JSON 到 OPClaw 或其他 MCP 客户端的配置文件中即可使用
{
"mcpServers": {
"github-enterprise": {
"args": [
"@ddukbg/github-enterprise-mcp"
],
"command": "npx",
"env": {
"GITHUB_ENTERPRISE_URL": "https://github.your-company.com/api/v3",
"GITHUB_TOKEN": "your_github_token"
}
}
}
}
该服务需要配置环境变量:GITHUB_ENTERPRISE_URL、GITHUB_TOKEN
服务介绍
GitHub Enterprise MCP 服务器
这是一个用于与 GitHub Enterprise API 集成的 MCP(Model Context Protocol)服务器。该服务器提供了一个 MCP 接口,以便在 Cursor 中轻松访问来自 GitHub Enterprise 的仓库信息、问题、PR 等。
兼容性
此项目主要设计用于 GitHub Enterprise Server 环境,但也适用于:
- GitHub.com
- GitHub Enterprise Cloud
注意:一些企业特定的功能(如许可证信息和企业统计信息)将不适用于 GitHub.com 或 GitHub Enterprise Cloud。
主要功能
- 从 GitHub Enterprise 实例检索仓库列表
- 获取详细的仓库信息
- 列出仓库分支
- 查看文件和目录内容
- 管理问题和拉取请求
- 仓库管理(创建、更新、删除)
- GitHub Actions 工作流管理
- 用户管理(列出、创建、更新、删除、暂停/恢复用户)
- 访问企业统计信息
- 增强的错误处理和用户友好的响应格式
开始使用
前提条件
- 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 启动容器:
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这将:
- 当文件更改时自动编译 TypeScript 代码
- 当编译的文件更新时重启服务器
- 以 HTTP 模式运行服务器,以便基于 URL 的连接
-
使用 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:
- 在你的 Cursor 的
.cursor/mcp.json文件中添加以下内容:
{ "mcpServers": { "github-enterprise": { "url": "http://localhost:3000/sse" } } } - 在你的 Cursor 的
选项 2:作为全局命令安装(npm link)
此方法对于本地开发非常有用:
# 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
在你的 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 模式(最稳定)
为了在 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 服务器
- 输入以下详细信息:
- 名称: GitHub Enterprise
- 命令:
npx - 参数:
@ddukbg/github-enterprise-mcp - 环境变量:
GITHUB_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 服务器支持英语和韩语。您可以使用以下方法配置语言:
环境变量
# 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 服务器提供以下工具:
| Tool Name | Description | Parameters | Required PAT Permissions |
|---|---|---|---|
list-repositories |
Retrieve repository list for a user or organization | owner: Username/org nameisOrg: Whether it's an organizationtype: Repository typesort: Sort criteriapage: Page numberperPage: Items per page |
repo |
get-repository |
Get detailed repository information | owner: Repository ownerrepo: Repository name |
repo |
list-branches |
List branches of a repository | owner: Repository ownerrepo: Repository nameprotected_only: Whether to show only protected branchespage: Page numberperPage: Items per page |
repo |
get-content |
Retrieve file or directory contents | owner: Repository ownerrepo: Repository namepath: File/directory pathref: Branch/commit (optional) |
repo |
list-pull-requests |
List pull requests in a repository | owner: Repository ownerrepo: Repository namestate: PR state filtersort: Sort criteriadirection: Sort directionpage: Page numberper_page: Items per page |
repo |
get-pull-request |
Get pull request details | owner: Repository ownerrepo: Repository namepull_number: Pull request number |
repo |
create-pull-request |
Create a new pull request | owner: Repository ownerrepo: Repository nametitle: PR titlehead: Head branchbase: Base branchbody: PR descriptiondraft: Create as draft PR |
repo |
merge-pull-request |
Merge a pull request | owner: Repository ownerrepo: Repository namepull_number: Pull request numbermerge_method: Merge methodcommit_title: Commit titlecommit_message: Commit message |
repo |
list-issues |
List issues in a repository | owner: Repository ownerrepo: Repository namestate: Issue state filtersort: Sort criteriadirection: Sort directionpage: Page numberper_page: Items per page |
repo |
get-issue |
Get issue details | owner: Repository ownerrepo: Repository nameissue_number: Issue number |
repo |
list-issue-comments |
List comments on an issue or pull request | owner: Repository ownerrepo: Repository nameissue_number: Issue/PR numberpage: Page numberper_page: Items per page |
repo |
create-issue |
Create a new issue | owner: Repository ownerrepo: Repository nametitle: Issue titlebody: Issue body contentlabels: Array of label namesassignees: Array of user loginsmilestone: Milestone ID |
repo |
create-repository |
Create a new repository | name: Repository namedescription: Repository descriptionprivate: Whether privateauto_init: Initialize with READMEgitignore_template: Add .gitignorelicense_template: Add licenseorg: Organization name |
repo |
update-repository |
Update repository settings | owner: Repository ownerrepo: Repository namedescription: New descriptionprivate: Change privacydefault_branch: Change default branchhas_issues: Enable/disable issueshas_projects: Enable/disable projectshas_wiki: Enable/disable wikiarchived: Archive/unarchive |
repo |
delete-repository |
Delete a repository | owner: Repository ownerrepo: Repository nameconfirm: Confirmation (must be true) |
delete_repo |
list-workflows |
List GitHub Actions workflows | owner: Repository ownerrepo: Repository namepage: Page numberperPage: Items per page |
actions:read |
list-workflow-runs |
List workflow runs | owner: Repository ownerrepo: Repository nameworkflow_id: Workflow ID/filenamebranch: Filter by branchstatus: Filter by statuspage: Page numberperPage: Items per page |
actions:read |
trigger-workflow |
Trigger a workflow | owner: Repository ownerrepo: Repository nameworkflow_id: Workflow ID/filenameref: Git referenceinputs: Workflow inputs |
actions:write |
get-license-info |
Get GitHub Enterprise license information | - | Requires site_admin (Administrator) account |
get-enterprise-stats |
Get GitHub Enterprise system statistics | - | Requires site_admin (Administrator) account |
注意:对于特定于企业的工具(
get-license-info和get-enterprise-stats),需要具有站点管理员权限的用户。建议使用经典个人访问令牌,因为细粒度令牌可能不支持这些企业级权限。
在 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 改进
- 灵活的 API URL 配置(支持多种环境变量和命令行参数)
- 增强的错误处理和超时管理
- 用户友好的响应格式和消息
贡献
欢迎贡献!请随时提交 Pull Request。
许可证
ISC