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
- Add url = "https://mcp.example.com/..." to the entry
- Check the spelling and case of the url key
- 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
- Pair every type = "http"/"sse" line with a url line
- TOML keys are case-sensitive - write url, not URL or Url
- Drop the type line for local stdio servers instead of leaving a typeless remote entry
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
- TOML 内容不能为空
- stdio 类型的 MCP 服务器必须包含 command 字段
- 不支持的 MCP 服务器类型: ${type}
- 无法识别的 TOML 格式。请提供单个 MCP 服务器配置,或使用 [mcp_servers.<id>] 格式
- 服务器配置必须是对象
AI-assisted analysis of farion1231/cc-switch@a2e22f3302 (2026-08-16).
Data as JSON: /api/errors/4d9c9ec7dcfbf625.
Report an issue: GitHub.