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:
David Soria Parra 2025-01-24 14:20:42 +00:00
commit 8ff4b5e9d3
No known key found for this signature in database

View file

@ -581,8 +581,8 @@ class TestContextInjection:
@mcp.tool()
async def tool_with_resource(ctx: Context) -> str:
data = await ctx.read_resource("test://data")
return f"Read resource: {data}"
data, mime_type = await ctx.read_resource("test://data")
return f"Read resource: {data} with mime type {mime_type}"
async with client_session(mcp._mcp_server) as client:
result = await client.call_tool("tool_with_resource", {})