{"record":{"id":"1ada6116dc085e0d","repo":"Hmbown/CodeWhale","slug":"invalid-environment-placeholder-in-mcp-config-valu","errorCode":null,"errorMessage":"invalid environment placeholder in MCP config value","messagePattern":"invalid environment placeholder in MCP config value","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/mcp.rs","lineNumber":91,"sourceCode":"///\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)]\nfn expand_env_placeholders(value: &str) -> Result<String> {\n    expand_env_placeholders_with(value, None)\n}\n","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/mcp.rs#L73-L109","documentation":"`${NAME}` placeholders in MCP config values allow only non-empty names of ASCII alphanumerics and underscores. expand_env_placeholders_with bails when the name between `${` and `}` is empty or contains any other character (hyphens, dots, spaces, non-ASCII).","triggerScenarios":"Placeholders like ${}, ${MY-VAR} (hyphen), ${my.var} (dot), ${VAR NAME} (space), or ${K8S_NAMESPACE/KEY} in any MCP config value string.","commonSituations":"Using kebab-case environment variable conventions (e.g. ${OPENAI-API-KEY}) that the grammar rejects; nested or composite references like ${A.B}; accidentally leaving ${} from an unfilled template.","solutions":["Rename the placeholder to ASCII letters, digits, and underscores only (e.g. ${OPENAI_API_KEY})","If the environment variable itself has hyphens (unusual), expose an underscore-aliased variable","Remove empty `${}` occurrences left by templates"],"exampleFix":"// before\n\"token\": \"${MY-API-KEY}\"\n// after\n\"token\": \"${MY_API_KEY}\"","handlingStrategy":"validation","validationCode":"const valid = /^\\$\\{[A-Za-z0-9_]+\\}$/.test(placeholder) ||\n  [...value.matchAll(/\\$\\{([^}]*)\\}/g)].every(([, n]) => /^[A-Za-z0-9_]+$/.test(n));\nif (!valid) throw new Error(`placeholder name in \"${value}\" must match [A-Za-z0-9_]+`);","typeGuard":null,"tryCatchPattern":"try {\n  loadMcpConfig(cfg);\n} catch (e) {\n  if (String(e).includes(\"invalid environment placeholder\")) {\n    // rename offending placeholder to snake_case and retry\n  }\n}","preventionTips":["Use UPPER_SNAKE_CASE names for all env placeholders in configs","Run a config linter that enforces /^[A-Za-z0-9_]+$/ on placeholder names","Provide underscore aliases for env vars that use hyphens or dots"],"tags":["mcp","config","env-placeholder"],"backgroundTag":"invalid-identifier-format","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"}