@bennycho/github-enterprise-mcp
v1.0.4
Published
MCP server for GitHub Enterprise API integration with Cursor, enabling AI access to repositories, issues, PRs and workflows
Maintainers
Readme
GitHub Enterprise MCP Server
這是一個用於與 GitHub Enterprise API 整合的 MCP (Model Context Protocol) 伺服器。此伺服器提供 MCP 介面,讓您能輕鬆地在 Cursor 中存取 GitHub Enterprise 的儲存庫資訊、Issues、PR 等內容。
相容性 (Compatibility)
本專案主要是為 GitHub Enterprise Server 環境設計,但也適用於:
- GitHub.com
- GitHub Enterprise Cloud
注意:某些企業特定功能(如授權資訊和企業統計數據)在 GitHub.com 或 GitHub Enterprise Cloud 上無法運作。
主要功能 (Key Features)
- 從 GitHub Enterprise 實例檢索儲存庫列表
- 獲取詳細的儲存庫資訊
- 列出儲存庫分支
- 查看檔案和目錄內容
- 管理 Issues 和 Pull Requests (PR)
- 儲存庫管理(建立、更新、刪除)
- GitHub Actions 工作流程 (Workflows) 管理
- 使用者管理(列出、建立、更新、刪除、暫停/恢復使用者)
- 存取企業統計數據
- 增強的錯誤處理和友善的回應格式
開始使用 (Getting Started)
先決條件 (Prerequisites)
- Node.js 18 或更高版本
- 能夠存取 GitHub Enterprise 實例
- 個人存取權杖 (Personal Access Token, 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
安裝與設定 (Installation and Setup)
本地開發(使用並行模式)
此方法推薦用於需要自動重新編譯和伺服器重啟的活躍開發過程:
複製儲存庫並安裝所需套件:
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)
此方法適用於本地開發:
# 複製儲存庫後
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選項 3:使用 npx(當套件已發布時)
如果套件已發布到公共 npm 註冊表:
npx @bennycho/github-enterprise-mcp --token=your_github_token --github-enterprise-url=https://github.your-company.com/api/v3與 AI 工具整合 (Integration with AI Tools)
Claude Desktop
將以下內容新增到您的 claude_desktop_config.json:
{
"mcpServers": {
"github-enterprise": {
"command": "npx",
"args": ["-y", "@bennycho/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 並前往 Settings (設定)
- 導航至 AI > MCP Servers
- 編輯您的
.cursor/mcp.json檔案:
{ "mcpServers": { "github-enterprise": { "url": "http://localhost:3000/sse" } } }重啟 Cursor 以套用變更
替代方案:Command 模式
或者,您可以將 Cursor 設定為使用 Command 模式,儘管 URL 模式更為可靠:
- 開啟 Cursor 並前往 Settings (設定)
- 導航至 AI > MCP Servers
- 點擊 Add MCP Server (新增 MCP 伺服器)
- 輸入以下詳細資訊:
- Name: GitHub Enterprise
- Command:
npx - Arguments:
@bennycho/github-enterprise-mcp - Environment Variables:
GITHUB_ENTERPRISE_URL: 您的 GitHub Enterprise API URLGITHUB_TOKEN: 您的 GitHub 個人存取權杖 (PAT)
或者,您可以手動編輯 .cursor/mcp.json 檔案以包含:
{
"mcpServers": {
"github-enterprise": {
"command": "npx",
"args": [
"@bennycho/github-enterprise-mcp"
],
"env": {
"GITHUB_ENTERPRISE_URL": "https://github.your-company.com/api/v3",
"GITHUB_TOKEN": "your_github_token"
}
}
}
}語言設定 (Language Configuration)
此 MCP 伺服器支援英文和韓文。您可以使用以下方式設定語言:
環境變數
# 設定語言為韓文
export LANGUAGE=ko
# 或者在 .env 檔案中
LANGUAGE=ko命令列參數
# 設定語言為韓文
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 工具 (Available MCP Tools)
此 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 | 列出儲存庫中的 Pull Requests | owner: 儲存庫擁有者repo: 儲存庫名稱state: PR 狀態篩選sort: 排序標準direction: 排序方向page: 頁碼per_page: 每頁項目數 | repo |
| get-pull-request | 獲取 Pull Request 詳情 | owner: 儲存庫擁有者repo: 儲存庫名稱pull_number: Pull Request 編號 | repo |
| create-pull-request | 建立新的 Pull Request | owner: 儲存庫擁有者repo: 儲存庫名稱title: PR 標題head: Head 分支base: Base 分支body: PR 描述draft: 建立為草稿 PR | repo |
| merge-pull-request | 合併 Pull Request | owner: 儲存庫擁有者repo: 儲存庫名稱pull_number: Pull Request 編號merge_method: 合併方式commit_title: 提交標題commit_message: 提交訊息 | repo |
| list-issues | 列出儲存庫中的 Issues | owner: 儲存庫擁有者repo: 儲存庫名稱state: Issue 狀態篩選sort: 排序標準direction: 排序方向page: 頁碼per_page: 每頁項目數 | repo |
| get-issue | 獲取 Issue 詳情 | owner: 儲存庫擁有者repo: 儲存庫名稱issue_number: Issue 編號 | repo |
| list-issue-comments | 列出 Issue 或 Pull Request 的留言 | owner: 儲存庫擁有者repo: 儲存庫名稱issue_number: Issue/PR 編號page: 頁碼per_page: 每頁項目數 | repo |
| create-issue | 建立新的 Issue | owner: 儲存庫擁有者repo: 儲存庫名稱title: Issue 標題body: Issue 內容labels: 標籤名稱陣列assignees: 被指派者登入帳號陣列milestone: 里程碑 ID | repo |
| create-repository | 建立新的儲存庫 | name: 儲存庫名稱description: 儲存庫描述private: 是否私人auto_init: 使用 README 初始化gitignore_template: 新增 .gitignorelicense_template: 新增授權條款org: 組織名稱 | repo |
| update-repository | 更新儲存庫設定 | owner: 儲存庫擁有者repo: 儲存庫名稱description: 新描述private: 變更隱私設定default_branch: 變更預設分支has_issues: 啟用/停用 issueshas_projects: 啟用/停用 projectshas_wiki: 啟用/停用 wikiarchived: 封存/取消封存 | repo |
| delete-repository | 刪除儲存庫 | owner: 儲存庫擁有者repo: 儲存庫名稱confirm: 確認 (必須為 true) | 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),需要具有 網站管理員 (site administrator) 權限的使用者。建議使用 Classic Personal Access Token,因為 Fine-grained tokens 可能不支援這些企業級權限。
在 Cursor 中使用工具
設定好 MCP 伺服器並配置 Cursor 連接後,您可以在 Cursor 的 AI 聊天中直接使用 GitHub Enterprise 工具。以下是一些範例:
列出儲存庫
mcp_github_enterprise_list_repositories(owner="octocat")獲取儲存庫資訊
mcp_github_enterprise_get_repository(owner="octocat", repo="hello-world")列出 Pull Requests
mcp_github_enterprise_list_pull_requests(owner="octocat", repo="hello-world", state="open")管理 Issues
# 列出 issues
mcp_github_enterprise_list_issues(owner="octocat", repo="hello-world", state="all")
# 獲取 issue 詳情
mcp_github_enterprise_get_issue(owner="octocat", repo="hello-world", issue_number=1)
# 獲取 issue/PR 留言
mcp_github_enterprise_list_issue_comments(owner="octocat", repo="hello-world", issue_number=1)
# 建立新的 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")儲存庫管理
# 建立新的儲存庫
mcp_github_enterprise_create_repository(
name="new-project",
description="This is a new project",
private=true,
auto_init=true
)
# 更新儲存庫設定
mcp_github_enterprise_update_repository(
owner="octocat",
repo="hello-world",
description="Updated description",
has_issues=true
)使用者管理(僅限 Enterprise)
這些功能專為 GitHub Enterprise Server 環境設計,需要管理員權限:
# 列出 GitHub Enterprise 實例中的所有使用者
mcp_github_enterprise_list_users(filter="active", per_page=100)
# 獲取特定使用者的詳細資訊
mcp_github_enterprise_get_user(username="octocat")
# 建立新使用者 (僅限 Enterprise)
mcp_github_enterprise_create_user(
login="newuser",
email="[email protected]",
name="New User",
company="ACME Inc."
)
# 更新使用者資訊 (僅限 Enterprise)
mcp_github_enterprise_update_user(
username="octocat",
email="[email protected]",
location="San Francisco"
)
# 暫停使用者 (僅限 Enterprise)
mcp_github_enterprise_suspend_user(
username="octocat",
reason="Violation of terms of service"
)
# 恢復使用者 (僅限 Enterprise)
mcp_github_enterprise_unsuspend_user(username="octocat")
# 列出使用者所屬的組織
mcp_github_enterprise_list_user_orgs(username="octocat")API 改進 (API Improvements)
- 靈活的 API URL 配置(支援各種環境變數和命令列參數)
- 增強的錯誤處理和逾時管理
- 友善的回應格式和訊息
貢獻 (Contributing)
歡迎提交貢獻!請隨意提交 Pull Request。
授權 (License)
ISC

