GitHub¶
The GitHub MCP Server connects AI tools directly to GitHub's platform. This gives your ADK agent the ability to read repositories and code files, manage issues and PRs, analyze code, and automate workflows using natural language.
GitHub MCP 服务器 将 AI 工具直接连接到 GitHub 平台。这使您的 ADK 智能体能够读取仓库和代码文件,管理问题和 PR,分析代码,并使用自然语言自动化工作流。
Use cases¶
用例¶
- Repository Management: Browse and query code, search files, analyze commits, and understand project structure across any repository you have access to. 仓库管理:浏览和查询代码,搜索文件,分析提交,并了解您可以访问的任何仓库的项目结构。
- Issue & PR Automation: Create, update, and manage issues and pull requests. Let AI help triage bugs, review code changes, and maintain project boards. 问题和 PR 自动化:创建、更新和管理问题以及拉取请求。让 AI 帮助分类错误、审查代码更改和维护项目看板。
- Code Analysis: Examine security findings, review Dependabot alerts, understand code patterns, and get comprehensive insights into your codebase. 代码分析:检查安全发现,审查 Dependabot 警报,了解代码模式,并对您的代码库获得全面见解。
Prerequisites¶
先决条件¶
- Create a Personal Access Token in GitHub. Refer to the documentation for more information. 在 GitHub 中创建个人访问令牌。有关更多信息,请参阅文档。
Use with agent¶
与智能体一起使用¶
from google.adk.agents import Agent
from google.adk.tools.mcp_tool import McpToolset
from google.adk.tools.mcp_tool.mcp_session_manager import StreamableHTTPServerParams
GITHUB_TOKEN = "YOUR_GITHUB_TOKEN"
root_agent = Agent(
model="gemini-2.5-pro",
name="github_agent",
instruction="Help users get information from GitHub",
tools=[
McpToolset(
connection_params=StreamableHTTPServerParams(
url="https://api.githubcopilot.com/mcp/",
headers={
"Authorization": f"Bearer {GITHUB_TOKEN}",
"X-MCP-Toolsets": "all",
"X-MCP-Readonly": "true"
},
),
)
],
)
Available tools¶
可用的工具¶
Tool | Description
工具 | 描述
---- | -----------
context | Tools that provide context about current user and GitHub context you are operating in
context | 提供有关当前用户和您正在操作的 GitHub 上下文的工具
copilot | Copilot related tools (e.g. Copilot Coding Agent)
copilot | Copilot 相关工具(例如 Copilot 编码智能体)
copilot_spaces | Copilot Spaces related tools
copilot_spaces | Copilot Spaces 相关工具
actions | GitHub Actions workflows and CI/CD operations
actions | GitHub Actions 工作流和 CI/CD 操作
code_security | Code security related tools, such as GitHub Code Scanning
code_security | 代码安全相关工具,如 GitHub 代码扫描
dependabot | Dependabot tools
dependabot | Dependabot 工具
discussions | GitHub Discussions related tools
discussions | GitHub Discussions 相关工具
experiments | Experimental features that are not considered stable yet
experiments | 尚未被视为稳定的实验性功能
gists | GitHub Gist related tools
gists | GitHub Gist 相关工具
github_support_docs_search | Search docs to answer GitHub product and support questions
github_support_docs_search | 搜索文档以回答 GitHub 产品和支持问题
issues | GitHub Issues related tools
issues | GitHub Issues 相关工具
labels | GitHub Labels related tools
labels | GitHub Labels 相关工具
notifications | GitHub Notifications related tools
notifications | GitHub Notifications 相关工具
orgs | GitHub Organization related tools
orgs | GitHub Organization 相关工具
projects | GitHub Projects related tools
projects | GitHub Projects 相关工具
pull_requests | GitHub Pull Request related tools
pull_requests | GitHub Pull Request 相关工具
repos | GitHub Repository related tools
repos | GitHub Repository 相关工具
secret_protection | Secret protection related tools, such as GitHub Secret Scanning
secret_protection | 秘密保护相关工具,如 GitHub 秘密扫描
security_advisories | Security advisories related tools
security_advisories | Security advisories 相关工具
stargazers | GitHub Stargazers related tools
stargazers | GitHub Stargazers 相关工具
users | GitHub User related tools
users | GitHub User 相关工具
Configuration¶
配置¶
Connection Parameters¶
连接参数¶
| Parameter | Type | Required | Default | Description
参数 | 类型 | 必需 | 默认值 | 描述
---------- | ------ | -------- | -------- | -----------
url | string | Yes | - | The URL of the GitHub MCP server endpoint
url | string | 是 | - | GitHub MCP 服务器端点的 URL
headers | dict | No | - | HTTP headers to include in requests
headers | dict | 否 | - | 要包含在请求中的 HTTP 头
timeout | int | No | 30 | Connection timeout in seconds
timeout | int | 否 | 30 | 连接超时时间(以秒为单位)
Header Options¶
头选项¶
| Header | Type | Required | Description
头 | 类型 | 必需 | 描述
-------- | ------ | -------- | -----------
Authorization | string | Yes | Bearer token for authentication (e.g., "Bearer YOUR_TOKEN")
Authorization | string | 是 | 用于身份验证的持有者令牌(例如,"Bearer YOUR_TOKEN")
X-MCP-Toolsets | string | No | Comma-separated list of toolsets to load (e.g., "all", "repos,issues")
X-MCP-Toolsets | string | 否 | 要加载的工具集的逗号分隔列表(例如,"all"、"repos,issues")
X-MCP-Readonly | string | No | Set to "true" for read-only access
X-MCP-Readonly | string | 否 | 设置为 "true" 以进行只读访问
Security Considerations¶
安全考虑¶
- Use environment variables to store your GitHub token, never hardcode it in your source code. 使用环境变量存储您的 GitHub 令牌,永远不要在源代码中硬编码它。
- Limit token permissions to only what's necessary for your use case. 将令牌权限限制为仅用例所需的内容。
- Use read-only mode (
X-MCP-Readonly: "true") when possible to reduce risk. 尽可能使用只读模式(X-MCP-Readonly: "true")以降低风险。 - Regularly rotate your tokens and monitor access logs. 定期轮换您的令牌并监控访问日志。