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:
- Minimal 9-tool surface (no destructive operations):
- Read tools (6):
github_get_issue,github_list_issues,github_get_pr,github_list_prs,github_get_pr_diff(byte-capped atGITHUB_MAX_DIFF_BYTES, default 64 KiB),github_get_pr_checks. - Write tools (3):
github_comment_issue,github_create_pr_review,github_create_pr(defaults todraft=True). - Intentionally absent:
merge_pr,delete_branch,push_files,create_release, andupdate_branch_protectiondo not exist on the server. - Fail-closed repository allowlists (
policy.py): ALLOWED_READ_REPOSandALLOWED_WRITE_REPOSrequire exactowner/reposlugs; wildcards (*) are rejected at startup.- If
ALLOWED_WRITE_REPOSis empty, all write tools fail closed. DENIED_WRITE_REPOS(defaults to["google/esmeralda"]) unconditionally blocks upstream writes even if misconfigured inALLOWED_WRITE_REPOS.- No agent self-approval (
ALLOW_PR_APPROVE=falsedefault): github_create_pr_reviewpermits onlyCOMMENTandREQUEST_CHANGESunlessALLOW_PR_APPROVE=trueis explicitly set.- Server-side GitHub App installation tokens (
github_client.py): - Signs 9-minute RS256 App JWTs using a Secret Manager private key (
GITHUB_APP_PRIVATE_KEYviasecret_key_ref), exchanges them atPOST /app/installations/{id}/access_tokens(optionally scoped toGITHUB_APP_SCOPED_REPOSITORIES), caches tokens in memory, proactively refreshes before expiry, and retries once on HTTP401. - Active secrets, JWTs, PEM blocks, and
Authorizationheaders are scrubbed from all error responses,/health, and structured audit logs. - Caller attribution & run correlation (
CallerGuard+ audit logs): - Cloud Run IAM + vendored
CallerGuardverify each caller's SPIFFE / GCP Service Account identity. - Incoming
X-Esmeralda-*andtraceparentheaders are written to structuredesmeralda.github_mcp.auditlogs for BigQuery / Cloud Logging correlation and are never forwarded toapi.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.
- Create the Secret Manager secret in the
mcpsproject (esm-dev-mcps-<sfx>): - Set non-secret App IDs and your fork write repo in your user-local env file (
~/.config/esmeralda/env, never committed):(KeepingESMERALDA_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>ESMERALDA_GITHUB_MCP_WRITE_REPOSin~/.config/esmeralda/envavoids hardcoding personal fork names inenv.yaml; optionalESMERALDA_GITHUB_MCP_EXTRA_READ_REPOSworks the same way.) - Build the image in Layer 0 Cloud Build (exports hash-pinned dependencies from
uv.lock): - Enable in
infrastructure/live/dev/env.yamlunderintegrations.scion.github_mcp: - Set
enabled = true - Set
allowed_read_repos = ["google/esmeralda", "<your-fork-owner>/<your-fork-repo>"] - Set
allowed_write_repos = ["<your-fork-owner>/<your-fork-repo>"] - Keep
denied_write_repos = ["google/esmeralda"]andallow_pr_approve = false - Plan and apply the unit:
- Wire into Envoy & catalog (when exposing at
https://github-mcp.esmeralda.internal/mcp): register the service incatalog/teams/platform/mcp/github-mcp.yaml, runesmeralda catalog resolve --env dev --write, add the route ingateways/envoy+entrypoint, and verify withesmeralda verify --env dev.