mastra-ai/mastra · error
page value too large
Error message
page value too large
What it means
list() rejects page values whose computed offset (page * perPage) exceeds Number.MAX_SAFE_INTEGER / 2. Multiplying an enormous page by perPage would produce an unsafe offset, so the adapter refuses it rather than silently corrupting slicing math.
Source
Thrown at packages/core/src/storage/domains/mcp-servers/inmemory.ts:132
// Also delete all versions for this server
await this.deleteVersionsByParentId(id);
}
async list(args?: StorageListMCPServersInput): Promise<StorageListMCPServersOutput> {
const { page = 0, perPage: perPageInput, orderBy, authorId, metadata, status = 'published' } = args || {};
const { field, direction } = this.parseOrderBy(orderBy);
// Normalize perPage for query (false → MAX_SAFE_INTEGER, 0 → 0, undefined → 100)
const perPage = normalizePerPage(perPageInput, 100);
if (page < 0) {
throw new Error('page must be >= 0');
}
// Prevent unreasonably large page values
const maxOffset = Number.MAX_SAFE_INTEGER / 2;
if (page * perPage > maxOffset) {
throw new Error('page value too large');
}
// Get all MCP servers and apply filters
let configs = Array.from(this.db.mcpServers.values());
// Filter by status
if (status) {
configs = configs.filter(config => config.status === status);
}
// Filter by authorId if provided
if (authorId !== undefined) {
configs = configs.filter(config => config.authorId === authorId);
}
// Filter by metadata if provided (AND logic)
if (metadata && Object.keys(metadata).length > 0) {
configs = configs.filter(config => {View on GitHub (pinned to 75dd419e61)
Solutions
- Use realistic page numbers (iterate pages starting at 0)
- Cap page at a sane maximum at your API boundary
- If you need everything, use perPage:false with page 0 instead of a huge page
Example fix
// before
await storage.listMCPServers({ page: 9e15 });
// after
const MAX_PAGE = 1_000_000;
await storage.listMCPServers({ page: Math.min(Number(input.page ?? 0), MAX_PAGE) }); Defensive patterns
Strategy: validation
Validate before calling
function safePage(page: unknown, perPage: number | false | undefined): number {
const n = Number(page ?? 0);
const eff = perPage === false ? Number.MAX_SAFE_INTEGER : perPage ?? 100;
if (n * eff > Number.MAX_SAFE_INTEGER / 2) throw new RangeError('page value too large');
return n;
} Type guard
const isBoundedPage = (p: unknown, perPage: number): p is number => typeof p === 'number' && Number.isInteger(p) && p >= 0 && p * perPage <= Number.MAX_SAFE_INTEGER / 2;
Try / catch
try {
return await storage.listMCPServers({ page, perPage });
} catch (e) {
if (e instanceof Error && e.message === 'page value too large') {
return await storage.listMCPServers({ page: 0, perPage });
}
throw e;
} Prevention
- Cap page at a sane maximum in your own API layer
- Never combine perPage:false with a non-zero page
- Treat untrusted page inputs as user data and bound them
When it happens
Trigger: Calling list() with a page so large that page * perPage > Number.MAX_SAFE_INTEGER / 2, e.g. page: Number.MAX_SAFE_INTEGER, or a huge page combined with perPage: false (which normalizes to MAX_SAFE_INTEGER).
Common situations: Clients sending garbage or adversarial page values in query strings; defaulting page from an unbounded number input; combining perPage:false with a large page.
Related errors
- perPage must be >= 0
- page must be >= 0
- page value too large
- Invalid knowledge node cursor.
- page must be >= 0
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/4397cf6f5c6aea9b.
Report an issue: GitHub.