Token导航 LogoToken导航TokenDH.com
GitHub MCP PR Reviewer logo
开发工具stdio官方级别未说明来源级核验

GitHub MCP PR Reviewer

MCP Server

一个为Go仓库提供自动化代码审查功能的MCP服务器,支持静态分析、测试执行和GitHub PR评论。

工具数

5

提示词数

0

GitHub Stars

7

资源数

0
代码审查静态分析PythonClaude自动化测试Claude DesktopClaude

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

Ankushryuga

提供方

Ankushryuga

最后核验

2026/5/17 20:20

运行时

Python

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

命令预览

python -m venv venv

详细介绍

GitHub公关审查员MCP服务器

一个MCP(模型上下文协议)服务器,为Go存储库提供自动代码审查功能。此服务器使Claude能够分析pull请求、运行测试、执行静态分析以及将评论发布到GitHub。

特性

  • 🔍 静态代码分析:在go代码上运行golangci-lint、gofmt和go-vet
  • 自动化测试:使用覆盖率分析执行Go测试
  • 📊 PR差异分析:获取并分析GitHub PR更改
  • 💬 评审意见:自动将评论反馈发布到GitHub
  • 🤖 全面审查:端到端PR审查工作流程编排

建筑

┌─────────────────┐
│                 │
│  Claude.ai /    │
│  Claude Desktop │
│                 │
└────────┬────────┘
         │ MCP Protocol
         │
┌────────▼────────────────────────────┐
│  GitHub PR Reviewer MCP Server      │
│                                     │
│  Tools:                             │
│  • github_pr_analyze_code           │
│  • github_pr_run_tests              │
│  • github_pr_get_diff               │
│  • github_pr_post_review            │
│  • github_pr_comprehensive_review   │
└────────┬────────────────────────────┘
         │
         ├──────────────┬──────────────┐
         │              │              │
    ┌────▼───┐    ┌────▼────┐    ┌───▼─────┐
    │ GitHub │    │  Local  │    │   Go    │
    │  API   │    │  Files  │    │  Tools  │
    └────────┘    └─────────┘    └─────────┘

先决条件

系统要求

  • Python 3.10或更高版本
  • Go 1.20或更高(用于Go项目分析)
  • Git

Go工具安装

安装所需的Go分析工具:

# Install golangci-lint
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest

# Ensure Go tools are in PATH
export PATH=$PATH:$(go env GOPATH)/bin

GitHub身份验证

您需要一个具有以下权限的GitHub个人访问令牌:

  • repo (用于私有存储库)
  • pull_requests:write (用于发表评论)

在以下位置创建令牌:https://github.com/settings/tokens

安装

1.克隆存储库

git clone https://github.com/yourusername/github-pr-reviewer-mcp.git
cd github-pr-reviewer-mcp

2.安装Python依赖项

# Create a virtual environment (recommended)
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

3.设置环境变量

# Set your GitHub token
export GITHUB_TOKEN="ghp_your_token_here"

对于持久配置,请添加 ~/.bashrc~/.zshrc:

echo 'export GITHUB_TOKEN="ghp_your_token_here"' >> ~/.bashrc
source ~/.bashrc

4.配置克劳德桌面

将服务器添加到Claude Desktop配置文件中:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json 视窗: %APPDATA%\Claude\claude_desktop_config.json Linux: ~/.config/Claude/claude_desktop_config.json

{
  "mcpServers": {
    "github-pr-reviewer": {
      "command": "python",
      "args": ["/absolute/path/to/github-pr-reviewer-mcp/github_pr_mcp.py"],
      "env": {
        "GITHUB_TOKEN": "ghp_your_token_here"
      }
    }
  }
}

替换 /absolute/path/to/github-pr-reviewer-mcp/ 与实际路径。

5.重新启动克劳德桌面

更新配置后,重新启动Claude Desktop以使更改生效。

用法

可用工具

1. github_pr_analyze_code

使用静态分析工具分析Go代码的质量问题。

参数:

  • file_path (string):Go文件或目录的路径
  • analysis_type (string):“lint”、“fmt”、“vet”或“all”
  • response_format (string):“markdown”或“json”

例子:

Can you analyze the code in /path/to/myproject/main.go?

2. github_pr_run_tests

运行带有可选覆盖率分析的Go测试。

参数:

  • package_path (string):转到包路径(默认:“./…”)
  • verbose (bool):启用详细输出
  • coverage (bool):生成覆盖率报告
  • response_format (string):“markdown”或“json”

例子:

Run tests on my Go project at /path/to/myproject with coverage

3. github_pr_get_diff

获取GitHub pull请求的差异。

参数:

  • owner (string):存储库所有者
  • repo (string):存储库名称
  • pr_number (int):拉取请求号
  • response_format (string):“markdown”或“json”

例子:

Show me the diff for PR #123 in owner/repo

4. github_pr_post_review

在GitHub pull请求中发布评论。

参数:

  • owner (string):存储库所有者
  • repo (string):存储库名称
  • pr_number (int):拉取请求号
  • body (string):审阅评论文本
  • event (string):“评论”、“批准”或“请求范围”
  • commit_id (字符串,可选):具体提交审核

例子:

Post a review comment to PR #123 in owner/repo saying "LGTM! Great work on the refactoring."

5. github_pr_comprehensive_review

对GitHub pull请求进行全面的自动审查。

