MCP Perforce
Perforce 的模型上下文协议 (MCP) 服务器实现,支持通过 P4 原生命令获取变更列表信息和文件差异。
功能概述
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) |
| base_revision | integer | 否 | 基准版本号 (用于头尾对比; 不传则自动通过 filelog 推导) |
diff 策略:
- Shelved (is_shelved=true):使用
p4 diff2 file file@=<CL>比较未提交的变更 - Affected (is_shelved=false):使用
p4 diff2 file#(base_rev) 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获取每个文件的差异 - 进行代码审查
发布
方式一:一键发布脚本
WSL/Linux/macOS:
chmod +x publish.sh
./publish.sh
方式二:手动发布
rm .venv -rf
rm dist -rf
uv sync
uv pip install twine
uv build
uv run twine upload ./dist/*
更新记录
- 0.4.2 - 升级到 MCP Python SDK 2.0,适配低层 Server API 与工具参数校验,并清理发布脚本中的硬编码凭据
- 0.4.1 - 迁移为独立项目,项目结构优化
- 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
Metadata
Release files for mcp-perforce 0.4.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mcp_perforce-0.4.2.tar.gz | 50.4 kB | Without provenance | Details for mcp_perforce-0.4.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mcp_perforce-0.4.2-py3-none-any.whl | Python 3 | none | any | Details for mcp_perforce-0.4.2-py3-none-any.whl |
Total release size: 60.2 kB
Release files / mcp_perforce-0.4.2.tar.gz
| Download URL | mcp_perforce-0.4.2.tar.gz |
|---|---|
| Size | 50.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5b50c417d272f8fdefffa662ee1ab5b52f7d69df8ab83a71174c0df55f20526f
|
|
BLAKE2b-256 checksum How to use checksums |
41152a5f924f3090b2fc4c9585d6d584826c3a337f811505ebf469c278a236a9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.13
|
Release files / mcp_perforce-0.4.2-py3-none-any.whl
| Download URL | mcp_perforce-0.4.2-py3-none-any.whl |
|---|---|
| Size | 9.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ef9299ecf98e053eba0fa0a5a6caacb45dff65a32081e0d33878bf3aa73da024
|
|
BLAKE2b-256 checksum How to use checksums |
6794761c6aea2b51c245ac8ec274c2298e36f7b63725bdf0ccd352d154cb41a9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.13
|
Security for mcp-perforce 0.4.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.