Skip to content

Support Dynamic Workspace/Server Switching for Multi-Server Environments #4

@bkatkam123

Description

@bkatkam123

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:

  1. ❌ All queries go to the same P4PORT server
  2. ❌ All queries use the same P4CLIENT workspace
  3. ❌ Cannot access depots on other Perforce servers
  4. ❌ Cannot switch workspace context during session
  5. ❌ Shell environment variables (export P4PORT=...) have no effect
  6. ❌ 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions