Add support for MCP tool annotations
Problem
The annotation hints are lost when getting the tools from the experimental_createMCPClient.
Use case
I want to be able to require execution confirmation for some of the tools from my MCP.
Details
I'm using the experimental_createMCPClient to get the tools from my MCP and pass it into the ai-sdk. This part is working great! But some of the tools should need user confirmation before being executed by the LLM.
As far as I know, the official way to handle this is through tool annotation hints. (e.g. { destructiveHint: true })
I was planning to use the hints to manually remove the tool's execute parameter, so that it becomes a HITL tool (as per the HITL cookbook). But then I realized it wasn't possible because the hints are lost when I get the tools.
Please let me know if there is a workaround to achieve this.
Thanks in advance!
AI SDK Version
ai: 4.3.16
Identify issue type
Identified type: Feature
Confidence: High
Rationale: The issue requests support for preserving/exposing MCP tool annotation hints as an additional capability. It is not framed as a violation of documented AI SDK behavior, so it is best classified as a feature request.
Evidence:
- Title asks to “Add support for MCP tool annotations.”
- Description says annotation hints such as
destructiveHintare lost when tools are obtained fromexperimental_createMCPClient. - Reporter wants to use those hints to require user confirmation / human-in-the-loop execution for MCP tools and asks for a workaround.
Opened #16752 to implement this.
The earlier attempt (#10463) was closed on design grounds — @lgrammel noted it "bleeds the MCP spec into our tool spec" by adding an MCP-shaped annotations field onto the core Tool type, suggested a generic metadata/hints property instead, and asked for tests + docs; @nicoalbanese "feel[s] strongly that this would be best implemented in some kind of generic tool metadata."
This PR is built around that feedback:
- No changes to the core
Tooltype.@ai-sdk/provider-utils,@ai-sdk/provider, andaiare untouched — all production changes are confined to@ai-sdk/mcp. The MCP spec never reaches the abstract tool spec. - Rides the existing generic metadata container — the "generic tool metadata" both of you pointed at. The core
Toolalready exposesmetadata?: JSONObject(which propagates to the tool call'stoolMetadata); the MCP client just writes the hints into it under a namespacedannotationskey. MCP's vocabulary is typed only inside@ai-sdk/mcp. - Namespaced, not flattened, so the hints can't collide with sibling metadata keys and stay self-evidently MCP-sourced.
- All four hints pass through, but only as generic MCP-local metadata — so there's no cost to including
destructive/idempotent/openWorld(anddestructiveHintis the one this issue was really about, for confirmation-gating). - Cast-free consumer ergonomics + correct scoping via two small helpers:
isMCPToolCall(source)to detect MCP tools and scope logic (so a generictoolApprovaldoesn't accidentally gate non-MCP tools), andgetMCPToolAnnotations(source)to read the typed hints without casting. - Tests, docs, and a runnable example included.
Usage — gating execution on the hints via toolApproval:
import { getMCPToolAnnotations, isMCPToolCall } from '@ai-sdk/mcp';
await generateText({
model,
tools: await client.tools(),
toolApproval: ({ toolCall }) => {
if (isMCPToolCall(toolCall)) {
const a = getMCPToolAnnotations(toolCall);
if (a?.readOnlyHint === true) return 'approved';
if (a?.destructiveHint === true) return 'user-approval';
return 'user-approval';
}
// your own policy for non-MCP tools
return 'approved';
},
prompt: '…',
});
Feedback on the design welcome before it's reviewed in depth.