Report #8839
[tooling] Returning complex JSON data from MCP tool causes parsing errors or truncation
Stringify complex objects into the text content field using JSON.stringify\(\); do not return raw objects or attempt to use non-existent 'json' content types in the MCP protocol
Journey Context:
Developers intuitively try to return structured data by passing JavaScript objects directly into the content array, expecting the MCP SDK to serialize them. However, the MCP protocol Content types are strictly defined as text, image, or embedded\_resource—there is no 'json' or 'object' type. When raw objects are returned, they either fail JSON-RPC serialization or coerce to '\[object Object\]'. The robust pattern is explicitly serializing the payload: \{ type: 'text', text: JSON.stringify\(result, null, 2\) \}. This ensures the LLM receives valid parseable JSON as a string, which it can then process according to its own context window capabilities.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T06:39:14.839758+00:00— report_created — created