
perforce/p4mcp-server
Analytics & monitoringPerforce P4 MCP Server is a Model Context Protocol (MCP) server that integrates with the Perforce P4 version control system.
Обзор
Perforce P4 MCP Server is a Model Context Protocol (MCP) server that integrates with the Perforce P4 version control system.
README
Features
- Comprehensive P4 integration: Read/write tools across files, changelists, shelves, workspaces, jobs, reviews, streams, and server information.
- Code review workflows: P4 Code Review support for review discovery, voting, state transitions, commenting, and participant management.
- Safety first: Read-only mode by default, ownership checks, interactive MCP elicitation (PROCEED/CANCEL) for destructive delete and obliterate operations.
- Flexible toolsets: Configure which tool categories to enable: server, files, changelists, shelves, workspaces, jobs, reviews, and streams.
- Robust logging: Application and session logging to the
logs/directory. - Optional telemetry: Consent-gated usage statistics. Disabled by default.
- Cross platform: Supported on macOS, Linux and Windows with pre-built binaries.
Prerequisites
- P4 Server access: Connection to a P4 Server with proper credentials
- Authentication: Valid P4 login (ticket-based or password)
System Requirements
| Component | Supported Versions |
|---|---|
| Operating Systems | Windows 10+macOS 12+Linux (glibc 2.34+, e.g. Ubuntu 22.04+, Rocky Linux 9+) |
| Perforce P4 Server | 2026.1 (earlier versions untested) |
| Python | 3.11+ (required only for building from source) |
Local P4 MCP Server Installation
Deployment
STDIO-based deployment
Configure MCP Client
Add the following to your mcp.json:
{
"servers": {
"perforce-p4mcp-docker": {
"command": "docker",
"args": [
"run", "-i", "--rm",
"--hostname", "your-hostname",
"-e", "P4PORT=ssl:perforce.example.com:1666",
"-e", "P4USER=your_username",
"-e", "P4CLIENT=your_workspace",
"-v", "/Users/your_username/.p4tickets:/home/mcpuser/.p4tickets:ro",
"ghcr.io/perforce/p4mcp-server:latest"
]
}
}
}
Configuration Options
| Flag | Description |
|---|---|
-i |
Interactive mode (required for STDIO) |
--rm |
Remove container when stopped |
--hostname |
Match workspace host restriction |
-e P4PORT |
P4 server address |
-e P4USER |
P4 username |
-e P4CLIENT |
Workspace name |
-v |
Mount P4 tickets file |
Authentication
Using P4 tickets:
# macOS/Linux
-v /Users/your_username/.p4tickets:/home/mcpuser/.p4tickets:ro
Note: Use the full path to your tickets file (not
~). After runningp4 login, restart the MCP server to pick up the new ticket.
Using a password:
-e P4PASSWD="your_password"
Workspace Host Restrictions
⚠️ Important: Docker containers have their own hostname, which differs from your local machine. If your P4 workspace is restricted to a specific host, operations like
syncwill fail.
To resolve this, set the container hostname to match your workspace’s host restriction:
--hostname your-hostname
To find your workspace host name:
# macOS/Linux
p4 client -o your_workspace | grep "^Host:"
Mounting Client Root for Write Operations
⚠️ Important: By default, the Docker container cannot access your local workspace files. For write operations like
sync,submit, orreconcile, you must mount your client root directory into the container at the same path.
Add a volume mount for your client root:
-v /path/to/your/client/root:/path/to/your/client/root
Example configuration with client root mounted:
{
"servers": {
"perforce-p4mcp-docker": {
"command": "docker",
"args": [
"run", "-i", "--rm",
"--hostname", "your-hostname",
"-e", "P4PORT=ssl:perforce.example.com:1666",
"-e", "P4USER=your_username",
"-e", "P4CLIENT=your_workspace",
"-v", "/Users/your_username/.p4tickets:/home/mcpuser/.p4tickets",
"-v", "/path/to/client/root:/path/to/client/root",
"ghcr.io/perforce/p4mcp-server:latest"
]
}
}
}
To find your client root:
p4 client -o your_workspace | grep "^Root:"
Note: The mount path inside the container must match the client root path exactly, as P4 tracks files by their absolute paths.
HTTP-based deployment
MCP client configuration
Note: In all configuration examples below, if
P4CONFIGis set, you do not need to set any environment variables in theenvblock. The server will use the configuration from the specified P4CONFIG file instead.
Tip: If you have uv installed, you can use
uvx p4mcp-serverinstead of/absolute/path/to/p4-mcp-serverin thecommandfield. This eliminates the need to download or build binaries manually.
P4 Environment Variables
P4PORT- P4 Server address. Examples:ssl:perforce.example.com:1666,localhost:1666P4USER- Your P4 usernameP4CLIENT- Your current P4 workspace. Optional, but recommended
Result limit environment variables
P4MCP_MAX_RESULTS- Cap on the number of rows the P4 server returns per command (p4.maxresults). Default:10000. Set to0to disable the limit (server default in effect). When a command would exceed this limit the server aborts it with an error rather than truncating results, so keep the value generous. Can be overridden by the--max-resultsCLI argument. Must be a non-negative integer; an invalid value fails fast at startup before any P4 connection is attempted.P4MCP_MAX_SCAN_ROWS- Cap on the number of rows the P4 server scans per command (p4.maxscanrows). Unset by default, so admin/group policy governs scan limits. Can be overridden by the--max-scan-rowsCLI argument. Must be a non-negative integer when supplied.
Logging environment variables
P4MCP_LOG_DIR- Directory for log files. Default:logs/in the server executable’s directory. Can be overridden by the--log-dirCLI argument.
SSL/TLS environment variables
P4MCP_TLS_CA_MODE- TLS certificate source mode.system(default): use OS trust store viatruststore. Note: In this mode,truststoreoverrides theverify=parameter — custom CA bundles set viaP4MCP_CA_BUNDLEor--ca-bundleare ignored. To use a custom CA bundle, setP4MCP_TLS_CA_MODE=certifi.certifi: disabletruststoreinjection and use default Python TLS certificate behavior. Custom CA bundles (P4MCP_CA_BUNDLE/--ca-bundle) take effect only in this mode.
P4MCP_SSL_VERIFY- Set tofalseto disable SSL verification for P4 Code Review API requests. Default:true. Works in both TLS modes.P4MCP_CA_BUNDLE- Path to a custom CA certificate bundle (PEM) for P4 Code Review API requests. Takes priority overP4MCP_SSL_VERIFY. RequiresP4MCP_TLS_CA_MODE=certifito take effect.
Telemetry environment variables
OTEL_EXPORTER_OTLP_ENDPOINT- OTLP collector endpoint for telemetry export. Default:https://grpc.public.prd.shared.perforce.com.OTEL_EXPORTER_OTLP_PROTOCOL- OTLP export protocol. Onlygrpcis supported; other values fall back togrpcwith a warning.
Supported arguments
-
--readonly- Control write operations.- If present, uses read-only mode. Safe for exploration and testing.
- If missing, enables write operations. Requires proper permissions on your P4 Server.
-
--allow-usage- Allow usage statistics.- If present, allows anonymous usage statistics collection.
- If missing, disables all usage statistics.
-
--toolsets- Specify which tool categories to enable.- Available:
files,changelists,shelves,workspaces,jobs,reviews,streams - Default: All toolsets enabled.
query_serveris always available regardless of the--toolsetssetting.
- Available:
-
--search-transform- Enable search-based tool discovery to reduce token overhead.regex— Expose a regex pattern-matching search tool. Best for targeted lookups.bm25— Expose a natural-language relevance-ranked search tool. Best for exploratory queries.both— Expose both search tools with distinct names (regex_search_tools/regex_call_toolandsemantic_search_tools/semantic_call_tool).- If omitted, the full tool catalog is sent to the client (default, backward-compatible).
- When enabled,
query_serveris always directly visible to the client. - Security: Admin permission checks (
CheckPermissionMiddleware) and--readonlyfiltering remain fully enforced. Search transforms query the real tool catalog internally, so tools blocked by middleware or excluded by read-only mode are never discoverable or callable through the search interface.
-
--max-results- Cap on the number of rows the P4 server returns per command (p4.maxresults).- Default:
10000. Set to0to disable the limit (server default in effect). - Protects against runaway AI-driven queries exhausting local memory or overwhelming the server.
- When a command would exceed this limit the server aborts it with an error — it does not truncate — so keep the value generous.
- Must be a non-negative integer; an invalid value fails fast at startup before any P4 connection is attempted.
Priority order:
--max-results>P4MCP_MAX_RESULTS> default (10000). - Default:
-
--max-scan-rows- Cap on the number of rows the P4 server scans per command (p4.maxscanrows).- Unset by default, so admin/group policy governs scan limits.
- Must be a non-negative integer when supplied; an invalid value fails fast at startup.
Priority order:
--max-scan-rows>P4MCP_MAX_SCAN_ROWS> default (unset). -
--ssl-no-verify- Disable SSL certificate verification for P4 Code Review API requests.- Useful for environments with self-signed or internal CA certificates.
- Works in both
systemandcertifiTLS modes. - These SSL options only affect HTTPS Swarm connections. If the Swarm URL is
http://, they have no effect.
-
--ca-bundle- Path to a custom CA certificate bundle (PEM) for P4 Code Review API requests.- Use this to trust an internal CA without disabling verification entirely.
- Requires
P4MCP_TLS_CA_MODE=certifito take effect. In the defaultsystemmode,truststoreuses the OS trust store and ignores this setting. - If both
--ca-bundleand--ssl-no-verifyare provided,--ca-bundletakes priority (verification is performed using the specified bundle).
Priority order:
--ca-bundle>--ssl-no-verify>P4MCP_CA_BUNDLE>P4MCP_SSL_VERIFY> default (true). CLI args take priority over environment variables. -
--log-dir- Directory for log files.- Specify a custom directory for log files (both application and session logs).
- Default:
logs/in the server executable’s directory. - Can also be set via
P4MCP_LOG_DIRenvironment variable. - CLI argument takes priority over environment variable.
Priority order:
--log-dir>P4MCP_LOG_DIR> default (logs/in the server executable’s directory).
Required configurations
- Use absolute paths for the
commandfield in all configurations. - Ensure environment variables are properly set for each host.
- Different hosts may have different argument parsing. Refer to the host’s documentation.
P4 configuration
User configuration
Example setup
# Windows (PowerShell)
$env:P4PORT = "ssl:perforce.example.com:1666"
$env:P4USER = "your_username"
$env:P4CLIENT = "your_workspace"
# macOS/Linux (Bash)
export P4PORT="ssl:perforce.example.com:1666"
export P4USER="your_username"
export P4CLIENT="your_workspace"
P4USERmust be a standard user. P4 MCP Server runs commands such asp4 describeandp4 changesthat aservice-type user is not permitted to run, so a service user will cause tools to fail at runtime. ConfigureP4USERwith a Perforce user of typestandard. Seep4 userin the P4 CLI documentation.
Connection-limit options
These options bound how much work a single P4 command can do, protecting the server against runaway queries:
max_results— Caps how many rows the P4 server returns per command. On by default with a generous value to protect against runaway queries. Lower the value to tighten the bound. Configured viaP4MCP_MAX_RESULTSor--max-results.max_scan_rows— Caps how many rows the server scans per command. Unset by default (governed by admin/group policy). Configured viaP4MCP_MAX_SCAN_ROWSor--max-scan-rows.
Admin configuration
Manage access through group-level and user-level server properties. P4 resolves each property to a single value using two rules, applied in order:
- Highest sequence number wins. The
-sflag is the primary sort key. It applies across all scopes — a group property at-s5beats a user property at-s1or default. - At the same sequence number, scope is the tiebreaker: user > group > global. Between groups at the same sequence, the alphabetically-first group name wins.
P4 does not compare values semantically. It does not know that false is more restrictive than true. The winning property’s value is returned as-is and checked by the MCP server.
If no property applies, MCP remains enabled unless explicitly disabled.
Master switch (global disable)
To disable MCP for all users:
p4 property -a -n mcp.enabled -v false
To re-enable group/user-based control, delete the global property first:
p4 property -d -n mcp.enabled
How properties are resolved
The MCP server checks properties in this order. Each property is resolved independently by P4 using the standard resolution rules (highest -s wins, then user > group > global at equal sequence, then alphabetically-first group name).
| Check order | Property | MCP server behavior |
|---|---|---|
| 1 | mcp.enabled |
If resolved value is false, block all access |
| 2 | mcp.toolsets.write |
If resolved value is false and tool is a write operation, block |
| 3 | mcp.toolsets.allowed |
If set, only listed toolsets are available |
| 4 | mcp.toolset..enabled |
If resolved value is false, block the toolset |
| 5 | mcp.toolset..write |
If resolved value is false and tool is a write operation, block |
| 6 | mcp.toolset..tools |
If set, only listed tools within the toolset are available |
Important notes
-
Each property is resolved to a single value by P4 before the MCP server sees it. P4 uses: highest sequence number (
-s) first, then scope (user > group > global) as a tiebreaker, then alphabetical group name. The MCP server does not perform its own multi-group or multi-scope resolution. -
mcp.enabledacts as the main switch. When its resolved value isfalse, all access is blocked. -
At the same sequence number, a group or user property overrides a global property. To ensure a global
falsecannot be overridden, assign it a high-svalue. -
Scope hierarchy (user > group > global) only applies as a tiebreaker at equal sequence numbers. A group property at
-s5will beat a user property at default sequence or-s1. -
When a user belongs to multiple groups, the alphabetically-first group name wins (at equal
-s). The winning value is used as-is — P4 does not comparetruevsfalseor pick the “most restrictive” value. Use explicit-svalues to control which group takes priority. -
Tool-specific overrides (
mcp.toolset..tools) can further restrict access but cannot bypass write restrictions. Write checks are evaluated before tool lists. -
Property changes take effect within 60 seconds due to server-side caching, or immediately on a new MCP server connection.
-
Only the value
false(case-insensitive) disables or blocks access. Any other value (includingtrue,1,yes, or invalid strings) is treated as not blocking.
Available tools
Query tools (read operations)
Modify tools (write operations)
Warnings in tool responses
When a P4 command produces a benign informational or warning message (for example,
file(s) up-to-dateorfile not on client), the tool returns a successstatusand includes the message text in an optional top-levelwarningslist. The field appears only when there is at least one warning. Genuine failures are unaffected and still return an errorstatuswith the existingcodeanderrorfields.
Logging and Usage Data
Logging system
Log locations:
- Application log:
logs/p4mcp.log- Main server operations and errors - Session logs:
logs/sessions/*.log- Individual session activities are recorded only when the--allow-usageflag is specified in the server’s startup arguments.
Usage Data
Privacy-first approach:
- Disabled by default: No data collection without explicit consent
- Consent-gated: First-run prompt for telemetry permission
- Transparent: Clear explanation of data collected
- Revocable: Easy opt-out at any time
Data collected (if consented):
- Tool usage frequency (anonymized)
- Error rates and types (no personal data)
- Performance metrics
- Feature adoption statistics
- P4 server version
Data not collected:
- File contents or names
- P4 Server details except version
- User credentials or personal information
- Specific project information
Control:
- Usage data is only collected if the
--allow-usageargument is provided at startup.
Troubleshooting
Server Startup Issues
Connection Issues
Authentication Problems
Workspace Issues
Permission Errors
Performance Issues
Tool Execution
Common Error Patterns
- Authentication: Ensure valid login before MCP operations.
- Workspace mapping: Verify client views include target files.
- Permissions: Check user and file permissions for write operations.
- Network: Verify connectivity for remote P4 Servers.
Getting Help
- Check the logs: Always check
logs/p4mcp.logfirst. - Test P4: Ensure
p4 infoworks before troubleshooting MCP. - Report issues to the community: Report issues with log excerpts and environment details.
Support
Perforce P4 MCP Server is a community supported project and is not officially supported by Perforce. Pull requests and issues are the responsibility of the project’s moderator(s); this may be a vetted individual or team with members outside of the Perforce organization. All issues should be reported and managed via GitHub (not via Perforce’s standard support process).
Contributions
We welcome contributions to the P4 MCP Server project.
License
This project is licensed under the MIT License. See LICENSE for details.
Third-Party Notices
This project includes third-party components. Their licenses and attributions are listed in THIRD-PARTY-NOTICES.
Установка
docker run -i --rm --hostname your-hostname -e P4PORT=ssl:perforce.example.com:1666 -e P4USER=your_username -e P4CLIENT=your_workspace -v /Users/your_username/.p4tickets:/home/mcpuser/.p4tickets:ro ghcr.io/perforce/p4mcp-server:latestКонфигурация
{
"mcpServers": {
"perforce-p4-mcp": {
"command": "/absolute/path/to/p4-mcp-server",
"env": {
"P4PORT": "ssl:perforce.example.com:1666",
"P4USER": "your_username",
"P4CLIENT": "your_workspace"
},
"args": [
"--readonly", "--allow-usage"
]
}
}
}