Declare tool annotations and shorten the untrusted-content wording on every tool #116

Closed
opened 2026-11-01 21:25:30 +00:00 by svc-agent-writer · 3 comments

Why

The MCP tool definition carries four behaviour hints: readOnlyHint, destructiveHint, idempotentHint, openWorldHint. Clients use them to decide which calls need human confirmation and which can run freely. No mailmind tool declares any. Measured on main at 70397c4 with an in-process _list_tools() dump of the read-token surface: all eleven tools show annotations=None. The write and wake tools, registered by _register_tools when configured, have none either.

FastMCP 3.4.11 (the pinned fastmcp>=3.4,<4) accepts annotations=ToolAnnotations(...) or a dict on mcp.tool(...).

Change

  • Read, evidence and wake-read tools (mail_mailboxes, mail_search, mail_thread, mail_read, mail_attachment, mail_changes, mail_people, mail_evidence, mail_status, mail_triage, mail_triage_rows, mail_wakes, mail_actions): readOnlyHint=True, destructiveHint=False, idempotentHint=True, openWorldHint=False.
  • Outbox write tools (mail_draft, mail_flag, mail_move, mail_undo) and mail_wakes_ack: readOnlyHint=False, destructiveHint=False, openWorldHint=False. ADR 0004 makes every write reversible and nothing is sent or deleted, so destructiveHint=False is honest. idempotentHint=True for mail_flag, mail_undo and mail_wakes_ack; False for mail_draft and mail_move, which queue a new action each call.
  • Route the hint through _register_tools so a tool cannot be registered without one: for example a dict keyed by function name beside WRITE_TOOLS/WAKE_TOOLS, or a per-function attribute read in the loop. Add the same to the decorated mail_triage_rows.
  • tests/test_server.py::test_tools_list_and_search_with_read_token: assert every listed tool carries annotations and every read-scope tool has readOnlyHint=True. Add one write-token case asserting the four outbox tools have readOnlyHint=False and destructiveHint=False.
  • README tool table: one sentence on the hints. No ADR: this records what ADR 0004 and ADR 0008 already decided.

Acceptance

  • tools/list over the read token shows annotations on every tool with the values above, and over a write token on the outbox tools.
  • make check green. No behaviour change to any tool body.

Out of scope

  • Nothing from #117: it is folded in below.
  • Protocol revision 2026-07-28 (server/discover, ttlMs): arrives with an SDK bump, not here.

Blocked by

None.

