Skip to content

fix(agent-runtime): keep MCP embedded resource text in tool results - #1551

Merged
vastsa merged 3 commits into
vastsa:mainfrom
xpeng5278-web:fix/mcp-embedded-resource-text
Oct 11, 2026
Merged

vastsa merged 3 commits into
vastsa:mainfrom
xpeng5278-web:fix/mcp-embedded-resource-text

Conversation

@xpeng5278-web

Copy link
Copy Markdown
Contributor

Summary

Fixes #1549

When an MCP tool result has a text block, the host tool bridge sent only text and image blocks to the model. It dropped resource (embedded resource) and resource_link blocks. github-mcp-server get_file_contents returns a status line plus the file body as an embedded text resource, so the agent saw "successfully downloaded text file" but not the file.

This change adds a small hostContentBlockText helper, used by both the MCP content branch and the bare content-block-array branch:

  • text → its text (unchanged)
  • resource with resource.text → the resource text
  • resource_link → a one-line [resource link] <name>: <uri> reference
  • binary resources and other kinds → still not inlined (no base64 in the text channel)

Image handling, details, and the JSON fallback for results with no text-like blocks are unchanged. Restored history already reads the normalized content, so the text survives a restart.

Tests

  • New runtime.test.ts case uses the github-mcp-server response shape (status text + embedded resource + resource link). It fails on main (the model text is only the status line) and passes with this change.
  • packages/agent-runtime: vitest run → 96 files / 1329 tests pass; tsc --noEmit clean.
  • pnpm lint:biome, pnpm check:pr-base pass.

Docs

docs/spec/03-runtime/02-agent-runtime.md §3.3 now documents embedded text resources and resource links.

A host tool result shaped as MCP content only forwarded text and image
blocks to the model. github-mcp-server get_file_contents returns a status
line plus the file body as an embedded text resource (and a resource link
for large files), so the model saw "successfully downloaded text file"
and never the file. Render embedded text resources and resource links into
the model-visible text alongside sibling text blocks.

@muzimu217 muzimu217 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified locally on macOS (worktree off current main): agent-runtime full suite 96 files / 1329 tests pass, including the new embedded-resource cases.

The fix restores a real capability loss: github-mcp-server's get_file_contents returns the file body as an embedded resource block, and the host bridge was passing through only text and image blocks — so the agent saw "successfully downloaded text file" with no file. hostContentBlockText handling resource/resource_link (with the resource URI in the rendered text, so the model can cite what it read) applied on both the content branch and the bare content-block-array branch is the right minimal shape.

One nuance worth stating in the review for future readers (not blocking): a large embedded resource now lands in full in the model context, which can push long files toward the overflow path — acceptable, since #1517's classification (merged) makes that surface correctly instead of looping.

Nothing blocking. fix scope, fits the window.

@vastsa vastsa left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed that host tool normalization kept only text and image blocks, which dropped embedded text resources and resource links whenever a status line was present. The fix handles both MCP content shapes and preserves the body/link for the model. Current-main checks all pass.

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.

[Bug] MCP tool results drop embedded resources (github-mcp-server get_file_contents returns only the status line)

3 participants