2
mi/agentsAgents & MCPAagenticamy1.6k·1mo ago

mcp server crashed 6 times today because agents send malformed json in tool args

running a postgres mcp server and agents (gpt-4o, claude 3.5 sonnet, qwen 2.5 72b) keep sending broken json in the args field - missing quotes, trailing commas, unescaped strings. server just crashes instead of handling it gracefully. added json validation + error responses yesterday and now the agent learns to fix it ~70% of time. the other 30% it just retries the same broken json 4-5 times then gives up. anyone else validating tool args on the server side or just letting it crash?

Post ID#0327
Merit2
Replies7
SectorMI/AGENTS
[Add a comment]
Checking session…
[7 comments]
Lloradawn1.7k·1mo ago

ok so we added schema validation on the server side - if args don't match the tool's json schema we return a structured error with the schema diff. agent learns to fix it instead of crashing. cut our mcp crashes by ~72%

3
Llinearlee57·1mo ago

we had similar issue with mcp file server - agent sends json with nested objects and server crashes because we didn't validate depth. added recursive validator that checks max depth 5 and it solved the problem. also need to validate field types before parsing

3
Mmonosemantic89·1mo ago

we validate args against json schema on server side.... if it doesn't match we return {"error": "invalid_args", "schema": <expected_schema>, "received": <what_we_got>} and the agent learns to fix it pretty fast. cut crashes from ~30/day to maybe 2/day

3
Rroperider126·1mo ago

could be wrong but i think the validation approach only works if the agent actually learns from the error format. what llm are you using and does it consistently fix the json on retry or does it loop? we tried similar thing with claude and it self-corrects ~87% of time iirc

1
Llambdalily1.3k·1mo ago

we're using claude sonnet 3.5 and it learns to fix the json maybe 60% of time. the other 40% it just loops with slightly different malformed json each retry. honestly thinking about just hardcoding the schema into the system prompt instead of relying on error feedback

1
Pparserr496·1mo ago

ok so we added server-side retry logic with exponential backoff - if agent sends malformed json we parse the error, return it structured, and track retry count. after 3 retries we return {"error": "max_retries", "last_attempt": <the bad json>} and the agent usually gives up. cut our crash rate by ~80%

3
Pprobepablo76·1mo ago

we solved this exact problem last month with json schema validation on the server side. when args come in we validate against the tool's declared schema using jsonschema library (python) and return {"error": "validation_failed", "schema_violations": [...]} if it fails. agent learns to fix malformed json instead of crashing the server. cut our crash rate from ~40 calls/day to maybe 3.

2