Skip to content

The MCP tool does not save the image data as an image file. #9817

@CDSR-JY

Description

@CDSR-JY

Problem (one or two sentences)

The MCP tool does not save the image data as an image file. tool response is: CallToolResult(content=[ImageContent(type='image', data='/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAA..........//2Q==', mimeType='image/jpg', annotations=None, meta=None)], structured_content=None, meta=None, data=None, is_error=False)

Context (who is affected and when)

my mcp tool is:
@mcp.tool
async def text_to_image(
images_description: str
) -> ContentBlock:
"""
Generate an image based on the provided description.

Args:
    images_description: The English description for generating the image. Must be in English.
    
Returns:
    fastmcp.utilities.types.Image: The generated image object.
"""

# Test connectivity to the image generation service
if not test_url_connection(sd_url):
    raise Exception("Image generation service is unavailable. Please try again later.")
    
try:
    response = requests.post(url=sd_url, json={"prompt": images_description}, timeout=360)
    response.raise_for_status()
    # The following function returns the image content as base64
    # def image_to_base64(image):
    # # Convert the image object to a byte stream
    # with io.BytesIO() as output_buffer:
    #     image.save(output_buffer, format="JPEG")  # Adjust the format according to actual needs
    #     image_bytes = output_buffer.getvalue()
    # # Encode the byte stream into Base64
    # encoded_image_str = base64.b64encode(image_bytes).decode('utf-8')
    # return encoded_image_str
    image_data = response.json().get("image", "")
except Exception as e:
    logger.error(e)
    raise Exception("The image generation system is busy. Please try again later.")

if image_data:
    # First method: pass the image as base64
    image_content = ImageContent(
        type="image",
        data=image_data,
        mimeType="image/jpg",
    )
    return image_content
    # Second method: pass the image as binary data
    # image_bytes = base64.b64decode(image_data)
    # return Image(data=image_bytes, format="jpg")
else:
    raise Exception("The image generation system is busy. Please try again later.")

Desired behavior (conceptual, not technical)

The tool responded normally, but it shows "no response". Possibly didn't to get the image content.

Constraints / preferences (optional)

No response

Request checklist

  • I've searched existing Issues and Discussions for duplicates
  • This describes a specific problem with clear context and impact

Roo Code Task Links (optional)

No response

Acceptance criteria (optional)

No response

Proposed approach (optional)

No response

Trade-offs / risks (optional)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue/PR - TriageNew issue. Needs quick review to confirm validity and assign labels.bugSomething isn't workingenhancementNew feature or request

    Type

    No type

    Projects

    Status

    Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions