github-mcp-server

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

github-mcp-server

github-mcp-server

Skill by ara.so — MCP Skills collection.
The GitHub MCP Server is GitHub's official Model Context Protocol server that connects AI tools directly to GitHub's platform. It enables AI agents to read repositories, manage issues and PRs, analyze code, monitor CI/CD pipelines, and automate workflows through natural language interactions.
ara.so提供的Skill — MCP Skills合集。
GitHub MCP Server是GitHub官方的模型上下文协议(Model Context Protocol)服务器,可将AI工具直接连接到GitHub平台。它支持AI Agent通过自然语言交互读取仓库、管理Issue和PR、分析代码、监控CI/CD流水线并自动化工作流。

What It Does

功能介绍

  • Repository Management: Browse code, search files, analyze commits, understand project structure
  • Issue & PR Automation: Create, update, and manage issues and pull requests
  • CI/CD Intelligence: Monitor GitHub Actions, analyze build failures, manage releases
  • Code Analysis: Review security findings, Dependabot alerts, code patterns
  • Team Collaboration: Access discussions, manage notifications, analyze team activity
  • 仓库管理:浏览代码、搜索文件、分析提交、了解项目结构
  • Issue与PR自动化:创建、更新和管理Issue与拉取请求(PR)
  • CI/CD智能监控:监控GitHub Actions、分析构建失败原因、管理版本发布
  • 代码分析:查看安全检测结果、Dependabot告警、代码模式
  • 团队协作:访问讨论内容、管理通知、分析团队活动

Installation

安装

Remote Server (Recommended)

远程服务器(推荐)

The remote GitHub MCP Server is hosted by GitHub and requires no local installation.
远程GitHub MCP Server由GitHub托管,无需本地安装。

VS Code (1.101+)

VS Code(1.101及以上版本)

Using OAuth (Recommended):
json
{
  "servers": {
    "github": {
      "type": "http",
      "url": "https://api.githubcopilot.com/mcp/"
    }
  }
}
Using GitHub PAT:
json
{
  "servers": {
    "github": {
      "type": "http",
      "url": "https://api.githubcopilot.com/mcp/",
      "headers": {
        "Authorization": "Bearer ${input:github_mcp_pat}"
      }
    }
  },
  "inputs": [
    {
      "type": "promptString",
      "id": "github_mcp_pat",
      "description": "GitHub Personal Access Token",
      "password": true
    }
  ]
}
使用OAuth(推荐):
json
{
  "servers": {
    "github": {
      "type": "http",
      "url": "https://api.githubcopilot.com/mcp/"
    }
  }
}
使用GitHub PAT:
json
{
  "servers": {
    "github": {
      "type": "http",
      "url": "https://api.githubcopilot.com/mcp/",
      "headers": {
        "Authorization": "Bearer ${input:github_mcp_pat}"
      }
    }
  },
  "inputs": [
    {
      "type": "promptString",
      "id": "github_mcp_pat",
      "description": "GitHub Personal Access Token",
      "password": true
    }
  ]
}

Claude Desktop

Claude Desktop

json
{
  "mcpServers": {
    "github": {
      "url": "https://api.githubcopilot.com/mcp/",
      "headers": {
        "Authorization": "Bearer YOUR_GITHUB_PAT"
      }
    }
  }
}
Note: Replace
YOUR_GITHUB_PAT
with
${GITHUB_PAT}
if your host supports environment variables.
json
{
  "mcpServers": {
    "github": {
      "url": "https://api.githubcopilot.com/mcp/",
      "headers": {
        "Authorization": "Bearer YOUR_GITHUB_PAT"
      }
    }
  }
}
注意:如果你的宿主环境支持环境变量,请将
YOUR_GITHUB_PAT
替换为
${GITHUB_PAT}

Cursor

Cursor

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

Local Server (Docker)

本地服务器(Docker)

