Skip to content

refactor(tools): DRY the 5 symmetric list_available_* tool bodies via _run_list helper - #22

Merged
romer8 merged 1 commit into
mainfrom
refactor/list-tools-dry
May 21, 2026
Merged

refactor(tools): DRY the 5 symmetric list_available_* tool bodies via _run_list helper#22
romer8 merged 1 commit into
mainfrom
refactor/list-tools-dry

Conversation

@romer8

@romer8 romer8 commented May 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Extract _run_list(*, log_name, envelope_key, required, log_fields, call) helper in nextgen_mcp/tools.py
  • Refactor 5 of 6 list_available_*_tool bodies to use it: models, forecasts, cycles, vpus, output_files
  • list_available_dates_tool left alone — its pagination + range-filtering body is structurally different

Internal-only refactor. No behavior change. Same Pydantic signatures, same response shapes, same log line content, same _require() envelope on missing args. The helper centralizes the boilerplate that was repeated 5× (call-log → run → envelope-wrap → completed-log).

Net diff: +89 / −84 lines. The line-count win is modest; the structural win is one place to fix logging format, envelope-key wrapping, and count derivation.

Companion to the deferred consolidation plan (docs/plans/2026-05-21-001-...): does the cheap maintenance win without the LLM-facing trade-offs of collapsing to one tool.

Test plan

  • pytest test_mcp/ --no-header -q174/174 passing
  • No public-API surface change (decorator names, parameters, descriptions all preserved)
  • list_available_dates_tool body untouched

…ailable_* tool bodies

Each of `list_available_models`, `list_available_forecasts`, `list_available_cycles`,
`list_available_vpus`, `list_available_output_files` repeated the same boilerplate
shape: `_require()` check -> log "called" line -> call backing logic.list_available_X
-> wrap with `_prefer_id_objects(raw, envelope_key)` -> log "completed" line with
count. Only the per-tool args, envelope key, and logic function call differed.

`_run_list(*, log_name, envelope_key, required, log_fields, call)` centralizes
items 2-5; each tool body now does its arg normalization (`_as_id`,
`_parse_date_or_today`) and provides the `call` lambda. The Pydantic-validated
signatures are unchanged - descriptions, defaults, `Annotated[...]` annotations
all preserved.

`list_available_dates` is skipped: its pagination + range-filtering body is
structurally different and doesn't fit the helper. `query_files_by_selector`
and the hydrofabric tools are unaffected.

No behavior change. 174/174 tests pass. Same response shapes, same log line
content, same `_require()` envelope on missing args.
@romer8
romer8 merged commit 18b306d into main May 21, 2026
2 checks passed
@romer8
romer8 deleted the refactor/list-tools-dry branch May 21, 2026 19:38
romer8 added a commit that referenced this pull request May 22, 2026
One PR: extract _run_list helper for the 5 symmetric list_available_*
tool bodies (#22). Pure refactor — no contract or behavior change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant