From bf3c54f6f198bada3c7009538970e3e678cb5bfe Mon Sep 17 00:00:00 2001 From: Jeremiah Lowin <153965+jlowin@users.noreply.github.com> Date: Wed, 11 Jun 2025 11:27:02 -0400 Subject: [PATCH 1/2] Ensure we handle false correctly; removed unused kwarg --- src/fastmcp/server/server.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/fastmcp/server/server.py b/src/fastmcp/server/server.py index b18d846d2..46661c7ba 100644 --- a/src/fastmcp/server/server.py +++ b/src/fastmcp/server/server.py @@ -1231,7 +1231,6 @@ class FastMCP(Generic[LifespanResultT]): port: int | None = None, log_level: str | None = None, path: str | None = None, - message_path: str | None = None, uvicorn_config: dict[str, Any] | None = None, ) -> None: """Run the server using SSE transport.""" @@ -1333,10 +1332,14 @@ class FastMCP(Generic[LifespanResultT]): event_store=None, auth=self.auth, json_response=( - json_response or self._deprecated_settings.json_response + json_response + if json_response is not None + else self._deprecated_settings.json_response ), stateless_http=( - stateless_http or self._deprecated_settings.stateless_http + stateless_http + if stateless_http is not None + else self._deprecated_settings.stateless_http ), debug=self._deprecated_settings.debug, middleware=middleware, From 1a6bb55b271b9c668c0d832fa5dbd714cc9c4757 Mon Sep 17 00:00:00 2001 From: William Easton Date: Wed, 11 Jun 2025 13:43:11 -0500 Subject: [PATCH 2/2] add examples to param transformation --- src/fastmcp/tools/tool_transform.py | 6 ++++++ tests/tools/test_tool_transform.py | 32 +++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) 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