For hosts without remote MCP support or GitHub Enterprise Server:
json
{
  "servers": {
    "github": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "GITHUB_PERSONAL_ACCESS_TOKEN",
        "ghcr.io/github/github-mcp-server"
      ],
      "env": {
        "GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_PAT}"
      }
    }
  }
}
适用于不支持远程MCP或使用GitHub Enterprise Server的环境:
json
{
  "servers": {
    "github": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "GITHUB_PERSONAL_ACCESS_TOKEN",
        "ghcr.io/github/github-mcp-server"
      ],
      "env": {
        "GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_PAT}"
      }
    }
  }
}

Authentication

身份验证

Creating a GitHub Personal Access Token (PAT)

创建GitHub个人访问令牌(PAT)

  1. Go to https://github.com/settings/personal-access-tokens/new
  2. Select permissions based on your needs:
    • repo
      - Full repository access (read/write code, issues, PRs)
    • read:org
      - Read organization data
    • workflow
      - Update GitHub Actions workflows
    • admin:org
      - Manage organization (if needed)
  3. Generate token and store securely
  4. Set as environment variable:
    bash
    export GITHUB_PAT=ghp_yourTokenHere
  1. 访问https://github.com/settings/personal-access-tokens/new
  2. 根据需求选择权限:
    • repo
      - 完整仓库访问权限(读写代码、Issue、PR)
    • read:org
      - 读取组织数据
    • workflow
      - 更新GitHub Actions工作流
    • admin:org
      - 管理组织(如需)
  3. 生成令牌并安全存储
  4. 设置为环境变量:
    bash
    export GITHUB_PAT=ghp_yourTokenHere

Token Security

令牌安全

Store tokens in environment variables, never hardcode:
bash
undefined
将令牌存储在环境变量中,切勿硬编码:
bash
undefined

.env file

.env文件

GITHUB_PAT=ghp_yourTokenHere
GITHUB_PAT=ghp_yourTokenHere

Add to .gitignore

添加到.gitignore

echo ".env" >> .gitignore
undefined
echo ".env" >> .gitignore
undefined

Configuration

配置

Toolsets

工具集

Configure which GitHub APIs are available:
json
{
  "servers": {
    "github": {
      "type": "http",
      "url": "https://api.githubcopilot.com/mcp/",
      "headers": {
        "X-GitHub-MCP-Toolsets": "repos,issues,pulls"
      }
    }
  }
}
Available Toolsets:
  • repos
    - Repository operations
  • issues
    - Issue management
  • pulls
    - Pull request operations
  • actions
    - GitHub Actions workflows
  • search
    - Code and repository search
  • gists
    - Gist management
  • notifications
    - Notification access
Default Toolset (when not specified):
repos,issues,pulls,actions,search
配置可用的GitHub API:
json
{
  "servers": {
    "github": {
      "type": "http",
      "url": "https://api.githubcopilot.com/mcp/",
      "headers": {
        "X-GitHub-MCP-Toolsets": "repos,issues,pulls"
      }
    }
  }
}
可用工具集:
  • repos
    - 仓库操作
  • issues
    - Issue管理
  • pulls
    - 拉取请求操作
  • actions
    - GitHub Actions工作流
  • search
    - 代码与仓库搜索
  • gists
    - Gist管理
  • notifications
    - 通知访问
默认工具集(未指定时):
repos,issues,pulls,actions,search

GitHub Enterprise Cloud (ghe.com)

GitHub Enterprise Cloud (ghe.com)

json
{
  "servers": {
    "github-enterprise": {
      "type": "http",
      "url": "https://copilot-api.octocorp.ghe.com/mcp",
      "headers": {
        "Authorization": "Bearer ${GITHUB_ENTERPRISE_PAT}"
      }
    }
  }
}
json
{
  "servers": {
    "github-enterprise": {
      "type": "http",
      "url": "https://copilot-api.octocorp.ghe.com/mcp",
      "headers": {
        "Authorization": "Bearer ${GITHUB_ENTERPRISE_PAT}"
      }
    }
  }
}

