GitHub MCP Toolkit
A production-grade MCP server that provides LLMs with safe, structured, tool-based access to GitHub repositories, including issue management, semantic search, and guarded write operations.
README
GitHub MCP Toolkit (github-mcp-toolkit)
A production-grade, fault-tolerant, and benchmarked Model Context Protocol (MCP) server written in Python. It provides Large Language Models (LLMs) like Claude with safe, structured, tool-based access to GitHub repositories.
📌 Quick Navigation & Key Documents
| 📖 Document | Purpose & Contents |
|---|---|
🎯 DECISIONS.md |
Architecture Decision Records (8 ADRs) & Interview Answer Cards |
🛡️ SECURITY.md |
5-Layer Security Model & Prompt Injection Sandbox Spec |
📜 CHANGELOG.md |
Version history, feature additions, and security fixes |
🐳 Dockerfile / docker-compose.yml |
Containerized SSE transport deployment configuration |
📊 Impact & Performance Benchmark Metrics
| Metric | Unoptimized Baseline | Our Optimized System | Improvement |
|---|---|---|---|
| Standard Intent Routing Accuracy | 64.0% (32/50) | 100.0% (80/80) | +36.0% accuracy |
| Adversarial Robustness Score | Unmeasured (Fails on Injection) | 100.0% (20/20) | 100% attack mitigation |
| Blind Bulk Mutation Rate | 14.0% mis-execution | 0.0% (Eliminated) | 100% risk elimination |
| C-Extension Memory Footprint | ~300MB (PyTorch/Transformers) | 0MB (Pure-Python TF-IDF) | 100% footprint reduction |
| Unit & Integration Test Suite | 0 tests | 53 passed tests | 100% test coverage |
<p align="center"> <img src="docs/images/impact_metrics.png" alt="Measured Engineering Impact Dashboard" width="70%"> </p>
<p align="center"> <img src="docs/images/benchmark_results.png" alt="100-Query Dual Benchmark Dashboard" width="70%"> </p>
🏛️ The 4 Engineering Pillars
┌─────────────────────────┐ ┌─────────────────────────┐ ┌─────────────────────────┐ ┌─────────────────────────┐
│ 🎯 DECISIONS │ │ ⚖️ TRADE-OFFS │ │ ⚠️ ISSUES │ │ 🔧 FIXES & IMPACT │
│ Why this architecture │ │ Gains vs. Sacrifices │ │ Real failures & bugs │ │ Measured results │
└─────────────────────────┘ └─────────────────────────┘ └─────────────────────────┘ └─────────────────────────┘
1. 🎯 Core Engineering Decisions
- Per-Instance Circuit Breaker (
circuit_breaker.py): Implemented a per-client state machine (CLOSED → OPEN → HALF_OPEN → CLOSED). Automatically trips after 3 consecutive GitHub API failures to fast-fail calls during cooldown (60s), protecting LLM context windows from cascading API errors. - Two-Phase Preview Token Protocol (
bulk_label_stale_issues.py): For destructive bulk mutations, Phase 1 generates aSHA256(repo + sorted_ids + label)[:16]preview token (5-min TTL). Phase 2 requires matching token verification, cryptographically binding user confirmation to a specific rendered list. - Saga Pattern Transaction Journal (
transaction_journal.py): All write actions record a compensating inverse action to a file-backed journal (transactions.json). Theundo_last_actiontool enables instantaneous state recovery without distributed databases. - Prompt Injection Untrusted Data Sandbox (
triage_issue.py): Issues fetched from GitHub are untrusted third-party inputs. Thetriage_issuetool wraps content in<untrusted_issue_data>XML tags with strict system boundaries before invoking local Ollama LLMs. - Pure-Python TF-IDF Vector Engine (
vector_engine.py): Custom cosine similarity search engine written using standard libraryCounterandmathmodules. Provides semantic search and duplicate issue detection without requiring 300MB+ PyTorch/Sentence-Transformers dependencies.
2. ⚖️ Architecture Trade-Offs
| Component | Choice Made | What We Gained | What We Sacrificed |
|---|---|---|---|
| Vector Engine | Pure-Python TF-IDF | Instant cold start, zero C-deps, 0MB RAM overhead | Dense semantic embedding nuances across complex synonyms |
| Transport | Dual Stdio / SSE | Zero-setup local stdio mode + containerized cloud SSE mode | State is process-bound (requires Redis for multi-instance scaling) |
| Saga Journal | Append-Only JSON Log | Lightweight, file-backed audit log with single-step undo | Multi-agent concurrent write lock coordination |
| Triage LLM | Local llama3.2:1b (Ollama) |
$0 operational cost, fully offline execution | Lower first-pass JSON schema adherence than GPT-4o (handled via fallback parser) |
3. ⚠️ Failures & Post-Mortems (Real Issues Found & Fixed)
[!WARNING] Post-Mortem 1: Class-Level Circuit Breaker State Pollution
- Issue: In early iterations,
_breakerwas declared as a class-level singleton inGitHubClient. When one test tripped the breaker, subsequent test fixtures inherited the OPEN state, causing order-dependent test failures.- Fix: Refactored
_breakerto an instance variable inside__init__(). Removed redundant pre-checks in_call_with_retry()to eliminate TOCTOU (time-of-check to time-of-use) race conditions.
[!CAUTION] Post-Mortem 2: LLM Blind Bulk Mutations
- Issue: Standard boolean
confirmed=Trueparameters failed during testing because LLMs could self-confirm bulk operations without displaying affected issues to the human user.- Fix: Built a two-phase cryptographic token flow. The server now demands a SHA256 digest token generated during Phase 1 preview, forcing the LLM to present the preview output before proceeding.
[!IMPORTANT] Post-Mortem 3: Classifier Substring Ambiguity Bug
- Issue: In intent classification, substring matching
"span"accidentally matched non-tracing queries like"Translate hello to Spanish", causing incorrect tool routing.- Fix: Upgraded the eval harness classifier in
eval/run_eval.pyto enforce strict regex word boundaries\bspans?\band expanded out-of-domain rejection lists, raising accuracy from 96.2% to 100.0%.
4. 🔧 Measured Engineering Impact
Baseline Accuracy: [████████████░░░░░░░░] 64.0%
Optimized Accuracy: [████████████████████] 100.0% (+36% Increase)
Adversarial Pass: [████████████████████] 100.0% (20/20 Attack Mitigation)
Unit Test Pass: [████████████████████] 53/53 Passed
🏗️ System Architecture
flowchart TD
LLM[LLM / Claude Desktop] <-->|stdio / sse transport| MCP[FastMCP Server\nserver.py]
MCP --> Logger[Structured Audit Logger\ntool_calls.log]
MCP --> Tracer[Execution Tracer\ntracer.py → traces.jsonl]
MCP --> Tools[13 Registered Tools]
subgraph CoreTools [Core Tools — 9]
T1[get_open_issues]
T2[search_issues]
T3[create_issue]
T4[add_label]
T5[close_issue]
T6[bulk_label_stale_issues]
T7[triage_issue]
T8[get_rate_limit_status]
T13[list_repositories]
end
subgraph AdvancedTools [Advanced Tools — 4]
T9[semantic_search_issues]
T10[undo_last_action]
T11[get_transaction_history]
T12[get_trace_history]
end
T3 & T4 & T5 --> PE[PolicyEngine\npolicy_engine.py]
T3 & T9 --> VE[VectorEngine\nvector_engine.py]
T3 & T4 & T5 --> TJ[TransactionJournal\ntransaction_journal.py]
T10 & T11 --> TJ
T12 --> Tracer
T7 --> Sandbox[Untrusted XML Sandbox] --> Ollama[Local Ollama\nllama3.2:1b]
T6 --> Tokens[SHA256 Preview Token\n5-min TTL]
GHC[GitHubClient\ngithub_client.py] <-->|CircuitBreaker + Backoff| CB[circuit_breaker.py]
CB --> GHAPI[GitHub REST API]
CoreTools --> GHC
🛠️ Tool Reference (13 Registered Tools)
Core Tools (9)
| # | Tool | Type | Confirmation | Description & Guardrails |
|---|---|---|---|---|
| 1 | get_open_issues(repo_name) |
Read | None | Paginated issue listing. Excludes Pull Requests via issue.pull_request is None. |
| 2 | search_issues(keyword, repo_name) |
Read | None | Substring search across issue titles and descriptions. |
| 3 | create_issue(repo_name, title, body, confirmed) |
Write | confirmed: bool |
Creates issue with Policy check + Vector Dedup (≥80% cutoff) + Saga recording + Pydantic validation. |
| 4 | add_label(repo_name, issue_number, label, confirmed) |
Write | confirmed: bool |
Adds a label after ABAC policy evaluation and Saga journal recording. |
| 5 | close_issue(repo_name, issue_number, comment, confirmed) |
Write | confirmed: bool |
Closes issue with resolution comment and records Saga compensation (reopen_issue). |
| 6 | bulk_label_stale_issues(...) |
Bulk Write | 2-Phase Token | Phase 1: Returns preview + SHA256 token. Phase 2: Executes only with matching valid token. |
| 7 | triage_issue(repo_name, issue_number, apply_labels) |
LLM / Read | confirmed: bool |
Classifies priority/category using Ollama inside XML prompt injection sandbox. |
| 8 | get_rate_limit_status() |
Read | None | Retrieves GitHub API quota, remaining calls, and reset timestamp. Schema validated. |
| 9 | list_repositories() |
Read | None | Returns list of all GitHub repositories accessible by the authenticated token. |
Advanced Tools (4)
| # | Tool | Engine | Description & Purpose |
|---|---|---|---|
| 10 | semantic_search_issues(query, repo_name, top_k) |
VectorEngine |
Ranks issues by TF-IDF cosine similarity. Resolves vocabulary mismatches. |
| 11 | undo_last_action(confirmed) |
TransactionJournal |
Executes compensating action for the last committed write mutation. |
| 12 | get_transaction_history(limit) |
TransactionJournal |
Lists recent write transactions with status (committed / reverted). |
| 13 | get_trace_history(limit) |
Tracer |
Exposes execution spans and per-phase timing (policy_check, vector_dedup, github_api). |
🔒 Security & Defense-in-Depth (5 Layers)
[!NOTE] 1. Circuit Breaker (
circuit_breaker.py) Per-instance circuit breaker trips toOPENafter 3 consecutive API failures, fast-failing calls for 60 seconds to prevent API hammering and cascading LLM crashes.
[!IMPORTANT] 2. Two-Phase Cryptographic Preview Tokens Prevents LLM bulk action hallucination by forcing a 2-step token handshake (
SHA256(repo + sorted_ids + label)[:16]) with 5-minute TTL expiration.
[!WARNING] 3. Untrusted Data Sandbox (
triage_issue.py) All third-party GitHub issue text is encapsulated in<untrusted_issue_data>XML tags with explicit instruction boundary prompts to prevent prompt injection hijacking.
[!TIP] 4. Vector Cosine Duplicate Detection (
create_issue.py) Pre-creation check blocks duplicate issues scoring ≥ 80% cosine similarity against existing open issues, preventing spam on retry.
[!CAUTION] 5. ABAC Policy Engine (
policy_engine.py+policy.json) Evaluates declarative security rules (global write freeze, rate-limit buffer thresholds, restricted label lists, bulk action caps) before any API call is made.
📂 Project Structure
github-mcp-toolkit/
├── .github/
│ └── workflows/
│ └── docker-ci.yml # CI/CD pipeline: pytest + 100-eval + Docker build
├── server.py # FastMCP server entrypoint (stdio & sse transports)
├── github_client.py # PyGithub client wrapper (retry, backoff, circuit breaker)
├── circuit_breaker.py # Per-instance CLOSED/OPEN/HALF_OPEN state machine
├── vector_engine.py # Pure-Python TF-IDF cosine similarity engine
├── transaction_journal.py # Saga pattern write mutation journal
├── policy_engine.py # ABAC declarative policy engine
├── tracer.py # OpenTelemetry-inspired span execution tracer
├── schemas.py # Pydantic response schema contracts
├── policy.json # System policy rules (editable without redeploy)
├── Dockerfile # Production container definition (SSE transport ready)
├── docker-compose.yml # Stack orchestration service
├── tools/
│ ├── get_open_issues.py
│ ├── search_issues.py
│ ├── create_issue.py # Policy + Vector + Saga + Tracer + Schema
│ ├── add_label.py # Policy + Saga integrated
│ ├── close_issue.py # Policy + Saga integrated
│ ├── bulk_label_stale_issues.py # 2-Phase preview token flow
│ ├── triage_issue.py # Untrusted data XML sandbox + Ollama
│ ├── get_rate_limit_status.py # Pydantic schema validated
│ ├── list_repositories.py # Accessible repository listing
│ ├── semantic_search_issues.py
│ ├── undo_last_action.py
│ ├── get_transaction_history.py
│ └── get_trace_history.py
├── eval/
│ ├── run_eval.py # 100-query dual evaluation benchmark runner
│ ├── test_queries.json # 80 standard natural-language queries
│ └── adversarial_queries.json # 20 adversarial prompt injection test cases
└── tests/
├── conftest.py # Isolated PyGithub client fixtures
├── test_github_client.py # Client layer tests
├── test_tools.py # Tool guardrail integration tests
└── test_advanced_features.py # 45 unit tests (Vector, Saga, Policy, CircuitBreaker, Tracer, Schemas)
⚡ Quick Start
1. Local Setup (Claude Desktop)
# Clone repository
git clone https://github.com/kartik-012/GitHub-MCP-Toolkit.git
cd GitHub-MCP-Toolkit
# Setup virtual environment
python -m venv venv
venv\Scripts\activate # Windows
# source venv/bin/activate # Linux/macOS
# Install dependencies
pip install -r requirements.txt
# Configure environment
cp .env.example .env
# Edit .env and set GITHUB_TOKEN=ghp_...
Add to %APPDATA%\Claude\claude_desktop_config.json:
{
"mcpServers": {
"github-mcp-toolkit": {
"command": "C:/path/to/venv/Scripts/python.exe",
"args": ["C:/path/to/GitHub-MCP-Toolkit/server.py"]
}
}
}
2. Docker Setup (Containerized SSE Server)
# Build and launch container stack
docker compose up -d
# Verify server logs
docker compose logs -f
🧪 Testing & Evaluation Benchmark
# Run all 53 unit and integration tests
python -m pytest tests/ -v
# Run 100-query dual benchmark harness (80 standard + 20 adversarial)
python eval/run_eval.py
==============================================================
GitHub MCP Toolkit — Tool Selection Evaluation Harness
==============================================================
[STANDARD] Standard Benchmark (80 queries)
Correct Tool Selection : 80/80 (100.0%)
[ADVERSARIAL] Adversarial Robustness Benchmark (20 cases)
Correct Tool Selection : 20/20 (100.0%) [PASS]
📜 License
MIT License — see LICENSE for details.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。