Skip to content

Commit 0bdae82

Browse files
committed
feat(docs[_ext]): add fastmcp_autodoc Sphinx extension for MCP tool docs
why: MCP tool documentation was hand-maintained and prone to drift from source code. Tool parameter tables, safety tiers, and descriptions need to stay in sync with the actual function signatures and docstrings. what: Extension (docs/_ext/fastmcp_autodoc.py): - fastmcp-tool directive: autodoc a single tool as a ToC-visible section with safety badge (floated top-right), one-line description from docstring - fastmcp-tool-input directive: emit parameter table + return type, placed after hand-written judgment content (Use when / Avoid when) - fastmcp-toolsummary directive: grouped summary tables by safety tier (Inspect / Act / Destroy) with cross-reference links - Collects all 27 tools from source at build time via mock FastMCP collector - Strips | None from optional parameter types - Splits union types into comma-separated <code> elements for clean wrapping - Cleans up t.Literal[...] and Literal[...] to bare quoted values - Parses RST inline markup in docstring descriptions via state.inline_text() - All output via docutils node API — tables, sections, badges are proper nodes Tool area pages (docs/tools/): - sessions.md: list_sessions, get_server_info, create_session, rename_session, kill_session, kill_server - windows.md: list_windows, list_panes, create_window, split_window, rename_window, select_layout, resize_window, kill_window - panes.md: capture_pane, get_pane_info, search_panes, wait_for_text, send_keys, set_pane_title, clear_pane, resize_pane, kill_pane - options.md: show_option, show_environment, set_option, set_environment - Each tool has: Use when / Avoid when, Side effects, JSON example, auto-generated Input table at section end Scan layer (docs/tools/index.md): - Hand-written card grid grouped by Inspect / Act / Destroy - Links to area pages for each of the 27 tools CSS (docs/_static/css/custom.css): - .tool-safety-badge floats badge top-right, drops to own row on narrow screens Tests (tests/docs/_ext/test_fastmcp_autodoc.py): - 28 tests covering: docstring parsing, annotation formatting, Literal cleanup, union type splitting, table construction, badge classes, tool collection, parameter extraction, integration with real libtmux_mcp tools
1 parent 5107783 commit 0bdae82

13 files changed

Lines changed: 1940 additions & 72 deletions

File tree

docs/_ext/fastmcp_autodoc.py

Lines changed: 719 additions & 0 deletions
Large diffs are not rendered by default.

docs/_static/css/custom.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,8 @@ img[src*="codecov.io"] {
232232
::view-transition-new(root) {
233233
animation-duration: 150ms;
234234
}
235+
236+
/* ── MCP Tool safety badges ──────────────────────────────
237+
* Badge sits inline next to the tool name in the heading.
238+
* Slight vertical offset for alignment with the code text.
239+
* ────────────────────────────────────────────────────────── */

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"sphinx_design",
4444
"myst_parser",
4545
"linkify_issues",
46+
"fastmcp_autodoc",
4647
]
4748

4849
myst_heading_anchors = 4

docs/tools/index.md

Lines changed: 158 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -4,114 +4,200 @@
44

55
All tools accept an optional `socket_name` parameter for multi-server support. It defaults to the `LIBTMUX_SOCKET` env var. See {ref}`configuration`.
66

7-
::::{grid} 1 1 2 2
7+
## Inspect
8+
9+
Read tmux state without changing anything.
10+
11+
::::{grid} 1 2 3 3
812
:gutter: 2 2 3 3
913

10-
:::{grid-item-card} Discovery
11-
Find and inspect tmux objects.
12-
^^^
13-
`list_sessions` `list_windows` `list_panes` `get_server_info` `get_pane_info`
14+
:::{grid-item-card} list_sessions
15+
:link: sessions
16+
:link-type: doc
17+
List all active sessions.
1418
:::
1519

16-
:::{grid-item-card} Capture & Search
17-
Read and search terminal output.
18-
^^^
19-
`capture_pane` `search_panes` `wait_for_text`
20+
:::{grid-item-card} list_windows
21+
:link: windows
22+
:link-type: doc
23+
List windows in a session.
2024
:::
2125

22-
:::{grid-item-card} Session Lifecycle
23-
Create and manage sessions.
24-
^^^
25-
`create_session` `rename_session` `kill_session`
26+
:::{grid-item-card} list_panes
27+
:link: windows
28+
:link-type: doc
29+
List panes in a window.
2630
:::
2731

