Can MCP resources return structured JSON instead of a text string?
In the modelcontextprotocol python-sdk, I use FastMCP to define a resource that returns a Pydantic model with mime_type='application/json'. The MCP response wraps the JSON as an escaped string in the text field, so clients must parse it again. Is there a way to make resources return structured JSON like tools' structuredContent?
Originally asked on GitHub: https://github.com/modelcontextprotocol/python-sdk/issues/279
4 answers
The issue was closed as explained: this is a limitation of the MCP specification, not of the python-sdk. Resource contents currently support only text and blob formats, so there is no structured JSON equivalent to the structuredContent field that tools support. A maintainer confirmed this on the thread, noted that structured output can be done via tools, and closed the issue after pointing to the open feature request in the spec repo: modelcontextprotocol/modelcontextprotocol#956.
The workaround given in the thread is to expose the data as a tool instead of a resource. Tools support structuredContent, which returns structured data directly rather than a string that the client has to parse. The maintainer also said many implementations use tools for pure data retrieval for this reason, and a commenter observed that projects such as Google's GenAI Toolbox expose dataset and table information through tools. In the meantime, a resource with mime_type='application/json' will keep returning the JSON serialized into the text field. If you have a concrete use case for structured resources, the maintainer asked for details and pointed to the spec issue to track it.
Did this work for you?What a GitHub user tried on GitHub (Didn't work)
Reproduced the problem with a minimal FastMCP resource that returns a Pydantic model with mime_type='application/json'. The response contained the model as an escaped JSON string in the text field instead of a structured data field.
Source: https://github.com/modelcontextprotocol/python-sdk/issues/279 (opens external site)
Did this work for you?What @felixweinberger tried on GitHub (Outcome unclear)
A maintainer explained that resources are intended to support only text and blob formats right now and suggested using tools for structured output.
Did this work for you?What @maxisbey tried on GitHub (Outcome unclear)
A maintainer confirmed the limitation is in the MCP spec, referenced open feature request #956, and recommended tools with structuredContent for structured output, then closed the issue.
Did this work for you?
Related questions
- MCP python-sdk simple-chatbot: 'Attempted to exit cancel scope in a different task than it was entered in'
- Why is my MCP resource template (greeting://{name}) not available in Claude Desktop?
- How to disable TLS certificate verification (verify=False) in MCP streamablehttp_client?
- anyio.ClosedResourceError in MCP StreamableHTTP message router on fast-failing requests?
- Python MCP SDK streamable HTTP: 'Error in message router' ClosedResourceError after 307 redirect