{"record":{"id":"e5135b506808ed95","repo":"xai-org/grok-build","slug":"invalid-command-command-it-looks-like-an-envi","errorCode":null,"errorMessage":"Invalid command '{command}': it looks like an environment variable. Pass each variable as its own flag: {pairs}","messagePattern":"Invalid command '(.+?)': it looks like an environment variable\\. Pass each variable as its own flag: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-pager/src/mcp_cmd.rs","lineNumber":340,"sourceCode":"        McpTransport::Stdio => {\n            let Some(command) = source else {\n                bail!(\n                    \"A command is required for stdio servers. Usage: grok mcp add <name> -- <command> [args...]\"\n                );\n            };\n            if !args.header.is_empty() {\n                bail!(\"--header can only be used with HTTP or SSE servers.\");\n            }\n            // A KEY=value command means an env pair leaked out of -e, which takes one pair per flag (the old --env was greedy)\n            if looks_like_env_pair(command) {\n                let pairs: Vec<String> = args\n                    .env\n                    .iter()\n                    .map(String::as_str)\n                    .chain([command])\n                    .map(|pair| format!(\"-e {pair}\"))\n                    .collect();\n                bail!(\n                    \"Invalid command '{command}': it looks like an environment variable. Pass each variable as its own flag: {}\",\n                    pairs.join(\" \")\n                );\n            }\n            let env = parse_env_vars(&args.env)?;\n\n            let mut warnings = Vec::new();\n            if !explicit_transport && looks_like_url(command) {\n                // Suggest a command that passes URL validation even when the original lacks a scheme (e.g. localhost:3000).\n                let suggested_url =\n                    if command.starts_with(\"http://\") || command.starts_with(\"https://\") {\n                        command.to_string()\n                    } else {\n                        format!(\"http://{command}\")\n                    };\n                warnings.push(format!(\n                    \"Warning: '{command}' looks like a URL, but it is being added as a stdio command because --transport was not specified.\\nFor a remote server, use: grok mcp add --transport http {} {suggested_url}\",\n                    args.name","sourceCodeStart":322,"sourceCodeEnd":358,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-pager/src/mcp_cmd.rs#L322-L358","documentation":"When the trailing command after `--` looks like a KEY=value environment variable pair, the CLI assumes an env assignment accidentally escaped the greedy/old `-e` parsing and refuses to treat it as the command. It echoes the offending token and suggests re-issuing each pair as its own `-e` flag. This guards against silently launching a bogus executable name.","triggerScenarios":"`grok mcp add <name> -- KEY=value` where the first (or only) token after `--` matches KEY=value shape and the transport is stdio; e.g. the user forgot the actual command or an env var was consumed as the command.","commonSituations":"Older command lines written when `--env` accepted multiple pairs, shell scripts where quoting dropped the real command, pasting `FOO=bar npx ...` style commands where the env prefix was split incorrectly.","solutions":["Pass each environment variable as its own -e flag: -e KEY1=value1 -e KEY2=value2.","Ensure the real executable appears first after `--`, e.g. `-- npx -y pkg` not `-- KEY=value npx -y pkg`.","Inline env vars in the shell instead (`KEY=value grok mcp add ...`) if you meant them for the CLI itself."],"exampleFix":"// before\ngrok mcp add api -- API_KEY=abc node server.js\n// after\ngrok mcp add api -e API_KEY=abc -- node server.js","handlingStrategy":"validation","validationCode":"fn looks_like_env_pair(s: &str) -> bool {\n    match s.split_once('=') { Some((k, _)) => !k.is_empty(), None => false }\n}\nif let Some(cmd) = command { assert!(!looks_like_env_pair(cmd), \"'{cmd}' looks like an env pair; use -e instead\"); }","typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"looks like an environment variable\") => {\n        // re-run with -e flags per the suggested pairs in the message\n    }\n    other => other?,\n}","preventionTips":["Always put the real executable first after `--`.","Use one -e flag per environment variable.","Update old scripts written for the greedy --env syntax."],"tags":["cli","mcp","environment-variables","arguments"],"backgroundTag":"env-var-passed-as-command","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}