Skip to content

Commit 77ecd08

Browse files
committed
add has_tool
1 parent c7671e4 commit 77ecd08

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/mcp/server/fastmcp/server.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -418,14 +418,15 @@ async def async_tool(x: int, context: Context) -> str:
418418
)
419419

420420
def decorator(fn: AnyFunction) -> AnyFunction:
421-
self.add_tool(
422-
fn,
423-
name=name,
424-
title=title,
425-
description=description,
426-
annotations=annotations,
427-
structured_output=structured_output,
428-
)
421+
if not self._tool_manager.has_tool(fn.__name__):
422+
self.add_tool(
423+
fn,
424+
name=name,
425+
title=title,
426+
description=description,
427+
annotations=annotations,
428+
structured_output=structured_output,
429+
)
429430
return fn
430431

431432
return decorator

src/mcp/server/fastmcp/tools/tool_manager.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ def get_tool(self, name: str) -> Tool | None:
3838
"""Get tool by name."""
3939
return self._tools.get(name)
4040

41+
def has_tool(self, name: str) -> bool:
42+
"""Check if a tool exists."""
43+
return name in self._tools
44+
4145
def list_tools(self) -> list[Tool]:
4246
"""List all registered tools."""
4347
return list(self._tools.values())

0 commit comments

Comments
 (0)