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
Called by tools_clause
Tested by 17 tests
test_a_bare_string_description_is_accepted, test_bad_json_names_the_file, test_empty_directory_is_an_error, test_filename_and_declared_tool_must_agree, test_missing_snippet_is_refused, test_missing_template_is_refused, test_missing_var_is_refused, test_no_description_claims_an_elided_field_is_null, test_no_served_text_is_ever_truncated, test_non_string_description_is_refused, test_registration_order_follows_declared_priority, test_row_returning_tools_all_carry_the_shared_rows_note
Calls _entry
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