Skip to content

Instantly share code, notes, and snippets.

@sjha4
Created October 14, 2025 22:53
Show Gist options
  • Select an option

  • Save sjha4/19df36a99d8dc1db8b975ba04e53a666 to your computer and use it in GitHub Desktop.

Select an option

Save sjha4/19df36a99d8dc1db8b975ba04e53a666 to your computer and use it in GitHub Desktop.

🧠 Setting up GitHub MCP Server for Claude

This guide walks through how to connect Claude to GitHub via an MCP (Model Context Protocol) server, enabling Claude to review PRs, comment on issues, and assist with testing workflows.


🔧 Prerequisites

  • Claude Desktop (v0.7.0 or later) or Anthropic workspace supporting MCP.

  • A valid GitHub Personal Access Token (PAT) with the required scopes.

  • Access to the Claude configuration file:

    ~/.config/claude/claude.json

🔑 Step 0: Generate a GitHub Personal Access Token (PAT)

Before connecting Claude to GitHub, create a Personal Access Token that Claude can use for API authentication.

🪜 Steps to Generate a PAT

  1. Go to your GitHub settings: https://github.com/settings/tokens

  2. Click “Fine-grained personal access tokens” (recommended). Then click “Generate new token” → “Fine-grained token”

  3. Configure the token:

    • Name: Claude MCP Access

    • Expiration: Choose a suitable duration (e.g., 90 days)

    • Repository access: Select either

      • All repositories (if Claude will access multiple repos), or
      • Only selected repositories (recommended for security)
    • Permissions: Grant Read-only access for:

      • Contents
      • Pull requests
      • Metadata
      • (Optional) Issues if you want Claude to comment on or view issues.
  4. Click Generate token and copy the value. It will look like this:

    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
    

⚠️ Important: Store this token securely. Once you leave the page, you won’t be able to view it again.


⚙️ Step 1: Add GitHub MCP Server

Now that you have your PAT, configure Claude to connect to GitHub.

Run the following command (or manually edit your config file):

claude mcp add github \
  --type http \
  --url https://api.githubcopilot.com/mcp/ \
  --header "Authorization: Bearer <YOUR_GITHUB_PAT>"

This adds a new entry under the "mcpServers" section in your claude.json:

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

Tip: Verify the MCP server was added correctly with:

claude mcp list

🧩 Step 2: Ask Claude to Review a GitHub PR

Once the MCP server is configured, Claude can directly access GitHub content.

For example, ask:

“Review the pull request #15874 in the Katello/katello repository.”

Claude will:

  • Retrieve PR details from GitHub via MCP
  • Analyze diffs, comments, and files
  • Provide a structured review (feedback, suggestions, and test coverage insights)

🤖 Step 3: Add an Agent for Edge Case Testing

You can extend Claude’s capabilities with custom agents specialized in tasks such as edge case testing.

Steps

  1. Open Agents in Claude.

  2. Click “Add Agent” → “Custom”

  3. Configure it with:

    • Name: PR Edge Tester

    • Purpose:

      Analyze PRs for edge cases, untested scenarios, and hidden regressions.
      
    • Skills:

      GitHub MCP integration, testing mindset, code review best practices.
      
  4. Save and run it with:

    “Run edge case testing on the PR I just reviewed.”

Claude will use the MCP connection to analyze the PR for potential edge cases.


✅ Verification

Confirm that the MCP server is connected:

claude mcp status github

Expected output:

Connected: true
Endpoint: https://api.githubcopilot.com/mcp/

If you encounter an error:

  • Ensure the token is valid and has not expired.
  • Check that the header starts with Bearer .
  • Make sure there are no extra spaces or line breaks in the token.

🧹 Credential Rotation or Removal

To rotate your PAT or remove the GitHub MCP server:

claude mcp remove github

claude mcp add github \
  --type http \
  --url https://api.githubcopilot.com/mcp/ \
  --header "Authorization: Bearer <NEW_PAT>"

💡 Example Workflow

  1. Add GitHub MCP connection

  2. Ask Claude:

    “Review PR #1234 in my repository.”

  3. Create and run an Edge Tester agent

  4. Get a structured summary and testing recommendations


🛠 Troubleshooting

Issue Possible Fix
401 Unauthorized Check token validity and scopes.
Claude doesn’t access PRs Ensure repository visibility and proper PAT permissions.
MCP not listed Re-run claude mcp add github and confirm config path.

📘 References


Author: Samir Jha Last updated: October 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment