sansan0/TrendRadar · error · InvalidParameterError
platforms 参数必须是列表类型
Error message
platforms 参数必须是列表类型
What it means
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.
Source
Thrown at mcp_server/utils/validators.py:235
- platforms=None 时,返回 config.yaml 中配置的平台列表
- 会验证平台ID是否在 config.yaml 的 platforms 配置中
- 配置加载失败时,允许所有平台通过(降级策略)
"""
supported_platforms = get_supported_platforms()
if platforms is None:
# 返回配置文件中的平台列表(用户的默认配置)
return supported_platforms if supported_platforms else []
# 支持字符串形式的列表输入(某些 MCP 客户端会将 JSON 数组序列化为字符串)
if isinstance(platforms, str):
platforms = _parse_string_to_list(platforms)
if not platforms:
# 空字符串或解析后为空,使用默认平台
return supported_platforms if supported_platforms else []
if not isinstance(platforms, list):
raise InvalidParameterError("platforms 参数必须是列表类型")
if not platforms:
# 空列表时,返回配置文件中的平台列表
return supported_platforms if supported_platforms else []
# 如果配置加载失败(supported_platforms为空),允许所有平台通过
if not supported_platforms:
print("警告:平台配置未加载,跳过平台验证")
return platforms
# 验证每个平台是否在配置中
invalid_platforms = [p for p in platforms if p not in supported_platforms]
if invalid_platforms:
raise InvalidParameterError(
f"不支持的平台: {', '.join(invalid_platforms)}",
suggestion=f"支持的平台(来自config.yaml): {', '.join(supported_platforms)}"
)
View on GitHub (pinned to 8ee26026ba)
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
Example fix
// before
{"platforms": "weibo"}
// after
{"platforms": ["weibo"]} Defensive patterns
Strategy: type-guard
Validate before calling
if (typeof platforms === 'string') {
try { platforms = JSON.parse(platforms); } catch { /* not JSON */ }
}
if (!Array.isArray(platforms)) platforms = undefined; // let server use defaults Type guard
function isPlatformList(v: unknown): v is string[] {
if (typeof v === 'string') {
try { return Array.isArray(JSON.parse(v)); } catch { return false; }
}
return Array.isArray(v) && v.every(p => typeof p === 'string');
} Try / catch
try { call({ platforms }); }
catch (e) {
if (/platforms 参数必须是列表类型/.test(e.message)) call({ platforms: undefined });
else throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- INVALID_PARAMETER
- 无法识别的日期表达式: {expression}
- 不支持的平台: {', '.join(invalid_platforms)}
- keyword 长度不能超过100个字符
- mode 必须是字符串类型
AI-assisted analysis of sansan0/TrendRadar@8ee26026ba (2026-08-15).
Data as JSON: /api/errors/a07b93ec15ec8254.
Report an issue: GitHub.