GitHub MCP服务器

一个轻量级、高效的GitHub MCP服务器,提供CLI优先的方法,用于GitHub工具调用和管理。

  • by gsornsen
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 gsornsen/lite-github-mcp-server

使用说明

Lite GitHub MCP 服务器

一个针对GitHub的极简、上下文高效的MCP服务器,采用命令行界面(CLI)优先的方法。

要求

  • Python 3.10及以上版本
  • 已安装 git 和 gh CLI(用于后续里程碑)

快速入门

# Install uv (https://github.com/astral-sh/uv)
# Then setup dev env
just setup

# Run tests
just test

# Run server
just run

# Format and lint
just fmt && just lint

使用 uvx 运行(无需本地检出)

# One-off run of the MCP server from PyPI using uvx
uvx lite-github-mcp

# CLI client (tools introspection and tool calls)
uvx lite-github-mcp-cli tools
uvx lite-github-mcp-cli call gh.ping

Open WebUI 集成(MCP)

  • 使用MCP编排器(mcpo):将mcpo指向命令 uvx lite-github-mcp。
# Example mcpo config snippet
servers:
  github:
    command: ["uvx", "lite-github-mcp"]
  • 不使用mcpo:如果您的Open WebUI支持直接配置MCP命令,请将其设置为 uvx lite-github-mcp。
# Example: environment-driven configuration (adjust to your Open WebUI setup)
export MCP_SERVER_GITHUB_COMMAND="uvx lite-github-mcp"

包装和构建

  • 使用UV的构建后端(uv_build) 用于 PEP 517 构建,通过 uv build。
  • 开发依赖项通过 [dependency-groups] 并通过(某种方式)安装 uv sync --group dev。
  • 在GitHub Actions中,发布创建时会自动进行发布。

Docker(注:Docker是一个用于开发、部署和运行应用程序的开源平台,它允许开发者将应用程序及其依赖打包到一个可移植的容器中,从而确保应用程序在不同环境中都能一致地运行。)

just docker_build
just compose_up
# ... use it ...
just compose_down

注释

  • 目标支持 Python 3.10+; uvloop 在Linux上仍然是可选的。
  • gh.ping 和 gh.whoami 可供使用; whoami 返回一个最小的认证状态。
  • 有关FastMCP的概念和最新的API详细信息,请参阅MDX文档:https://github.com/jlowin/fastmcp/tree/main/docs

可观测性(可选)

  • 工具调用的结构化JSON日志记录(可选启用):
# Enable lightweight timing logs (one line per tool call)
LGMCP_LOG_JSON=1 just run
# or
LGMCP_LOG_JSON=1 uv run python -m lite_github_mcp.server

发射场: tool, arg_keys, duration_ms,可选 error。

  • 缓存与ETag:
# Disk-backed cache using `diskcache` under XDG cache dir
# ETag-based conditional requests are enabled for GitHub REST via gh api
# Cache TTLs: lists=30s, meta=5m, blobs=1h
# Automatic rate-limit backoff with Retry-After respected (bounded retries)
  • 上下文预算检查:
    • CI 对工具注册表实施预算限制(包括字节和代币估算)
    • 本地实时测试(模式感知):
# Run only the marked context test and print a brief report
just test_context
# Or with pytest directly
uv run pytest -q -m context_budget -s

你会看到一个简短的报告,类似:

Context budget (tool registry):
  minimal bytes: 1084 / 8192 (13.2%)
  full bytes:    5628 / 32768 (17.2%)
  tokens:        1407 / 4000 (35.2%)

CLI 示例(分页和范围)

# List tools
# Mono-tool by default; set multi-tool mode via env:
# LGMCP_MULTI_TOOLS=1 just cli_tools
just cli_tools

# Trees (limit, cursor)
just cli_call gh.file.tree '{"repo_path": ".", "ref": "HEAD", "limit": 3}'
# Use the returned next_cursor to fetch next page
just cli_call gh.file.tree '{"repo_path": ".", "ref": "HEAD", "limit": 3, "cursor": "<next>"}'

# Search (limit, cursor)
just cli_call gh.search.files '{"repo_path": ".", "pattern": "FastMCP", "limit": 2}'
# Restrict search to paths
just cli_call gh.search.files '{"repo_path": ".", "pattern": "TODO", "paths": ["src/", "docs/"]}'

# Blob ranges (offset, max_bytes)
just cli_call gh.file.blob '{"repo_path": ".", "blob_sha": "<sha>", "max_bytes": 128, "offset": 0}'

# PRs (ids-first, meta, timeline)
just cli_call gh.pr.list '{"repo": "gsornsen/lite-github-mcp-server", "state": "open", "limit": 10}'
just cli_call gh.pr.get '{"repo": "gsornsen/lite-github-mcp-server", "number": 3}'
just cli_call gh.pr.timeline '{"repo": "gsornsen/lite-github-mcp-server", "number": 3, "limit": 5}'