fix: preserve MCP CallToolResult.meta field in tool output#4806
Open
IanSteno wants to merge 1 commit intolivekit:mainfrom
Open
fix: preserve MCP CallToolResult.meta field in tool output#4806IanSteno wants to merge 1 commit intolivekit:mainfrom
IanSteno wants to merge 1 commit intolivekit:mainfrom
Conversation
The MCP spec (since v1.10.0) supports a `meta` field on CallToolResult for returning sideband metadata from tool executions. The SDK already passes `tool.meta` for tool definitions (raw_schema), but discards `tool_result.meta` when processing tool call results. This preserves the meta field by including it in the returned JSON, allowing consumers to extract metadata (notifications, citations, tracking data) from tool results before they reach the LLM. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
metafield onCallToolResultfor returning sideband metadata from tool executionstool.metafor tool definitions (line 85, 133-134 in mcp.py), buttool_result.metais discarded when processing tool call resultsmetafield by including it in the returned JSON stringProblem
When an MCP server returns a
CallToolResultwith ametafield:The current
_tool_calledfunction only extracts.contentand returns it as JSON, completely discarding.meta. This means consumers of tool results (e.g., event handlers listening toFunctionToolsExecutedEvent) cannot access any metadata the MCP server intended to communicate.Fix
After extracting content into
result, check iftool_result.metais present and merge it into the returned JSON:This is backward-compatible — if
metaisNone(the default), behavior is unchanged.Use Cases
The
metafield enables MCP servers to return sideband data that consumers can intercept before it reaches the LLM:Test plan
tool_result.metaisNone(default case){"content": [...], "meta": {...}}ToolError(meta check is after error handling)🤖 Generated with Claude Code