Skip to content

Commit 3a0b171

Browse files
amcclainclaude
andcommitted
Switch github MCP to gh auth token, removing need for plaintext PAT in env
The github MCP entry in .mcp.json previously read $GITHUB_TOKEN from the shell environment, requiring developers to keep a plaintext PAT in their shell rc files. That token was readable by every child process spawned from that shell (npm postinstall scripts, MCP servers, ad-hoc CLIs), making accidental exfiltration a real concern. The new pattern launches the MCP via a bash wrapper that runs `gh auth token` at startup, pulling the credential from the macOS Keychain (or gh's credential store on other platforms). No plaintext token needs to live in the shell environment. Side benefit: `gh auth login` issues an OAuth token with default scopes `gist, read:org, repo, workflow`, dropping the admin-level scopes that typical PATs carry (admin:org, delete_repo, package admin, etc.). The `repo` scope still covers all everyday dev operations -- opening PRs, commenting, merging, branch/commit work -- so no real functionality is lost. CLAUDE.md gets a new "MCP Servers" section documenting the github MCP setup with the gh-auth-login flow. This repo previously had no MCP-related docs, so this also brings it into line with the conventions in the sibling Hoist repos. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 8e2d7f8 commit 3a0b171

2 files changed

Lines changed: 34 additions & 11 deletions

File tree

.mcp.json

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
{
22
"mcpServers": {
33
"github": {
4-
"command": "docker",
4+
"command": "bash",
55
"args": [
6-
"run",
7-
"-i",
8-
"--rm",
9-
"-e",
10-
"GITHUB_PERSONAL_ACCESS_TOKEN",
11-
"ghcr.io/github/github-mcp-server"
12-
],
13-
"env": {
14-
"GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_TOKEN}"
15-
}
6+
"-c",
7+
"GITHUB_PERSONAL_ACCESS_TOKEN=\"$(gh auth token)\" exec docker run -i --rm -e GITHUB_PERSONAL_ACCESS_TOKEN ghcr.io/github/github-mcp-server"
8+
]
169
},
1710
"jetbrains": {
1811
"url": "http://localhost:${JETBRAINS_MCP_PORT:-64342}/sse",

CLAUDE.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,33 @@ Prettier config (`.prettierrc.json`):
8585
- 4-space indent, 100 char print width
8686
- Single quotes, no bracket spacing, no trailing commas
8787
- Arrow parens: avoid
88+
89+
## MCP Servers
90+
91+
### GitHub MCP Server (opt-in)
92+
93+
A Docker-based server providing GitHub API tools (issues, PRs, code search, etc.) via the
94+
official `github-mcp-server` image. Configured in `.mcp.json` but **not enabled by default**
95+
it requires Docker and an authenticated GitHub CLI, which not every developer keeps running.
96+
97+
**To enable:**
98+
99+
1. Install and start **Docker**.
100+
2. Install the **GitHub CLI** (`brew install gh`) and authenticate with `gh auth login`. The
101+
server invokes `gh auth token` at startup to fetch a token from the macOS Keychain (or
102+
`gh`'s credential store on other platforms), so no plaintext token needs to live in your
103+
shell environment.
104+
3. Add `"github"` to `enabledMcpjsonServers` in `.claude/settings.local.json` (local settings
105+
merge with the shared `settings.json` — enabling locally does not affect other developers):
106+
```json
107+
{
108+
"enabledMcpjsonServers": ["github"]
109+
}
110+
```
111+
112+
If Docker is not running or `gh` is not authenticated when the server is enabled, Claude Code
113+
may show errors on startup — remove `"github"` from your local settings to resolve.
114+
115+
**Fallback when not enabled:** The `gh` CLI provides functionally equivalent access to the same
116+
operations (`gh pr view`, `gh issue list`, `gh api`, `gh pr create`, etc.). Prefer `gh` over
117+
crafting raw `curl` calls to the GitHub API.

0 commit comments

Comments
 (0)