alibaba/open-code-review · error
invalid env entry %q: must be in KEY=VALUE format
Error message
invalid env entry %q: must be in KEY=VALUE format
What it means
Raised after the env JSON array parses: each element must be a KEY=VALUE string. An entry with no '=' (idx <= 0 also rejects empty key, i.e. '=VALUE') cannot be turned into an environment variable for the MCP server subprocess, so the setter fails with the offending entry quoted.
Source
Thrown at cmd/opencodereview/config_cmd.go:881
if value == "" {
return fmt.Errorf("MCP server command cannot be empty")
}
entry.Command = value
case "args":
var args []string
if err := json.Unmarshal([]byte(value), &args); err != nil {
return fmt.Errorf("invalid JSON array for %s: %w", key, err)
}
entry.Args = args
case "env":
var env []string
if err := json.Unmarshal([]byte(value), &env); err != nil {
return fmt.Errorf("invalid JSON array for %s: %w", key, err)
}
for _, e := range env {
idx := strings.Index(e, "=")
if idx <= 0 {
return fmt.Errorf("invalid env entry %q: must be in KEY=VALUE format", e)
}
}
entry.Env = env
case "url":
if value == "" {
return fmt.Errorf("MCP server URL cannot be empty")
}
parsed, err := url.Parse(value)
if err != nil {
return fmt.Errorf("invalid MCP server URL %q: %w", value, err)
}
if parsed.Scheme != "http" && parsed.Scheme != "https" {
return fmt.Errorf("MCP server URL must use http or https scheme, got %q", parsed.Scheme)
}
if parsed.Host == "" {
return fmt.Errorf("MCP server URL %q must include a host", value)
}
entry.URL = valueView on GitHub (pinned to 5cf97d0d15)
Solutions
- Write each entry as KEY=VALUE, e.g. '["DEBUG=1"]'
- To pass through an existing variable, read it in the shell first: '["TOKEN='$TOKEN'"]'
- Remove empty or name-only entries from the array
Example fix
// before ocr config set mcp_servers.fs.env '["DEBUG"]' // after ocr config set mcp_servers.fs.env '["DEBUG=1"]'
Defensive patterns
Strategy: validation
Validate before calling
for _, e := range entries {
if i := strings.Index(e, "="); i <= 0 {
return fmt.Errorf("entry %q must be KEY=VALUE", e)
}
} Type guard
func isValidEnvEntry(e string) bool {
return strings.Index(e, "=") > 0
} Try / catch
if err := setMCPServerValue(cfg, key, value); err != nil {
fmt.Fprintf(os.Stderr, "config set failed: %v\n", err)
os.Exit(1)
} Prevention
- Include '=' in every entry, with a non-empty key before it
- Expand existing variables in the shell before building the array
- Trim the array of empty strings from copy-paste
When it happens
Trigger: Calling setMCPServerValue with field "env" where any array element lacks '=', e.g. '["DEBUG"]', '["=1"]', or '[""]'.
Common situations: Listing variable names only (expecting the tool to read them from the parent environment), typos dropping the '=', or an empty string left in the array from copy-paste.
Related errors
- invalid MCP server key %q: expected mcp_servers.<name>.<fiel
- invalid MCP server type %q: must be "stdio" or "remote"
- MCP server command cannot be empty
- invalid JSON array for %s: %w
- MCP server URL cannot be empty
AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02).
Data as JSON: /api/errors/bd69ddb373fb536f.
Report an issue: GitHub.