xai-org/grok-build · error
Invalid environment variable format: '{pair}'. Environment v
Error message
Invalid environment variable format: '{pair}'. Environment variables should be added as: -e KEY1=value1 -e KEY2=value2 What it means
`parse_env_vars` requires every -e value to be a KEY=value pair with a non-empty key. Any pair lacking an `=` or with an empty key is rejected with this message, which restates the correct per-flag syntax.
Source
Thrown at crates/codegen/xai-grok-pager/src/mcp_cmd.rs:442
|| !name
.chars()
.all(|c| c.is_ascii_alphanumeric() || c == '-' || c == '_')
{
bail!(
"Invalid name '{name}'. Names can only contain letters, numbers, hyphens, and underscores."
);
}
Ok(())
}
fn parse_env_vars(pairs: &[String]) -> Result<HashMap<String, String>> {
let mut env = HashMap::new();
for pair in pairs {
match pair.split_once('=') {
Some((key, value)) if !key.is_empty() => {
env.insert(key.to_string(), value.to_string());
}
_ => bail!(
"Invalid environment variable format: '{pair}'. Environment variables should be added as: -e KEY1=value1 -e KEY2=value2"
),
}
}
Ok(env)
}
fn parse_headers(headers: &[String]) -> Result<HashMap<String, String>> {
let mut parsed = HashMap::new();
for header in headers {
let Some((name, value)) = header.split_once(':') else {
bail!("Invalid header format: '{header}'. Expected format: 'Name: value'");
};
let name = name.trim();
if name.is_empty() {
bail!("Invalid header: '{header}'. Header name cannot be empty.");
}
parsed.insert(name.to_string(), value.trim().to_string());View on GitHub (pinned to bc7f02eddd)
Solutions
- Quote each pair: -e "KEY=value with spaces".
- Use one -e flag per variable: -e A=1 -e B=2.
- Ensure each pair contains '=' with a non-empty key before the equals sign.
Example fix
// before grok mcp add fs -e LOG_LEVEL -- npx server-fs // after grok mcp add fs -e LOG_LEVEL=debug -- npx server-fs
Defensive patterns
Strategy: validation
Validate before calling
for pair in env_pairs {
match pair.split_once('=') {
Some((k, _)) if !k.is_empty() => {}
_ => panic!("'{pair}' is not KEY=value; use one -e flag per variable"),
}
} Prevention
- Quote values containing spaces.
- One -e flag per variable, always with KEY=value.
- Never pass bare variable names to -e.
When it happens
Trigger: `-e KEY` (no =value), `-e =value` (empty key), or an unquoted value containing spaces that split into multiple args like `-e KEY=hello world`.
Common situations: Shell splitting of unquoted values with spaces, assuming -e is greedy and accepts multiple pairs (`-e A=1 B=2`), passing bare variable names expecting the parent environment to be forwarded.
Related errors
- Invalid command '{command}': it looks like an environment va
- --env can only be used with stdio servers.
- Invalid header format: '{header}'. Expected format: 'Name: v
- --header can only be used with HTTP or SSE servers.
- A URL is required for {label} servers. Usage: grok mcp add -
AI-assisted analysis of xai-org/grok-build@bc7f02eddd (2026-08-31).
Data as JSON: /api/errors/b6898bf7006fa83e.
Report an issue: GitHub.