Hybrid desktop automation without stealing the mouse

Most desktop automation MCP servers repeat the same slow loop: take a full screenshot, base64-encode it, ship it to a vision model, click one coordinate, sleep 500 ms, and take another screenshot. While that loop runs, the user loses control of their physical mouse and waits through several cloud turns for a two-dialog task.

computer-use is a standalone stdio MCP server for Linux (Wayland and X11), Windows 10/11, and macOS built around two constraints: avoid image offloads whenever local accessibility trees or local OCR can resolve a target, and keep the user's physical mouse and foreground session usable while actions run.

1. Zero-screenshot-first hybrid observation

Both desktop_observe and desktop_act(observe="auto") escalate through four layers in strict cost order so vision turns stay a last resort:

  1. Native accessibility trees run first: AT-SPI2 on Linux (calibrated for Wayland with a 4-second sparse-app cache), MTA IUIAutomation COM on Windows, and AXUIElement (0.35 s timeout) on macOS. Repeat turns return compact AX_DIFF deltas keyed by stable [ref] IDs.
  2. When an application exposes an empty or sparse accessibility tree (Discord, Electron, Steam, Chromium, Spotify), scripts/fast_ocr.py runs 8-thread pre-warmed libtesseract (tessdata_fast, PSM_SPARSE_TEXT, load_system_dawg=0, blank-strip skipping, and 4x local dark/light/colored-button polarity normalization) and returns clickable [x,y] "Label" coordinates inline without sending an image to the LLM.
  3. Compound steps in desktop_act (wait_and_click, wait(text=...), and wait(gone=...)) capture a pre-click snapshot, diff against new frames so stale text on the prior screen cannot match, and OCR only the changed modal bounding box in 14 to 45 ms. For closing modals, wait(gone=...) locks onto the matched bounding box, polls pixel diff at 0.25 ms, and runs a 4.5 ms tiny-crop check once pixels change.
  4. Only when OCR returns fewer than 5 words, or when the caller explicitly asks for mode: "vision", does the server emit an 896px AVX2 libturbojpeg JPEG (41 to 50 KB) with a 0..1000 coordinate grid.

Running local libtesseract inside a long-lived server exposed concurrency and hang defects that synthetic happy-path tests missed. Setting OMP_THREAD_LIMIT=1 inside the process is required to stop OpenMP thread oversubscription across the 8 worker pool threads (cutting full 1920x1080 OCR from 1,800 ms down to 108 to 161 ms); on hot reload inside an existing Linux host process, an isolated memfd + mmap helper preserves that thread limit, guarded by bounded OCR IPC timeouts, dead-worker recovery, and a 160x90 blake2b frame cache. Separately, FastOCR._ensure_init() previously called self.close() on initialization failure while already holding its non-reentrant self._lock, deadlocking the worker and leaking partially created TessBaseAPI handles. Splitting cleanup into _close_locked() plus out-of-lock _teardown_resources() eliminated both hazards.

Operation Backend Measured Notes
desktop_act(observe="none") Direct /dev/uinput 0.05 ms Zero capture, zero settle
Cyan AI cursor glide (55 ms curve) 120Hz async overlay thread 0.008 ms Animates off the action path
400x300 region capture KWin.ScreenShot2 FD pipe 0.25 ms Sub-millisecond diff crop
Private background capture (800x600) Authenticated Xvfb + libX11 1.91 ms No foreground interference
Full 1920x1080 capture + 896px JPEG KWin.ScreenShot2 + Cairo + AVX2 libturbojpeg 4.54 ms 41 KB (50 KB with grid)
Tiny 220x60 wait(gone) bbox verify Pre-warmed tessdata_fast + diff gate 4.5 ms 0.25 ms/poll while unchanged
Modal popup 440x520 local OCR 8-thread tessdata_fast + diff crop 14 to 45 ms Dark, light, and colored button polarity
Full 1920x1080 local OCR 8-thread tessdata_fast (no_dawg) 108 to 161 ms Down from 790 ms (tessdata_best) or 1,800 ms

2. Independent 120Hz cyan overlay cursor and lost-wakeup race fixes

