mirror of
https://github.com/aljazceru/mcp-python-sdk.git
synced 2025-12-30 20:24:25 +01:00
fix: respect resource mime type in responses
The server was ignoring mime types set on resources, defaulting to text/plain for strings and application/octet-stream for bytes. Now properly preserves the specified mime type in both FastMCP and low-level server implementations. Note that this is breaks backwards compatibility as it changes the return values of read_resource() on FastMCP. It is BC compatible on lowlevel since it only extends the callback. Github-Issue: #152 Reported-by: eiseleMichael
This commit is contained in:
@@ -98,9 +98,9 @@ async def test_lowlevel_resource_mime_type():
|
||||
@server.read_resource()
|
||||
async def handle_read_resource(uri: AnyUrl):
|
||||
if str(uri) == "test://image":
|
||||
return base64_string
|
||||
return (base64_string, "image/png")
|
||||
elif str(uri) == "test://image_bytes":
|
||||
return image_bytes
|
||||
return (bytes(image_bytes), "image/png")
|
||||
raise Exception(f"Resource not found: {uri}")
|
||||
|
||||
# Test that resources are listed with correct mime type
|
||||
|
||||
Reference in New Issue
Block a user