Skip to content

[BR-2167] Switch MCP registrations with the active workspace - #1364

Open
sunishsheth2009 wants to merge 7 commits into
mainfrom
sunish/br-2167-mcp-only
Open

sunishsheth2009 wants to merge 7 commits into
mainfrom
sunish/br-2167-mcp-only

Conversation

@sunishsheth2009

@sunishsheth2009 sunishsheth2009 commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

BR-2167

Coding agents keep MCP registrations in a global config keyed by server name. Adding workspace B's MCP server while workspace A remains active can expose B's tools to an A session; appending a workspace suffix does not isolate the sessions. Model configuration already selects one active workspace.

This PR makes MCP registration follow that active-workspace boundary:

  • ug mcp add --workspace B refuses to register while A is active and points to ug configure --workspace B. On first setup, MCP add selects its workspace without configuring agent models.
  • An explicit configure switch saves the destination workspace's own MCP selections, removes registrations left from the previous workspace, configures models and policy, then restores the destination's saved user MCP entries. Managed MCPs are reconciled before user entries are restored, including the single-agent Codex path.
  • Switching back restores A's saved MCP entries. A and B can use the same server name; the active agent config contains the selected workspace's URL under that name, with no workspace suffix.
  • MCP-only configure paths and Claude Cowork sync use the selected workspace. README documents the switch.

Example: with A active and system-ai-github saved for A, first run ug configure --workspace B --agent codex. A's registration is removed and B's saved registration is installed, if one exists. Run ug mcp add --agents codex --names system.ai.github if B has no saved selection. Start a new Codex session to use B's tools. Running ug configure --workspace A --agent codex restores A's saved URL.

Validation

  • tests/test_mcp.py tests/test_cli.py tests/test_agent_vscode.py: 1,023 passed locally after the review fixes.
  • Workspace-switch regression covers A → B → A, including identical MCP names with different workspace URLs, and the active workspace on first MCP setup.
  • Ruff check/format on src/ and tests/, Ty check on src/, and git diff --check passed.
  • Fixed the Linux/Windows VS Code unit fixture and preserved source-workspace managed MCP delivery state until reconciliation. The new regression verifies removal of a stale managed fallback while retaining destination user choices.
  • Review fixes: stale entries are matched per (name, client); restoration reads post-reconciliation state; and a saved workspace is restored after revert leaves no active workspace. Focused regressions cover all three.
  • The preceding CI run passed Linux and Windows unit tests, the Claude managed-config workspace-switch journey, CUJ 6 repeated config/removal, and the full Codex Linux journey. CI for the review-fix commit is pending.
  • The earlier live staging test covered MCP registration with a disposable HOME and unchanged machine-wide files. A live A → B → A agent session/tool call was not rerun for this revision. LiteSwap does not exercise local CLI/agent config paths.

BR-2276 PR #1363 changes nearby MCP client detection and registration code but has no functional dependency. Rebase it after this PR if this merges first.

@sunishsheth2009 sunishsheth2009 changed the title [BR-2167] Keep MCP add scoped to the requested workspace and agents [BR-2167] Switch MCP registrations with the active workspace Oct 30, 2026
Comment thread src/ucode/cli.py Outdated
Comment thread src/ucode/mcp.py
Comment thread src/ucode/cli.py Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants