GitHub and GitLab MCP Integration
Your AI just wrote a utility function that already exists in your codebase — buried three directories deep in a file nobody remembers. It created a branch with a name that violates your team’s convention. It wrote a commit message that says “fix stuff.” All of these problems disappear when the AI can actually read your git history and interact with your version control platform.
What You’ll Walk Away With
Section titled “What You’ll Walk Away With”- Setup for GitHub MCP (official) and GitLab MCP across all three tools
- Prompts for code search, PR review, branch management, and commit workflows
- Security guidance for scoping personal access tokens
- Strategies for using version control MCP in monorepo environments
GitHub MCP Server (Official)
Section titled “GitHub MCP Server (Official)”GitHub’s official MCP server provides deep integration with the GitHub API: code search, PR management, issue tracking, CI status, and repository operations.
{ "mcpServers": { "github": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-github"], "env": { "GITHUB_PERSONAL_ACCESS_TOKEN": "<your-token>" } } }}{ "mcpServers": { "github": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-github"], "env": { "GITHUB_PERSONAL_ACCESS_TOKEN": "<your-token>" } } }}[mcp.github]transport = "stdio"command = "npx"args = ["-y", "@modelcontextprotocol/server-github"]
[mcp.github.env]GITHUB_PERSONAL_ACCESS_TOKEN = "<your-token>"Git MCP Server (Local Repos)
Section titled “Git MCP Server (Local Repos)”The Git MCP server works with your local repository. It gives the AI structured access to branches, commits, diffs, and logs without fragile shell parsing.
{ "mcpServers": { "git": { "command": "uvx", "args": ["mcp-server-git"] } }}Claude Code has built-in git capabilities through its native Bash tool. It can run git commands directly. A separate Git MCP is useful if you want structured responses rather than raw command output.
[mcp.git]transport = "stdio"command = "uvx"args = ["mcp-server-git"]GitLab MCP
Section titled “GitLab MCP”For teams on GitLab, the GitLab MCP server provides integration with CI/CD pipelines, merge requests, and issue tracking.
{ "mcpServers": { "gitlab": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-gitlab"], "env": { "GITLAB_TOKEN": "<your-token>", "GITLAB_URL": "https://gitlab.com" } } }}{ "mcpServers": { "gitlab": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-gitlab"], "env": { "GITLAB_TOKEN": "<your-token>", "GITLAB_URL": "https://gitlab.com" } } }}[mcp.gitlab]transport = "stdio"command = "npx"args = ["-y", "@modelcontextprotocol/server-gitlab"]
[mcp.gitlab.env]GITLAB_TOKEN = "<your-token>"GITLAB_URL = "https://gitlab.com"Token Scoping for Security
Section titled “Token Scoping for Security”When creating personal access tokens, apply the principle of least privilege:
| Scope | GitHub | GitLab | Use Case |
|---|---|---|---|
| Read code | repo (read) | read_repository | Code search, file reading |
| Read PRs/MRs | repo (read) | read_api | PR review, diff analysis |
| Write PRs/MRs | repo (write) | api | Creating PRs, updating issues |
| CI status | repo (read) | read_api | Pipeline monitoring |
Start with read-only scopes. Add write access only when the AI needs to create branches, PRs, or update issues.
When This Breaks
Section titled “When This Breaks”“Bad credentials” error. Regenerate your token with the correct scopes. Fine-grained tokens on GitHub require explicit repository access — make sure you selected the right repos.
Code search returns no results. GitHub’s code search requires the repository to be indexed. New repositories or recently pushed branches may take a few minutes to appear in search results.
Rate limiting. The GitHub API has rate limits (5,000 requests/hour for authenticated users). If the AI makes too many calls, you will see 403 errors. Reduce the scope of your prompts or use the local Git MCP for operations that do not require GitHub’s API.