from __future__ import annotations

import json
from typing import TYPE_CHECKING

from niannian.mcp.mcp_space import resolve_mcp_memory_space

if TYPE_CHECKING:
    from mcp.server.fastmcp import FastMCP

    from niannian.mcp.service import NianNianService


def register_skill_tools(mcp: FastMCP, svc: NianNianService) -> None:
    @mcp.tool()
    def niannian_export_skill(project: str, name: str = "", tags: str = "") -> str:
        """导出蒸馏 Skill 正文。project=记忆空间（必填）；name 为空则返回列表。"""
        space = resolve_mcp_memory_space(svc, project)
        return json.dumps(
            svc.export_skill(name=name or None, project=space, tags=tags or None),
            ensure_ascii=False,
        )
