MCP & Integrations/MCP Servers
Intermediate16 min

Claude Code GitHub Connector -- AI That Understands Your Whole Repo

The GitHub MCP server turns Claude Code into a full-featured GitHub client. This guide covers setup, real PR review workflows, issue management, CI monitoring, and security best practices. Learn when to use the GitHub MCP versus the gh CLI and how to combine both for maximum productivity.

Quick Reference

  • GitHub MCP server: npx -y @modelcontextprotocol/server-github with GITHUB_TOKEN env var
  • Create a fine-grained personal access token at github.com/settings/tokens with only needed permissions
  • GitHub MCP can read PRs, diffs, comments, reviews, issues, labels, workflow runs, and repo metadata
  • GitHub MCP can write: create PRs, post review comments, open/close issues, add labels
  • gh CLI is better for one-off commands; GitHub MCP is better when Claude needs multi-step repo context
  • Claude can review a PR end-to-end: fetch diff, analyze code, post inline comments, approve or request changes
  • Always use read-only tokens for projects where Claude should only observe, not modify
  • GitHub MCP respects repository permissions -- Claude cannot access repos your token cannot access

Setting Up the GitHub MCP Server

The GitHub MCP server connects Claude Code to the GitHub API. Once connected, Claude can interact with your repositories the same way you would through the GitHub web interface or gh CLI -- but with the added intelligence of understanding code context.

1

Create a personal access token

Go to github.com/settings/tokens and create a fine-grained personal access token. Select only the repositories you want Claude to access. Grant permissions for: Contents (read), Pull requests (read/write), Issues (read/write), Actions (read), and Metadata (read).

2

Set the environment variable

Add export GITHUB_TOKEN="ghp_your_token_here" to your .zshrc or .bashrc file. Run source ~/.zshrc to apply immediately.

3

Add the server to .mcp.json

Create or edit .mcp.json in your project root. Add the github server with command "npx", args ["-y", "@modelcontextprotocol/server-github"], and env GITHUB_TOKEN set to "${GITHUB_TOKEN}".

4

Verify the connection

Start Claude Code and ask "List my open pull requests." If Claude returns your PRs, the connection is working. If it fails, check that GITHUB_TOKEN is set in your shell environment.

GitHub MCP server configuration in .mcp.json
Token scope matters

If Claude says it cannot access a repository or perform an action, the issue is almost always token permissions. Fine-grained tokens let you grant access per-repository and per-capability. Start with minimal permissions and add more as needed.