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

A local MCP server that gives [Claude Code](https://claude.com/claude-code) eyes and hands on a
Windows desktop: it reads the UI Automation tree, takes screenshots, and clicks and types through
Win32 `SendInput`. Claude Code runs the agent loop itself, so there is no second LLM, no API key
and no browser extension. It works in any app because it acts at the OS level.

The hard part isn't moving the mouse. It's letting a model act on a real, logged-in desktop
without leaking what's on screen or doing something it shouldn't. Most of this repo is that
safety layer.

## What it does

The v1 demo prompt: *"Open Edge, search the weather in Córdoba, Argentina, and paste the result
into Notepad."* It passed live in 5 of the 40 allowed steps, with every action approved by hand.

| Read-only (no prompt) | Actions (each one asks first) |
|---|---|
| `list_windows`, `screenshot`, `ui_tree`, `wait` | `click`, `double_click`, `right_click`, `click_element`, `drag`, `scroll`, `type`, `key`, `focus`, `launch_app`, `read_clipboard` |

Perception is the UIA tree first, with screenshots as the fallback. Coordinate tools take
screenshot pixels plus the id of the image they came from, and the server maps them to physical
pixels (DPI-aware). Full tool contract: [`docs/spec-tools.md`](docs/spec-tools.md).

## Safety design

Every action call goes through the same guard pipeline, in a fixed order
([`docs/spec-safety.md`](docs/spec-safety.md)):

- **Human approval on every action.** Action tools are `ask` in Claude Code's permissions. The
  server refuses to start, and refuses each call, if any settings file has an `allow` entry for
  one of them (a "don't ask again" click turns into a refusal, not a silent bypass).
- **Two kill switches, one latch.** A global hotkey (`Ctrl+Shift+F12`) and human-takeover
  detection (cursor movement the server didn't cause, while an action is running) both write a
  `STOPPED` flag file. While it exists every tool refuses. Only the human clears it; a
  `PreToolUse` hook stops Claude's own shell and file tools from touching it.
- **Fail closed everywhere.** A failed hotkey registration, a dead watcher thread, an unreadable
  cursor, a malformed config or an elevated server process all mean refuse or don't start.
- **Input integrity.** Every action names a `target_window`. The server focuses it, checks that
  it really is in front (and stays in front between typed characters), and checks that the point
  being clicked belongs to it. Focus goes back to the previous window afterwards, so the next
  approval keystroke can't land in the target app.
- **Denylists.** NO-INPUT: terminals, VS Code, Explorer and the shell, Task Manager, the Run
  dialog. NO-CAPTURE: password managers, browser password pages and user-configured confidential
  folders. Those windows are redacted in `list_windows`, and no screenshot or UI tree is taken
  while one is visible.
- **Limits.** At most 40 actions per run, latched until reconnect. A key-combo allowlist (no bare
  `Win`, no `Win+R`). `launch_app` only starts Edge and Notepad, by absolute path. The clipboard
  is readable only right after the agent's own copy.
- **Nothing stored.** Screenshots stay in memory. The action log is JSON only: no window titles,
  no images, typed text recorded as its length.

The design was tested against reality: the live sessions found problems the unit tests couldn't,
such as Windows 11 Notepad restoring an old file into a "new" window, a dictation app swallowing
the kill hotkey, and Edge's address bar displaying the clipboard. Each one is written up in
[`memory.md`](memory.md) and fixed in code or in the run checklist.

## Setup

Windows 10 or 11, Python 3.14, Claude Code.

```
python -m venv %USERPROFILE%\.venvs\desktop-hands-mcp
%USERPROFILE%\.venvs\desktop-hands-mcp\Scripts\python.exe -m pip install -r requirements.txt
python init.py
```

`init.py` runs the test suite and checks the settings and hooks. Then start Claude Code from the
repo root: `.mcp.json` registers the server, and `.claude/settings.json` holds the permission
rules. Optional extra protection goes in `%USERPROFILE%\.desktop-hands\config.toml`:

```toml
[no_capture]
patterns = ["my-private-folder"]   # window titles or Explorer paths to never capture
processes = ["Enpass.exe"]         # password managers not covered by default
```

Before a live run: close password managers and confidential windows, keep nothing sensitive in
the clipboard, and approve prompts with the keyboard. Then try `/demo`.

## How it was built

It was built with Claude Code in a Planner → Builder → Reviewer loop (`roles/`), one spec-backed
task per commit (`docs/plan.md`), with every lesson from a failed review or live run appended to
`memory.md`. There are 458 unit tests, and all Win32 calls are faked: no test touches the real
desktop.

## Limits (v1)

Primary monitor only. Detecting VS Code's integrated terminal isn't possible through UIA, so the
whole VS Code window is NO-INPUT. `click_element` can't target classic Win32 menu items (the
fallback is a screenshot click). The denylists are defense in depth, not a guarantee.

## License

MIT, see [`LICENSE`](LICENSE).