mcp-tmux

v0.3.1
mcp-tmux Checked 3 days ago Published 1 month ago

A comprehensive, universal MCP server for driving tmux (local and over SSH).

These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.

tmux_command

Run an arbitrary tmux command and return its raw result. This is the universal escape hatch — it runs `tmux <args>` verbatim, so it can do anything the target's tmux supports. Pass the subcommand and its flags as a list, e.g. args=["new-window", "-t", "mysess", "-n", "logs"]. Do NOT include the leading "tmux". Returns {"stdout", "stderr", "exit_code"}. Non-zero exit codes are returned, not raised, so you can inspect failures. `target` selects where tmux runs: omit (or "local") for the local machine, a named profile from the c…

ParameterTypeDescription
args *arraytmux subcommand + flags as a list (no leading "tmux").
targetHost or named SSH profile from the config to run against; omit (or pass "local") to act on the local machine.
timeoutMax seconds to wait for the command.

tmux_query

Evaluate a tmux format string (e.g. "#{pane_current_path}"). Uses `display-message -p` to expand any #{...} format variable. Optional `target_pane` sets the context (-t) the format is evaluated against. This returns the expanded value to you; to instead show a message on a client's status line, use `tmux_display_message`. Returns {"value": <expanded string>}.

ParameterTypeDescription
format *stringtmux format string to expand, e.g. "#{pane_current_path}".
targetHost or named SSH profile from the config to run against; omit (or pass "local") to act on the local machine.
target_paneThe pane to act on (e.g. "%3" or "sess:1.2"); defaults to the active pane when omitted.

tmux_version

Report the target's tmux version and whether it is supported (1.8+). For more server facts (pid, socket path) use `tmux_server_info`.

ParameterTypeDescription
targetHost or named SSH profile from the config to run against; omit (or pass "local") to act on the local machine.

tmux_list_targets

List configured targets: 'local' plus any named profiles from config. Pass one of these names as the `target` argument of any other tool to run it against that host.

tmux_has_session

Check whether a session exists. Returns {"exists": bool}. To enumerate sessions use `tmux_list(kind="session")`; to create one only if it is missing, use `tmux_new_session(attach_or_create=True)` directly.

ParameterTypeDescription
session *stringSession name or id to check for.
targetHost or named SSH profile from the config to run against; omit (or pass "local") to act on the local machine.

tmux_new_session

