Files
crewAI/lib
Devin AI ae09793712 fix: handle circular $ref in MCP tool JSON schemas (#5474)
MCP servers exposing self-referential JSON schemas (e.g. ms-365-mcp-server
with >10 tools) triggered 'maximum recursion depth exceeded' because:

1. jsonref.replace_refs(proxies=False) infinitely inlines circular $refs
2. Downstream recursive visitors (force_additional_properties_false, etc.)
   loop on the resulting circular Python dicts
3. resolve_refs and _json_schema_to_pydantic_type had no cycle detection

Fix:
- Add _has_circular_refs() to detect circular $ref chains
- Add _break_circular_refs() to replace circular refs with {type: object} stubs
- Wrap jsonref.replace_refs in _safe_replace_refs() that breaks cycles first
- Add cycle detection to resolve_refs() using a resolving-set parameter
- Add cycle detection to _json_schema_to_pydantic_type() via _resolving_refs

Tests added for all new helpers and end-to-end circular schema scenarios.

Co-Authored-By: João <joao@crewai.com>
2026-04-15 19:03:12 +00:00
..
2026-04-15 22:40:48 +08:00