from __future__ import annotations

from niannian.memory.space import ensure_memory_space, require_mcp_memory_space
from niannian.mcp.service import NianNianService


def resolve_mcp_memory_space(svc: NianNianService, project: str) -> str:
    """MCP 工具层：校验必填并确保空间已注册。"""
    space = require_mcp_memory_space(project)
    home = svc.home
    if home is not None:
        ensure_memory_space(home, space)
    return space
