{"record":{"id":"622d820d3d867ee6","repo":"sansan0/TrendRadar","slug":"limit-max-limit","errorCode":null,"errorMessage":"limit 不能超过 {max_limit}","messagePattern":"limit 不能超过 (.+?)","errorType":"validation","errorClass":"InvalidParameterError","httpStatus":null,"severity":"error","filePath":"mcp_server/utils/validators.py","lineNumber":286,"sourceCode":"\n    Raises:\n        InvalidParameterError: 参数无效\n    \"\"\"\n    if limit is None:\n        return default\n\n    # 支持字符串形式的整数（某些 MCP 客户端会将数字序列化为字符串）\n    if isinstance(limit, str):\n        limit = _parse_string_to_int(limit, \"limit\")\n\n    if not isinstance(limit, int):\n        raise InvalidParameterError(\"limit 参数必须是整数类型\")\n\n    if limit <= 0:\n        raise InvalidParameterError(\"limit 必须大于0\")\n\n    if limit > max_limit:\n        raise InvalidParameterError(\n            f\"limit 不能超过 {max_limit}\",\n            suggestion=f\"请使用分页或降低limit值\"\n        )\n\n    return limit\n\n\ndef validate_date(date_str: str) -> datetime:\n    \"\"\"\n    验证日期格式\n\n    Args:\n        date_str: 日期字符串 (YYYY-MM-DD)\n\n    Returns:\n        datetime对象\n\n    Raises:","sourceCodeStart":268,"sourceCodeEnd":304,"githubUrl":"https://github.com/sansan0/TrendRadar/blob/8ee26026ba6c11dec41a95fb3895a7162876caa1/mcp_server/utils/validators.py#L268-L304","documentation":"Raised by validate_limit when limit > max_limit (default 1000, configurable per call site). It is a resource guard: one request cannot fetch more than the cap; the suggestion tells you to paginate or lower the limit.","triggerScenarios":"Passing limit: 5000 to a tool whose call site uses the default max_limit=1000, or a call site with a tighter cap (e.g. max_limit=100) and limit: 200. LLMs asking for 'all data' with limit: 99999 also hit this.","commonSituations":"Users attempting full-dataset exports in one call; tool wrappers not surfacing the per-tool max; a lower max_limit configured for an expensive tool while the client assumes the global default.","solutions":["Lower limit to at most max_limit (check the tool's schema/docs for its cap; default 1000)","Implement pagination: request in batches of max_limit using offset/cursor parameters until fewer than a full page returns","Cache or narrow the query (date_range, keyword) so a smaller limit suffices","If you operate the server and genuinely need bigger pages, raise max_limit at that call site (mind memory/time)"],"exampleFix":"# before\nresult = service.query(limit=5000)\n# after\nbatch = []\noffset = 0\nwhile True:\n    page = service.query(limit=1000, offset=offset)\n    batch.extend(page)\n    if len(page) < 1000:\n        break\n    offset += 1000","handlingStrategy":"validation","validationCode":"const MAX = 1000; // confirm per-tool cap\nconst limit = Math.min(desiredLimit, MAX);\nconst pages = paginate(desiredCount, limit); // loop offset until short page","typeGuard":null,"tryCatchPattern":"try { call({ limit: desired }); }\ncatch (e) {\n  const m = e.message.match(/limit 不能超过 (\\d+)/);\n  if (m) desired = Number(m[1]); // adopt server cap, paginate from there\n  else throw e;\n}","preventionTips":["Read the tool schema for its max_limit before choosing page size","Always paginate large exports instead of one oversized call","Cache the discovered cap after the first 4xx-style response"],"tags":["limit","pagination","resource-guard"],"backgroundTag":null,"analyzedSha":"8ee26026ba6c11dec41a95fb3895a7162876caa1","analyzedAt":"2026-08-15T01:42:18.084Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}