Skip to content

fix: pass tool annotations to McpServer.tool() before the callback - #267

Open
vishalhabib99 wants to merge 1 commit into
idosal:mainfrom
vishalhabib99:fix/pass-tool-annotations
Open

vishalhabib99 wants to merge 1 commit into
idosal:mainfrom
vishalhabib99:fix/pass-tool-annotations

Conversation

@vishalhabib99

Copy link
Copy Markdown

Fixes #266.

#210 added readOnlyHint: true / destructiveHint: false to the tools, but the live server doesn't return them. src/index.ts passed them after the callback, wrapped in { annotations }. In the locked SDK (1.11.2), McpServer.tool() only reads annotations between paramsSchema and the callback, then treats rest[0] as the callback, so the trailing argument was silently dropped.

This passes the annotations object itself, in the position the SDK expects (tool(name, description, paramsSchema, annotations, cb), an overload in the 1.11.2 type definitions). Tools without annotations are registered exactly as before.

Tested against @modelcontextprotocol/sdk@1.11.2: tools registered both ways, then listed through a real Client over InMemoryTransport:

OLD (current main):
  with_params:    annotations=undefined
  empty_params:   annotations=undefined
  no_annotations: annotations=undefined
NEW (this PR):
  with_params:    annotations={"readOnlyHint":true,"destructiveHint":false}
  empty_params:   annotations={"readOnlyHint":true,"destructiveHint":false}   <- empty {} paramsSchema still parsed as params
  no_annotations: annotations=undefined
callTool succeeds in both

I didn't run the Worker end to end (wrangler dev), so a quick tools/list against a preview deploy would confirm it live.

Why it matters: without annotations, clients fall back to the spec defaults (readOnlyHint: false, destructiveHint: true), so cautious hosts treat every documentation fetch as potentially destructive and may ask for approval on each call.

🤖 Generated with Claude Code

idosal#210 added readOnlyHint/destructiveHint annotations, but they were passed
after the callback, wrapped in { annotations }. McpServer.tool() only reads
annotations between paramsSchema and the callback, so the trailing argument
was ignored and tools/list returned no annotations.

Fixes idosal#266

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@voucha-checks

voucha-checks Bot commented Sep 26, 2026

Copy link
Copy Markdown

VOUCHA

VOUCHA is currently in early access and is not enabled for this repository yet.

To request access, contact @idosal.

VOUCHA has not added a comprehension check to this PR.

This branch has not been deployed

No deployments
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.

Tool annotations from #210 never reach clients (passed after the callback)

1 participant