fastmcp: allow passing Tool directly to FastMCP constructor (#699)

This commit is contained in:
Vadym Barda 2025-05-19 22:52:02 -04:00 • committed by GitHub
commit 5a9340af71
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -19,8 +19,19 @@ logger = get_logger(__name__)
class ToolManager:
"""Manages FastMCP tools."""
def __init__(self, warn_on_duplicate_tools: bool = True):
def __init__(
self,
warn_on_duplicate_tools: bool = True,
*,
tools: list[Tool] | None = None,
):
self._tools: dict[str, Tool] = {}
if tools is not None:
for tool in tools:
if warn_on_duplicate_tools and tool.name in self._tools:
logger.warning(f"Tool already exists: {tool.name}")
self._tools[tool.name] = tool
self.warn_on_duplicate_tools = warn_on_duplicate_tools
def get_tool(self, name: str) -> Tool | None: