Skip to content
Discussion options

You must be logged in to vote

JSON serialization and the resource's MIME type are separate here. Returning a dict can produce JSON text while the resource still advertises the default text/plain. A -> dict return annotation does not change that default.

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 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…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ilia-kats
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants