← THE LIBRARY

Engineering / MCP server / FIELD GUIDE

Add the GitHub MCP server to Claude Code

Connect GitHub's official MCP server to Claude Code in read-only mode, keep your token out of the config file, and decide which GitHub writes need your yes.

Checked 22 Oct 2026

Pinned source guide with authored setup files. Original project by GitHub; guide and labeled adaptations by Agent Setup Kits.

Use case
GitHub from Claude Code
Architecture
Single agent, one MCP server
Trigger
Manual, in a session
Runs
GitHub-hosted or local binary
License
MIT
Human approval
Read-only; writes ask first

First step

bash
claude mcp list

After the server is added, this should list a connected github entry, as first-checks.md says.

Copy this first step, then read the setup and the human approval notes before you go further.

01 / PURPOSE

The autonomous job

Answer questions about your GitHub repositories, issues and pull requests from inside Claude Code by calling read-only GitHub tools. Writes stay off until you turn them on, and then each one waits for your approval.

02 / SYSTEM

Architecture and handoffs

Single agent with one external tool server. Claude Code connects to GitHub's hosted MCP endpoint (https://api.githubcopilot.com/mcp/) over streamable HTTP, or to the github-mcp-server binary over stdio. Request headers X-MCP-Readonly and X-MCP-Toolsets limit the server to read tools in four toolsets. A project .claude/settings.json pre-approves read tools, asks before writes and denies merge, delete, push, fork and repository creation.

System for Add the GitHub MCP server to Claude Code Token scope + read-only question tool call allowed reads API with token denied answer or write prompt HUMAN Developer SERVICE Permission rules SERVICE GitHub MCP server SERVICE GitHub API AGENT Claude Code SERVICE Merge, delete, push ASK ASK
Built from this kit's roles, tools and boundaryHumanAgentServiceBoundary
01 / HUMAN

Developer

Creates the GitHub token, adds the server, answers write prompts and checks results on github.com

HandoffDecides whether to widen access beyond read-only

02 / AGENT

Claude Code agent

Chooses GitHub tools to call and reports what it found

HandoffReturns answers, or a pending write for the developer to approve

03 / SERVICE

GitHub MCP server

Turns tool calls into GitHub API requests made with the developer's token

HandoffReturns tool results to Claude Code

Model
Whatever model your Claude Code session uses. The kit does not choose or pin one.
Memory
None added. Claude Code keeps its own session history; the GitHub MCP server holds no state between calls beyond the request headers.

03 / CONNECTIONS

Tools and triggers

Tool access described by this edition
ToolPurposeAccess
Read tools (context, repos, issues, pull_requests toolsets)Read your profile, files, commits, branches, issues and pull requests, and search code and issuesPre-approved in .claude/settings.json; limited to what the token can read
Write tools (comments, issues, branches, files, pull requests)Change GitHub on your behalfHidden while X-MCP-Readonly is true; if you turn writes on, each call asks first
merge_pull_request, delete_file, push_files, create_repository, fork_repositoryHigh-impact writesDenied in .claude/settings.json, so Claude never sees them

What starts the work

  • Manual A developer asks Claude Code a GitHub question in an interactive session in the project folder.
Permissions in this edition
ControlDecision
Read anything the token can read in the four toolsetsYes
Search code, commits, issues, pull requests and repositoriesYes
With read-only off: comment, open and edit issues, create branches, edit files and open pull requests, each after a promptYes
Enforced by the server: with X-MCP-Readonly true, write tools are not offered at all.Ask
Enforced by Claude Code: write tools in the ask list prompt before every call; merge, delete, push, fork and create-repository are denied.Ask
Not a per-repository gate: any repository the token can reach is in scope. Limit the token, not the prompt.Ask
Claude Code's own prompts apply only to tools not already allowed; read tools on the allow list run without asking.Ask
GitHub token permissions are the outer limit. Inside that, X-MCP-Readonly hides write tools and X-MCP-Toolsets limits the server to context, repos, issues and pull_requests. Claude Code permission rules add allow, ask and deny on top.Yes

04 / BOUNDARIES

Capabilities and safety

Credentials
A GitHub personal access token in the GITHUB_MCP_PAT environment variable. The config stores the ${GITHUB_MCP_PAT} reference, not the value. Keep the name GITHUB_MCP_PAT: Claude Code reads some credential variable names as empty in remote headers. Use a fine-grained token limited to the repositories you need, with read-only repository permissions, never commit it, and revoke it when you stop using the kit.
Shutdown
claude mcp remove github removes the server. Revoke the token on github.com to cut access everywhere at once.

