Report #15267
[gotcha] Complex JSON Schema features \(anyOf, oneOf, nested $ref\) in MCP tool parameters cause LLMs to generate malformed calls
Flatten all tool parameter schemas to simple types. Replace anyOf/oneOf with separate tool variants \(e.g., instead of 'search' with anyOf\[query, file\_pattern\], create 'search\_by\_query' and 'search\_by\_pattern'\). Avoid $ref—inline all definitions. Use enums for constrained string values. Test that your LLM can correctly populate every tool's schema before registering it.
Journey Context:
The MCP spec allows full JSON Schema for tool parameters, but LLMs are trained on simple, common schema patterns. When a tool uses anyOf, oneOf, allOf, or nested $ref, the LLM frequently generates invalid parameters—missing required fields from one branch, mixing fields from multiple branches, or simply hallucinating values. The MCP server then rejects the call with a validation error, the agent retries with the same malformed parameters, and the loop continues. The root cause is a mismatch: JSON Schema is designed for validation, but LLMs need schemas optimized for generation. Flat, simple schemas with clear field names and descriptions dramatically improve call success rates.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T23:41:54.726883+00:00— report_created — created