{"record":{"id":"dc777d012ee900d4","repo":"mastra-ai/mastra","slug":"page-value-too-large-dc777d","errorCode":null,"errorMessage":"page value too large","messagePattern":"page value too large","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/storage/domains/mcp-clients/inmemory.ts","lineNumber":132,"sourceCode":"    // Also delete all versions for this client\n    await this.deleteVersionsByParentId(id);\n  }\n\n  async list(args?: StorageListMCPClientsInput): Promise<StorageListMCPClientsOutput> {\n    const { page = 0, perPage: perPageInput, orderBy, authorId, metadata, status } = args || {};\n    const { field, direction } = this.parseOrderBy(orderBy);\n\n    // Normalize perPage for query (false → MAX_SAFE_INTEGER, 0 → 0, undefined → 100)\n    const perPage = normalizePerPage(perPageInput, 100);\n\n    if (page < 0) {\n      throw new Error('page must be >= 0');\n    }\n\n    // Prevent unreasonably large page values\n    const maxOffset = Number.MAX_SAFE_INTEGER / 2;\n    if (page * perPage > maxOffset) {\n      throw new Error('page value too large');\n    }\n\n    // Get all MCP clients and apply filters\n    let configs = Array.from(this.db.mcpClients.values());\n\n    // Filter by status\n    if (status) {\n      configs = configs.filter(config => config.status === status);\n    }\n\n    // Filter by authorId if provided\n    if (authorId !== undefined) {\n      configs = configs.filter(config => config.authorId === authorId);\n    }\n\n    // Filter by metadata if provided (AND logic)\n    if (metadata && Object.keys(metadata).length > 0) {\n      configs = configs.filter(config => {","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/storage/domains/mcp-clients/inmemory.ts#L114-L150","documentation":"Also in `list` of the in-memory MCP clients domain: thrown when `page * perPage` would exceed `Number.MAX_SAFE_INTEGER / 2`, i.e., the computed offset is so large the slice would be meaningless or unsafe. It guards against absurd page numbers rather than memory blowup.","triggerScenarios":"Calling `list({ page: 1e300 })` or any huge page value; unvalidated user input flowing straight into the page parameter; multiplication with normalized perPage (default 100, or MAX_SAFE_INTEGER when perPage=false).","commonSituations":"Passing raw unsanitized query params; arithmetic bugs producing enormous page counters; passing `false` for perPage (fetch-all) with a large page.","solutions":["Cap the page value to a sane maximum before calling.","Sanitize numeric inputs from external sources with bounds checking.","Debug why the page counter grew that large (infinite pagination loop, counter overflow)."],"exampleFix":"// before\nawait mcpClients.list({ page: Number(req.query.page) });\n// after\nconst page = Math.min(Math.max(0, Number(req.query.page) || 0), 1_000_000);\nawait mcpClients.list({ page });","handlingStrategy":"validation","validationCode":"const MAX_PAGE = 1_000_000;\nconst safePage = Number.isFinite(page) ? Math.min(Math.max(0, Math.floor(page)), MAX_PAGE) : 0;\nawait mcpClients.list({ page: safePage, perPage });","typeGuard":"const isSafePage = (page: unknown): page is number =>\n  typeof page === 'number' && Number.isFinite(page) && page >= 0 && page * 100 <= Number.MAX_SAFE_INTEGER / 2;","tryCatchPattern":"try {\n  return await mcpClients.list({ page, perPage });\n} catch (err) {\n  if (err instanceof Error && err.message === 'page value too large') {\n    return mcpClients.list({ page: 0, perPage });\n  }\n  throw err;\n}","preventionTips":["Never pass raw external input as page; parse, floor, and bound it.","Watch for pagination loops that never terminate and inflate the page counter.","Avoid combining perPage: false (fetch-all) with large page values."],"tags":["pagination","validation","argument-error","in-memory"],"backgroundTag":"invalid-pagination-arguments","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}