Wording change (folded from #117, operator decision 2026-11-02, option 2)

The untrusted-content rule is stated once in the server instructions string, which already carries the UNTRUSTED constant. Each tool docstring keeps one short field-specific marker, for example "Subjects and addresses are untrusted." Only the repeated clause goes. Option 3 (drop the per-tool sentence) was rejected.

  • src/imap_mailmind_mcp/server.py: shorten every tool docstring as above, read, evidence, wake and write tools alike. Keep every other sentence; front-load what the tool does and returns.
  • mail_search: move the FTS5 syntax detail out of the tool description into the query parameter description, where part of it already lives, so the tool description stays under 500 chars.
  • tests/test_server.py line 112 and tests/test_panel.py line 173: keep asserting the word untrusted in every description. Add the annotations assertions from the section above beside them.
  • CLAUDE.md convention line: "Every tool docstring names its untrusted fields in one short sentence; the full rule lives in the server instructions." README tool-table rows that quote the old wording to match.
  • Acceptance: total read-token tools/list definition size falls below the 13,328 chars measured on 70397c4, mail_search description under 500 chars, every description still contains untrusted.
## Why The MCP tool definition carries four behaviour hints: `readOnlyHint`, `destructiveHint`, `idempotentHint`, `openWorldHint`. Clients use them to decide which calls need human confirmation and which can run freely. No mailmind tool declares any. Measured on main at 70397c4 with an in-process `_list_tools()` dump of the read-token surface: all eleven tools show `annotations=None`. The write and wake tools, registered by `_register_tools` when configured, have none either. FastMCP 3.4.11 (the pinned `fastmcp>=3.4,<4`) accepts `annotations=ToolAnnotations(...)` or a dict on `mcp.tool(...)`. ## Change - Read, evidence and wake-read tools (`mail_mailboxes`, `mail_search`, `mail_thread`, `mail_read`, `mail_attachment`, `mail_changes`, `mail_people`, `mail_evidence`, `mail_status`, `mail_triage`, `mail_triage_rows`, `mail_wakes`, `mail_actions`): `readOnlyHint=True`, `destructiveHint=False`, `idempotentHint=True`, `openWorldHint=False`. - Outbox write tools (`mail_draft`, `mail_flag`, `mail_move`, `mail_undo`) and `mail_wakes_ack`: `readOnlyHint=False`, `destructiveHint=False`, `openWorldHint=False`. ADR 0004 makes every write reversible and nothing is sent or deleted, so `destructiveHint=False` is honest. `idempotentHint=True` for `mail_flag`, `mail_undo` and `mail_wakes_ack`; `False` for `mail_draft` and `mail_move`, which queue a new action each call. - Route the hint through `_register_tools` so a tool cannot be registered without one: for example a dict keyed by function name beside `WRITE_TOOLS`/`WAKE_TOOLS`, or a per-function attribute read in the loop. Add the same to the decorated `mail_triage_rows`. - `tests/test_server.py::test_tools_list_and_search_with_read_token`: assert every listed tool carries annotations and every read-scope tool has `readOnlyHint=True`. Add one write-token case asserting the four outbox tools have `readOnlyHint=False` and `destructiveHint=False`. - README tool table: one sentence on the hints. No ADR: this records what ADR 0004 and ADR 0008 already decided. ## Acceptance - `tools/list` over the read token shows `annotations` on every tool with the values above, and over a write token on the outbox tools. - `make check` green. No behaviour change to any tool body. ## Out of scope - Nothing from #117: it is folded in below. - Protocol revision 2026-07-28 (`server/discover`, `ttlMs`): arrives with an SDK bump, not here. ## Blocked by None. ## Wording change (folded from #117, operator decision 2026-11-02, option 2) The untrusted-content rule is stated once in the server `instructions` string, which already carries the `UNTRUSTED` constant. Each tool docstring keeps one short field-specific marker, for example "Subjects and addresses are untrusted." Only the repeated clause goes. Option 3 (drop the per-tool sentence) was rejected. - `src/imap_mailmind_mcp/server.py`: shorten every tool docstring as above, read, evidence, wake and write tools alike. Keep every other sentence; front-load what the tool does and returns. - `mail_search`: move the FTS5 syntax detail out of the tool description into the `query` parameter description, where part of it already lives, so the tool description stays under 500 chars. - `tests/test_server.py` line 112 and `tests/test_panel.py` line 173: keep asserting the word `untrusted` in every description. Add the annotations assertions from the section above beside them. - `CLAUDE.md` convention line: "Every tool docstring names its untrusted fields in one short sentence; the full rule lives in the server instructions." README tool-table rows that quote the old wording to match. - Acceptance: total read-token `tools/list` definition size falls below the 13,328 chars measured on 70397c4, `mail_search` description under 500 chars, every description still contains `untrusted`.
Author
Member

Sibling in peoplemind: dev/peoplemind-mcp#29. Wording issue for this repo: #117.

Sibling in peoplemind: dev/peoplemind-mcp#29. Wording issue for this repo: #117.
svc-agent-writer changed title from Declare MCP tool annotations (readOnlyHint and friends) on every tool to Declare tool annotations and shorten the untrusted-content wording on every tool 2026-11-01 21:57:35 +00:00
Collaborator

⏸ SVD architect gate: dev/imap-mailmind-mcp#116 declare-tool-annotations-and-shorten-the-untrusted-content-w

Status: CLEAN after 0 rework round(s) · 0 blocking defect(s) · 0 lens(es) INCONCLUSIVE (could not run) · 0 lens(es) DEGRADED (deterministic denial) · complexity standard · dispatch effort medium

Run: 20261101T222737Z-0c60d2c2

Held because: CLEAN but 4 open risk(s) (1 verification · 3 decision) — HOLD-ALL parks everything. The risks, verbatim:

Open risks:

  1. The issue's size criterion ('total read-token tools/list definition size below 13,328') came from the wording-only #117 and conflicts with the annotations half after the fold-in. Measured in the Half-A sandbox at 85d45c7 (src identical to 70397c4): baseline exactly 13328, and annotations add +1243 chars. Meeting the literal total needs about 1250 chars of real cuts, which 'keep every other sentence' forbids. Sibling peoplemind#29 hit the same conflict, and its gate ruled option (a) on 2026-11-02. Question: apply the same ruling here (size excluding the annotations key, plus the description total, both below baseline; total reported with no threshold, as this spec's lean does), or hold mailmind to the literal total? [decision]
  2. The issue declares mail_wakes readOnlyHint=True, but Store.wake_position (store.py:1164-1174) inserts a wake_consumers row the first time a named consumer calls it. The insert is idempotent (ON CONFLICT DO NOTHING) server bookkeeping. Question: keep READ_ONLY as the issue prescribes (the lean), or declare mail_wakes readOnlyHint=False, idempotentHint=True? The override is one TOOL_HINTS entry and one test assertion. [decision]
  3. The issue frames the mail_search cut as moving 'the FTS5 syntax detail' into the query parameter, but the 1185-char description is mostly per-mode and ranking detail. Getting under 500 means moving facts into the mode, similar_to and attachment_flag Field descriptions as well. Question: does relocating each fact to the parameter it qualifies, deleting only exact duplicates of existing parameter text, satisfy 'Keep every other sentence'? The lean assumes yes. [decision]
  4. The spec is filed as 2026-11-01-declare-tool-annotations-and-shorten-the-untrusted-content-w-mailmind-116.md because the unsuffixed slug path already holds the registered peoplemind#29 spec. Check after codex-svd registration: grep -n "mailmind-116\|peoplemind-mcp#29" /Users/piers/.local/state/exhaust/groupthink/specs/_index.md shows two separate rows, and the peoplemind row still points at the unsuffixed file. [verification]

