@@ -249,15 +249,19 @@ def __repr__(self) -> str:
249249 return f"ToolRegistry(tools={ len (self ._tools )} , functions={ len (self ._functions )} )"
250250
251251
252- # Global registry instance
252+ # Global registry instance (protected by _registry_lock for thread safety)
253+ _registry_lock = threading .Lock ()
253254_global_registry : Optional [ToolRegistry ] = None
254255
255256
256257def get_registry () -> ToolRegistry :
257- """Get the global tool registry instance."""
258+ """Get the global tool registry instance. Thread-safe singleton. """
258259 global _global_registry
259260 if _global_registry is None :
260- _global_registry = ToolRegistry ()
261+ with _registry_lock :
262+ # Double-checked locking pattern
263+ if _global_registry is None :
264+ _global_registry = ToolRegistry ()
261265 return _global_registry
262266
263267
@@ -309,14 +313,7 @@ def remove_tool(name: str) -> bool:
309313 Returns:
310314 True if tool was found and removed, False otherwise
311315 """
312- registry = get_registry ()
313- if name in registry ._tools :
314- del registry ._tools [name ]
315- return True
316- if name in registry ._functions :
317- del registry ._functions [name ]
318- return True
319- return False
316+ return get_registry ().unregister (name )
320317
321318
322319def list_tools () -> List [str ]:
@@ -325,8 +322,7 @@ def list_tools() -> List[str]:
325322 Returns:
326323 List of tool names
327324 """
328- registry = get_registry ()
329- return list (registry ._tools .keys ()) + list (registry ._functions .keys ())
325+ return get_registry ().list_tools ()
330326
331327
332328def discover_plugins () -> int :
0 commit comments