28-
:::{grid-item-card} Windows & Panes
29-
Create, split, and organize.
30-
^^^
31-
`create_window` `split_window` `rename_window` `select_layout` `resize_window` `resize_pane` `kill_window` `kill_pane`
32+
:::{grid-item-card} capture_pane
33+
:link: panes
34+
:link-type: doc
35+
Read visible content of a pane.
3236
:::
3337

34-
:::{grid-item-card} Execution
35-
Send commands and interact with terminals.
36-
^^^
37-
`send_keys` `set_pane_title` `clear_pane`
38+
:::{grid-item-card} get_pane_info
39+
:link: panes
40+
:link-type: doc
41+
Get detailed pane metadata.
3842
:::
3943

40-
:::{grid-item-card} Options & Environment
41-
Read and set tmux configuration.
42-
^^^
43-
`show_option` `set_option` `show_environment` `set_environment`
44+
:::{grid-item-card} search_panes
45+
:link: panes
46+
:link-type: doc
47+
Search text across panes.
4448
:::
4549

46-
:::{grid-item-card} Server Management
47-
Destructive server operations.
48-
^^^
49-
`kill_server`
50+
:::{grid-item-card} wait_for_text
51+
:link: panes
52+
:link-type: doc
53+
Wait for text to appear in a pane.
54+
:::
55+
56+
:::{grid-item-card} get_server_info
57+
:link: sessions
58+
:link-type: doc
59+
Get tmux server info.
60+
:::
61+
62+
:::{grid-item-card} show_option
63+
:link: options
64+
:link-type: doc
65+
Query a tmux option value.
66+
:::
67+
68+
:::{grid-item-card} show_environment
69+
:link: options
70+
:link-type: doc
71+
Show tmux environment variables.
5072
:::
5173

5274
::::
5375

54-
## Discovery
76+
## Act
77+
78+
Create or modify tmux objects.
79+
80+
::::{grid} 1 2 3 3
81+
:gutter: 2 2 3 3
82+
83+
:::{grid-item-card} create_session
84+
:link: sessions
85+
:link-type: doc
86+
Start a new tmux session.
87+
:::
88+
89+
:::{grid-item-card} create_window
90+
:link: windows
91+
:link-type: doc
92+
Add a window to a session.
93+
:::
94+
95+
:::{grid-item-card} split_window
96+
:link: windows
97+
:link-type: doc
98+
Split a window into panes.
99+
:::
55100

56-
Find and inspect tmux objects.
101+
:::{grid-item-card} send_keys
102+
:link: panes
103+
:link-type: doc
104+
Send commands or keystrokes to a pane.
105+
:::
57106

58-
- **`list_sessions`** — List all sessions (with optional filters)
59-
- **`list_windows`** — List windows in a session or across all sessions
60-
- **`list_panes`** — List panes in a window or across all windows
61-
- **`get_server_info`** — Server status: version, socket path, session count, alive status
62-
- **`get_pane_info`** — Pane metadata: size, title, current command, PID
107+
:::{grid-item-card} rename_session
108+
:link: sessions
109+
:link-type: doc
110+
Rename a session.
111+
:::
63112

64-
## Capture and search
113+
:::{grid-item-card} rename_window
114+
:link: windows
115+
:link-type: doc
116+
Rename a window.
117+
:::
65118

66-
Read and search terminal output.
119+
:::{grid-item-card} resize_pane
120+
:link: panes
121+
:link-type: doc
122+
Adjust pane dimensions.
123+
:::
67124

68-
- **`capture_pane`** — Capture pane content as text (visible area or scrollback)
69-
- **`search_panes`** — Search across all pane contents for text or regex
70-
- **`wait_for_text`** — Wait for text to appear in a pane (polling with timeout)
125+
:::{grid-item-card} resize_window
126+
:link: windows
127+
:link-type: doc
128+
Adjust window dimensions.
129+
:::
71130

72-
## Session lifecycle
131+
:::{grid-item-card} select_layout
132+
:link: windows
133+
:link-type: doc
134+
Set window layout.
135+
:::
73136

74-
Create and manage sessions.
137+
:::{grid-item-card} set_pane_title
138+
:link: panes
139+
:link-type: doc
140+
Set pane title.
141+
:::
75142

76-
- **`create_session`** — Create a new session with optional window name, size, and env vars
77-
- **`rename_session`** — Rename an existing session
78-
- **`kill_session`** — Kill a session (destructive)
143+
:::{grid-item-card} clear_pane
144+
:link: panes
145+
:link-type: doc
146+
Clear pane content.
147+
:::
79148

80-
## Windows and panes
149+
:::{grid-item-card} set_option
150+
:link: options
151+
:link-type: doc
152+
Set a tmux option.
153+
:::
81154

