barrel_mcp_pagination (barrel_mcp v2.0.2)

View Source

Cursor-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

fetch_fun/0

-type fetch_fun() ::
          fun((undefined | binary()) ->
                  {ok, [term()], undefined | binary()} | {ok, [term()]} | {error, term()}).

Functions

walk(Fetch)

-spec walk(fetch_fun()) -> {ok, [term()]} | {error, term()}.

Walk pagination starting from no cursor, with a 1000-page cap.

walk(Fetch, MaxPages)

-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.