Skip to content

Conversation

@tonypan2
Copy link

Summary

Preserve all MCP tool annotations (readOnlyHint, destructiveHint, idempotentHint, openWorldHint) when converting MCP tools to AI SDK tools.

Changes

Previously, only the title annotation was extracted and preserved from MCP servers. This PR adds support for passing through all five annotation fields defined in the MCP specification (2025-03-26):

  • title - Human-readable tool title
  • readOnlyHint - Tool doesn't modify its environment
  • destructiveHint - Tool may perform destructive updates
  • idempotentHint - Repeated calls with same args have no additional effect
  • openWorldHint - Tool interacts with external entities

Implementation

  1. Added annotations field to Tool type definition in @ai-sdk/provider-utils
  2. Updated dynamicTool() function signature to accept annotations parameter
  3. Pass annotations from MCP listTools response to tool creation in MCP client

Use Cases

These annotations enable clients to:

  • Filter tools by behavior characteristics (e.g., only allow read-only tools in production)
  • Show UI warnings before executing destructive operations
  • Implement smart retry logic for idempotent tools
  • Track/log external system interactions

Security Note

Per the MCP specification, these annotations are informational hints only and should not be used for security-critical decisions. The documentation explicitly states this caveat.

Testing

  • ✅ Existing tests pass
  • ✅ TypeScript types are properly defined
  • ✅ Backward compatible (all fields are optional)

Related

🤖 Generated with Claude Code

Co-Authored-By: Claude [email protected]

Preserve all MCP tool annotations (readOnlyHint, destructiveHint,
idempotentHint, openWorldHint) when converting MCP tools to AI SDK tools.

Previously, only the title annotation was extracted and preserved.
Now the full annotations object is passed through to enable clients
to make informed decisions about tool behavior based on these hints.

Changes:
- Add annotations field to Tool type definition
- Update dynamicTool function to accept annotations parameter
- Pass annotations from MCP listTools response to tool creation

These annotations are informational hints per the MCP spec and should
not be used for security-critical decisions.
@lgrammel
Copy link
Collaborator

lgrammel commented Nov 24, 2025

a) I am not sure how much we should tie MCP to our more abstract tools. This PR bleeds the MCP spec into our tool spec
b) if we want to proceed in the current form, tests and documentation would be good to have

For your use case, is readOnlyHint the main thing you need? If so, we could add that one specifically to our spec because it's usefulness is clear. The other hints are more MCP specific imo.

If that is potential path, then tools could have a metadata or hints property.

@nicoalbanese
Copy link
Collaborator

Agree with @lgrammel and feel strongly that this would be best implemented in some kind of generic tool metadata. This might require some further thinking though

@tonypan2
Copy link
Author

closing as this needs more thinking

@tonypan2 tonypan2 closed this Nov 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants