sansan0/TrendRadar · warning · InvalidParameterError

{param_name} 必须在 {min_value} 到 {max_value} 之间,当前值: {threshol

Error message

{param_name} 必须在 {min_value} 到 {max_value} 之间,当前值: {threshold}

What it means

Raised by the threshold validator when the value is numeric but outside [min_value, max_value]. This is a range check after type coercion succeeded (int→float, numeric string→float). The message shows the offending value and suggests the recommended default.

Source

Thrown at mcp_server/utils/validators.py:620

    if threshold is None:
        return default

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

    # 整数转浮点数
    if isinstance(threshold, int):
        threshold = float(threshold)

    if not isinstance(threshold, float):
        raise InvalidParameterError(
            f"{param_name} 必须是数字类型",
            suggestion=f"请提供 {min_value} 到 {max_value} 之间的数字"
        )

    if threshold < min_value or threshold > max_value:
        raise InvalidParameterError(
            f"{param_name} 必须在 {min_value} 到 {max_value} 之间,当前值: {threshold}",
            suggestion=f"推荐值: {default}"
        )

    return threshold


def validate_date_query(
    date_query: str,
    allow_future: bool = False,
    max_days_ago: int = 365
) -> datetime:
    """
    验证并解析日期查询字符串

    Args:
        date_query: 日期查询字符串
        allow_future: 是否允许未来日期

View on GitHub (pinned to 8ee26026ba)

Solutions

  1. Rescale the value into [min_value, max_value] as shown in the message (e.g. 80 → 0.8).
  2. Pass null/omit the parameter to accept the recommended default.
  3. Check the tool's parameter schema or docstring for the documented bounds before choosing a value.

Example fix

# before
threshold = 80  # percent, out of 0.0-1.0 range

# after
threshold = 0.8  # fraction within range
Defensive patterns

Strategy: validation

Validate before calling

def clamp_threshold(v, lo, hi, default):
    if v is None:
        return default
    v = float(v)
    return max(lo, min(hi, v))  # or reject instead of clamping
tool_call(threshold=clamp_threshold(t, 0.0, 1.0, 0.8))

Type guard

def in_range(v, lo, hi) -> bool:
    return v is not None and isinstance(v, (int, float)) and lo <= v <= hi

Try / catch

try:
    tool_call(threshold=t)
except InvalidParameterError as e:
    if "之间" in str(e):
        t = 0.8  # recommended default from suggestion
        tool_call(threshold=t)

Prevention

When it happens

Trigger: Passing threshold=5.0 when the parameter is bounded to 0.0–1.0; passing a percentage (80) where a fraction (0.8) is expected; negative values for a positive-only parameter.

Common situations: Unit confusion (percent vs fraction) is the most common cause — the API expects 0.8 but the user sends 80. Also copying a value tuned for one parameter into another with a different range.

Related errors


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