Repository navigation
fix(core): keep unsupported MCP media out of tool attachments - #57640
Conversation
There was a problem hiding this comment.
Looks good. I reproduced #54798 on the base branch: the request after the MCP tool call failed with Anthropic Messages does not support media type text/markdown, and so did every later turn. With this branch both turns go through. The markdown arrives as text in the tool result and the PNG is still sent as an image. A session broken on the base branch also recovers when continued on this branch, thanks to the request-time fallback.
bun test test/mcp.test.ts test/session-model-request.test.ts passes, except for the MCP descendant-termination test, which fails on dev too. packages/core type-checks.
Public API is unchanged: ToolOutput.save and the optional uri on MCP media content are internal to core.
No blocking concerns.
Related: #55271
Fixes #54798
Fixes #52448
Problem
MCP tool calls stored every non-text result as a tool attachment with whatever media type the server declared. A Jira attachment arriving as
text/markdownortext/x-patch, or a.parquetfile, ended up as afileitem that no provider route can send. The next request failed before it left the client:That attachment stays in history, so every later turn in the session failed the same way.
Every other path (the read tool, webfetch, user attachments) only ever sends PNG, JPEG, GIF, WebP and PDF. The MCP tool path was the only one with no filter.
Change
MCP tool results now follow the same rule as the read tool:
ToolOutput.save(bytes, extension)writes to the sametool-output/folder as truncated output, with the sametool_<id>names, so the existing 7 day cleanup removes these files too.uriso the note can name the resource.read_mcp_resourceuses the same image/PDF allowlist, soimage/svg+xmland other image types no longer get attached.isTextualmoved from webfetch intoMimeso both callers share it.Out of scope
read_mcp_resourcestill returns non-image blobs as base64 in its structured output.Verification
bun test test/mcp.test.ts(new case for decoded text and saved binaries)bun run testinpackages/core: only the shell parity failures that also fail on cleandevbun run checkAdded by the opencode bot (AI-generated).
Related: #55271