{"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":"warning","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/a2e22f330273a5b6ffa87cb8b82b624601bac562/src/utils/tomlUtils.ts#L74-L110","documentation":"Thrown when the TOML parses but matches none of the three accepted shapes: direct server fields at the top level (type/command/url/args/env), a [mcp_servers.<id>] table, or the tolerated [mcp.servers.<id>] misspelling. The message ('Unrecognized TOML format...') tells the user the two supported forms.","triggerScenarios":"tomlToMcpServer('name = \"x\"') (scalar-only top level), ('[tools]\\nedit = true') (unrelated table), or a [mcp_servers] header written without the .<id> suffix.","commonSituations":"Pasting an entire app settings.toml instead of one server block; pasting config for a different tool; table header typo dropping the server id.","solutions":["Wrap the server fields under a [mcp_servers.my-server] header","Paste only a single server's fields, not the whole app config","Check the table header spelling - the id segment is required"],"exampleFix":"# before (throws)\ntitle = \"my config\"\n[tools]\nedit = true\n\n# after\n[mcp_servers.my-server]\ncommand = \"npx\"\nargs = [\"-y\", \"@modelcontextprotocol/server-filesystem\"]","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const server = tomlToMcpServer(tomlText);\n} catch (e) {\n  if (e instanceof Error && e.message.includes(\"无法识别的 TOML 格式\")) {\n    setImportError(\"Use a single server config or a [mcp_servers.<id>] table\");\n  } else {\n    throw e;\n  }\n}","preventionTips":["Import one server block at a time, never a whole app config file","Use the [mcp_servers.<id>] header format as the default authoring style","Show the accepted-format example next to the import textarea"],"tags":["toml","mcp","parsing","import"],"backgroundTag":null,"analyzedSha":"a2e22f330273a5b6ffa87cb8b82b624601bac562","analyzedAt":"2026-08-16T03:46:07.889Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}