How to Set Up the GitHub MCP Server for Repository Management
Connect your AI agent to GitHub repositories. Create issues, manage pull requests, search code, and automate repository workflows through MCP.
Generate & Test GitHub MCP Server Config
One-click export with environment variables & path locators for Claude Desktop, Cursor, Windsurf, and OpenAI Codex CLI.
Set Up the GitHub MCP Server
The GitHub MCP server provides comprehensive access to GitHub's REST API. It transforms your AI agent into an automated project manager and code reviewer capable of managing repositories, triaging issues, and drafting pull requests.
Prerequisites
- βΈA GitHub account.
- βΈA GitHub Personal Access Token (PAT).
- βΈNode.js 18+ installed locally.
Creating a Fine-Grained Personal Access Token
It is strongly recommended to use Fine-Grained Tokens rather than Classic Tokens for security.
- βΈGo to GitHub Settings β Developer Settings β Personal Access Tokens β Fine-grained tokens.
- βΈClick Generate new token.
- βΈSet the Repository access to "Only select repositories".
- βΈAssign the following Permissions:
- βΈContents (Read/Write)
- βΈIssues (Read/Write)
- βΈPull Requests (Read/Write)
- βΈGenerate the token and copy it immediately.
Configuration Setup
Add the following to your MCP client config:
{
"mcpServers": {
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "github_pat_your_token_here"
}
}
}
}Available Tools
The GitHub server exposes a massive suite of tools to the agent:
Repository Operations
- βΈ
create_repository/search_repositories/get_file_contents/push_files/create_branch
Issue Management
- βΈ
create_issue/list_issues/update_issue/add_issue_comment
Pull Request Operations
- βΈ
create_pull_request/list_pull_requests/merge_pull_request/get_pull_request_diff
Example Workflows
- βΈCode Review Assistant: "Review the latest pull request on
my-org/my-repo, look for security vulnerabilities, and add a comment on the issue with your findings." - βΈIssue Triage: "List all open issues labeled 'bug' in
my-repoand categorize them by severity based on the user descriptions." - βΈRepository Analysis: "Analyze the codebase structure of
my-org/my-repoand create aREADME.mdoutline."
Troubleshooting
- βΈ
403 Forbidden/ SAML SSO: If your organization enforces SAML Single Sign-On, your PAT will be rejected by the API unless you explicitly authorize the token for use with that specific organization in the GitHub UI. - βΈ
404 Not Found: This almost always means your token lacks the correct permissions to view the repository, or the repository name is misspelled. Remember that repos must be prefixed with their owner (owner-name/repo-name). - βΈToken Expiry: Fine-grained tokens have a maximum lifespan of 1 year. If your agent suddenly loses access, verify your PAT hasn't expired.
Using with OpenAI Codex
You can use this MCP server with the OpenAI Codex CLI by adding it to your configuration:
codex mcp add --name github --command "npx -y @modelcontextprotocol/server-github" --env GITHUB_PERSONAL_ACCESS_TOKEN=ghp_your_tokenFor a full list of recommended servers, see Best MCP Servers for OpenAI Codex.
Build your full agent toolstack in the Visual Generator
Combine GitHub with databases, search APIs, and memory graphs in a single configuration file.
Related Guides
How to Build a Custom MCP Server from Scratch
Learn how to create your own MCP server using the TypeScript or Python SDK. Expose custom tools and resources for AI agents to use.
Dev ToolsHow to Use the Puppeteer MCP Server for Web Scraping & Automation
Automate web browsers using the Puppeteer MCP server. Navigate websites, take screenshots, extract data, and automate web interactions through AI.
Dev ToolsHow to Use the Git MCP Server for Version Control Operations
Manage local Git repositories through AI agents. Clone repos, create branches, make commits, and view diffs using the Git MCP server.