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:
parent
f10c2e3f1f
commit
8ff4b5e9d3
1 changed files with 82 additions and 40 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue