desktop-pilot
by NjProVk
README.md
# desktop-pilot — eyes and hands for AI on your computer (MCP)
A local MCP server that lets a connected multimodal model **see** the actual screen through
screenshots, zoom, the UI Automation / AT-SPI accessibility tree, and OCR. The model can
**act** using the mouse, keyboard, windows, and applications, and **verify the result** of each action.
* The primary platform is **Windows 10/11**, fully tested on a real desktop.
* **Linux (Manjaro/Arch)** offers a full X11 implementation and experimental Wayland support (see limitations).
* The server uses **stdio**, with no cloud service or paid APIs. It uses Python 3.11+ and the official MCP SDK v2.
```
model ──MCP/stdio──► desktop-pilot ──► platform backend ──► OS
│ observations (obs_N) + exact coordinate mapping
│ serialized, cancellable input + tracking of held keys
└─ verification: before/after (pixels, windows, focus, field text via UIA)
```
## Capabilities
| Group | Tools |
|---|---|
| Observation | `desktop_state`, `screenshot` (monitor / all monitors / window / region, set-of-marks, grid, OCR), `zoom`, `ui_elements`, `inspect_point` |
| Synchronization | `wait_for` (window appears, disappears, or gains focus, element appears or disappears, screen changes or stabilizes, OCR detects text) |
| Mouse | `mouse_move`, `click` (1–3 clicks, any mouse button, modifiers, long press), `drag`, `scroll` (vertical / horizontal) |
| Keyboard | `type_text` (any Unicode text, including Cyrillic and line breaks, with clipboard paste and restore), `press_keys` (shortcuts and sequences), `hold_input` (hold keys or buttons) |
| Accessibility | `ui_action` (invoke, toggle, select, expand/collapse, set_value, focus, scroll_into_view) |
| Windows and applications | `window_control` (activate, minimize, maximize, restore, move, resize), `window_close`, `launch` (program, file, URL) |
| Other | `clipboard` (get/set), `run_sequence` (up to 30 steps run atomically, with intermediate screenshots) |
See the [tool reference](docs/TOOLS.md), [coordinate systems](docs/COORDINATES.md), [example workflows](docs/SCENARIOS.md), and [known limitations](docs/LIMITATIONS.md).
## See → act → verify
1. `screenshot` returns an **image** (MCP `ImageContent`, PNG/JPEG) and metadata. Metadata includes `observation_id`,
the source screen region, image dimensions, scale, mapping formula, monitor and its DPI, cursor,
active window, and windows in the image.
2. The model supplies a point **in image pixels** and `observation_id`, or an element `element_id`.
The server maps the point precisely to screen coordinates even if the image is downscaled by a factor of 2.7
(measured error ≤ 1 px on a 4K monitor at 150 % scale).
3. Before acting, the server checks that the same window is under the point and has stayed in place
since the observation. If the check fails, it returns `TARGET_CHANGED` / `TARGET_OCCLUDED` / `WINDOW_NOT_FOUND` and skips the click.
4. The result reports **execution** (`executed`) and **verification** (`verification`) separately:
| `verification.status` | Meaning |
|---|---|
| `confirmed` | The expected state was confirmed (field text was read, a checkbox was on, a window had focus, or a value was set) |
| `changed` | An observable change occurred (bounding box of changed pixels, opened or closed windows, or focus change). The model checks whether it matches expectations |
| `no_visible_change` | No visible change occurred. The action may have missed, so take a new observation |
| `failed` | Verification found a mismatch, such as unexpected text in a field |
| `unverifiable` / `not_checked` | Verification is unavailable (for example, a password field or access denied) / verification is disabled |
## Installation
Use [uv](https://docs.astral.sh/uv/) or standard `pip`. All dependencies are installed in the project's local `.venv`.
### Windows
```powershell
cd desktop-pilot-mcp
uv sync --extra ocr # without OCR: uv sync
uv run desktop-pilot diagnose
```
`diagnose` checks screen capture, the cursor, windows, input availability (UAC or session lock),
UI Automation, OCR, the clipboard, and emergency stop hotkey registration without sending any input.
### Manjaro / Arch (X11 recommended)
```bash
sudo pacman -S --needed python uv tk xclip at-spi2-core python-gobject tesseract tesseract-data-rus tesseract-data-eng
cd desktop-pilot-mcp
uv venv --python /usr/bin/python --system-site-packages # AT-SPI needs the system 'gi'
uv sync
uv run desktop-pilot diagnose
```
Alternatively, run [scripts/install_manjaro.sh](scripts/install_manjaro.sh). For Wayland, also run
`sudo pacman -S grim ydotool wtype wl-clipboard` and `systemctl --user enable --now ydotool`. On KDE, install `kdotool` from the AUR. See [known limitations](docs/LIMITATIONS.md) for details.
## Connect an MCP client
Use `<project>/.venv/Scripts/desktop-pilot.exe` on Windows or `<project>/.venv/bin/desktop-pilot` on Linux to start the server.
The stdio transport requires no arguments.
**Claude Code** (from any terminal):
```powershell
claude mcp add desktop-pilot -- "C:\tools\desktop-pilot\.venv\Scripts\desktop-pilot.exe"
```
**Claude Desktop** uses `%APPDATA%\Claude\claude_desktop_config.json` on Windows or `~/.config/Claude/claude_desktop_config.json` on Linux:
```json
{
"mcpServers": {
"desktop-pilot": {
"command": "C:\\tools\\desktop-pilot\\.venv\\Scripts\\desktop-pilot.exe",
"args": [],
"env": { "DESKTOP_PILOT_LOG_LEVEL": "INFO" }
}
}
}
```
See [connection examples](examples/) for Claude Desktop, Claude Code (`.mcp.json`), Cursor, `uv run`, and Linux.
On Linux, the server needs the session's `DISPLAY` / `WAYLAND_DISPLAY` variables. Start the client from
the graphical session or set those variables in `env`.
## Safety and user control
* **Emergency stop — `Ctrl+Alt+End`** (configurable). Immediately interrupts the current action and sequence,
releases all keys and buttons, and **blocks** further input with an audible signal. Observation
remains available. Only the user can unblock input by pressing the hotkey again. On Linux,
`pkill -USR1 -f desktop_pilot` also works. You can assign it to a global shortcut in KDE or GNOME settings.
On Wayland, this is the only hotkey option.
* **Mouse takeover**. If the user moves the mouse during a multistep action such as text entry,
a drag, or a sequence, the action stops with `USER_INTERRUPTED`.
* **Client cancellation** (MCP `notifications/cancelled`, or Stop/Esc in the client) interrupts the action at
the next checkpoint and releases all pressed keys.
* **Input release**. Shortcuts are sent in one atomic batch. Inputs pressed within an action are
released in `finally`. Explicit holds (`hold_input`) appear in every response and are automatically
released after 60 s. All inputs are released when the server shuts down (EOF, SIGTERM, Ctrl+C).
* **OS access controls**. Elevated windows return `PERMISSION_DENIED` (UIPI). The UAC prompt and lock screen return
`SECURE_DESKTOP`. The server cannot simulate Ctrl+Alt+Del.
* **Client-side confirmations**. Potentially destructive actions have their own tools and MCP
annotations (`destructiveHint` on `click`, `type_text`, `press_keys`, `window_close`, `launch`, `clipboard`, and `run_sequence`,
and `readOnlyHint` on observation tools). Clients can require confirmation for those actions and
allow screenshots without prompting.
* **Untrusted screen data**. Server instructions and tool descriptions tell the model to treat text
from the screen, UI elements, OCR, and the clipboard as untrusted data.
* **Privacy**. Screenshots, typed text, and clipboard contents **stay out of logs and off disk**.
Logs (stderr) contain only operation and error codes. On Windows, pasted text uses clipboard
formats that exclude it from clipboard history (Win+V) and cloud sync. To save screenshots
for debugging, explicitly set `DESKTOP_PILOT_DEBUG_SAVE_DIR`.
## Configuration (environment variables)
| Variable | Default | Description |
|---|---|---|
| `DESKTOP_PILOT_ESTOP_HOTKEY` | `ctrl+alt+end` | Emergency stop hotkey (`--hotkey`) |
| `DESKTOP_PILOT_ENABLE_HOTKEY` | `true` | Disable with `--no-hotkey` |
| `DESKTOP_PILOT_USER_INTERRUPT` | `true` | Interrupt the action when the user moves the mouse |
| `DESKTOP_PILOT_MAX_IMAGE_EDGE` / `_MAX_IMAGE_PIXELS` | `1568` / `1150000` | Screenshot size limit for the model |
| `DESKTOP_PILOT_IMAGE_FORMAT` | `auto` | `auto` (PNG if the image is small enough), `png`, `jpeg` |
| `DESKTOP_PILOT_VERIFY_BY_DEFAULT` | `true` | Before-and-after verification for actions |
| `DESKTOP_PILOT_SETTLE_TIMEOUT_MS` | `1500` | How long to wait for the UI to settle after an action |
| `DESKTOP_PILOT_MAX_HOLD_SECONDS` | `60` | Automatically release held keys |
| `DESKTOP_PILOT_LOG_LEVEL` / `_LOG_FILE` | `INFO` / — | Diagnostics (stderr/file only, with no user data) |
| `DESKTOP_PILOT_DEBUG_SAVE_DIR` | — | Directory for debug screenshots (disabled by default) |
| `DESKTOP_PILOT_LINUX_BACKEND` | Auto | Force `x11` or `wayland` |
## Tests
```powershell
uv run pytest -q # 81 tests (1 skipped on Windows without python-xlib):
# coordinates, keys, validation, errors, serialization,
# cancellation, emergency stop, the MCP layer, Linux logic
uv run python scripts/e2e_check.py # 18 scenarios on the REAL desktop (≈1 min)
```
`e2e_check.py` starts the server over stdio as a real MCP client, opens a safe Tk test application
([teststand/stand.py](teststand/stand.py)), and uses its JSON event log to verify the results. It checks
click accuracy against the image, button activation, Cyrillic input with line breaks, shortcuts,
holding Shift, clipboard paste and restore, scrolling, dragging, stale observations after moving a
window, cancellation during input, the emergency stop hotkey, closed windows, and timeouts. On Windows,
it also checks Calculator through UI Automation and a native WinForms test application
([teststand/stand_winforms.ps1](teststand/stand_winforms.ps1)) that verifies input by reading the field.
Leave the mouse alone while the tests run. See [test coverage and limitations](docs/LIMITATIONS.md).
## Project layout
```
src/desktop_pilot/
server.py MCP tools, schemas, response and error format, run_sequence
desktop.py platform-independent logic: observations, targets, checks, actions
controller.py input serialization, cancellation, emergency stop, tracking of held keys
verify.py before/after verification (pixel diff, windows, focus)
geometry.py rectangles and the exact image ↔ screen mapping
keys.py key names and shortcut parsing
state.py observations and the UI element registry (in memory only)
platform/windows Win32 (SendInput, DWM, GDI/PrintWindow), UI Automation (comtypes), WinRT OCR
platform/linux X11 (XTest, EWMH, XKB), AT-SPI, Wayland (experimental), tesseract
tests/ tests on a fake platform + Linux logic
scripts/ e2e_check.py, install_manjaro.sh
teststand/ safe test applications
examples/ MCP client configurations
```
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues