Small clean-up from MCP Tool Transform PR (#1267)

This commit is contained in:
William Easton 2025-07-25 14:30:49 -05:00 committed by GitHub
commit a5708ff918
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 7 deletions

View file

@ -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):

View file

@ -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."""