|
| 1 | +(concepts)= |
| 2 | + |
| 3 | +# Concepts |
| 4 | + |
| 5 | +The mental model you need to use libtmux-mcp effectively. |
| 6 | + |
| 7 | +## tmux hierarchy |
| 8 | + |
| 9 | +tmux organizes terminals in a strict hierarchy: |
| 10 | + |
| 11 | +``` |
| 12 | +Server (tmux server instance) |
| 13 | + └─ Session (named group of windows, e.g. "dev") |
| 14 | + └─ Window (tab within a session, e.g. "editor") |
| 15 | + └─ Pane (terminal split within a window) |
| 16 | +``` |
| 17 | + |
| 18 | +libtmux-mcp mirrors this hierarchy. Every tool operates on one of these objects. |
| 19 | + |
| 20 | +## Identifiers |
| 21 | + |
| 22 | +Each tmux object has identifiers you can use to target it: |
| 23 | + |
| 24 | +| Object | ID format | Name | Index | |
| 25 | +|--------|----------|------|-------| |
| 26 | +| Session | `$1`, `$2` | `"dev"`, `"build"` | — | |
| 27 | +| Window | `@1`, `@2` | `"editor"`, `"tests"` | `0`, `1`, `2` | |
| 28 | +| Pane | `%1`, `%2` | — | — | |
| 29 | + |
| 30 | +**Pane IDs are globally unique** within a tmux server and are the preferred targeting method. When you know the pane ID, use it directly — no session or window context needed. |
| 31 | + |
| 32 | +Session names and window names are human-readable but may not be unique. Window indexes are unique within a session. |
| 33 | + |
| 34 | +## Targeting |
| 35 | + |
| 36 | +Most tools accept multiple targeting parameters. The resolution order is: |
| 37 | + |
| 38 | +1. **Direct ID** — `pane_id`, `window_id`, or `session_id` (fastest, unambiguous) |
| 39 | +2. **Name lookup** — `session_name` + optional `window_index` (convenient but may be ambiguous) |
| 40 | +3. **Default** — If no targeting parameter is given, tools that need a single object will fail; list tools return everything |
| 41 | + |
| 42 | +For pane tools, you can combine parameters to narrow the search: `session_name` + `window_id` → find the pane in that specific window. |
| 43 | + |
| 44 | +## Discovery vs. mutation |
| 45 | + |
| 46 | +Tools fall into three categories: |
| 47 | + |
| 48 | +- **Discovery** — Read-only operations: `list_sessions`, `list_windows`, `list_panes`, `capture_pane`, `get_pane_info`, `search_panes`, `wait_for_text`, `show_option`, `show_environment` |
| 49 | +- **Mutation** — Create, modify, or send input: `create_session`, `create_window`, `split_window`, `send_keys`, `rename_*`, `resize_*`, `set_pane_title`, `clear_pane`, `select_layout`, `set_option`, `set_environment` |
| 50 | +- **Destruction** — Remove tmux objects: `kill_server`, `kill_session`, `kill_window`, `kill_pane` |
| 51 | + |
| 52 | +These map to {ref}`safety tiers <safety>`. |
| 53 | + |
| 54 | +## Agent self-awareness |
| 55 | + |
| 56 | +When the MCP server runs inside a tmux pane (detected via the `TMUX_PANE` environment variable), it: |
| 57 | + |
| 58 | +- Includes the caller's pane context in server instructions |
| 59 | +- Annotates the caller's own pane with `is_caller=true` in tool results |
| 60 | +- Prevents destructive tools from killing the caller's own pane, window, session, or server |
| 61 | + |
| 62 | +This means agents can safely explore and manage tmux without accidentally terminating themselves. |
| 63 | + |
| 64 | +## Server caching |
| 65 | + |
| 66 | +Server instances are cached by `(socket_name, socket_path, tmux_bin)` tuple with thread-safe access. Dead servers are automatically evicted via `is_alive()` checks. This means multiple tool calls reuse the same server connection efficiently. |
| 67 | + |
| 68 | +## Filtering |
| 69 | + |
| 70 | +List tools (`list_sessions`, `list_windows`, `list_panes`) support Django-style filters: |
| 71 | + |
| 72 | +```json |
| 73 | +{"session_name__contains": "dev"} |
| 74 | +``` |
| 75 | + |
| 76 | +Supported operators: `exact`, `contains`, `startswith`, `endswith`, `regex`, `icontains`, `iexact`, `istartswith`, `iendswith`, `iregex`. |
| 77 | + |
| 78 | +## Resources |
| 79 | + |
| 80 | +In addition to tools, the MCP server exposes `tmux://` URI resources for browsing the hierarchy: |
| 81 | + |
| 82 | +- `tmux://sessions` — All sessions |
| 83 | +- `tmux://sessions/{name}` — Session detail with windows |
| 84 | +- `tmux://sessions/{name}/windows` — Session's windows |
| 85 | +- `tmux://sessions/{name}/windows/{index}` — Window detail with panes |
| 86 | +- `tmux://panes/{id}` — Pane details |
| 87 | +- `tmux://panes/{id}/content` — Pane captured content |
0 commit comments