Skip to content

Commit 18743cd

Browse files
committed
Add test coverage for ResourceAnnotations now that we can.
1 parent 6857ef2 commit 18743cd

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

tests/mcp_server.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from mcp.server.fastmcp import Context, FastMCP, Image
66
from mcp.server.session import ServerSession
77
from mcp.types import (
8+
Annotations,
89
BlobResourceContents,
910
CreateMessageResult,
1011
EmbeddedResource,
@@ -120,7 +121,11 @@ async def get_product_name_link() -> ResourceLink:
120121
)
121122

122123

123-
@mcp.resource('resource://product_name.txt', mime_type='text/plain')
124+
@mcp.resource(
125+
'resource://product_name.txt',
126+
mime_type='text/plain',
127+
annotations=Annotations(audience=['user', 'assistant'], priority=0.5),
128+
)
124129
async def product_name_resource() -> str:
125130
return Path(__file__).parent.joinpath('assets/product_name.txt').read_text()
126131

tests/test_mcp.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,14 +330,20 @@ async def test_stdio_server_list_resources(run_context: RunContext[int]):
330330
assert resources[0].uri == snapshot('resource://kiwi.png')
331331
assert resources[0].mime_type == snapshot('image/png')
332332
assert resources[0].name == snapshot('kiwi_resource')
333+
assert resources[0].annotations is None
333334

334335
assert resources[1].uri == snapshot('resource://marcelo.mp3')
335336
assert resources[1].mime_type == snapshot('audio/mpeg')
336337
assert resources[1].name == snapshot('marcelo_resource')
338+
assert resources[1].annotations is None
337339

338340
assert resources[2].uri == snapshot('resource://product_name.txt')
339341
assert resources[2].mime_type == snapshot('text/plain')
340342
assert resources[2].name == snapshot('product_name_resource')
343+
# Test ResourceAnnotations
344+
assert resources[2].annotations is not None
345+
assert resources[2].annotations.audience == snapshot(['user', 'assistant'])
346+
assert resources[2].annotations.priority == snapshot(0.5)
341347

342348

343349
async def test_stdio_server_list_resource_templates(run_context: RunContext[int]):

0 commit comments

Comments
 (0)