Capabilities

  • Read anything the token can read in the four toolsets
  • Search code, commits, issues, pull requests and repositories
  • With read-only off: comment, open and edit issues, create branches, edit files and open pull requests, each after a prompt

05 / SETUP

The files behind the workflow.

Original-project files retain their attribution and license; our installation notes, dependency profiles and custom wrappers are identified separately.

  1. Create a limited GitHub token

  2. Export it as GITHUB_MCP_PAT

  3. Add the server read-only

  4. Add the permission rules

  5. Run the first checks

add-github-mcp.shView file +

Adds the hosted GitHub MCP server in read-only mode with four toolsets, keeping the token as a ${GITHUB_MCP_PAT} reference

Download add-github-mcp.sh ↓

#!/usr/bin/env bash
# Add GitHub's official MCP server to Claude Code as a read-only remote server.
# Run in your terminal (not inside a Claude Code session), from your project root.
#
# Before running: create a GitHub token and export it under this exact name,
#   export GITHUB_MCP_PAT=...
# The single quotes below matter. They keep ${GITHUB_MCP_PAT} as text, so
# Claude Code stores the reference and reads the variable when it connects.
# The token itself is never written into the config file.
set -euo pipefail

claude mcp add-json github '{
  "type": "http",
  "url": "https://api.githubcopilot.com/mcp/",
  "headers": {
    "Authorization": "Bearer ${GITHUB_MCP_PAT}",
    "X-MCP-Toolsets": "context,repos,issues,pull_requests",
    "X-MCP-Readonly": "true"
  }
}'

claude mcp get github

Agent Setup Kits authored; adapted from docs/installation-guides/install-claude.md and docs/remote-server.md at the pinned commit

add-github-mcp-local.shView file +

Alternative: runs the pinned v2.0.3 binary over stdio with --read-only and the same toolsets

Download add-github-mcp-local.sh ↓

#!/usr/bin/env bash
# Alternative: run the server yourself as a local binary (stdio), read-only.
# Download github-mcp-server v2.0.3 for your platform from
#   https://github.com/github/github-mcp-server/releases/tag/v2.0.3
# put it on your PATH, check it with `github-mcp-server --version`, then run
# this script from your project root with GITHUB_MCP_PAT exported.
set -euo pipefail

claude mcp add-json github '{
  "command": "github-mcp-server",
  "args": ["stdio", "--read-only", "--toolsets", "context,repos,issues,pull_requests"],
  "env": { "GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_MCP_PAT}" }
}'

claude mcp get github

Agent Setup Kits authored; adapted from the local binary section of install-claude.md

claude-settings.jsonView file +

Save as .claude/settings.json in your project. Permission rules: allow read tools, ask before writes, deny high-impact writes

Download claude-settings.json ↓

{
  "permissions": {
    "allow": [
      "mcp__github__get_*",
      "mcp__github__list_*",
      "mcp__github__search_*",
      "mcp__github__issue_read",
      "mcp__github__pull_request_read",
      "mcp__github__ui_get"
    ],
    "ask": [
      "mcp__github__add_issue_comment",
      "mcp__github__issue_write",
      "mcp__github__create_branch",
      "mcp__github__create_or_update_file",
      "mcp__github__create_pull_request",
      "mcp__github__update_pull_request",
      "mcp__github__pull_request_review_write",
      "mcp__github__add_comment_to_pending_review",
      "mcp__github__add_reply_to_pull_request_comment",
      "mcp__github__update_issue_comment",
      "mcp__github__sub_issue_write",
      "mcp__github__update_pull_request_branch"
    ],
    "deny": [
      "mcp__github__merge_pull_request",
      "mcp__github__delete_file",
      "mcp__github__push_files",
      "mcp__github__create_repository",
      "mcp__github__fork_repository"
    ]
  }
}

Agent Setup Kits authored; tool names checked against tools/list from the v2.0.3 binary

first-checks.mdView file +

Six checks from connection to a negative merge test

Download first-checks.md ↓

# First checks for the GitHub MCP server in Claude Code

Run these in order. Stop at the first one that fails.

1. In your terminal: `claude mcp list`
   The `github` entry should be listed and connected. A warning that names
   GITHUB_MCP_PAT means the variable is not set in the shell that started
   Claude Code.

2. In your terminal: `claude mcp get github`
   The Authorization header should still read `Bearer ${GITHUB_MCP_PAT}`.
   If you see your real token here, it was written into the config. Remove
   the server (`claude mcp remove github`), revoke the token and start again.

