MCP server for Perforce code review - supports P4 native commands
Project description
MCP Perforce 服务器
Perforce 的模型上下文协议 (MCP) 服务器实现,支持通过 P4 原生命令获取变更列表信息和文件差异。
功能概述
MCP Perforce 服务器提供以下工具:
1. get-changelist-files-catalog
获取变更列表中的文件目录,自动检测 CL 类型(Shelved/Affected)。
参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| changelist_id | integer | 是 | Perforce 变更列表 ID (CL号) |
返回:
- CL 类型(Shelved 未提交 / Affected 已提交)
- CL 描述信息
- 受影响的文件列表(已过滤二进制文件和配置的跳过扩展名)
2. get-file-details
获取变更列表中指定文件的详细差异信息。
参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| action | string | 是 | 文件操作类型 (add/edit/delete/integrate/branch) |
| file_path | string | 是 | depot 文件路径 |
| revision | integer | 是 | 文件版本号 |
| changelist_id | integer | 是 | Perforce 变更列表 ID (CL号) |
| is_shelved | boolean | 是 | 是否是 Shelved CL (未提交为 true,已提交为 false) |
diff 策略:
- Shelved (is_shelved=true):使用
p4 diff2 file file@=<CL>比较未提交的变更 - Affected (is_shelved=false):使用
p4 diff2 file#(rev-1) file#rev比较已提交的变更
配置说明
Cursor MCP 配置
{
"mcpServers": {
"p4-review-dev": {
"command": "uvx",
"args": [
"mcp-perforce",
"--p4config",
"./path/to/your/p4config.json"
]
}
}
}
p4config.json 配置
{
"skip_file_extensions": [".pb.go", ".cs"]
}
配置项说明
| 配置项 | 必填 | 说明 |
|---|---|---|
| skip_file_extensions | 否 | 需要跳过的文件扩展名列表,默认为 [".pb.go", ".cs"] |
编码自适应
服务器启动时会自动通过 p4 set 命令检测 P4CHARSET 配置,并使用对应的编码读取 P4 命令输出:
| P4CHARSET | Python 编码 |
|---|---|
| cp936 | gbk (简体中文) |
| utf8 / utf-8 | utf-8 |
| eucjp | euc-jp (日文) |
| shiftjis | shift_jis (日文) |
| winansi | cp1252 |
| 其他/未设置 | utf-8 (默认) |
使用说明
在 Cursor Agent 模式中输入:
帮我 review 一下 3280706
Cursor 将自动:
- 调用
get-changelist-files-catalog获取文件列表 - 根据 CL 类型(Shelved/Affected)调用
get-file-details获取每个文件的差异 - 进行代码审查
更新记录
- 0.3.0 - 重大重构
- 移除 Swarm API 依赖,完全使用 P4 原生命令
- 支持 Shelved (未提交) 和 Affected (已提交) 两种 CL 类型
- 新增
is_shelved参数,根据 CL 类型使用不同的 diff 策略 - 新增编码自适应功能,自动检测 P4CHARSET 配置
- 移除
get-changelist-diff-native工具,功能已合并到get-changelist-files-catalog和get-file-details
- 0.2.6 - 新增
skip_file_extensions配置项,支持自定义跳过的文件扩展名 - 0.2.5 - 新增
get-changelist-diff-native工具,支持使用 P4 原生命令获取 CL 差异 - 0.2.4 - 修复代码提交后,无法获取 reviews 中的差异信息的 BUG
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mcp_perforce-0.3.0.tar.gz.
File metadata
- Download URL: mcp_perforce-0.3.0.tar.gz
- Upload date:
- Size: 15.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15ff8369409139ff5fd0824340427d4567595ac4faff982dbf804013ff8dbdec
|
|
| MD5 |
5aa24d246f9030d60c8428214e7ae954
|
|
| BLAKE2b-256 |
42a805350d757ff79c934e26d09dd4cd82278969abc08427a106625baef11941
|
File details
Details for the file mcp_perforce-0.3.0-py3-none-any.whl.
File metadata
- Download URL: mcp_perforce-0.3.0-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
63198afd42a4437c681c4c2d79112ee1e5b3e270d96a17165a90d87007d22fb1
|
|
| MD5 |
a6ca3a843f6a66c3daa1a1a976c5bf74
|
|
| BLAKE2b-256 |
f6b40d6f2cc25b092dc3a7824d1a8e8a08a8f355bfef2f9e23283085c8f06d65
|