MCPcopy
hub / github.com/AstrBotDevs/AstrBot / toggle_tool

Method toggle_tool

astrbot/dashboard/services/tools_service.py:326–358  ·  view source on GitHub ↗
(self, data: Any)

Source from the content-addressed store, hash-verified

324 ) from exc
325
326 def toggle_tool(self, data: Any) -> str:
327 try:
328 tool_name = data.get("name")
329 action = data.get("activate")
330
331 if not tool_name or action is None:
332 raise ToolsServiceError("Missing required parameters: name or activate")
333
334 if self.tool_mgr.is_builtin_tool(tool_name):
335 raise ToolsServiceError(
336 "Builtin tools are read-only and cannot be toggled."
337 )
338
339 if action:
340 try:
341 ok = self.tool_mgr.activate_llm_tool(tool_name, star_map=star_map)
342 except ValueError as exc:
343 raise ToolsServiceError(
344 f"Failed to activate tool: {exc!s}"
345 ) from exc
346 else:
347 ok = self.tool_mgr.deactivate_llm_tool(tool_name)
348
349 if ok:
350 return "Operation successful."
351 raise ToolsServiceError(
352 f"Tool {tool_name} does not exist or the operation failed."
353 )
354 except ToolsServiceError:
355 raise
356 except Exception as exc:
357 logger.error(traceback.format_exc())
358 raise ToolsServiceError(f"Failed to operate tool: {exc!s}") from exc
359
360 async def sync_provider(self, data: Any) -> str:
361 try:

Callers 1

_toggle_toolFunction · 0.80

Calls 6

ToolsServiceErrorClass · 0.85
getMethod · 0.45
is_builtin_toolMethod · 0.45
activate_llm_toolMethod · 0.45
deactivate_llm_toolMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected