AI Agent 自动审查 PR,发布行内评论,根据团队规范批准或请求修改。

适用场景

Engineering teams of 5+ developers who want to reduce review turnaround time and catch common issues before human review.

前提条件

Claude API access, MCP GitHub server, GitHub repo admin access, webhook hosting (n8n or server)

工作流图

用 MCP + GitHub 自动代码审查

Install MCP GitHub Server
Create Review Prompt Template
Webhook Integration
Post Review Comments
Feedback Loop

分步指南

  1. 1

    Install MCP GitHub Server

    Run: npx @modelcontextprotocol/server-github. Set GITHUB_TOKEN environment variable with repo:pull_request_write scope. Configure the server in Claude Desktop config.

  2. 2

    Create Review Prompt Template

    Write a system prompt that defines your review criteria: 1) Code style compliance, 2) Potential bugs, 3) Security issues (OWASP), 4) Performance concerns, 5) Test coverage. Be specific about your team's conventions.

  3. 3

    Webhook Integration

    Set up a GitHub webhook for pull_request events. Point it to a simple server (can be an n8n webhook) that triggers Claude with the PR details via MCP. The agent reads the diff, analyzes it, and prepares review comments.

  4. 4

    Post Review Comments

    The agent uses the MCP GitHub server to post inline comments on specific lines. For critical issues, it requests changes. For clean PRs, it approves. Add a summary comment with overall assessment and metrics.

  5. 5

    Feedback Loop

    Track which AI suggestions were accepted vs rejected by developers. Use this data to refine the review prompt. Set up a weekly report of AI review accuracy to continuously improve the agent.

标签

#mcp#github#code-review#automation#agent