# cua-rs **An AI agent drives your Mac. Your mouse and keyboard stay yours.** [![ci](https://github.com/maestrojeong/cua-rs-mcp/actions/workflows/ci.yml/badge.svg)](https://github.com/maestrojeong/cua-rs-mcp/actions/workflows/ci.yml) [![release](https://img.shields.io/github/v/release/maestrojeong/cua-rs-mcp)](https://github.com/maestrojeong/cua-rs-mcp/releases) [![license](https://img.shields.io/badge/license-Apache--2.0-blue)](LICENSE) ![platforms](https://img.shields.io/badge/platform-macOS%20arm64-lightgrey) ## What is this? `cua-rs` is an **MCP server** that lets an AI agent (Claude, Codex, etc.) drive real macOS apps — without taking over the mouse, keyboard or screen you're currently using. Most "computer-using agent" tools work by moving the mouse to screen coordinates and clicking. `cua-rs` instead uses macOS's **Accessibility API** to address "that button" or "this text field" directly as an element, and delivers clicks/keys to the target app's process only. So: - Your mouse cursor never moves. - Your active app and keyboard focus never change. - No Space (virtual desktop) switch. While you're writing a document, the agent can quietly drive some other app (Notes, a messenger, etc.) in the background. Single Rust binary.

Top, blue lane: the agent goes through MCP to cua-rs, which addresses an element via the Accessibility API to operate the target app. Bottom, orange lane: you keep using your real mouse and keyboard on whatever window is frontmost. No arrow crosses between the two lanes.

