Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

fix(cua-driver): scrub the Claude MCP registration the CLI actually creates

umutcagand558ddf0141c9
diff --git a/libs/cua-driver/scripts/tests/test_uninstall_claude_mcp.py b/libs/cua-driver/scripts/tests/test_uninstall_claude_mcp.py
new file mode 100644
index 0000000000..f5f96ae7ed
--- /dev/null
+++ b/libs/cua-driver/scripts/tests/test_uninstall_claude_mcp.py
@@ -0,0 +1,215 @@
+"""Claude MCP scrubbing in the release uninstaller.
+
+`cua-driver mcp-config --client claude` registers the server as
+`cua-computer-use`, so an uninstaller that only matched `cua-driver-rs` left a
+live registration behind while reporting a clean uninstall.
+"""
+
+from __future__ import annotations
+
+import json
+import os
+from pathlib import Path
+import subprocess
+
+
+REPO_ROOT = Path(__file__).resolve().parents[4]
+UNINSTALL = REPO_ROOT / "libs/cua-driver/scripts/uninstall.sh"
+
+
+def _executable(path: Path, body: str) -> None:
+ path.parent.mkdir(parents=True, exist_ok=True)
+ path.write_text(f"#!/bin/sh\n{body}", encoding="utf-8")
+ path.chmod(0o755)
+
+
+def _run(
+ tmp_path: Path,
+ servers: dict,
+ *,
+ rust_marker: bool,
+ with_claude_cli: bool = False,
+) -> tuple[dict, str]:
+ """Uninstall against a fake HOME and return the surviving servers."""
+
+ home = tmp_path / "home"
+ fake_bin = tmp_path / "fake-bin"
+ (home / ".local/bin").mkdir(parents=True)
+ if rust_marker:
+ (home / ".cua-driver/packages/current").mkdir(parents=True)
+
+ _executable(fake_bin / "uname", "printf 'Linux\\n'")
+ _executable(fake_bin / "pkill", "exit 0")
+ _executable(fake_bin / "systemctl", "exit 0")
+ if with_claude_cli:
+ _executable(fake_bin / "claude", f'echo "$@" >> "{tmp_path / "claude-calls"}"\nexit 1')
+
+ claude_json = home / ".claude.json"
+ claude_json.write_text(json.dumps(servers), encoding="utf-8")
+
+ env = os.environ.copy()
+ env.update({"HOME": str(home), "PATH": f"{fake_bin}:/usr/bin:/bin"})
+ result = subprocess.run(
+ ["/bin/bash", str(UNINSTALL)],
+ cwd=REPO_ROOT,
+ env=env,
+ text=True,
+ capture_output=True,
+ check=False,
+ )
+ assert result.returncode == 0, result.stdout + result.stderr
+ return json.loads(claude_json.read_text(encoding="utf-8")), result.stdout
+
+
+def _user_servers(config: dict) -> set:
+ return set(config["mcpServers"])
+
+
+def test_registered_claude_server_is_removed(tmp_path: Path) -> None:
+ """The reported bug: the name the CLI actually registers survived."""
+
+ config, stdout = _run(
+ tmp_path,
+ {
+ "mcpServers": {
+ "cua-computer-use": {
+ "command": "/home/u/.local/bin/cua-driver",
+ "args": ["mcp"],
+ },
+ "unrelated": {"command": "/usr/bin/other", "args": ["mcp"]},
+ }
+ },
+ rust_marker=True,
+ )
+
+ assert _user_servers(config) == {"unrelated"}
+ assert "removed Claude MCP registration(s): user:cua-computer-use" in stdout
+
+
+def test_project_scoped_registrations_are_scrubbed_too(tmp_path: Path) -> None:
+ config, _ = _run(
+ tmp_path,
+ {
+ "mcpServers": {},
+ "projects": {
+ "/work/repo": {
+ "mcpServers": {
+ "cua-computer-use": {
+ "command": "/home/u/.local/bin/cua-driver",
+ "args": ["mcp"],
+ },
+ "unrelated": {"command": "/usr/bin/other"},
+ }
+ }
+ },
+ },
+ rust_marker=True,
+ )
+
+ assert set(config["projects"]["/work/repo"]["mcpServers"]) == {"unrelated"}
+
+
+def test_a_renamed_key_still_matches_on_the_launcher(tmp_path: Path) -> None:
+ config, _ = _run(
+ tmp_path,
+ {
+ "mcpServers": {
+ "my-driver": {"command": "/home/u/.local/bin/cua-driver", "args": ["mcp"]}
+ }
+ },
+ rust_marker=True,
+ )
+
+ assert _user_servers(config) == set()
+
+
+def test_a_name_without_a_readable_command_is_still_removed(tmp_path: Path) -> None:
+ config, _ = _run(
+ tmp_path,
+ {"mcpServers": {"cua-computer-use": {"args": ["mcp"]}}},
+ rust_marker=True,
+ )
+
+ assert _user_servers(config) == set()
+
+
+def test_the_legacy_name_is_removed_without_a_marker(tmp_path: Path) -> None:
+ """`cua-driver-rs` was only ever ours, so it needs no disambiguation."""
+
+ config, _ = _run(
+ tmp_path,
+ {"mcpServers": {"cua-driver-rs": {"command": "/x/cua-driver-rs", "args": ["mcp"]}}},
+ rust_marker=False,
+ )
+
+ assert _user_servers(config) == set()
+
+
+def test_shared_names_are_kept_without_a_rust_marker(tmp_path: Path) -> None:
+ """A Swift-only Mac used the same names; leave its registrations alone."""
+
+ config, stdout = _run(
+ tmp_path,
+ {
+ "mcpServers": {
+ "cua-computer-use": {
+ "command": "/home/u/.local/bin/cua-driver",
+ "args": ["mcp"],
+ }
+ }
+ },
+ rust_marker=False,
+ )
+
+ assert _user_servers(config) == {"cua-computer-use"}
+ assert "no Claude MCP registrations for cua-driver found" in stdout
+
+
+def test_another_installs_launcher_is_left_to_its_own_uninstaller(tmp_path: Path) -> None:
+ """A side-by-side launcher registers under the same name and owns its entry."""
+
+ config, _ = _run(
+ tmp_path,
+ {
+ "mcpServers": {
+ "cua-computer-use": {
+ "command": "/home/u/.local/bin/cua-driver-sidecar",
+ "args": ["mcp"],
+ }
+ }
+ },
+ rust_marker=True,
+ )
+
+ assert _user_servers(config) == {"cua-computer-use"}
+
+
+def _claude_removals(tmp_path: Path) -> set:
+ """Server names the uninstaller asked the `claude` CLI to remove."""
+
+ calls = (tmp_path / "claude-calls").read_text(encoding="utf-8").splitlines()
+ return {parts[2] for parts in (call.split() for call in calls) if parts[:2] == ["mcp", "remove"]}
+
+
+def test_cli_fallback_asks_to_remove_the_registered_name(tmp_path: Path) -> None:
+ _run(tmp_path, {"mcpServers": {}}, rust_marker=True, with_claude_cli=True)
+
+ assert _claude_removals(tmp_path) == {"cua-driver-rs", "cua-driver", "cua-computer-use"}
+
+
+def test_cli_fallback_keeps_shared_names_without_a_rust_marker(tmp_path: Path) -> None:
+ _run(tmp_path, {"mcpServers": {}}, rust_marker=False, with_claude_cli=True)
+
+ assert _claude_removals(tmp_path) == {"cua-driver-rs"}
+
+
+def test_windows_guidance_names_the_registered_server() -> None:
+ """Windows does not auto-edit the config, so the printed command must be right."""
+
+ script = (REPO_ROOT / "libs/cua-driver/scripts/uninstall.ps1").read_text(
+ encoding="utf-8-sig"
+ )
+
+ assert "claude mcp remove cua-computer-use" in script
+ # The legacy name stays for installs that registered under it.
+ assert "claude mcp remove cua-driver-rs" in script
diff --git a/libs/cua-driver/scripts/uninstall.ps1 b/libs/cua-driver/scripts/uninstall.ps1
index fbf78e2657..eba49e8845 100644
--- a/libs/cua-driver/scripts/uninstall.ps1
+++ b/libs/cua-driver/scripts/uninstall.ps1
@@ -1,4 +1,4 @@
-# cua-driver-rs uninstaller (Windows) — removes the runtime installed by install.ps1
+# cua-driver-rs uninstaller (Windows) — removes the runtime installed by install.ps1
# laid down: the Scheduled Task autostart entry, running daemon
# processes, the directory junctions wiring the visible bin dir back to
# a per-version release dir, the entire package home tree, and any skill
@@ -39,7 +39,9 @@
# Conservative on Claude MCP cleanup: we DON'T auto-edit %USERPROFILE%\
# .claude.json on Windows (mirrors the macOS uninstall.sh's stance for
# environments without python3). The closing message prints the
-# `claude mcp remove cua-driver-rs` command for the user to run.
+# `claude mcp remove cua-computer-use` command for the user to run —
+# that is the name `mcp-config --client claude` registers — plus the
+# legacy cua-driver-rs name for older installs.
#
# Env overrides (mirror install.ps1's variable names):
# $env:CUA_DRIVER_RS_INSTALL_DIR visible bin dir to remove
@@ -496,8 +498,13 @@ if (-not $Purge) {
Write-Host ""
}
Write-Host "Claude Code MCP registrations:" -ForegroundColor Yellow
-Write-Host " We don't auto-edit ~/.claude.json on Windows. If you registered cua-driver-rs"
-Write-Host " with Claude Code, remove it manually:"
+Write-Host " We don't auto-edit ~/.claude.json on Windows. If you registered cua-driver"
+Write-Host " with Claude Code, remove it manually. mcp-config --client claude registers"
+Write-Host " the server under the name cua-computer-use:"
+Write-Host ""
+Write-Host " claude mcp remove cua-computer-use"
+Write-Host ""
+Write-Host " Installs from v0.2.13 and earlier used the name cua-driver-rs:"
Write-Host ""
Write-Host " claude mcp remove cua-driver-rs"
Write-Host ""
diff --git a/libs/cua-driver/scripts/uninstall.sh b/libs/cua-driver/scripts/uninstall.sh
index 606d13bb0c..595304a70c 100755
--- a/libs/cua-driver/scripts/uninstall.sh
+++ b/libs/cua-driver/scripts/uninstall.sh
@@ -48,8 +48,9 @@
# (~/.cua-driver/packages/, legacy ~/.cua-driver-rs/, CuaDriverRs.app,
# the LaunchAgent/systemd unit, or current Rust telemetry state).
#
-# Also scrubs Claude MCP registrations in ~/.claude.json that match
-# the active backend.
+# Also scrubs Claude MCP registrations in ~/.claude.json (cua-driver /
+# cua-computer-use / legacy cua-driver-rs), gated on the same Rust marker
+# for the names the retired Swift driver also used.
#
# Revokes TCC grants on macOS by default (Accessibility + Screen Recording)
# so the next install prompts cleanly under the new signing identity. Pass
@@ -770,9 +771,10 @@ if [[ "$USE_RUST_BACKEND" == "1" ]]; then
fi
# --- Claude Code MCP registrations ---
- # Same scrub shape as the Swift branch, keyed on the cua-driver-rs
- # binary name + the per-platform install paths. Unrelated MCP
- # servers are left alone.
+ # Keyed on the names the CLI registers (`cua-driver`,
+ # `cua-computer-use`, legacy `cua-driver-rs`) plus the per-platform
+ # install paths. Unrelated MCP servers are left alone, and the names
+ # shared with the retired Swift driver need a Rust marker on disk.
CLAUDE_JSON="$HOME/.claude.json"
if [[ -f "$CLAUDE_JSON" ]] && command -v python3 >/dev/null 2>&1; then
PY_OUTPUT="$(
@@ -826,8 +828,40 @@ def invokes_cua_driver_rs(server):
return True
return False
+# The names the CLI actually registers. `cua-driver mcp-config --client
+# claude` emits `claude mcp add-json --scope user cua-computer-use`, so
+# `cua-driver-rs` alone never matched a current registration. Both names
+# were also the retired Swift driver's, so they are gated on the same Rust
+# marker as every other shared-path removal.
+RELEASE_SERVER_NAMES = {"cua-driver", "cua-computer-use"}
+
+def launcher_name(server):
+ # The launcher filename this registration runs, compared exactly rather
+ # than by substring: a side-by-side install ships a differently-named
+ # launcher and owns its own registration through its own uninstaller.
+ # A substring test would reach into it.
+ if not isinstance(server, dict):
+ return ""
+ command = server.get("command")
+ if not isinstance(command, str):
+ return ""
+ return os.path.basename(command)
+
def should_remove(name, server):
- return name in {"cua-driver-rs"} or invokes_cua_driver_rs(server)
+ if name == "cua-driver-rs" or invokes_cua_driver_rs(server):
+ return True
+ # Everything below is a name or path the retired Swift driver used too,
+ # so a Swift-only Mac that runs this script by mistake keeps its
+ # registrations.
+ if not rust_install_present:
+ return False
+ launcher = launcher_name(server)
+ if launcher == "cua-driver":
+ return True
+ # Name-only match, for an entry whose command we cannot read. When the
+ # command does name a launcher and it is not ours, the entry belongs to
+ # whatever installed it — leave it to that uninstaller.
+ return name in RELEASE_SERVER_NAMES and not launcher
def scrub_servers(servers, scope):
if not isinstance(servers, dict):
@@ -879,7 +913,7 @@ PY
log "$line"
done <<< "$PY_OUTPUT"
else
- log "no Claude MCP registrations for cua-driver-rs found in $CLAUDE_JSON"
+ log "no Claude MCP registrations for cua-driver found in $CLAUDE_JSON"
fi
else
log "no Claude config cleanup via python3 (missing $CLAUDE_JSON or python3)"
@@ -889,7 +923,14 @@ PY
# active project / user scopes — fine to run; it's a no-op when the
# entries were already scrubbed above.
if command -v claude >/dev/null 2>&1; then
- for SERVER in cua-driver-rs; do
+ # `cua-driver-rs` was only ever ours. The two current names are
+ # shared with the retired Swift driver, so they follow the same
+ # Rust-marker gate the config scrub above uses.
+ CLAUDE_MCP_SERVERS=(cua-driver-rs)
+ if [[ "$RUST_INSTALL_PRESENT" == "1" ]]; then
+ CLAUDE_MCP_SERVERS+=(cua-driver cua-computer-use)
+ fi
+ for SERVER in "${CLAUDE_MCP_SERVERS[@]}"; do
for SCOPE in local project user; do
if claude mcp remove "$SERVER" -s "$SCOPE" >/dev/null 2>&1; then
log "removed Claude MCP server $SERVER from $SCOPE scope"