mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-21 21:14:17 +02:00
Keep json schema $defs on transform
This commit is contained in:
parent
cbb8a0d110
commit
8cdce8d848
2 changed files with 21 additions and 0 deletions
|
|
@ -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 needs
|
||||
async def _forward(**kwargs):
|
||||
# Validate arguments
|
||||
|
|
|
|||
|
|
@ -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."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue