Back to MCP directory
publicPublicdnsLocal runtime

github-pr-mcp

GitHub PR评论MCP服务器,通过GitHub API获取拉取请求的评论数据。

article

README

🚀 GitHub PR 评论 MCP 服务器

这是一个使用 GitHub 私人访问令牌获取 GitHub 拉取请求评论的模型上下文协议(MCP)服务器,能帮助用户方便地获取 PR 评论信息,以结构化的 JSON 格式呈现,便于后续处理和使用。

🚀 快速开始

安装

本服务器提供了自动和手动两种安装方式,你可以根据自己的需求进行选择。

使用

安装完成后,按照步骤构建项目、运行服务器,即可使用 get_pr_comments 工具获取 PR 评论。

✨ 主要特性

  • 获取详细评论:获取包含文件路径、行范围和回复的 PR 评论。
  • 调用 GitHub API:使用 Octokit 调用 GitHub API。
  • 实现 MCP 服务器:使用 StdioServerTransport 实现 MCP 服务器。
  • 结构化输出:返回结构化的 JSON 格式评论。

📦 安装指南

使用 Smithery 自动安装

要通过 Smithery 自动为 Claude Desktop 安装 github - pr - mcp,可执行以下命令:

npx -y @smithery/cli install github-pr-mcp --client claude

手动安装

  1. 克隆仓库。
  2. 安装依赖项:
    npm install
    
  3. 创建一个包含 GitHub 令牌的 .env 文件:
    GITHUB_TOKEN=your_github_token_here
    

💻 使用示例

基础用法

  1. 构建项目:
    npm run build
    
  2. 运行服务器:
    npm start
    

或直接使用 GitHub 令牌运行:

node dist/server.js your_github_token_here
  1. 服务器提供了一个名为 get_pr_comments 的工具,接受以下参数:
    • owner: 仓库所有者(用户名或组织)
    • repo: 仓库名称
    • pull_number: 拉取请求编号

与 Cursor 集成

要将此服务器集成到 Cursor,请在 Cursor 的 MCP 服务器配置中使用以下命令:

node /path/to/dist/server.js your_github_token_here

请将 /path/to 替换为实际项目路径,并将 your_github_token_here 替换为你的 GitHub 个人访问令牌。

测试

包含一个测试客户端来验证服务器功能:

  1. 构建项目:
    npm run build
    
  2. 运行测试客户端:
    npm test
    

测试客户端将启动服务器,连接到它,并调用 get_pr_comments 工具,使用示例参数。

📚 详细文档

响应格式

服务器返回以下 JSON 格式评论:

{
  "comments": [
    {
      "id": 123456789,
      "path": "src/example.js",
      "body": "This is a comment on a specific line",
      "line": 42,
      "start_line": 40,
      "user": {
        "login": "username"
      },
      "created_at": "2023-01-01T00:00:00Z",
      "replies": [
        {
          "id": 987654321,
          "body": "This is a reply to the comment",
          "user": {
            "login": "another-username"
          },
          "created_at": "2023-01-02T00:00:00Z"
        }
      ]
    }
  ]
}

开发

以开发模式运行服务器:

npm run dev

📄 许可证

本项目采用 ISC 许可证。

help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client