Skip to content

6.3 Enterprise Governed GitHub MCP Server

Autonomous coding agents need to read issues, inspect pull requests and CI checks, post review comments, and open draft pull requests on a fork. Handing a raw GITHUB_TOKEN or gh CLI directly to an agent sandbox breaks least privilege: any prompt injection or tool misuse can invoke every API endpoint the token allows (merging PRs, deleting branches, mutating branch protection, or writing to upstream repositories).

Esmeralda's Governed GitHub MCP Server (apps/mcps/github-mcp/) removes raw GitHub API tokens from agent sandboxes and enforces defense-in-depth policy server-side behind Esmeralda's Envoy MCP Gateway.


1. Architecture & Control-Plane / Git-Transport Separation

flowchart LR
    subgraph Sandbox["Agent Sandbox (Scion VM or GKE Pod)"]
        Agent["Factory Agent<br/>(lead / builder / reviewer / security-reviewer)"]
        MCPProxy["mcp_oidc_proxy.py<br/>(127.0.0.1:8788)"]
        Git["git clone / git push<br/>(separate fork-only Git transport)"]
    end

    subgraph Esmeralda["Esmeralda Governance Plane"]
        EP["Internal HTTPS Entry Point<br/>(github-mcp.esmeralda.internal)"]
        Envoy["Envoy MCP Gateway<br/>(token = none • usage.lua • Model Armor)"]
        GHMCP["Cloud Run: github-mcp<br/>(IAM Invoker + CallerGuard +<br/>Repo/Tool Policy + GitHub App Minter)"]
        SM[("Secret Manager<br/>GitHub App Private Key")]
    end

    subgraph GitHub["GitHub.com"]
        API["GitHub REST API<br/>(api.github.com)"]
        Fork["Fork Git Remote<br/>(branch push only)"]
    end

    Agent -->|"Streamable HTTP MCP<br/>(no GitHub token)"| MCPProxy
    MCPProxy -->|"OIDC ID token<br/>(SPIFFE / GSA) + X-Esmeralda-*"| EP
    EP --> Envoy
    Envoy -->|"Original caller token"| GHMCP
    SM -.->|"secret_key_ref"| GHMCP
    GHMCP -->|"Short-lived App<br/>installation token"| API
    Agent -.->|"Git smart HTTP<br/>(sciontool credential-helper)"| Git
    Git -.-> Fork

Why Git Transport Stays Separate

