Skip to main content

MCP server giving AI agents controlled GitHub access with policy guard and audit trail

Project description

GitHub MCP Agent Server

CI Python License

MCP server giving AI agents controlled GitHub access with policy guard and audit trail.


Architecture

   ┌───────────────┐        MCP stdio         ┌───────────────────┐
   │   AI Agent    │ ◄──────────────────────► │ GitHub MCP Server │
   │ (Claude, Codex│      JSON-RPC 2.0        │                   │
   │   or any MCP  │                         ┌─┴───────────────┐   │
   │    client)    │                         │ Policy Guard    │   │
   └───────────────┘                         ├─────────────────┤   │
                                             │ Audit Log       │   │
                                             └─────────────────┘   │
           ┌──────────────────────────────────────────────┐      │
           │                 github_client.py               │      │
           │                    (httpx)                     │      │
           │                   GitHub API                   │      │
           └──────────────────────────────────────────────┘      │
           ┌──────────────────────────────────────────────┐      │
           │          Review Engine (ruff + regex)          │      │
           └──────────────────────────────────────────────┘      │
                                                                └───┘

Features & Tools

Tool Description Example Input Example Output
search_code Search GitHub repo code by query search_code("def main", "owner/repo") List of matching files with paths & URLs
list_issues List open or closed issues list_issues("owner/repo", state="open") Formatted list of issues
create_issue Create a new issue (policy-guarded) create_issue("owner/repo", "Bug: timeout", "Steps to reproduce...") Confirmation with issue URL
get_pr_diff Fetch raw diff of a pull request get_pr_diff("owner/repo", pr_number=7) Unified diff as text
create_pr Create a pull request between branches create_pr("owner/repo", "Add feature", "Details...", head="feat", base="main") Confirmation with PR URL
review_pr_diff Run local automated code review rules review_pr_diff("owner/repo", pr_number=7) List of warnings and errors found
comment_pr_review Post review findings as PR comments comment_pr_review("owner/repo", pr_number=7) Number of comments posted

Security Model

  • Repository Allowlist: Only repositories explicitly allowed by policy can be accessed.
  • Branch Protection: PRs to protected branches are subject to branch protection rules before merging.
  • Dry-Run Mode: Execute operations without side effects for safe testing and auditing.
  • Audit Logging: All actions logged in JSONL format with precise timestamps to maintain traceability.
  • Policy Configuration: Start from policy.example.json to configure repository allowlists and protected branches.

FAQ

Why not call the GitHub API directly?
Direct API calls lack centralized policy enforcement, audit logging, and uniform tooling support for AI agents. This MCP server adds a controlled, auditable layer for safer automation.

What MCP clients work with this?
Agents like Claude Code, OpenAI Codex, and any client supporting the MCP JSON-RPC 2.0 transport can connect to this server.

How is this different from the official GitHub MCP server?
This project's key differentiator is policy enforcement. Repository allowlists prevent agents from touching unauthorized repos, branch protection blocks accidental PRs to sensitive branches, dry-run mode supports safe validation, and write actions are audit-logged with timestamps.


Quick Start

Prerequisites

  • Python 3.10+
  • GitHub personal access token with repo scope

Install

pip install fastmcp httpx python-dotenv

Configure and Run

git clone https://github.com/FMorgan-111/github-mcp-server.git
cd github-mcp-server
cp .env.example .env && nano .env
python3 -m src.main

Connect with Claude Code

claude mcp add github-agent -- python3 /path/to/github-mcp-server/src/main.py

Development

pip install -e . --break-system-packages
python3 -m pytest tests/ -v
python3 -m src.main

23 tests, all passing.


Deployment with Docker

docker build -t github-mcp-server .
docker run -e GITHUB_TOKEN=ghp_your_token_here -i github-mcp-server

The -e GITHUB_TOKEN=... flag passes the token into the container because the local .env file is not copied into the image.


License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_github_agent-0.1.0.tar.gz (22.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_github_agent-0.1.0-py3-none-any.whl (28.2 kB view details)

Uploaded Python 3

File details

Details for the file mcp_github_agent-0.1.0.tar.gz.

File metadata

  • Download URL: mcp_github_agent-0.1.0.tar.gz
  • Upload date:
  • Size: 22.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for mcp_github_agent-0.1.0.tar.gz
Algorithm Hash digest
SHA256 36fad939ae0ab848b3243e80cdb3b8abdfbfa133ecc0a81ea31162a862ed1bad
MD5 5b0edac1ccd8a8d35fd7b8baba06fb89
BLAKE2b-256 7daf443142fb7049f1f82138c4f1ae6664bf34e5b893137ef08fdf1f828e2d21

See more details on using hashes here.

File details

Details for the file mcp_github_agent-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mcp_github_agent-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b59136326e9311e5ee34ae4131d9d7cfcdfbcb8bec22824a0f6d7fb17f4853e2
MD5 dbb388e49d68c2c67283b4381e7fc3b6
BLAKE2b-256 544f804421ac292b5c64ab47ed10a85013155eb2bf1d3afbd0a2691cb79abc69

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page