Skip to main content
Glama

English | 中文

PR-Agent MCP Server

一个 MCP(模型上下文协议)服务器,将 pr-agent CLI 命令暴露为 MCP 工具,并可选集成 Gitea Webhook 以实现自动 PR 审查。支持 SSE 和 StreamableHTTP 传输协议,可在本地或 Docker 中运行。

功能特性

  • MCP 工具:将 pr-agent 命令(reviewdescribeimproveaskreflectupdate_changeloggenerate_labels)暴露为 MCP 工具。

  • 传输协议:SSE(/sse)和 StreamableHTTP(/mcp),可通过 --transport sse|streamable-http|both 选择。

  • Gitea Webhook:当 Gitea 中打开新 PR 时,自动触发 review、describe 和 improve 操作。

  • HMAC 签名验证:可选的 Webhook 签名验证,增强安全性。

  • 配置注入:自动从 ~/.secrets.toml 加载凭据并注入到 pr-agent 子进程环境中。

项目结构

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

这将:

  1. 构建镜像(多阶段构建:将 pr-agentmcp 依赖安装到 venv 中,运行时安装 git)。

  2. 将主目录以只读方式挂载到容器的 /host-home,以便读取 ~/.secrets.toml

  3. 将主机端口 9000 映射到容器端口 9000

  4. 启动服务器,同时启用 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" -NoBuild

3. 在其他机器上运行(例如测试服务器)

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

端点

端点

方法

描述

/sse

GET

面向 AI 客户端的 MCP SSE 连接端点

/mcp

POST

MCP StreamableHTTP 端点

/messages/

POST

MCP 消息传输端点(SSE 模式)

/webhook

POST

Gitea Webhook 接收器,用于自动 PR 审查

MCP 工具

工具

描述

review_pr

审查 PR:总结和具体建议

describe_pr

生成或更新 PR 标题和描述

improve_code

以 PR 评论形式建议代码改进

ask_question

就 PR 提出问题

reflect

向 PR 作者提问关于 PR 的问题

update_changelog

根据 PR 内容更新变更日志

generate_labels

为 PR 生成标签

Gitea Webhook 配置

  1. 在 Gitea 仓库中,进入 设置 → Webhooks → 添加 Webhook

  2. 将目标 URL 设置为 http://<your-server>:9000/webhook

  3. 设置 HTTP 方法为 POST,内容类型为 application/json

  4. 可选地设置一个密钥(必须与 server.py 中的 WEBHOOK_SECRET 一致)。

  5. 选择 Pull Request 事件,动作为 Opened

当 PR 被打开时,服务器将自动运行 reviewdescribeimprove 操作,并将结果作为 PR 评论发布。

测试

使用附带的 test.http 文件(配合 VS Code REST Client 或类似 HTTP 客户端)手动测试 Webhook 端点。

buggy_samples.py 包含多个类别的故意错误(安全、逻辑、并发、错误处理),用于测试 pr-agent 的代码审查检测能力。

许可证

私有——仅供内部使用。

-
license - not tested
-
quality - not tested
B
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/kkmeteor/pr-agent-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server