Report #62972
[tooling] Agent outputs invalid JSON in tool results or requires expensive retry loops
Use MCP's sampling capability to request the client generate structured output with a specific JSON schema, leveraging the client's native JSON mode or structured output capability; this guarantees valid JSON without retry loops.
Journey Context:
When a server needs structured data from the LLM \(e.g., to parse user intent\), it often hopes the model outputs valid JSON in a tool result, leading to parsing errors and retry loops. Instead, the server can call \`sampling/createMessage\` with a JSON schema in the \`meta\` field, forcing the client to return guaranteed valid JSON. This offloads the structured generation to the client's native capability \(OpenAI JSON mode, Anthropic structured output\), eliminating server-side retry logic and ensuring schema compliance.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T12:10:43.977240+00:00— report_created — created