Skip to content

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

Merge branch 'main' into transform-tools

Jeremiah Lowin0b8bf825c131
diff --cc tests/tools/test_tool.py
index bc7423848,97f6fdf81..fb4a95b64
--- a/tests/tools/test_tool.py
+++ b/tests/tools/test_tool.py
@@@ -5,7 -5,7 +5,7 @@@ from pydantic import AnyUrl, BaseMode
from fastmcp import FastMCP, Image
from fastmcp.client import Client
from fastmcp.exceptions import ToolError
- from fastmcp.tools import FunctionTool
-from fastmcp.tools.tool import Tool, _convert_to_content
++from fastmcp.tools.tool import FunctionTool, _convert_to_content
from fastmcp.utilities.tests import temporary_settings
@@@ -183,6 -183,32 +183,32 @@@ class TestToolFromFunction
class MyClass:
x: int = 10
+ @classmethod
+ def call(cls, x: int, y: int) -> int:
+ """Add two numbers."""
+ return x + y
+
- tool = Tool.from_function(MyClass.call)
++ tool = FunctionTool.from_function(MyClass.call)
+ assert tool.name == "call"
+ assert tool.description == "Add two numbers."
+ assert "x" in tool.parameters["properties"]
+ assert "y" in tool.parameters["properties"]
+
+ async def test_tool_serializer(self):
+ """Test that a tool's serializer is used to serialize the result."""
+
+ def custom_serializer(data) -> str:
+ return f"Custom serializer: {data}"
+
+ def process_list(items: list[int]) -> int:
+ return sum(items)
+
- tool = Tool.from_function(process_list, serializer=custom_serializer)
++ tool = FunctionTool.from_function(process_list, serializer=custom_serializer)
+
+ result = await tool.run(arguments={"items": [1, 2, 3, 4, 5]})
+ assert isinstance(result[0], TextContent)
+ assert result[0].text == "Custom serializer: 15"
+
class TestLegacyToolJsonParsing:
"""Tests for Tool's JSON pre-parsing functionality."""