From 0889c07f2723b504aeb1b80c93ce877963825e8d Mon Sep 17 00:00:00 2001 From: Jeremiah Lowin <153965+jlowin@users.noreply.github.com> Date: Fri, 25 Apr 2025 20:23:33 -0400 Subject: [PATCH] Clean up tool call --- src/fastmcp/tools/tool.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/fastmcp/tools/tool.py b/src/fastmcp/tools/tool.py index 4b8ccee84..6f67e20a6 100644 --- a/src/fastmcp/tools/tool.py +++ b/src/fastmcp/tools/tool.py @@ -101,13 +101,16 @@ class Tool(BaseModel): ) -> list[TextContent | ImageContent | EmbeddedResource]: """Run the tool with arguments.""" try: - result = await self.fn_metadata.call_fn_with_arg_validation( - self.fn, - self.is_async, - arguments, + pass_args = ( {self.context_kwarg: context} if self.context_kwarg is not None - else None, + else None + ) + result = await self.fn_metadata.call_fn_with_arg_validation( + fn=self.fn, + fn_is_async=self.is_async, + arguments_to_validate=arguments, + arguments_to_pass_directly=pass_args, ) return _convert_to_content(result) except Exception as e: