{"record":{"id":"817605ada5bb1dfd","repo":"farion1231/cc-switch","slug":"toml-mcp-mcp-servers-id","errorCode":null,"errorMessage":"无法识别的 TOML 格式。请提供单个 MCP 服务器配置，或使用 [mcp_servers.<id>] 格式","messagePattern":"无法识别的 TOML 格式。请提供单个 MCP 服务器配置，或使用 \\[mcp_servers\\.<id>\\] 格式","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/utils/tomlUtils.ts","lineNumber":92,"sourceCode":"    if (serverIds.length > 0) {\n      const firstServer = (parsed.mcp_servers as any)[serverIds[0]];\n      return normalizeServerConfig(firstServer);\n    }\n  }\n\n  // 情况 3: [mcp.servers.<id>] 错误格式（容错解析）\n  if (parsed.mcp && typeof parsed.mcp === \"object\") {\n    const mcpObj = parsed.mcp as any;\n    if (mcpObj.servers && typeof mcpObj.servers === \"object\") {\n      const serverIds = Object.keys(mcpObj.servers);\n      if (serverIds.length > 0) {\n        const firstServer = mcpObj.servers[serverIds[0]];\n        return normalizeServerConfig(firstServer);\n      }\n    }\n  }\n\n  throw new Error(\n    \"无法识别的 TOML 格式。请提供单个 MCP 服务器配置，或使用 [mcp_servers.<id>] 格式\",\n  );\n};\n\n/**\n * 规范化服务器配置对象为 McpServer 格式\n * 保留所有字段（包括扩展字段如 timeout_ms）\n */\nfunction normalizeServerConfig(config: any): McpServerSpec {\n  if (!config || typeof config !== \"object\") {\n    throw new Error(\"服务器配置必须是对象\");\n  }\n\n  const type = (config.type as string) || \"stdio\";\n\n  // 已知字段列表（用于后续排除）\n  const knownFields = new Set<string>();\n","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/farion1231/cc-switch/blob/0b5da510168914b251481654a568c3ffacd62cf4/src/utils/tomlUtils.ts#L74-L110","documentation":"After parsing, tomlToMcpServer tries three shapes in order: a direct server config (type/command/url/args/env at the top level), a [mcp_servers.<id>] table (first server wins), and the tolerated-but-wrong [mcp.servers.<id>] form. '无法识别的 TOML 格式...' is the terminal throw when none match — the TOML parsed successfully but contains no recognizable MCP server stanzas.","triggerScenarios":"Pasting a settings file whose server sits under a different table (e.g. [tools.mcp.x]), a document with only unrelated top-level keys, or an [mcp_servers] table that is empty.","commonSituations":"Copying a whole config.toml from another app that uses a different section name; the real entry commented out so the table is empty; config schema drift between tool versions.","solutions":["Wrap the server under [mcp_servers.<id>] — the recommended format this parser looks for first","Or paste only the server's own keys (command = '...', args = [...]) at the top level","Preview with extractIdFromToml to confirm the parser can see the table before importing"],"exampleFix":"# before\ncat = \"meow\"\nowner = \"dev\"\n\n# after\n[mcp_servers.fetch]\ntype = \"stdio\"\ncommand = \"uvx\"\nargs = [\"mcp-server-fetch\"]","handlingStrategy":"validation","validationCode":"const parsed = parseToml(normalizeTomlText(tomlText));\nconst recognizable =\n  Boolean(parsed.type || parsed.command || parsed.url || parsed.args || parsed.env) ||\n  Object.keys(parsed.mcp_servers ?? {}).length > 0 ||\n  Object.keys((parsed.mcp as Record<string, unknown> | undefined)?.servers ?? {}).length > 0;\nif (!recognizable) {\n  // show format guidance before calling tomlToMcpServer\n}","typeGuard":null,"tryCatchPattern":"try {\n  const server = tomlToMcpServer(tomlText);\n} catch (error) {\n  if (error instanceof Error && error.message.includes('无法识别的 TOML 格式')) {\n    // guide the user to [mcp_servers.<id>] format\n  } else {\n    throw error;\n  }\n}","preventionTips":["Recommend the [mcp_servers.<id>] format in the import dialog placeholder","Preview with extractIdFromToml before importing","Keep example snippets next to the textarea"],"tags":["toml","mcp","config-format","import"],"backgroundTag":"unrecognized-config-format","analyzedSha":"0b5da510168914b251481654a568c3ffacd62cf4","analyzedAt":"2026-08-20T14:29:00.113Z","contentChangedAt":"2026-08-20T14:29:00.113Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}