Python: fix(claude): preserve $defs in JSON schema for nested Pydantic models (#3655)

* fix(claude): preserve $defs in JSON schema for nested Pydantic models

- Preserve $defs section from Pydantic JSON schema when converting FunctionTool to SDK MCP tool
- This fixes tools with nested Pydantic models that use $ref references
- Add test for nested type schema preservation

Fixes #3654

* Adjust shared state import

* Fix MCP tool kwargs serialization bug

---------

Co-authored-by: Evan Mattson <evan.mattson@microsoft.com>
This commit is contained in:
Dineshsuriya D
2026-02-04 06:34:26 +00:00
committed by GitHub
co-authored by Evan Mattson
parent 06d43ee130
commit 5c6cf4fc92
6 changed files with 50 additions and 5 deletions
@@ -511,6 +511,9 @@ class ClaudeAgent(BaseAgent, Generic[TOptions]):
"properties": schema.get("properties", {}),
"required": schema.get("required", []),
}
# Preserve $defs for nested type references (Pydantic uses $defs for nested models)
if "$defs" in schema:
input_schema["$defs"] = schema["$defs"]
return SdkMcpTool(
name=func_tool.name,