sansan0/TrendRadar · error · InvalidParameterError

limit 不能超过 {max_limit}

Error message

limit 不能超过 {max_limit}

What it means

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.

Source

Thrown at mcp_server/utils/validators.py:286

    Raises:
        InvalidParameterError: 参数无效
    """
    if limit is None:
        return default

    # 支持字符串形式的整数(某些 MCP 客户端会将数字序列化为字符串)
    if isinstance(limit, str):
        limit = _parse_string_to_int(limit, "limit")

    if not isinstance(limit, int):
        raise InvalidParameterError("limit 参数必须是整数类型")

    if limit <= 0:
        raise InvalidParameterError("limit 必须大于0")

    if limit > max_limit:
        raise InvalidParameterError(
            f"limit 不能超过 {max_limit}",
            suggestion=f"请使用分页或降低limit值"
        )

    return limit


def validate_date(date_str: str) -> datetime:
    """
    验证日期格式

    Args:
        date_str: 日期字符串 (YYYY-MM-DD)

    Returns:
        datetime对象

    Raises:

View on GitHub (pinned to 8ee26026ba)

Solutions

  1. Lower limit to at most max_limit (check the tool's schema/docs for its cap; default 1000)
  2. Implement pagination: request in batches of max_limit using offset/cursor parameters until fewer than a full page returns
  3. Cache or narrow the query (date_range, keyword) so a smaller limit suffices
  4. If you operate the server and genuinely need bigger pages, raise max_limit at that call site (mind memory/time)

Example fix

# before
result = service.query(limit=5000)
# after
batch = []
offset = 0
while True:
    page = service.query(limit=1000, offset=offset)
    batch.extend(page)
    if len(page) < 1000:
        break
    offset += 1000
Defensive patterns

Strategy: validation

Validate before calling

const MAX = 1000; // confirm per-tool cap
const limit = Math.min(desiredLimit, MAX);
const pages = paginate(desiredCount, limit); // loop offset until short page

Try / catch

try { call({ limit: desired }); }
catch (e) {
  const m = e.message.match(/limit 不能超过 (\d+)/);
  if (m) desired = Number(m[1]); // adopt server cap, paginate from there
  else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of sansan0/TrendRadar@8ee26026ba (2026-08-15). Data as JSON: /api/errors/622d820d3d867ee6. Report an issue: GitHub.