{"record":{"id":"14b2df91e57f92d1","repo":"Hmbown/CodeWhale","slug":"mcp-config-exceeds-the-1-mib-limit-14b2df","errorCode":null,"errorMessage":"MCP config exceeds the 1 MiB limit","messagePattern":"MCP config exceeds the 1 MiB limit","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/mcp.rs","lineNumber":5867,"sourceCode":"        if legacy {\n            let object = raw\n                .as_object_mut()\n                .context(\"MCP config must be an object\")?;\n            let servers = object.remove(\"mcpServers\").expect(\"checked above\");\n            object.insert(\"servers\".into(), servers);\n        }\n        apply_json_delta(&mut raw, &before, &after);\n        if legacy {\n            let object = raw\n                .as_object_mut()\n                .context(\"MCP config must be an object\")?;\n            if let Some(servers) = object.remove(\"servers\") {\n                object.insert(\"mcpServers\".into(), servers);\n            }\n        }\n        let rendered = serde_json::to_string_pretty(&raw)?;\n        if rendered.len() as u64 > MAX_MCP_CONFIG_BYTES {\n            anyhow::bail!(\"MCP config exceeds the 1 MiB limit\");\n        }\n        write_atomic(path, rendered.as_bytes())?;\n        Ok((result, config_revision(Some(&rendered))))\n    })\n}\n\nfn mcp_template_json() -> Result<String> {\n    let mut cfg = McpConfig::default();\n    cfg.servers.insert(\n        \"example\".to_string(),\n        McpServerConfig {\n            command: Some(\"node\".to_string()),\n            args: vec![\"./path/to/your-mcp-server.js\".to_string()],\n            env: HashMap::new(),\n            cwd: None,\n            url: None,\n            transport: None,\n            connect_timeout: None,","sourceCodeStart":5849,"sourceCodeEnd":5885,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/mcp.rs#L5849-L5885","documentation":"MCP configuration files are capped at 1 MiB (`MAX_MCP_CONFIG_BYTES`). Before atomically writing a mutated config, the library re-serializes it and bails if the rendered JSON would exceed the limit, protecting against unbounded config growth and pathological file sizes.","triggerScenarios":"Calling an MCP config mutation function (add/update server, consent history writes) whose resulting pretty-printed JSON exceeds 1,048,576 bytes on write (crates/tui/src/mcp.rs:5867).","commonSituations":"Adding hundreds of MCP servers to one config; pasting very large env var blobs or long argument lists into a server entry; a sync tool duplicating entries on every run until the file balloons.","solutions":["Remove unused or duplicate MCP server entries to shrink the config","Move large data (long args, big env payloads) out of the config — e.g. into scripts or environment files referenced by name","Split servers across project vs user scope configs instead of one file","If the config was already over the limit, hand-edit the file to a valid subset before re-running mutations"],"exampleFix":"// before\n\"env\": {\"BIG_BLOB\": \"<2 MB of inline data>\"}\n// after\n\"env\": {\"BIG_BLOB_FILE\": \"./blobs/big.txt\"} // keep the payload out of mcp.json","handlingStrategy":"validation","validationCode":"const MAX_MCP_CONFIG_BYTES: u64 = 1_048_576;\nlet rendered = serde_json::to_string_pretty(&raw)?;\nif rendered.len() as u64 > MAX_MCP_CONFIG_BYTES {\n    eprintln!(\"config too large: {} bytes\", rendered.len());\n}","typeGuard":null,"tryCatchPattern":"match mutate_config(path, None, edit) {\n    Ok(r) => r,\n    Err(e) if e.to_string().contains(\"1 MiB limit\") => {\n        prune_unused_servers(&mut cfg)?;\n        mutate_config(path, None, |_| Ok(pruned)) // retry after shrinking\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Keep env blobs and long args out of mcp.json","Periodically prune unused server entries","Monitor rendered config size in scripts that batch-add servers"],"tags":["mcp","config","limit","file-size"],"backgroundTag":"file-size-limit-exceeded","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"}