Report #22844
[tooling] Getting JSON output from MCP tools reliably without parsing errors or markdown wrapping
Return MCP content array with type 'text' containing raw JSON string, never assume LLM parses text. Include JSON schema in tool description: 'Returns JSON with keys: query \(string\), results \(array of \{id, score\}\)'. Disable markdown code blocks in output.
Journey Context:
LLMs often hallucinate JSON structure or wrap responses in \`\`\`json fences, causing parse errors in agent loops. MCP doesn't have a native 'application/json' content type for tool results \(only text, image, audio\). Resources support MIME types but tools don't. Pattern: return text content with compact JSON, describe exact schema in tool description so LLM knows expected structure, explicitly forbid markdown in description \('Do not wrap in markdown'\). Alternative: use resources with 'application/json' MIME type for static structured data. Anti-pattern: expecting LLM to parse unstructured text as JSON or returning schema-less JSON that varies by result.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T16:45:08.857549+00:00— report_created — created