No arrow crosses between the two lanes — that's the whole point. One caveat: a key event still lands on the target app's currently focused element, not necessarily the exact one you named. See [DESIGN.md](DESIGN.md) for the full rationale. ## Install ```bash curl -fsSL https://raw.githubusercontent.com/maestrojeong/cua-rs-mcp/main/install.sh | sh cua-rs --help ``` Pin a version with `CUA_VERSION=v0.4.2`, or build from source (installs both binaries together): ```bash cargo install --git https://github.com/maestrojeong/cua-rs-mcp cua-mcp cua-overlay ``` > Downloaded a binary by hand? Clear the quarantine flag first: > `xattr -d com.apple.quarantine ./cua-rs` (the install script does this > automatically). ## Permissions Two grants, given to whatever app **launches** `cua-rs` (e.g. Claude Desktop) — upgrading `cua-rs` never needs re-approval. | Permission | Needed for | Without it | |---|:--|:--| | Accessibility | reading the screen, every action | nothing works | | Screen Recording | screenshots, click-safety checks | still works, no images | ```bash cua-rs permissions # checks status, never prompts ``` Add the app that runs `cua-rs` under **System Settings → Privacy & Security → Accessibility** (then Screen Recording), and restart it. `cua-rs` **refuses to act** on System Settings, Keychain Access, password managers, etc. — reading them is still fine. See [Safety](#safety). ## Connect `cua-rs` speaks standard MCP over stdio — any compliant client connects with one line of config. Pick yours:
Claude Code ```bash claude mcp add cua -- cua-rs ``` Registers it for the current project. Add `-s user` to register it globally for all projects instead. Verify with `claude mcp list`.
Codex CLI Add to `~/.codex/config.toml`: ```toml [mcp_servers.cua-rs] command = "cua-rs" ```
Claude Desktop Add to `claude_desktop_config.json`: ```json { "mcpServers": { "cua": { "command": "cua-rs" } } } ```
Cursor Add to `~/.cursor/mcp.json` (global) or `.cursor/mcp.json` (per-project): ```json { "mcpServers": { "cua": { "command": "cua-rs" } } } ```
Gemini CLI Add to `~/.gemini/settings.json`: ```json { "mcpServers": { "cua": { "command": "cua-rs" } } } ```
Any other MCP client Any MCP-compliant client that launches a stdio server works. The command is just `cua-rs`, no arguments: ```json { "mcpServers": { "cua": { "command": "cua-rs" } } } ```
Or Streamable HTTP, for attaching to an already-running server: ```bash cua-rs 9331 # http://127.0.0.1:9331/mcp ``` Local connections only, protected by a bearer token (random by default, or pin one with `CUA_HTTP_TOKEN`). stdio needs no token. ## Safety Several gates are on by default; a blocked action always explains why and how to unblock it. - **Scope which apps can be driven** — `CUA_ALLOWED_APPS`. Recommended. - **Credential/security apps are never driven** (Keychain, password managers, System Settings, lock screens). Reading still works. - **Destructive actions need confirming** — buttons like "Delete", "Erase", "Reset" require `confirm_destructive: true`. "Cancel"/"Save" are always allowed. - **Quitting an app always needs confirming**, and Finder, Dock, the menu bar, loginwindow and WindowServer are never quit. - **Nothing reaches a locked screen or screensaver.** - **Optional: yield to a human actively using the app** — `CUA_YIELD_TO_HUMAN=1` (off by default). - **Clipboard secrets stay hidden.** `clipboard_get` withholds the text (and returns only its types) when a password manager marked it concealed, when a credential app wrote it, or when one is frontmost. Clipboard writes are refused while the screen is locked, and — with `CUA_YIELD_TO_HUMAN=1` — while the human is active. `CUA_ALLOWED_APPS` is the strongest guarantee: once set, the agent can never widen it itself. Full criteria in [DESIGN.md §7a](DESIGN.md). ## How agents use it Start with `get_app_state` to see what's on screen: ```text Notes (pid 41277) snapshot_id=1 AXWindow "Groceries" [3] AXButton "New Note" [7] AXTextField:SearchField "Search" (editable) [21] AXTextArea = "milk\neggs" (editable, focused) ``` Numbered elements (`[3]`, `[7]`, `[21]`) can be clicked or filled in. | Tool | What it does | |---|:--| | `get_app_state` | call first — tree + screenshot together | | `find` / `wait_for` | look for text to appear/disappear | | `click` / `drag` / `hover` | act on an element | | `set_value` / `type_text` / `select_text` | write, append, or select text | | `press_key` | press a key or shortcut | | `menu_bar` | read the menu bar and click an item | | `scroll` | scroll a view | | `clipboard_get` | read clipboard text; lists the types when there is none | | `clipboard_set` / `clipboard_clear` | write plain text to the clipboard, or empty it | | `list_windows` / `list_displays` | every window of an app (id, title, frame, level, state); every display | | `focus_window` | raise a window — without activating the app or taking your keyboard | | `move_window` / `resize_window` | set a window's position or size (refused if it would end up off screen) | | `minimize_window` / `maximize_window` / `restore_window` | Dock, zoom, and back | | `launch_app` / `close_app` | start an app (in the background unless asked); quit one gracefully (always needs `confirm_destructive`) | | `list_apps` / `check_permissions` | list apps; check permission status | | `list_notifications` | read notification banners, and with `include_history` the Notification Center history (app, title, body, actions, stable id) | | `dismiss_notification` / `dismiss_all_notifications` | close one notification by id, or all of them one at a time (stops at the first failure and reports progress) | | `notification_action` | press a named action a notification advertises (Show Details, …) — **app-defined buttons like Reply are unverified** | | `batch` | run several of the tools above in one call, in order | Notification tools were measured on macOS 26.2 only. Close was verified with the Korean label (닫기); other locales rely on expected translations. Close deletes the notification from history, so notifications from credential apps (and, under `CUA_ALLOWED_APPS`, from out-of-scope or unidentifiable apps) are refused. Details: [DESIGN.md §14](DESIGN.md). Every action returns what changed, so acting and verifying take one round trip. Every action's result also names its `disposition` — `delivered_verified`, `delivered_unverified`, or (on a refused/failed call) `not_delivered` — and an error carries a second content block with a structured `code`, so an agent can decide whether a retry is safe without re-parsing the message. See [Errors and disposition](#errors-and-disposition). ## Errors and disposition Every failed tool call returns two things: the same human-readable message this server has always printed, and a second block with a stable JSON shape: ```json {"code":"STALE_REF","disposition":"not_delivered","retry_safe":true} ``` `disposition` is `not_delivered` (nothing was dispatched — always true for a refused call, always safe to retry), `delivered_unverified` (an event was sent and reported success, but nothing independently confirms its effect — this is also what a *successful* action reports when its own `ui_changed` heuristic says `no` or `unknown`), or `delivered_verified` (sent, and a re-read confirms the target changed). `retry_safe` is `true` only for `not_delivered` — it is derived from `disposition`, never set independently, so the two can never disagree. | `code` | meaning | |---|:--| | `PERM_DENIED` | Accessibility or Screen Recording grant missing | | `APP_NOT_FOUND` / `AMBIGUOUS_TARGET` | `app` matches nothing / more than one app | | `ELEMENT_NOT_FOUND` / `WINDOW_NOT_FOUND` | no such element, point or menu row / no drivable window | | `STALE_REF` | index, token, coordinate or snapshot is out of date — re-read | | `ACTION_NOT_SUPPORTED` | the target can't do this (or not right now) | | `ACTION_FAILED` | attempted, and the app or platform failed it | | `TIMEOUT` | the app (or a `wait_for`) didn't answer in time | | `PLATFORM_NOT_SUPPORTED` | this macOS build lacks a needed primitive | | `INVALID_ARGS` | malformed arguments | | `POLICY_DENIED` | a safety gate refused; `policy_reason` is `scope`, `forbidden_target`, `destructive`, `screen_locked`, `yield_to_human` or `strict_focus` | | `INTERNAL` | a bug or unexpected native failure | The wording of every refusal and error message is unchanged by this — `code` and `disposition` are new structure next to the existing prose, not a replacement for it. See [DESIGN.md](DESIGN.md) §10a for the full reasoning, including why `NativePanic` is the one case reported as unverified rather than not-delivered. `batch` sends a sequence of steps in a single call. Each step names a tool and passes exactly the arguments that tool takes on its own: ```json { "steps": [ {"tool": "set_value", "params": {"app": "Notes", "element_token": "1-7-AXTextField", "value": "eggs", "return_state": false}}, {"tool": "press_key", "params": {"app": "Notes", "element_token": "1-7-AXTextField", "key": "return"}}, {"tool": "find", "params": {"app": "Notes", "text": "eggs"}} ], "bail_on_error": true } ``` Results come back tagged by step index. With `bail_on_error` (the default) the batch stops at the first failing step and lists the steps it did not run; pass `false` to run them all. Each step goes through the same safety checks and `snapshot_id` checks as a solo call. So if a step re-reads the window (any action with `return_state` on, or `get_app_state`), a later step that cites the old snapshot fails just as it would on its own. Turn `return_state` off on the steps in between. Every tool except `batch` itself can be a step, up to 50 per call. ## What works, what doesn't - Buttons, menus, tabs, lists, text fields — works well, native and Electron. - Pop-up menus from a click — use the item's keyboard shortcut or the menu bar instead of clicking inside the pop-up. - Hover — works on web pages, not on native lists like Finder's. - Scroll with no Accessibility scroll action (canvas, some Electron lists) — falls back to a page-up/down suggestion instead of faking it. - Chrome/Safari in the background reject clicks and hover entirely. For web automation, use [browser-rs](https://github.com/maestrojeong/browser-rs-mcp) (CDP-based) instead. - Terminals — reading works; typing needs `mechanism: "keystrokes"`. Full experiment notes in [DESIGN.md](DESIGN.md). ## The on-screen cursor The Accessibility path leaves no visible trace, so a companion binary, `cua-overlay`, draws a **click-through, transparent arrow** wherever the agent acts. Not a real cursor, never intercepts input, only visible while the driven app is frontmost. `cua-rs` looks for `cua-overlay` next to its own binary; if missing, it logs one warning and keeps working without the indicator. The installer and the `cargo install` command above install both together.

An arrow and ring marking where the agent clicked

## For developers ```bash cargo build --workspace cargo test --workspace # 353 tests, no special permissions needed cargo clippy --workspace --all-targets -- -D warnings ``` ```text cua-ax safe wrapper over the macOS Accessibility (AXUIElement) API cua-capture finds windows, takes screenshots cua-core snapshots, app resolution, safety gates, the clipboard cua-hid delivers clicks/keys to a specific process cua-mcp the MCP server itself, binary `cua-rs` cua-overlay the on-screen cursor ``` Design rationale and constraints: [DESIGN.md](DESIGN.md). ## Related projects - [**trycua/cua**](https://github.com/trycua/cua/tree/main/libs/cua-driver) — bigger, cross-platform, further along. - [**lahfir/agent-desktop**](https://github.com/lahfir/agent-desktop) — Rust accessibility engine, CLI rather than MCP. - [**minghinmatthewlam/computer-use-mcp**](https://github.com/minghinmatthewlam/computer-use-mcp) — same idea, in Swift. ## License Apache-2.0