{"record":{"id":"a07b93ec15ec8254","repo":"sansan0/TrendRadar","slug":"platforms","errorCode":null,"errorMessage":"platforms 参数必须是列表类型","messagePattern":"platforms 参数必须是列表类型","errorType":"validation","errorClass":"InvalidParameterError","httpStatus":null,"severity":"error","filePath":"mcp_server/utils/validators.py","lineNumber":235,"sourceCode":"        - platforms=None 时，返回 config.yaml 中配置的平台列表\n        - 会验证平台ID是否在 config.yaml 的 platforms 配置中\n        - 配置加载失败时，允许所有平台通过（降级策略）\n    \"\"\"\n    supported_platforms = get_supported_platforms()\n\n    if platforms is None:\n        # 返回配置文件中的平台列表（用户的默认配置）\n        return supported_platforms if supported_platforms else []\n\n    # 支持字符串形式的列表输入（某些 MCP 客户端会将 JSON 数组序列化为字符串）\n    if isinstance(platforms, str):\n        platforms = _parse_string_to_list(platforms)\n        if not platforms:\n            # 空字符串或解析后为空，使用默认平台\n            return supported_platforms if supported_platforms else []\n\n    if not isinstance(platforms, list):\n        raise InvalidParameterError(\"platforms 参数必须是列表类型\")\n\n    if not platforms:\n        # 空列表时，返回配置文件中的平台列表\n        return supported_platforms if supported_platforms else []\n\n    # 如果配置加载失败（supported_platforms为空），允许所有平台通过\n    if not supported_platforms:\n        print(\"警告：平台配置未加载，跳过平台验证\")\n        return platforms\n\n    # 验证每个平台是否在配置中\n    invalid_platforms = [p for p in platforms if p not in supported_platforms]\n    if invalid_platforms:\n        raise InvalidParameterError(\n            f\"不支持的平台: {', '.join(invalid_platforms)}\",\n            suggestion=f\"支持的平台（来自config.yaml）: {', '.join(supported_platforms)}\"\n        )\n","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/sansan0/TrendRadar/blob/8ee26026ba6c11dec41a95fb3895a7162876caa1/mcp_server/utils/validators.py#L217-L253","documentation":"Raised by the platforms validator when, after the string-parsing path, the value is still not a list. The function accepts None (uses config defaults), a JSON-array string like \"[\\\"weibo\\\"]\" (parsed via _parse_string_to_list), or an actual list; any other type (dict, int, bare non-JSON string) reaches this raise.","triggerScenarios":"Passing platforms as a single bare string \"weibo\" (not JSON-array syntax), a number, or an object like {\"platform\": \"weibo\"}. Example: tools/call with {\"platforms\": \"weibo, wechat\"} — commas without brackets are not JSON, and if _parse_string_to_list returns a non-list this raise fires.","commonSituations":"MCP clients that collapse arrays into concatenated strings; users writing a comma-separated list instead of a JSON array; client SDKs sending query-string style values.","solutions":["Pass an actual JSON array: [\"weibo\", \"wechat\"]","If forced to send a string, use JSON array syntax: \"[\\\"weibo\\\", \\\"wechat\\\"]\"","Omit the parameter entirely (null) to use the configured default platform list","Verify your MCP client is not flattening array parameters before transport"],"exampleFix":"// before\n{\"platforms\": \"weibo\"}\n// after\n{\"platforms\": [\"weibo\"]}","handlingStrategy":"type-guard","validationCode":"if (typeof platforms === 'string') {\n  try { platforms = JSON.parse(platforms); } catch { /* not JSON */ }\n}\nif (!Array.isArray(platforms)) platforms = undefined; // let server use defaults","typeGuard":"function isPlatformList(v: unknown): v is string[] {\n  if (typeof v === 'string') {\n    try { return Array.isArray(JSON.parse(v)); } catch { return false; }\n  }\n  return Array.isArray(v) && v.every(p => typeof p === 'string');\n}","tryCatchPattern":"try { call({ platforms }); }\ncatch (e) {\n  if (/platforms 参数必须是列表类型/.test(e.message)) call({ platforms: undefined });\n  else throw e;\n}","preventionTips":["Always send platforms as a JSON array of strings","Verify your MCP transport preserves array types (test round-trip once)","Omit the parameter to use configured defaults instead of sending odd types"],"tags":["validation","platforms","json-serialization","mcp"],"backgroundTag":null,"analyzedSha":"8ee26026ba6c11dec41a95fb3895a7162876caa1","analyzedAt":"2026-08-15T01:42:18.084Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}