Summary
The p4 MCP server currently uses static P4PORT/P4CLIENT configuration set at startup, making it impossible to query multiple Perforce servers or switch workspaces dynamically. This significantly limits the tool's usefulness in enterprise environments with multiple Perforce servers (e.g., product lines on different servers) and forensic/investigation workflows that require analyzing data across different depots.
Environment
- P4 MCP Server Version: 2025.1.0
- MCP Client: Claude Code / Anthropic
- Infrastructure: Multi-server Perforce environment
- Server 1:
server1.example.com:1666 (Corporate tools - //corp_tools depot)
- Server 2:
server2.example.com:1666 (Product development - //product_a, //product_b depots)
- Use Case: Forensic analysis, cross-depot investigation, multi-project development
Current Behavior
The MCP server is configured with static environment variables at startup:
{
"mcpServers": {
"perforce-p4-mcp": {
"command": "/path/to/p4-mcp-server",
"env": {
"P4PORT": "server1.example.com:1666",
"P4CLIENT": "workspace1"
}
}
}
}
Limitations:
- ❌ All queries go to the same P4PORT server
- ❌ All queries use the same P4CLIENT workspace
- ❌ Cannot access depots on other Perforce servers
- ❌ Cannot switch workspace context during session
- ❌ Shell environment variables (export P4PORT=...) have no effect
- ❌ Working directory changes (cd /workspace) are ignored
Expected/Desired Behavior
Support one or more of the following approaches to enable dynamic workspace/server switching:
Option 1: Per-Query Server/Workspace Override (Preferred)
Allow query tools to accept optional parameters to override the default connection:
{
"action": "history",
"file_path": "//product_a/main/lib/example_cell/schematic/sch.oa",
"p4_config": {
"P4PORT": "server2.example.com:1666",
"P4CLIENT": "workspace2"
}
}
Benefits:
- ✅ Flexible per-query configuration
- ✅ Single MCP server can access multiple P4 servers
- ✅ Backward compatible (optional parameter)
- ✅ Most powerful solution
Option 2: P4CONFIG Directory Support
Allow queries to specify a directory containing .p4config file:
{
"action": "history",
"file_path": "//product_a/main/lib/example_cell/schematic/sch.oa",
"p4config_dir": "/workspace/product_a"
}
The MCP server would read .p4config from that directory to determine P4PORT/P4CLIENT.
Benefits:
- ✅ Leverages existing P4CONFIG mechanism
- ✅ Familiar to Perforce users
- ✅ Works with existing workspace configurations
Option 3: Workspace Switching Tool
Add a new tool to dynamically switch the active workspace:
{
"tool": "set_workspace",
"params": {
"P4PORT": "server2.example.com:1666",
"P4CLIENT": "workspace2"
}
}
All subsequent queries would use the new configuration until changed again.
Benefits:
- ✅ Simpler than per-query override
- ✅ Efficient for multiple queries to same server
- ⚠️ Stateful (queries affect each other)
Option 4: Multiple Named Connections
Allow MCP configuration to define multiple named connections:
{
"mcpServers": {
"perforce-p4-mcp": {
"command": "/path/to/p4-mcp-server",
"connections": {
"corporate": {
"P4PORT": "server1.example.com:1666",
"P4CLIENT": "workspace1"
},
"products": {
"P4PORT": "server2.example.com:1666",
"P4CLIENT": "workspace2"
}
},
"default_connection": "corporate"
}
}
}
Queries could specify which connection to use:
{
"action": "history",
"connection": "products",
"file_path": "//product_a/..."
}
Benefits:
- ✅ Pre-configured trusted connections
- ✅ Simple connection selection per query
- ✅ Secure (no arbitrary server access)
Summary
The p4 MCP server currently uses static P4PORT/P4CLIENT configuration set at startup, making it impossible to query multiple Perforce servers or switch workspaces dynamically. This significantly limits the tool's usefulness in enterprise environments with multiple Perforce servers (e.g., product lines on different servers) and forensic/investigation workflows that require analyzing data across different depots.
Environment
server1.example.com:1666(Corporate tools - //corp_tools depot)server2.example.com:1666(Product development - //product_a, //product_b depots)Current Behavior
The MCP server is configured with static environment variables at startup:
{ "mcpServers": { "perforce-p4-mcp": { "command": "/path/to/p4-mcp-server", "env": { "P4PORT": "server1.example.com:1666", "P4CLIENT": "workspace1" } } } }Limitations:
Expected/Desired Behavior
Support one or more of the following approaches to enable dynamic workspace/server switching:
Option 1: Per-Query Server/Workspace Override (Preferred)
Allow query tools to accept optional parameters to override the default connection:
{ "action": "history", "file_path": "//product_a/main/lib/example_cell/schematic/sch.oa", "p4_config": { "P4PORT": "server2.example.com:1666", "P4CLIENT": "workspace2" } }Benefits:
Option 2: P4CONFIG Directory Support
Allow queries to specify a directory containing .p4config file:
{ "action": "history", "file_path": "//product_a/main/lib/example_cell/schematic/sch.oa", "p4config_dir": "/workspace/product_a" }The MCP server would read
.p4configfrom that directory to determine P4PORT/P4CLIENT.Benefits:
Option 3: Workspace Switching Tool
Add a new tool to dynamically switch the active workspace:
{ "tool": "set_workspace", "params": { "P4PORT": "server2.example.com:1666", "P4CLIENT": "workspace2" } }All subsequent queries would use the new configuration until changed again.
Benefits:
Option 4: Multiple Named Connections
Allow MCP configuration to define multiple named connections:
{ "mcpServers": { "perforce-p4-mcp": { "command": "/path/to/p4-mcp-server", "connections": { "corporate": { "P4PORT": "server1.example.com:1666", "P4CLIENT": "workspace1" }, "products": { "P4PORT": "server2.example.com:1666", "P4CLIENT": "workspace2" } }, "default_connection": "corporate" } } }Queries could specify which connection to use:
{ "action": "history", "connection": "products", "file_path": "//product_a/..." }Benefits: