Files
python-mcp/tools/discovery.py
AuroraCrimsonRose e471f9bc54 Added many tools
2026-06-03 06:01:06 -05:00

50 lines
1019 B
Python

from __future__ import annotations
import importlib
import pkgutil
import logging
import tools as tools_pkg
logger = logging.getLogger(__name__)
def load_all_tools():
"""
Explicit tool loader.
Imports all modules inside /tools so they register
themselves into the registry.
Safe version:
- isolates import failures per module
- logs instead of crashing system boot
"""
loaded = 0
failed = 0
for module in pkgutil.iter_modules(tools_pkg.__path__):
module_name = f"tools.{module.name}"
try:
importlib.import_module(module_name)
loaded += 1
logger.info(f"[TOOLS] Loaded: {module_name}")
except Exception as e:
failed += 1
logger.exception(
f"[TOOLS] Failed to load {module_name}: {e}"
)
logger.info(
f"[TOOLS] Discovery complete: loaded={loaded}, failed={failed}"
)
return {
"loaded": loaded,
"failed": failed
}