Skip to main content
Glama
kde-desktop-mcp

kde-desktop-mcp

by marvin1099
README.md
# KDE Desktop Automation

A Python toolkit, CLI, and MCP server for inspecting and automating KDE Plasma.
It defaults to a separate, private KWin session; access to the live desktop must
be selected explicitly.

[Codeberg (primary)](https://codeberg.org/marvin1099/kde-desktop-automation) ·
[GitHub mirror](https://github.com/marvin1099/kde-desktop-automation)

> **Prototype:** support depends on the installed KDE/Wayland components and
> system utilities. Input is best-effort and does not prove an application acted
> on it. A private session isolates its compositor and home directory, but is
> **not a security sandbox** and runs as your Unix user.

## What it can do

- Create private virtual desktops and launch applications inside them.
- Auto-stop private sessions after six hours by default; extend their lease,
  make one indefinite with `-1`, or stop it explicitly.
- Observe windows, displays, pointer/focus context, and capture full-desktop,
  output-region, or individual-window screenshots.
- Create reusable output-bound region handles for cropped observations and
  region-local pointer clicks/drags, without changing window-ID controls.
- Find, inspect, activate, minimize/restore, and place windows; send guarded
  keyboard/text input and coordinate clicks/drags. Query the active window
  read-only, and probe input paths with a pointer health check that reports
  what was actually verified versus merely submitted.
- Inspect and control MPRIS media players.
- Inspect and change live PipeWire audio settings (live desktop only).
- Temporarily inhibit sleep, KDE screen locking, and other available power
  actions on the live desktop, with timed or explicit release.
- Expose the same target-aware operations through an stdio MCP server.

Capabilities vary by target and installed tools. There is no accessibility tree,
OCR-based control discovery, or app-specific action API yet. See the
[usage guide](docs/usage.md) for exact commands and limitations.

## Requirements

- Linux with KDE Plasma on Wayland; private sessions use KWin's virtual-output
  backend. Exact support depends on the installed Plasma/KWin version.
- Python 3.12 or newer and [uv](https://docs.astral.sh/uv/) to install from a
  checkout.
- Optional system utilities provide additional features. Run `kde-desktop
  doctor` to see which are available; per-target `capabilities` reports what can
  be used.
- Screenshots use KWin Screenshot2 through a separately built and authorized
  native helper; Spectacle is not used. See the [usage guide](docs/usage.md#kwin-screenshot2-helper).

## Quick start

```bash
git clone https://codeberg.org/marvin1099/kde-desktop-automation.git
cd kde-desktop-automation
uv sync
uv run kde-desktop doctor
uv run kde-desktop session create --name agent --width 1280 --height 800 --json
```

Copy the `session_id` from the result and use it for commands in that private
desktop:

```bash
SESSION_ID='agent-...'
uv run kde-desktop --session "$SESSION_ID" observe --json
uv run kde-desktop session launch "$SESSION_ID" -- kate --new /tmp/agent-note.txt
uv run kde-desktop --session "$SESSION_ID" screenshot --output /tmp/agent.png --json
uv run kde-desktop session stop "$SESSION_ID"
```

To deliberately target the real desktop, pass `--session user-desktop` on each
command. Private sessions cannot see host windows or media players. Do not run
untrusted applications in them: they are not an OS-level sandbox.

## MCP server

After `uv sync`, configure your MCP client to launch `kde-desktop-mcp` from this
checkout. OpenCode users in this repository are configured by the project-local
`opencode.json`, which starts the stdio server with `uv run kde-desktop-mcp`.
Other MCP clients can use:

```json
{
  "mcpServers": {
    "kde-desktop": {
      "command": "uv",
      "args": [
        "run",
        "--directory",
        "/absolute/path/to/kde-desktop-automation",
        "kde-desktop-mcp"
      ]
    }
  }
}
```

Every MCP desktop call requires an explicit `session` value: a managed session
ID or `user-desktop` when intentionally using the live desktop.

## Safety essentials

- A missing or stopped private session never falls back to the live desktop.
- Window-targeted input requires that window to already be active; it is guarded
  by focus, not atomically routed to the window.
- Global clicks and drags use logical desktop coordinates, move the pointer, and
  may change focus. A successful input receipt is not proof of an app effect;
  inspect again and verify the result independently.
- Window placement is a KWin frame-geometry request. KWin may constrain it; the
  tool reads back and reports the effective geometry.
- Audio controls are live-desktop-only. Private sessions do not provide an
  isolated audio server.
- Power inhibitors affect the real host; indefinite inhibitors remain active
  until explicitly released with their returned ID.

## Guides

- [CLI and MCP usage](docs/usage.md)
- [Examples](docs/examples.md)
- [Interface and design notes](docs/interface.md)
- [Automation roadmap](docs/automation-roadmap.md)
- [Release process](docs/releasing.md)

## Development

```bash
uv sync --all-groups
uv run pytest -q
uv run ruff check .
uv run ruff format --check .
uv run mypy src
uv build
```

The private-KWin tests are opt-in. The Dolphin-to-Kate drag test additionally
requires Dolphin, Kate, `kdotool`, and `wl-paste`:

```bash
KDE_DESKTOP_RUN_KWIN_INTEGRATION=1 \
KDE_DESKTOP_RUN_KWIN_DND_INTEGRATION=1 \
uv run pytest tests/test_kwin_integration.py::test_private_dolphin_drag_and_drop_opens_file_in_kate -q
```

## License

Licensed under the [GNU Affero General Public License v3.0 only](LICENSE).

TDQS

B3.4/5.0

Scored across 32 tools

Disambiguation4/5

Most tools are clearly partitioned by domain and action (session_*, window_*, input_*, audio_*, media_*), and descriptions actively disambiguate near-pairs like click vs click_at (window-relative vs global) and media_control vs media_seek_to (relative vs absolute). Minor residual overlap remains: kde_screenshot vs kde_desktop_observe (which also returns screenshot content), and kde_window_find/wait/list/inspect all target the same resource from different angles.

Naming Consistency5/5

Every tool follows the same kde_<domain>_<verb>_<noun> snake_case pattern (kde_session_create, kde_audio_set_volume, kde_media_seek_to, kde_window_set_geometry). The domain prefix groups tools predictably and no mixed conventions appear.

Tool Count3/5

32 tools is heavy for a single server, though the count is spread across seven genuinely distinct subsystems (sessions, windows, input, audio, media, display, screenshot) rather than being padding. It sits at the edge where an agent must scan a large surface to pick a tool, but each tool still maps to a real operation.

Completeness3/5

Coverage is broad and lifecycle-ish for sessions, audio, media, and window placement/state, but there are notable desktop-automation gaps: no window close/kill tool and no mouse scroll/wheel input, both of which are core to GUI automation and would force workarounds. Session management also lacks an explicit delete (only stop/launch).

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues