Skip to content

clear stale MCP entries when switching workspaces#111

Open
asujithan wants to merge 1 commit into
mainfrom
mcp-clear-state
Open

clear stale MCP entries when switching workspaces#111
asujithan wants to merge 1 commit into
mainfrom
mcp-clear-state

Conversation

@asujithan
Copy link
Copy Markdown
Collaborator

Summary

Fixes #110. After switching Databricks workspaces in ucode, agent configs (~/.claude.json, ~/.codex/..., etc.) used to keep MCP entries pointing at the previous workspace until the user explicitly re-ran ucode configure mcp. This PR scrubs them automatically.

What Changed

  • New helper purge_cross_workspace_mcp_residue(state, workspace) in mcp.py runs two passes:
    1. Drops entries from state["mcp_servers"] whose URL host doesn't match the current workspace and unregisters them from installed clients.
    2. Removes MCP names tracked only in other workspaces' state buckets from installed clients (idempotent — re-runs stay quiet once configs are clean).
  • Called from two places:
    • configure_mcp_command — heals state pollution from before this fix existed.
    • configure_shared_state — runs on every workspace switch, so users no longer need a follow-up configure mcp to reconcile agent configs.

Test plan

  • uv run ruff check .
  • uv run ruff format --check src/ tests/
  • uv run pytest --ignore=tests/test_e2e.py
  • New focused tests in tests/test_mcp.py cover both cleanup passes and the idempotency case.
  • New tests in tests/test_cli.py verify the switch-time trigger fires only when the workspace actually changes.

@asujithan asujithan requested a review from AarushiShah-db May 27, 2026 23:23
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.

Switching workspaces in ucode does not clear MCP configurations

1 participant