Skip to main content
Glama
README.md
# desktop-mcp

Guarded macOS desktop control for [Claude Code](https://claude.com/claude-code) in the terminal:
read an app's accessibility tree, screenshot its window, click, type and scroll, via MCP.

It drives apps the way an accessibility tool does (macOS Accessibility API + synthetic keyboard
and mouse events). It never modifies the apps it controls. It ships with a
[WhatsApp skill](skills/whatsapp/SKILL.md) that teaches Claude Code to send messages safely
through the WhatsApp desktop app.

## Safety model

| Guard | What it does |
|---|---|
| Allowlist | Only bundle ids in `~/.config/desktop-mcp/config.toml` can be touched, or every non-blocked app with `allow_all = true`. Missing config = nothing allowed. |
| Hard blocklist | Terminals, IDEs, the Claude app, macOS password prompts/login window, Keychain/Passwords and password managers. Cannot be overridden by config (Claude must never approve its own permission prompts or enter passwords). |
| Frontmost check | Input events are only posted after verifying the target app is frontmost. |
| Hit test | Coordinate clicks are refused if another app's window covers the point. |
| Confirmation | Return/Enter, `type_text(submit=True)` and clicks on controls labelled send/submit/delete/pay/confirm/... open a native dialog. Default button is **Deny**; it times out to Deny after 60s. |
| Trusted chats | WhatsApp chats in `whatsapp_trusted_chats` skip the dialog, but only when the open chat's exact name matches **and** the message box holds exactly the typed text. |
| Draft protection | `type_text` refuses to type into a field that already has text, unless `clear_existing=True`. Before sending it reads the field back and refuses on any mismatch. |
| Focus watch | While typing, it checks after every character that the same field still has focus, and stops at once if not. |
| Human pacing | Randomised per-key timing (longer after spaces/punctuation, occasional pauses) and a delay after every click. |
| One at a time | A lock serialises all actions, including while a dialog is open. |
| Audit log | Every action goes to `~/.local/state/desktop-mcp/actions.jsonl`. |
| Window-only screenshots | Captures the target app's window, never the whole screen. |

## Setup

Requires macOS and [uv](https://docs.astral.sh/uv/).

```sh
git clone https://github.com/Jenish-1235/desktop-mcp && cd desktop-mcp
uv sync

# 1. Config: you edit this, not Claude
mkdir -p ~/.config/desktop-mcp
cp config.example.toml ~/.config/desktop-mcp/config.toml

# 2. Register with Claude Code (user scope)
claude mcp add desktop -s user -- uv --directory "$PWD" run desktop-mcp

# 3. Optional: install the WhatsApp skill for all Claude Code sessions
mkdir -p ~/.claude/skills && cp -r skills/whatsapp ~/.claude/skills/
```

4. macOS permissions, for the terminal app that runs `claude` (iTerm, Ghostty, Terminal, ...):
   System Settings → Privacy & Security → **Accessibility** and **Screen Recording**. Restart the terminal.
5. In Claude Code, ask it to run `check_setup`.

After changing the server code, reload it with `/mcp` → desktop → Reconnect. Config changes
apply immediately.

### Recommended: stop Claude from editing its own config

Add to `~/.claude/settings.json`:

```json
{
  "permissions": {
    "deny": [
      "Edit(~/.config/desktop-mcp/**)",
      "Write(~/.config/desktop-mcp/**)",
      "Bash(osascript:*)"
    ]
  }
}
```

## Config

See [`config.example.toml`](config.example.toml):

| Key | Default | Meaning |
|---|---|---|
| `allowed_apps` | `[]` | Bundle ids Claude may control (`osascript -e 'id of app "WhatsApp"'`). |
| `allow_all` | `false` | Allow every app except the hard blocklist. |
| `whatsapp_trusted_chats` | `[]` | Exact chat names (as in "Messages in chat with …") that send without a dialog. Your own chat is `"You"`. |
| `type_delay` | `0.03` | Median seconds per keystroke (0–0.5), randomised. |
| `click_delay` | `0.5` | Seconds to wait after each click (0–5). |

## Tools

`check_setup`, `list_apps`, `open_app`, `ui_tree`, `screenshot`, `click_element`, `click`,
`type_text`, `press_key`, `scroll`.

Prefer `ui_tree` + `click_element`: element refs are exact and cost far fewer tokens than
images. Use `screenshot` + `click` for apps with poor accessibility support.

## Limits & known gaps

- Coordinates assume the window doesn't move between `screenshot` and `click` (it checks the window id, not position).
- Keycodes are ANSI US layout; `type_text` uses Unicode events so typing works on any layout.
- Risky-click detection is label based. Unlabelled icon buttons won't trigger a dialog unless they're activated with Return.
- Trusted chats match by name, so a group renamed to a trusted name would also count.
- Claude Code's Bash tool can still run arbitrary `osascript`/`cliclick`; the deny rules above close the obvious path.
- Web apps installed as Chrome apps (e.g. YouTube Music) are owned by Chrome; for websites, the Claude in Chrome extension is the better tool.
- WhatsApp: keep it to occasional messages to people who know you. This doesn't change ban risk from volume or spam reports.

## Dev

```sh
uv run pytest
```

## License

[MIT](LICENSE)