{"record":{"id":"77d436ecd94bfc5d","repo":"sansan0/TrendRadar","slug":"keyword-100","errorCode":null,"errorMessage":"keyword 长度不能超过100个字符","messagePattern":"keyword 长度不能超过100个字符","errorType":"validation","errorClass":"InvalidParameterError","httpStatus":null,"severity":"warning","filePath":"mcp_server/utils/validators.py","lineNumber":507,"sourceCode":"    Returns:\n        处理后的关键词\n\n    Raises:\n        InvalidParameterError: 关键词无效\n    \"\"\"\n    if not keyword:\n        raise InvalidParameterError(\"keyword 不能为空\")\n\n    if not isinstance(keyword, str):\n        raise InvalidParameterError(\"keyword 必须是字符串类型\")\n\n    keyword = keyword.strip()\n\n    if not keyword:\n        raise InvalidParameterError(\"keyword 不能为空白字符\")\n\n    if len(keyword) > 100:\n        raise InvalidParameterError(\n            \"keyword 长度不能超过100个字符\",\n            suggestion=\"请使用更简洁的关键词\"\n        )\n\n    return keyword\n\n\ndef validate_top_n(top_n: Optional[Union[int, str]], default: int = 10) -> int:\n    \"\"\"\n    验证TOP N参数\n\n    Args:\n        top_n: TOP N数量（整数或字符串）\n        default: 默认值\n\n    Returns:\n        验证后的值\n","sourceCodeStart":489,"sourceCodeEnd":525,"githubUrl":"https://github.com/sansan0/TrendRadar/blob/8ee26026ba6c11dec41a95fb3895a7162876caa1/mcp_server/utils/validators.py#L489-L525","documentation":"Raised by the keyword validator in the MCP server when a search keyword exceeds 100 characters after stripping whitespace. The limit enforces concise search terms so downstream news-search providers do not truncate or reject the query. It is an InvalidParameterError carrying a suggestion ('请使用更简洁的关键词'), so it is a client-input validation error, not a server fault.","triggerScenarios":"Calling an MCP tool that accepts a `keyword` parameter (e.g. news search) with a string longer than 100 chars after `.strip()`. Leading/trailing whitespace does not count toward the limit because the check runs on the stripped value.","commonSituations":"A user pastes a full sentence, URL, or log excerpt into a keyword field; an LLM-driven MCP client concatenates multiple search terms into one keyword string instead of issuing separate calls.","solutions":["Shorten the keyword to a concise term (<= 100 characters, excluding surrounding whitespace).","If searching for multiple concepts, split into several tool calls, one keyword each.","If the keyword is a long URL or quote, extract the distinctive phrase instead of passing the whole string.","Catch InvalidParameterError client-side and surface the embedded suggestion text to the user."],"exampleFix":"// before\ntool_call(keyword=\"人工智能在医疗健康领域的最新研究进展、行业落地案例以及监管政策变化趋势的完整分析报告\")\n\n// after\ntool_call(keyword=\"人工智能 医疗监管\")","handlingStrategy":"validation","validationCode":"def safe_keyword(kw: str) -> str:\n    kw = (kw or \"\").strip()\n    if not kw:\n        raise ValueError(\"keyword is empty\")\n    if len(kw) > 100:\n        raise ValueError(f\"keyword too long: {len(kw)} > 100\")\n    return kw\n\ntool_call(keyword=safe_keyword(user_input))","typeGuard":"def is_valid_keyword(v) -> bool:\n    return isinstance(v, str) and 0 < len(v.strip()) <= 100","tryCatchPattern":"try:\n    result = tool_call(keyword=kw)\nexcept InvalidParameterError as e:\n    # e.message contains the Chinese reason; e.suggestion has guidance\n    show_user(e.message, getattr(e, \"suggestion\", None))","preventionTips":["Trim and length-check keywords in the client before every MCP call.","Split multi-concept searches into separate calls instead of one long keyword."],"tags":["validation","mcp","keyword","input-length"],"backgroundTag":null,"analyzedSha":"8ee26026ba6c11dec41a95fb3895a7162876caa1","analyzedAt":"2026-08-15T01:42:18.084Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}