Interface McpCursor

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

Pagination strategy for MCP list dispatchers (tools / prompts / resources / resource templates).

Built-in strategies:

  • SINGLE_PAGE - Returns everything in one page (default; ignores any incoming cursor).
  • fixedSize(int) - Slices a list into pages of a fixed size using opaque integer cursors.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final McpCursor
    Returns everything in a single page; emits no nextCursor.
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    cursorOf(Object params)
    Extracts the opaque pagination cursor from a JSON-RPC params value.
    static McpCursor
    fixedSize(int pageSize)
    Returns a fixed-page-size cursor.
    <T> McpPage<T>
    page(List<T> all, String cursor, BeanStore ctx)
    Slices a descriptor list into a page returned from tools/list, prompts/list, resources/list, or resources/templates/list.
    static int
    Parses a cursor as a non-negative integer offset; returns 0 for null or non-numeric inputs.
  • Field Details

    • SINGLE_PAGE

      static final McpCursor SINGLE_PAGE
      Returns everything in a single page; emits no nextCursor.
  • Method Details

    • page

      <T> McpPage<T> page(List<T> all, String cursor, BeanStore ctx)
      Slices a descriptor list into a page returned from tools/list, prompts/list, resources/list, or resources/templates/list.
      Type Parameters:
      T - Element type.
      Parameters:
      all - The full list of descriptors. Never null.
      cursor - Opaque cursor from the request, or null for the first page.
      ctx - Per-request bean store (provided for cursor strategies that need access to the request).
      Returns:
      A non-null page.
    • fixedSize

      static McpCursor fixedSize(int pageSize)
      Returns a fixed-page-size cursor.

      Cursor representation is an opaque integer offset (parsed leniently; non-numeric values restart at offset 0).

      Parameters:
      pageSize - Maximum items per page. Must be > 0.
      Returns:
      A new cursor strategy.
    • parseOffset

      static int parseOffset(String cursor)
      Parses a cursor as a non-negative integer offset; returns 0 for null or non-numeric inputs.
      Parameters:
      cursor - Cursor value (may be null).
      Returns:
      Parsed offset.
    • cursorOf

      static String cursorOf(Object params)
      Extracts the opaque pagination cursor from a JSON-RPC params value.
      Parameters:
      params - The raw params value from the request. Can be null.
      Returns:
      The cursor parameter, or null if absent.
      Throws:
      McpException - If params is present but is not a JSON object.