Skip to content

feat(docs[_ext]): add fastmcp_autodoc Sphinx extension for MCP tool docs#2

Merged
tony merged 1 commit intomainfrom
fastmcp-autodoc-extension
Mar 25, 2026
Merged

feat(docs[_ext]): add fastmcp_autodoc Sphinx extension for MCP tool docs#2
tony merged 1 commit intomainfrom
fastmcp-autodoc-extension

Conversation

@tony
Copy link
Member

@tony tony commented Mar 25, 2026

Summary

Custom Sphinx extension that autodocuments FastMCP tools from source code using the docutils node API.

What it does

  • fastmcp-tool directive: creates a ToC-visible section with safety badge (readonly/mutating/destructive), one-line description parsed from the function's docstring
  • fastmcp-tool-input directive: emits parameter table + return type, designed to be placed after hand-written judgment content
  • fastmcp-toolsummary directive: generates grouped summary tables by safety tier (Inspect / Act / Destroy)

Key features

  • Collects all 27 tools from libtmux_mcp.tools 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[...] to bare quoted values, each in its own <code>
  • Parses RST inline markup in docstring descriptions
  • All output via docutils node API — no text generation or markdown parsing

Tool area pages

Each tool has: Use when / Avoid when, Side effects, JSON example, auto-generated Input table.

Test plan

  • 28 unit tests passing (tests/docs/_ext/test_fastmcp_autodoc.py)
  • ruff check clean
  • ruff format clean
  • just html builds successfully
  • Visual inspection at http://localhost:8024/tools/

@tony tony force-pushed the fastmcp-autodoc-extension branch from 5db9211 to a716b50 Compare March 25, 2026 22:44
@tony tony force-pushed the fastmcp-autodoc-extension branch from fe75f57 to 91d60b4 Compare March 25, 2026 22:50
@tony tony force-pushed the fastmcp-autodoc-extension branch from 91d60b4 to 33d88c6 Compare March 25, 2026 22:53
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
@tony tony force-pushed the fastmcp-autodoc-extension branch from 33d88c6 to 686d27b Compare March 25, 2026 22:55
@tony tony marked this pull request as ready for review March 25, 2026 22:57
@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 66.66667% with 141 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.12%. Comparing base (5107783) to head (686d27b).

Files with missing lines Patch % Lines
docs/_ext/fastmcp_autodoc.py 56.73% 130 Missing and 5 partials ⚠️
tests/docs/_ext/test_fastmcp_autodoc.py 95.37% 5 Missing ⚠️
tests/docs/_ext/conftest.py 66.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main       #2      +/-   ##
==========================================
- Coverage   79.71%   75.12%   -4.60%     
==========================================
  Files          17       20       +3     
  Lines         779     1202     +423     
  Branches       93      156      +63     
==========================================
+ Hits          621      903     +282     
- Misses        121      256     +135     
- Partials       37       43       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tony tony force-pushed the fastmcp-autodoc-extension branch from 686d27b to 0bdae82 Compare March 25, 2026 23:07
@tony tony merged commit d6e6ee4 into main Mar 25, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants