Repository avatar
Other Tools
v0.5.0
active

plasma-mcp

io.github.RJCogburn/plasma-mcp

Safely control KDE Plasma 6 desktops from MCP agents

Documentation

plasma-mcp

An MCP server that lets AI agents (Claude Code, Codex, Cursor and other MCP clients) see and control a KDE Plasma 6 desktop. It works through KDE's own interfaces (D-Bus, KWin scripting and KConfig) instead of screenshots and simulated clicks.

Every write can be previewed and undone. Ask your agent to "tile my editor next to the browser", "switch to a dark theme" or "tell me when the build notification arrives".

Contents

Requirements

  • KDE Plasma 6 (tested on Plasma 6.8, Wayland, CachyOS)
  • Python 3.12+ and uv
  • kreadconfig6 / kwriteconfig6 and the plasma-apply-* tools, which ship with Plasma
  • Optional: KDE Customizer (kdec on your PATH), required only for the theme tools

Install

From a release

Install the MCP server as a user tool:

uv tool install plasma-mcp

The executable will be available as plasma-mcp.

Register it with Claude Code:

claude mcp add --scope user plasma -- plasma-mcp

For another MCP client, configure it to run plasma-mcp over stdio.

From source

git clone https://github.com/RJCogburn/plasma-mcp.git
cd plasma-mcp
uv sync

Register it with Claude Code for all your projects:

claude mcp add --scope user plasma -- uv --directory /path/to/plasma-mcp run plasma-mcp

Start a new Claude Code session; the tools appear as mcp__plasma__*.

For other MCP clients, run the stdio command uv --directory /path/to/plasma-mcp run plasma-mcp.

Theme tools (optional)

Either install method needs KDE Customizer for the theme tools:

uv tool install git+https://github.com/RJCogburn/kde-customizer

Upgrading

uv tool upgrade plasma-mcp

Tools

The tier column refers to the permission tiers described below.

Settings

ToolTierWhat it does
get_settingreadRead a KConfig value, e.g. kwinrc / Windows / FocusPolicy. Nested groups use /.
set_settingwriteWrite a KConfig value. Dry run by default.
undo_lastwriteRestore the most recent snapshot (settings or theme).

Windows

ToolTierWhat it does
list_windowsreadEach window's id, app, title, desktops, geometry and active/minimized state, plus the virtual desktops.
focus_windowwriteActivate a window. It un-minimizes it and switches to its desktop.
move_to_desktopwriteMove a window to a virtual desktop, by name or 1-based number.
tile_windowwriteTile it to the left / right / top / bottom half, maximize or unmaximize.

Theming (needs KDE Customizer)

ToolTierWhat it does
current_themereadThe global theme, color scheme, Plasma style, icons and cursor in use.
theme_guidereadThe theme spec format. Agents read this before writing a theme.
check_themereadValidate a .toml theme spec (contrast, missing installed themes).
apply_themewriteBuild and apply a spec. Dry run by default. It shows the exact install script. layout=true also replaces panels and needs the dangerous tier.

Notifications

ToolTierWhat it does
notifywriteShow a notification (low / normal / critical). Returns its id.
close_notificationwriteClose a notification by id.
notification_statusreadServer info and whether Do Not Disturb is on.
watch_notificationsprivateCollect notifications from any app for up to 120 s.

Media

ToolTierWhat it does
media_statusreadMPRIS players with playback status and the current track.
media_play_pausewriteToggle play/pause on a player.

Power

ToolTierWhat it does
power_statusreadAC or battery, the lid, laptop batteries, wireless peripherals (mouse, keyboard, headset) and the power profile.
set_power_profilewriteSwitch between power-saver, balanced and performance. Dry run by default. The response names the previous profile (it isn't a config file, so undo_last doesn't cover it).

Global shortcuts

ToolTierWhat it does
list_shortcutsreadEvery global shortcut with current and default keys. Search by text, by key (key="Meta+E" answers "what uses Meta+E?") or by component.
set_shortcutwriteSet or remove (keys=[]) an action's keys. Refuses keys another action already uses. Dry run by default.
invoke_shortcutdangerousTrigger an action directly, without simulating a key press. Dry run by default.