When foreground actions run, scripts/cursor_overlay.py draws a click-through cyan pointer and expanding click ripples on an independent 120Hz render thread: zwlr_layer_shell_v1 + wl_shm + Cairo on Linux Wayland, WS_EX_LAYERED + WS_EX_TRANSPARENT + WDA_EXCLUDEFROMCAPTURE on Windows, and a dedicated main-thread AppKit NSWindow (NSWindowSharingNone) helper on macOS. Because glide_to() hands the target coordinates to the overlay thread and returns in 0.008 ms, animation never blocks input dispatch. Immediately after each click, drag, scroll, or typing step, _restore_user_cursor() runs inside a try/finally block so even an input exception cannot leave the user's physical cursor stranded at the target widget.

Auditing the overlay thread under stress uncovered three subtle concurrency and wire-protocol bugs that were fixed with cross-platform regression tests in tests/test_cursor_overlay.py:

3. Cross-platform background mode

Passing background: true after desktop_background isolates automation from the user's live desktop so the agent never moves the cursor, steals window focus, or touches the system clipboard.

Platform Module Capture path Input delivery
Linux (Wayland / X11) scripts/linux_bg.py Private MIT-MAGIC-COOKIE-1 Xvfb + direct libX11 XGetImage Direct libXtst XTest pointer and keyboard events
Windows 10 / 11 scripts/win32_backend.py PrintWindow(PW_RENDERFULLCONTENT) Child-HWND PostMessageW mouse and UTF-16 keyboard messages
macOS 13+ scripts/macos_backend.py Occluded CGWindowListCreateImage / screencapture -l Native AXPress and CGEventPostToPid

Background compound waits in _exec_bg_step() previously fell back to a blind 150 ms sleep for wait(change/text/gone) and skipped click offsets in background wait_and_click. Both paths now run the same frame-diff and local OCR loop (background.capture(), capture.diff_frames(), and ocr.find_text()) and apply offset_x and offset_y before clicking.

4. Layout-aware /dev/uinput input and audit log redaction

On Linux Wayland, scripts/uinput_driver.py opens a persistent virtual pointer modeled on a QEMU usb-tablet absolute device (EV_ABS 0..65535 without BTN_TOUCH or INPUT_PROP_POINTER), mapped across multi-monitor virtual desktop bounds including negative monitor offsets. One subtle Linux kernel behavior breaks repeated clicks on shared desktops: if the virtual pointer emits the exact same (ABS_X, ABS_Y) coordinates twice in a row after the user moved their physical mouse somewhere else, the kernel deduplicates the identical EV_ABS values and drops the move. Guarding repeated moves with a 1-unit nudge (ax ^ 1 immediately followed by ax) forces the compositor to reposition the pointer every time.

For typing, detect_keyboard_layout() inspects COMPUTER_USE_KEYMAP, KDE ~/.config/kxkbrc (including VariantList= dead-key checks), GNOME gsettings, localectl, and setxkbmap. Standard US and UK ASCII sequences type directly through kernel keycodes, while Unicode strings or international dead-key layouts fall back automatically to atomic clipboard paste with asynchronous clipboard restoration (saving roughly 110 ms per paste compared to synchronous restore).

At the MCP protocol boundary in scripts/computer_use_mcp.py, JSON-RPC dispatch validates method names, parameter object shapes, and tool argument types before execution, returning standard -32600, -32602, and -32603 error payloads instead of crashing the stdio loop. Quick preview screenshots write via os.fdopen(fd, "wb") with 0o600 mode (plus O_BINARY on Windows) and atomic os.replace() to prevent short-write truncation. When COMPUTER_USE_AUDIT_LOG is enabled, DesktopEngine._sanitize_audit_args() recursively walks top-level arguments, desktop_act steps, and nested repeat.steps (up to depth 16) without mutating caller inputs, redacting any text, value, or type_text string longer than 40 characters to <N chars> so typed credentials or messages never land verbatim in JSONL logs.

5. Install and verify locally

Standalone installation writes ~/.local/bin/computer-use-mcp (or a PowerShell shim on Windows) and runs non-destructive protocol, backend, and desktop_status runtime diagnostics:

git clone https://github.com/alexander-src/computer-use.git
cd computer-use
./install.sh --standalone

# Version, host diagnostics, MCP schema export, headless self-test, benchmark, and test suite
python3 scripts/computer_use_mcp.py --version
python3 scripts/computer_use_mcp.py --doctor --json
python3 scripts/computer_use_mcp.py --schema
python3 scripts/computer_use_mcp.py --selftest --json
python3 scripts/computer_use_mcp.py --bench --json
python3 scripts/computer_use_mcp.py --demo-cursor
python3 -W error -m unittest discover -s tests -v

Limitations