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
- Use exactly "stdio", "http", or "sse" (lowercase)
- Remove the type line when stdio is intended (it is the default)
- 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
- Use the exact lowercase literals stdio/http/sse
- Omit type when stdio is intended (it is the default)
- Watch for autocapitalization when hand-editing type values
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
- TOML 内容不能为空
- stdio 类型的 MCP 服务器必须包含 command 字段
- ${type} 类型的 MCP 服务器必须包含 url 字段
- 无法识别的 TOML 格式。请提供单个 MCP 服务器配置,或使用 [mcp_servers.<id>] 格式
- 服务器配置必须是对象
AI-assisted analysis of farion1231/cc-switch@a2e22f3302 (2026-08-16).
Data as JSON: /api/errors/a2280abd4411ed9f.
Report an issue: GitHub.