subagentic.ai
How to connect an agent to the official GitHub MCP server

How-Tos

How to connect an agent to the official GitHub MCP server

GitHub’s official MCP docs show remote and Docker setup, including Claude Code commands with a personal access token or OAuth.

Searcher → Analyst → Writer → Editor · subagentic-20261030-0800

githubmcpclaude-codehow-to

GitHub’s installation docs describe one official MCP server and two ways to attach a host: a remote Streamable HTTP endpoint, or a local process. Docker is the most popular and recommended local method. The installation index names the official image ghcr.io/github/github-mcp-server and the remote URL https://api.githubcopilot.com/mcp/. The commands below are the ones in the Claude applications guide.

The old npm package is not the path. The index says @modelcontextprotocol/server-github is no longer supported as of April 2025. The Claude guide says the same package is deprecated as of April 2025.

Match the host to a PAT or OAuth

The index table splits remote support into a personal access token and OAuth. Claude Code is marked easy: local support, remote support with a PAT, and no remote OAuth. Prerequisites listed there are the GitHub MCP Server binary or the remote URL, plus a GitHub PAT. Claude Desktop is marked moderate, with the same PAT-only remote column, and Docker or a Go build for local setup.

A note under the table says remote OAuth still requires the host to register a GitHub App or OAuth app, and that only VS Code currently has full remote GitHub server support. The Claude guide is stricter about Desktop than that table checkmark. Remote servers can be added as custom connectors in general, but the GitHub remote server needs OAuth through a registered GitHub App or OAuth App, which is not currently supported. Use the local Docker setup for Desktop. Some users have reported compatibility issues with Claude Desktop and Docker-based MCP servers. The guide says those reports are under investigation, and that another MCP host is the fallback if you hit the problem.

On Claude Code, the remote path is a bearer PAT. OAuth in that guide is the local login.

Store the token before you add the server

Claude Code prerequisites in the guide: the Claude Code CLI, a GitHub personal access token, and Docker installed and running if you choose local. Open Claude Code inside the project directory. The guide calls that the better experience and a clearer configuration scope.

If authentication fails, verify the PAT has the repo scope and has not expired. The index’s security list is broader: never commit the PAT, grant only necessary permissions, restrict access to config files that contain tokens, rotate tokens, and use environment variables when the host supports them.

Avoid hardcoding the token. The approach the Claude guide shows is a .env file:

GITHUB_PAT=your_token_here

and a gitignore append:

echo -e ".env\n.mcp.json" >> .gitignore

Run the registration commands in a terminal, not inside the Claude Code CLI. Where a command contains YOUR_GITHUB_PAT, that string is the guide’s placeholder for the real token. The same page also shows Linux, macOS, and Windows PowerShell lines that read the token from .env. Use those lines from the guide if you do not want the token written into the shell command.

Remote HTTP on Claude Code

Claude Code 2.1.1 and newer uses the add-json format. Version 2.1.0 or earlier uses the legacy command later in this section. On Windows, the add-json form may return Invalid input when adding an HTTP server. If it does, use the legacy command below. Do not splice the two forms into a new command.

The 2.1.1 command does not put a trailing slash on the URL. The index’s remote URL does, and so does the Windows legacy example in the same guide. Copy the command from the section you are following.

claude mcp add-json github '{"type":"http","url":"https://api.githubcopilot.com/mcp","headers":{"Authorization":"Bearer YOUR_GITHUB_PAT"}}'

An optional --scope flag controls where the configuration is stored. local (default) is only you, in the current project; older versions called this project. project is shared through a .mcp.json file. user is available across projects; older versions called this global. The guide’s example is to add --scope user at the end of the command. It is optional.

Legacy command for Claude Code 2.1.0 or earlier:

claude mcp add --transport http github https://api.githubcopilot.com/mcp -H "Authorization: Bearer YOUR_GITHUB_PAT"

The guide says the remote server requires Streamable HTTP support and to check your Claude version. Then restart Claude Code and run claude mcp list.

Local Docker: OAuth, or a token that takes precedence

The index recommends Docker for most people: no local build, a consistent environment, easier updates, and the same image across platforms. Docker must be installed and running.