参数:

  • owner (string):存储库所有者
  • repo (string):存储库名称
  • pr_number (int):拉取请求号
  • local_path (字符串,可选):克隆存储库的本地路径
  • run_tests (bool):是否运行测试
  • post_comments (bool):自动将评论发布到GitHub
  • response_format (string):“markdown”或“json”

例子:

Review PR #456 in myorg/myrepo. The local clone is at /home/user/myrepo. Run tests and post the review.

示例工作流

工作流程1:快速静态分析

User: Analyze the Go code in my-project/handlers/api.go

Claude will:
1. Use github_pr_analyze_code tool
2. Run golangci-lint, gofmt, and go vet
3. Return formatted results with any issues found

工作流程2:测试本地更改

User: Run tests on my Go project at /home/user/awesome-app with coverage

Claude will:
1. Use github_pr_run_tests tool
2. Execute tests with coverage
3. Return test results and coverage percentages

工作流程3:审查GitHub PR

User: Review PR #42 in acme/rocket-engine. Local copy is at /home/user/rocket-engine.

Claude will:
1. Use github_pr_get_diff to fetch PR changes
2. Identify changed Go files
3. Use github_pr_analyze_code on each changed file
4. Use github_pr_run_tests to run the test suite
5. Generate comprehensive review summary
6. Optionally post review to GitHub (if requested)

工作流程4:完成自动审核

User: Do a full automated review of PR #789 in myorg/backend-api, local path is /projects/backend-api, and post the results.

Claude will:
1. Use github_pr_comprehensive_review tool
2. Fetch PR diff
3. Analyze all changed Go files
4. Run full test suite
5. Generate review with recommendations
6. Post review comment to GitHub PR

配置

环境变量

变量必填描述
GITHUB_TOKENGitHub个人访问令牌

工具特定设置

您可以通过修改MCP服务器代码来自定义分析行为:

# In github_pr_mcp.py

# Change default golangci-lint settings
lint_result = _run_command(
    ["golangci-lint", "run", "--config", ".golangci.yml", str(file_path)]
)

# Adjust test timeout
result = subprocess.run(
    cmd,
    timeout=600  # 10 minutes instead of 5
)

故障排除

问题:“未设置GITHUB_TOKEN环境变量”

解决方案: 确保在Claude Desktop配置中设置了令牌:

{
  "mcpServers": {
    "github-pr-reviewer": {
      "env": {
        "GITHUB_TOKEN": "ghp_your_actual_token"
      }
    }
  }
}

问题:“golangci-lint:找不到命令”

解决方案: 安装golangci lint并确保它在PATH中:

go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
export PATH=$PATH:$(go env GOPATH)/bin

问题:MCP服务器未出现在Claude Desktop中

解决方案:

  1. 验证配置文件路径是否适用于您的操作系统
  2. 检查JSON语法(使用JSON验证器)
  3. 确保Python脚本路径是绝对的
  4. 完全重新启动克劳德桌面
  5. 检查Claude Desktop日志是否有错误

问题:测试失败,“包中没有Go文件”

解决方案: 确保从正确的目录运行测试:

  • local_path 存储库根的参数
  • 检查测试文件是否存在并具有 _test.go 后缀

发展

运行测试

# Run Python tests
python -m pytest tests/

# Test MCP server directly
python github_pr_mcp.py

添加新工具

要添加新的分析工具,请执行以下操作:

  1. 定义Pydantic输入模型
  2. 为操作创建辅助函数
  3. 添加一个 @mcp.tool 装饰功能
  4. 更新文档

例子:

class NewToolInput(BaseModel):
    param: str = Field(..., description="Parameter description")

@mcp.tool(name="github_pr_new_tool")
async def new_tool(params: NewToolInput) -> str:
    """Tool description."""
    # Implementation
    pass

代码的风格

该项目如下:

  • Python代码的PEP 8
  • 为所有函数键入提示
  • 用于输入验证的Pydantic模型
  • 全面的文档字符串

安全最佳实践

  1. 从不提交代币:保持 GITHUB_TOKEN 仅在环境变量中
  2. 使用最小权限:仅授予必要的GitHub令牌范围
  3. 验证输入:所有输入均通过Pydantic模型进行验证
  4. 限制文件访问:服务器仅读取/写入指定目录
  5. 超时操作:所有命令都有合理的超时

贡献

欢迎投稿!拜托:

  1. 分叉存储库
  2. 创建要素分支
  3. 添加新功能的测试
  4. 确保代码通过linting
  5. 提交拉取请求

许可证

MIT许可证-有关详细信息,请参阅许可证文件

支持

对于问题和疑问:

  • GitHub问题:https://github.com/yourusername/github-pr-reviewer-mcp/issues
  • MCP文件:https://modelcontextprotocol.io/
  • 人类不和:https://discord.gg/anthropic

更新日志

v1.0.0(2025-02-07)

  • 初始版本
  • 静态代码分析支持(golangci-lint、gofmt、go-vet)
  • 覆盖范围内的测试执行
  • GitHub公关集成
  • 全面审查工作流程

目录标签

目录标签

代码审查静态分析PythonClaude自动化测试本地部署GitHub集成Go语言

支持客户端

Claude DesktopClaude

接入字段

传输方式(transport,传输协议)

stdio

鉴权方式(authType,认证方式)

token

运行时(runtime,运行环境)

Python

工具数量(toolCount,工具数)

5

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

stdiotoken部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

来源信息

继续浏览同类 MCP