{"record":{"id":"28439b145c7d7f15","repo":"Hmbown/CodeWhale","slug":"invalid-json-payload-at-key-mcp-server-definition","errorCode":null,"errorMessage":"invalid JSON payload at key {MCP_SERVER_DEFINITIONS_KEY}; contents were omitted","messagePattern":"invalid JSON payload at key (.+?); contents were omitted","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/cli/src/lib.rs","lineNumber":5185,"sourceCode":"\n    match parse_mcp_server_definitions(&raw) {\n        Ok(definitions) => definitions,\n        Err(err) => {\n            eprintln!(\n                \"warning: failed to parse persisted MCP server definitions ({MCP_SERVER_DEFINITIONS_KEY}): {err}\"\n            );\n            Vec::new()\n        }\n    }\n}\n\nfn parse_mcp_server_definitions(raw: &str) -> Result<Vec<McpServerDefinition>> {\n    if let Ok(parsed) = serde_json::from_str::<Vec<McpServerDefinition>>(raw) {\n        return Ok(parsed);\n    }\n\n    let unwrapped: String = serde_json::from_str(raw).map_err(|_| {\n        anyhow!(\"invalid JSON payload at key {MCP_SERVER_DEFINITIONS_KEY}; contents were omitted\")\n    })?;\n    serde_json::from_str::<Vec<McpServerDefinition>>(&unwrapped).map_err(|_| {\n        anyhow!(\n            \"invalid MCP server definition list in key {MCP_SERVER_DEFINITIONS_KEY}; contents were omitted\"\n        )\n    })\n}\n\nfn persist_mcp_server_definitions(\n    store: &mut ConfigStore,\n    definitions: &[McpServerDefinition],\n) -> Result<()> {\n    let encoded =\n        serde_json::to_string(definitions).context(\"failed to encode MCP server definitions\")?;\n    store\n        .config\n        .set_value(MCP_SERVER_DEFINITIONS_KEY, &encoded)?;\n    store.save()","sourceCodeStart":5167,"sourceCodeEnd":5203,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/cli/src/lib.rs#L5167-L5203","documentation":"parse_mcp_server_definitions reads the MCP server definitions key and expects either a JSON array of definitions or a JSON string that unwraps to such an array. If the raw value is not valid JSON at all (and also not a JSON string), this error is thrown. Payload contents are deliberately omitted to avoid leaking secrets that may be embedded in the config value.","triggerScenarios":"The config value at MCP_SERVER_DEFINITIONS_KEY is malformed JSON — e.g. truncated file, hand-edited config with a missing brace or quote, or a value written by a tool that escaped it incorrectly.","commonSituations":"Manual editing of the CLI config/state store, an interrupted write leaving partial JSON, or pasting a definition list with shell quoting that mangled it.","solutions":["Validate the JSON at MCP_SERVER_DEFINITIONS_KEY with a JSON linter or `jq .` before launching.","Re-write the key with a proper JSON array of McpServerDefinition objects, e.g. `[{\"name\":\"...\",...}]`.","Restore the config from backup or re-create the MCP server definitions.","If the value should be a wrapped string, ensure it is a valid JSON string literal (double quotes, escaped content)."],"exampleFix":"// before (invalid)\nMCP_SERVER_DEFINITIONS = [{name: \"fs\"}]\n// after\nMCP_SERVER_DEFINITIONS = [{\"name\":\"fs\"}]","handlingStrategy":"validation","validationCode":"// validate the raw value parses before use\nJSON.parse(raw); // throws early with a clear position if invalid","typeGuard":null,"tryCatchPattern":"try {\n  let defs = JSON.parse(raw);\n} catch (e) {\n  console.error(`MCP server definitions at ${key} are not valid JSON: ${e.message}`);\n}","preventionTips":["Always edit MCP definitions through the CLI command, not by hand.","Run `jq .` on the config file after manual edits.","Keep config writes atomic (write temp file + rename).","Back up the config before upgrades."],"tags":["json","mcp","config","validation"],"backgroundTag":"json-parse-error","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}