Skip to content

Commit bba2608

Browse files
committed
fix(docs[_ext]): Pin badge size in headings, scope to tools index only
why: Badges in h2 headings inherited the heading font size, making them oversized. Section badges on individual tool pages were redundant since every tool already has its own badge. what: - CSS: Pin .sd-badge to 0.75rem with vertical-align: middle - Scope _add_section_badges to fromdocname == "tools/index" only - Add test for page scoping (tools/sessions skipped) - Refactor test helper to reduce duplication
1 parent 47a28f1 commit bba2608

3 files changed

Lines changed: 41 additions & 34 deletions

File tree

docs/_ext/fastmcp_autodoc.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,9 +752,14 @@ def _add_section_badges(
752752
) -> None:
753753
"""Append safety badges to Inspect/Act/Destroy section headings.
754754
755+
Only applied to the tools index page — individual tool pages already
756+
have per-tool badges, making section-level badges redundant.
757+
755758
Runs at ``doctree-resolved`` — section IDs are already frozen, so
756759
appending nodes to the title doesn't affect anchors or cross-refs.
757760
"""
761+
if fromdocname != "tools/index":
762+
return
758763
for section in doctree.findall(nodes.section):
759764
if not section.children or not isinstance(section[0], nodes.title):
760765
continue

docs/_static/css/custom.css

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,11 @@ img[src*="codecov.io"] {
234234
}
235235

236236
/* ── 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.
237+
* Badges appear inline in both h2/h3 headings and body text.
238+
* Pin size to body-text scale so they don't inflate in headings.
239+
* Vertical-align keeps them centered with adjacent text.
239240
* ────────────────────────────────────────────────────────── */
241+
.sd-badge {
242+
font-size: 0.75rem;
243+
vertical-align: middle;
244+
}

tests/docs/_ext/test_fastmcp_autodoc.py

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import fastmcp_autodoc
88
import pytest
9+
from docutils import nodes
910

1011
# ---------------------------------------------------------------------------
1112
# _parse_numpy_params
@@ -455,25 +456,31 @@ def test_section_badge_map_headings() -> None:
455456
assert m["Destroy"] == "destructive"
456457

457458

458-
def test_add_section_badges_appends_badge_to_title() -> None:
459-
"""_add_section_badges appends a safety badge to matching titles."""
459+
def _make_doc_with_section(
460+
section_id: str, title_text: str
461+
) -> tuple[nodes.document, nodes.section, nodes.title]:
462+
"""Build a minimal doctree with one section."""
460463
from docutils import nodes
461464
from docutils.frontend import OptionParser
462465
from docutils.utils import new_document
463466

464467
settings = OptionParser(components=()).get_default_values()
465468
doc = new_document("test", settings)
466-
467-
section = nodes.section(ids=["inspect"])
468-
title = nodes.title("", "Inspect")
469+
section = nodes.section(ids=[section_id])
470+
title = nodes.title("", title_text)
469471
section += title
470472
doc += section
473+
return doc, section, title
474+
475+
476+
def test_add_section_badges_appends_badge_on_tools_index() -> None:
477+
"""_add_section_badges appends badge when fromdocname is tools/index."""
478+
from docutils import nodes
471479

472-
# Simulate the handler — it expects (app, doctree, fromdocname)
473-
# but only uses doctree, so pass None for the others.
474-
fastmcp_autodoc._add_section_badges(None, doc, "")
480+
doc, _section, title = _make_doc_with_section("inspect", "Inspect")
481+
482+
fastmcp_autodoc._add_section_badges(None, doc, "tools/index")
475483

476-
# Title should now have 3 children: Text("Inspect"), Text(" "), inline(badge)
477484
assert len(title.children) == 3
478485
badge = title.children[2]
479486
assert isinstance(badge, nodes.inline)
@@ -483,39 +490,29 @@ def test_add_section_badges_appends_badge_to_title() -> None:
483490

484491
def test_add_section_badges_preserves_section_id() -> None:
485492
"""_add_section_badges does not change the section ID."""
486-
from docutils import nodes
487-
from docutils.frontend import OptionParser
488-
from docutils.utils import new_document
493+
doc, section, _title = _make_doc_with_section("inspect", "Inspect")
489494

490-
settings = OptionParser(components=()).get_default_values()
491-
doc = new_document("test", settings)
495+
fastmcp_autodoc._add_section_badges(None, doc, "tools/index")
492496

493-
section = nodes.section(ids=["inspect"])
494-
section += nodes.title("", "Inspect")
495-
doc += section
497+
assert section["ids"] == ["inspect"]
496498

497-
fastmcp_autodoc._add_section_badges(None, doc, "")
498499

499-
assert section["ids"] == ["inspect"]
500+
def test_add_section_badges_skips_non_index_pages() -> None:
501+
"""_add_section_badges skips individual tool pages (redundant)."""
502+
doc, _section, title = _make_doc_with_section("inspect", "Inspect")
500503

504+
fastmcp_autodoc._add_section_badges(None, doc, "tools/sessions")
501505

502-
def test_add_section_badges_ignores_non_matching() -> None:
503-
"""_add_section_badges leaves non-matching headings untouched."""
504-
from docutils import nodes
505-
from docutils.frontend import OptionParser
506-
from docutils.utils import new_document
506+
assert len(title.children) == 1
507+
assert title.astext() == "Inspect"
507508

508-
settings = OptionParser(components=()).get_default_values()
509-
doc = new_document("test", settings)
510509

511-
section = nodes.section(ids=["overview"])
512-
title = nodes.title("", "Overview")
513-
section += title
514-
doc += section
510+
def test_add_section_badges_ignores_non_matching() -> None:
511+
"""_add_section_badges leaves non-matching headings untouched."""
512+
doc, _section, title = _make_doc_with_section("overview", "Overview")
515513

516-
fastmcp_autodoc._add_section_badges(None, doc, "")
514+
fastmcp_autodoc._add_section_badges(None, doc, "tools/index")
517515

518-
# Title should still have only the original text child
519516
assert len(title.children) == 1
520517
assert title.astext() == "Overview"
521518

0 commit comments

Comments
 (0)