{"record":{"id":"a2280abd4411ed9f","repo":"farion1231/cc-switch","slug":"mcp-type","errorCode":null,"errorMessage":"不支持的 MCP 服务器类型: ${type}","messagePattern":"不支持的 MCP 服务器类型: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"src/utils/tomlUtils.ts","lineNumber":180,"sourceCode":"    if (config.headers && typeof config.headers === \"object\") {\n      const headers: Record<string, string> = {};\n      for (const [k, v] of Object.entries(config.headers)) {\n        headers[k] = String(v);\n      }\n      server.headers = headers;\n      knownFields.add(\"headers\");\n    }\n\n    // 保留所有未知字段\n    for (const key of Object.keys(config)) {\n      if (!knownFields.has(key)) {\n        server[key] = config[key];\n      }\n    }\n\n    return server;\n  } else {\n    throw new Error(`不支持的 MCP 服务器类型: ${type}`);\n  }\n}\n\n/**\n * 尝试从 TOML 中提取合理的服务器 ID/标题\n * @param tomlText TOML 文本\n * @returns 建议的 ID，失败返回空字符串\n */\nexport const extractIdFromToml = (tomlText: string): string => {\n  try {\n    const parsed = parseToml(normalizeTomlText(tomlText));\n\n    // 尝试从 [mcp_servers.<id>] 或 [mcp.servers.<id>] 中提取 ID\n    if (parsed.mcp_servers && typeof parsed.mcp_servers === \"object\") {\n      const serverIds = Object.keys(parsed.mcp_servers);\n      if (serverIds.length > 0) {\n        return serverIds[0];\n      }","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/farion1231/cc-switch/blob/a2e22f330273a5b6ffa87cb8b82b624601bac562/src/utils/tomlUtils.ts#L162-L198","documentation":"normalizeServerConfig accepts only stdio, http, and sse. Any other type value ('Unsupported MCP server type: <type>') lands in the else branch - the offending value is echoed back. Type matching is exact and case-sensitive.","triggerScenarios":"type = \"websocket\", \"ws\", \"streamable-http\", or \"Stdio\" (capitalized) - anything outside the exact lowercase set {stdio, http, sse}.","commonSituations":"The MCP ecosystem ships a transport name this parser does not know yet; config authored for a different client that uses other type names; casing typo.","solutions":["Use exactly \"stdio\", \"http\", or \"sse\" (lowercase)","Remove the type line when stdio is intended (it is the default)","If a genuinely new transport is required, extend normalizeServerConfig rather than working around the error"],"exampleFix":"# before (throws)\ntype = \"websocket\"\nurl = \"https://mcp.example.com/ws\"\n\n# after\ntype = \"http\"\nurl = \"https://mcp.example.com/mcp\"","handlingStrategy":"validation","validationCode":"const SUPPORTED_MCP_TYPES = new Set([\"stdio\", \"http\", \"sse\"]);\n\nconst declared = typeof entry.type === \"string\" ? entry.type : \"stdio\";\nif (!SUPPORTED_MCP_TYPES.has(declared)) {\n  setImportError(`Unsupported type \"${declared}\" - use stdio, http, or sse`);\n}","typeGuard":"function isSupportedMcpType(v: unknown): v is \"stdio\" | \"http\" | \"sse\" {\n  return v === \"stdio\" || v === \"http\" || v === \"sse\";\n}","tryCatchPattern":"try {\n  const server = tomlToMcpServer(tomlText);\n} catch (e) {\n  if (e instanceof Error && e.message.includes(\"不支持的 MCP 服务器类型\")) {\n    setImportError(\"Only stdio, http, and sse (lowercase) are supported\");\n  } else {\n    throw e;\n  }\n}","preventionTips":["Use the exact lowercase literals stdio/http/sse","Omit type when stdio is intended (it is the default)","Watch for autocapitalization when hand-editing type values"],"tags":["toml","mcp","validation","compatibility"],"backgroundTag":null,"analyzedSha":"a2e22f330273a5b6ffa87cb8b82b624601bac562","analyzedAt":"2026-08-16T03:46:07.889Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}