descriptions.py

clew/mcp_server/descriptions.py

Loader for the MCP tool descriptions, which live in JSON — not in Python.

load_descriptions

dict[str, str] clew.mcp_server.descriptions.load_descriptions(int tier=DEFAULT_TIER)

Every description declared for one tier, in registration order.

clew/mcp_server/descriptions.py:212

Source · 28 lines
def load_descriptions(tier: int = DEFAULT_TIER) -> dict[str, str]:
    """Reads every `*.json` in `descriptions/` except the `_templates/` subdirectory,
    keeps those declaring the requested TIER, and orders them by declared priority then
    name. An empty result raises rather than returning `{}` — a packaging mistake that
    dropped the data files would otherwise present as a server with no tools and no
    explanation, and a mistyped tier as a server with no tier-0 surface.

    THE TIER IS DECLARED IN THE TOOL'S OWN FILE, not inferred from which Python module
    registers it. The tier-0 tools' descriptions used to be inline string literals in
    `server.py` — the one arrangement this module exists to prevent — and the reason they
    survived there is mechanical rather than principled: this loader returned EVERY file
    it found and `tools_query` assigned that straight to `TIER1_TOOLS`, so a tier-0 file
    dropped in beside the others would have been registered as a query tool.

    Tier-0 REGISTRATION order stays fixed in `build_server`, which names each function
    explicitly, so `priority` is read for tier 1 and carried harmlessly for tier 0.

    @brief Load one tier's tool descriptions from JSON.
    @return Ordered {tool: description}.
    @version 2
    """
    files = sorted(p for p in DESCRIPTIONS_DIR.glob("*.json") if not p.name.startswith("_"))
    if not files:
        raise ValueError(f"no tool descriptions found in {DESCRIPTIONS_DIR}")
    entries = sorted(e for e in (_entry(p) for p in files) if e[0] == tier)
    if not entries:
        raise ValueError(f"no tool descriptions declare tier {tier} in {DESCRIPTIONS_DIR}")
    return {name: text for _, _, name, text in entries}

1 more lines, not shown

Activity · 7 steps
lines 233–233files = sorted(p for p in DESCRIPTIONS_DIR.glob("*.json") if not p.name.startswith("_"))lines 234–234◇ if not fileslines 235–235raise ValueError(f"no tool descriptions found in {DESCRIPTIONS_DIR}")lines 236–236entries = sorted(e for e in (_entry(p) for p in files) if e[0] == tier)lines 237–237◇ if not entrieslines 238–238raise ValueError(f"no tool descriptions declare tier {tier} in {DESCRIPTIONS_DIR}")lines 239–239return {name: text for _, _, name, text in entries}

Requirements

REQ-DDB-MCP-001

Flows