farion1231/cc-switch · warning · Error

无法识别的 TOML 格式。请提供单个 MCP 服务器配置,或使用 [mcp_servers.<id>] 格式

Error message

无法识别的 TOML 格式。请提供单个 MCP 服务器配置,或使用 [mcp_servers.<id>] 格式

What it means

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.

Source

Thrown at src/utils/tomlUtils.ts:92

    if (serverIds.length > 0) {
      const firstServer = (parsed.mcp_servers as any)[serverIds[0]];
      return normalizeServerConfig(firstServer);
    }
  }

  // 情况 3: [mcp.servers.<id>] 错误格式(容错解析)
  if (parsed.mcp && typeof parsed.mcp === "object") {
    const mcpObj = parsed.mcp as any;
    if (mcpObj.servers && typeof mcpObj.servers === "object") {
      const serverIds = Object.keys(mcpObj.servers);
      if (serverIds.length > 0) {
        const firstServer = mcpObj.servers[serverIds[0]];
        return normalizeServerConfig(firstServer);
      }
    }
  }

  throw new Error(
    "无法识别的 TOML 格式。请提供单个 MCP 服务器配置,或使用 [mcp_servers.<id>] 格式",
  );
};

/**
 * 规范化服务器配置对象为 McpServer 格式
 * 保留所有字段(包括扩展字段如 timeout_ms)
 */
function normalizeServerConfig(config: any): McpServerSpec {
  if (!config || typeof config !== "object") {
    throw new Error("服务器配置必须是对象");
  }

  const type = (config.type as string) || "stdio";

  // 已知字段列表(用于后续排除)
  const knownFields = new Set<string>();

View on GitHub (pinned to a2e22f3302)

Solutions

  1. Wrap the server fields under a [mcp_servers.my-server] header
  2. Paste only a single server's fields, not the whole app config
  3. Check the table header spelling - the id segment is required

Example fix

# before (throws)
title = "my config"
[tools]
edit = true

# after
[mcp_servers.my-server]
command = "npx"
args = ["-y", "@modelcontextprotocol/server-filesystem"]
Defensive patterns

Strategy: try-catch

Try / catch

try {
  const server = tomlToMcpServer(tomlText);
} catch (e) {
  if (e instanceof Error && e.message.includes("无法识别的 TOML 格式")) {
    setImportError("Use a single server config or a [mcp_servers.<id>] table");
  } else {
    throw e;
  }
}

Prevention

When it happens

Trigger: tomlToMcpServer('name = "x"') (scalar-only top level), ('[tools]\nedit = true') (unrelated table), or a [mcp_servers] header written without the .<id> suffix.

Common situations: Pasting an entire app settings.toml instead of one server block; pasting config for a different tool; table header typo dropping the server id.

Related errors


AI-assisted analysis of farion1231/cc-switch@a2e22f3302 (2026-08-16). Data as JSON: /api/errors/817605ada5bb1dfd. Report an issue: GitHub.