Skip to content

πŸš€ The fast, Pythonic way to build MCP servers and clients.

fix(tools): keep hidden parameter factories out of visible defaults (#6283)

Felix Shi1e19bbafd0d5
diff --git a/fastmcp_slim/fastmcp/tools/tool_transform.py b/fastmcp_slim/fastmcp/tools/tool_transform.py
index fbba0fa76..fcee8c7f0 100644
--- a/fastmcp_slim/fastmcp/tools/tool_transform.py
+++ b/fastmcp_slim/fastmcp/tools/tool_transform.py
@@ -424,6 +424,11 @@ class TransformedTool(Tool):
if self.transform_args:
# Find the original parameter name that maps to this param_name
for orig_name, transform in self.transform_args.items():
+ if transform.hide:
+ # Hidden parameters are not part of the schema and
+ # their factory defaults are applied when forwarding
+ # to the parent, so they must not fill visible ones.
+ continue
transform_name = (
transform.name
if transform.name is not NotSet
diff --git a/tests/tools/tool_transform/test_args.py b/tests/tools/tool_transform/test_args.py
index 7401527dc..feb314302 100644
--- a/tests/tools/tool_transform/test_args.py
+++ b/tests/tools/tool_transform/test_args.py
@@ -215,6 +215,27 @@ async def test_arg_transform_type_precedence_runtime():
assert "result: 8" in result.content[0].text
+async def test_hidden_rename_does_not_leak_factory_into_visible_sibling():
+ """A hidden parameter renamed to a visible sibling's name must not
+ override that sibling's schema default with its factory value."""
+
+ @Tool.from_function
+ def base_tool(x: str = "x-default", y: str = "y-default") -> str:
+ return f"{x}|{y}"
+
+ new_tool = Tool.from_tool(
+ base_tool,
+ transform_args={
+ "x": ArgTransform(name="y", hide=True, default_factory=lambda: "factory")
+ },
+ )
+
+ result = await new_tool.run(arguments={})
+ assert isinstance(result.content[0], TextContent)
+ # x is forwarded its factory value; y must keep its schema default
+ assert result.content[0].text == "factory|y-default"
+
+
async def test_arg_transform_default_factory():
"""Test ArgTransform with default_factory for hidden parameters."""
import asyncio