GitHub Enterprise Server

GitHub Enterprise Server

json
{
  "servers": {
    "github-ghes": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "GITHUB_PERSONAL_ACCESS_TOKEN",
        "-e",
        "GITHUB_HOST",
        "ghcr.io/github/github-mcp-server"
      ],
      "env": {
        "GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_PAT}",
        "GITHUB_HOST": "https://github.yourcompany.com"
      }
    }
  }
}
json
{
  "servers": {
    "github-ghes": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "GITHUB_PERSONAL_ACCESS_TOKEN",
        "-e",
        "GITHUB_HOST",
        "ghcr.io/github/github-mcp-server"
      ],
      "env": {
        "GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_PAT}",
        "GITHUB_HOST": "https://github.yourcompany.com"
      }
    }
  }
}

Insiders Mode

内测模式

Access experimental features:
Via URL:
json
{
  "servers": {
    "github": {
      "type": "http",
      "url": "https://api.githubcopilot.com/mcp/insiders"
    }
  }
}
Via Header:
json
{
  "servers": {
    "github": {
      "type": "http",
      "url": "https://api.githubcopilot.com/mcp/",
      "headers": {
        "X-MCP-Insiders": "true"
      }
    }
  }
}
访问实验性功能:
通过URL:
json
{
  "servers": {
    "github": {
      "type": "http",
      "url": "https://api.githubcopilot.com/mcp/insiders"
    }
  }
}
通过请求头:
json
{
  "servers": {
    "github": {
      "type": "http",
      "url": "https://api.githubcopilot.com/mcp/",
      "headers": {
        "X-MCP-Insiders": "true"
      }
    }
  }
}

Usage Patterns

使用场景

Repository Operations

仓库操作

List repository files:
Show me all Python files in github/github-mcp-server
Read file contents:
Show me the contents of main.go in github/github-mcp-server
Search code:
Find all functions that use the GitHub API in github/github-mcp-server
Analyze commits:
Show recent commits in github/github-mcp-server main branch
列出仓库文件:
Show me all Python files in github/github-mcp-server
读取文件内容:
Show me the contents of main.go in github/github-mcp-server
搜索代码:
Find all functions that use the GitHub API in github/github-mcp-server
分析提交记录:
Show recent commits in github/github-mcp-server main branch

Issue Management

Issue管理

List issues:
Show open issues in github/github-mcp-server labeled as bug
Create issue:
Create an issue in github/github-mcp-server titled "Add support for X" with description "We need X because..."
Update issue:
Add comment to issue #123 in github/github-mcp-server saying "Working on this"
Close issue:
Close issue #456 in github/github-mcp-server
列出Issue:
Show open issues in github/github-mcp-server labeled as bug
创建Issue:
Create an issue in github/github-mcp-server titled "Add support for X" with description "We need X because..."
更新Issue:
Add comment to issue #123 in github/github-mcp-server saying "Working on this"
关闭Issue:
Close issue #456 in github/github-mcp-server

Pull Request Operations

拉取请求操作

List PRs:
Show all open pull requests in github/github-mcp-server
Create PR:
Create a pull request in github/github-mcp-server from feature-branch to main with title "Add new feature"
Review PR:
Show me the diff for PR #789 in github/github-mcp-server
Merge PR:
Merge pull request #101 in github/github-mcp-server
列出PR:
Show all open pull requests in github/github-mcp-server
创建PR:
Create a pull request in github/github-mcp-server from feature-branch to main with title "Add new feature"
评审PR:
Show me the diff for PR #789 in github/github-mcp-server
合并PR:
Merge pull request #101 in github/github-mcp-server

GitHub Actions

GitHub Actions