Change: In src/imap_mailmind_mcp/server.py:

  • Import mcp.types.ToolAnnotations. Add Final hint constants (READ_ONLY, WRITE_SAME, WRITE_NEW) after FlagColor at :67, in the style of UNTRUSTED at :63.
  • Pass annotations=READ_ONLY on the 11 @mcp.tool decorators (:196, 209, 344, 374, 421, 454, 563, 601, 650, 716, 737).
  • Add TOOL_HINTS, a dict keyed by function name, beside WRITE_TOOLS/WAKE_TOOLS (:1008-1011): draft/move WRITE_NEW; flag/undo/wakes_ack WRITE_SAME; actions/wakes READ_ONLY.
  • In _register_tools (:1014-1022), call mcp.tool(fn, auth=..., annotations=TOOL_HINTS[fn.name]). A missing hint then raises KeyError at build_app.
  • In each of the 18 docstrings, replace only the untrusted clause with a short field-specific marker that keeps the word 'untrusted' (per-tool table in the spec). ADR 0008 §5's field list stays in mail_evidence.
  • Bring the mail_search description (:241-252, 1185 chars) under 500 by moving each per-mode fact into the query/mode/similar_to/attachment_flag Field descriptions.
    Tests:
  • Extend tests/test_server.py:93-121 with annotation and <500 assertions, and add a WRITE_TOKEN test on served for the outbox hints.
  • Assert annotations beside tests/test_panel.py:173 and tests/test_wakes.py:41.
    Docs: replace CLAUDE.md:58 with the issue's convention line, and add one README sentence on the hints. No README row quotes the old docstring clause.

Files: src/imap_mailmind_mcp/server.py · tests/test_server.py · tests/test_panel.py · tests/test_wakes.py · README.md · CLAUDE.md

Decision: accept the 4 open risk(s) above and dispatch this spec (svd:go), or park (svd:skip) / re-spec (svd:respec)?