Create a new session (detached by default). Optional `command` runs as the first pane's command; `start_directory` sets the working dir; `width`/`height` size the detached session. `attach_or_create=True` makes the call idempotent: if a session named `name` already exists it is reused (its id/name returned) instead of erroring, otherwise it is created. tmux's own `new-session -A` *attaches* the existing session, which a headless MCP server has no terminal to do; so the reuse here is a detached `has-session` check (the create-time…

ParameterTypeDescription
attach_or_createbooleanReuse an existing session of this name instead of erroring.
commandCommand to run as the first pane instead of the default shell.
detachedbooleanCreate the session detached (-d); default True.
envSession environment variables (-e KEY=VAL; tmux 3.0+).
heightHeight in rows for the detached session (-y).
nameName for the new session (-s).
start_directoryWorking directory for the first pane (-c).
targetHost or named SSH profile from the config to run against; omit (or pass "local") to act on the local machine.
widthWidth in columns for the detached session (-x).

tmux_new_window

Create a window. `session` is the target session (or "sess:index"). Set select=False to create it in the background (-d). Use this to add a window to an existing session; for a whole new session use `tmux_new_session`, or `tmux_split_window` to add a pane to the current window instead. Returns the new window's {"id", "index", "name"}.

ParameterTypeDescription
commandCommand to run instead of the default shell.
nameName for the new window (-n).
selectbooleanFocus the new window (default); False backgrounds it (-d).
sessionTarget session or "sess:index" (-t); current session if omitted.
start_directoryWorking directory for the new window (-c).
targetHost or named SSH profile from the config to run against; omit (or pass "local") to act on the local machine.

tmux_list_panes

List panes. Scope to a `window` (-t), a `session` (-s), or the whole server (default, -a). For sessions/windows/clients/buffers use `tmux_list(kind=...)`; panes live here because they have two independent scope axes (window vs session).

ParameterTypeDescription
sessionScope to all panes in a session (-s).
targetHost or named SSH profile from the config to run against; omit (or pass "local") to act on the local machine.
windowScope to a single window (-t); takes precedence over session.

tmux_split_window

Split a pane. By default splits left/right; vertical=True splits top/bottom. `percentage` sizes the new pane (e.g. 30). select=False keeps focus on the original pane (-d). Use this to add a pane to the current window; use `tmux_new_window` for a fresh window instead, or `tmux_join_pane` to move an existing pane in as the split rather than spawning a new one. Returns the new pane's {"id", "index"}.

ParameterTypeDescription
commandShell command to run in the new pane instead of the default shell.
percentageSize of the new pane as a percentage of the space (e.g. 30).
selectbooleanFocus the new pane (default); False keeps focus on the original (-d).
start_directoryWorking directory for the new pane (-c).
targetHost or named SSH profile from the config to run against; omit (or pass "local") to act on the local machine.
target_paneThe pane to act on (e.g. "%3" or "sess:1.2"); defaults to the active pane when omitted.
verticalbooleanSplit top/bottom instead of the default left/right.

tmux_list

List sessions, windows, clients, or paste buffers. `kind` selects what to enumerate: - "session" — all sessions (`scope` ignored) - "window" — windows in `scope` (a session); all windows server-wide (-a) when `scope` is omitted - "client" — clients attached to `scope` (a session); all clients when omitted - "buffer" — paste buffers (`scope` ignored) Panes are NOT here — use `tmux_list_panes`, which has two independent scope axes (a window vs a session). Key bindings use `tmux_list_keys`…

ParameterTypeDescription
kind *stringWhat to enumerate: "session", "window", "client", or "buffer".
scopeContext for the listing: a session for kind="window"/"client" (omit for server-wide); ignored for "session"/"buffer".
targetHost or named SSH profile from the config to run against; omit (or pass "local") to act on the local machine.

tmux_kill

Kill a session, window, pane, or the whole server (destructive). Irreversible and immediate: tmux does not prompt for confirmation, and any program running in the killed entity is terminated (SIGHUP) along with its unsaved state and scrollback. Killing the last pane in a window closes the window; killing the last window in a session ends the session. `kind` selects what to kill: "session" / "window" / "pane" / "server". `id` is the target entity (e.g. session name "work", a window "sess:2", a pane "%3" or "sess:2.1") and is required for…

ParameterTypeDescription
kind *stringWhat to kill: "session", "window", "pane", or "server".
idThe entity to kill (e.g. session "work", window "sess:2", pane "%3"); required for every kind except "server".
targetHost or named SSH profile from the config to run against; omit (or pass "local") to act on the local machine.

tmux_rename

Rename a session or window. `kind` is "session" or "window"; `id` is the entity to rename. Maps to `rename-<kind> -t id new_name`. To label a pane (rather than rename its window), use `tmux_set_pane_title` instead. Returns {"renamed": True, "kind": kind, "name": new_name}.

ParameterTypeDescription
id *stringThe entity to rename (e.g. "work" or "work:2").
kind *stringWhat to rename: "session" or "window".
new_name *stringThe new name to assign.
targetHost or named SSH profile from the config to run against; omit (or pass "local") to act on the local machine.

tmux_select

Make a window or pane the active (focused) one. Moves the selection so that subsequent interactive input and any attached client's view go to this entity; selecting a pane also selects its window. This only changes focus — it does not alter contents or layout, and it is not required before targeting an entity by id elsewhere (e.g. `tmux_send_keys` and `tmux_capture_pane` address a pane directly, regardless of which one is active). `kind` is "window" or "pane"; `id` is the entity to activate (e.g. "mysess:2" for a window, "%3"…

ParameterTypeDescription
id *stringThe entity to activate (e.g. "mysess:2" or pane "%3").
kind *stringWhat to activate: "window" or "pane".
targetHost or named SSH profile from the config to run against; omit (or pass "local") to act on the local machine.

tmux_send_keys

Send input to a pane. Two modes (provide exactly one of `text` / `keys`): * `text`: a literal string. With literal=True (default) it is sent exactly as written via `send-keys -l` (so "C-c" types those three characters). Set literal=False to let tmux interpret key names inside the string. * `keys`: a list of tmux key tokens interpreted by tmux, e.g. ["C-c"], ["Escape"], ["Up", "Up", "Enter"]. `enter=True` appends an Enter keypress after the input — the usual way to "run" a typed command. This is fire-a…

ParameterTypeDescription
target_pane *stringThe pane to act on, as a tmux target (e.g. "%3" or "sess:1.2").
enterbooleanAppend an Enter keypress after the input (i.e. run it).
keystmux key tokens to send, e.g. ["C-c"], ["Up", "Enter"].
literalbooleanSend text exactly (-l); False lets tmux interpret key names.
targetHost or named SSH profile from the config to run against; omit (or pass "local") to act on the local machine.
textLiteral string to type (mutually exclusive with keys).

tmux_capture_pane

Capture (read) the visible contents and/or scrollback of a pane. This is the primary way to observe output. `start`/`end` select a scrollback line range (-S/-E): negative or "-" for the start of history, e.g. start=-100 grabs the last 100+ lines. `escapes=True` keeps ANSI color/escape sequences (-e). `join=True` rejoins wrapped lines (-J). `trim=True` (default) drops the empty padding lines tmux emits below the last line of real content; set trim=False to keep the raw capture. This is a point-in-time snapshot. To wait for output to appe…

ParameterTypeDescription
endScrollback end line (-E); "-" for the end of history.
escapesbooleanKeep ANSI color/escape sequences (-e).
joinbooleanRejoin wrapped lines (-J).
startScrollback start line (-S); negative or "-" for start of history.
targetHost or named SSH profile from the config to run against; omit (or pass "local") to act on the local machine.
target_paneThe pane to act on (e.g. "%3" or "sess:1.2"); defaults to the active pane when omitted.
trimbooleanDrop trailing empty padding lines (default); False keeps raw.

tmux_wait_for_text

Wait until `pattern` appears in a pane, or `timeout` seconds elapse. `pattern` is a substring by default, or a regular expression when regex=True. `history` optionally includes that many scrollback lines in each check (-S -history). Returns {"matched", "elapsed", "content"} where content is the last capture taken. Caveat: the pane also shows the command you typed, so a pattern can match your own echoed input line rather than the command's output. To wait for a command to *finish* and get just its output, prefer `tmux_run`.

ParameterTypeDescription
pattern *stringText to wait for: a substring, or a regex when regex=True.
target_pane *stringThe pane to act on, as a tmux target (e.g. "%3" or "sess:1.2").
historyInclude this many scrollback lines in each check (-S).
poll_intervalnumberSeconds between capture checks.
regexbooleanTreat pattern as a regular expression.
targetHost or named SSH profile from the config to run against; omit (or pass "local") to act on the local machine.
timeoutnumberMax seconds to wait before giving up.

tmux_wait_for_idle

Wait until a pane's visible content stops changing. Returns once the capture is unchanged for `idle_seconds` (i.e. output has settled), or after `timeout`. Use this when you don't know the exact completion text; if you do, wait on it with `tmux_wait_for_text`, and to run a command and get just its output + exit code, use `tmux_run`. Returns {"idle", "elapsed", "content"}.

ParameterTypeDescription
target_pane *stringThe pane to act on, as a tmux target (e.g. "%3" or "sess:1.2").
idle_secondsnumberSeconds the content must stay unchanged to count as idle.
poll_intervalnumberSeconds between capture checks.
targetHost or named SSH profile from the config to run against; omit (or pass "local") to act on the local machine.
timeoutnumberMax seconds to wait before giving up.

tmux_run

Run a shell command in a pane and return just its output + exit code. Types `command` into the pane bracketed by unique markers, then polls until the command finishes, and returns the text printed between the markers. This is the reliable alternative to send-keys + sleep + capture. Intended for NON-interactive commands at a shell prompt. Returns {"completed", "exit_code", "output", "elapsed"}; on timeout, completed is False and output holds the raw capture so far.

ParameterTypeDescription
command *stringNon-interactive shell command to run at the pane's prompt.
target_pane *stringThe pane to act on, as a tmux target (e.g. "%3" or "sess:1.2").
historyintegerScrollback lines to scan when locating the output markers.
poll_intervalnumberSeconds between capture checks.
targetHost or named SSH profile from the config to run against; omit (or pass "local") to act on the local machine.
timeoutnumberMax seconds to wait for the command to finish.