List workflows:
Show all GitHub Actions workflows in github/github-mcp-server
View workflow runs:
Show recent workflow runs for CI in github/github-mcp-server
Analyze failures:
Why did the latest build fail in github/github-mcp-server?
Trigger workflow:
Trigger the deploy workflow in github/github-mcp-server
列出工作流:
Show all GitHub Actions workflows in github/github-mcp-server
查看工作流运行记录:
Show recent workflow runs for CI in github/github-mcp-server
分析构建失败原因:
Why did the latest build fail in github/github-mcp-server?
触发工作流:
Trigger the deploy workflow in github/github-mcp-server

Code Analysis

代码分析

Security alerts:
Show Dependabot alerts for github/github-mcp-server
Code search across organization:
Find all repositories in github org using deprecated API
Analyze repository structure:
What's the directory structure of github/github-mcp-server?
安全告警:
Show Dependabot alerts for github/github-mcp-server
跨组织代码搜索:
Find all repositories in github org using deprecated API
分析仓库结构:
What's the directory structure of github/github-mcp-server?

Common Patterns

常见使用模式

Multi-Repository Analysis

多仓库分析

Compare the CI/CD setup between github/repo1 and github/repo2
Compare the CI/CD setup between github/repo1 and github/repo2

Automated Triage

自动分类

Label all open issues in github/github-mcp-server that mention "authentication" with "auth"
Label all open issues in github/github-mcp-server that mention "authentication" with "auth"

Release Management

版本发布管理

Create a release for github/github-mcp-server version 2.0.0 with notes from recent PRs
Create a release for github/github-mcp-server version 2.0.0 with notes from recent PRs

Team Coordination

团队协作

Show me all PRs assigned to me across github organization
Show me all PRs assigned to me across github organization

Code Review Assistance

代码评审辅助

Review PR #234 in github/github-mcp-server and suggest improvements
Review PR #234 in github/github-mcp-server and suggest improvements

Troubleshooting

故障排查

Connection Issues

连接问题

Problem: Server not connecting
Error: Unable to connect to GitHub MCP server
Solution: Verify server configuration
  1. Check URL is correct:
    https://api.githubcopilot.com/mcp/
  2. For local Docker: Ensure Docker is running
  3. Restart your IDE/MCP host
问题:服务器无法连接
Error: Unable to connect to GitHub MCP server
解决方案:验证服务器配置
  1. 检查URL是否正确:
    https://api.githubcopilot.com/mcp/
  2. 本地Docker环境:确保Docker正在运行
  3. 重启你的IDE/MCP宿主环境

Authentication Failures

身份验证失败

Problem: 401 Unauthorized
Error: Authentication failed
Solution: Verify token
  1. Check PAT is valid: https://github.com/settings/tokens
  2. Ensure token has required scopes
  3. Verify environment variable is set correctly:
    bash
    echo $GITHUB_PAT
  4. Restart MCP host after updating token
问题:401 Unauthorized
Error: Authentication failed
解决方案:验证令牌
  1. 检查PAT是否有效:访问https://github.com/settings/tokens
  2. 确保令牌拥有所需权限
  3. 验证环境变量是否正确设置:
    bash
    echo $GITHUB_PAT
  4. 更新令牌后重启MCP宿主环境

Permission Errors

权限错误

Problem: 403 Forbidden or 404 Not Found
Error: Resource not accessible
Solution: Check token permissions
  1. Verify PAT has required scope (e.g.,
    repo
    for private repos)
  2. Confirm you have access to the repository
  3. For organizations, check if SSO is required:
问题:403 Forbidden或404 Not Found
Error: Resource not accessible
解决方案:检查令牌权限
  1. 验证PAT拥有所需权限(例如,私有仓库需要
    repo
    权限)
  2. 确认你拥有该仓库的访问权限
  3. 针对组织,检查是否需要SSO:

Docker Issues

Docker问题

Problem: Image pull failed
Error: failed to pull ghcr.io/github/github-mcp-server
Solution:
  1. Check Docker is running:
    docker ps
  2. Logout if you have expired credentials:
    bash
    docker logout ghcr.io
  3. Pull manually to test:
    bash
    docker pull ghcr.io/github/github-mcp-server