Your call (when this issue is held at the gate via svd:hold):

  • add label svd:go — approve; Half-B dispatch accepts exactly this spec (open risks accepted)
  • add label svd:fire beside svd:go — approve AND authorise the Half-B fire from the phone; never on its own
  • add label svd:skip — park it; dispatch refuses it and the issue stays for a human
  • add label svd:respec — discard this spec; the next Half-A run re-produces it with this record as prior-attempt context

Spec: /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-01-declare-tool-annotations-and-shorten-the-untrusted-content-w-mailmind-116.md — next: codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-01-declare-tool-annotations-and-shorten-the-untrusted-content-w-mailmind-116.md

### ⏸ SVD architect gate: dev/imap-mailmind-mcp#116 declare-tool-annotations-and-shorten-the-untrusted-content-w **Status:** CLEAN after 0 rework round(s) · 0 blocking defect(s) · 0 lens(es) INCONCLUSIVE (could not run) · 0 lens(es) DEGRADED (deterministic denial) · complexity `standard` · dispatch effort `medium` **Run:** `20261101T222737Z-0c60d2c2` **Held because:** CLEAN but 4 open risk(s) (1 verification · 3 decision) — HOLD-ALL parks everything. The risks, verbatim: **Open risks:** 1. The issue's size criterion ('total read-token tools/list definition size below 13,328') came from the wording-only #117 and conflicts with the annotations half after the fold-in. Measured in the Half-A sandbox at 85d45c7 (src identical to 70397c4): baseline exactly 13328, and annotations add +1243 chars. Meeting the literal total needs about 1250 chars of real cuts, which 'keep every other sentence' forbids. Sibling peoplemind#29 hit the same conflict, and its gate ruled option (a) on 2026-11-02. Question: apply the same ruling here (size excluding the annotations key, plus the description total, both below baseline; total reported with no threshold, as this spec's lean does), or hold mailmind to the literal total? [decision] 2. The issue declares mail_wakes readOnlyHint=True, but Store.wake_position (store.py:1164-1174) inserts a wake_consumers row the first time a named consumer calls it. The insert is idempotent (ON CONFLICT DO NOTHING) server bookkeeping. Question: keep READ_ONLY as the issue prescribes (the lean), or declare mail_wakes readOnlyHint=False, idempotentHint=True? The override is one TOOL_HINTS entry and one test assertion. [decision] 3. The issue frames the mail_search cut as moving 'the FTS5 syntax detail' into the query parameter, but the 1185-char description is mostly per-mode and ranking detail. Getting under 500 means moving facts into the mode, similar_to and attachment_flag Field descriptions as well. Question: does relocating each fact to the parameter it qualifies, deleting only exact duplicates of existing parameter text, satisfy 'Keep every other sentence'? The lean assumes yes. [decision] 4. The spec is filed as 2026-11-01-declare-tool-annotations-and-shorten-the-untrusted-content-w-mailmind-116.md because the unsuffixed slug path already holds the registered peoplemind#29 spec. Check after codex-svd registration: `grep -n "mailmind-116\|peoplemind-mcp#29" /Users/piers/.local/state/exhaust/groupthink/specs/_index.md` shows two separate rows, and the peoplemind row still points at the unsuffixed file. [verification] **Change:** In src/imap_mailmind_mcp/server.py: - Import mcp.types.ToolAnnotations. Add Final hint constants (READ_ONLY, WRITE_SAME, WRITE_NEW) after FlagColor at :67, in the style of UNTRUSTED at :63. - Pass annotations=READ_ONLY on the 11 @mcp.tool decorators (:196, 209, 344, 374, 421, 454, 563, 601, 650, 716, 737). - Add TOOL_HINTS, a dict keyed by function name, beside WRITE_TOOLS/WAKE_TOOLS (:1008-1011): draft/move WRITE_NEW; flag/undo/wakes_ack WRITE_SAME; actions/wakes READ_ONLY. - In _register_tools (:1014-1022), call mcp.tool(fn, auth=..., annotations=TOOL_HINTS[fn.__name__]). A missing hint then raises KeyError at build_app. - In each of the 18 docstrings, replace only the untrusted clause with a short field-specific marker that keeps the word 'untrusted' (per-tool table in the spec). ADR 0008 §5's field list stays in mail_evidence. - Bring the mail_search description (:241-252, 1185 chars) under 500 by moving each per-mode fact into the query/mode/similar_to/attachment_flag Field descriptions. Tests: - Extend tests/test_server.py:93-121 with annotation and <500 assertions, and add a WRITE_TOKEN test on `served` for the outbox hints. - Assert annotations beside tests/test_panel.py:173 and tests/test_wakes.py:41. Docs: replace CLAUDE.md:58 with the issue's convention line, and add one README sentence on the hints. No README row quotes the old docstring clause. **Files:** `src/imap_mailmind_mcp/server.py` · `tests/test_server.py` · `tests/test_panel.py` · `tests/test_wakes.py` · `README.md` · `CLAUDE.md` **Decision:** accept the 4 open risk(s) above and dispatch this spec (`svd:go`), or park (`svd:skip`) / re-spec (`svd:respec`)? **Your call** (when this issue is held at the gate via `svd:hold`): - add label `svd:go` — approve; Half-B dispatch accepts exactly this spec (open risks accepted) - add label `svd:fire` **beside** `svd:go` — approve AND authorise the Half-B fire from the phone; never on its own - add label `svd:skip` — park it; dispatch refuses it and the issue stays for a human - add label `svd:respec` — discard this spec; the next Half-A run re-produces it with this record as prior-attempt context <sub>Spec: `/Users/piers/.local/state/exhaust/groupthink/specs/2026-11-01-declare-tool-annotations-and-shorten-the-untrusted-content-w-mailmind-116.md` — next: `codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-01-declare-tool-annotations-and-shorten-the-untrusted-content-w-mailmind-116.md`</sub>
Collaborator

