mcptools icon indicating copy to clipboard operation
mcptools copied to clipboard

No support for structuredContent in tool results (MCP spec 2025-06-18)

Open mrcanofcatfood opened this issue 6 months ago • 0 comments

Problem

The MCP spec (2025-06-18) defines a structuredContent field on tool results — a JSON object that provides machine-readable structured output alongside the human-readable content text.

Currently, as_tool_call_result() only produces content (text-only). There's no path for structuredContent.

Expected

When a tool returns a list/data structure, the result should include both:

{
  "content": [
    {"type": "text", "text": "{\"auc\": 0.92, \"tss\": 0.81}"}
  ],
  "structuredContent": {
    "auc": 0.92,
    "tss": 0.81
  }
}
  • content: Human-readable text (for backwards compatibility)
  • structuredContent: Machine-readable JSON (for clients that support it)

Per spec: "For backwards compatibility, a tool that returns structured content SHOULD also return the serialized JSON in a TextContent block."

Use Case

SDM MCP server with ~70 tools. Each tool produces structured results (model metrics, file paths, area statistics). Clients that understand structuredContent get validated, typed data. Others fall back to text. This is the biggest quality-of-life improvement for tool-heavy servers.

Fix

In as_tool_call_result(), if the tool result is a list (and not an ellmer Content object), include it as structuredContent alongside the text serialization.

Related to #103 (outputSchema) — if a tool declares an outputSchema, the structuredContent should be validated against it.

mrcanofcatfood avatar May 20 '26 12:05 mrcanofcatfood