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

  1. Prefix the URL with https:// (or http:// for plain local endpoints)
  2. Do not use ws:// or wss://; the client speaks HTTP/SSE
  3. 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

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


AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02). Data as JSON: /api/errors/72dbf122a0761f88. Report an issue: GitHub.