github-mcp

github-mcp

MCP server for the GitHub REST API: issues, PRs, repos; read always on, write env-gated.

Category
访问服务器

README

github-mcp

PyPI MCP Registry License: MIT tests

A public read+write MCP server over the GitHub REST API, built to the desktop-mcp/rag-mcp/mcp-factory standard (own pyproject, fastmcp server, honest README, real test suite) with env-gated tool groups (write disabled by default). Not the official GitHub MCP server -- see below.

Quickstart (60 seconds)

pip install jaimenbell-github-mcp
// Add to your MCP host config (e.g. Claude Desktop/Code's mcpServers block)
{
  "mcpServers": {
    "github-mcp": {
      "command": "github-mcp"
    }
  }
}

The write tool group (issue/PR mutations) is off by default -- see Env vars below to enable it.

What this is / is not

This is a reference portfolio implementation demonstrating a hardened read+write MCP server pattern over a real external SaaS API (GitHub) -- env-gated tool groups, typed error/rate-limit handling, auth that degrades gracefully, a real test suite. It exists to show, concretely, "I build read/write MCP servers over external APIs" with a link a client can click.

It is NOT the official GitHub MCP server. It does not aim for parity with GitHub's own MCP offering (GraphQL, Actions, webhooks, GitHub Apps are all out of scope -- see below). It started life as a factory-scaffolded read-only demo (mcp-factory's generated/github_read_server.py) and was hand-hardened into this standalone read+write server -- the scaffold-then-harden path is itself part of the story this repo tells.

Tool groups

