用于GitHub API的MCP服务器,支持文件操作、仓库管理、搜索功能等更多功能。
7.0w 查看 · 2026-07-07 更新
简介
用于GitHub API的MCP服务器,支持文件操作、仓库管理、搜索功能等更多功能。
简介
用于GitHub API的MCP服务器,支持文件操作、仓库管理、搜索功能等更多功能。
GitHub MCP 服务器
用于 GitHub API 的 MCP 服务器,支持文件操作、仓库管理、搜索功能等。
功能
- 自动分支创建:在创建/更新文件或推送更改时,如果分支不存在则会自动创建
- 全面的错误处理:针对常见问题提供清晰的错误信息
- Git 历史记录保留:操作过程中保持 Git 历史记录,不会强制推送
- 批量操作:支持单个文件和多个文件的操作
- 高级搜索:支持代码、问题/PR 和用户的搜索
工具
-
create_or_update_file- Create or update a single file in a repository
- Inputs:
owner(string): Repository owner (username or organization)repo(string): Repository namepath(string): Path where to create/update the filecontent(string): Content of the filemessage(string): Commit messagebranch(string): Branch to create/update the file insha(optional string): SHA of file being replaced (for updates)
- Returns: File content and commit details
-
push_files- Push multiple files in a single commit
- Inputs:
owner(string): Repository ownerrepo(string): Repository namebranch(string): Branch to push tofiles(array): Files to push, each withpathandcontentmessage(string): Commit message
- Returns: Updated branch reference
-
search_repositories- Search for GitHub repositories
- Inputs:
query(string): Search querypage(optional number): Page number for paginationperPage(optional number): Results per page (max 100)
- Returns: Repository search results
-
create_repository- Create a new GitHub repository
- Inputs:
name(string): Repository namedescription(optional string): Repository descriptionprivate(optional boolean): Whether repo should be privateautoInit(optional boolean): Initialize with README
- Returns: Created repository details
-
get_file_contents- Get contents of a file or directory
- Inputs:
owner(string): Repository ownerrepo(string): Repository namepath(string): Path to file/directorybranch(optional string): Branch to get contents from
- Returns: File/directory contents
-
create_issue- Create a new issue
- Inputs:
owner(string): Repository ownerrepo(string): Repository nametitle(string): Issue titlebody(optional string): Issue descriptionassignees(optional string[]): Usernames to assignlabels(optional string[]): Labels to addmilestone(optional number): Milestone number
- Returns: Created issue details
-
create_pull_request- Create a new pull request
- Inputs:
owner(string): Repository ownerrepo(string): Repository nametitle(string): PR titlebody(optional string): PR descriptionhead(string): Branch containing changesbase(string): Branch to merge intodraft(optional boolean): Create as draft PRmaintainer_can_modify(optional boolean): Allow maintainer edits
- Returns: Created pull request details
-
fork_repository- Fork a repository
- Inputs:
owner(string): Repository ownerrepo(string): Repository nameorganization(optional string): Organization to fork to
- Returns: Forked repository details
-
create_branch- Create a new branch
- Inputs:
owner(string): Repository ownerrepo(string): Repository namebranch(string): Name for new branchfrom_branch(optional string): Source branch (defaults to repo default)
- Returns: Created branch reference
-
list_issues- List and filter repository issues
- Inputs:
owner(string): Repository ownerrepo(string): Repository namestate(optional string): Filter by state ('open', 'closed', 'all')labels(optional string[]): Filter by labelssort(optional string): Sort by ('created', 'updated', 'comments')direction(optional string): Sort direction ('asc', 'desc')since(optional string): Filter by date (ISO 8601 timestamp)page(optional number): Page numberper_page(optional number): Results per page
- Returns: Array of issue details
-
update_issue- Update an existing issue
- Inputs:
owner(string): Repository ownerrepo(string): Repository nameissue_number(number): Issue number to updatetitle(optional string): New titlebody(optional string): New descriptionstate(optional string): New state ('open' or 'closed')labels(optional string[]): New labelsassignees(optional string[]): New assigneesmilestone(optional number): New milestone number
- Returns: Updated issue details
-
add_issue_comment- Add a comment to an issue
- Inputs:
owner(string): Repository ownerrepo(string): Repository nameissue_number(number): Issue number to comment onbody(string): Comment text
- Returns: Created comment details
-
search_code- Search for code across GitHub repositories
- Inputs:
q(string): Search query using GitHub code search syntaxsort(optional string): Sort field ('indexed' only)order(optional string): Sort order ('asc' or 'desc')per_page(optional number): Results per page (max 100)page(optional number): Page number
- Returns: Code search results with repository context
-
search_issues- Search for issues and pull requests
- Inputs:
q(string): Search query using GitHub issues search syntaxsort(optional string): Sort field (comments, reactions, created, etc.)order(optional string): Sort order ('asc' or 'desc')per_page(optional number): Results per page (max 100)page(optional number): Page number
- Returns: Issue and pull request search results
-
search_users- Search for GitHub users
- Inputs:
q(string): Search query using GitHub users search syntaxsort(optional string): Sort field (followers, repositories, joined)order(optional string): Sort order ('asc' or 'desc')per_page(optional number): Results per page (max 100)page(optional number): Page number
- Returns: User search results
-
list_commits
- 获取仓库中某个分支的提交记录
- 输入参数:
owner(字符串): 仓库所有者repo(字符串): 仓库名称page(可选字符串): 页码per_page(可选字符串): 每页的记录数sha(可选字符串): 分支名称
- 返回: 提交记录列表
get_issue
- 获取仓库内特定问题的内容
- 输入参数:
owner(字符串): 仓库所有者repo(字符串): 仓库名称issue_number(数字): 要检索的问题编号
- 返回: Github 问题对象及详情
get_pull_request
- 获取特定拉取请求的详细信息
- 输入参数:
owner(字符串): 仓库所有者repo(字符串): 仓库名称pull_number(数字): 拉取请求编号
- 返回: 包括差异和审查状态在内的拉取请求详细信息
list_pull_requests
- 列出并过滤仓库的拉取请求
- 输入参数:
owner(字符串): 仓库所有者repo(字符串): 仓库名称state(可选字符串): 按状态过滤 ('open', 'closed', 'all')head(可选字符串): 按头用户/组织及其分支过滤base(可选字符串): 按基础分支过滤sort(可选字符串): 排序依据 ('created', 'updated', 'popularity', 'long-running')direction(可选字符串): 排序方向 ('asc', 'desc')per_page(可选数字): 每页的结果数量(最大100)page(可选数字): 页码
- 返回: 拉取请求详细信息数组
create_pull_request_review
- 在拉取请求上创建审查
- 输入参数:
owner(字符串): 仓库所有者repo(字符串): 仓库名称pull_number(数字): 拉取请求编号body(字符串): 审查评论文本event(字符串): 审查动作 ('APPROVE', 'REQUEST_CHANGES', 'COMMENT')commit_id(可选字符串): 要审查的提交SHAcomments(可选数组): 针对特定行的评论,每个包含:path(字符串): 文件路径position(数字): 差异中的行位置body(字符串): 评论文本
- 返回: 创建的审查详细信息
merge_pull_request
- 合并一个拉取请求
- 输入参数:
owner(字符串): 仓库所有者repo(字符串): 仓库名称pull_number(数字): 拉取请求编号commit_title(可选字符串): 合并提交标题commit_message(可选字符串): 合并提交的额外说明merge_method(可选字符串): 合并方法 ('merge', 'squash', 'rebase')
- 返回: 合并结果详细信息
get_pull_request_files
- 获取拉取请求中更改的文件列表
- 输入参数:
owner(字符串): 仓库所有者repo(字符串): 仓库名称pull_number(数字): 拉取请求编号
- 返回: 包含补丁和状态详细信息的更改文件数组
get_pull_request_status
- 获取拉取请求的所有状态检查的合并状态
- 输入:
owner(字符串):仓库所有者repo(字符串):仓库名称pull_number(数字):拉取请求编号
- 返回:合并状态检查结果及各检查详情
- 输入:
update_pull_request_branch
- 使用基础分支的最新更改更新拉取请求分支(相当于 GitHub 的“更新分支”按钮)
- 输入:
owner(字符串):仓库所有者repo(字符串):仓库名称pull_number(数字):拉取请求编号expected_head_sha(可选字符串):拉取请求 HEAD 引用的预期 SHA
- 返回:当分支更新成功时返回成功消息
get_pull_request_comments
- 获取拉取请求的审查评论
- 输入:
owner(字符串):仓库所有者repo(字符串):仓库名称pull_number(数字):拉取请求编号
- 返回:包含评论文本、作者以及在差异中的位置等详细信息的拉取请求审查评论数组
get_pull_request_reviews
- 获取拉取请求的审查
- 输入:
owner(字符串):仓库所有者repo(字符串):仓库名称pull_number(数字):拉取请求编号
- 返回:包含审查状态(APPROVED, CHANGES_REQUESTED 等)、审查人和审查正文等详细信息的拉取请求审查数组
搜索查询语法
代码搜索
language:javascript:按编程语言搜索repo:owner/name:在特定仓库中搜索path:app/src:在特定路径中搜索extension:js:按文件扩展名搜索- 示例:
q: "import express" language:typescript path:src/
问题搜索
is:issue或is:pr:按类型过滤is:open或is:closed:按状态过滤label:bug:按标签搜索author:username:按作者搜索- 示例:
q: "memory leak" is:issue is:open label:bug
用户搜索
type:user或type:org:按账户类型过滤followers:>1000:按关注者数量过滤location:London:按位置搜索- 示例:
q: "fullstack developer" location:London followers:>100
有关详细的搜索语法,请参阅 GitHub 的搜索文档。
设置
个人访问令牌
- 转到 个人访问令牌(位于 GitHub 设置 > 开发者设置)
- 选择此令牌应有权访问的仓库(公开、全部或选择)
- 创建一个具有
repo范围的令牌(“对私有仓库的完全控制”)- 或者,如果仅处理公共仓库,请仅选择
public_repo范围
- 或者,如果仅处理公共仓库,请仅选择
- 复制生成的令牌
与 Claude Desktop 一起使用
要与此 Claude Desktop 一起使用,请将以下内容添加到您的 claude_desktop_config.json 文件中:
Docker
{ "mcpServers": { "github": { "command": "docker", "args": [ "run", "-i", "--rm", "-e", "GITHUB_PERSONAL_ACCESS_TOKEN", "mcp/github" ], "env": { "GITHUB_PERSONAL_ACCESS_TOKEN": "<YOUR_TOKEN>" } } } }
NPX
{ "mcpServers": { "github": { "command": "npx", "args": [ "-y", "@modelcontextprotocol/server-github" ], "env": { "GITHUB_PERSONAL_ACCESS_TOKEN": "<YOUR_TOKEN>" } } } }
构建
Docker 构建:
docker build -t mcp/github -f src/github/Dockerfile .
许可证
此 MCP 服务器根据 MIT 许可证许可。这意味着您可以自由使用、修改和分发该软件,但需遵守 MIT 许可证的条款和条件。更多详情,请参阅项目仓库中的 LICENSE 文件。
工具列表
-
create_or_update_file: Create or update a single file in a GitHub repository
-
search_repositories: Search for GitHub repositories
-
create_repository: Create a new GitHub repository in your account
-
get_file_contents: Get the contents of a file or directory from a GitHub repository
-
push_files: Push multiple files to a GitHub repository in a single commit
-
create_issue: Create a new issue in a GitHub repository
-
create_pull_request: Create a new pull request in a GitHub repository
-
fork_repository: Fork a GitHub repository to your account or specified organization
-
create_branch: Create a new branch in a GitHub repository
-
list_commits: Get list of commits of a branch in a GitHub repository
-
list_issues: List issues in a GitHub repository with filtering options
-
update_issue: Update an existing issue in a GitHub repository
-
add_issue_comment: Add a comment to an existing issue
-
search_code: Search for code across GitHub repositories
-
search_issues: Search for issues and pull requests across GitHub repositories
-
search_users: Search for users on GitHub
-
get_issue: Get details of a specific issue in a GitHub repository.
服务配置
[{'mcpServers': {'github': {'args': ['-y', '@modelcontextprotocol/server-github'], 'command': 'npx', 'env': {'GITHUB_PERSONAL_ACCESS_TOKEN': '<YOUR_TOKEN>'}}}}]