Skip to content

refactor(dbus): replace dbus-send CLI with in-process dbus-python#23

Open
isac322 wants to merge 3 commits into
mainfrom
overhaul/pr2-dbus
Open

refactor(dbus): replace dbus-send CLI with in-process dbus-python#23
isac322 wants to merge 3 commits into
mainfrom
overhaul/pr2-dbus

Conversation

@isac322
Copy link
Copy Markdown
Owner

@isac322 isac322 commented May 5, 2026

Why

The dbus_call MCP tool ran subprocess.run(["dbus-send", ...]) for every call. Spawn overhead, fd-passing limitations, no structured error handling.

What

  • src/kwin_mcp/dbus_args.py (NEW, 482L): full dbus-send syntax recursive-descent parser
    • 12 basic types (string, int16/32/64, uint*, byte, double, boolean, objpath, signature)
    • Container types (array:T:v1,v2, dict:K:V:k1:v1,k2:v2, variant:T:v) + nesting
    • Outputs dbus.types.* (no parallel type system)
    • Plus: typed JSON dict ({"type":"int32","value":42}) dispatcher + round-trip safety (to_dbus_send_string)
  • src/kwin_mcp/core.py:dbus_call: dbus.bus.BusConnection(addr).get_object().get_dbus_method(method)(*parsed_args). Zero subprocess.
  • src/kwin_mcp/server.py:dbus_call schema: args: list[str | dict] | None (additive widening; legacy ["string:hello"] remains compatible)
  • tests/test_dbus_args.py: 80 unit tests (all basic types + containers + nesting + edge cases)
  • tests/integration/test_dbus_call_compat.py: 6 integration tests (legacy / typed / mixed / error formats)
  • docs/design/dbus-call-call-sites.md: call-site map

Compatibility

  • Existing external clients sending ["string:hello", "int32:42"] continue to work
  • Typed JSON is now also accepted — both styles can be mixed in the same call
  • Error output format changes to dbus-python exception messages (documented under [Internal] in CHANGELOG)

Verify

uv run pytest tests/test_dbus_args.py                              # → 80 passed
uv run pytest -m kwin tests/integration/test_dbus_call_compat.py   # → 6 passed

Series: Stacked on top of PR 0. Base = overhaul/pr0-tests-ci-guards. Once PR 0 merges, GitHub will automatically retarget this PR's base to main.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
@isac322 isac322 changed the base branch from overhaul/pr0-tests-ci-guards to launch/backend-overhaul May 5, 2026 13:34
@isac322 isac322 force-pushed the overhaul/pr2-dbus branch from b261e43 to 00423eb Compare May 5, 2026 13:44
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 5, 2026

📝 Docs & SEO Review

Source files changed in this PR:

pyproject.toml
src/kwin_mcp/core.py
src/kwin_mcp/dbus_args.py
src/kwin_mcp/server.py

Consistency check results:

✅  All documentation/plugin SEO checks passed.

Run @docs-seo in Claude Code to perform a full documentation review.

@isac322 isac322 force-pushed the overhaul/pr2-dbus branch from 00423eb to 6f26525 Compare May 5, 2026 14:00
isac322 added 2 commits May 5, 2026 23:12
- Add dbus_args.py: full dbus-send recursive-descent parser (12 basic
  types + array/dict/variant containers) returning dbus-python types.
- Add typed-JSON args dispatcher: args list now accepts both legacy
  'type:value' strings and {type, value} dicts, mixed in one call.
  Schema widened (additive): list[str] -> list[str | dict].
- core.py:dbus_call now uses dbus.bus.BusConnection + Interface in-process
  (no subprocess). Errors surface as 'D-Bus error: <name>: <msg>'.
- _format_dbus_result: void -> empty, primitive -> bare, container -> JSON.
- 80 unit tests for the parser; 6 integration tests against virtual KWin.
- docs/design/dbus-call-call-sites.md documents the public-tool contract.

Pre-commit: ruff/ty clean, ci_guards pass, 87 tests green.
@isac322 isac322 force-pushed the overhaul/pr2-dbus branch from 6f26525 to d3c3573 Compare May 5, 2026 14:12
Base automatically changed from launch/backend-overhaul to main May 29, 2026 02:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant