Skip to main content
Glama
LeonidYasin

MCP GitHub Server

by LeonidYasin

MCP GitHub Server

可扩展的 MCP HTTP 服务器,用于 GitHub API,具备模块化架构和自动工具发现功能。

功能

服务器提供 19 个工具 用于与 GitHub 交互:

📁 文件操作 (4)

工具

描述

get_file_contents

从仓库读取文件内容

create_or_update_file

创建和更新文本文件

create_or_update_binary_file

创建和更新二进制文件(base64)

delete_file

删除文件(自动获取 SHA)

📝 提交 (2)

工具

描述

list_commits

最近提交列表

get_commit_status

提交的检查状态

⚙️ 工作流 (7)

工具

描述

get_latest_workflow_error

最新构建的错误

get_workflow_run_logs

特定工作流运行的日志

get_full_workflow_logs

运行中所有作业的完整日志

get_workflow_by_file

按 YAML 文件名获取工作流运行

list_workflow_runs

运行列表,包含 run_id 和状态

get_latest_run_id

最新运行的 run_id

get_workflow_run_steps

运行中所有步骤及其状态的列表

🏗️ 构建与调试 (6)

工具

描述

watch_build

监控构建

auto_fix_build

自动修复构建错误(Android/iOS)

get_android_build_error

Android 构建的详细错误

get_ios_build_error

iOS 构建的详细错误

get_run_logs_by_step

按名称获取特定步骤的日志

create_or_update_file_with_sha

创建/更新并自动获取 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)在启动时:

  1. 扫描 mcp_server/tools/

  2. 查找所有子包(包含 __init__.py 的目录)

  3. 导入它们并查找带有 @mcp_tool 装饰器的函数

  4. 注册找到的工具

工具编写规则

  1. 函数必须是同步的,并将 client: GitHubClient 作为第一个参数

  2. @mcp_tool 装饰器定义:

    • name — 工具名称(调用时使用的名称)

    • description — 给 AI 助手的描述

    • parameters — 参数字典,格式为 JSON Schema

    • required — 必填参数列表

  3. 需要返回 dict,其中包含 content 键——对象列表 {"type": "text", "text": "..."}

  4. 对于 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 个,包括工作流、构建和调试相关功能

Maintenance

ActivityMaintained
ResponsivenessSyncing

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

Related MCP Servers

  • F
    license
    Not graded
    quality
    D
    maintenance
    Standalone MCP server for GitHub that enables repository management, branch operations, pull request handling, and commit retrieval via tools listed in the README.
    1
  • A
    license
    B
    quality
    D
    maintenance
    MCP (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.
    15
    14
    MIT
  • F
    license
    Not graded
    quality
    B
    maintenance
    A 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.
    1

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/LeonidYasin/mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server