Fix list_dag_runs (MCP tool + af CLI) returning oldest runs first#192
Merged
kaxil merged 4 commits intoastronomer:mainfrom Apr 27, 2026
Merged
Conversation
… pagination
The list_dag_runs MCP tool only accepted dag_id and called Airflow's
GET /dags/{dag_id}/dagRuns with no order_by. Airflow defaults to id ASC,
so for any DAG with > 100 runs the tool returned the oldest 100 runs
ever created and recent runs were unreachable through the MCP. The
docstring already promised "sorted by most recent", so this is a
contract bug.
- Expose limit, offset, order_by on the list_dag_runs MCP tool.
- Default order_by to "-start_date" so callers get newest first by
default (start_date is a valid sort field on Airflow 2.x and 3.x,
no adapter changes needed).
- _list_dag_runs_impl drops order_by from the kwargs when None so
callers can still opt back into the Airflow API default if needed.
- Add unit tests in test_consolidated_tools.py covering the default
sort, limit/offset passthrough, custom order_by override, the
None-fallback in the internal impl, and error paths.
BaseAdapter._call already filters None values from query params, so the extra dict + conditional in _list_dag_runs_impl was redundant. Pass order_by straight through to the adapter; the HTTP behaviour is identical. Adjust the corresponding test to assert order_by=None reaches the adapter (rather than asserting it was omitted from the call).
Mirrors the MCP-tool fix in this PR: change the `--order-by` default from `None` (which falls through to the Airflow API default of `id` ascending - oldest first) to `-start_date`. Users investigating recent DAG activity see new runs at the top instead of having to scroll past hundreds of historical runs. Closes astronomer#168
kaxil
approved these changes
Apr 27, 2026
Contributor
|
Thanks for the PR @JoaVirtudes19 -- I pushed a couple more changes so I can release it today |
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.
The
list_dag_runsMCP tool only accepteddag_idand called Airflow'sGET /dags/{dag_id}/dagRunswith noorder_by. Airflow's default sort on that endpoint isid ASC, so for any DAG with more than 100 runs the tool returned the oldest 100 runs and the recent ones were unreachable through the MCP — directly contradicting the docstring's promise of "sorted by most recent".The
af runs listCLI hit the same root cause:--order-bydefaulted toNone, so the API again returned oldest-first. Issue #168 reported this from the CLI side.Changes
MCP tool (
list_dag_runs)limit,offset, andorder_byon the tool surfaceorder_by="-start_date"so callers get newest-firstCLI (
af runs list)--order-bydefault fromNoneto-start_date, matching the MCP toolWhy
-start_datestart_dateis the only sort field available on both Airflow 2.x and 3.x DAG-run list endpoints.run_afteris Airflow 3 only;logical_datedoesn't exist in v2 (it'sexecution_datethere). Picking-start_datekeeps a single default that works across both adapters.Callers who want a different order (e.g.
idascending to match the old Airflow default, or filter by state) can still pass--order-byexplicitly on the CLI ororder_by=on the MCP tool.Closes #168