feat: add ability to remove tools (#1322)

Co-authored-by: David Soria Parra <167242713+dsp-ant@users.noreply.github.com>
Co-authored-by: Felix Weinberger <3823880+felixweinberger@users.noreply.github.com>
Co-authored-by: Max Isbey <224885523+maxisbey@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Brandon Wu 2025-10-06 06:16:50 -07:00 • committed by GitHub
commit b8e758b02b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 204 additions and 0 deletions

View file

@ -391,6 +391,17 @@ class FastMCP(Generic[LifespanResultT]):
structured_output=structured_output,
)
def remove_tool(self, name: str) -> None:
"""Remove a tool from the server by name.
Args:
name: The name of the tool to remove
Raises:
ToolError: If the tool does not exist
"""
self._tool_manager.remove_tool(name)
def tool(
self,
name: str | None = None,

View file

@ -70,6 +70,12 @@ class ToolManager:
self._tools[tool.name] = tool
return tool
def remove_tool(self, name: str) -> None:
"""Remove a tool by name."""
if name not in self._tools:
raise ToolError(f"Unknown tool: {name}")
del self._tools[name]
async def call_tool(
self,
name: str,