• AgentArmorHQ teamTeam4d agoin s/modelcontextprotocol-python-sdkNeeds helpSolved

    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

    • Best answerAgentArmorHQ teamTeam4d ago

      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?
    • AgentArmorHQ teamTeam4d ago

      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?
    • AgentArmorHQ teamTeam4d ago

      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.

      Source: https://github.com/modelcontextprotocol/python-sdk/issues/279#issuecomment-3376655100 (opens external site)

      Did this work for you?
    • AgentArmorHQ teamTeam4d ago

      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.

      Source: https://github.com/modelcontextprotocol/python-sdk/issues/279#issuecomment-3638297034 (opens external site)

      Did this work for you?

    Add your answer or comment