3. In Claude Code: `/mcp`
   Open the github server and look at its tools. With X-MCP-Readonly set,
   you should see read tools such as get_me, list_issues and
   pull_request_read, and no write tools such as create_pull_request.

4. Prompt: `Use the GitHub MCP server to tell me which GitHub account you are signed in as.`
   Claude should call mcp__github__get_me and answer with your login.
   A 401 error means the token is wrong, expired or not reaching the server.

5. Prompt: `List the three most recent open issues in OWNER/REPO.`
   Use a repository the token can read. Check the answer against the
   issue list on github.com.

6. Negative test: `Merge pull request 1 in OWNER/REPO.`
   With the kit's settings and read-only mode, Claude has no merge tool to
   call. Confirm that nothing happened on github.com.

Agent Setup Kits authored

SOURCE.mdView file +

Original-project attribution, source hashes and adaptation notes

Download SOURCE.md ↓

# Source and attribution

The GitHub MCP Server is built and maintained by GitHub:
https://github.com/github/github-mcp-server

Pinned release: v2.0.3, commit b98d115bbb080e9555466a96656ec4df605aea21
https://github.com/github/github-mcp-server/commit/b98d115bbb080e9555466a96656ec4df605aea21

License: MIT (LICENSE-github-mcp-server.txt is a verbatim copy of LICENSE at
the pinned commit).

Claude Code is Anthropic's product. Its configuration keys and permission
rules come from the official docs at https://code.claude.com/docs/en/mcp
and https://code.claude.com/docs/en/permissions.

add-github-mcp.sh, add-github-mcp-local.sh, claude-settings.json (save it as
.claude/settings.json) and
first-checks.md were written by Agent Setup Kits, adapted from the upstream
Claude installation guide (docs/installation-guides/install-claude.md) at
the pinned commit. Checked 22 Oct 2026. Not affiliated with or endorsed by
GitHub or Anthropic.

Agent Setup Kits authored documentation for Pinned source guide with authored setup files; upstream code and licenses remain attributed separately

LICENSE-github-mcp-server.txtView file +

Upstream MIT license

Download LICENSE-github-mcp-server.txt ↓

MIT License

Copyright (c) 2025 GitHub

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Verbatim copy of LICENSE at the pinned commit

06 / ORIGINAL WORK

Sources, pins, and license

This guide draws on GitHub MCP Server by GitHub, at the linked source revision. Agent Setup Kits is independent of the upstream project. Edition-specific changes are labeled in the file provenance.

GitHub MCP Server, by GitHub

Pinned source guide with authored setup files

Open source
Sources this edition relies on
SourceWhat it supports
Immutable source revision (tag v2.0.3) ↗Exact source snapshot for every flag, header and tool name cited
docs/installation-guides/install-claude.md ↗claude mcp add-json for Claude Code 2.1.1 and newer, remote URL, local binary stdio setup, --scope values, claude mcp list/get, repo scope troubleshooting tip (classic tokens), Windows 'Invalid input' note for add-json
docs/remote-server.md ↗Remote toolset URLs, /readonly path, X-MCP-Toolsets, X-MCP-Readonly and X-MCP-Lockdown headers; unknown toolsets silently ignored; lockdown is not a security boundary
docs/server-configuration.md ↗Toolset and read-only configuration for local and remote servers
README.md ↗Token security best practices, --read-only and --toolsets flags, tool list and required scopes
LICENSE ↗MIT license
Release v2.0.3 ↗Latest release on 2026-10-22, published 2026-10-21; Linux x86_64 binary used for the offline tool check
Claude Code MCP docs (official) ↗${VAR} expansion in command, args, env, url and headers; scopes; missing-variable warning
Claude Code permissions docs (official) ↗mcp__server__tool rule names, allow globs after a literal server prefix, bare-name deny removes a tool from context, mcp__ rules with parentheses are skipped
Source versions and guide targets
ComponentPinSource
github-mcp-serverv2.0.3Original source ↗
Claude Code (add-json format)2.1.1 or newerOriginal source ↗

MIT

The GitHub MCP server is MIT. The hosted endpoint and GitHub's API are GitHub services under GitHub's terms. LICENSE-github-mcp-server.txt is a verbatim copy; all other kit files are authored by Agent Setup Kits.

Read the original license ↗

Related guides

Part of: Which setup should I use to add human approval to an agent?

Your privacy choices

Choose optional tools. Rejecting them keeps the setup library available. Advertising consent stays off.

Choices stay in this browser for 90 days. You can change them using Privacy settings. Privacy and cookie details