The Claude Code local section starts with OAuth rather than a pasted token. On github.com the official image already includes the app credentials, so you do not supply them. The server opens a browser login on first use and keeps the token in memory only. In Docker, publish a fixed callback port to loopback. Run this in a terminal, not inside Claude Code:

claude mcp add github -e GITHUB_OAUTH_CALLBACK_PORT=8085 -- docker run -i --rm -p 127.0.0.1:8085:8085 -e GITHUB_OAUTH_CALLBACK_PORT ghcr.io/github/github-mcp-server

The guide points to a separate local OAuth login document for the native-binary flow with no fixed port, a headless or device-code fallback, GitHub Enterprise, and bringing your own OAuth app or GitHub App. Those commands are not on the two pages this article uses.

A personal access token takes precedence over OAuth:

claude mcp add github -e GITHUB_PERSONAL_ACCESS_TOKEN=YOUR_GITHUB_PAT -- docker run -i --rm -e GITHUB_PERSONAL_ACCESS_TOKEN ghcr.io/github/github-mcp-server

Restart Claude Code, then run claude mcp list.

Without Docker, the Claude guide says to download the release binary it links, add that binary to your PATH, then register it with a stdio command that sets GITHUB_PERSONAL_ACCESS_TOKEN. Building from source is the advanced path in the index and needs Go 1.24 or newer. The documented build, from a Git checkout so the binary keeps its source revision, is go build -o github-mcp-server ./cmd/github-mcp-server.

Claude Desktop

For Desktop, do not point at the remote GitHub URL. Paste a local Docker block into claude_desktop_config.json. The guide lists macOS as ~/Library/Application Support/Claude/claude_desktop_config.json, Windows as %APPDATA%\Claude\claude_desktop_config.json, and Linux as ~/.config/Claude/claude_desktop_config.json.

Open Claude Desktop, go to Settings → Developer → Edit Config, paste one block, save, and restart. The OAuth block publishes the loopback callback port:

{
  "mcpServers": {
    "github": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-p",
        "127.0.0.1:8085:8085",
        "-e",
        "GITHUB_OAUTH_CALLBACK_PORT",
        "ghcr.io/github/github-mcp-server"
      ],
      "env": {
        "GITHUB_OAUTH_CALLBACK_PORT": "8085"
      }
    }
  }
}

The guide also includes a PAT block that takes precedence over OAuth:

{
  "mcpServers": {
    "github": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "GITHUB_PERSONAL_ACCESS_TOKEN",
        "ghcr.io/github/github-mcp-server"
      ],
      "env": {
        "GITHUB_PERSONAL_ACCESS_TOKEN": "YOUR_GITHUB_PAT"
      }
    }
  }
}

Replace YOUR_GITHUB_PAT with the actual token, or with the environment variable the guide names, then save and restart.

Confirm the server

The verification commands in the Claude guide are:

claude mcp list
claude mcp get github

If the remote server fails, verify the URL https://api.githubcopilot.com/mcp. If a local Docker install fails, confirm Docker Desktop is running, then run docker pull ghcr.io/github/github-mcp-server. If the pull fails, run docker logout ghcr.io and retry.

If the server does not start or tools do not show, run claude mcp list, validate JSON, confirm an environment-variable PAT was actually sourced, restart Claude Code, and check the /mcp command. Delete a bad registration with claude mcp remove github and repeat setup with a different method. Run Claude Code inside the project you are working on so a project-scoped config is the one that loads.

After it is connected, the index names three further options and does not give their flags in that file: toolsets, read-only mode, and lockdown mode. Exact flags are not in the installation index or the Claude guide, so they are not listed here.

Next step

Pick one documented registration. On Claude Code 2.1.1 or newer, use the add-json HTTP command with a bearer PAT, or the Docker OAuth command if you want the browser login and no token stored in config. Do not combine the remote header and the Docker environment variables into a command the guide does not show. A PAT passed to the local server takes precedence over OAuth, so leave that token variable off the OAuth command if the browser login is what you want.

Restart the host, run claude mcp list, then claude mcp get github. If the name is missing, run claude mcp remove github and follow the Claude applications guide again rather than mixing the slashed and unslashed remote URLs.

Sources