barrel_mcp_pagination (barrel_mcp v2.0.2)
View SourceCursor-based pagination walker for MCP */list methods.
Every MCP */list response may include a nextCursor that the client passes back as cursor on the next call until the server omits it. This module turns that loop into a single function call.
Usage from the client:
barrel_mcp_pagination:walk(
fun(Cursor) -> barrel_mcp_client:list_tools(Pid, #{cursor => Cursor, want_cursor => true}) end).Returns {ok, AllItems} or {error, Reason} on the first error. A MaxPages guard prevents accidental runaway pagination.
Summary
Functions
Walk pagination starting from no cursor, with a 1000-page cap.
Walk pagination with an explicit page cap. The cap stops the loop with {error, max_pages} before exhausting memory if a server never stops returning a cursor.
Types
Functions
Walk pagination starting from no cursor, with a 1000-page cap.
-spec walk(fetch_fun(), pos_integer()) -> {ok, [term()]} | {error, term()}.
Walk pagination with an explicit page cap. The cap stops the loop with {error, max_pages} before exhausting memory if a server never stops returning a cursor.