refactor(tools): DRY the 5 symmetric list_available_* tool bodies via _run_list helper - #22
Merged
Merged
Conversation
…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
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_run_list(*, log_name, envelope_key, required, log_fields, call)helper innextgen_mcp/tools.pylist_available_*_toolbodies to use it:models,forecasts,cycles,vpus,output_fileslist_available_dates_toolleft alone — its pagination + range-filtering body is structurally differentInternal-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 -q→ 174/174 passinglist_available_dates_toolbody untouched