Skip to content

Commit d1a07a8

Browse files
committed
docs(tools): Add behavioral guidance to 22 tool docstrings
why: "Use when / Avoid when" guidance existed only in Markdown docs, invisible to agents at runtime. FastMCP exposes function __doc__ as MCP tool descriptions — enriching docstrings directly improves agent tool selection and workflow composition. what: - Add 2-3 line behavioral summary to each of 22 tool docstrings - Covers: use case, common next step, side effects, race conditions - Key addition: send_keys warns about capture_pane race condition - Destructive tools note self-kill protection and alternatives - Max ~100 words per tool to manage context window token cost - Existing docstring content (params, returns) unchanged
1 parent 8f8b8e6 commit d1a07a8

6 files changed

Lines changed: 65 additions & 0 deletions

File tree

src/libtmux_mcp/tools/env_tools.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ def show_environment(
2727
) -> EnvironmentResult:
2828
"""Show tmux environment variables.
2929
30+
Use to inspect tmux environment variables that affect child processes.
31+
3032
Parameters
3133
----------
3234
session_name : str, optional
@@ -66,6 +68,9 @@ def set_environment(
6668
) -> EnvironmentSetResult:
6769
"""Set a tmux environment variable.
6870
71+
Use to set variables that will be inherited by new panes and windows.
72+
Changes do not affect already-running processes.
73+
6974
Parameters
7075
----------
7176
name : str

src/libtmux_mcp/tools/option_tools.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ def show_option(
7373
) -> OptionResult:
7474
"""Show a tmux option value.
7575
76+
Use to check tmux configuration values such as history-limit,
77+
mouse support, or status bar settings.
78+
7679
Parameters
7780
----------
7881
option : str
@@ -109,6 +112,9 @@ def set_option(
109112
) -> OptionSetResult:
110113
"""Set a tmux option value.
111114
115+
Use to change tmux behavior at runtime. Common uses: adjusting
116+
history-limit, enabling mouse support, changing status bar format.
117+
112118
Parameters
113119
----------
114120
option : str

src/libtmux_mcp/tools/pane_tools.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ def send_keys(
4040
) -> str:
4141
"""Send keys (commands or text) to a tmux pane.
4242
43+
After sending, use wait_for_text to block until the command completes,
44+
or capture_pane to read the result. Do not capture_pane immediately —
45+
there is a race condition.
46+
4347
Parameters
4448
----------
4549
keys : str
@@ -147,6 +151,8 @@ def resize_pane(
147151
) -> PaneInfo:
148152
"""Resize a tmux pane.
149153
154+
Use when adjusting layout for better readability or to fit content.
155+
150156
Parameters
151157
----------
152158
pane_id : str, optional
@@ -205,6 +211,9 @@ def kill_pane(
205211
) -> str:
206212
"""Kill (close) a tmux pane. Requires exact pane_id (e.g. '%5').
207213
214+
Use to clean up panes no longer needed. To remove an entire window
215+
and all its panes, use kill_window instead.
216+
208217
Parameters
209218
----------
210219
pane_id : str
@@ -245,6 +254,8 @@ def set_pane_title(
245254
) -> PaneInfo:
246255
"""Set the title of a tmux pane.
247256
257+
Use titles to label panes for later identification via list_panes or get_pane_info.
258+
248259
Parameters
249260
----------
250261
title : str
@@ -287,6 +298,9 @@ def get_pane_info(
287298
) -> PaneInfo:
288299
"""Get detailed information about a tmux pane.
289300
301+
Use this for metadata (PID, path, dimensions) without reading terminal content.
302+
To read what is displayed in the pane, use capture_pane instead.
303+
290304
Parameters
291305
----------
292306
pane_id : str, optional
@@ -326,6 +340,9 @@ def clear_pane(
326340
) -> str:
327341
"""Clear the contents of a tmux pane.
328342
343+
Use before send_keys + capture_pane to get a clean capture without prior output.
344+
Note: this is two tmux commands with a brief gap — not fully atomic.
345+
329346
Parameters
330347
----------
331348
pane_id : str, optional

