Skip to content

Commit 494e876

Browse files
committed
fix(examples): encode thumbnail as PNG bytes instead of raw pixel data (#3805)
1 parent 77001c9 commit 494e876

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

‎examples/snippets/servers/images.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Example showing image handling with MCPServer."""
22

3+
import io
4+
35
from PIL import Image as PILImage
46

57
from mcp.server.mcpserver import Image, MCPServer
@@ -12,4 +14,6 @@ def create_thumbnail(image_path: str) -> Image:
1214
"""Create a thumbnail from an image"""
1315
img = PILImage.open(image_path)
1416
img.thumbnail((100, 100))
15-
return Image(data=img.tobytes(), format="png")
17+
buf = io.BytesIO()
18+
img.save(buf, format="PNG")
19+
return Image(data=buf.getvalue(), format="png")

0 commit comments

Comments
 (0)