fix(mcptoolset): preserve non-text MCP tool result content - #1401
Open
ktsoator wants to merge 3 commits into
Open
fix(mcptoolset): preserve non-text MCP tool result content#1401ktsoator wants to merge 3 commits into
ktsoator wants to merge 3 commits into
Conversation
MCP tool result conversion discarded all non-text content blocks, preventing agents from seeing embedded file contents and resource links. Render textual embedded resources into tool responses, describe binary resources and media with relevant metadata, and retain non-text content alongside structured output. Reuse the same conversion for error details while preserving existing text-only response behavior. Fixes google#1391
Decode text-like embedded resource blobs only when their declared charset and byte content can be represented safely as UTF-8. Fall back to resource metadata for unsupported charsets or invalid UTF-8 instead of passing corrupted text to the model.
Contributor
Author
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.
Link to Issue or Description of Change
Thanks @lukephillippi for the detailed report and real-world reproduction.
Problem
mcpTool.Run only retained TextContent from MCP tool results. EmbeddedResource, ResourceLink, ImageContent, and AudioContent were silently discarded.
This prevented agents from receiving file contents returned by GitHub's MCP server and also dropped non-text content from error and structured responses.
Solution
FunctionTool.Run currently exposes a JSON response rather than function-response media parts, so image and audio blocks are represented by metadata in this focused change. Native inline media support can be addressed separately.
Testing Plan