Jeremiah Lowin commited on
Commit
23b7b52
·
1 Parent(s): fbacb68

fix typing

Browse files
src/fastmcp/tools/tool.py CHANGED
@@ -101,7 +101,7 @@ class Tool(FastMCPBaseModel, ABC):
101
  tool: Tool,
102
  transform_fn: Callable[..., Any] | None = None,
103
  name: str | None = None,
104
- transform_args: dict[str, str | ArgTransform | None] | None = None,
105
  description: str | None = None,
106
  tags: set[str] | None = None,
107
  annotations: ToolAnnotations | None = None,
 
101
  tool: Tool,
102
  transform_fn: Callable[..., Any] | None = None,
103
  name: str | None = None,
104
+ transform_args: dict[str, ArgTransform] | None = None,
105
  description: str | None = None,
106
  tags: set[str] | None = None,
107
  annotations: ToolAnnotations | None = None,
src/fastmcp/tools/tool_transform.py CHANGED
@@ -168,6 +168,11 @@ class ArgTransform:
168
  "Hidden parameters cannot be required since clients cannot provide them."
169
  )
170
 
 
 
 
 
 
171
 
172
  class TransformedTool(Tool):
173
  """A tool that is transformed from another tool.
 
168
  "Hidden parameters cannot be required since clients cannot provide them."
169
  )
170
 
171
+ if self.required is False:
172
+ raise ValueError(
173
+ "Cannot specify 'required=False'. Set a default value instead."
174
+ )
175
+
176
 
177
  class TransformedTool(Tool):
178
  """A tool that is transformed from another tool.
tests/tools/test_tool_transform.py CHANGED
@@ -858,23 +858,14 @@ async def test_arg_transform_required_false():
858
  def base_tool(required_param: int) -> str:
859
  return f"value: {required_param}"
860
 
861
- # Make the required parameter optional with a default
862
- new_tool = Tool.from_tool(
863
- base_tool,
864
- transform_args={"required_param": ArgTransform(required=False, default=99)},
865
- )
866
-
867
- # Parameter should now be optional (not in required list, has default)
868
- assert "required_param" not in new_tool.parameters["required"]
869
- assert new_tool.parameters["properties"]["required_param"]["default"] == 99
870
-
871
- # Should work when parameter is not provided (uses default)
872
- result = await new_tool.run(arguments={})
873
- assert result[0].text == "value: 99" # type: ignore
874
-
875
- # Should work when parameter is provided
876
- result = await new_tool.run(arguments={"required_param": 123})
877
- assert result[0].text == "value: 123" # type: ignore
878
 
879
 
880
  async def test_arg_transform_required_with_rename():
 
858
  def base_tool(required_param: int) -> str:
859
  return f"value: {required_param}"
860
 
861
+ with pytest.raises(
862
+ ValueError,
863
+ match="Cannot specify 'required=False'. Set a default value instead.",
864
+ ):
865
+ Tool.from_tool(
866
+ base_tool,
867
+ transform_args={"required_param": ArgTransform(required=False, default=99)}, # type: ignore
868
+ )
 
 
 
 
 
 
 
 
 
869
 
870
 
871
  async def test_arg_transform_required_with_rename():