Skip to content

Commit 258ecfb

Browse files
committed
mcp(fix[resources]): lead format-strings reference with subset disclaimer
The ``tmux://reference/format-strings`` resource lists ~25 of tmux's ~200 format variables. Without a clear "this is a subset" signal at the top, an agent that reads the body and doesn't find e.g. ``#{history_size}`` (one of the 175 omitted strings) may erroneously conclude that string is unsupported and skip a ``display_message`` call that would have worked. The closing ``man tmux`` line existed but came after the substantive content — too easy to miss in a top-down skim. Adds a leading note declaring the resource a curated cheat sheet, not the complete catalog, and points readers at ``man tmux`` for anything not listed. Also softens the ``get_format_string_reference`` docstring's "avoids hallucinated format names" claim — the resource is now honest about being a subset, so the docstring framing matches. Test: ``test_format_string_reference_leads_with_subset_disclaimer`` asserts both that the disclaimer keywords are present AND that the disclaimer precedes the first format-variable example, so a future edit can't quietly move the disclaimer to the bottom (recreating the original problem).
1 parent b20d651 commit 258ecfb

2 files changed

Lines changed: 52 additions & 6 deletions

File tree

src/libtmux_mcp/resources/reference.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727
_FORMAT_STRING_REFERENCE = textwrap.dedent("""\
2828
# tmux format strings
2929
30+
> **Note:** This is a curated cheat sheet, not the complete catalog.
31+
> tmux supports ~200 format variables; this lists the ones agents
32+
> most commonly need. Omission here does NOT mean a string is
33+
> unsupported — fall back to ``man tmux`` (FORMATS section) for
34+
> anything not listed.
35+
3036
Pass via ``display_message(format_string="#{...}")`` or any other
3137
tool that accepts a tmux format expression.
3238
@@ -90,12 +96,15 @@ def register(mcp: FastMCP) -> None:
9096
mime_type=_MARKDOWN_MIME,
9197
)
9298
def get_format_string_reference() -> str:
93-
"""Return the tmux format-string cheat sheet as Markdown.
94-
95-
Static reference content. Use this when an agent encounters
96-
an unfamiliar ``#{...}`` field — pulling the resource is
97-
cheaper than a ``display_message`` round-trip and avoids
98-
hallucinated format names.
99+
"""Return a curated subset of the tmux format-string catalog as Markdown.
100+
101+
Covers the format variables agents most commonly encounter; for
102+
less-common ones, the body itself directs the agent at
103+
``man tmux`` (FORMATS section). The resource is intentionally
104+
a subset rather than a mirror — it stays small enough to be
105+
cheap to pull, and the disclaimer at the top prevents the
106+
false-negative trap where an agent assumes an omitted string
107+
is unsupported.
99108
"""
100109
return _FORMAT_STRING_REFERENCE
101110

tests/test_resources.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,43 @@ def test_format_string_reference_returns_markdown(
237237
assert "#{?cond,then,else}" in body
238238

239239

240+
def test_format_string_reference_leads_with_subset_disclaimer(
241+
reference_resource_functions: dict[str, t.Any],
242+
) -> None:
243+
"""The body declares itself a curated subset BEFORE the substantive content.
244+
245+
Without a leading disclaimer, an agent that reads the resource and
246+
doesn't find a format string it knows is valid (e.g.
247+
``#{history_size}``, one of the ~175 omitted strings) may
248+
erroneously conclude the string is unsupported and skip a
249+
``display_message`` call that would have worked. The disclaimer
250+
must precede the catalog content so an agent skim-reading the top
251+
of the body cannot miss it.
252+
"""
253+
fn = reference_resource_functions["tmux://reference/format-strings"]
254+
body = fn()
255+
256+
# Disclaimer keywords must appear in the body...
257+
assert "curated" in body.lower(), (
258+
"format-string reference must declare itself a curated subset"
259+
)
260+
assert "man tmux" in body, (
261+
"format-string reference must point readers at man tmux for the "
262+
"complete catalog"
263+
)
264+
265+
# ...AND must appear *before* the first format-variable example.
266+
# Otherwise a top-down skim hits the catalog before the caveat.
267+
first_example = body.find("#{pane_id}")
268+
disclaimer = body.lower().find("curated")
269+
assert disclaimer != -1, "disclaimer absent"
270+
assert disclaimer < first_example, (
271+
f"disclaimer at offset {disclaimer} comes after first format-variable "
272+
f"example at offset {first_example}; readers will see the catalog "
273+
f"before the 'this is a subset' caveat"
274+
)
275+
276+
240277
def test_format_string_reference_advertises_markdown_mime() -> None:
241278
"""tmux://reference/format-strings is registered with text/markdown.
242279

0 commit comments

Comments
 (0)