diff --git a/src/fastmcp/tools/tool_transform.py b/src/fastmcp/tools/tool_transform.py index f7293afe9..e84c44407 100644 --- a/src/fastmcp/tools/tool_transform.py +++ b/src/fastmcp/tools/tool_transform.py @@ -97,6 +97,7 @@ class ArgTransform: type: New type for the argument. Use ... for no change. hide: If True, hide this argument from clients but pass a constant value to parent. required: If True, make argument required (remove default). Use ... for no change. + examples: Examples for the argument. Use ... for no change. Examples: # Rename argument 'old_name' to 'new_name' @@ -137,6 +138,7 @@ class ArgTransform: type: Any | EllipsisType = NotSet hide: bool = False required: Literal[True] | EllipsisType = NotSet + examples: Any | EllipsisType = NotSet def __post_init__(self): """Validate that only one of default or default_factory is provided.""" @@ -584,6 +586,10 @@ class TransformedTool(Tool): # Update the schema with the type information from TypeAdapter new_schema.update(type_schema) + # Handle examples transformation + if transform.examples is not NotSet: + new_schema["examples"] = transform.examples + return new_name, new_schema, is_required @staticmethod diff --git a/tests/tools/test_tool_transform.py b/tests/tools/test_tool_transform.py index f9e91b92e..0498c6c5c 100644 --- a/tests/tools/test_tool_transform.py +++ b/tests/tools/test_tool_transform.py @@ -987,3 +987,35 @@ class TestEnableDisable: with pytest.raises(ToolError): await client.call_tool("new_add", {"x": 1, "y": 2}) + + +def test_arg_transform_examples_in_schema(add_tool): + # Simple example + new_tool = Tool.from_tool( + add_tool, + transform_args={ + "old_x": ArgTransform(examples=[1, 2, 3]), + }, + ) + prop = get_property(new_tool, "old_x") + assert prop["examples"] == [1, 2, 3] + + # Nested example (e.g., for array type) + new_tool2 = Tool.from_tool( + add_tool, + transform_args={ + "old_x": ArgTransform(examples=[["a", "b"], ["c", "d"]]), + }, + ) + prop2 = get_property(new_tool2, "old_x") + assert prop2["examples"] == [["a", "b"], ["c", "d"]] + + # If not set, should not be present + new_tool3 = Tool.from_tool( + add_tool, + transform_args={ + "old_x": ArgTransform(), + }, + ) + prop3 = get_property(new_tool3, "old_x") + assert "examples" not in prop3