Metadata-Version: 2.4
Name: omni-desktop-mcp
Version: 0.1.0
Summary: Desktop automation MCP server: compact UIA tree diffs, native Windows OCR (Chinese + English), background-first input delivery, and safety guardrails. Windows is the supported platform; macOS and Linux backends are experimental stubs.
Author: yangdw2024
License-Expression: MIT
Project-URL: Homepage, https://github.com/yangdw2024/omni-desktop-mcp
Project-URL: Issues, https://github.com/yangdw2024/omni-desktop-mcp/issues
Keywords: mcp,model-context-protocol,computer-use,desktop-automation,uiautomation,ocr,windows,deepseek-harness
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Operating System :: Microsoft :: Windows
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: mcp<3,>=2.0
Requires-Dist: pillow>=10.0
Requires-Dist: uiautomation>=2.0; sys_platform == "win32"
Requires-Dist: pywin32>=306; sys_platform == "win32"
Dynamic: license-file

# Omni-Desktop-MCP

An [MCP](https://modelcontextprotocol.io) server that lets an AI agent observe and operate desktop applications through three stable tools.

> **Platform status**
>
> | Platform | Status |
> |---|---|
> | Windows 10/11 | Implemented and tested (see [Testing](#testing)). |
> | macOS | Experimental stub: window listing and screenshots only; input actions return `unsupported_on_current_host`. Not tested on macOS hardware. |
> | Linux | Experimental stub using `wmctrl`/`xdotool` when present. Not tested on a Linux desktop. |
>
> This is alpha software (0.1.0). It can click, type, and close windows on your machine. Read [Safety](#safety) first.

## What it does

- **Three tools** (a small, fixed tool list keeps prompts and caches stable): `desktop_observe`, `desktop_act`, `desktop_status`.
- **Compact UI Automation tree** with one line per interactive control, plus `diff=true` to return only added (`+`), changed (`~`), and removed (`-`) controls since the last observation of that window.
- **OCR on Windows** through the built-in WinRT OCR engine (Chinese and English language packs, whichever are installed), mapped back to screen coordinates, as a fallback for UIs that expose no accessibility tree.
- **Background-first input**: `desktop_act` tries UIA patterns (Invoke, Value, Toggle, SelectionItem, ExpandCollapse, Scroll) first, which move no cursor and change no focus. If that is unavailable it falls back to foreground `SendInput`, then to a foreground-lock workaround, and restores the previous foreground window by default.
- **Unicode-safe typing**: UIA ValuePattern with read-back verification, otherwise Unicode `SendInput`, or a clipboard paste that restores the previous clipboard text.
- **Guardrails**: stale-snapshot rejection, a 5 s repeat suppressor, a blocklist of dangerous hotkeys, and protection against closing system and harness windows.

## Install

```powershell
pip install omni-desktop-mcp
```

Requires Python 3.10+ and `mcp` 2.x (installed automatically). Windows dependencies (`pywin32`, `uiautomation`) are installed automatically on Windows.

Run it directly:

```powershell
omni-desktop-mcp                                   # stdio
omni-desktop-mcp --http --host 127.0.0.1 --port 8765   # Streamable HTTP
```

### Register with your clients

Preview which config files would change (nothing is written):

```powershell
omni-desktop-mcp-install
```

Apply (existing files are backed up to `*.bak-<timestamp>` first; a file that fails to parse is left alone):

```powershell
omni-desktop-mcp-install --apply
omni-desktop-mcp-install --apply --only codex,trae
```

It knows about Antigravity (`~/.gemini`), Codex (`~/.codex/config.toml`), and Trae CN, only touches clients whose config directory already exists, and also installs the bundled usage skill for DeepSeek Harness, Codex, and Trae CN where a skills directory exists.

Or add it by hand. Generic snippets are in [`clients/doubao-mcp.json`](clients/doubao-mcp.json), for example:

```json
{
  "mcpServers": {
    "omni-desktop": {
      "command": "python",
      "args": ["-m", "omni_desktop_mcp"],
      "env": { "PYTHONIOENCODING": "utf-8" }
    }
  }
}
```

If `python` on your PATH is not the one you installed into, use the absolute path to that `python.exe`.

**DeepSeek Harness** can mount it as a configuration-only bundle using its built-in MCP client:

```yaml
- insert:
    - id: omni-desktop-mcp
      name: '@deepseek-ai/dsh-mcp-client'
      config:
        serverName: desktop
        transport: stdio
        command: C:\path\to\python.exe
        args: [-m, omni_desktop_mcp]
        env: { PYTHONIOENCODING: utf-8 }
        toolCallTimeoutMs: 120000
        startupTimeoutMs: 25000
        failOnStartupError: false
```

## Tools

- `desktop_observe(mode, window, diff, max_elements, ocr_lang, include_image, annotate, region)`: `mode` is `windows`, `tree`, `ocr`, `screenshot`, or `hybrid`. If `tree` finds no interactive controls it automatically adds OCR. Images are capped at 1920x1080.
- `desktop_act(action, target, window, snapshot_id, delivery, ...)`: `click`, `double_click`, `right_click`, `move`, `drag`, `scroll`, `type`, `press_key`, `hotkey`, `window_focus`, `window_state`, `launch_app`, `wait_for`, `batch`. `target` is a ref such as `w1:e3` / `w1:o2` from the latest observation, or `{x, y}` in physical screen pixels.
- `desktop_status(command)`: `health`, `policy`, `reset_guard`, `clear_snapshots`.

## Safety

This is not a sandbox. Anything the logged-in user can do with mouse and keyboard, an agent connected to this server can do.

- Dangerous hotkeys (`Ctrl+Alt+Del`, `Win+L`, `Shift+Del`, `Alt+F4`) and closing protected windows are refused unless `allow_dangerous=true` is passed. Treat that flag as something a human grants, not something an agent decides.
- Holding `Esc` aborts the current action; the key is polled at dispatch and between batch/drag steps, not inside a single OS call. No global input hooks are installed.
- The HTTP transport has **no authentication**. Keep it on `127.0.0.1`. Do not expose it to a network.
- Windows UIPI: a non-elevated server cannot drive an elevated window; such actions fail with `foreground_unavailable` rather than reporting success.
- Screenshots and OCR text can contain secrets that are on screen. They are returned to the connected client.

## Known limitations

- OCR is imperfect (for example `CLICKED` was read as `CL℃KED` in our own test). Do not rely on a single exact OCR string to confirm an action.
- Coordinates are physical screen pixels. The process declares Per-Monitor DPI v2 awareness; behaviour on unusual multi-monitor layouts has only been checked on one two-monitor machine.
- UIA tree walks are time-limited (2 s) and breadth-first with a node cap, so very large trees come back truncated and flagged.
- No latency or accuracy benchmarks against other desktop-automation servers have been run, so none are claimed.

## Testing

```powershell
pip install pytest
pytest
```

The unit tests cover snapshot diffing, stale refs, and the safety guard. `tests/test_windows_e2e.py` launches a temporary Tk window and drives it through observe, type, OCR, click, and screenshot; it needs an interactive Windows desktop and will briefly take foreground focus.

## License

MIT. See [LICENSE](LICENSE).
