MCP 服务器工具

@asbloom-py/mcp-servers
Hosted
1 Stars 352 次浏览 asbloom-py 更新于 2026-08-23

通过 GitHub API 启用与 GitHub 的交互,支持文件操作、仓库管理、高级搜索和问题跟踪,具有全面的错误处理和自动分支创建功能。

MCP 服务配置

复制以下 JSON 到 OPClaw 或其他 MCP 客户端的配置文件中即可使用

{
  "mcpServers": {
    "github": {
      "args": [
        "-y",
        "@modelcontextprotocol/server-github"
      ],
      "command": "npx",
      "env": {
        "GITHUB_PERSONAL_ACCESS_TOKEN": "\u003cYOUR_TOKEN\u003e"
      }
    }
  }
}

该服务需要配置环境变量:GITHUB_PERSONAL_ACCESS_TOKEN

服务介绍

GitHub MCP 服务器

用于 GitHub API 的 MCP 服务器,支持文件操作、仓库管理、搜索功能等。

功能

  • 自动分支创建:在创建/更新文件或推送更改时,如果分支不存在,则会自动创建
  • 全面的错误处理:针对常见问题提供清晰的错误信息
  • Git 历史记录保留:操作过程中保持正确的 Git 历史记录,不使用强制推送
  • 批量操作:支持单个文件和多个文件的操作
  • 高级搜索:支持代码、问题/PR 和用户的搜索

