farion1231/cc-switch · error · Error
不支持的 MCP 服务器类型
Error message
不支持的 MCP 服务器类型: ${type} What it means
normalizeServerConfig only knows three types — stdio, http, sse — and any other value for type falls into the final throw '不支持的 MCP 服务器类型: <type>'. The comparison is exact and case-sensitive, and type defaults to stdio when absent, so this fires only when an explicit unrecognized value is present.
Solutions
- Use one of stdio | http | sse, lowercase, as the type value
- For streamable-http servers, try type = "http" if the endpoint is compatible
- Omit the type key entirely for local-process servers to get the stdio default
Example fix
# before type = "streamable-http" # after type = "http" url = "https://example.com/mcp"
Defensive patterns
Strategy: type-guard
Validate before calling
const SUPPORTED = new Set(['stdio', 'http', 'sse']);
const type = (first?.type as string) || 'stdio';
if (!SUPPORTED.has(type)) {
// show "type must be stdio | http | sse" before importing
} Type guard
const SUPPORTED_MCP_TYPES: ReadonlySet<string> = new Set(['stdio', 'http', 'sse']);
function isSupportedMcpServerType(value: unknown): value is 'stdio' | 'http' | 'sse' {
return typeof value === 'string' && SUPPORTED_MCP_TYPES.has(value);
} Try / catch
try {
const server = tomlToMcpServer(tomlText);
} catch (error) {
if (error instanceof Error && error.message.startsWith('不支持的 MCP 服务器类型')) {
// hint the supported set and lowercase requirement
} else {
throw error;
}
} Prevention
- Write type values lowercase and from the supported set
- Map ws://→http transport names before pasting
- Omit type for stdio servers to use the default
When it happens
Trigger: type = "websocket", type = "WebSocket" (case mismatch), type = "streamable-http", or any string outside {stdio, http, sse}.
Common situations: Newer MCP transport names pasted from other tools' configs; capitalized type values; typos like 'ss3' or 'http2'.
Related errors
- TOML 内容不能为空
- 服务器配置必须是对象
- stdio 类型的 MCP 服务器必须包含 command 字段
- 无法识别的 TOML 格式。请提供单个 MCP 服务器配置,或使用
- 类型的 MCP 服务器必须包含 url 字段
AI-assisted analysis of farion1231/cc-switch@0b5da51016 (2026-08-20).
Data as JSON: /api/errors/a2280abd4411ed9f.
Report an issue: GitHub.
Appendix: 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 0b5da51016)