feat(hints): add label field to StructuredHint#217
Conversation
Add a short semantic label (e.g. "routes via members", "implementors", "handler") to every structured hint so LLM agents can triage hints without parsing args. 37 named LABEL_* constants derived from existing TPL_* template prefixes. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
HumanBean17
left a comment
There was a problem hiding this comment.
Review: label field for StructuredHint
Reviewed the diff across all 3 files (mcp_hints.py, mcp_v2.py, propose/HINTS-STRUCTURED-LABEL.md).
Correctness
All label values match their corresponding string template prefixes exactly (the text before the first : in TPL_* constants). For colon-less advisory templates, the assigned labels are sensible short descriptions (e.g., "high fanout", "fuzzy strategy", "weak results").
Every _StructuredHint(...) constructor (47 total) now includes a label argument. No constructors were missed. Verified programmatically by scanning all _StructuredHint( calls and confirming LABEL_ appears in each constructor body.
Completeness
Three LABEL_* constants are defined but never used in any _StructuredHint constructor:
LABEL_ROLE_FILTER_FALLBACK("role filter fallback") -- pairs withTPL_NEIGHBORS_CALLS_ROLE_FILTER_OTHER_FALLBACKLABEL_ROLE_COLLISION("role collision") -- pairs withTPL_NEIGHBORS_CALLS_NODEFILTER_ROLE_COLLISIONLABEL_HAS_UNRESOLVED("has unresolved") -- pairs withTPL_NEIGHBORS_CALLS_HAS_UNRESOLVED
These correspond to string-only hints in neighbors_calls_meta_hints and neighbors_calls_fanout_hints which currently have no structured hint counterparts. This is not a bug -- the string hints fire in those functions but no _StructuredHint is emitted alongside them. The unused constants are harmless (dead code, not incorrect), but worth noting for a follow-up if structured counterparts are planned.
Consistency
Similar hints consistently get the same label regardless of context. For example:
"declaring method"is used for all route/client/producer declaring-method lookups (N5, N6, describe route/client/producer)"HTTP targets"is used consistently for HTTP_CALLS outbound follow-ups"handler"is used consistently for EXPOSES inbound lookups
StructuredHint field ordering
StructuredHint in mcp_v2.py: label is placed before tool, which puts the human-readable identifier first in JSON output. Good choice -- LLM consumers see the semantic name before the technical details.
_StructuredHint NamedTuple: label is last with default "", which is correct and required by Python's NamedTuple (defaulted fields must follow non-defaulted fields).
Description update
MCP_HINTS_STRUCTURED_FIELD_DESCRIPTION is updated to mention label before tool, consistent with the new field order.
Propose alignment
The propose document lists tests/test_mcp_hints.py -- assert on label values in scope, but the PR includes no test changes. Existing tests still pass (216 passed, 2 skipped) because label="" is the default on _StructuredHint. No test asserts that labels are present or correct. This is a minor gap -- explicit label assertions would strengthen coverage.
Validation
ruff check mcp_hints.py mcp_v2.py-- all checks passedpytest tests/test_mcp_hints.py-- 216 passed, 2 skipped
Verdict: LGTM. The implementation is correct, complete (all constructors labeled), and consistent. The three unused label constants are minor dead code. The missing test assertions for labels are a gap noted in the propose doc but not blocking.
- Add label parameter to _assert_structured_hint helper - Assert all structured hints have non-empty labels in parity + round-trip tests - Add test_structured_hint_label_values with 13 specific label checks - Remove 3 unused LABEL_* constants (role filter fallback, role collision, has unresolved) — will be added when structured counterparts are built Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Summary
label: strfield to_StructuredHint(internal NamedTuple) andStructuredHint(public Pydantic model)LABEL_*constants derived from existingTPL_*template prefixes (e.g."routes via members","implementors","handler")_StructuredHint(...)constructor now includes a label_to_structured_hintspasseslabelthrough to the public APIMotivation
String hints encode a semantic name before the colon (
"routes via members: neighbors(...)"), buthints_structuredhad no equivalent — LLM agents had to infer hint purpose fromargsalone. Alabelfield provides a stable, human-readable category tag.Relationship to #211 (
reasonfield)labelandreasonare complementary:labelis what (1–4 word semantic name),reasonis why (full advisory text). See the analysis in #216.Scope
mcp_hints.py— addlabelfield to_StructuredHint, addLABEL_*constants, update all constructorsmcp_v2.py— addlabelfield toStructuredHint, update_to_structured_hintspropose/HINTS-STRUCTURED-LABEL.md— propose documentNo reindex required — output-only change.
Validation
Closes #216
🤖 Generated with Claude Code