Keys use the names System Settings shows, such as Meta+Ctrl+A, Meta+Shift+Left or Volume Up. Super and Win are accepted for Meta. invoke_shortcut is in the dangerous tier because some actions log out, shut down or close windows without asking.

Clipboard

ToolTierWhat it does
get_clipboardprivateThe current clipboard text.
clipboard_historyprivateRecent clipboard entries, newest first.
set_clipboardwritePut text on the clipboard. Dry run by default. The previous contents stay in clipboard history.

Clipboards often hold passwords and private messages, so reading needs the private tier. Password managers mark secrets so Klipper never records them; plasma-mcp never sees those.

Panels and widgets

ToolTierWhat it does
list_panelsreadPanels (screen, location, height, alignment, hiding, length mode, floating) with their widgets in on-screen order, plus the desktops and their widgets.
list_widget_typesreadInstalled widget plugins, e.g. org.kde.plasma.digitalclock. search filters.
get_widget_configreadA widget's options in one config group (e.g. Appearance).
add_widgetdangerousAdd a widget to a panel (at the end or before another widget) or to a desktop. Dry run by default.
remove_widgetdangerousRemove a widget. Dry run by default.
set_paneldangerousChange a panel's location, height, alignment, hiding, length mode or floating. Dry run by default.
add_paneldangerousCreate a panel on a screen with a list of widgets. Dry run by default.
remove_paneldangerousRemove a panel and its widgets. Dry run by default.
set_widget_configdangerousSet one widget option, e.g. a clock's showSeconds. Dry run by default.

Panel changes are in the dangerous tier because undoing them restarts plasmashell (your panels disappear for a second or two). They are still snapshotted and undoable.

Events

