|
10 | 10 | # pyright: reportUnknownArgumentType=false |
11 | 11 |
|
12 | 12 | import json |
| 13 | +from pathlib import Path |
13 | 14 |
|
14 | 15 | import pytest |
15 | 16 | from inline_snapshot import snapshot |
|
19 | 20 | ElicitRequestParams, |
20 | 21 | ElicitResult, |
21 | 22 | GetPromptResult, |
| 23 | + ImageContent, |
22 | 24 | LoggingMessageNotification, |
23 | 25 | LoggingMessageNotificationParams, |
24 | 26 | NotificationParams, |
|
40 | 42 | basic_tool, |
41 | 43 | completion, |
42 | 44 | elicitation, |
| 45 | + images, |
43 | 46 | mcpserver_quickstart, |
44 | 47 | notifications, |
45 | 48 | sampling, |
@@ -342,3 +345,27 @@ async def test_structured_output() -> None: |
342 | 345 | assert "sunny" in result_text # condition |
343 | 346 | assert "45" in result_text # humidity |
344 | 347 | assert "5.2" in result_text # wind_speed |
| 348 | + |
| 349 | + |
| 350 | +async def test_images_thumbnail(tmp_path: Path) -> None: |
| 351 | + """Test image thumbnail creation with valid PNG encoding.""" |
| 352 | + import base64 |
| 353 | + import io |
| 354 | + |
| 355 | + from PIL import Image as PILImage |
| 356 | + |
| 357 | + img_file = tmp_path / "test.png" |
| 358 | + PILImage.new("RGB", (200, 200), (255, 0, 0)).save(img_file, format="PNG") |
| 359 | + |
| 360 | + async with Client(images.mcp) as client: |
| 361 | + result = await client.call_tool("create_thumbnail", {"image_path": str(img_file)}) |
| 362 | + assert len(result.content) == 1 |
| 363 | + content = result.content[0] |
| 364 | + assert isinstance(content, ImageContent) |
| 365 | + assert content.mime_type == "image/png" |
| 366 | + |
| 367 | + # Verify decoded bytes form a valid PIL image |
| 368 | + decoded = base64.b64decode(content.data) |
| 369 | + with PILImage.open(io.BytesIO(decoded)) as decoded_img: |
| 370 | + assert decoded_img.format == "PNG" |
| 371 | + assert decoded_img.size == (100, 100) |
0 commit comments