工具

  1. create_or_update_file

    • Create or update a single file in a repository
    • Inputs:
      • owner (string): Repository owner (username or organization)
      • repo (string): Repository name
      • path (string): Path where to create/update the file
      • content (string): Content of the file
      • message (string): Commit message
      • branch (string): Branch to create/update the file in
      • sha (optional string): SHA of file being replaced (for updates)
    • Returns: File content and commit details
  2. push_files

    • Push multiple files in a single commit
    • Inputs:
      • owner (string): Repository owner
      • repo (string): Repository name
      • branch (string): Branch to push to
      • files (array): Files to push, each with path and content
      • message (string): Commit message
    • Returns: Updated branch reference
  3. search_repositories

    • Search for GitHub repositories
    • Inputs:
      • query (string): Search query
      • page (optional number): Page number for pagination
      • perPage (optional number): Results per page (max 100)
    • Returns: Repository search results
  4. create_repository

    • Create a new GitHub repository
    • Inputs:
      • name (string): Repository name
      • description (optional string): Repository description
      • private (optional boolean): Whether repo should be private
      • autoInit (optional boolean): Initialize with README
    • Returns: Created repository details
  5. get_file_contents

    • Get contents of a file or directory
    • Inputs:
      • owner (string): Repository owner
      • repo (string): Repository name
      • path (string): Path to file/directory
      • branch (optional string): Branch to get contents from
    • Returns: File/directory contents
  6. create_issue

    • Create a new issue
    • Inputs:
      • owner (string): Repository owner
      • repo (string): Repository name
      • title (string): Issue title
      • body (optional string): Issue description
      • assignees (optional string[]): Usernames to assign
      • labels (optional string[]): Labels to add
      • milestone (optional number): Milestone number
    • Returns: Created issue details
  7. create_pull_request

    • Create a new pull request
    • Inputs:
      • owner (string): Repository owner
      • repo (string): Repository name
      • title (string): PR title
      • body (optional string): PR description
      • head (string): Branch containing changes
      • base (string): Branch to merge into
      • draft (optional boolean): Create as draft PR
      • maintainer_can_modify (optional boolean): Allow maintainer edits
    • Returns: Created pull request details
  8. fork_repository

    • Fork a repository
    • Inputs:
      • owner (string): Repository owner
      • repo (string): Repository name
      • organization (optional string): Organization to fork to
    • Returns: Forked repository details
  9. create_branch

    • Create a new branch
    • Inputs:
      • owner (string): Repository owner
      • repo (string): Repository name
      • branch (string): Name for new branch
      • from_branch (optional string): Source branch (defaults to repo default)
    • Returns: Created branch reference
  10. list_issues

    • List and filter repository issues
    • Inputs:
      • owner (string): Repository owner
      • repo (string): Repository name
      • state (optional string): Filter by state ('open', 'closed', 'all')
      • labels (optional string[]): Filter by labels
      • sort (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 number
      • per_page (optional number): Results per page
    • Returns: Array of issue details
  11. update_issue

    • Update an existing issue
    • Inputs:
      • owner (string): Repository owner
      • repo (string): Repository name
      • issue_number (number): Issue number to update
      • title (optional string): New title
      • body (optional string): New description
      • state (optional string): New state ('open' or 'closed')
      • labels (optional string[]): New labels
      • assignees (optional string[]): New assignees
      • milestone (optional number): New milestone number
    • Returns: Updated issue details
  12. add_issue_comment

    • Add a comment to an issue
    • Inputs:
      • owner (string): Repository owner
      • repo (string): Repository name
      • issue_number (number): Issue number to comment on
      • body (string): Comment text
    • Returns: Created comment details
  13. search_code

    • Search for code across GitHub repositories
    • Inputs:
      • q (string): Search query using GitHub code search syntax
      • sort (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
  14. search_issues

    • Search for issues and pull requests
    • Inputs:
      • q (string): Search query using GitHub issues search syntax
      • sort (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
  15. search_users

    • Search for GitHub users
    • Inputs:
      • q (string): Search query using GitHub users search syntax
      • sort (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
  16. list_commits

  • 获取仓库中某个分支的提交记录
  • 输入参数:
    • owner (字符串): 仓库所有者
    • repo (字符串): 仓库名称
    • page (可选字符串): 页码
    • per_page (可选字符串): 每页记录数
    • sha (可选字符串): 分支名称
  • 返回: 提交记录列表
  1. get_issue
  • 获取仓库中某个问题的内容
  • 输入参数:
    • owner (字符串): 仓库所有者
    • repo (字符串): 仓库名称
    • issue_number (数字): 要检索的问题编号
  • 返回: GitHub 问题对象及详细信息
  1. get_issue_comments
  • 获取某个问题或拉取请求的评论
  • 输入参数:
    • owner (字符串): 仓库所有者
    • repo (字符串): 仓库名称
    • issue_number (数字): 要检索评论的问题/PR 编号
  • 返回: 包含评论 ID、正文文本、作者和时间戳的 GitHub 评论对象数组

搜索查询语法

代码搜索

  • language:javascript: 按编程语言搜索
  • repo:owner/name: 在特定仓库中搜索
  • path:app/src: 在特定路径中搜索
  • extension:js: 按文件扩展名搜索
  • 示例: q: "import express" language:typescript path:src/

问题搜索

  • is:issueis:pr: 按类型过滤
  • is:openis:closed: 按状态过滤
  • label:bug: 按标签搜索
  • author:username: 按作者搜索
  • 示例: q: "memory leak" is:issue is:open label:bug

用户搜索

  • type:usertype:org: 按账户类型过滤
  • followers:>1000: 按关注者数量过滤
  • location:London: 按位置搜索
  • 示例: q: "fullstack developer" location:London followers:>100

有关详细的搜索语法,请参阅 GitHub 的搜索文档

设置

个人访问令牌

创建一个具有适当权限的 GitHub 个人访问令牌

  • 前往 个人访问令牌(在 GitHub 设置 > 开发者设置中)
  • 选择此令牌要访问的仓库(公开、全部或选择)
  • 创建一个带有 repo 范围的令牌(“对私有仓库的完全控制”)
    • 如果仅处理公共仓库,可以选择只使用 public_repo 范围
  • 复制生成的令牌

与 Claude Desktop 一起使用

要在 Claude Desktop 中使用此功能,请将以下内容添加到您的 claude_desktop_config.json 文件中:

{
  "mcpServers": {
    "github": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-github"
      ],
      "env": {
        "GITHUB_PERSONAL_ACCESS_TOKEN": "<YOUR_TOKEN>"
      }
    }
  }
}

许可证

此 MCP 服务器根据 MIT 许可证授权。这意味着您可以自由地使用、修改和分发该软件,但需遵守 MIT 许可证的条款和条件。更多详情,请参见项目仓库中的 LICENSE 文件。

相关 MCP 服务