|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +Project guide for AI-assisted development of linux-desktop-mcp. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +An MCP server providing Chrome-extension-level semantic element targeting for native Linux desktop applications using AT-SPI2. Exposes 11 tools for desktop automation (snapshot, find, click, type, key, capabilities, context, target_window, create_window_group, release_window). |
| 8 | + |
| 9 | +## Layout |
| 10 | + |
| 11 | +``` |
| 12 | +src/linux_desktop_mcp/ |
| 13 | + __init__.py # Package entry, version, exception exports |
| 14 | + server.py # MCP server setup, initialization, tool dispatch |
| 15 | + handlers.py # ServerContext dataclass + 10 async handler functions |
| 16 | + tool_definitions.py # get_tool_definitions() with all 11 Tool schemas |
| 17 | + exceptions.py # Custom exception hierarchy (LinuxDesktopMCPError base) |
| 18 | + atspi_bridge.py # AT-SPI2 tree building, element interaction (ThreadPoolExecutor) |
| 19 | + references.py # ElementReference, ReferenceManager, GC |
| 20 | + input_backends.py # InputManager + YdotoolBackend, XdotoolBackend, WtypeBackend |
| 21 | + window_manager.py # WindowGroup, WindowTarget, WindowGroupManager |
| 22 | + window_discovery.py # Window enumeration via AT-SPI desktop |
| 23 | + overlay.py # GTK3 border overlay windows (X11 backend) |
| 24 | + detection.py # Display server, compositor, and tool detection |
| 25 | +tests/ |
| 26 | + conftest.py # MCP module mocks, shared fixtures |
| 27 | + test_server.py # Handler tests via ServerContext |
| 28 | + test_window_manager.py |
| 29 | + test_detection.py |
| 30 | + test_input_backends_manager.py |
| 31 | + test_window_discovery.py |
| 32 | + test_overlay.py |
| 33 | +``` |
| 34 | + |
| 35 | +## Build & Test |
| 36 | + |
| 37 | +```bash |
| 38 | +# Run tests (mocks MCP + AT-SPI, no desktop needed) |
| 39 | +PYTHONPATH=src pytest tests/ -v |
| 40 | + |
| 41 | +# Lint and format |
| 42 | +ruff check . |
| 43 | +ruff format . |
| 44 | + |
| 45 | +# Import check |
| 46 | +python -c "from linux_desktop_mcp import __version__; print(__version__)" |
| 47 | +``` |
| 48 | + |
| 49 | +## Code Conventions |
| 50 | + |
| 51 | +- **Python 3.10+** target. Use `X | None` union syntax, `dict[str, Any]` (not `Dict`). |
| 52 | +- **Exception handling**: Use custom exceptions from `exceptions.py`. AT-SPI modules use `_GLibError` conditional import pattern. Never use bare `except Exception` except in the top-level `call_tool` safety net. |
| 53 | +- **Async handlers**: Each tool handler is a standalone async function in `handlers.py` receiving `(ctx: ServerContext, args: dict)` and returning `list[TextContent]`. |
| 54 | +- **Input backends**: Subprocess-based, mock `asyncio.create_subprocess_exec` in tests. |
| 55 | +- **AT-SPI bridge**: Runs blocking AT-SPI calls in `ThreadPoolExecutor` via `asyncio.to_thread`. Uses `threading.Lock` for thread safety. |
| 56 | +- **Tests**: Pure Python where possible (dataclasses, enums). MCP modules mocked at conftest level. No real desktop or AT-SPI required. |
| 57 | +- **Formatting**: ruff with line-length=100, double quotes, isort-compatible imports. |
0 commit comments