src/libtmux_mcp/tools/server_tools.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ def list_sessions(
3131
) -> list[SessionInfo]:
3232
"""List all tmux sessions.
3333
34+
Use as the starting point for discovery — call this before targeting
35+
specific sessions, windows, or panes.
36+
3437
Parameters
3538
----------
3639
socket_name : str, optional
@@ -61,6 +64,9 @@ def create_session(
6164
) -> SessionInfo:
6265
"""Create a new tmux session.
6366
67+
Check list_sessions first to avoid name conflicts. A new session
68+
starts with one window and one pane.
69+
6470
Parameters
6571
----------
6672
session_name : str, optional
@@ -105,6 +111,10 @@ def create_session(
105111
def kill_server(socket_name: str | None = None) -> str:
106112
"""Kill the tmux server and all its sessions.
107113
114+
Destroys ALL sessions, windows, and panes on this server. Use kill_session
115+
to remove a single session instead. Self-kill protection prevents killing
116+
the server running this MCP process.
117+
108118
Parameters
109119
----------
110120
socket_name : str, optional
@@ -134,6 +144,9 @@ def kill_server(socket_name: str | None = None) -> str:
134144
def get_server_info(socket_name: str | None = None) -> ServerInfo:
135145
"""Get information about the tmux server.
136146
147+
Use to verify the tmux server is running before other operations.
148+
For session-level details, use list_sessions instead.
149+
137150
Parameters
138151
----------
139152
socket_name : str, optional

src/libtmux_mcp/tools/session_tools.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ def create_window(
8181
) -> WindowInfo:
8282
"""Create a new window in a tmux session.
8383
84+
Creates a window with one pane. Use split_window to add more panes afterward.
85+
8486
Parameters
8587
----------
8688
session_name : str, optional
@@ -137,6 +139,9 @@ def rename_session(
137139
) -> SessionInfo:
138140
"""Rename a tmux session.
139141
142+
Use when a session's purpose has changed. Existing pane_id references
143+
remain valid after renaming.
144+
140145
Parameters
141146
----------
142147
new_name : str
@@ -167,6 +172,10 @@ def kill_session(
167172
) -> str:
168173
"""Kill a tmux session.
169174
175+
Destroys the session and all its windows and panes. Use kill_window
176+
to remove a single window instead. Self-kill protection prevents
177+
killing the session containing this MCP process.
178+
170179
Parameters
171180
----------
172181
session_name : str, optional

src/libtmux_mcp/tools/window_tools.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ def split_window(
111111
) -> PaneInfo:
112112
"""Split a tmux window to create a new pane.
113113
114+
Creates a new pane by splitting an existing one. Use direction to choose
115+
above/below/left/right. Returns the new pane's info including its pane_id.
116+
114117
Parameters
115118
----------
116119
pane_id : str, optional
@@ -188,6 +191,9 @@ def rename_window(
188191
) -> WindowInfo:
189192
"""Rename a tmux window.
190193
194+
Use when a window's purpose has changed. Existing window_id references
195+
remain valid after renaming.
196+
191197
Parameters
192198
----------
193199
new_name : str
@@ -227,6 +233,10 @@ def kill_window(
227233
) -> str:
228234
"""Kill (close) a tmux window. Requires exact window_id (e.g. '@3').
229235
236+
Destroys the window and all its panes. Use kill_pane to remove a single
237+
pane instead. Self-kill protection prevents killing the window containing
238+
this MCP process.
239+
230240
Parameters
231241
----------
232242
window_id : str
@@ -272,6 +282,9 @@ def select_layout(
272282
) -> WindowInfo:
273283
"""Set the layout of a tmux window.
274284
285+
Choose from: even-horizontal, even-vertical, main-horizontal,
286+
main-vertical, or tiled. Rearranges all panes in the window.
287+
275288
Parameters
276289
----------
277290
layout : str
@@ -319,6 +332,8 @@ def resize_window(
319332
) -> WindowInfo:
320333
"""Resize a tmux window.
321334
335+
Use to adjust the window dimensions. This affects all panes within the window.
336+
322337
Parameters
323338
----------
324339
window_id : str, optional

0 commit comments

Comments
 (0)