Group Tools Default state
read get_repo, list_issues, get_issue, list_pull_requests, get_pull_request, get_file_content, search_repos, get_user, list_commits always on, works unauthenticated (GitHub's 60 req/hr tier)
write create_issue, comment_on_issue, update_issue_state, add_labels, create_pr_review_comment env-gated, OFF by default -- requires GITHUB_MCP_ENABLE_WRITE=1 and GITHUB_TOKEN

A disabled write call returns a structured policy_refusal error (never a silent no-op, never a crash). A write call with the group enabled but no token returns a structured auth_required error -- the group gate and the token precondition are checked independently, both before any network call.

Write-safety-off-by-default

This is defense-in-depth, mirroring desktop-mcp's input group: harness-level permission prompts are the first gate, but the server itself refuses every write tool unless its own environment explicitly opts in with GITHUB_MCP_ENABLE_WRITE=1, and even then refuses without a GITHUB_TOKEN. A misconfigured or overly-permissive MCP host cannot turn on GitHub mutations this process wasn't deliberately configured to allow. The registration this repo ships with (see ~/.claude.json's github-mcp entry) has the write group absent from env -- enabling it is a deliberate per-registration operator choice, not a code change.

Honest-capabilities table

Every claim below maps to the file that implements it and the test(s) that verify it -- no capability is asserted without a corresponding implementation and test.

Claim Implementation Verified by
Repo metadata (stars, language, license, default branch, archived flag...) github_mcp/groups/read.py::get_repo tests/test_read.py::TestGetRepo, live: tests/test_live_smoke.py::test_live_get_repo_real_json
List / fetch issues (PRs filtered from list) github_mcp/groups/read.py::list_issues, get_issue tests/test_read.py::TestListIssues, TestGetIssue
List / fetch pull requests github_mcp/groups/read.py::list_pull_requests, get_pull_request tests/test_read.py::TestListPullRequests, TestGetPullRequest
Read a repo file's content (base64-decoded, binary detected not decoded) github_mcp/groups/read.py::get_file_content tests/test_read.py::TestGetFileContent
Search public repositories github_mcp/groups/read.py::search_repos tests/test_read.py::TestSearchRepos
Public user/org profile github_mcp/groups/read.py::get_user tests/test_read.py::TestGetUser
List commits on a branch/ref github_mcp/groups/read.py::list_commits tests/test_read.py::TestListCommits
Open an issue github_mcp/groups/write.py::create_issue tests/test_write.py::TestCreateIssue
Comment on an issue/PR github_mcp/groups/write.py::comment_on_issue tests/test_write.py::TestCommentOnIssue
Open/close an issue github_mcp/groups/write.py::update_issue_state tests/test_write.py::TestUpdateIssueState
Add labels to an issue/PR github_mcp/groups/write.py::add_labels tests/test_write.py::TestAddLabels
Create a PR review comment on a diff line github_mcp/groups/write.py::create_pr_review_comment tests/test_write.py::TestCreatePrReviewComment
Write group OFF by default, structured refusal when disabled github_mcp/config.py::group_enabled, gated_write tests/test_config.py::TestGroupEnabled, tests/test_write.py::TestGateDisabledByDefault
Write tools require a token even when the group is enabled github_mcp/config.py::check_write_preconditions tests/test_config.py::TestCheckWritePreconditions, tests/test_write.py::TestAuthRequiredWhenGroupEnabled
Fine-grained PAT auth, degrades to unauthenticated tier when absent github_mcp/client.py::_headers tests/test_client.py::TestAuthHeaderInjection, tests/test_read.py::TestUnauthDegrade
GitHub primary rate-limit (403 + X-RateLimit-Reset) and secondary rate-limit (403 + Retry-After, no X-RateLimit-Remaining) both surface as a typed error with reset/retry time, never a crash github_mcp/client.py::_rate_limit_error, _is_rate_limit_response tests/test_client.py::TestRateLimitError, tests/test_client.py::TestRateLimitError::test_secondary_rate_limit_no_ratelimit_headers_retry_after_only, tests/test_read.py::TestUnauthDegrade::test_get_repo_rate_limited_without_token_is_typed
Malformed owner/repo/path (control chars etc.) that would raise httpx.InvalidURL surfaces as a typed error, never an uncaught exception github_mcp/client.py::request tests/test_client.py::TestNetworkError::test_malformed_path_raises_invalid_url_caught_as_network_error
Generic 4xx/5xx surfaces as a typed error, never a crash github_mcp/client.py::_api_error tests/test_client.py::TestApiError
Non-JSON / malformed responses and network failures surface as typed errors github_mcp/client.py::_handle_response, request tests/test_client.py::TestDecodeError, TestNetworkError

Limitations (read before relying on this)

  • REST v1 only. No GraphQL API coverage.
  • No webhooks / GitHub App auth. Fine-grained PAT only.
  • No Actions/workflow-dispatch tools. Issue/PR CRUD is the v1 write surface.
  • Unauthenticated read is rate-limited to 60 req/hr by GitHub itself (10 req/min for search) -- expect rate_limited errors under sustained unauthenticated use; set GITHUB_TOKEN (even a read-only fine-grained PAT) to raise this considerably.
  • get_file_content truncates past 100KB and reports (rather than decodes) non-UTF-8 files.
  • No pagination beyond a single page for list endpoints (limit, capped per-endpoint, is the only page-size control in v1).
  • Not registered with the mcp-factory hub. Ships as a standalone repo (own pyproject, system Python312 install), matching the rag-mcp/desktop-mcp model.

Env vars

Var Effect Default
GITHUB_MCP_ENABLE_WRITE enable the write tool group unset (off)
GITHUB_TOKEN fine-grained PAT; read works without it (degraded unauth rate), write requires it unset
GITHUB_MCP_LIVE 1 to run the real-network smoke test (see Testing) unset (skip)

Usage examples

// A tool call from the MCP host, illustrative -- not a shell command.
{"tool": "get_repo", "arguments": {"owner": "anthropics", "repo": "anthropic-sdk-python"}}
// -> {"ok": true, "full_name": "anthropics/anthropic-sdk-python", "stargazers_count": 1234, ...}

// write group disabled (default):
{"tool": "create_issue", "arguments": {"owner": "o", "repo": "r", "title": "bug"}}
// -> {"ok": false, "error": {"type": "policy_refusal", "group": "write", "required_env": "GITHUB_MCP_ENABLE_WRITE", ...}}

// write group enabled, no token set:
{"tool": "create_issue", "arguments": {"owner": "o", "repo": "r", "title": "bug"}}
// -> {"ok": false, "error": {"type": "auth_required", "tool": "create_issue", ...}}

Testing

# unit suite (respx-mocked api.github.com, no real network touched)
python -m pytest -q

# handshake check -- prints every registered tool name
python scripts/list_tools.py

# real-network read smoke (get_repo against a stable public repo;
# no write smoke exists anywhere in this suite -- see safety rails above)
GITHUB_MCP_LIVE=1 python -m pytest -q -k live_get_repo

Install

pip install -r requirements.txt   # or: pip install .
# deps: fastmcp==3.4.2, httpx==0.28.1
# test-only: pytest==9.0.3, respx==0.23.1

Setup / connect

  1. pip install -r requirements.txt on Python 3.12+.
  2. (Optional) generate a fine-grained PAT scoped to the repos you want read+write access to (Issues: read/write, Pull requests: read/write, Contents: read is enough for v1). Read tools work with no token at all -- they just run at GitHub's unauthenticated 60 req/hr tier.
  3. Add to your MCP host config (e.g. ~/.claude.json):
{
  "mcpServers": {
    "github-mcp": {
      "command": "C:\\Users\\jaime\\AppData\\Local\\Programs\\Python\\Python312\\python.exe",
      "args": ["C:\\Users\\jaime\\projects\\github-mcp\\run_server.py"],
      "env": {
        "GITHUB_TOKEN": "your-fine-grained-pat-here"
        // GITHUB_MCP_ENABLE_WRITE intentionally absent -- write stays off
        // until you deliberately opt in per-deployment.
      }
    }
  }
}
  1. To enable write tools for a given deployment, add "GITHUB_MCP_ENABLE_WRITE": "1" to that entry's env block. This is a registration-time operator decision, not a code change.

Registered in ~/.claude.json as github-mcp (stdio, system Python312, read group always on, write group absent from env -- off).

Commercial support

Maintained by Jaimen Bell. For production MCP integrations, custom servers, or agent-reliability work, see jaimenbell.dev or sponsor ongoing maintenance via GitHub Sponsors.

<!-- MCP registry ownership marker --> mcp-name: io.github.jaimenbell/github-mcp

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选