"""Decide which tools the console advertises by default.Dumping the whole ~273-verb tree into ``tools/list`` crowds out the user'squestion and degrades tool selection (ADR ``mcp-progressive-discovery`` P1,amending the refoundation ADR's R2 delivery posture). The console thereforeadvertises an **orientation core** by default - the always-on floor, grounding,and meta-discovery tools plus the small manifest-derived orientation slice (the``overview`` obligation-derivation family and the capability ``contract`` verb,the surfaces the operator rules mandate reading first). The full per-verbuniverse stays reachable through the ``search`` + ``execute`` meta pair andthrough runtime toolset activation; it is not advertised up front.The ``AEAT_MCP_SURFACE`` environment toggle preserves the flat surface for anoperator who wants it (``full``) and for the core-vs-full A/B measurement; theshipped default is ``core``. This module is SDK-independent and pure - itclassifies descriptors by command key - so the policy is unit-tested directlywithout the stdio transport."""from__future__importannotationsfromenumimportStrEnumfrom._toolsimportMcpToolDescriptor#: The environment variable selecting the advertised tool surface.SURFACE_ENV_VAR="AEAT_MCP_SURFACE"#: Command-key prefixes whose verbs are part of the orientation slice. The#: ``overview`` family derives the taxpayer's obligations from the live surface -#: the operator rules mandate reading it first - so its verbs are always#: advertised. Membership is a prefix test against the live command keys, never a#: hand-listed verb set, so a verb added to the family joins the core for free._ORIENTATION_PREFIXES:tuple[str,...]=("overview.",)#: Standalone orientation command keys. ``contract`` is the capability manifest#: the operator rules mandate reading first; it has no dotted family._ORIENTATION_KEYS:frozenset[str]=frozenset({"contract"})
[docs]classSurfaceMode(StrEnum):"""The advertised-tool-surface policy. ``CORE`` (the shipped default) advertises only the orientation slice up front; ``FULL`` advertises every persona-scoped per-verb tool, the pre-ADR flat surface, kept for opt-out and for the core-vs-full measurement. """CORE="core"FULL="full"
[docs]defresolve_surface_mode(raw:str|None)->SurfaceMode:"""Resolve the ``AEAT_MCP_SURFACE`` value to a :class:`SurfaceMode`. An unset or blank value is the shipped ``core`` default. A set value must name a mode exactly (case-insensitively); an unrecognised value raises with the accepted set named, so a misconfiguration fails loudly rather than silently reverting to a surface the operator did not choose. Args: raw: The raw environment value, or ``None`` when unset. Returns: The selected :class:`SurfaceMode`. Raises: ValueError: When ``raw`` is a non-empty string naming no known mode. """ifrawisNoneornotraw.strip():returnSurfaceMode.COREvalue=raw.strip().lower()try:returnSurfaceMode(value)exceptValueError:accepted=", ".join(mode.valueformodeinSurfaceMode)raiseValueError(f"{SURFACE_ENV_VAR}={raw!r} is not a valid surface mode; accepted: {accepted}",)fromNone
[docs]defis_orientation_command(command_key:str)->bool:"""Whether ``command_key`` belongs to the always-advertised orientation slice."""ifcommand_keyin_ORIENTATION_KEYS:returnTruereturnany(command_key.startswith(prefix)forprefixin_ORIENTATION_PREFIXES)
[docs]defadvertised_descriptors(descriptors:tuple[McpToolDescriptor,...],*,mode:SurfaceMode,)->tuple[McpToolDescriptor,...]:"""Narrow the per-verb descriptors to those advertised under ``mode``. ``FULL`` returns ``descriptors`` unchanged - the flat surface. ``CORE`` returns only the orientation slice; the rest of the universe stays reachable through the meta pair and toolset activation but is not listed up front. The caller has already narrowed ``descriptors`` to the active persona's scope, so the orientation core is itself persona-filtered. Returns: The subset of ``descriptors`` to advertise in ``tools/list``. """ifmodeisSurfaceMode.FULL:returndescriptorsreturntuple(descriptorfordescriptorindescriptorsifis_orientation_command(descriptor.command_key))