sansan0/TrendRadar · error · InvalidParameterError

INVALID_PARAMETER

INVALID_PARAMETER

Error message

无效的搜索模式: {search_mode}

What it means

Thrown by search_news_unified when the search_mode argument is not one of the three supported modes: keyword, fuzzy, entity. The check runs right after keyword validation and before any query execution, so no search happens when it fires.

Source

Thrown at mcp_server/tools/search_tools.py:83

            include_rss: 是否同时搜索RSS数据,默认False
            rss_limit: RSS返回条数限制,默认20

        Returns:
            搜索结果字典,包含匹配的新闻列表(热榜和RSS分开展示)

        Examples:
            - search_news_unified(query="人工智能", search_mode="keyword")
            - search_news_unified(query="特斯拉降价", search_mode="fuzzy", threshold=0.4)
            - search_news_unified(query="马斯克", search_mode="entity", limit=20)
            - search_news_unified(query="AI", include_rss=True)  # 同时搜索热榜和RSS
            - search_news_unified(query="iPhone 16", date_range={"start": "2025-01-01", "end": "2025-01-07"})
        """
        try:
            # 参数验证
            query = validate_keyword(query)

            if search_mode not in ["keyword", "fuzzy", "entity"]:
                raise InvalidParameterError(
                    f"无效的搜索模式: {search_mode}",
                    suggestion="支持的模式: keyword, fuzzy, entity"
                )

            if sort_by not in ["relevance", "weight", "date"]:
                raise InvalidParameterError(
                    f"无效的排序方式: {sort_by}",
                    suggestion="支持的排序: relevance, weight, date"
                )

            limit = validate_limit(limit, default=50)
            threshold = validate_threshold(threshold, default=0.6, min_value=0.0, max_value=1.0)

            # 处理日期范围
            if date_range:
                from ..utils.validators import validate_date_range
                date_range_tuple = validate_date_range(date_range)
                start_date, end_date = date_range_tuple

View on GitHub (pinned to 8ee26026ba)

Solutions

  1. Set search_mode to exactly one of: keyword, fuzzy, entity
  2. For approximate matching use fuzzy together with threshold (default 0.6, range 0.0–1.0)
  3. For named-entity based search (e.g. person/company names) use entity

Example fix

# before
search_news_unified(query="AI", search_mode="semantic")

# after
search_news_unified(query="AI", search_mode="fuzzy", threshold=0.4)
Defensive patterns

Strategy: validation

Validate before calling

SEARCH_MODES = {"keyword", "fuzzy", "entity"}
search_mode = search_mode if search_mode in SEARCH_MODES else "keyword"

Type guard

def is_search_mode(v) -> bool:
    return isinstance(v, str) and v in {"keyword", "fuzzy", "entity"}

Try / catch

try:
    search_news_unified(query=q, search_mode=mode)
except InvalidParameterError as e:
    if "搜索模式" in str(e):
        return search_news_unified(query=q, search_mode="keyword")  # safe fallback
    raise

Prevention

When it happens

Trigger: Calling search_news_unified with search_mode="semantic", "match", "regex", or any string outside ["keyword", "fuzzy", "entity"]; passing a mode from a different tool's vocabulary.

Common situations: LLM agents guessing mode names; copying mode values from another search API; case sensitivity issues ("Keyword" is rejected — the check is exact-match).

Related errors


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