farion1231/cc-switch · warning · Error

${type} 类型的 MCP 服务器必须包含 url 字段

Error message

${type} 类型的 MCP 服务器必须包含 url 字段

What it means

For entries declaring type "http" or "sse", a string url is mandatory ('http/sse MCP server must include url field'). Thrown when the type explicitly selects a remote transport but url is missing, misspelled, or not a string.

Source

Thrown at src/utils/tomlUtils.ts:151

      server.env = env;
      knownFields.add("env");
    }
    if (config.cwd && typeof config.cwd === "string") {
      server.cwd = config.cwd;
      knownFields.add("cwd");
    }

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

    return server;
  } else if (type === "http" || type === "sse") {
    if (!config.url || typeof config.url !== "string") {
      throw new Error(`${type} 类型的 MCP 服务器必须包含 url 字段`);
    }

    const server: McpServerSpec = {
      type: type as "http" | "sse",
      url: config.url,
    };
    knownFields.add("type");
    knownFields.add("url");

    // 可选字段
    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");
    }

View on GitHub (pinned to a2e22f3302)

Solutions

  1. Add url = "https://mcp.example.com/..." to the entry
  2. Check the spelling and case of the url key
  3. Drop the type line if the server is actually a local stdio process

Example fix

# before (throws)
type = "http"
command = "npx"

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

Strategy: validation

Validate before calling

function isRemoteEntry(e: Record<string, unknown>): e is { type: "http" | "sse"; url: string } {
  return (
    (e.type === "http" || e.type === "sse") &&
    typeof e.url === "string" &&
    e.url.length > 0
  );
}

if ((entry.type === "http" || entry.type === "sse") && !isRemoteEntry(entry)) {
  setImportError("http/sse servers must include url");
}

Type guard

function isRemoteEntry(e: Record<string, unknown>): e is { type: "http" | "sse"; url: string } {
  return (
    (e.type === "http" || e.type === "sse") &&
    typeof e.url === "string" &&
    e.url.length > 0
  );
}

Try / catch

try {
  const server = tomlToMcpServer(tomlText);
} catch (e) {
  if (e instanceof Error && e.message.includes("必须包含 url 字段")) {
    setImportError("Add url = \"https://...\" to the http/sse server entry");
  } else {
    throw e;
  }
}

Prevention

When it happens

Trigger: type = "http" with only command/args present; url key misspelled or wrong case (TOML keys are case-sensitive); url set to a non-string value.

Common situations: Converting a stdio config to remote and forgetting the url line; key typo like 'URL =' after hand-editing.

Related errors


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