ToolTierWhat it does
subscribe_eventsread (notifications: private)Start buffering events of the given kinds in the background. Returns a cursor.
poll_eventsreadEvents after cursor, oldest first, plus the next cursor. wait_seconds (up to 120) waits for the first event.
unsubscribe_eventsreadStop listening (all kinds when none are given).
KindEvents
windowswindow_opened, window_closed, window_focused (with the window's id, app, title, geometry)
desktopsdesktop_switched, desktop_added, desktop_removed, desktop_renamed
mediaplayback (Playing / Paused / Stopped), track, player_opened, player_closed
configconfig_changed: which KConfig file, groups and keys changed (names only, no values)
screenscreen_locked, screen_unlocked
notificationsnotification from any app (app, summary, body, urgency). Needs the private tier.
clipboardclipboard_changed with the new text (first 2000 characters). Needs the private tier.
poweron_battery, on_ac, battery_level (every 5%), battery_state, battery_warning, device_added, device_removed, profile_changed, lid_closed, lid_opened, suspending, resumed, shutting_down

An agent subscribes once and then polls in a loop, for example: "subscribe to windows and media, then tell me when a new window opens". Events are kept until they're read, so nothing is lost between calls. The buffer holds the last 1000, and poll_events reports missed if older ones were dropped.

Permissions

Tools are grouped into tiers. You choose which tiers are enabled in ~/.config/plasma-mcp.toml:

[tiers]
read = true        # default: on
write = true       # default: on  (every write is previewable and undoable)
dangerous = false  # default: off (panel and widget changes; undo restarts plasmashell)
private = false    # default: off (reading other apps' notifications and the clipboard)

When a tool's tier is off, the call fails with an error that names the tier and this file.

Undo and snapshots

Every real write first copies the config files it can touch to ~/.local/state/plasma-mcp/snapshots/. undo_last restores the newest snapshot and deletes it, so repeated calls step further back.

Restoring files alone doesn't change a desktop that's already running, so theme snapshots also record what was active: global theme, color scheme, Plasma style, cursor and icons. On undo, plasma-mcp re-applies those first, then copies the files back. A theme change and its undo leave your config byte-for-byte as it was. This was verified on a live desktop.

Two KDE details matter here:

  • A global theme's values live in ~/.config/kdedefaults/, not in the files you would expect. Snapshots include that folder.
  • plasmashell keeps the panel layout in memory, writes it back when it exits, and writes panel settings (height, alignment, ...) to disk about 10 seconds after a change. So layout undo (panel tools and apply_theme(layout=true)) stops plasmashell, copies the files back, starts it again, then re-applies each panel's settings as they were live when the snapshot was taken. Verified live: a panel removed seconds after being changed comes back exactly as it was.

How it works

  • Settings: kreadconfig6 / kwriteconfig6.
  • Windows: a KWin script can't return a value to whoever loaded it. So for each call, plasma-mcp exports a small D-Bus object, loads a one-shot script that calls back to it with JSON (callDBus), then unloads the script. See plasma_mcp/kwin.py; new KWin features can reuse kwin.run(js).
  • Theming: shells out to KDE Customizer's kdec (check, apply, ai-guide) rather than importing it, so the theme format and its install script stay in one place.
  • Notifications: org.freedesktop.Notifications. Watching uses a D-Bus monitor connection (BecomeMonitor) that only matches Notify calls.
  • Media: MPRIS over the session bus.
  • Power: on the system bus. UPower for AC, lid and batteries (including wireless peripherals), power-profiles-daemon for the profile, and logind's PrepareForSleep / PrepareForShutdown for suspend, resume and shutdown events.
  • Global shortcuts: kglobalaccel (org.kde.kglobalaccel). Keys travel as Qt key codes; plasma_mcp/qtkeys.py maps them to names and is generated from Qt itself (scripts/gen_qtkeys.py). kglobalaccel keeps shortcuts in memory, so undo sets the old keys back over D-Bus before restoring kglobalshortcutsrc.
  • Clipboard: Klipper (org.kde.klipper, part of plasmashell). Clipboard events listen for clipboardHistoryUpdated and report only when the text actually changed.
  • Panels and widgets: plasmashell's desktop scripting API (org.kde.PlasmaShell.evaluateScript). Tool arguments are passed to the script as a JSON value, never spliced into its code. See plasma_mcp/shell.py.
  • Events: one shared D-Bus connection with signal matches for desktops, screen lock, KConfig changes and MPRIS, plus a monitor connection for notifications. Window events come from a long-running KWin script (plasma_mcp_events) that calls back over D-Bus. Nothing listens until something subscribes, and everything (including the KWin script) is removed on unsubscribe or when the server exits.

Limitations

  • Plasma 6 only. The KWin scripting API changed between Plasma versions; no GNOME backend yet.
  • No synthetic keyboard or mouse input. On Wayland that needs ydotool, libei or the RemoteDesktop portal, and it is out of scope for now.
  • No screenshots yet. When they come, they will go through xdg-desktop-portal so you approve each one.
  • Window geometry updates asynchronously. After tile_window, call list_windows again about half a second later to see the new size.
  • Fixed-size dialogs ignore tile and maximize.
  • Widgets can't be moved within a panel yet. plasmashell's scripting API can insert a new widget at a position but not reorder existing ones while it runs. Remove and re-add instead (the widget's settings are lost).
  • get_widget_config shows only options that have been set. Defaults aren't stored, so a fresh widget's group can look empty.
  • Shortcuts are single key combinations. KDE allows multi-chord sequences (e.g. Ctrl+X, Ctrl+S); set_shortcut sets one combination per key and list_shortcuts shows the first chord.
  • Clipboard is text only. Images and rich formatting aren't read, and set_clipboard puts plain text. Clearing the clipboard or its history isn't supported (it can't be undone).
  • Events are polled, not pushed. Agents call poll_events (with wait_seconds to block until something happens); MCP clients don't yet act on server-pushed events. KWin reports window_focused for a new window just before window_opened.
  • Do Not Disturb. While it is on, only critical notifications pop up. plasma-mcp never changes your Do Not Disturb setting.

Development

uv sync --extra dev
uv run pytest
  • Project notes and conventions for coding agents: CLAUDE.md.
  • Every new tool must call policy.require(<tier>), and every config write must go through snapshots.take before changing anything.
  • Test write tools on throwaway windows (a Tk or kdialog window you open yourself), never on the user's own windows.

License

MIT, see LICENSE.

PYPI
plasma-mcp
Install Command
pip install plasma-mcp