{"record":{"id":"b2402d2204604dc9","repo":"Hmbown/CodeWhale","slug":"failed-to-render-mcp-template-json-e","errorCode":null,"errorMessage":"Failed to render MCP template JSON: {e}","messagePattern":"Failed to render MCP template JSON: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/lib.rs","lineNumber":3562,"sourceCode":"            read_timeout: None,\n            disabled: true,\n            enabled: true,\n            required: false,\n            enabled_tools: Vec::new(),\n            disabled_tools: Vec::new(),\n            headers: std::collections::HashMap::new(),\n            env_headers: std::collections::HashMap::new(),\n            bearer_token_env_var: None,\n            scopes: Vec::new(),\n            oauth: None,\n            oauth_resource: None,\n            reviewed_plugin: None,\n            runtime_added: false,\n            allow_private_network: false,\n        },\n    );\n    serde_json::to_string_pretty(&cfg)\n        .map_err(|e| anyhow!(\"Failed to render MCP template JSON: {e}\"))\n}\n\nfn init_mcp_config(path: &Path, force: bool) -> Result<WriteStatus> {\n    let template = mcp_template_json()?;\n    write_template_file(path, &template, force)\n}\n\nfn skills_template(name: &str) -> String {\n    format!(\n        \"\\\n---\\n\\\nname: {name}\\n\\\ndescription: Quick repo diagnostics and setup guidance\\n\\\nallowed-tools: diagnostics, list_dir, read_file, grep_files, git_status, git_diff\\n\\\n---\\n\\n\\\nWhen this skill is active:\\n\\\n1. Run the diagnostics tool to report workspace and sandbox status.\\n\\\n2. Skim key project files (README.md, Cargo.toml, AGENTS.md) before editing.\\n\\","sourceCodeStart":3544,"sourceCodeEnd":3580,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/crates/tui/src/lib.rs#L3544-L3580","documentation":"Raised by mcp_template_json when serde_json::to_string_pretty fails to serialize the generated MCP configuration template. Serialization of plain config structs should never fail in practice, so this usually indicates an internal problem (e.g. a non-string map key or NaN-like value introduced into the template) rather than user input.","triggerScenarios":"Calling the MCP config initialization path (init_mcp_config / template rendering) where the in-memory McpConfig template contains values serde_json cannot represent (e.g. a map with non-string keys, a float that is not a finite number).","commonSituations":"A code change added a new field to the MCP template struct that is not JSON-serializable; custom serialization of server entries with exotic key types; effectively only reachable after a source-level regression.","solutions":["Report/inspect the newly added template field that breaks serde_json serialization","Ensure all template map keys are strings and no non-finite floats are present","Update or rebuild the binary so template code and serde derives match"],"exampleFix":"// before\nlet servers: HashMap<ServerId, ServerConfig> = ...;\n// after\nlet servers: BTreeMap<String, ServerConfig> = ...;","handlingStrategy":"try-catch","validationCode":"// template is internal; nothing the caller can validate beforehand,\n// but a sanity render test protects against regressions\nlet json = serde_json::to_string_pretty(&cfg)\n    .expect(\"MCP template must remain JSON-serializable\");","typeGuard":null,"tryCatchPattern":"match mcp_template_json() {\n    Err(e) if e.to_string().contains(\"Failed to render MCP template JSON\") => {\n        eprintln!(\"internal template serialization bug: {e}\");\n    }\n    Err(e) => return Err(e),\n    Ok(t) => write_template_file(path, &t, force)?,\n}","preventionTips":["Add a unit test asserting the MCP template serializes after any struct change","Keep template map keys as String and floats finite","Run existing template tests when extending McpConfig fields"],"tags":["serialization","json","mcp","template"],"backgroundTag":"json-serialization-failed","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}