GitHub集成工具

GitHub MCP Server是一个为AI助手提供GitHub集成工具的服务,支持管理仓库、问题、拉取请求和内容。

  • by fleXRPL
  • Python
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 flexrpl/github-mcp

使用说明

GitHub MCP服务器

一个模型上下文协议(MCP)服务器,为AI助手提供GitHub集成工具。该服务器实现了一组工具,允许AI模型与GitHub存储库、问题、拉取请求和内容进行交互。

特性

  • 库管理
    • 列出存储库
    • 获取存储库详细信息
  • 问题管理
    • 列出问题
    • 创建问题
  • 拉取请求管理
    • 列出拉取请求
    • 创建拉取请求
  • 内容管理
    • 获取文件内容
    • 列出目录内容

安装

  1. 克隆存储库:
git clone https://github.com/yourusername/github-mcp.git
cd github-mcp
  1. 安装软件包:
pip install -e .

认证

此服务器使用 githubauthlib 用于安全的GitHub身份验证。库从系统的钥匙链中检索GitHub令牌:

  • macOS:使用钥匙链访问
  • Windows:使用凭据管理器
  • Linux:使用libsecret

要设置身份验证,请执行以下操作:

  1. 安装所需的系统依赖项:

    • macOS:无需额外设置

    • Windows:无需额外设置

    • Linux:安装libsecret

      # Ubuntu/Debian
      sudo apt-get install libsecret-tools
      
      # Fedora
      sudo dnf install libsecret
      
  2. 配置您的GitHub凭据:

    • 服务器将自动使用系统密钥链中的Git凭据

    • 如果找不到凭据,则需要使用GitHub凭据配置Git:

      git config --global credential.helper store
      # Then perform a Git operation that requires authentication
      

用法

  1. 启动服务器:
python -m github_mcp.server

服务器将于启动 http://localhost:8000 默认情况下。

  1. 配置游标IDE:
    • 打开光标IDE设置

    • 添加以下MCP服务器配置:

      {
        "mcp": {
          "servers": [
            {
              "name": "github-mcp",
              "url": "http://localhost:8000/sse"
            }
          ]
        }
      }
      

API终点

  • GET /:服务器信息和可用工具
  • POST /tool:同步工具调用
  • GET /sse:用于流式响应的服务器发送事件端点

可用工具

存储库工具

  • list_repositories:列出GitHub存储库
    • 参数:
      • visibility (可选):“全部”、“公共”或“私人”
      • sort (可选):“创建”、“更新”、“推送”或“full_name”
  • get_repository:获取存储库详细信息
    • 参数:
      • owner:存储库所有者
      • repo:存储库名称

问题工具

  • list_issues:列出存储库问题
    • 参数:
      • owner:存储库所有者
      • repo:存储库名称
      • state (可选):“打开”、“关闭”或“全部”
      • labels (可选):标签名称列表
  • create_issue:创建新问题
    • 参数:
      • owner:存储库所有者
      • repo:存储库名称
      • title:发行标题
      • body (可选):问题描述
      • labels (可选):标签名称列表
      • assignees (可选):受让人用户名列表

拉取请求工具

  • list_pull_requests:列出存储库拉取请求
    • 参数:
      • owner:存储库所有者
      • repo:存储库名称
      • state (可选):“打开”、“关闭”或“全部”
      • sort (可选):“创建”、“更新”、“流行度”或“长时间运行”
  • create_pull_request:创建新的pull请求
    • 参数:
      • owner:存储库所有者
      • repo:存储库名称
      • title:拉取请求标题
      • body (可选):拉取请求描述
      • head:源分支
      • base (可选):目标分支(默认:“main”)
      • draft (可选):创建为草稿(默认值:false)

内容工具

  • get_file_content:获取文件内容
    • 参数:
      • owner:存储库所有者
      • repo:存储库名称
      • path:文件路径
      • ref (可选):分支/标签/提交引用
  • list_directory:列出目录内容
    • 参数:
      • owner:存储库所有者
      • repo:存储库名称
      • path (可选):目录路径(默认:“”)
      • ref (可选):分支/标签/提交引用

发展

  1. 安装开发依赖项:
pip install -e ".[dev]"
  1. 运行测试:
pytest
  1. 运行linting:
ruff check .

许可证

此项目根据MIT许可证获得许可-有关详细信息,请参阅许可证文件。

贡献

  1. 分叉存储库
  2. 创建功能分支(git checkout -b feature/amazing-feature)
  3. 提交您的更改(git commit -m 'Add amazing feature')
  4. 推到分支(git push origin feature/amazing-feature)
  5. 打开拉取请求

致谢