Skip to main content

Module pagination

Module pagination 

Source
Expand description

CLI-side pagination walkers.

Mirror of crate::mcp::pagination, but tuned for the CLI’s output model: these helpers walk pages and return the accumulated raw items as a Vec<Value> so the existing OutputConfig::print_items machinery can format them as tables, JSON, or CSV. No compaction, no envelope — just the loop logic and termination handling shared across every paginated CLI command.

§Contract

Every walker respects the global pagination flags on crate::Cli:

  • --all: auto-fetch pages until natural termination or --limit hit.
  • --limit N: cap total items returned across pages.
  • --page N (page-style only): manual page selection. With --all, the starting page.
  • --cursor X (cursor-style only): manual cursor. With --all, the starting cursor.
  • --start MS + --start-id ID (start-id-style only): manual boundary pair. With --all, the starting boundary.

--limit is enforced after walking, so --all --limit 500 returns up to 500 items across N pages rather than truncating the first page to 500. A hard cap of 100 pages prevents runaway loops.

Functions§

walk_body
Body-based walker for the v3 audit-log endpoint. POST to path with base_body() + pagination block; advance via next_timestamp(last_item). extra_pagination lets the caller pre-populate pageRows / pageDirection fields the helper doesn’t manage directly.
walk_cursor
Cursor-based walker for v3 endpoints (?cursor=X, response carries next_cursor: string or empty). build_path(Option<&str>) returns the URL given an optional cursor. items_keys is the priority list of candidate response keys (e.g. &["data", "channels"]).
walk_page
Page-based walker for v2 endpoints (?page=N, response carries last_page: bool). build_path(page) returns the URL for a given page. items_key is the response field holding the array (e.g. "tasks").
walk_start_id
Start-id-based walker for v2 comment endpoints (?start=<ms>&start_id=<id> paired, response carries {comments: [...]} with termination inferred from short page). build_path(Option<i64>, Option<&str>) returns the URL given an optional boundary pair. items_key is the response key (typically "comments").