{"record":{"id":"4d9c9ec7dcfbf625","repo":"farion1231/cc-switch","slug":"type-mcp-url","errorCode":null,"errorMessage":"${type} 类型的 MCP 服务器必须包含 url 字段","messagePattern":"(.+?) 类型的 MCP 服务器必须包含 url 字段","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/utils/tomlUtils.ts","lineNumber":151,"sourceCode":"      server.env = env;\n      knownFields.add(\"env\");\n    }\n    if (config.cwd && typeof config.cwd === \"string\") {\n      server.cwd = config.cwd;\n      knownFields.add(\"cwd\");\n    }\n\n    // 保留所有未知字段（如 timeout_ms 等扩展字段）\n    for (const key of Object.keys(config)) {\n      if (!knownFields.has(key)) {\n        server[key] = config[key];\n      }\n    }\n\n    return server;\n  } else if (type === \"http\" || type === \"sse\") {\n    if (!config.url || typeof config.url !== \"string\") {\n      throw new Error(`${type} 类型的 MCP 服务器必须包含 url 字段`);\n    }\n\n    const server: McpServerSpec = {\n      type: type as \"http\" | \"sse\",\n      url: config.url,\n    };\n    knownFields.add(\"type\");\n    knownFields.add(\"url\");\n\n    // 可选字段\n    if (config.headers && typeof config.headers === \"object\") {\n      const headers: Record<string, string> = {};\n      for (const [k, v] of Object.entries(config.headers)) {\n        headers[k] = String(v);\n      }\n      server.headers = headers;\n      knownFields.add(\"headers\");\n    }","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/farion1231/cc-switch/blob/0b5da510168914b251481654a568c3ffacd62cf4/src/utils/tomlUtils.ts#L133-L169","documentation":"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.","triggerScenarios":"Pasting 'type = \"http\"' with command/args but no url, or with url empty or a non-string value.","commonSituations":"Switching a stdio config to http by editing only the type line; url key typo (Url, endpoint); url left empty when templating configs.","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"],"exampleFix":"# before\n[mcp_servers.remote]\ntype = \"http\"\ncommand = \"serve\"\n\n# after\n[mcp_servers.remote]\ntype = \"http\"\nurl = \"https://mcp.example.com/sse\"","handlingStrategy":"validation","validationCode":"const type = (first?.type as string) || 'stdio';\nif ((type === 'http' || type === 'sse') && (typeof first?.url !== 'string' || !first.url)) {\n  // show \"<type> server needs a url\" before importing\n}","typeGuard":null,"tryCatchPattern":"try {\n  const server = tomlToMcpServer(tomlText);\n} catch (error) {\n  if (error instanceof Error && error.message.includes('必须包含 url 字段')) {\n    // highlight the url field guidance\n  } else {\n    throw error;\n  }\n}","preventionTips":["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"],"tags":["toml","mcp","http","sse","required-field"],"backgroundTag":"missing-required-argument","analyzedSha":"0b5da510168914b251481654a568c3ffacd62cf4","analyzedAt":"2026-08-20T14:29:00.113Z","contentChangedAt":"2026-08-20T14:29:00.113Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}