Skip to main content

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 将自动:

  1. 调用 get-changelist-files-catalog 获取文件列表
  2. 根据 CL 类型(Shelved/Affected)调用 get-file-details 获取每个文件的差异
  3. 进行代码审查

发布

方式一:一键发布脚本

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-catalogget-file-details
  • 0.2.6 - 新增 skip_file_extensions 配置项,支持自定义跳过的文件扩展名
  • 0.2.5 - 新增 get-changelist-diff-native 工具,支持使用P4原生命令获取CL差异
  • 0.2.4 - 修复代码提交后,无法获取reviews中的差异信息的BUG

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_perforce-0.4.2.tar.gz (50.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_perforce-0.4.2-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file mcp_perforce-0.4.2.tar.gz.

File metadata

  • Download URL: mcp_perforce-0.4.2.tar.gz
  • Upload date:
  • Size: 50.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.13

File hashes

Hashes for mcp_perforce-0.4.2.tar.gz
Algorithm Hash digest
SHA256 5b50c417d272f8fdefffa662ee1ab5b52f7d69df8ab83a71174c0df55f20526f
MD5 0368067120611c193f9b71a354ab2fcb
BLAKE2b-256 41152a5f924f3090b2fc4c9585d6d584826c3a337f811505ebf469c278a236a9

See more details on using hashes here.

File details

Details for the file mcp_perforce-0.4.2-py3-none-any.whl.

File metadata

  • Download URL: mcp_perforce-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.13

File hashes

Hashes for mcp_perforce-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ef9299ecf98e053eba0fa0a5a6caacb45dff65a32081e0d33878bf3aa73da024
MD5 2d5d05834ea02e72dea2646a59e8cfeb
BLAKE2b-256 6794761c6aea2b51c245ac8ec274c2298e36f7b63725bdf0ccd352d154cb41a9

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.4.2 This release

2 files

0.4.1

2 files

0.4.0

2 files

0.3.0

2 files

0.2.6

2 files

0.2.5

2 files

0.2.4

2 files

0.2.3

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page