alibaba/open-code-review · error
MCP server URL must use http or https scheme, got %q
Error message
MCP server URL must use http or https scheme, got %q
What it means
Only http and https schemes are accepted for remote MCP server URLs. Other schemes (ws, ftp, file, or a missing scheme making parsed.Scheme empty) are rejected with this error naming the offending scheme.
Source
Thrown at cmd/opencodereview/config_cmd.go:894
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 = 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))View on GitHub (pinned to 5cf97d0d15)
Solutions
- Prefix the URL with https:// (or http:// for plain local endpoints)
- Do not use ws:// or wss://; the client speaks HTTP/SSE
- If targeting localhost, still write the full scheme: http://localhost:8080
Example fix
// before ocr config set mcp_servers.api.url localhost:8080/mcp // after ocr config set mcp_servers.api.url http://localhost:8080/mcp
Defensive patterns
Strategy: validation
Validate before calling
u, err := url.Parse(rawURL)
if err != nil || (u.Scheme != "http" && u.Scheme != "https") {
return fmt.Errorf("URL must use http or https")
} Type guard
func isHTTPURL(rawURL string) bool {
u, err := url.Parse(rawURL)
return err == nil && (u.Scheme == "http" || u.Scheme == "https")
} 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 prefix URLs with https:// or http://
- Do not use ws://, wss://, or file:// schemes
- Even localhost endpoints need an explicit scheme
When it happens
Trigger: Calling setMCPServerValue with field "url" whose parsed scheme is not http or https: e.g. "ftp://host", "localhost:8080" (scheme parsed as empty/other), or "wss://host".
Common situations: Omitting the scheme so Go parses the URL as an opaque/path-only value; using websocket schemes from other MCP client configs; pasting file:// URLs for local servers.
Related errors
- MCP server URL cannot be empty
- invalid MCP server URL %q: %w
- 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/72dbf122a0761f88.
Report an issue: GitHub.