alibaba/open-code-review · error
MCP server URL %q must include a host
Error message
MCP server URL %q must include a host
What it means
After the URL parses and passes the http/https scheme check, the setter requires a non-empty Host. A URL like 'http://' or a scheme-only/relative form has no host to connect to, so a remote MCP server configured with it would be unreachable; the setter rejects it with the original value quoted.
Source
Thrown at cmd/opencodereview/config_cmd.go:897
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 = parsed
case "tools":
var tools []string
if err := json.Unmarshal([]byte(value), &tools); err != nil {
return fmt.Errorf("invalid JSON array for %s: %w", key, err)
}
seen := make(map[string]struct{}, len(tools))
filtered := make([]string, 0, len(tools))
for _, t := range tools {
if t == "" {
return fmt.Errorf("tool names in %s must not be empty", key)View on GitHub (pinned to 5cf97d0d15)
Solutions
- Include the hostname (and port if needed) after the scheme: https://mcp.example.com/sse
- Re-copy the complete URL from the server documentation
- Check templated/scripted values so the host placeholder is filled
Example fix
// before ocr config set mcp_servers.api.url https:///api/mcp // after ocr config set mcp_servers.api.url https://mcp.example.com/api/mcp
Defensive patterns
Strategy: validation
Validate before calling
u, err := url.Parse(rawURL)
if err != nil || u.Host == "" {
return fmt.Errorf("URL must include a host")
} Type guard
func hasHost(rawURL string) bool {
u, err := url.Parse(rawURL)
return err == nil && u.Host != ""
} Try / catch
if err := setMCPServerValue(cfg, key, value); err != nil {
fmt.Fprintf(os.Stderr, "config set failed: %v\n", err)
os.Exit(1)
} Prevention
- Verify the hostname is present after the scheme
- Re-copy the full URL from server docs rather than retyping
- In scripts, check that the host variable is non-empty before interpolation
When it happens
Trigger: Calling setMCPServerValue with field "url" where the URL has a valid http/https scheme but no host, e.g. "http://" or "https:///api/mcp".
Common situations: Truncated paste of a URL losing the hostname; templated URLs where the host variable was empty; mistyping extra slashes after the scheme.
Understand the failure class
Background: "Invalid URL" / "URL cannot be empty": fix the malformed or missing URL behind request-construction failures — this error's family across 50 libraries.
Related errors
- MCP server URL cannot be empty
- invalid MCP server URL %q: %w
- MCP server URL must use http or https scheme, got %q
- 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/772dcbc3ae1ff808.
Report an issue: GitHub.