test_image_conversion.pyโข2.37 kB
#!/usr/bin/env python3
"""
Comprehensive test for the ORLY MCP server showing image conversion to ImageContent
"""
import sys
import os
# Add the current directory to the path
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from orly_mcp.server import generate_orly_cover
from mcp.types import ImageContent
def test_image_conversion():
"""Test that the tool properly converts to ImageContent for MCP"""
print("๐งช Testing ORLY MCP tool image conversion...")
try:
# Generate a cover with lower scale (1.0 = 500x700px instead of 1500x2100px)
image_result = generate_orly_cover(
title="Windows WPF",
author="Microsoft Corp",
subtitle="Super Future Technology!!!",
guide_text="The 'F' Stands for 'Forever'",
guide_text_placement="bottom_right",
scale=1.0 # Much smaller resolution for testing
)
print(f"โ
Generated Image object: {type(image_result)}")
# Convert to ImageContent (this is what MCP does internally)
image_content = image_result.to_image_content()
print(f"๐ผ๏ธ Converted to ImageContent: {type(image_content)}")
print(f"๐ MIME Type: {image_content.mimeType}")
print(f"๐ Base64 data length: {len(image_content.data)} characters")
print(f"๐ท๏ธ Content type: {image_content.type}")
# Verify it's proper ImageContent
assert isinstance(image_content, ImageContent)
assert image_content.type == "image"
assert image_content.mimeType == "image/png"
assert len(image_content.data) > 0
# Test base64 decoding
import base64
decoded_data = base64.b64decode(image_content.data)
print(f"๐ข Decoded image size: {len(decoded_data)} bytes")
# Verify PNG header
if decoded_data.startswith(b'\x89PNG\r\n\x1a\n'):
print("โ
Valid PNG file detected!")
else:
print("โ ๏ธ Warning: PNG header not detected")
print("\n๐ All tests passed! The MCP server will display images directly in chat.")
except Exception as e:
print(f"โ Test failed: {e}")
import traceback
traceback.print_exc()
if __name__ == "__main__":
test_image_conversion()