"""MCP 工具注册中心 (tool registry).

═══════════════════════════════════════════════════════════════════════════
  这里是"MCP 工具"的总装配点。app/tools/ 目录下每个 *.py 文件只要从
  `app.mcp_instance` import 了 `mcp` 并用 `@mcp.tool`（本后端写法）装饰一个函数，
  就会在被 import 时自动注册 —— 你不用改这个文件。
  Every *.py file in app/tools/ that imports `mcp` from app.mcp_instance and
  decorates a function with `@mcp.tool` registers itself as an import side-effect.
  You do NOT edit this file to add a tool — just drop a new .py file next to
  echo.py.
═══════════════════════════════════════════════════════════════════════════
"""

import importlib
import pkgutil
from pathlib import Path

_TOOLS_DIR = Path(__file__).resolve().parent


def register_tools() -> None:
    """import 本包下所有模块；装饰器在 import 时把工具注册到共享的 `mcp` 单例上.

    注册发生在 import 那一刻：每个工具模块顶部 `from app.mcp_instance import mcp`
    并用 `@mcp.tool`（本后端写法）装饰函数，import 模块即运行装饰器、完成注册。
    Importing a tool module runs its `@mcp.tool` decorator(s), which register
    against the shared `mcp` singleton — so importing IS registering.
    """
    for module_info in pkgutil.iter_modules([str(_TOOLS_DIR)]):
        importlib.import_module(f"{__name__}.{module_info.name}")
