π The fast, Pythonic way to build MCP servers and clients.
Keep json schema $defs on transform
William Easton8cdce8d84817
diff --git a/src/fastmcp/tools/tool_transform.py b/src/fastmcp/tools/tool_transform.pyindex 95c4a877e..0f965c275 100644--- a/src/fastmcp/tools/tool_transform.py+++ b/src/fastmcp/tools/tool_transform.py@@ -553,6 +553,7 @@ class TransformedTool(Tool):"""# Build transformed schema and mapping+ parent_defs = parent_tool.parameters.get("$defs", {})parent_props = parent_tool.parameters.get("properties", {}).copy()parent_required = set(parent_tool.parameters.get("required", []))@@ -608,6 +609,9 @@ class TransformedTool(Tool):"required": list(new_required),}+ if parent_defs:+ schema["$defs"] = parent_defs+# Create forwarding function that closes over everything it needsasync def _forward(**kwargs):# Validate argumentsdiff --git a/tests/tools/test_tool_transform.py b/tests/tools/test_tool_transform.pyindex 0ebbf5309..23b446f68 100644--- a/tests/tools/test_tool_transform.py+++ b/tests/tools/test_tool_transform.py@@ -383,6 +383,23 @@ async def test_forward_raw_outside_context_raises_error():):await forward_raw(new_x=1, old_y=2)+def test_transform_args_with_parent_defaults():+ """Test that transform_args with parent defaults works."""++ class CoolModel(BaseModel):+ x: int = 10++ def parent_tool(cool_model: CoolModel) -> int:+ return cool_model.x++ tool = Tool.from_function(parent_tool)++ new_tool = Tool.from_tool(+ tool+ )++ assert new_tool.parameters["$defs"] == tool.parameters["$defs"]+def test_transform_args_validation_unknown_arg(add_tool):"""Test that transform_args with unknown arguments raises ValueError."""