Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/mcp/server/fastmcp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,14 +418,15 @@ async def async_tool(x: int, context: Context) -> str:
)

def decorator(fn: AnyFunction) -> AnyFunction:
self.add_tool(
fn,
name=name,
title=title,
description=description,
annotations=annotations,
structured_output=structured_output,
)
if not self._tool_manager.has_tool(fn.__name__):
self.add_tool(
fn,
name=name,
title=title,
description=description,
annotations=annotations,
structured_output=structured_output,
)
return fn

return decorator
Expand Down
4 changes: 4 additions & 0 deletions src/mcp/server/fastmcp/tools/tool_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ def get_tool(self, name: str) -> Tool | None:
"""Get tool by name."""
return self._tools.get(name)

def has_tool(self, name: str) -> bool:
"""Check if a tool exists."""
return name in self._tools

def list_tools(self) -> list[Tool]:
"""List all registered tools."""
return list(self._tools.values())
Expand Down
Loading