Commit 09993dc
authored
feat(fastmcp): align tool surface, prompts, and middleware (#15)
Broad follow-up to the initial MCP surface, realigning the server
around FastMCP 3.2 primitives and closing gaps that blocked real
agent workflows. Adds four prompt recipes, a full middleware stack
(timing, error-handling, audit, safety, readonly-retry,
tail-preserving response limiting), a discovery tool, buffer and
read-only hook tools, and channel-based wait primitives — all with
Pydantic output models, NumPy-docstring-derived parameter
descriptions, bounded outputs with tail-preserving truncation, and
CI coverage across the supported tmux matrix.
**New tools**
- Discovery: `list_servers` — enumerates live tmux sockets with
an honest scope (default dir + `LIBTMUX_SOCKET_PATH` +
`extra_socket_paths`) rather than a filesystem crawl.
- Waits: `wait_for_text`, `wait_for_content_change`,
`wait_for_channel`, `signal_channel`. All bounded,
`Context.report_progress` / `Context.warning` aware, and
propagate `asyncio.CancelledError` cleanly. `capture_pane` calls
run through `asyncio.to_thread` so FastMCP's event loop stays
responsive under long waits.
- Buffers: `load_buffer`, `paste_buffer`, `show_buffer`,
`delete_buffer`. Agent-namespaced as
`libtmux_mcp_<uuid>_<name>` to prevent collisions; leaked
buffers are GC'd on graceful lifespan shutdown.
- Hooks (read-only): `show_hook`, `show_hooks` — the latter
merges the `-g` global-window tree into `scope='server'`.
**Prompt recipes**
- Four FastMCP prompts: `run_and_wait`, `diagnose_failing_pane`,
`build_dev_workspace`, `interrupt_gracefully`. `run_and_wait`
UUID-scopes its wait-for channel and uses `repr()` for
send-keys payloads. `build_dev_workspace` uses the real tool
parameter names (`session_name=`, `pane_id=`, `direction=`),
drops stray Enter presses, and no longer waits for shell
prompts after launching screen-grabbing programs (`vim`,
`watch`, `tail -f`); a new `log_command` parameter replaces
the Linux-only `/var/log/syslog` default.
- Set `LIBTMUX_MCP_PROMPTS_AS_TOOLS=1` to expose prompts as
tools for tools-only MCP clients.
**Middleware stack**
- `TimingMiddleware`, `ErrorHandlingMiddleware`.
- `AuditMiddleware`: per-call structured logging with
digest-redacted argument summaries. Moved outside
`SafetyMiddleware` so tier denials are audited too.
- `SafetyMiddleware`: tier-gated tool visibility
(readonly / mutating / destructive).
- `ReadonlyRetryMiddleware`: transparent retry of readonly tools
on transient `libtmux.exc.LibTmuxException`; mutating tools
never retry. Retry warnings log under `libtmux_mcp.retry`.
- `TailPreservingResponseLimitingMiddleware`: trims oversized
output from the head so the active prompt survives.
**Bounded outputs**
- `capture_pane`, `snapshot_pane`, `show_buffer` accept
`max_lines` (default 500) with tail-preserving truncation and
typed `content_truncated` / `content_truncated_lines` signals.
Pass `max_lines=None` to opt out.
**Lifespan + safety**
- FastMCP lifespan with a `tmux` presence probe that fails fast
with `RuntimeError` if the binary is missing on `PATH`.
- `search_panes` neutralizes tmux format-string injection in the
regex fast path; also always takes the fast path when
`regex=False`, and returns panes in numeric `pane_id` order.
- macOS `TMUX_TMPDIR` self-kill guard: resolves the server
socket via `tmux display-message #{socket_path}` before
env-based reconstruction, with a basename-match fallback that
closes the launchd divergence gap.
- Caller-identity scoping: self-protection is scoped to the
caller's tmux socket rather than global.
**Refactors**
- `tools/pane_tools.py` split into a `pane_tools/` subpackage
(`io`, `meta`, `layout`, `lifecycle`, `copy_mode`, `pipe`,
`search`, `wait`) with a thin `__init__` re-export.
- `handle_tool_errors_async` decorator for Context-using tools.
- `ANNOTATIONS_SHELL` open-world shell-tool annotations hoisted
into `_utils` with the five consumers documented inline.
**Docs**
- New pages: `tools/buffers.md`, `tools/hooks.md`,
`tools/waits.md`, `tools/index.md`; `panes.md` documents the
`SearchPanesResult` migration; `safety.md` covers the macOS
`TMUX_TMPDIR` caveat, the audit log, `pipe_pane`, and
`set_environment`.
- New topic pages: `topics/completion.md`, `topics/logging.md`,
`topics/pagination.md`.
- Reusable Sphinx widget framework under `docs/_ext/widgets/`
powers a `{mcp-install}` picker with nested client /
install-method tabs and per-client tool hints. Rendering goes
through the Jinja `highlight` filter so copybutton parity
matches the rest of the site; non-HTML Sphinx builders degrade
gracefully.
- Prompts and Resources promoted to top-level peers of Tools,
surfaced as landing-page grid cards with FastMCP autodoc
wiring.
### Breaking changes
- `search_panes` now returns
`libtmux_mcp.models.SearchPanesResult` instead of
`list[PaneContentMatch]`. Matches moved to `.matches`; new
`truncated`, `truncated_panes`, `total_panes_matched`,
`offset`, `limit` fields enable pagination.
Migration: `for m in search_panes(...)` →
`for m in search_panes(...).matches`.
- Minimum `fastmcp>=3.2.4` (was `>=3.1.0`). Required for
`ReadonlyRetryMiddleware` and per-parameter input-schema
descriptions.77 files changed
Lines changed: 10068 additions & 1645 deletions
File tree
- docs
- _ext/widgets
- _static/js
- _widgets/mcp-install
- reference/api
- tools
- topics
- src/libtmux_mcp
- prompts
- resources
- tools
- pane_tools
- tests
- docs
- __snapshots__
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
254 | 254 | | |
255 | 255 | | |
256 | 256 | | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
265 | 282 | | |
266 | 283 | | |
267 | 284 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
9 | 106 | | |
10 | 107 | | |
11 | 108 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
0 commit comments