mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-05-04 08:42:38 +00:00
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>