To add the GitHub MCP server to Claude Code, point it at GitHub's hosted endpoint and pass a personal access token (PAT). Run this in your terminal, not inside a Claude Code session:
Quick command
export GITHUB_PAT=ghp_your_token_here
claude mcp add-json github '{"type":"http","url":"https://api.githubcopilot.com/mcp/","headers":{"Authorization":"Bearer ${GITHUB_PAT}"}}'
The alias is github. That is the name you will see in claude mcp list and /mcp.
Use single quotes so ${GITHUB_PAT} stays a literal placeholder in the config. Claude Code expands it from your environment each time it starts the server. The token itself never gets written to ~/.claude.json.
GitHub's own install guide builds the JSON with the token already substituted in. That works too, but then the raw token sits in your Claude Code config file.
Why a token and not OAuth?
The hosted server at api.githubcopilot.com/mcp/ supports OAuth only for host apps that have registered a GitHub App or OAuth App with GitHub. For Claude Code, GitHub's install guide documents the PAT header. OAuth login in that guide is only for the local Docker server.
Create a token at github.com/settings/personal-access-tokens/new. A fine-grained token lets you pick which repositories Claude Code can touch. For the default tools, give it access to Contents, Issues, and Pull requests. Use read-only access unless you want Claude to open issues or PRs.
With a classic token, GitHub's README lists repo for repository work and read:org for organization and team data.
Verify it works
claude mcp list
You should see a line like:
github: https://api.githubcopilot.com/mcp/ (HTTP) - ✓ Connected
You can also check the stored config:
claude mcp get github
The Authorization header should still show Bearer ${GITHUB_PAT}, not your real token.
Inside Claude Code, run /mcp to see the server and its tools, then ask something small:
List my open pull requests on GitHub.
Common mistakes
Missing environment variables: GITHUB_PAT
claude mcp list prints this warning when the variable isn't set in the shell that started Claude Code. Exporting it in one terminal tab doesn't help a Claude Code session running in another. Put the export in your ~/.zshrc or ~/.bashrc, or start Claude Code from the same shell.
Using double quotes around the JSON
With double quotes, your shell expands ${GITHUB_PAT} before Claude Code sees it, and the token ends up in the config file. If the variable isn't set at that moment, you store an empty header instead. Use single quotes.
Installing @modelcontextprotocol/server-github
Plenty of older tutorials use npx @modelcontextprotocol/server-github. That npm package is deprecated, and its last release is 2025.4.8. GitHub's own server at github/github-mcp-server replaced it, and the hosted endpoint above runs that code.
Wrong URL
The endpoint is https://api.githubcopilot.com/mcp/. It is not on api.github.com, even though some guides say it is.
Invalid input on Windows
GitHub's install guide notes that claude mcp add-json can fail with Invalid input for HTTP servers on Windows. Use the add form with a header instead:
claude mcp add github --transport http https://api.githubcopilot.com/mcp/ -H "Authorization: Bearer $env:GITHUB_PAT"
This stores the expanded token in the config, so keep that file private.
Make it read-only
Add /readonly to the URL to hide every tool that writes to GitHub:
claude mcp add-json github '{"type":"http","url":"https://api.githubcopilot.com/mcp/readonly","headers":{"Authorization":"Bearer ${GITHUB_PAT}"}}'
A read-only token does the same job on GitHub's side. Doing both means a mistake in one layer doesn't let Claude push or comment.
Pick toolsets
The default toolsets are context, repos, issues, pull_requests, and users. To load a different set, send the X-MCP-Toolsets header:
claude mcp add-json github '{"type":"http","url":"https://api.githubcopilot.com/mcp/","headers":{"Authorization":"Bearer ${GITHUB_PAT}","X-MCP-Toolsets":"repos,issues,pull_requests,actions"}}'
Fewer toolsets means fewer tool definitions in Claude's context. Unknown toolset names are ignored silently, so check the list in /mcp after you change it.
X-MCP-Readonly: true works as a header too, if you'd rather not change the URL.
Use it in every project, or share it with your team
The commands above use local scope, so the server only loads in the directory where you ran them. Add --scope user to load it in every project:
claude mcp add-json --scope user github '{"type":"http","url":"https://api.githubcopilot.com/mcp/","headers":{"Authorization":"Bearer ${GITHUB_PAT}"}}'
--scope project writes the server to .mcp.json in the repo root, which you can commit. Since the file only holds ${GITHUB_PAT}, each teammate sets their own token and nothing secret goes into git. Claude Code asks each person to approve project-scoped servers the first time it loads them.
References
- GitHub MCP server: install in Claude
- GitHub remote MCP server: toolsets, headers, URL paths
- Claude Code MCP docs
Other MCP setups on this blog: Datadog, PagerDuty, and Context7.
Final check
Export GITHUB_PAT, run claude mcp add-json with the ${GITHUB_PAT} placeholder in single quotes, and confirm with claude mcp list. Switch the URL to /mcp/readonly if Claude Code shouldn't write to GitHub.