GitHub MCP Server Setup for Codex & Claude | Complete 2026 Guide
Connect GitHub to OpenAI Codex & Claude Desktop in 5 minutes. Full config.toml, PAT authentication, tool reference (create_issue, create_pr, search_repos), and troubleshooting. Verified working.
claude_desktop_config.json{
"mcpServers": {
"github": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-github"
],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_xxxxxxxxxxxxxxxxxxxx"
}
}
}
}Generate & Test GitHub MCP Server Config
One-click export with environment variables & path locators for Claude Desktop, Cursor, Windsurf, and OpenAI Codex CLI.
GitHub MCP Server Setup and Configuration Guide
The official GitHub Model Context Protocol (MCP) server enables AI agents—including Claude Desktop, Cursor, Windsurf, and OpenAI Codex CLI—to interact directly with your GitHub repositories. Once configured, your AI assistant can review code, create pull requests, search across codebases, triage issues, and automate complex workflows using standardized tool calls.
This guide walks you through generating a fine-grained Personal Access Token (PAT), configuring your client of choice, and troubleshooting permissions and SAML SSO hurdles.
Prerequisites
- ▸An active GitHub account.
- ▸A GitHub Personal Access Token (PAT) with repository permissions.
- ▸Node.js 18+ installed on your system (verify with
node -v).
Step 1: Create a Fine-Grained Personal Access Token
We strongly recommend using Fine-Grained Personal Access Tokens instead of classic tokens to adhere to the principle of least privilege.
- ▸Navigate to GitHub Settings → Developer Settings → Personal Access Tokens → Fine-grained tokens (opens in a new tab).
- ▸Click Generate new token.
- ▸Fill in the token details:
- ▸Token name:
mcp-github-server - ▸Expiration: Choose 30, 60, or 90 days (never select "No expiration" in enterprise environments).
- ▸Repository access: Choose Only select repositories and pick the repositories your agent will work on.
- ▸Token name:
- ▸Set Repository Permissions:
- ▸Contents:
Read and write(for reading code, creating commits, and creating branches) - ▸Pull requests:
Read and write(for drafting and reviewing PRs) - ▸Issues:
Read and write(for listing and creating issues) - ▸Metadata:
Read-only(selected automatically)
- ▸Contents:
- ▸Click Generate token and copy the token string (
github_pat_...) immediately.
Step 2: Configure Your AI Client
Select your host environment below to copy the exact configuration template.
Claude Desktop (claude_desktop_config.json)
File path:
- ▸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_your_token_here"
}
}
}
}Cursor IDE (~/.cursor/mcp.json)
File path:
- ▸macOS/Linux:
~/.cursor/mcp.json - ▸Windows:
%USERPROFILE%\.cursor\mcp.json
{
"mcpServers": {
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "github_pat_your_token_here"
}
}
}
}OpenAI Codex CLI (~/.codex/config.toml)
File path:
- ▸macOS/Linux:
~/.codex/config.toml - ▸Windows:
%USERPROFILE%\.codex\config.toml
[mcp_servers.github]
command = "npx"
args = ["-y", "@modelcontextprotocol/server-github"]
[mcp_servers.github.env]
GITHUB_PERSONAL_ACCESS_TOKEN = "github_pat_your_token_here"Or add it in one terminal command:
codex mcp add --name github --command "npx -y @modelcontextprotocol/server-github" --env GITHUB_PERSONAL_ACCESS_TOKEN=github_pat_your_token_hereWindsurf / Cascade (~/.codeium/windsurf/mcp_config.json)
{
"mcpServers": {
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "github_pat_your_token_here"
}
}
}
}Step 3: Verify the Connection
- ▸Save your configuration file and restart your AI client (or run
codex mcp restart githubin Codex CLI). - ▸Open a chat session with your AI agent and prompt:
"Use the GitHub tool to search for open pull requests in my repository
<owner>/<repo>." - ▸The client will trigger the
search_repositoriesorlist_pull_requeststool. If prompted, confirm execution.
Available GitHub Tools Reference
The GitHub MCP server provides 20+ specialized tools:
| Category | Tools | Capabilities |
|---|---|---|
| Repositories | search_repositories, get_file_contents, create_or_update_file, push_files | Search code, read repository trees, push multi-file commits |
| Branches | create_branch, list_commits | Create release branches and inspect git history |
| Issues | create_issue, list_issues, update_issue, add_issue_comment | Automate issue triage and bug tracking |
| Pull Requests | create_pull_request, list_pull_requests, get_pull_request_diff, merge_pull_request | Automated PR creation, diff reviews, and merging |
Troubleshooting Common Issues
1. 403 Forbidden / SAML SSO Enforcement
- ▸Symptom: API requests return
403 Resource not accessible by personal access tokenor SAML error. - ▸Fix: If your organization uses Single Sign-On (SAML SSO), you must authorize your token. Go to Personal access tokens in GitHub, find your token, click Configure SSO, and click Authorize next to your organization name.
2. 404 Not Found When Querying Repositories
- ▸Symptom: Agent reports repository does not exist.
- ▸Fix: Verify you provided both the repository owner and name in format
<owner>/<repo>. Also ensure the fine-grained PAT includes access to that specific repository under "Selected Repositories".
3. Rate Limit Exceeded
- ▸Symptom:
403 API rate limit exceeded. - ▸Fix: Personal Access Tokens are granted 5,000 requests per hour. For high-frequency CI/CD agents, consider authenticating via a GitHub App instead of a PAT.
Interactive Links & Tools
Weekly Protocol Diffs & Verified Drops
New server guides, benchmarks, and security audits. No spam. Unsubscribe anytime.
Zero marketing spam. 1-click unsubscribe anytime.
Build your full agent toolstack in the Visual Generator
Combine GitHub with databases, search APIs, and memory graphs in a single configuration file.
Did this setup guide work with your AI host?
Help test this configuration across Claude, Cursor, and Codex CLI. Be the first to report:
GitHub MCP Server Setup for Codex & Claude | Complete 2026 Guide FAQ
What is the GitHub MCP Server Setup for Codex & Claude | Complete 2026 Guide?
Connect GitHub to OpenAI Codex & Claude Desktop in 5 minutes. Full config.toml, PAT authentication, tool reference (create_issue, create_pr, search_repos), and troubleshooting. Verified working.
How do I configure GitHub MCP Server Setup for Codex & Claude | Complete 2026 Guide in Claude Desktop or Cursor?
You can copy the configuration JSON from our guide or launch the interactive MCP Codex Config Generator at https://mcp-codex.com/generator to export valid configs in 1 click.
Can I use GitHub MCP Server Setup for Codex & Claude | Complete 2026 Guide with the OpenAI Codex CLI?
Yes, OpenAI Codex CLI supports Model Context Protocol. You can add it directly to ~/.codex/config.toml or pass arguments to codex mcp add.
Specializing in Model Context Protocol (MCP) integrations, autonomous AI agent orchestration, and distributed developer toolchains. Researches and benchmarks production MCP client-server architectures across OpenAI Codex, Claude, and Cursor.
Related Guides
OpenCode Free AI Agent Guide
Guide to running OpenCode coding agent completely free without API keys using Zen free tier, local LLMs, and OAuth accounts.
Dev ToolsSelf-Correcting Verification Loops in Agents
Build robust self-correcting /loop verification harnesses for AI agents using Test-Driven Agent Development, dual-agent critics, and MCP test sandboxes.
Dev ToolsAutomated Doc Verification Loops with Claude CLI
Build automated documentation verification loops with Claude CLI and MCP. Validate code snippets, test tool schemas, and sync SDK docs in CI/CD. Verified.