Agentic AI with Java: Live Cohort
Claude CodeGitHub MCP Server Integration

Configuring the GitHub MCP Server

Create a least-privilege fine-grained GitHub token, add the GitHub MCP server to Claude Code safely, choose the right scope, and verify the connection.

Let us connect Claude Code to GitHub through GitHub's official MCP server. It needs two things: a token that proves who you are, and the server configuration in Claude Code.

Check what is already connected

/mcp

This lists your MCP servers and their status. In the video, two connectors (Gmail and Google Calendar) were already listed but needed authentication. If you do not use them, disable or remove them.

Step 1: Create a fine-grained personal access token

GitHub offers two kinds of personal access tokens (PAT):

TypeAccessUse it?
Classic tokensBroad scopes across all your repositoriesAvoid for this
Fine-grained tokensSpecific repositories, specific permissions, expiry dateYes

If a token ever leaks, a fine-grained token limits the damage to exactly what you allowed.

Open token settings

GitHub → your avatar → Settings → Developer settings → Personal access tokens → Fine-grained tokens → Generate new token. Or go directly to github.com/settings/personal-access-tokens.

Name, description and expiry

For example: name claude-code-demo, description "Experiment with Claude Code MCP", expiry 30 days. Short expiry is safer. You can always create a new token.

Repository access

Choose Only select repositories and pick content-tracker. Do not choose "All repositories".

Permissions

Grant only what this workflow needs:

PermissionAccessWhy
ContentsRead and writeRead files and branches
IssuesRead and writeList and create issues
Pull requestsRead and writeOpen pull requests
MetadataRead-onlyAdded automatically, required by GitHub

Generate and copy

Click Generate token and copy it. GitHub shows it only once.

Treat the token like a password

Do not share it, do not commit it, do not paste it into a Claude prompt, and do not show it on screen while recording. If it is exposed, revoke it immediately in the same settings page. In the video the token was briefly visible and was deleted after recording.

Step 2: Add the GitHub MCP server

The command, from the official Claude Code docs:

claude mcp add --transport http github https://api.githubcopilot.com/mcp/ \
  --header "Authorization: Bearer YOUR_GITHUB_PAT"
PartMeaning
claude mcp addRegister a new MCP server
--transport httpIt is a remote server reached over HTTP
githubThe name you give the server inside Claude Code
https://api.githubcopilot.com/mcp/GitHub's hosted MCP server endpoint
--header "Authorization: Bearer ..."Sends your token with every request

Run it in a separate terminal

Run this command in a normal terminal, not as a prompt inside Claude Code. If you type it into the Claude Code prompt, the token becomes part of the conversation. That is exactly what we want to avoid.

On Windows PowerShell, put it on one line (or use a backtick for line continuation instead of \).

Where is it saved? Scopes

ScopeFlagStored inShared?
Local (default)none, or --scope local~/.claude.json, under this projectOnly you, only this project
Project--scope project.mcp.json in the project rootYes, through git
User--scope user~/.claude.jsonOnly you, all projects

We used the default local scope, which is right for a personal token. If you want to share the server with your team through .mcp.json, never put the token in the file itself. Use environment variable expansion instead:

.mcp.json
{
  "mcpServers": {
    "github": {
      "type": "http",
      "url": "https://api.githubcopilot.com/mcp/",
      "headers": {
        "Authorization": "Bearer ${GITHUB_PAT}"
      }
    }
  }
}

Each teammate sets GITHUB_PAT in their own environment.

Step 3: Verify the connection

A running session does not pick up servers added from another terminal. Start a new Claude Code session and run:

/mcp

You should see github with the status connected. You can also check from any terminal:

claude mcp list
claude mcp get github

If the status says it failed to connect, the most common causes are a mistyped token, an expired token, or missing permissions.

CommandPurpose
claude mcp listList all servers and their health
claude mcp get githubDetails and status of one server
claude mcp remove githubRemove the server
/mcp (inside Claude Code)Manage, enable, disable, reconnect or authenticate servers

Official references


Written By: Shramik Masti

How is this guide?

Last updated on