"""Platform MCP tools — what a project is built on or ships as. Thin wrappers over services/platforms.py. The catalog is global; a project's platforms decide which family ideas reach it. """ from __future__ import annotations from grimoire.mcp._context import current_user_id from grimoire.services import platforms as platforms_svc async def list_platforms(project_id: int = 0) -> dict: """The GLOBAL platform catalog — runtimes, delivery channels and toolchains a project can be built on or ship as (Android app, container image, Go, …) — and, with a project_id, that project's answer for each. A project's platforms decide which family ideas reach it: an idea is for some platforms, and every project that is one of them answers it. Pass slugs from here to set_project_platforms and decide_project_inception. Each platform's `markers` are the file patterns that let the coverage refresh DETECT it in a bound repo. A project's `state` per platform is `declared` (a person said so), `detected` (a marker said so) or `rejected` (a person said no — kept so detection cannot add it back). Only declared and detected are membership. Args: project_id: also return this project's answers. 0 = catalog only. """ catalog = await platforms_svc.list_platforms() out: dict = {"platforms": [p.to_dict() for p in catalog]} if project_id: rows = await platforms_svc.project_platforms(current_user_id(), project_id) if rows is None: raise ValueError(f"project {project_id} not found") out["project_platforms"] = rows return out async def set_project_platforms( project_id: int, declared: list[str] | None = None, rejected: list[str] | None = None, withdrawn: list[str] | None = None, ) -> dict: """Say which platforms a project is — or is not. Only the platforms named change; everything else is left exactly as it is. Use it when the operator corrects what detection found, or when a project starts or stops shipping something (it gains an Android client; it drops its container image). At project creation, decide_project_inception's `platforms` is the place instead — it records the answer with the rest of what the project inherits. Args: project_id: the project. declared: slugs the project IS (list_platforms). rejected: slugs it is NOT — recorded as a "no", so the coverage refresh never detects it back. withdrawn: slugs whose answer to drop entirely, so detection may decide again on the next refresh. """ updates: dict[str, str | None] = {} for slug in withdrawn or []: updates[slug] = None for slug in rejected or []: updates[slug] = "rejected" for slug in declared or []: updates[slug] = "declared" if not updates: raise ValueError("name at least one platform to declare, reject or withdraw") rows = await platforms_svc.set_project_platforms(current_user_id(), project_id, updates) return {"project_id": project_id, "project_platforms": rows} def register(mcp) -> None: for fn in (list_platforms, set_project_platforms): mcp.tool(name=fn.__name__)(fn)