Connecting Claude Desktop to GitHub MCP Server: Token Scopes, Repository Permissions, and PR Automation
Context switching between code editors, GitHub pull requests, and chat interfaces creates substantial friction during daily engineering tasks. With the official GitHub Model Context Protocol (MCP) server, you can turn Claude Desktop into an autonomous code review assistant and repository investigator. Claude can read repository trees, examine commit histories, search code across branches, and draft contextual pull request comments directly from your desktop.
In this guide, we walk through configuring the GitHub MCP server, determining the exact fine-grained Personal Access Token (PAT) permissions required for enterprise security, and setting up an automated PR review workflow.
Why Use GitHub MCP Over Generic Web Scraping or Copy-Pasting?
Past approaches to AI code reviews involved copying diff files into prompts or using web scraping bots with incomplete context. The GitHub MCP server exposes structured, programmatic tools:
- Granular Code Retrieval: Claude fetches exact file blobs without stuffing the entire repository into the prompt context window.
- Multi-Branch Diff Inspection: Compare feature branches directly against production branches using GitHub API endpoints.
- Issue & PR Management: Claude can list open issues, search issue discussions, and post structured review comments natively.
Underlying Mechanism: How Claude Queries GitHub via MCP
When you ask Claude Desktop a question about a GitHub repository, it formulates structured tool calls. Rather than downloading a giant zip archive or running a heavy git clone on your machine, the GitHub MCP server translates Claude's requests into optimized GitHub REST and GraphQL API calls.
For example, if you ask Claude to compare changes in a pull request, the MCP server invokes octokit.rest.pulls.get to fetch the file diff manifest, identifies the specific modified lines, and returns only the affected hunks. This keeps token utilization minimal while ensuring the model reasons over ground-truth code.
Step 1: Creating a Fine-Grained GitHub Personal Access Token
Never use Classic Personal Access Tokens with blanket repo permissions unless your organization strictly mandates them. Fine-grained tokens restrict Claude's access to specific repositories and enforce least-privilege access.
Required Token Permissions Matrix
| Permission Category | Access Level | Engineering Purpose |
|---|---|---|
Repository permissions > Contents |
Read-only | Read file trees, blobs, commit history, and release tags. |
Repository permissions > Pull requests |
Read and write | Inspect diffs, read existing comments, and submit review drafts. |
Repository permissions > Issues |
Read-only (or Read/Write) | Fetch bug report descriptions and link PRs to existing issue numbers. |
Repository permissions > Metadata |
Read-only (Mandatory) | Mandatory default scope required by GitHub API for basic repo discovery. |
- Navigate to GitHub Settings > Developer Settings > Personal Access Tokens > Fine-grained tokens.
- Click Generate new token. Set an expiration date (we recommend 30 or 90 days with rotation).
- Under Repository access, select Only select repositories and pick the repositories Claude is authorized to access.
- Under Permissions, configure the scopes from the table above.
- Generate the token and copy the secret key (starting with
github_pat_...). Store it safely.
Step 2: Configuring Claude Desktop with GitHub MCP
Anthropic's official GitHub MCP server is distributed via Docker or npm (@modelcontextprotocol/server-github). Using Docker is recommended for sandboxed environments, but Node.js via npx is faster for local development.
Open your claude_desktop_config.json file:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"github": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-github"
],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "github_pat_11AEXAMPLEKEY_..."
}
}
}
}
Security Tip: On macOS, ensure npx is accessible in your system path. If Claude logs complain about spawn npx ENOENT, replace "command": "npx" with the full path from your terminal (e.g., /opt/homebrew/bin/npx or /usr/local/bin/npx).
Step 3: Verification and Available Tools
Restart Claude Desktop (Cmd + Q to quit completely). Open a new chat session and click the hammer icon. You should see an extensive list of GitHub tools, including:
get_file_contents: Fetch code from a specific repository, branch, and filepath.create_or_update_file: Stage modifications directly to a branch.push_files: Batch commit changes to Git.create_pull_request: Create PRs between branches.search_repositories&search_code: Find references across your repositories.
Step 4: Real-World Workflow — Automated PR Review
Here is an operational prompt you can use to have Claude conduct an in-depth security and performance review of an active pull request:
Please inspect Pull Request #42 in the repository "my-org/saas-backend".
Perform the following review steps:
1. Fetch the PR title, description, and list of changed files.
2. Read the diffs for any modified database schemas or API route handlers.
3. Check for security vulnerabilities (e.g., unindexed database queries, missing authentication guards, exposed secrets, SQL injection).
4. Evaluate backward compatibility: will this change break existing mobile or web clients?
5. Generate a structured review summary with specific code block improvements.
Claude will autonomously query the GitHub API, read the exact files touched by PR #42, synthesize the changes, and produce a senior-level code review.
CI/CD Integration: Running Automated PR Reviews in GitHub Actions
While Claude Desktop provides interactive review capabilities on your local workstation, you can also embed the same review intelligence into your automated CI/CD pipeline using a headless runner. When a pull request is opened, GitHub Actions can trigger an automated review check:
name: Claude PR Reviewer
on:
pull_request:
types: [opened, synchronize]
jobs:
review:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Run AI Review Check
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
npx @modelcontextprotocol/runner-review --pr ${{ github.event.pull_request.number }} --repo ${{ github.repository }}
This hybrid workflow allows engineers to use Claude Desktop for deep conversational architecture discussions while letting automated CI jobs catch basic oversights before human team members spend time on review rounds.
Security Best Practices When Granting LLMs Repository Access
- Avoid Storing Tokens in Git: Ensure your
claude_desktop_config.jsonis never committed to a public dotfiles repository. - Use Repository Branch Protection: Even if Claude has write access to pull requests, ensure your
mainormasterbranch has branch protection rules requiring human peer approval and CI passing checks. Never grant Claude bypass rights on branch protection rules. - Be Cautious of Prompt Injections in Untrusted PRs: If you open Claude Desktop against public open-source pull requests submitted by external contributors, malicious actors could embed prompt injection payloads inside comments or markdown docs. Always inspect PR origin before asking Claude to read untrusted branches.
Frequently Asked Questions (FAQ)
Does the GitHub MCP server support GitHub Enterprise Server (on-premises)?
Yes. The server accepts an optional environment variable GITHUB_API_URL. For self-hosted GitHub Enterprise installations, set "GITHUB_API_URL": "https://github.corp.mycompany.com/api/v3" in your server's env block.
Can Claude commit code directly to my protected branches?
Not if branch protection rules are enabled. Claude interacts with GitHub through the standard GitHub REST API using the permissions of your personal access token. If your branch requires pull request reviews, status checks, or signed commits, GitHub rejects any direct push attempt with an HTTP 403 Forbidden error.
What is the GitHub API rate limit for this MCP server?
Authenticated requests using a Personal Access Token enjoy a limit of 5,000 requests per hour per user account. Because Claude fetches targeted diffs rather than entire repositories, an exhaustive code review of an average PR typically consumes between 8 and 25 API requests.
How do I restrict Claude to read-only access?
When creating your fine-grained personal access token, simply omit write permissions: grant Read-only to Contents, Issues, and Pull Requests. If Claude attempts to call a write tool such as create_or_update_file, GitHub will immediately return a permission error.
Conclusion
Connecting Claude Desktop to GitHub via MCP eliminates manual diff copying and provides an AI pairing partner with deep codebase context. By enforcing least-privilege fine-grained tokens and branch protection rules, you gain a high-velocity code review workflow without compromising enterprise security standards.
Join the conversation