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.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.