farion1231/cc-switch · warning · Error

不支持的 MCP 服务器类型: ${type}

Error message

不支持的 MCP 服务器类型: ${type}

What it means

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.

Source

Thrown at src/utils/tomlUtils.ts:180

    if (config.headers && typeof config.headers === "object") {
      const headers: Record<string, string> = {};
      for (const [k, v] of Object.entries(config.headers)) {
        headers[k] = String(v);
      }
      server.headers = headers;
      knownFields.add("headers");
    }

    // 保留所有未知字段
    for (const key of Object.keys(config)) {
      if (!knownFields.has(key)) {
        server[key] = config[key];
      }
    }

    return server;
  } else {
    throw new Error(`不支持的 MCP 服务器类型: ${type}`);
  }
}

/**
 * 尝试从 TOML 中提取合理的服务器 ID/标题
 * @param tomlText TOML 文本
 * @returns 建议的 ID,失败返回空字符串
 */
export const extractIdFromToml = (tomlText: string): string => {
  try {
    const parsed = parseToml(normalizeTomlText(tomlText));

    // 尝试从 [mcp_servers.<id>] 或 [mcp.servers.<id>] 中提取 ID
    if (parsed.mcp_servers && typeof parsed.mcp_servers === "object") {
      const serverIds = Object.keys(parsed.mcp_servers);
      if (serverIds.length > 0) {
        return serverIds[0];
      }

View on GitHub (pinned to a2e22f3302)

Solutions

  1. Use exactly "stdio", "http", or "sse" (lowercase)
  2. Remove the type line when stdio is intended (it is the default)
  3. If a genuinely new transport is required, extend normalizeServerConfig rather than working around the error

Example fix

# before (throws)
type = "websocket"
url = "https://mcp.example.com/ws"

# after
type = "http"
url = "https://mcp.example.com/mcp"
Defensive patterns

Strategy: validation

Validate before calling

const SUPPORTED_MCP_TYPES = new Set(["stdio", "http", "sse"]);

const declared = typeof entry.type === "string" ? entry.type : "stdio";
if (!SUPPORTED_MCP_TYPES.has(declared)) {
  setImportError(`Unsupported type "${declared}" - use stdio, http, or sse`);
}

Type guard

function isSupportedMcpType(v: unknown): v is "stdio" | "http" | "sse" {
  return v === "stdio" || v === "http" || v === "sse";
}

Try / catch

try {
  const server = tomlToMcpServer(tomlText);
} catch (e) {
  if (e instanceof Error && e.message.includes("不支持的 MCP 服务器类型")) {
    setImportError("Only stdio, http, and sse (lowercase) are supported");
  } else {
    throw e;
  }
}

Prevention

When it happens

Trigger: type = "websocket", "ws", "streamable-http", or "Stdio" (capitalized) - anything outside the exact lowercase set {stdio, http, sse}.

Common situations: 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.

Related errors


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