Repository navigation
resource mimetype not set to JSON automatically #2411
|
As far as I understand the docs, if a resource function's return value is converted to JSON, also the mimetype will be automatically set to Am I misunderstanding the docs or is there something missing here? |
Replies: 1 comment
|
JSON serialization and the resource's MIME type are separate here. Returning a Set the MIME type explicitly on the resource: from fastmcp import FastMCP
mcp = FastMCP("example")
@mcp.resource("data://config", mime_type="application/json")
def config() -> dict:
return {"ok": True}There is no need to call The current return-value documentation now explains that JSON-native return values retain the resource's declared MIME type. So the automatic JSON conversion does not imply automatic I verified both |
JSON serialization and the resource's MIME type are separate here. Returning a
dictcan produce JSON text while the resource still advertises the defaulttext/plain. A-> dictreturn annotation does not change that default.Set the MIME type explicitly on the resource:
There is no need to call
json.dumps()for that dictionary. If your function already returns a JSON string, keep the explicit MIME type as well.The current return-value documentation now explains that JSON-native return values retain the resource's declared MIME ty…