Commit 883cd80
committed
mcp(feat[instructions]): make the card visibility-aware via run_server
Phase 4 of the BASE_INSTRUCTIONS slim-down. The card names specific
tools by hint phrase (``snapshot_pane over capture_pane + get_pane_info``,
``wait_for_text over capture_pane in a retry loop``,
``search_panes over list_panes...``); under
``LIBTMUX_SAFETY=readonly`` some of those tools are hidden by
``mcp.enable(tags=..., only=True)``, so naming them in the card was
misleading.
Composition
-----------
* New ``_HANDLE_HINTS: tuple[tuple[str, str], ...]`` keyed by tool name.
* New ``_format_handles_section(visible_tool_names)`` renders the
three-bullet handles list, filtering the Tools-handle hints by
visibility. ``visible_tool_names=None`` keeps every hint
(backward-compat for tests that build instructions without invoking
``mcp.enable``, and for the module-import-time placeholder).
* ``_INSTR_HANDLES`` is now ``_format_handles_section(None)`` — the
unfiltered baseline used by ``_BASE_INSTRUCTIONS``.
Wiring
------
* ``_build_instructions`` gains a ``visible_tool_names: set[str] | None``
parameter. When provided it rebuilds the base from ``_INSTR_CARD`` +
filtered handles; otherwise it uses ``_BASE_INSTRUCTIONS`` directly.
Env-driven ``is_caller`` block is unchanged.
* ``run_server`` now collects visible tool names via
``asyncio.run(mcp.list_tools())`` after ``mcp.enable(tags=..., only=True)``
has applied the safety-tier filter, then overwrites ``mcp.instructions``
with the visibility-filtered card. The module-import-time
``instructions=`` set on the FastMCP constructor is now an explicitly
documented placeholder.
Tests
-----
* ``test_card_omits_invisible_tools`` (parametrized) — drops one tool
from the visible set and asserts its hint phrase disappears, with a
paired sanity check that the phrase IS present when the tool is
visible.
* ``test_build_instructions_default_visible_tool_names_emits_full_card``
— pins the backward-compat behavior so a future contributor doesn't
silently break the placeholder by changing the default.
End-to-end smoke: simulating ``LIBTMUX_SAFETY=readonly`` (wait_for_text
hidden), the card drops the wait_for_text hint while keeping
snapshot_pane and search_panes. Default placeholder still emits all
three at 215 total words.1 parent 72abdae commit 883cd80
2 files changed
Lines changed: 147 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
82 | 84 | | |
83 | 85 | | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
84 | 128 | | |
85 | 129 | | |
86 | 130 | | |
87 | | - | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
88 | 135 | | |
89 | 136 | | |
90 | 137 | | |
| |||
95 | 142 | | |
96 | 143 | | |
97 | 144 | | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
98 | 153 | | |
99 | 154 | | |
100 | 155 | | |
101 | 156 | | |
102 | 157 | | |
103 | 158 | | |
104 | | - | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
105 | 164 | | |
106 | 165 | | |
107 | 166 | | |
| |||
273 | 332 | | |
274 | 333 | | |
275 | 334 | | |
| 335 | + | |
| 336 | + | |
276 | 337 | | |
277 | 338 | | |
278 | 339 | | |
| |||
284 | 345 | | |
285 | 346 | | |
286 | 347 | | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
287 | 361 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
218 | 218 | | |
219 | 219 | | |
220 | 220 | | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
221 | 282 | | |
222 | 283 | | |
223 | 284 | | |
| |||
0 commit comments