|
29 | 29 | UnexpectedModelBehavior, |
30 | 30 | UserError, |
31 | 31 | ) |
32 | | -from pydantic_ai.mcp import MCPError, MCPServerStreamableHTTP, Resource, ServerCapabilities, load_mcp_servers |
| 32 | +from pydantic_ai.mcp import ( |
| 33 | + MCPError, |
| 34 | + MCPServerStreamableHTTP, |
| 35 | + Resource, |
| 36 | + ResourceAnnotations, |
| 37 | + ResourceTemplate, |
| 38 | + ServerCapabilities, |
| 39 | + load_mcp_servers, |
| 40 | +) |
33 | 41 | from pydantic_ai.models import Model |
34 | 42 | from pydantic_ai.models.test import TestModel |
35 | 43 | from pydantic_ai.tools import RunContext |
@@ -328,36 +336,35 @@ async def test_stdio_server_list_resources(run_context: RunContext[int]): |
328 | 336 | server = MCPServerStdio('python', ['-m', 'tests.mcp_server']) |
329 | 337 | async with server: |
330 | 338 | resources = await server.list_resources() |
331 | | - assert len(resources) == snapshot(3) |
332 | | - |
333 | | - assert resources[0].uri == snapshot('resource://kiwi.png') |
334 | | - assert resources[0].mime_type == snapshot('image/png') |
335 | | - assert resources[0].name == snapshot('kiwi_resource') |
336 | | - assert resources[0].annotations is None |
337 | | - |
338 | | - assert resources[1].uri == snapshot('resource://marcelo.mp3') |
339 | | - assert resources[1].mime_type == snapshot('audio/mpeg') |
340 | | - assert resources[1].name == snapshot('marcelo_resource') |
341 | | - assert resources[1].annotations is None |
342 | | - |
343 | | - assert resources[2].uri == snapshot('resource://product_name.txt') |
344 | | - assert resources[2].mime_type == snapshot('text/plain') |
345 | | - assert resources[2].name == snapshot('product_name_resource') |
346 | | - # Test ResourceAnnotations |
347 | | - assert resources[2].annotations is not None |
348 | | - assert resources[2].annotations.audience == snapshot(['user', 'assistant']) |
349 | | - assert resources[2].annotations.priority == snapshot(0.5) |
| 339 | + assert resources == snapshot( |
| 340 | + [ |
| 341 | + Resource(name='kiwi_resource', description='', mime_type='image/png', uri='resource://kiwi.png'), |
| 342 | + Resource(name='marcelo_resource', description='', mime_type='audio/mpeg', uri='resource://marcelo.mp3'), |
| 343 | + Resource( |
| 344 | + name='product_name_resource', |
| 345 | + description='', |
| 346 | + mime_type='text/plain', |
| 347 | + annotations=ResourceAnnotations(audience=['user', 'assistant'], priority=0.5), |
| 348 | + uri='resource://product_name.txt', |
| 349 | + ), |
| 350 | + ] |
| 351 | + ) |
350 | 352 |
|
351 | 353 |
|
352 | 354 | async def test_stdio_server_list_resource_templates(run_context: RunContext[int]): |
353 | 355 | server = MCPServerStdio('python', ['-m', 'tests.mcp_server']) |
354 | 356 | async with server: |
355 | 357 | resource_templates = await server.list_resource_templates() |
356 | | - assert len(resource_templates) == snapshot(1) |
357 | | - |
358 | | - assert resource_templates[0].uri_template == snapshot('resource://greeting/{name}') |
359 | | - assert resource_templates[0].name == snapshot('greeting_resource_template') |
360 | | - assert resource_templates[0].description == snapshot('Dynamic greeting resource template.') |
| 358 | + assert resource_templates == snapshot( |
| 359 | + [ |
| 360 | + ResourceTemplate( |
| 361 | + name='greeting_resource_template', |
| 362 | + description='Dynamic greeting resource template.', |
| 363 | + mime_type='text/plain', |
| 364 | + uri_template='resource://greeting/{name}', |
| 365 | + ) |
| 366 | + ] |
| 367 | + ) |
361 | 368 |
|
362 | 369 |
|
363 | 370 | async def test_log_level_set(run_context: RunContext[int]): |
|
0 commit comments