alibaba/open-code-review · error
MCP server URL cannot be empty
Error message
MCP server URL cannot be empty
What it means
Validation in setMCPServerValue's url case: a remote MCP server entry requires a non-empty URL. Setting mcp_servers.<name>.url to an empty string would leave the remote transport with no endpoint, so the setter rejects it.
Source
Thrown at cmd/opencodereview/config_cmd.go:887
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 = value
case "headers":
parsed, err := parseMCPHeaders(value)
if err != nil {
return fmt.Errorf("invalid headers for %s: %w", key, err)
}
entry.Headers = parsedView on GitHub (pinned to 5cf97d0d15)
Solutions
- Pass the full server URL, e.g. https://mcp.example.com/sse
- If the server is local, use type stdio with command/args instead of url
- Check that any script variable holding the URL is actually set
Example fix
// before ocr config set mcp_servers.api.url "" // after ocr config set mcp_servers.api.url https://mcp.example.com/sse
Defensive patterns
Strategy: validation
Validate before calling
if url == "" {
return fmt.Errorf("url is required for remote servers")
} Try / catch
if err := setMCPServerValue(cfg, key, value); err != nil {
fmt.Fprintf(os.Stderr, "config set failed: %v\n", err)
os.Exit(1)
} Prevention
- Always pass the URL as a quoted argument
- In scripts, fail fast if the URL variable is empty (set -u / : "${URL:?}")
- Use stdio type with command for local servers instead
When it happens
Trigger: Calling setMCPServerValue with field "url" and value "".
Common situations: Running `ocr config set mcp_servers.api.url` without the value argument (shell passes empty string), or templated scripts where the URL variable is unset.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- invalid MCP server URL %q: %w
- MCP server URL must use http or https scheme, got %q
- MCP server URL %q must include a host
- invalid URL for %s: %w
- invalid MCP server key %q: expected mcp_servers.<name>.<fiel
AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02).
Data as JSON: /api/errors/9717825c02b069a2.
Report an issue: GitHub.