#7049·spring-ai

SyncMcpToolCallback: tool result JSON drops each content part's `type`

Author: mandsCreated Sep 24, 2026Updated Sep 26, 2026
Labelsstatus: waiting-for-triage

Repo: spring-projects/spring-ai. Module: spring-ai-mcp (org.springframework.ai.mcp.SyncMcpToolCallback), 2.0.1.

Problem

SyncMcpToolCallback.call returns jsonHelper.toJson(response.content()). The resulting JSON has no type on each content part. A text part comes out as {"text":"…"}, not {"type":"text","text":"…"} as in the MCP spec. A consumer of the tool result cannot tell text, image, audio and resource parts apart by their kind. It must guess from which fields are present.

Repro

An MCP server whose tools/call answers {"content":[{"type":"text","text":"hello"}],"isError":false}. Call the tool through SyncMcpToolCallback.call("{…}"). The result is [{"text":"hello"}].

Proposal

Serialize the content list with its element type so the type discriminator is kept. For example, write it through a writer for List<McpSchema.Content>, or map each part to the spec's wire shape. The model and any ToolCallback decorator then see the MCP content as the spec defines it.

Our workaround

Our decorator over the MCP callbacks treats a part as text when it has a top-level text field (McpResultToolCallback.mkJson). An embedded resource keeps its text under resource.text, so the test does not confuse the two.

(issue generated with AI assistance)

Source: spring-projects/spring-ai