UNPKG

@debugg-ai/debugg-ai-mcp

Version:

Zero-Config, Fully AI-Managed End-to-End Testing for all code gen platforms.

33 lines (32 loc) 1.17 kB
/** * Shared pagination helpers for list_* tools. Every list tool must expose * {page?, pageSize?} inputs and return a consistent pageInfo object so * callers never silently get truncated results. */ export const DEFAULT_PAGE_SIZE = 20; export const MAX_PAGE_SIZE = 200; /** * Translate caller inputs into safe backend query params. * Defaults page=1, pageSize=20. Clamps pageSize to [1, MAX_PAGE_SIZE=200]. * Returns snake_case keys matching the backend's `?page=&page_size=` convention. */ export function toPaginationParams(input) { const page = Math.max(1, Math.floor(input.page ?? 1)); const pageSize = Math.min(MAX_PAGE_SIZE, Math.max(1, Math.floor(input.pageSize ?? DEFAULT_PAGE_SIZE))); return { page, pageSize }; } /** * Build the pageInfo block for the MCP response from the backend's * DRF-style list envelope (count + next + previous). */ export function makePageInfo(page, pageSize, count, next) { const totalCount = count ?? 0; const totalPages = totalCount === 0 ? 0 : Math.ceil(totalCount / pageSize); return { page, pageSize, totalCount, totalPages, hasMore: !!next, }; }