* feat: allow lowlevel servers to return a list of resources The resource/read message in MCP allows of multiple resources to be returned. However, in the SDK we do not allow this. This change is such that we allow returning multiple resource in the lowlevel API if needed. However in FastMCP we stick to one, since a FastMCP resource defines the mime_type in the decorator and hence a resource cannot dynamically return different mime_typed resources. It also is just the better default to only return one resource. However in the lowlevel API we will allow this. Strictly speaking this is not a BC break since the new return value is additive, but if people subclassed server, it will break them. * feat: lower the type requriements for call_tool to Iterable
This commit is contained in:
parent
2eb9d1786a
commit
c8ce49c92d
2 changed files with 62 additions and 32 deletions
|
|
@ -51,8 +51,10 @@ async def test_resource_template_edge_cases():
|
|||
|
||||
# Verify valid template works
|
||||
result = await mcp.read_resource("resource://users/123/posts/456")
|
||||
assert result.content == "Post 456 by user 123"
|
||||
assert result.mime_type == "text/plain"
|
||||
result_list = list(result)
|
||||
assert len(result_list) == 1
|
||||
assert result_list[0].content == "Post 456 by user 123"
|
||||
assert result_list[0].mime_type == "text/plain"
|
||||
|
||||
# Verify invalid parameters raise error
|
||||
with pytest.raises(ValueError, match="Unknown resource"):
|
||||
|
|
|
|||
|
|
@ -99,11 +99,11 @@ async def test_lowlevel_resource_mime_type():
|
|||
@server.read_resource()
|
||||
async def handle_read_resource(uri: AnyUrl):
|
||||
if str(uri) == "test://image":
|
||||
return ReadResourceContents(content=base64_string, mime_type="image/png")
|
||||
return [ReadResourceContents(content=base64_string, mime_type="image/png")]
|
||||
elif str(uri) == "test://image_bytes":
|
||||
return ReadResourceContents(
|
||||
content=bytes(image_bytes), mime_type="image/png"
|
||||
)
|
||||
return [
|
||||
ReadResourceContents(content=bytes(image_bytes), mime_type="image/png")
|
||||
]
|
||||
raise Exception(f"Resource not found: {uri}")
|
||||
|
||||
# Test that resources are listed with correct mime type
|
||||
|
|
|
|||
Loading…
Reference in a new issue