Skip to content

fix(mcptoolset): preserve non-text MCP tool result content - #1401

Open
ktsoator wants to merge 3 commits into
google:mainfrom
ktsoator:fix/mcptoolset-nontext-content
Open

fix(mcptoolset): preserve non-text MCP tool result content#1401
ktsoator wants to merge 3 commits into
google:mainfrom
ktsoator:fix/mcptoolset-nontext-content

Conversation

@ktsoator

@ktsoator ktsoator commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

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

  • Preserve textual embedded resources in tool responses.
  • Safely decode UTF-8 and US-ASCII embedded blobs with text-like MIME types.
  • Represent binary resources, resource links, images, and audio with relevant URI, MIME type, and size metadata.
  • Preserve content order and existing text-only response behavior.
  • Retain non-text content alongside structured output.
  • Use the same conversion for MCP error details.

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

  • Added table-driven tests for text-only compatibility.
  • Added a GitHub MCP-style text and embedded-resource regression test.
  • Added tests for textual blobs, binary resources, resource links, images, audio, structured output, error responses, and nil resources.
  • go build -mod=readonly work
  • go test -race -mod=readonly -count=1 -shuffle=on work
  • golangci-lint run in every module
  • go mod tidy -diff in every module

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.
@ktsoator

Copy link
Copy Markdown
Contributor Author

Hi @baptmont and @hanorik, when you have a chance, could you please review this PR? It addresses #1391 by surfacing non-text MCP tool result content while preserving existing text-only behavior. All CI checks are passing. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mcptoolset: non-text tool-result content blocks are silently dropped (EmbeddedResource, ResourceLink, Image, Audio)

1 participant