github-mcp governs GitHub REST API control-plane actions (issues, PRs, diffs, checks, comments, reviews). Large binary/packfile git clone and git push operations remain on Git transport (for example, Scion's sciontool credential-helper scoped strictly to the fork repository), avoiding base64 file uploads through LLM tool contexts and keeping push_files / delete_branch completely out of the MCP tool surface.


2. Hard Server-Side Least Privilege

Prompt instructions alone are not a security boundary. github-mcp enforces five independent server-side controls:

  1. Minimal 9-tool surface (no destructive operations):
  2. Read tools (6): github_get_issue, github_list_issues, github_get_pr, github_list_prs, github_get_pr_diff (byte-capped at GITHUB_MAX_DIFF_BYTES, default 64 KiB), github_get_pr_checks.
  3. Write tools (3): github_comment_issue, github_create_pr_review, github_create_pr (defaults to draft=True).
  4. Intentionally absent: merge_pr, delete_branch, push_files, create_release, and update_branch_protection do not exist on the server.
  5. Fail-closed repository allowlists (policy.py):
  6. ALLOWED_READ_REPOS and ALLOWED_WRITE_REPOS require exact owner/repo slugs; wildcards (*) are rejected at startup.
  7. If ALLOWED_WRITE_REPOS is empty, all write tools fail closed.
  8. DENIED_WRITE_REPOS (defaults to ["google/esmeralda"]) unconditionally blocks upstream writes even if misconfigured in ALLOWED_WRITE_REPOS.
  9. No agent self-approval (ALLOW_PR_APPROVE=false default):
  10. github_create_pr_review permits only COMMENT and REQUEST_CHANGES unless ALLOW_PR_APPROVE=true is explicitly set.
  11. Server-side GitHub App installation tokens (github_client.py):
  12. Signs 9-minute RS256 App JWTs using a Secret Manager private key (GITHUB_APP_PRIVATE_KEY via secret_key_ref), exchanges them at POST /app/installations/{id}/access_tokens (optionally scoped to GITHUB_APP_SCOPED_REPOSITORIES), caches tokens in memory, proactively refreshes before expiry, and retries once on HTTP 401.
  13. Active secrets, JWTs, PEM blocks, and Authorization headers are scrubbed from all error responses, /health, and structured audit logs.
  14. Caller attribution & run correlation (CallerGuard + audit logs):
  15. Cloud Run IAM + vendored CallerGuard verify each caller's SPIFFE / GCP Service Account identity.
  16. Incoming X-Esmeralda-* and traceparent headers are written to structured esmeralda.github_mcp.audit logs for BigQuery / Cloud Logging correlation and are never forwarded to api.github.com.

3. Binding Per-Agent Factory Policies

When factory agents share one github-mcp instance, set CALLER_TOOL_POLICY (JSON, passed through integrations.scion.github_mcp.caller_tool_policy_json in env.yaml) to narrow each verified caller's tools and target repositories. Per-caller rules can only narrow the server-wide allowlists—never widen them.

Factory Agent (CallerGuard caller) Recommended Allowed Tools Read Repos Write Repos
esmeralda-lead Read tools + github_comment_issue Upstream + fork Fork only
esmeralda-architect Read tools only Upstream + fork (none)
esmeralda-builder / esmeralda-mcp-builder Read tools + github_comment_issue + github_create_pr Upstream + fork Fork only
esmeralda-reviewer github_get_issue, github_get_pr, github_get_pr_diff, github_get_pr_checks, github_create_pr_review Upstream + fork Fork only (COMMENT / REQUEST_CHANGES)
esmeralda-security-reviewer github_get_pr, github_get_pr_diff, github_get_pr_checks, github_create_pr_review Upstream + fork Fork only (COMMENT / REQUEST_CHANGES)

Example CALLER_TOOL_POLICY value:

{
  "esmeralda-lead": {
    "allowed_tools": [
      "github_get_issue",
      "github_list_issues",
      "github_get_pr",
      "github_list_prs",
      "github_get_pr_checks",
      "github_comment_issue"
    ],
    "allowed_write_repos": ["your-org/esmeralda-fork"]
  },
  "esmeralda-builder": {
    "allowed_tools": [
      "github_get_issue",
      "github_get_pr",
      "github_get_pr_checks",
      "github_comment_issue",
      "github_create_pr"
    ],
    "allowed_write_repos": ["your-org/esmeralda-fork"]
  },
  "esmeralda-reviewer": {
    "allowed_tools": [
      "github_get_issue",
      "github_get_pr",
      "github_get_pr_diff",
      "github_get_pr_checks",
      "github_create_pr_review"
    ],
    "allowed_write_repos": ["your-org/esmeralda-fork"]
  },
  "esmeralda-security-reviewer": {
    "allowed_tools": [
      "github_get_pr",
      "github_get_pr_diff",
      "github_get_pr_checks",
      "github_create_pr_review"
    ],
    "allowed_write_repos": ["your-org/esmeralda-fork"]
  }
}

4. Enabling & Live-Testing in dev

The Layer 5 Terragrunt unit infrastructure/live/{dev,prd}/layer-5-workloads/mcps/github-mcp/terragrunt.hcl is disabled by default (integrations.scion.github_mcp.enabled = false in env.yaml) so existing deployments have zero diff until opted in.

  1. Create the Secret Manager secret in the mcps project (esm-dev-mcps-<sfx>):
    gcloud secrets create github-mcp-app-private-key --project="<mcps-project-id>" --replication-policy="automatic"
    gcloud secrets versions add github-mcp-app-private-key --project="<mcps-project-id>" --data-file="/path/to/app.private-key.pem"
    
  2. Set non-secret App IDs and your fork write repo in your user-local env file (~/.config/esmeralda/env, never committed):
    ESMERALDA_GITHUB_MCP_APP_ID=<your-app-id>
    ESMERALDA_GITHUB_MCP_INSTALLATION_ID=<your-installation-id>
    ESMERALDA_GITHUB_MCP_WRITE_REPOS=<your-fork-owner>/<your-fork-repo>
    
    (Keeping ESMERALDA_GITHUB_MCP_WRITE_REPOS in ~/.config/esmeralda/env avoids hardcoding personal fork names in env.yaml; optional ESMERALDA_GITHUB_MCP_EXTRA_READ_REPOS works the same way.)
  3. Build the image in Layer 0 Cloud Build (exports hash-pinned dependencies from uv.lock):
    uv run --frozen esmeralda build github-mcp
    
  4. Enable in infrastructure/live/dev/env.yaml under integrations.scion.github_mcp:
  5. Set enabled = true
  6. Set allowed_read_repos = ["google/esmeralda", "<your-fork-owner>/<your-fork-repo>"]
  7. Set allowed_write_repos = ["<your-fork-owner>/<your-fork-repo>"]
  8. Keep denied_write_repos = ["google/esmeralda"] and allow_pr_approve = false
  9. Plan and apply the unit:
    uv run --frozen esmeralda plan layer-5-workloads/mcps/github-mcp --env dev
    uv run --frozen esmeralda apply layer-5-workloads/mcps/github-mcp --env dev
    
  10. Wire into Envoy & catalog (when exposing at https://github-mcp.esmeralda.internal/mcp): register the service in catalog/teams/platform/mcp/github-mcp.yaml, run esmeralda catalog resolve --env dev --write, add the route in gateways/envoy + entrypoint, and verify with esmeralda verify --env dev.

5. Offline Validation

uv run --frozen --package orders --extra dev pytest apps/mcps/github-mcp/tests/test_github_mcp.py
uv run --frozen --package esmeralda --extra dev pytest tests/security/test_github_mcp.py