Skip to content

Conversation

@roomote
Copy link
Collaborator

@roomote roomote commented Jun 30, 2025

Summary

This PR fixes issue #5252 where the access_mcp_resource function fails to handle images that don't use the standard data:image/;base64,base64string format.

Problem

Most image resources in MCP servers don't use the data URI format, causing image processing to fail when the system expects all images to be in data:image/png;base64,base64string format.

Solution

Changes Made

  1. Modified accessMcpResourceTool.ts (lines 71-87):

    • Added logic to detect if blob data is already in data URI format
    • Converts raw base64 data to proper data URI format with appropriate MIME type
    • Maintains backward compatibility with existing data URI format
  2. Updated formatImagesIntoBlocks in responses.ts (lines 179-203):

    • Enhanced to handle both data URI and raw base64 formats
    • Extracts MIME type from data URI or defaults to 'image/png' for raw base64
    • Preserves existing functionality for standard data URI format
  3. Added comprehensive test suite (responses-image-handling.spec.ts):

    • Tests standard data URI format handling
    • Tests raw base64 data handling
    • Tests mixed format scenarios
    • Tests different MIME types (PNG, JPEG, GIF, WebP)
    • Tests edge cases (empty arrays, undefined inputs)

Technical Details

  • Backward Compatible: Existing data URI format continues to work unchanged
  • MIME Type Handling: Preserves original MIME types from data URIs, defaults to 'image/png' for raw base64
  • Format Detection: Uses regex pattern to detect data URI vs raw base64 format
  • Error Handling: Graceful fallback to default MIME type if parsing fails

Testing

  • ✅ All new tests pass (9 test cases)
  • ✅ Linting passes
  • ✅ Type checking passes
  • ✅ Maintains backward compatibility

Fixes

Closes #5252


Important

Fixes image handling in accessMcpResourceTool to support both data URI and raw base64 formats, with comprehensive tests added.

  • Behavior:
    • accessMcpResourceTool in accessMcpResourceTool.ts now detects if image blobs are in data URI format and converts raw base64 data to data URI with MIME type.
    • formatImagesIntoBlocks in responses.ts enhanced to handle both data URI and raw base64 formats, defaulting to 'image/png' for raw base64.
  • Testing:
    • New test suite responses-image-handling.spec.ts added to test standard data URI, raw base64, mixed formats, and different MIME types.
  • Misc:
    • Maintains backward compatibility with existing data URI format.

This description was created by Ellipsis for 86e5ff3. You can customize this summary. It will automatically update as commits are pushed.

…urce

- Modified accessMcpResourceTool.ts to detect and convert raw base64 data to proper data URI format
- Updated formatImagesIntoBlocks in responses.ts to handle both data URI and raw base64 formats
- Added comprehensive test suite covering standard data URI, raw base64, mixed formats, and different MIME types
- Maintains backward compatibility with existing data URI format
- Uses 'image/png' as default MIME type for raw base64 data
@roomote roomote requested review from cte, jr and mrubens as code owners June 30, 2025 11:15
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Jun 30, 2025
@delve-auditor
Copy link

delve-auditor bot commented Jun 30, 2025

No security or compliance issues detected. Reviewed everything up to 86e5ff3.

Security Overview
  • 🔎 Scanned files: 3 changed file(s)
Detected Code Changes

The diff is too large to display a summary of code changes.

Reply to this PR with @delve-auditor followed by a description of what change you want and we'll auto-submit a change to this PR to implement it.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jun 30, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jul 7, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Jul 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

bug: access_mcp_resource fails to handle images correctly

3 participants