MCP GitHub Server
MCP GitHub Server
可扩展的 MCP HTTP 服务器,用于 GitHub API,具备模块化架构和自动工具发现功能。
功能
服务器提供 19 个工具 用于与 GitHub 交互:
📁 文件操作 (4)
工具 | 描述 |
| 从仓库读取文件内容 |
| 创建和更新文本文件 |
| 创建和更新二进制文件(base64) |
| 删除文件(自动获取 SHA) |
📝 提交 (2)
工具 | 描述 |
| 最近提交列表 |
| 提交的检查状态 |
⚙️ 工作流 (7)
工具 | 描述 |
| 最新构建的错误 |
| 特定工作流运行的日志 |
| 运行中所有作业的完整日志 |
| 按 YAML 文件名获取工作流运行 |
| 运行列表,包含 run_id 和状态 |
| 最新运行的 run_id |
| 运行中所有步骤及其状态的列表 |
🏗️ 构建与调试 (6)
工具 | 描述 |
| 监控构建 |
| 自动修复构建错误(Android/iOS) |
| Android 构建的详细错误 |
| iOS 构建的详细错误 |
| 按名称获取特定步骤的日志 |
| 创建/更新并自动获取 SHA |
Related MCP server: git-mcp
安装
git clone https://github.com/LeonidYasin/mcp-server.git
cd mcp-server
pip install flask httpx python-dotenv flask-cors运行
python -m mcp_server.server服务器运行在 http://0.0.0.0:3001,MCP 端点为:POST /mcp。
GitHub 令牌通过 Authorization: Bearer <token> 请求头传递。
连接到 DeepSeek++
在 DeepSeek++ 插件设置中:
URL:
http://127.0.0.1:3001/mcp类型: HTTP
请求头:
Authorization: Bearer <ваш_github_token>
项目结构
mcp-server/
├── pyproject.toml
├── README.md
└── mcp_server/
├── __init__.py
├── server.py # Flask HTTP-сервер
├── core/
│ ├── __init__.py
│ ├── tool.py # Tool dataclass
│ └── registry.py # ToolRegistry с авто-обнаружением
└── tools/
├── __init__.py
└── github/
├── __init__.py # Экспорт инструментов
├── client.py # GitHub API HTTP-клиент
├── file_ops.py # get_file_contents, create_or_update_file, delete_file
├── file_sha_ops.py # create_or_update_file_with_sha
├── create_update_binary.py # create_or_update_binary_file
├── commits.py # list_commits, get_commit_status
├── workflows.py # workflow-инструменты (4 шт)
├── workflow_runs.py # list_workflow_runs, get_latest_run_id, get_workflow_run_steps, get_run_logs_by_step
├── build_logs.py # watch_build
├── build_logs_loader.py # auto_fix_build, get_android_build_error, get_ios_build_error
└── build_logs_tools.py # вспомогательные функции для сборки如何添加新工具
步骤 1:在 mcp_server/tools/github/ 中创建文件
示例:mcp_server/tools/github/create_branch.py
"""MCP tool: create_branch - создаёт новую ветку."""
from mcp_server.core.registry import mcp_tool
from mcp_server.tools.github.client import GitHubClient
@mcp_tool(
name="create_branch",
description="Создаёт новую ветку в репозитории",
parameters={
"owner": {"type": "string", "description": "Владелец репозитория"},
"repo": {"type": "string", "description": "Имя репозитория"},
"branch": {"type": "string", "description": "Имя новой ветки"},
"from_branch": {"type": "string", "description": "Источник (по умолчанию main)"},
},
required=["owner", "repo", "branch"],
)
def create_branch(client: GitHubClient, owner: str, repo: str, branch: str, from_branch: str = "main") -> dict:
"""Создать новую ветку."""
# 1. Получаем SHA родительской ветки
ref_resp = client._request(
"GET", f"/repos/{owner}/{repo}/git/ref/heads/{from_branch}"
)
sha = ref_resp.json()["object"]["sha"]
# 2. Создаём ветку
client._request(
"POST",
f"/repos/{owner}/{repo}/git/refs",
json={"ref": f"refs/heads/{branch}", "sha": sha},
)
return {
"content": [{
"type": "text",
"text": f"✅ Ветка '{branch}' создана из '{from_branch}'"
}]
}步骤 2:导出工具
在 mcp_server/tools/github/__init__.py 中添加一行:
from mcp_server.tools.github.create_branch import create_branch步骤 3:重启服务器
# Остановите Ctrl+C и снова запустите
python -m mcp_server.server工具将自动出现在列表中。无需任何其他配置。
自动发现的工作原理
ToolRegistry(位于 mcp_server/core/registry.py)在启动时:
扫描
mcp_server/tools/查找所有子包(包含
__init__.py的目录)导入它们并查找带有
@mcp_tool装饰器的函数注册找到的工具
工具编写规则
函数必须是同步的,并将
client: GitHubClient作为第一个参数@mcp_tool装饰器定义:name— 工具名称(调用时使用的名称)description— 给 AI 助手的描述parameters— 参数字典,格式为 JSON Schemarequired— 必填参数列表
需要返回
dict,其中包含content键——对象列表{"type": "text", "text": "..."}对于 GitHub API 请求,请使用
client._request(method, path, ...)
复制模板
"""MCP tool: имя_инструмента - краткое описание."""
from mcp_server.core.registry import mcp_tool
from mcp_server.tools.github.client import GitHubClient
@mcp_tool(
name="имя_инструмента",
description="Что делает инструмент",
parameters={
"owner": {"type": "string", "description": "Владелец репозитория"},
"repo": {"type": "string", "description": "Имя репозитория"},
},
required=["owner", "repo"],
)
def имя_инструмента(client: GitHubClient, owner: str, repo: str) -> dict:
# Ваш код здесь
return {
"content": [{"type": "text", "text": "Результат работы"}]
}GitHub 令牌要求
令牌必须具有以下权限(scopes):
repo(或Contents: Read and write)— 用于文件操作Actions: Read— 用于查看工作流Metadata: Read— 用于基本信息(通常默认包含)
通过 curl 测试服务器
# Проверка списка инструментов
curl -X POST http://127.0.0.1:3001/mcp \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <токен>" \
-d '{"jsonrpc":"2.0","id":"1","method":"tools/list","params":{}}'
# Чтение файла
curl -X POST http://127.0.0.1:3001/mcp \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <токен>" \
-d '{"jsonrpc":"2.0","id":"2","method":"tools/call","params":{"name":"get_file_contents","arguments":{"owner":"LeonidYasin","repo":"mcp-server","path":"README.md"}}}'版本记录
v0.1.0 — stdio 传输,基本模块化架构
v0.2.0 — Flask HTTP 传输,10 个工具,自动发现,开发者文档
v0.3.0 — 新增 9 个工具:共 19 个,包括工作流、构建和调试相关功能
This server cannot be deployed
Maintenance
Related MCP Connectors
Create, deploy, and operate MCP servers directly from your GitHub repositories.
GitHub MCP — wraps the GitHub public REST API (no auth required for public endpoints)
A MCP server built for developers enabling Git based project management with project and personal…
Nifty's MCP server — exposes tasks, projects, messages, and files as tools for AI agents.
Related MCP Servers
- -licenseNot gradedqualityAmaintenanceMCP Server for the GitHub API, enabling file operations, repository management, search functionality, and more.189,189 npm91,812MIT
- FlicenseNot gradedqualityDmaintenanceStandalone MCP server for GitHub that enables repository management, branch operations, pull request handling, and commit retrieval via tools listed in the README.1-
- AlicenseBqualityDmaintenanceMCP (Model Context Protocol) server for GitHub API integration. This server provides comprehensive tools for interacting with GitHub repositories, issues, pull requests, branches, and code search through a unified interface.156 npmMIT
- AlicenseNot gradedqualityBmaintenanceA lightweight MCP server that exposes GitHub operations as tools over HTTP, enabling any MCP-compatible client to interact with GitHub repositories without a built-in connector.1MIT