fastmcp/tests/server/test_tool_transformation.py
William Easton 1b953820b3
[🐶] Transform MCP Server Tools (#1132)
Co-authored-by: Jeremiah Lowin <153965+jlowin@users.noreply.github.com>
2025-07-19 15:52:47 -04:00

40 lines
1.2 KiB
Python

from fastmcp import FastMCP
from fastmcp.tools.tool_transform import ToolTransformConfig
async def test_tool_transformation_in_tool_manager():
"""Test that tool transformations are applied in the tool manager."""
mcp = FastMCP("Test Server")
@mcp.tool()
def echo(message: str) -> str:
"""Echo back the message provided."""
return message
mcp.add_tool_transformation("echo", ToolTransformConfig(name="echo_transformed"))
tools_dict = await mcp._tool_manager.get_tools()
tools = list(tools_dict.values())
assert len(tools) == 1
assert "echo_transformed" in tools_dict
assert tools_dict["echo_transformed"].name == "echo_transformed"
async def test_transformed_tool_filtering():
"""Test that tool transformations are applied in the tool manager."""
mcp = FastMCP("Test Server", include_tags={"enabled_tools"})
@mcp.tool()
def echo(message: str) -> str:
"""Echo back the message provided."""
return message
tools = list(await mcp._list_tools())
assert len(tools) == 0
mcp.add_tool_transformation(
"echo", ToolTransformConfig(name="echo_transformed", tags={"enabled_tools"})
)
tools = list(await mcp._list_tools())
assert len(tools) == 1