spec-verify-dispatch Half B for dev/imap-mailmind-mcp#116 declare-tool-annotations-and-shorten-the-untrusted-content-w completed integration verify.

  • PR: dev/imap-mailmind-mcp#120
  • Branch: feat/svd-dev-imap-mailmind-mcp-116-declare-tool-annotations-a-fbb758cb
  • Commit: ccc7f292c5
  • Build: none
  • Test: green
  • Reader audit clean: True
  • Spec fidelity: True
  • Ready for merge: True
  • Checks: PR #120 at ccc7f29: no commit statuses on the head, so there are no remote checks. Local: 755 passed, 8 skipped, 18 deselected; ruff check, ruff format --check and mypy --strict are clean.
  • Warning: The PR head commit ccc7f29 has no commit statuses on Forgejo, so no remote CI ran. The repo's CI files are added by the architect.
  • Warning: The dispatched-run self-review fix (restoring best-first ordering in the mode description) is in the diff; no follow-up needed.
  • Decision: review the PR and merge? (codex-svd ship --run-id 20261101T224709Z-fbb758cb --confirm-merge)
spec-verify-dispatch Half B for dev/imap-mailmind-mcp#116 declare-tool-annotations-and-shorten-the-untrusted-content-w completed integration verify. - PR: https://git.groupthink.asia/dev/imap-mailmind-mcp/pulls/120 - Branch: feat/svd-dev-imap-mailmind-mcp-116-declare-tool-annotations-a-fbb758cb - Commit: ccc7f292c5c814d7640f9bf19448b51ce7ef8b00 - Build: none - Test: green - Reader audit clean: True - Spec fidelity: True - Ready for merge: True - Checks: PR #120 at ccc7f29: no commit statuses on the head, so there are no remote checks. Local: 755 passed, 8 skipped, 18 deselected; ruff check, ruff format --check and mypy --strict are clean. - Warning: The PR head commit ccc7f29 has no commit statuses on Forgejo, so no remote CI ran. The repo's CI files are added by the architect. - Warning: The dispatched-run self-review fix (restoring best-first ordering in the mode description) is in the diff; no follow-up needed. - Decision: review the PR and merge? (`codex-svd ship --run-id 20261101T224709Z-fbb758cb --confirm-merge`)
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
dev/mail-mind-mcp#116
No description provided.