Metadata-Version: 2.4
Name: omni-desktop-mcp
Version: 0.2.0
Summary: High-efficiency desktop automation MCP server: COM UIA CacheRequest diffs, background PrintWindow capture, dual RapidOCR + WinRT OCR, one-shot find_and_act, parameterized macro playbooks, and safety guardrails. Windows is supported; 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"
Provides-Extra: ocr
Requires-Dist: rapidocr>=2.0; python_version >= "3.13" and extra == "ocr"
Requires-Dist: onnxruntime>=1.19; python_version >= "3.13" and extra == "ocr"
Requires-Dist: rapidocr-onnxruntime<2,>=1.4.0; python_version < "3.13" and extra == "ocr"
Dynamic: license-file

# Omni-Desktop-MCP

An [MCP](https://modelcontextprotocol.io) server that lets an AI agent observe and operate desktop applications efficiently through **three stable tools** (`desktop_observe`, `desktop_act`, `desktop_status`).

> **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.2.0). It can click, type, and close windows on your machine. Read [Safety](#safety) first.

## What is new in v0.2.0

- **3–4× faster Windows UIA inspection**: single-RPC COM `IUIAutomation.FindAllBuildCache` on a dedicated STA thread (with automatic BFS fallback) plus live COM element handle caching for sub-20 ms background L1 `Invoke` / `Value` / `Scroll` calls. On local testing (Microsoft Edge), COM CacheRequest ran in **130 ms** vs **405 ms** for Python BFS; on DeepSeek Harness (Electron), **417 ms** for 213 elements vs **1538 ms** truncated at 78.
- **Background capture without stealing focus**: `PrintWindow(PW_RENDERFULLCONTENT)` reads obscured Windows apps cleanly (with automatic correction for DPI-unaware windows under >100% Windows scaling and black-frame fallback to screen grab).
- **Adaptive dual-engine OCR + frame-hash cache**: automatically uses offline **RapidOCR** (`pip install "omni-desktop-mcp[ocr]"`) when installed and falls back cleanly to zero-dependency **WinRT OCR** (Chinese + English). Identical frames return from the micro-cache in ~1–2 ms.
- **50%+ fewer LLM round-trips**:
  - `observe_after="diff|tree|ocr|hybrid|screenshot"` + `settle_ms` merges post-action observation into `desktop_act`.
  - `action="find_and_act"` finds a control by label (UIA first, background OCR fallback) and acts in one call.
  - **Parameterized Macro Playbooks** (`macro_record_start`, `macro_record_stop`, `macro_save`, `macro_run`, `macro_delete`, `desktop_status(command="macros")`): persist reusable multi-step JSON playbooks under `~/.omni-desktop/macros/` with `{{var}}` substitution, `dry_run` preview, and full `SafetyGuard` enforcement.

## Install

```powershell
# Core (zero-dependency Windows WinRT OCR)
pip install omni-desktop-mcp

# Recommended: include offline high-accuracy RapidOCR (PP-OCR)
pip install "omni-desktop-mcp[ocr]"
```

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 installs the bundled `omni-desktop-control` skill for DeepSeek Harness, Codex, and Trae CN where a skills directory exists.

Or configure manually using snippets in [`clients/doubao-mcp.json`](clients/doubao-mcp.json):

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

**DeepSeek Harness**: the repository root is also a configuration-only DSH bundle (`package.json` with `dsh.bundle`, plus `cordis.patch.yml`) that mounts the server through DSH's built-in MCP client. Run `pip install omni-desktop-mcp` first; if `python` on DSH's PATH is not the environment you installed into, set `command` to the absolute path of that `python.exe`.

## Tools

Keeping the tool surface fixed at 3 tools protects client prompt caches:

1. **`desktop_observe(mode, window, diff, max_elements, ocr_lang, ocr_engine, include_image, annotate, background_capture, region)`**
   - `mode`: `windows`, `tree`, `ocr`, `screenshot`, `hybrid`. If `tree` finds 0 interactive controls, it automatically adds OCR. Images are capped at 1920×1080.
2. **`desktop_act(action, ...)`**
   - Actions: `click`, `double_click`, `right_click`, `move`, `drag`, `scroll`, `type`, `press_key`, `hotkey`, `window_focus`, `window_state`, `launch_app`, `wait_for`, `find_and_act`, `batch`, `macro_record_start`, `macro_record_stop`, `macro_save`, `macro_run`, `macro_delete`.
   - Delivery: `auto` (L1 background UIA → L2 foreground `SendInput` → L3 foreground-lock bypass with focus restore), `background`, or `foreground`.
   - `observe_after`: `"none" | "diff" | "tree" | "ocr" | "hybrid" | "screenshot"` appends post-action state after `settle_ms`.
3. **`desktop_status(command)`**
   - `health`, `policy`, `macros`, `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 (DSH, Explorer, core Windows processes) are refused by default — including inside `batch` and `macro_run` — unless `allow_dangerous=true` is explicitly passed.
- Holding `Esc` aborts the current action, drag, batch, or macro at dispatch and between steps. No global mouse hooks are installed (immune to zero-delta wireless mouse `WM_MOUSEMOVE` lockups).
- The HTTP transport has **no authentication**. Keep it bound to `127.0.0.1`.
- Windows UIPI: a non-elevated server cannot drive an elevated window; such actions fail with `foreground_unavailable`.

## Known limitations

- Without `[ocr]`, the zero-dependency WinRT OCR engine can misread small thin Latin fonts (for example reading `CLICKED` as `CL℃KED`). Installing `omni-desktop-mcp[ocr]` (RapidOCR) resolved this in our live E2E test.
- Some exclusive DirectX/OpenGL windows return a blank frame from `PrintWindow`; the backend detects this and falls back to screen capture (which requires the window to be visible on screen).
- No cross-project accuracy benchmark against other desktop-automation servers has been run; only local timing comparisons between our v0.1 BFS path and v0.2 COM path were measured.

## Testing

```powershell
pip install pytest
pytest -v
```

12 automated tests cover snapshot diffs, OCR routing & caching, macro CRUD/generalization/safety, safety guardrails, and a live Windows E2E test (`tests/test_windows_e2e.py`) that launches temporary Tk windows (including an obscured window behind an always-on-top cover window) to verify COM UIA, `PrintWindow` background capture + DPI correction, RapidOCR accuracy, `find_and_act` + `observe_after`, and macro playback.

## License

MIT. See [LICENSE](LICENSE).
