Skip to content

Commit 14c3973

Browse files
committed
Test cleanups.
1 parent 21ad2b0 commit 14c3973

File tree

2 files changed

+33
-25
lines changed

2 files changed

+33
-25
lines changed

pydantic_ai_slim/pydantic_ai/mcp.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
'load_mcp_servers',
5353
'MCPError',
5454
'Resource',
55+
'ResourceAnnotations',
5556
'ResourceTemplate',
5657
'ServerCapabilities',
5758
)

tests/test_mcp.py

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,15 @@
2929
UnexpectedModelBehavior,
3030
UserError,
3131
)
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+
)
3341
from pydantic_ai.models import Model
3442
from pydantic_ai.models.test import TestModel
3543
from pydantic_ai.tools import RunContext
@@ -328,36 +336,35 @@ async def test_stdio_server_list_resources(run_context: RunContext[int]):
328336
server = MCPServerStdio('python', ['-m', 'tests.mcp_server'])
329337
async with server:
330338
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+
)
350352

351353

352354
async def test_stdio_server_list_resource_templates(run_context: RunContext[int]):
353355
server = MCPServerStdio('python', ['-m', 'tests.mcp_server'])
354356
async with server:
355357
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+
)
361368

362369

363370
async def test_log_level_set(run_context: RunContext[int]):

0 commit comments

Comments
 (0)