Jeremiah Lowin commited on
Commit
92cf7e6
·
1 Parent(s): 1d7fa1d

Add get_tool utility

Browse files
Files changed (1) hide show
  1. src/fastmcp/server/server.py +6 -0
src/fastmcp/server/server.py CHANGED
@@ -263,6 +263,12 @@ class FastMCP(Generic[LifespanResultT]):
263
  self._cache.set("tools", tools)
264
  return tools
265
 
 
 
 
 
 
 
266
  async def get_resources(self) -> dict[str, Resource]:
267
  """Get all registered resources, indexed by registered key."""
268
  if (resources := self._cache.get("resources")) is self._cache.NOT_FOUND:
 
263
  self._cache.set("tools", tools)
264
  return tools
265
 
266
+ async def get_tool(self, key: str) -> Tool:
267
+ tools = await self.get_tools()
268
+ if key not in tools:
269
+ raise NotFoundError(f"Unknown tool: {key}")
270
+ return tools[key]
271
+
272
  async def get_resources(self) -> dict[str, Resource]:
273
  """Get all registered resources, indexed by registered key."""
274
  if (resources := self._cache.get("resources")) is self._cache.NOT_FOUND: