pr-agent-mcp
English | 中文
PR-Agent MCP Server
一个 MCP(模型上下文协议)服务器,将 pr-agent CLI 命令暴露为 MCP 工具,并可选集成 Gitea Webhook 以实现自动 PR 审查。支持 SSE 和 StreamableHTTP 传输协议,可在本地或 Docker 中运行。
功能特性
MCP 工具:将 pr-agent 命令(
review、describe、improve、ask、reflect、update_changelog、generate_labels)暴露为 MCP 工具。传输协议:SSE(
/sse)和 StreamableHTTP(/mcp),可通过--transport sse|streamable-http|both选择。Gitea Webhook:当 Gitea 中打开新 PR 时,自动触发 review、describe 和 improve 操作。
HMAC 签名验证:可选的 Webhook 签名验证,增强安全性。
配置注入:自动从
~/.secrets.toml加载凭据并注入到 pr-agent 子进程环境中。
Related MCP server: gitea-mcp
项目结构
pr-agent-mcp/
├── server.py # Main MCP server and webhook handler
├── run.ps1 # PowerShell startup script (local run)
├── requirements.txt # Python dependencies
├── Dockerfile # Multi-stage Docker image definition
├── docker-compose.yml # Docker Compose service definition
├── push.ps1 # Build & push image to registry
├── .dockerignore # Exclude files from Docker build context
├── buggy_samples.py # Intentional bug samples for pr-agent testing
├── test.http # HTTP test requests (VS Code REST Client / similar)
├── README.md
├── README.zh-CN.md
└── .gitignore前提条件
Docker 及 Docker Compose(推荐)或 Python 3.11+(使用
tomllib)Gitea 实例(用于 Webhook 集成,可选)
包含提供者凭据的
~/.secrets.toml文件(见下文)
配置凭据
在用户主目录下创建 ~/.secrets.toml,填入提供者和 LLM 凭据:
[gitea]
url = "http://your-gitea-instance:3000"
token = "your-gitea-personal-access-token"
[openai]
key = "sk-your-openai-api-key"环境变量
SECRETS_TOML_PATH可覆盖默认路径(~/.secrets.toml)。Docker 镜像使用该变量定位绑定的挂载文件。
Docker 部署(推荐)
1. 构建并在本地启动
docker compose up -d --build这将:
构建镜像(多阶段构建:将
pr-agent和mcp依赖安装到 venv 中,运行时安装git)。将主目录以只读方式挂载到容器的
/host-home,以便读取~/.secrets.toml。将主机端口
9000映射到容器端口9000。启动服务器,同时启用 SSE 和 StreamableHTTP 传输协议。
容器挂载的是
${USERPROFILE}(整个主目录),而非单个.secrets.toml文件。挂载不存在的宿主文件会导致 Docker 创建目录,从而引发IsADirectoryError错误——挂载父目录可避免此问题。
2. 推送镜像到私有仓库
# Build + tag + push to the default registry (10.10.11.194:1000/pr-agent-mcp:latest)
.\push.ps1
# Push to another registry / with a version tag / skip rebuild
.\push.ps1 -Registry "192.168.1.100:5000" -Tag "v1.0.0" -NoBuild3. 在其他机器上运行(例如测试服务器)
将 docker-compose.yml 复制到目标机器,将 build: . 改为 image: 10.10.11.194:1000/pr-agent-mcp:latest,然后:
docker pull 10.10.11.194:1000/pr-agent-mcp:latest
docker compose up -d或直接运行,无需 compose 文件:
docker run -d \
--name pr-agent-mcp \
-p 9000:9000 \
-v $env:USERPROFILE:/host-home:ro \
-e SECRETS_TOML_PATH=/host-home/.secrets.toml \
--restart unless-stopped \
10.10.11.194:1000/pr-agent-mcp:latest管理容器
# View logs
docker compose logs -f
# Stop & remove
docker compose down
# Restart
docker compose restart本地运行(不使用 Docker)
1. 安装依赖
python -m venv mcp_env
mcp_env\Scripts\activate
pip install -r requirements.txt
requirements.txt仅包含mcp(MCP 框架)。pr-agent 不是此服务器的 Python 依赖——它通过server.py中配置的路径(或环境变量PR_AGENT_EXE)作为子进程调用。请确保 pr-agent 已安装在机器上。
2. (可选)配置 Webhook 密钥
在 server.py 中设置 WEBHOOK_SECRET,使其与 Gitea Webhook 设置中配置的密钥一致。留空则禁用签名验证(生产环境不推荐)。
3. 启动服务器
.\run.ps1或直接运行:
python server.py
python server.py --transport sse # SSE only
python server.py --transport streamable-http # StreamableHTTP only端点
端点 | 方法 | 描述 |
| GET | 面向 AI 客户端的 MCP SSE 连接端点 |
| POST | MCP StreamableHTTP 端点 |
| POST | MCP 消息传输端点(SSE 模式) |
| POST | Gitea Webhook 接收器,用于自动 PR 审查 |
MCP 工具
工具 | 描述 |
| 审查 PR:总结和具体建议 |
| 生成或更新 PR 标题和描述 |
| 以 PR 评论形式建议代码改进 |
| 就 PR 提出问题 |
| 向 PR 作者提问关于 PR 的问题 |
| 根据 PR 内容更新变更日志 |
| 为 PR 生成标签 |
Gitea Webhook 配置
在 Gitea 仓库中,进入 设置 → Webhooks → 添加 Webhook。
将目标 URL 设置为
http://<your-server>:9000/webhook。设置 HTTP 方法为
POST,内容类型为application/json。可选地设置一个密钥(必须与
server.py中的WEBHOOK_SECRET一致)。选择 Pull Request 事件,动作为 Opened。
当 PR 被打开时,服务器将自动运行 review、describe 和 improve 操作,并将结果作为 PR 评论发布。
测试
使用附带的 test.http 文件(配合 VS Code REST Client 或类似 HTTP 客户端)手动测试 Webhook 端点。
buggy_samples.py 包含多个类别的故意错误(安全、逻辑、并发、错误处理),用于测试 pr-agent 的代码审查检测能力。
许可证
私有——仅供内部使用。
This server cannot be deployed
Maintenance
Related MCP Connectors
GitHub Copilot MCP: code, repo, PR, workflow tools for AI assistants.
AI-native git hosting — repos, PRs, issues, CI gates, and AI code review over MCP (60 tools).
MCP server for your apps' tools and custom tools, plus hosted AI agents and approval-gated workflows
A Model Context Protocol (MCP) application for automated GitHub PR analysis and issue management.…
Related MCP Servers
- FlicenseNot gradedqualityNot gradedmaintenanceA GitHub integration tool that enables MCP clients to manage pull requests through tools for creating, updating, and listing PRs with automated descriptions. It also includes a webhook server for real-time PR updates and a customizable CLI with distinct personality modes.-
- AlicenseAqualityAmaintenanceAn MCP server providing comprehensive Gitea API coverage with 186 tools for managing repositories, issues, pull requests, and CI/CD workflows. It enables autonomous AI agents to perform complex development and administrative tasks directly through a Gitea instance.7MIT
- AlicenseBqualityCmaintenanceMCP server that exposes GitHub operations as tools for AI agents, enabling code search, issue management, and PR review.12MIT
- AlicenseAqualityCmaintenanceProvides GitHub PR review capabilities to LLMs, enabling automated PR analysis, review submission, and inline commenting via MCP.1414 npm1MIT