{"record":{"id":"9d40f7ec854806e7","repo":"xai-org/grok-build","slug":"failed-to-serialize-mcp-server-name-e","errorCode":null,"errorMessage":"failed to serialize MCP server {name}: {e}","messagePattern":"failed to serialize MCP server (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-shell/src/claude_import.rs","lineNumber":987,"sourceCode":"\n/// Merge MCP server configs into `[mcp_servers]`. Existing servers are NOT overwritten.\nfn merge_mcp_servers(\n    table: &mut TomlMap<String, TomlValue>,\n    servers: &[(&str, &McpServerConfig)],\n) -> anyhow::Result<usize> {\n    let mcp = table\n        .entry(\"mcp_servers\")\n        .or_insert_with(|| TomlValue::Table(TomlMap::new()));\n    let mcp_table = mcp\n        .as_table_mut()\n        .ok_or_else(|| anyhow::anyhow!(\"[mcp_servers] is not a table\"))?;\n\n    let mut count = 0;\n    for (name, config) in servers {\n        // Don't overwrite existing server entries.\n        if !mcp_table.contains_key(*name) {\n            let serialized = toml::Value::try_from(*config)\n                .map_err(|e| anyhow::anyhow!(\"failed to serialize MCP server {name}: {e}\"))?;\n            mcp_table.insert(name.to_string(), serialized);\n            count += 1;\n        }\n    }\n    Ok(count)\n}\n\n/// Merge a list of path strings into `[paths] <key>` (an array of strings).\n///\n/// Existing entries are preserved; new entries that aren't already present\n/// are appended. Returns the number of newly added entries.\nfn merge_paths(\n    table: &mut TomlMap<String, TomlValue>,\n    key: &str,\n    new_paths: &[&str],\n) -> anyhow::Result<usize> {\n    let paths = table\n        .entry(\"paths\")","sourceCodeStart":969,"sourceCodeEnd":1005,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-shell/src/claude_import.rs#L969-L1005","documentation":"merge_mcp_servers could not convert a server's JSON config value into a TOML value (toml::Value::try_from failed). TOML cannot represent every JSON shape, e.g. top-level arrays or nulls, so the server entry is rejected rather than written incorrectly.","triggerScenarios":"apply_items_to_config imports an MCP server whose config object contains a null value or another TOML-unsupported shape, causing toml::Value::try_from to fail.","commonSituations":"Claude JSON config has \"env\": null or a null array element; server config with keys TOML cannot map directly.","solutions":["Remove/null-out unsupported values (nulls) in the server's JSON config before importing.","Provide a TOML-compatible object (strings, numbers, booleans, arrays, tables only) for the server config.","Skip the failing server and add its entry manually under [mcp_servers.<name>] in the config."],"exampleFix":"// before (claude_desktop_config.json)\n{ \"mcpServers\": { \"fs\": { \"env\": null } } }\n\n// after\n{ \"mcpServers\": { \"fs\": { \"env\": {} } } }","handlingStrategy":"try-catch","validationCode":"fn toml_compatible(v: &serde_json::Value) -> bool {\n    match v {\n        serde_json::Value::Null => false,\n        serde_json::Value::Array(a) => a.iter().all(toml_compatible),\n        serde_json::Value::Object(o) => o.values().all(toml_compatible),\n        _ => true,\n    }\n}","typeGuard":"fn is_toml_representable(v: &serde_json::Value) -> bool {\n    toml::Value::try_from(v).is_ok()\n}","tryCatchPattern":"match apply_import(items, &path) {\n    Err(e) if e.to_string().contains(\"failed to serialize MCP server\") => {\n        let name = /* extract from message */;\n        eprintln!(\"Server '{name}' has TOML-unsupported values (likely nulls); fix its JSON config\");\n    }\n    r => r?,\n}","preventionTips":["Remove null values from MCP server JSON configs before importing (use empty objects/maps instead).","Pre-sanitize JSON with a TOML-representability check.","Prefer skipping/normalizing problematic servers instead of failing the whole import."],"tags":["toml","config","serialization","mcp"],"backgroundTag":"json-to-toml-serialization","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}