82-
Create, split, and organize.
155+
:::{grid-item-card} set_environment
156+
:link: options
157+
:link-type: doc
158+
Set a tmux environment variable.
159+
:::
83160

84-
- **`create_window`** — Create a new window in a session
85-
- **`split_window`** — Split a window to create a new pane (horizontal or vertical)
86-
- **`rename_window`** — Rename a window
87-
- **`select_layout`** — Set layout: `even-horizontal`, `even-vertical`, `main-horizontal`, `main-vertical`, `tiled`
88-
- **`resize_window`** — Resize a window (width and/or height)
89-
- **`resize_pane`** — Resize a pane (width, height, or zoom toggle)
90-
- **`kill_window`** — Kill a window (destructive)
91-
- **`kill_pane`** — Kill a pane (destructive)
161+
::::
92162

93-
## Execution
163+
## Destroy
94164

95-
Send commands and interact with terminals.
165+
Tear down tmux objects. Not reversible.
96166

97-
- **`send_keys`** — Send keys or text to a pane (with optional Enter, literal mode, history suppression)
98-
- **`set_pane_title`** — Set a pane's title
99-
- **`clear_pane`** — Clear pane content and scrollback history
167+
::::{grid} 1 2 3 3
168+
:gutter: 2 2 3 3
100169

101-
## Options and environment
170+
:::{grid-item-card} kill_session
171+
:link: sessions
172+
:link-type: doc
173+
Destroy a session and all its windows.
174+
:::
102175

103-
Read and set tmux configuration.
176+
:::{grid-item-card} kill_window
177+
:link: windows
178+
:link-type: doc
179+
Destroy a window and all its panes.
180+
:::
104181

105-
- **`show_option`** — Query a tmux option value (server, session, window, or pane scope)
106-
- **`set_option`** — Set a tmux option
107-
- **`show_environment`** — Show tmux environment variables
108-
- **`set_environment`** — Set a tmux environment variable
182+
:::{grid-item-card} kill_pane
183+
:link: panes
184+
:link-type: doc
185+
Destroy a pane.
186+
:::
109187

110-
## Server management
188+
:::{grid-item-card} kill_server
189+
:link: sessions
190+
:link-type: doc
191+
Kill the entire tmux server.
192+
:::
111193

112-
- **`kill_server`** — Kill the tmux server (destructive)
194+
::::
113195

114-
## Tool parameter reference
196+
```{toctree}
197+
:hidden:
115198
116-
For full parameter documentation (types, defaults, descriptions), see the
117-
[API reference](../reference/api/index.md).
199+
sessions
200+
windows
201+
panes
202+
options
203+
```

docs/tools/options.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Options & Environment
2+
3+
## Inspect
4+
5+
```{fastmcp-tool} option_tools.show_option
6+
```
7+
8+
**Use when** you need to check a tmux configuration value — buffer limits,
9+
history size, status bar settings, etc.
10+
11+
**Side effects:** None. Readonly.
12+
13+
**Example:**
14+
15+
```json
16+
{
17+
"tool": "show_option",
18+
"arguments": {
19+
"option": "history-limit"
20+
}
21+
}
22+
```
23+
24+
```{fastmcp-tool-input} option_tools.show_option
25+
```
26+
27+
---
28+
29+
```{fastmcp-tool} env_tools.show_environment
30+
```
31+
32+
**Use when** you need to inspect tmux environment variables.
33+
34+
**Side effects:** None. Readonly.
35+
36+
```{fastmcp-tool-input} env_tools.show_environment
37+
```
38+
39+
## Act
40+
41+
```{fastmcp-tool} option_tools.set_option
42+
```
43+
44+
**Use when** you need to change tmux behavior — adjusting history limits,
45+
enabling mouse support, changing status bar format.
46+
47+
**Side effects:** Changes the tmux option value.
48+
49+
**Example:**
50+
51+
```json
52+
{
53+
"tool": "set_option",
54+
"arguments": {
55+
"option": "history-limit",
56+
"value": "50000"
57+
}
58+
}
59+
```
60+
61+
```{fastmcp-tool-input} option_tools.set_option
62+
```
63+
64+
---
65+
66+
```{fastmcp-tool} env_tools.set_environment
67+
```
68+
69+
**Use when** you need to set a tmux environment variable.
70+
71+
**Side effects:** Sets the variable in the tmux server.
72+
73+
```{fastmcp-tool-input} env_tools.set_environment
74+
```

0 commit comments

Comments
 (0)