Repository navigation
fix(decopilot): show MCP image results to the model instead of base64 text - #7870
Open
yuriassuncx wants to merge 1 commit into
Open
yuriassuncx wants to merge 1 commit into
yuriassuncx wants to merge 1 commit into
Conversation
… text toModelOutput stringified every non-text MCP content block, so an image returned by an MCP tool reached the model as a JSON string holding its base64 bytes: unreadable, about 1 token per 4 bytes, and large enough to push the whole result past the 32k-token cap so even the text was replaced by a read_tool_output preview. Queue those images on pendingImages, the path take_screenshot and the VM Read tool already use (prepareStep attaches them as a user message, which every provider accepts), and leave a short text placeholder in the tool result. Without a queue, or above 5 MB, the image is only described. The tool result the UI renders is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
@pedrofrxncx could you take a look at this one? I'd like your read on whether the approach makes sense before it goes in. Context: I'm adding a Figma MCP in decocms/mcps#558, so task-board agents get a real reference to the design (screenshot, layout as CSS, comments) instead of guessing. When I tested it through a Studio connection, the decopilot chat sent the screenshot to the model as base64 text. That was about 25k tokens for a 450×768 frame, and the model couldn't see the image. On larger frames the result went over the 32k cap, and the whole result, text outline included, was replaced by a What I'd like you to check:
Thanks! |
This branch has not been deployed
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.
What is this contribution about?
When an MCP tool returns
imagecontent, decopilot sends it to the model as text.toModelOutputinmcp-tools.tsrunsJSON.stringifyon every non-text block, so the model gets a JSON string holding the base64 bytes.Measured with the new Figma MCP (decocms/mcps#558). One
get_design_contextcall on a 450×768 frame returned 100,341 bytes, about 25k tokens, almost all of it the PNG as base64. The model cannot read that. On larger frames the total goes overMAX_RESULT_TOKENS(32k), andtruncateForModelthen replaces the whole result, including the useful text outline, with aread_tool_outputpreview.Studio already has a way to show tool images to the model.
take_screenshotand the VMReadtool put images onpendingImages, andprepareStepattaches them as a user message. The comment inbuilt-in-tools/index.tsexplains why: images inside tool-result messages are not supported by every provider, but images in user content are. This PR routes MCP images through the same queue:attachToolResultImagesswaps eachimageblock for a short placeholder,[image/png image, 98 KB, attached below], and queues the bytes onpendingImages.toolCallIdqueues its images only once, even iftoModelOutputruns again.tools.tspassesextras.pendingImages, the queue the built-in tools already share, intotoolsFromMCP.Behavior change on non-image results: none. They take the same code path as before.
Why not put the image inside the tool result?
AI SDK v7 does support
{ type: "content", value: [..., { type: "file", mediaType, data }] }. I checked how each provider converts it:input_imageJSON.stringify: back to base64 textThe
pendingImagespath works the same way for all of them, and it is the convention Studio already uses.Related PRs
How did you verify your code works?
mcp-tools.test.ts(3 tests):toolsFromMCP: a result of about 400 KB of base64 plus text gives the model"[image/png image, 293 KB, attached below]\nFRAME Card 320x200"instead of a truncation preview. The image is queued once across twotoModelOutputcalls, and the original result keeps itsimageblock.bun test src/harnesses/lib/decopilot: 188 pass, 0 fail.tsc --noEmitinapps/api: clean.biome formatandoxlinton the changed files: clean. The kebab-case filename warning already existed.How to Test
get_design_contexton a frame link.Review Checklist
🤖 Generated with Claude Code
Summary by cubic
Shows MCP tool image results to the model as attached images instead of unreadable base64 text.
read_tool_outputpreview.pendingImagesqueue used bytake_screenshotand the VMReadtool, leaving a short text placeholder in the model-bound tool result.imageblock.Written for commit f87ff0a. Summary will update on new commits.