The GitHub MCP Server is GitHub’s official Model Context Protocol server. It lets an AI client such as Claude Code read repositories, issues and pull requests, and create them, through GitHub’s API. You can use the hosted remote server at https://api.githubcopilot.com/mcp/ or run the Docker image ghcr.io/github/github-mcp-server locally, and in both cases the token you give it decides what it can actually do.
This guide covers both install paths for Claude Code, the fine-grained token permissions for reading code and opening a pull request, how to shrink the tool list, and what to check before you approve a PR. If MCP itself is new to you, start with What Is an MCP Server?.
One honest caveat: the tool listing and failure paths below were run without a real GitHub token, using an obviously fake placeholder, with Claude Code 2.1.332 and server v2.3.0. The remote server setup was not run. A live pull request was not created in this walkthrough, so the PR section is a procedure with a sample prompt, not a recording. Details follow the official README and Claude install guide, checked 2026-11-29 against release v2.3.0.
Remote or local GitHub MCP server?
Pick one. Both give Claude Code GitHub tools, but they run in different places, and the README lists some extra tools that only the remote server offers.
| Remote | Local (Docker) | |
|---|---|---|
| Runs | Hosted by GitHub at https://api.githubcopilot.com/mcp/ | On your machine from ghcr.io/github/github-mcp-server |
| Needs Docker | No | Yes, and it must be running |
| Auth in Claude Code | Token sent as a Bearer header | Token as an environment variable |
| Extra | Nothing to update locally | On github.com it can log in with OAuth in the browser on first use |
If you just want it working, use the remote server. Use the local one if you want the process on your own machine or want the browser login. The README says the OAuth token is kept in memory only (see docs/oauth-login.md in the repo), and that setting GITHUB_PERSONAL_ACCESS_TOKEN takes precedence over OAuth. For background on how MCP authorization works in general, see MCP Authorization with OAuth 2.1.
Create a token with the right permissions
For a personal access token (PAT), a fine-grained token limited to the repositories you need is the tighter option. The README’s general advice is to grant minimum scopes (it lists repo, read:packages and read:org for classic tokens), use separate tokens for separate purposes, rotate them, and never commit them.
For fine-grained tokens, the permissions per task are listed in GitHub’s permissions-required reference. Here is what you need for the two jobs in this guide:
| Task | Fine-grained permission |
|---|---|
| Every request | Metadata: read (mandatory) |
| Read code, branches, commits | Contents: read |
| Read pull requests | Pull requests: read |
| Push a branch or files | Contents: write |
| Create a pull request | Pull requests: write |
Check the table against that GitHub page before you rely on it, since GitHub adjusts these lists. Start with the read-only rows, add the write rows only when you want Claude Code to change things, and keep the token out of your shell history by exporting it from a password manager or secrets file.
export GITHUB_PAT="paste-your-token-here"Add the GitHub MCP server to Claude Code
Option 1: remote server
The official guide says the remote setup needs Claude Code 2.1.1 or newer. Run:
claude mcp add-json github '{"type":"http","url":"https://api.githubcopilot.com/mcp","headers":{"Authorization":"Bearer '"$GITHUB_PAT"'"}}'Option 2: local server with Docker
Docker must be running. The image is public, so no registry login is needed:
claude mcp add github -e GITHUB_PERSONAL_ACCESS_TOKEN=$GITHUB_PAT -- docker run -i --rm -e GITHUB_PERSONAL_ACCESS_TOKEN ghcr.io/github/github-mcp-serverCheck that it registered
claude mcp listclaude mcp get githubTo try this without touching your real setup, point Claude Code at a throwaway config directory and use a placeholder token first:
export CLAUDE_CONFIG_DIR="$(mktemp -d)"export GITHUB_PAT="fake-token-for-testing"claude mcp add github -e GITHUB_PERSONAL_ACCESS_TOKEN=$GITHUB_PAT -- docker run -i --rm -e GITHUB_PERSONAL_ACCESS_TOKEN ghcr.io/github/github-mcp-serverclaude mcp listclaude mcp get github
Note two things in that output. The status reads Connected even though the token is fake, so it shows that the server starts and answers, not that your credentials work. The real test is a tool call, which we do below. Also, claude mcp get prints the token value, and the -e NAME=$VALUE form stores it in the Claude Code config file, so treat that file and that output as secrets.
See what the server exposes
Before you give an AI client a tool list, look at it yourself. First confirm the image runs:
docker run --rm ghcr.io/github/github-mcp-server --helpdocker run --rm ghcr.io/github/github-mcp-server --version
The server speaks JSON-RPC over stdio, so a short Python script can start it, send initialize and tools/list, and print the tool names. The image runs the stdio command by default, but any argument you add after the image name replaces that default. So pass stdio explicitly before any server flags, as the script does. This is the same idea as in Debugging with MCP Inspector, just without a UI.
import jsonimport osimport subprocessimport sys
IMAGE = "ghcr.io/github/github-mcp-server"
def start(extra_args): cmd = [ "docker", "run", "-i", "--rm", "-e", "GITHUB_PERSONAL_ACCESS_TOKEN", IMAGE, "stdio", *extra_args, ] return subprocess.Popen( cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, text=True, env=os.environ, )
def send(proc, message): proc.stdin.write(json.dumps(message) + "\n") proc.stdin.flush()
def read_response(proc, request_id): for line in proc.stdout: msg = json.loads(line) if msg.get("id") == request_id: return msg raise RuntimeError("server closed before responding")
def main(): # usage: python list_github_tools.py [call-get-me] [server flags] args = sys.argv[1:] call_get_me = bool(args) and args[0] == "call-get-me" if call_get_me: args = args[1:]
proc = start(args) send(proc, { "jsonrpc": "2.0", "id": 1, "method": "initialize", "params": { "protocolVersion": "2024-11-05", "capabilities": {}, "clientInfo": {"name": "tool-lister", "version": "0.1"}, }, }) read_response(proc, 1) send(proc, {"jsonrpc": "2.0", "method": "notifications/initialized"})
if call_get_me: send(proc, { "jsonrpc": "2.0", "id": 2, "method": "tools/call", "params": {"name": "get_me", "arguments": {}}, }) print(json.dumps(read_response(proc, 2), indent=2)) else: send(proc, {"jsonrpc": "2.0", "id": 2, "method": "tools/list"}) tools = read_response(proc, 2)["result"]["tools"] print(f"{len(tools)} tools") for tool in sorted(t["name"] for t in tools): print(tool)
proc.stdin.close() proc.terminate()
if __name__ == "__main__": main()Run it with the placeholder token. Listing tools does not need a valid token:
export GITHUB_PERSONAL_ACCESS_TOKEN="fake-token-for-testing"python list_github_tools.py
Cut the tool list with toolsets and read-only mode
Every tool you expose costs context and widens what the model can do. The server lets you trim both.
In v2.3.0 the --help output lists the default toolsets as context, copilot, issues, pull_requests, repos and users. Change them with the --toolsets flag or the GITHUB_TOOLSETS environment variable. The README says the environment variable takes precedence when both are set, but on v2.3.0 I saw the opposite: the flag won over the environment variable. Set only one of them to avoid surprises. The special values all and default are also accepted. To pick individual tools instead, use --tools.
python list_github_tools.py --toolsets repos,pull_requests
The list drops from 46 tools to 29, and it still includes merge_pull_request, delete_file and push_files. For a safe first session, add --read-only (setting the environment variable GITHUB_READ_ONLY=1 also worked). It offers only read tools and takes precedence over --tools: asking for --tools create_pull_request,get_me --read-only returned only get_me.
python list_github_tools.py --toolsets repos,pull_requests --read-only
Two cautions from the README. Fine-grained PATs are not hidden by classic PAT scope filtering, so the server may list tools your token cannot actually use; a listed tool is not proof of permission. The README also documents a --lockdown-mode flag, so read it if you work with repositories that accept content from outsiders.
To make Claude Code use these settings, put stdio and then the flags after the image name. If a github server is already registered, remove it first with claude mcp remove github:
claude mcp add github -e GITHUB_PERSONAL_ACCESS_TOKEN=$GITHUB_PAT -- docker run -i --rm -e GITHUB_PERSONAL_ACCESS_TOKEN ghcr.io/github/github-mcp-server stdio --toolsets repos,pull_requests --read-onlyOpen a pull request from Claude Code
For this you need a token with Contents: write and Pull requests: write, no --read-only, and the pull_requests toolset (it is on by default). Again, this part is a procedure; no PR was created for this article.
Give Claude Code a specific, bounded prompt:
In the repository OWNER/REPO, create a branch named docs/fix-readme-typo from main,fix the typo in README.md line 12, and open a pull request against main titled"Fix README typo". Make it a draft. Show me the diff before you push anything.In its default permission mode, Claude Code asks for approval before running an MCP tool you have not already allowed. Check these before you say yes:
- Target repo. Is the
ownerandrepoin the tool call the one you meant? - Branch names. Is the head a new branch, and is the base the branch you intended?
- Diff. Does the content match what you asked for, with no unrelated files?
- Title and body. Do they describe the change accurately?
- Draft flag. For a first run, prefer a draft so nothing is merged or reviewed by accident.
Afterwards, open the PR on GitHub and review it like anyone else’s work. Merging stays your decision.
Common failures
Bad credentials or authentication error. The token is wrong, expired, revoked or lacks access to the repo. With the placeholder token, a call to get_me fails with 401 Bad credentials, which is a quick way to see the error without any real account:
python list_github_tools.py call-get-me
Docker is not running. The local server cannot start. When I pointed Claude Code at an unreachable Docker socket, claude mcp list showed Failed to connect. Start Docker Desktop or the Docker daemon, then retry.
Image pull fails. The image is public, so the README says a pull error can mean an expired token stored for ghcr.io. Log out and pull again:
docker logout ghcr.iodocker pull ghcr.io/github/github-mcp-serverA tool is listed but denied. See the fine-grained PAT caution above. Check the token’s repository access and permissions against the table.
FAQ
What is the GitHub MCP Server?
It is GitHub’s official MCP server, which exposes GitHub operations such as reading repos, managing issues and creating pull requests as tools an MCP client can call. It is available as a hosted remote server or as a Docker image you run yourself.
Should I use the remote or local GitHub MCP server with Claude Code?
Use the remote one if you want the simplest setup, with no Docker. Choose the local Docker server if you want it to run on your own machine, or want the browser OAuth login on github.com when no token is set.
What token permissions does the GitHub MCP Server need to open a pull request?
With a fine-grained token: Metadata: read (mandatory), Contents: write to push a branch or files, and Pull requests: write to create the PR. Confirm against GitHub’s permissions reference before creating the token.
How do I stop Claude Code from changing my repositories?
Start the server with --read-only so only read tools are offered, and restrict toolsets with --toolsets. Pair that with a token that has read-only permissions, since the token is the real boundary.