问题:镜像拉取失败
Error: failed to pull ghcr.io/github/github-mcp-server
解决方案
  1. 检查Docker是否正在运行:
    docker ps
  2. 如果凭证过期,登出:
    bash
    docker logout ghcr.io
  3. 手动拉取测试:
    bash
    docker pull ghcr.io/github/github-mcp-server

Rate Limiting

速率限制

Problem: API rate limit exceeded
Error: API rate limit exceeded
Solution: Authenticated requests have higher limits
  1. Ensure PAT is properly configured
  2. Wait for rate limit reset (check response headers)
  3. For heavy usage, consider GitHub Apps instead of PATs
问题:API速率限制超出
Error: API rate limit exceeded
解决方案:已认证请求拥有更高限制
  1. 确保PAT已正确配置
  2. 等待速率限制重置(查看响应头)
  3. 对于高频使用场景,考虑使用GitHub Apps替代PAT

Enterprise Server Connection

Enterprise Server连接问题

Problem: Cannot connect to GitHub Enterprise Server
Error: Connection timeout
Solution: Check GITHUB_HOST configuration
  1. Ensure URL includes
    https://
    scheme:
    json
    "GITHUB_HOST": "https://github.company.com"
  2. Verify server is accessible from your network
  3. Check firewall/VPN settings
问题:无法连接到GitHub Enterprise Server
Error: Connection timeout
解决方案:检查GITHUB_HOST配置
  1. 确保URL包含
    https://
    协议:
    json
    "GITHUB_HOST": "https://github.company.com"
  2. 验证服务器在你的网络中可访问
  3. 检查防火墙/VPN设置

Toolset Not Available

工具集不可用

Problem: Tool not found
Error: Tool 'create_gist' not available
Solution: Enable required toolset
json
{
  "headers": {
    "X-GitHub-MCP-Toolsets": "repos,issues,pulls,gists"
  }
}
问题:工具未找到
Error: Tool 'create_gist' not available
解决方案:启用所需工具集
json
{
  "headers": {
    "X-GitHub-MCP-Toolsets": "repos,issues,pulls,gists"
  }
}

VS Code Integration Issues

VS Code集成问题

Problem: Server not appearing in VS Code
Server 'github' not found
Solution:
  1. Ensure VS Code version is 1.101+
  2. Reload VS Code: Cmd/Ctrl + Shift + P → "Developer: Reload Window"
  3. Check settings location:
    .vscode/settings.json
    or user settings
  4. Enable Agent mode in Copilot Chat
问题:服务器未在VS Code中显示
Server 'github' not found
解决方案
  1. 确保VS Code版本为1.101及以上
  2. 重新加载VS Code:Cmd/Ctrl + Shift + P → "开发者:重新加载窗口"
  3. 检查设置位置:
    .vscode/settings.json
    或用户设置
  4. 在Copilot Chat中启用Agent模式

Environment Variable Not Resolved

环境变量未解析

Problem: Token showing as literal string
Authorization: Bearer ${GITHUB_PAT}
Solution: Host-specific syntax
  • Some hosts use
    ${GITHUB_PAT}
  • Others use
    ${input:github_token}
  • Some require hardcoded values
  • Check host documentation for variable syntax
问题:令牌显示为字面字符串
Authorization: Bearer ${GITHUB_PAT}
解决方案:根据宿主环境使用对应语法
  • 部分宿主使用
    ${GITHUB_PAT}
  • 其他宿主使用
    ${input:github_token}
  • 部分环境需要硬编码值
  • 查看宿主文档了解变量语法

Testing Connection

测试连接

Verify server is working:
List repositories in github organization
If successful, you should see a list of repositories. If not, check logs in your MCP host.
验证服务器是否正常工作:
List repositories in github organization
如果成功,你将看到仓库列表。如果失败,请查看MCP宿主环境中的日志。