plasma-mcp 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 RJCogburn
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,228 @@
1
+ Metadata-Version: 2.4
2
+ Name: plasma-mcp
3
+ Version: 0.1.0
4
+ Summary: Safely control KDE Plasma 6 desktops from MCP agents
5
+ Author: RJCogburn
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/RJCogburn/plasma-mcp
8
+ Project-URL: Repository, https://github.com/RJCogburn/plasma-mcp
9
+ Project-URL: Issues, https://github.com/RJCogburn/plasma-mcp/issues
10
+ Keywords: mcp,kde,plasma,dbus,desktop,ai-agents
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Environment :: X11 Applications :: KDE
13
+ Classifier: Operating System :: POSIX :: Linux
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Topic :: Desktop Environment
17
+ Requires-Python: >=3.12
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Requires-Dist: mcp<3,>=2
21
+ Requires-Dist: dbus-next>=0.2.3
22
+ Provides-Extra: dev
23
+ Requires-Dist: build>=1.2; extra == "dev"
24
+ Requires-Dist: pytest>=8; extra == "dev"
25
+ Dynamic: license-file
26
+
27
+ # plasma-mcp
28
+
29
+ An [MCP](https://modelcontextprotocol.io) server that lets AI agents (Claude Code, Codex,
30
+ Cursor and other MCP clients) see and control a **KDE Plasma 6** desktop. It works through
31
+ KDE's own interfaces (D-Bus, KWin scripting and KConfig) instead of screenshots and
32
+ simulated clicks.
33
+
34
+ Every write can be previewed and undone. Ask your agent to "tile my editor next to the
35
+ browser", "switch to a dark theme" or "tell me when the build notification arrives".
36
+
37
+ ## Contents
38
+
39
+ - [Requirements](#requirements)
40
+ - [Install](#install)
41
+ - [Tools](#tools)
42
+ - [Permissions](#permissions)
43
+ - [Undo and snapshots](#undo-and-snapshots)
44
+ - [How it works](#how-it-works)
45
+ - [Limitations](#limitations)
46
+ - [Development](#development)
47
+
48
+ ## Requirements
49
+
50
+ - KDE Plasma 6 (tested on Plasma 6.8, Wayland, CachyOS)
51
+ - Python 3.12+ and [uv](https://docs.astral.sh/uv/)
52
+ - `kreadconfig6` / `kwriteconfig6` and the `plasma-apply-*` tools, which ship with Plasma
53
+ - Optional: [KDE Customizer](https://github.com/RJCogburn/kde-customizer) (`kdec` on your
54
+ `PATH`), required only for the theme tools
55
+
56
+ ## Install
57
+
58
+ ### From a release
59
+
60
+ Install the MCP server as a user tool:
61
+
62
+ ```sh
63
+ uv tool install plasma-mcp
64
+ ```
65
+
66
+ The executable will be available as `plasma-mcp`.
67
+
68
+ Register it with Claude Code:
69
+
70
+ ```sh
71
+ claude mcp add --scope user plasma -- plasma-mcp
72
+ ```
73
+
74
+ For another MCP client, configure it to run `plasma-mcp` over stdio.
75
+
76
+ ### From source
77
+
78
+ ```sh
79
+ git clone https://github.com/RJCogburn/plasma-mcp.git
80
+ cd plasma-mcp
81
+ uv sync
82
+ ```
83
+
84
+ Register it with Claude Code for all your projects:
85
+
86
+ ```sh
87
+ claude mcp add --scope user plasma -- uv --directory /path/to/plasma-mcp run plasma-mcp
88
+ ```
89
+
90
+ Start a new Claude Code session; the tools appear as `mcp__plasma__*`.
91
+
92
+ For other MCP clients, run the stdio command `uv --directory /path/to/plasma-mcp run plasma-mcp`.
93
+
94
+ ### Theme tools (optional)
95
+
96
+ Either install method needs KDE Customizer for the theme tools:
97
+
98
+ ```sh
99
+ uv tool install git+https://github.com/RJCogburn/kde-customizer
100
+ ```
101
+
102
+ ### Upgrading
103
+
104
+ ```sh
105
+ uv tool upgrade plasma-mcp
106
+ ```
107
+
108
+ ## Tools
109
+
110
+ The tier column refers to the permission tiers described [below](#permissions).
111
+
112
+ ### Settings
113
+
114
+ | Tool | Tier | What it does |
115
+ |---|---|---|
116
+ | `get_setting` | read | Read a KConfig value, e.g. `kwinrc` / `Windows` / `FocusPolicy`. Nested groups use `/`. |
117
+ | `set_setting` | write | Write a KConfig value. **Dry run by default.** |
118
+ | `undo_last` | write | Restore the most recent snapshot (settings or theme). |
119
+
120
+ ### Windows
121
+
122
+ | Tool | Tier | What it does |
123
+ |---|---|---|
124
+ | `list_windows` | read | Each window's id, app, title, desktops, geometry and active/minimized state, plus the virtual desktops. |
125
+ | `focus_window` | write | Activate a window. It un-minimizes it and switches to its desktop. |
126
+ | `move_to_desktop` | write | Move a window to a virtual desktop, by name or 1-based number. |
127
+ | `tile_window` | write | Tile it to the `left` / `right` / `top` / `bottom` half, `maximize` or `unmaximize`. |
128
+
129
+ ### Theming (needs KDE Customizer)
130
+
131
+ | Tool | Tier | What it does |
132
+ |---|---|---|
133
+ | `current_theme` | read | The global theme, color scheme, Plasma style, icons and cursor in use. |
134
+ | `theme_guide` | read | The theme spec format. Agents read this before writing a theme. |
135
+ | `check_theme` | read | Validate a `.toml` theme spec (contrast, missing installed themes). |
136
+ | `apply_theme` | write | Build and apply a spec. **Dry run by default.** It shows the exact install script. `layout=true` also replaces panels and needs the `dangerous` tier. |
137
+
138
+ ### Notifications
139
+
140
+ | Tool | Tier | What it does |
141
+ |---|---|---|
142
+ | `notify` | write | Show a notification (`low` / `normal` / `critical`). Returns its id. |
143
+ | `close_notification` | write | Close a notification by id. |
144
+ | `notification_status` | read | Server info and whether Do Not Disturb is on. |
145
+ | `watch_notifications` | **private** | Collect notifications from *any* app for up to 120 s. |
146
+
147
+ ### Media
148
+
149
+ | Tool | Tier | What it does |
150
+ |---|---|---|
151
+ | `media_status` | read | MPRIS players with playback status and the current track. |
152
+ | `media_play_pause` | write | Toggle play/pause on a player. |
153
+
154
+ ## Permissions
155
+
156
+ Tools are grouped into tiers. You choose which tiers are enabled in
157
+ `~/.config/plasma-mcp.toml`:
158
+
159
+ ```toml
160
+ [tiers]
161
+ read = true # default: on
162
+ write = true # default: on (every write is previewable and undoable)
163
+ dangerous = false # default: off (e.g. replacing your panel layout)
164
+ private = false # default: off (reading other apps' notifications, e.g. chat messages)
165
+ ```
166
+
167
+ When a tool's tier is off, the call fails with an error that names the tier and this file.
168
+
169
+ ## Undo and snapshots
170
+
171
+ Every real write first copies the config files it can touch to
172
+ `~/.local/state/plasma-mcp/snapshots/`. `undo_last` restores the newest snapshot and
173
+ deletes it, so repeated calls step further back.
174
+
175
+ Restoring files alone doesn't change a desktop that's already running, so theme snapshots
176
+ also record what was active: global theme, color scheme, Plasma style, cursor and icons.
177
+ On undo, plasma-mcp re-applies those first, then copies the files back. A theme change and
178
+ its undo leave your config byte-for-byte as it was. This was verified on a live desktop.
179
+
180
+ Two KDE details matter here:
181
+
182
+ - A global theme's values live in `~/.config/kdedefaults/`, not in the files you would
183
+ expect. Snapshots include that folder.
184
+ - Undoing `apply_theme(layout=true)` also restarts plasmashell to bring back your panels.
185
+
186
+ ## How it works
187
+
188
+ - **Settings**: `kreadconfig6` / `kwriteconfig6`.
189
+ - **Windows**: a KWin script can't return a value to whoever loaded it. So for each call,
190
+ plasma-mcp exports a small D-Bus object, loads a one-shot script that calls back to it
191
+ with JSON (`callDBus`), then unloads the script. See `plasma_mcp/kwin.py`; new KWin
192
+ features can reuse `kwin.run(js)`.
193
+ - **Theming**: shells out to KDE Customizer's `kdec` (`check`, `apply`, `ai-guide`) rather
194
+ than importing it, so the theme format and its install script stay in one place.
195
+ - **Notifications**: `org.freedesktop.Notifications`. Watching uses a D-Bus monitor
196
+ connection (`BecomeMonitor`) that only matches `Notify` calls.
197
+ - **Media**: MPRIS over the session bus.
198
+
199
+ ## Limitations
200
+
201
+ - **Plasma 6 only.** The KWin scripting API changed between Plasma versions; no GNOME
202
+ backend yet.
203
+ - **No synthetic keyboard or mouse input.** On Wayland that needs ydotool, libei or the
204
+ RemoteDesktop portal, and it is out of scope for now.
205
+ - **No screenshots yet.** When they come, they will go through xdg-desktop-portal so you
206
+ approve each one.
207
+ - **Window geometry updates asynchronously.** After `tile_window`, call `list_windows`
208
+ again about half a second later to see the new size.
209
+ - **Fixed-size dialogs** ignore tile and maximize.
210
+ - **Do Not Disturb.** While it is on, only `critical` notifications pop up. plasma-mcp never
211
+ changes your Do Not Disturb setting.
212
+
213
+ ## Development
214
+
215
+ ```sh
216
+ uv sync --extra dev
217
+ uv run pytest
218
+ ```
219
+
220
+ - Project notes and conventions for coding agents: `CLAUDE.md`.
221
+ - Every new tool must call `policy.require(<tier>)`, and every config write must go
222
+ through `snapshots.take` before changing anything.
223
+ - Test write tools on throwaway windows (a Tk or `kdialog` window you open yourself),
224
+ never on the user's own windows.
225
+
226
+ ## License
227
+
228
+ MIT, see [LICENSE](LICENSE).
@@ -0,0 +1,202 @@
1
+ # plasma-mcp
2
+
3
+ An [MCP](https://modelcontextprotocol.io) server that lets AI agents (Claude Code, Codex,
4
+ Cursor and other MCP clients) see and control a **KDE Plasma 6** desktop. It works through
5
+ KDE's own interfaces (D-Bus, KWin scripting and KConfig) instead of screenshots and
6
+ simulated clicks.
7
+
8
+ Every write can be previewed and undone. Ask your agent to "tile my editor next to the
9
+ browser", "switch to a dark theme" or "tell me when the build notification arrives".
10
+
11
+ ## Contents
12
+
13
+ - [Requirements](#requirements)
14
+ - [Install](#install)
15
+ - [Tools](#tools)
16
+ - [Permissions](#permissions)
17
+ - [Undo and snapshots](#undo-and-snapshots)
18
+ - [How it works](#how-it-works)
19
+ - [Limitations](#limitations)
20
+ - [Development](#development)
21
+
22
+ ## Requirements
23
+
24
+ - KDE Plasma 6 (tested on Plasma 6.8, Wayland, CachyOS)
25
+ - Python 3.12+ and [uv](https://docs.astral.sh/uv/)
26
+ - `kreadconfig6` / `kwriteconfig6` and the `plasma-apply-*` tools, which ship with Plasma
27
+ - Optional: [KDE Customizer](https://github.com/RJCogburn/kde-customizer) (`kdec` on your
28
+ `PATH`), required only for the theme tools
29
+
30
+ ## Install
31
+
32
+ ### From a release
33
+
34
+ Install the MCP server as a user tool:
35
+
36
+ ```sh
37
+ uv tool install plasma-mcp
38
+ ```
39
+
40
+ The executable will be available as `plasma-mcp`.
41
+
42
+ Register it with Claude Code:
43
+
44
+ ```sh
45
+ claude mcp add --scope user plasma -- plasma-mcp
46
+ ```
47
+
48
+ For another MCP client, configure it to run `plasma-mcp` over stdio.
49
+
50
+ ### From source
51
+
52
+ ```sh
53
+ git clone https://github.com/RJCogburn/plasma-mcp.git
54
+ cd plasma-mcp
55
+ uv sync
56
+ ```
57
+
58
+ Register it with Claude Code for all your projects:
59
+
60
+ ```sh
61
+ claude mcp add --scope user plasma -- uv --directory /path/to/plasma-mcp run plasma-mcp
62
+ ```
63
+
64
+ Start a new Claude Code session; the tools appear as `mcp__plasma__*`.
65
+
66
+ For other MCP clients, run the stdio command `uv --directory /path/to/plasma-mcp run plasma-mcp`.
67
+
68
+ ### Theme tools (optional)
69
+
70
+ Either install method needs KDE Customizer for the theme tools:
71
+
72
+ ```sh
73
+ uv tool install git+https://github.com/RJCogburn/kde-customizer
74
+ ```
75
+
76
+ ### Upgrading
77
+
78
+ ```sh
79
+ uv tool upgrade plasma-mcp
80
+ ```
81
+
82
+ ## Tools
83
+
84
+ The tier column refers to the permission tiers described [below](#permissions).
85
+
86
+ ### Settings
87
+
88
+ | Tool | Tier | What it does |
89
+ |---|---|---|
90
+ | `get_setting` | read | Read a KConfig value, e.g. `kwinrc` / `Windows` / `FocusPolicy`. Nested groups use `/`. |
91
+ | `set_setting` | write | Write a KConfig value. **Dry run by default.** |
92
+ | `undo_last` | write | Restore the most recent snapshot (settings or theme). |
93
+
94
+ ### Windows
95
+
96
+ | Tool | Tier | What it does |
97
+ |---|---|---|
98
+ | `list_windows` | read | Each window's id, app, title, desktops, geometry and active/minimized state, plus the virtual desktops. |
99
+ | `focus_window` | write | Activate a window. It un-minimizes it and switches to its desktop. |
100
+ | `move_to_desktop` | write | Move a window to a virtual desktop, by name or 1-based number. |
101
+ | `tile_window` | write | Tile it to the `left` / `right` / `top` / `bottom` half, `maximize` or `unmaximize`. |
102
+
103
+ ### Theming (needs KDE Customizer)
104
+
105
+ | Tool | Tier | What it does |
106
+ |---|---|---|
107
+ | `current_theme` | read | The global theme, color scheme, Plasma style, icons and cursor in use. |
108
+ | `theme_guide` | read | The theme spec format. Agents read this before writing a theme. |
109
+ | `check_theme` | read | Validate a `.toml` theme spec (contrast, missing installed themes). |
110
+ | `apply_theme` | write | Build and apply a spec. **Dry run by default.** It shows the exact install script. `layout=true` also replaces panels and needs the `dangerous` tier. |
111
+
112
+ ### Notifications
113
+
114
+ | Tool | Tier | What it does |
115
+ |---|---|---|
116
+ | `notify` | write | Show a notification (`low` / `normal` / `critical`). Returns its id. |
117
+ | `close_notification` | write | Close a notification by id. |
118
+ | `notification_status` | read | Server info and whether Do Not Disturb is on. |
119
+ | `watch_notifications` | **private** | Collect notifications from *any* app for up to 120 s. |
120
+
121
+ ### Media
122
+
123
+ | Tool | Tier | What it does |
124
+ |---|---|---|
125
+ | `media_status` | read | MPRIS players with playback status and the current track. |
126
+ | `media_play_pause` | write | Toggle play/pause on a player. |
127
+
128
+ ## Permissions
129
+
130
+ Tools are grouped into tiers. You choose which tiers are enabled in
131
+ `~/.config/plasma-mcp.toml`:
132
+
133
+ ```toml
134
+ [tiers]
135
+ read = true # default: on
136
+ write = true # default: on (every write is previewable and undoable)
137
+ dangerous = false # default: off (e.g. replacing your panel layout)
138
+ private = false # default: off (reading other apps' notifications, e.g. chat messages)
139
+ ```
140
+
141
+ When a tool's tier is off, the call fails with an error that names the tier and this file.
142
+
143
+ ## Undo and snapshots
144
+
145
+ Every real write first copies the config files it can touch to
146
+ `~/.local/state/plasma-mcp/snapshots/`. `undo_last` restores the newest snapshot and
147
+ deletes it, so repeated calls step further back.
148
+
149
+ Restoring files alone doesn't change a desktop that's already running, so theme snapshots
150
+ also record what was active: global theme, color scheme, Plasma style, cursor and icons.
151
+ On undo, plasma-mcp re-applies those first, then copies the files back. A theme change and
152
+ its undo leave your config byte-for-byte as it was. This was verified on a live desktop.
153
+
154
+ Two KDE details matter here:
155
+
156
+ - A global theme's values live in `~/.config/kdedefaults/`, not in the files you would
157
+ expect. Snapshots include that folder.
158
+ - Undoing `apply_theme(layout=true)` also restarts plasmashell to bring back your panels.
159
+
160
+ ## How it works
161
+
162
+ - **Settings**: `kreadconfig6` / `kwriteconfig6`.
163
+ - **Windows**: a KWin script can't return a value to whoever loaded it. So for each call,
164
+ plasma-mcp exports a small D-Bus object, loads a one-shot script that calls back to it
165
+ with JSON (`callDBus`), then unloads the script. See `plasma_mcp/kwin.py`; new KWin
166
+ features can reuse `kwin.run(js)`.
167
+ - **Theming**: shells out to KDE Customizer's `kdec` (`check`, `apply`, `ai-guide`) rather
168
+ than importing it, so the theme format and its install script stay in one place.
169
+ - **Notifications**: `org.freedesktop.Notifications`. Watching uses a D-Bus monitor
170
+ connection (`BecomeMonitor`) that only matches `Notify` calls.
171
+ - **Media**: MPRIS over the session bus.
172
+
173
+ ## Limitations
174
+
175
+ - **Plasma 6 only.** The KWin scripting API changed between Plasma versions; no GNOME
176
+ backend yet.
177
+ - **No synthetic keyboard or mouse input.** On Wayland that needs ydotool, libei or the
178
+ RemoteDesktop portal, and it is out of scope for now.
179
+ - **No screenshots yet.** When they come, they will go through xdg-desktop-portal so you
180
+ approve each one.
181
+ - **Window geometry updates asynchronously.** After `tile_window`, call `list_windows`
182
+ again about half a second later to see the new size.
183
+ - **Fixed-size dialogs** ignore tile and maximize.
184
+ - **Do Not Disturb.** While it is on, only `critical` notifications pop up. plasma-mcp never
185
+ changes your Do Not Disturb setting.
186
+
187
+ ## Development
188
+
189
+ ```sh
190
+ uv sync --extra dev
191
+ uv run pytest
192
+ ```
193
+
194
+ - Project notes and conventions for coding agents: `CLAUDE.md`.
195
+ - Every new tool must call `policy.require(<tier>)`, and every config write must go
196
+ through `snapshots.take` before changing anything.
197
+ - Test write tools on throwaway windows (a Tk or `kdialog` window you open yourself),
198
+ never on the user's own windows.
199
+
200
+ ## License
201
+
202
+ MIT, see [LICENSE](LICENSE).
@@ -0,0 +1,2 @@
1
+ """plasma-mcp: KDE Plasma 6 desktop control for agents over MCP."""
2
+ __version__ = "0.1.0"
@@ -0,0 +1,100 @@
1
+ """Run one-shot KWin scripts and get a JSON result back over D-Bus.
2
+
3
+ KWin scripts can't return values to the caller of loadScript, so each run:
4
+ 1. exports a tiny D-Bus object on our own (unique) bus connection,
5
+ 2. loads a script whose body calls `reply(obj)` -> callDBus(<us>, ..., "Reply", JSON),
6
+ 3. waits for the reply, then unloads the script.
7
+ Same pattern as a long-running KWin focus watcher, but one-shot.
8
+ """
9
+ from __future__ import annotations
10
+
11
+ import asyncio
12
+ import json
13
+ import os
14
+ import tempfile
15
+ import uuid
16
+
17
+ from dbus_next import Message, MessageType
18
+ from dbus_next.aio import MessageBus
19
+ from dbus_next.service import ServiceInterface, method
20
+
21
+ IFACE = "org.plasmamcp.Reply"
22
+ OBJ_PATH = "/org/plasmamcp/Reply"
23
+
24
+ PRELUDE = """
25
+ function reply(obj) {
26
+ callDBus(%(service)s, %(path)s, %(iface)s, "Reply", JSON.stringify(obj));
27
+ }
28
+ function winInfo(w) {
29
+ var g = w.frameGeometry;
30
+ return {id: String(w.internalId), caption: String(w.caption || ""),
31
+ app: String(w.resourceClass || ""), pid: w.pid,
32
+ desktops: (w.desktops || []).map(function (d) { return String(d.name); }),
33
+ on_all_desktops: w.onAllDesktops, minimized: w.minimized,
34
+ active: workspace.activeWindow === w,
35
+ geometry: {x: g.x, y: g.y, width: g.width, height: g.height}};
36
+ }
37
+ function findWindow(id) {
38
+ var ws = workspace.windowList();
39
+ for (var i = 0; i < ws.length; i++) if (String(ws[i].internalId) === id) return ws[i];
40
+ return null;
41
+ }
42
+ try {
43
+ %(body)s
44
+ } catch (e) { reply({error: String(e)}); }
45
+ """
46
+
47
+
48
+ class KWinError(RuntimeError):
49
+ pass
50
+
51
+
52
+ class _Endpoint(ServiceInterface):
53
+ def __init__(self, fut: asyncio.Future):
54
+ super().__init__(IFACE)
55
+ self._fut = fut
56
+
57
+ @method()
58
+ def Reply(self, payload: "s"): # noqa: F821 (dbus-next signature annotation)
59
+ if not self._fut.done():
60
+ self._fut.set_result(payload)
61
+
62
+
63
+ async def _kwin_call(bus: MessageBus, member: str, signature: str = "", body=None):
64
+ r = await bus.call(Message(destination="org.kde.KWin", path="/Scripting",
65
+ interface="org.kde.kwin.Scripting", member=member,
66
+ signature=signature, body=body or []))
67
+ if r.message_type == MessageType.ERROR:
68
+ raise KWinError(f"KWin {member}: {r.error_name} {r.body}")
69
+ return r.body
70
+
71
+
72
+ async def run(body: str, timeout: float = 5.0) -> dict | list:
73
+ """Run `body` (JS that must call reply(...)) inside KWin; return the parsed reply."""
74
+ bus = await MessageBus().connect()
75
+ fut = asyncio.get_running_loop().create_future()
76
+ bus.export(OBJ_PATH, _Endpoint(fut))
77
+ name = f"plasma_mcp_{uuid.uuid4().hex[:12]}"
78
+ src = PRELUDE % {"service": json.dumps(bus.unique_name), "path": json.dumps(OBJ_PATH),
79
+ "iface": json.dumps(IFACE), "body": body}
80
+ fd, path = tempfile.mkstemp(prefix=name, suffix=".js")
81
+ try:
82
+ with os.fdopen(fd, "w") as f:
83
+ f.write(src)
84
+ await _kwin_call(bus, "loadScript", "ss", [path, name])
85
+ await _kwin_call(bus, "start")
86
+ try:
87
+ raw = await asyncio.wait_for(fut, timeout)
88
+ except asyncio.TimeoutError:
89
+ raise KWinError("KWin script did not reply (is this a Plasma 6 session?)") from None
90
+ finally:
91
+ try:
92
+ await _kwin_call(bus, "unloadScript", "s", [name])
93
+ except Exception:
94
+ pass
95
+ os.unlink(path)
96
+ bus.disconnect()
97
+ result = json.loads(raw)
98
+ if isinstance(result, dict) and "error" in result:
99
+ raise KWinError(result["error"])
100
+ return result
@@ -0,0 +1,32 @@
1
+ """Per-tool permission tiers, read from ~/.config/plasma-mcp.toml.
2
+
3
+ [tiers]
4
+ read = true # list/get tools
5
+ write = true # settings, theme, notifications (always snapshotted)
6
+ dangerous = false # anything not undoable (e.g. replacing panels)
7
+ private = false # reading other apps' content (watch_notifications)
8
+ """
9
+ from __future__ import annotations
10
+
11
+ import os
12
+ import tomllib
13
+ from pathlib import Path
14
+
15
+ CONFIG = Path(os.environ.get("XDG_CONFIG_HOME", Path.home() / ".config")) / "plasma-mcp.toml"
16
+ DEFAULTS = {"read": True, "write": True, "dangerous": False, "private": False}
17
+
18
+
19
+ class Denied(Exception):
20
+ pass
21
+
22
+
23
+ def tiers() -> dict[str, bool]:
24
+ t = dict(DEFAULTS)
25
+ if CONFIG.exists():
26
+ t.update(tomllib.loads(CONFIG.read_text()).get("tiers", {}))
27
+ return t
28
+
29
+
30
+ def require(tier: str):
31
+ if not tiers().get(tier, False):
32
+ raise Denied(f"tier '{tier}' is disabled in {CONFIG}")