{"record":{"id":"3d6373df9d132e7e","repo":"Hmbown/CodeWhale","slug":"unterminated-environment-placeholder-in-mcp-config","errorCode":null,"errorMessage":"unterminated environment placeholder in MCP config value","messagePattern":"unterminated environment placeholder in MCP config value","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/mcp.rs","lineNumber":87,"sourceCode":"/// Expand `${NAME}` placeholders in an MCP config value from the process\n/// environment. This lets secrets (API keys, bearer tokens, …) be supplied\n/// through environment variables instead of being written in cleartext into\n/// the MCP config file on disk.\n///\n/// On a missing or malformed placeholder the error names only the offending\n/// variable, never the surrounding value, so a secret-bearing string is never\n/// echoed into logs or error output.\nfn expand_env_placeholders_with(\n    value: &str,\n    environment: Option<&crate::plugins::HostEnvironment>,\n) -> Result<String> {\n    let mut out = String::new();\n    let mut rest = value;\n    while let Some(start) = rest.find(\"${\") {\n        out.push_str(&rest[..start]);\n        let after = &rest[start + 2..];\n        let Some(end) = after.find('}') else {\n            anyhow::bail!(\"unterminated environment placeholder in MCP config value\");\n        };\n        let name = &after[..end];\n        if name.is_empty() || !name.chars().all(|c| c.is_ascii_alphanumeric() || c == '_') {\n            anyhow::bail!(\"invalid environment placeholder in MCP config value\");\n        }\n        let env_value = environment\n            .map_or_else(|| std::env::var(name), |env| env.var(name))\n            .with_context(|| {\n                format!(\"environment variable {name} required by MCP config is not set\")\n            })?;\n        out.push_str(&env_value);\n        rest = &after[end + 1..];\n    }\n    out.push_str(rest);\n    Ok(out)\n}\n\n#[cfg(test)]","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/mcp.rs#L69-L105","documentation":"MCP config values support `${NAME}` environment-variable placeholders. expand_env_placeholders_with scans each value and bails when it finds `${` with no closing `}` — an unterminated placeholder would otherwise be silently passed through as literal text.","triggerScenarios":"An MCP config value containing `${VAR` without a closing brace, e.g. \"Bearer ${API_KEY\" or a value with a stray `${` in a URL; JSON editing that accidentally deleted the closing brace; shell escaping leaving a literal `${` behind.","commonSituations":"Hand-editing mcp.json and dropping the brace; copy-pasting shell snippets where `${VAR}` was meant for the shell, not the config; config generators that truncate values.","solutions":["Add the missing `}` to close the placeholder: ${VAR}","If a literal `${` is intended, escape or restructure the value so it does not parse as a placeholder","Validate the JSON config values with a quick check for balanced `${`...`}` pairs before loading"],"exampleFix":"// before\n\"header\": \"Bearer ${API_KEY\"\n// after\n\"header\": \"Bearer ${API_KEY}\"","handlingStrategy":"validation","validationCode":"function checkPlaceholders(v) {\n  let i = 0;\n  while ((i = v.indexOf(\"${\", i)) !== -1) {\n    const end = v.indexOf(\"}\", i);\n    if (end === -1) throw new Error(`unterminated placeholder in: ${v}`);\n    i = end + 1;\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  loadMcpConfig(cfg);\n} catch (e) {\n  if (String(e).includes(\"unterminated environment placeholder\")) {\n    // point user at the offending value; check balanced ${...} pairs\n  }\n}","preventionTips":["Lint MCP config values for balanced ${...} pairs in CI","Distinguish shell interpolation (done before writing config) from config placeholders (done at load)","Quote ${ sequences intended literally or avoid them in values"],"tags":["mcp","config","env-placeholder"],"backgroundTag":"invalid-config-value","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"}