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 = 'NO DEDICATED HOOK-WRITE TOOLS: use show_hooks/show_hook. Write hooks survive process death; keep them in your tmux config file.'¶libtmux_mcp.server._INSTR_HOOKS_GAP = 'NO DEDICATED HOOK-WRITE TOOLS: use show_hooks/show_hook. Write hooks survive process death; keep them in your tmux config file.'¶
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 = 'BUFFERS: load_buffer stages, paste_buffer delivers, delete_buffer removes via returned BufferRef. No list_buffers: tmux buffers may include clipboard history.'¶libtmux_mcp.server._INSTR_BUFFERS_GAP = 'BUFFERS: load_buffer stages, paste_buffer delivers, delete_buffer removes via returned BufferRef. No list_buffers: tmux buffers may include clipboard history.'¶
Gap-explainer:
list_buffersis intentionally absent because tmux buffers can include OS clipboard history. See module comment above.
Enabled when
LIBTMUX_TOOLSETSis unset.teardownis not in it: this server still reaches whichever tmux server the environment points at, so deletion stays something an operator asks for by name.
Build server instructions with agent context and toolsets.
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._resolve_toolsets(value)¶libtmux_mcp.server._resolve_toolsets(value)¶
Return the enabled toolsets for a
LIBTMUX_TOOLSETSvalue.- Parameters:
value (
str or None) – Comma-separated toolset names.Nonetakes the default; an empty string enables none, which is legal.- Returns:
Enabled toolsets.
- Return type:
frozenset of str- Raises:
RuntimeError– If a name is not a toolset. A typo silently falling back is how a narrowed surface quietly becomes a wider one.
-
libtmux_mcp.server._resolve_tool_names(value)¶libtmux_mcp.server._resolve_tool_names(value)¶
Return a comma-separated tool-name list as a set.
-
libtmux_mcp.server._reject_retired_safety_env()¶libtmux_mcp.server._reject_retired_safety_env()¶
Fail startup when
LIBTMUX_SAFETYis still set.The former setting selected an ordered ladder that read as a permission system and was not one. Ignoring the variable would silently widen a surface an operator believes is narrow.
- Return type:
-
libtmux_mcp.server._RESPONSE_LIMITED_TOOLS = ['capture_pane', 'capture_since', 'search_panes', 'snapshot_pane', 'show_buffer']¶libtmux_mcp.server._RESPONSE_LIMITED_TOOLS = ['capture_pane', 'capture_since', '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¶
Validates named tool includes and exclusions against the transformed catalog, then verifies that a
tmuxbinary is onPATH. Without the binary probe, tools fail at first call with a genericTmuxCommandNotFounddeep inside libtmux. Failing at server start instead surfaces a clear cold-start error before 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. Shutdown sends no tmux commands. Buffer tools expose explicit cleanup, and a process-wide prefix does not prove which MCP instance owns a buffer.- Parameters:
_app (
FastMCP)- Return type:
-
libtmux_mcp.server._register_all()¶libtmux_mcp.server._register_all()¶
Register all tools, resources, and prompts with the MCP server.
- Return type:
-
libtmux_mcp.server._enable_allowed_tools()¶libtmux_mcp.server._enable_allowed_tools()¶
Apply FastMCP’s visibility gate for the enabled toolsets.
- Return type: