Repository navigation
feat(agent): keep MCP tool annotations from tools/list (DEV-1374) - #148
Merged
Merged
Conversation
listToolDefs dropped the annotations a server reports per tool, so a consumer could not read readOnlyHint or destructiveHint after discovery. Carry them on the tool definition, expose them on the MCP-branded tool, and store and restore them in cache snapshots. Linear: DEV-1374
…hots for annotations Also copies a snapshot's annotations on rehydrate so tools do not share the snapshot's object, and documents the five kept fields with an isMcpTool example. Linear: DEV-1374
Contributor
Author
|
AGENT-WRITTEN: Perry reviewed head
|
…mcp-tool-annotations # Conflicts: # packages/agent/src/lib/tool.ts # packages/agent/src/mcp/tool-wrapper.ts
After merging main, wrapMcpTool carried the loop key, annotations and wire schema conditionals and passed the structural gate's complexity limit. Linear: DEV-1374
mattapperson
left a comment
Contributor
There was a problem hiding this comment.
Looks good overall. CI is green, and the live path holds up: the SDK rejects a mistyped hint outright, so the "wrong type must not read as truthy" property is real there.
Five comments inline. I'd like the first three fixed before merge; the last two are worth a look but I won't block on them.
Separately, while reviewing I found a few bugs in the existing MCP code on main (not from this PR). I'm putting up a PR for those.
Review feedback on the annotations change. - A snapshot's annotations go through the same copy as a server's, so a key that is not a standard hint is dropped on both paths, as the README says. - The tool, the handle and each snapshot hold their own annotations object. Changing the hints read from a tool no longer changes what serialize() writes, and changing a returned snapshot no longer changes the tool. - McpToolAnnotations fields are readonly and document the MCP default of an absent hint, with the specification's warning about untrusted servers. - The changeset and README carry an API example. Linear: DEV-1374
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linear: DEV-1374
Problem
An MCP server reports behaviour hints per tool in
tools/list(annotations:readOnlyHint,destructiveHint,idempotentHint,openWorldHint,title).listToolDefscopies onlyname,description,inputSchema,outputSchemaand the loop key, so the hints are gone after discovery and the handle offers no other way to read them.OpenRouter's MCP loop needs them for two things:
mcp_list_toolsitem lists every tool withannotations: { read_only }. The loop cannot fill that field.require_approvalandallowed_toolsselectors that useread_only, because it cannot tell which tools are read-only.Change
McpToolDefandSerializedMCPToolDefgain an optionalannotations.listToolDefscopies the hints the server defined. A tool with no annotations gets no field.markMcpacceptsannotationsnext toloopKey, andMcpBrandedexposes it astool.annotations.McpToolAnnotationsis exported from the package root.copyToolAnnotations(src/mcp/tool-annotations.ts). So only the five standard hints are kept, from a server and from a snapshot, and the tool, the handle and each snapshot hold separate objects.McpToolAnnotationsfields arereadonly, and each documents the MCP default of an absent hint.isSerializedMCPServerrejects a snapshot whoseannotationsis not an object, or holds a hint that is not a boolean, or a title that is not a string. A consumer may gate approval on a hint, so a wrong type must not read as truthy.Nothing reaches the model: annotations are not part of the wire tool definition.
API example
Behaviour to review
annotations. Older versions ignore the extra field when they read such a snapshot. Snapshots written by older versions have no annotations, so tools rehydrated from them have none until the nextrefresh().truefordestructiveHintandopenWorldHint. The example compares against the default.Tests
tests/unit/mcp/annotations.test.ts:createMCPToolsexposes each tool with the hints its server reported, and none for a tool without annotations.serialize(), after a JSON round trip, restores the same hints throughrehydrateMCPToolswithout callingtools/list.isSerializedMCPServerrejects malformed annotations and accepts well-formed ones.I checked that the first two fail when the
listToolDefschange is removed, and the second fails when therehydratechange is removed.Overlap
#146 also adds an option to
markMcp(wireInputSchema) and edits the same lines intool-wrapper.ts. Whichever lands second needs a small merge there.Review resolutions
364fe4a)364fe4a)readonly(364fe4a)364fe4a)