Server¶
FastMCP server instance for libtmux.
Creates and configures the MCP server with all tools and resources.
-
libtmux_mcp.server._INSTR_SCOPE = <...truncated, 465 chars>¶libtmux_mcp.server._INSTR_SCOPE = <...truncated, 465 chars>¶
Activation rule. Names positive triggers and explicit anti-triggers so bare ‘pane’/’window’/’session’ default to tmux but the server stays out of the way for browser/editor/GUI/Jupyter contexts.
-
libtmux_mcp.server._INSTR_HOOKS_GAP = 'HOOKS ARE READ-ONLY: inspect via show_hooks / show_hook. Write-hooks survive process death; keep them in your tmux config file, not a transient MCP session.'¶libtmux_mcp.server._INSTR_HOOKS_GAP = 'HOOKS ARE READ-ONLY: inspect via show_hooks / show_hook. Write-hooks survive process death; keep them in your tmux config file, not a transient MCP session.'¶
Gap-explainer: write-hook tools are intentionally absent. See module comment above for when to add another
_GAPsegment vs. push the explanation into a tool description.
-
libtmux_mcp.server._INSTR_BUFFERS_GAP = <...truncated, 204 chars>¶libtmux_mcp.server._INSTR_BUFFERS_GAP = <...truncated, 204 chars>¶
Gap-explainer:
list_buffersis intentionally absent because tmux buffers can include OS clipboard history. See module comment above.
-
libtmux_mcp.server._build_instructions(safety_level=TAG_MUTATING)¶libtmux_mcp.server._build_instructions(safety_level=TAG_MUTATING)¶
Build server instructions with agent context and safety level.
When the MCP server process runs inside a tmux pane,
TMUX_PANEandTMUXenvironment variables are available. This function appends that context so the LLM knows which pane is its own without extra tool calls.
-
libtmux_mcp.server._RESPONSE_LIMITED_TOOLS = ['capture_pane', 'search_panes', 'snapshot_pane', 'show_buffer']¶libtmux_mcp.server._RESPONSE_LIMITED_TOOLS = ['capture_pane', 'search_panes', 'snapshot_pane', 'show_buffer']¶
Tools covered by the tail-preserving response limiter. Only tools whose output is terminal scrollback benefit from this backstop; structured responses from list/get tools stay under the cap naturally.
-
libtmux_mcp.server._lifespan(_app)¶libtmux_mcp.server._lifespan(_app)¶
FastMCP lifespan: fail-fast startup + deterministic cache cleanup.
Startup¶
Verifies that a
tmuxbinary is onPATH. Without this probe, tools fail at first call with a genericTmuxCommandNotFounddeep inside libtmux. Failing at server start instead surfaces a clear cold-start error before any tool traffic arrives.Shutdown¶
Clears the process-wide
_server_cacheso repeated test runs don’t share stale Server references and HTTP-transport reload cycles start clean. Also best-effort GC’s any leftoverlibtmux_mcp_*paste buffers on every cached server — agents are supposed todelete_bufferafter use, but an interrupted call chain can leak. Note: FastMCP lifespan teardown runs on SIGTERM / SIGINT only;kill -9and OOM bypass it, so this path must not be relied on for any invariant that must survive a hard crash (see the hook_tools module docstring for why write-hooks are explicitly NOT gated on lifespan cleanup).- Parameters:
_app (
FastMCP)- Return type:
-
libtmux_mcp.server._gc_mcp_buffers(cache)¶libtmux_mcp.server._gc_mcp_buffers(cache)¶
Best-effort delete of leaked
libtmux_mcp_*paste buffers.Iterates every cached tmux Server, lists buffer names, and deletes anything matching the MCP prefix. Never raises: tmux may be unreachable, buffers may vanish mid-scan, and none of that should block lifespan shutdown. Logs at debug level so operators can still surface leaks via verbose logging.