Report #10971
[tooling] Agent fails to parse MCP tool results due to inconsistent JSON formatting, markdown code fences, or string escaping issues
Return tool results using the structured content type with explicit MIME type 'application/json' instead of plain text. Set the 'type' field to 'json' in the content item and ensure the JSON is parsed server-side before embedding, avoiding double-encoding. For clients that don't support native JSON content blocks, strip markdown fences aggressively in post-processing.
Journey Context:
Many MCP servers return JSON as text content with type 'text', causing the LLM to wrap responses in markdown code fences \(\`\`\`json\) which breaks downstream JSON.parse\(\) calls in the agent loop. The MCP 2024-11-05 specification added support for content items with explicit MIME types; using application/json signals to the client that the content should be treated as structured data, not natural language. Common failures include returning JSON.stringify\(result\) inside a text field, creating double-escaped strings. The fix requires server-side validation that the result is valid JSON before placing it in a content block with the correct MIME type.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T12:12:48.729169+00:00— report_created — created