farion1231/cc-switch · error · Error
类型的 MCP 服务器必须包含 url 字段
Error message
${type} 类型的 MCP 服务器必须包含 url 字段 What it means
The remote-server counterpart of the command check: when type is 'http' or 'sse', normalizeServerConfig requires a url field that is a non-empty string ('<type> 类型的 MCP 服务器必须包含 url 字段'). Remote MCP servers are addressed by URL, and headers are copied only afterwards, so a missing url aborts before any transport config is built.
Solutions
- Add url = "https://host/path" to the http/sse server block
- If the server is a local process, remove type (or set stdio) and provide command instead
- Verify the key is exactly lowercase url and holds a string
Example fix
# before [mcp_servers.remote] type = "http" command = "serve" # after [mcp_servers.remote] type = "http" url = "https://mcp.example.com/sse"
Defensive patterns
Strategy: validation
Validate before calling
const type = (first?.type as string) || 'stdio';
if ((type === 'http' || type === 'sse') && (typeof first?.url !== 'string' || !first.url)) {
// show "<type> server needs a url" before importing
} Try / catch
try {
const server = tomlToMcpServer(tomlText);
} catch (error) {
if (error instanceof Error && error.message.includes('必须包含 url 字段')) {
// highlight the url field guidance
} else {
throw error;
}
} Prevention
- When changing type to http/sse, add url in the same edit
- Use the exact lowercase key 'url' holding a string
- Keep transport and address fields together in snippets
When it happens
Trigger: Pasting 'type = "http"' with command/args but no url, or with url empty or a non-string value.
Common situations: Switching a stdio config to http by editing only the type line; url key typo (Url, endpoint); url left empty when templating configs.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- stdio 类型的 MCP 服务器必须包含 command 字段
- 服务器配置必须是对象
- 不支持的 MCP 服务器类型
- TOML 内容不能为空
- 无法识别的 TOML 格式。请提供单个 MCP 服务器配置,或使用
AI-assisted analysis of farion1231/cc-switch@0b5da51016 (2026-08-20).
Data as JSON: /api/errors/4d9c9ec7dcfbf625.
Report an issue: GitHub.
Appendix: 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 0b5da51016)