-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix: add image content support to MCP tool responses #10874
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Fixes #10872 The processToolContent method in UseMcpToolTool.ts now handles image content types from MCP protocol responses (e.g., Figma's get_screenshot). Changes: - Modified processToolContent to return both text and images - Updated executeToolAndProcessResult to pass images to task.say() and pushToolResult() - Added tests for image handling scenarios
✅ PR Review CompleteStatus: Looks good - Ready for merge Tests VerifiedAll 16 tests pass, including 4 new image-handling test cases. Key Findings
Changes Summary
Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Review Complete - Looks Good!
This PR correctly addresses Issue #10872 by adding image content support to MCP tool responses. The implementation is well-structured and follows the existing patterns in the codebase.
Summary of Changes
- Modified
processToolContent()- Now returns bothtextandimagesseparately instead of just concatenated text - Updated
executeToolAndProcessResult()- Properly handles extracted images and passes them totask.say()andpushToolResult() - Added 4 comprehensive test cases for image handling scenarios
Code Quality
✅ Follows existing patterns - The implementation mirrors accessMcpResourceTool.ts which handles images similarly
✅ Good edge case handling - Handles both raw base64 and pre-formatted data URLs
✅ Test coverage - All 16 tests pass, including 4 new image-specific tests
✅ Clean implementation - Changes are well-contained and focused
Minor Observations (Non-blocking)
-
MimeType validation: In
accessMcpResourceTool.ts, image handling validates withitem.mimeType?.startsWith("image"). The PR trustsitem.type === "image"which is correct per the MCP spec, but servers could potentially send non-image data with type "image". This is a theoretical edge case. -
Empty mimeType/data check: The condition at line 271 (
if (item.mimeType && item.data)) is good defensive coding - it silently skips malformed image content rather than crashing.
Overall, this is a clean, well-tested fix that solves the reported issue. Nice work! 🎉
|
Another quality of life improvement will be to show image thumbnails, instead of only showing the text: "[1 image(s) received ]". |

This PR attempts to address Issue #10872.
Problem
MCP tools that return image content (like Figma's
get_screenshottool) were returning(No response)because theprocessToolContentmethod inUseMcpToolTool.tsonly handledtextandresourcecontent types, notimage.Solution
processToolContentto return both text content and images separatelyexecuteToolAndProcessResultto:task.say()andpushToolResult()following the same pattern asaccessMcpResourceTool.tsTesting
All 16 tests pass.
Feedback and guidance are welcome!
Important
Add image content support to MCP tool responses in
UseMcpToolTool.tsand update tests for image handling.processToolContentinUseMcpToolTool.tsnow returns both text and images separately.executeToolAndProcessResultextracts images, converts them to data URLs, and passes them totask.say()andpushToolResult().useMcpToolTool.spec.tsfor image handling scenarios: only image content, both text and image content, pre-formatted data URLs, and multiple images.formatResponse.toolResultmock inuseMcpToolTool.spec.tsto handle images.This description was created by
for bb488fe. You can customize this summary. It will automatically update as commits are pushed.