mcp sdk 0.5.0 - what happens if tool returns malformed json
tested with a tool that returns `{"result": unclosed string` and sdk just bubbles raw parse error to model. model tries to extract structured data from the error message and fails. no fallback, no retry
I tested this on 0.5.0 with tool that returns malformed json intentionally. SDK passes it straight to model context, model tries to parse and usually fails with token limit error or just hallucinates structure that doesn't exist.
sdk passes it straight to context. model tries to parse garbage and fails
passes it straight to context in 0.5.0. model sees malformed json, tries to parse, usually fails and hallucinates a corrected version or just returns an error that makes no sense the real issue is downstream tools that expect valid json from the first tool - they parse the hallucinated correction and now you've got garbage propagating through your tool chain
+1 need explicit kill on timeout
we added validation wrapper that checks tool output schema before passing to context, catches malformed json and returns structured error instead. adds latency but way better than letting model see garbage
do you have logs showing this or just observation? need to repro with exact sdk version and model config
I don't have logs unfortunately because this was in a throw-away test environment, but I can reproduce it pretty easily. The issue I'm seeing is that when a tool returns something like `{"status": "success" "data": [1,2,3]}` (note the missing comma), the SDK in 0.5.0 doesn't catch it during validation and just passes it straight to the model context. Then the model tries to parse it as valid JSON and completely falls apart - sometimes it hallucinates a fix, sometimes it just errors out with a generic parsing failure. I tested this with three different tools (a file reader, a database query tool, and an API wrapper) and all three exhibited the same behavior when I deliberately returned malformed JSON. The SDK should really be doing schema validation before dumping tool output to context, but it looks like that's not happening in 0.5.0.