{"record":{"id":"a7f329712c0d54a5","repo":"sansan0/TrendRadar","slug":"mode","errorCode":null,"errorMessage":"mode 必须是字符串类型","messagePattern":"mode 必须是字符串类型","errorType":"validation","errorClass":"InvalidParameterError","httpStatus":null,"severity":"error","filePath":"mcp_server/utils/validators.py","lineNumber":551,"sourceCode":"    \"\"\"\n    验证模式参数\n\n    Args:\n        mode: 模式字符串\n        valid_modes: 有效模式列表\n        default: 默认模式\n\n    Returns:\n        验证后的模式\n\n    Raises:\n        InvalidParameterError: 模式无效\n    \"\"\"\n    if mode is None:\n        return default\n\n    if not isinstance(mode, str):\n        raise InvalidParameterError(\"mode 必须是字符串类型\")\n\n    if mode not in valid_modes:\n        raise InvalidParameterError(\n            f\"无效的模式: {mode}\",\n            suggestion=f\"支持的模式: {', '.join(valid_modes)}\"\n        )\n\n    return mode\n\n\ndef validate_config_section(section: Optional[str]) -> str:\n    \"\"\"\n    验证配置节参数\n\n    Args:\n        section: 配置节名称\n\n    Returns:","sourceCodeStart":533,"sourceCodeEnd":569,"githubUrl":"https://github.com/sansan0/TrendRadar/blob/8ee26026ba6c11dec41a95fb3895a7162876caa1/mcp_server/utils/validators.py#L533-L569","documentation":"Raised by validate_mode when the `mode` argument is not None and not a str instance. The MCP server validates mode-like parameters against an allow-list; a non-string (int, dict, list, bool) fails type validation before the membership check. Only None is permitted (it maps to the default).","triggerScenarios":"Calling an MCP tool with `mode=1`, `mode={\"name\":\"fast\"}`, `mode=[\"fast\"]`, or `mode=True` instead of `mode=\"fast\"`. Any JSON type other than string or null triggers it.","commonSituations":"MCP clients serializing enum-like params as numbers or nested objects; LLM tool-calling producing structured JSON where a bare string was expected; passing a Python bool because a mode was named like a flag.","solutions":["Pass the mode as a plain string, e.g. mode=\"fast\", matching one of valid_modes.","Omit the parameter entirely (or pass null) to accept the documented default.","Check the tool schema in the MCP client and map enum values to strings before the call."],"exampleFix":"// before\ntool_call(mode=1)\n\n// after\ntool_call(mode=\"fast\")","handlingStrategy":"type-guard","validationCode":"if mode is not None and not isinstance(mode, str):\n    mode = str(mode)  # or reject explicitly\ntool_call(mode=mode)","typeGuard":"def is_valid_mode(v) -> bool:\n    return v is None or isinstance(v, str)","tryCatchPattern":"try:\n    tool_call(mode=mode)\nexcept InvalidParameterError as e:\n    if \"必须是字符串类型\" in str(e):\n        mode = str(mode)  # coerce and retry once","preventionTips":["Always send mode as a JSON string or omit it.","In LLM tool schemas, declare mode as an enum of strings so callers cannot send numbers."],"tags":["validation","mcp","type-error","mode"],"backgroundTag":null,"analyzedSha":"8ee26026ba6c11dec41a95fb3895a7162876caa1","analyzedAt":"2026-08-15T01:42:18.084Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}