From a5708ff91878fb5544d50e867884b878de526aa3 Mon Sep 17 00:00:00 2001 From: William Easton Date: Fri, 25 Jul 2025 14:30:49 -0500 Subject: [PATCH] Small clean-up from MCP Tool Transform PR (#1267) --- src/fastmcp/tools/tool_transform.py | 10 ++++++---- src/fastmcp/utilities/mcp_config.py | 8 +++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/fastmcp/tools/tool_transform.py b/src/fastmcp/tools/tool_transform.py index 5f40b91bf..cab7adba0 100644 --- a/src/fastmcp/tools/tool_transform.py +++ b/src/fastmcp/tools/tool_transform.py @@ -12,7 +12,7 @@ from pydantic.fields import Field from pydantic.functional_validators import BeforeValidator from fastmcp.tools.tool import ParsedFunction, Tool, ToolResult, _convert_to_content -from fastmcp.utilities.components import FastMCPComponent, _convert_set_default_none +from fastmcp.utilities.components import _convert_set_default_none from fastmcp.utilities.logging import get_logger from fastmcp.utilities.types import ( FastMCPBaseModel, @@ -832,7 +832,7 @@ class TransformedTool(Tool): ) -class ToolTransformConfig(FastMCPComponent): +class ToolTransformConfig(FastMCPBaseModel): """Provides a way to transform a tool.""" name: str | None = Field(default=None, description="The new name for the tool.") @@ -863,7 +863,9 @@ class ToolTransformConfig(FastMCPComponent): def apply(self, tool: Tool) -> TransformedTool: """Create a TransformedTool from a provided tool and this transformation configuration.""" - tool_changes = self.model_dump(exclude_unset=True, exclude={"arguments"}) + tool_changes: dict[str, Any] = self.model_dump( + exclude_unset=True, exclude={"arguments"} + ) return TransformedTool.from_tool( tool=tool, @@ -880,7 +882,7 @@ def apply_transformations_to_tools( are left unchanged. """ - transformed_tools = {} + transformed_tools: dict[str, Tool] = {} for tool_name, tool in tools.items(): if transformation := transformations.get(tool_name): diff --git a/src/fastmcp/utilities/mcp_config.py b/src/fastmcp/utilities/mcp_config.py index 3d868bd06..e648f4c1c 100644 --- a/src/fastmcp/utilities/mcp_config.py +++ b/src/fastmcp/utilities/mcp_config.py @@ -1,12 +1,14 @@ +from typing import Any + from fastmcp.mcp_config import MCPConfig from fastmcp.server.server import FastMCP def composite_server_from_mcp_config( config: MCPConfig, name_as_prefix: bool = True -) -> FastMCP: +) -> FastMCP[None]: """A utility function to create a composite server from an MCPConfig.""" - composite_server = FastMCP() + composite_server = FastMCP[None]() mount_mcp_config_into_server(config, composite_server, name_as_prefix) @@ -15,7 +17,7 @@ def composite_server_from_mcp_config( def mount_mcp_config_into_server( config: MCPConfig, - server: FastMCP, + server: FastMCP[Any], name_as_prefix: bool = True, ) -> None: """A utility function to mount the servers from an MCPConfig into a FastMCP server."""