{"record":{"id":"a89fa56de79bb2c4","repo":"alibaba/open-code-review","slug":"invalid-headers-for-s-w","errorCode":null,"errorMessage":"invalid headers for %s: %w","messagePattern":"invalid headers for (.+?): %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/opencodereview/config_cmd.go","lineNumber":903,"sourceCode":"\tcase \"url\":\n\t\tif value == \"\" {\n\t\t\treturn fmt.Errorf(\"MCP server URL cannot be empty\")\n\t\t}\n\t\tparsed, err := url.Parse(value)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"invalid MCP server URL %q: %w\", value, err)\n\t\t}\n\t\tif parsed.Scheme != \"http\" && parsed.Scheme != \"https\" {\n\t\t\treturn fmt.Errorf(\"MCP server URL must use http or https scheme, got %q\", parsed.Scheme)\n\t\t}\n\t\tif parsed.Host == \"\" {\n\t\t\treturn fmt.Errorf(\"MCP server URL %q must include a host\", value)\n\t\t}\n\t\tentry.URL = value\n\tcase \"headers\":\n\t\tparsed, err := parseMCPHeaders(value)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"invalid headers for %s: %w\", key, err)\n\t\t}\n\t\tentry.Headers = parsed\n\tcase \"tools\":\n\t\tvar tools []string\n\t\tif err := json.Unmarshal([]byte(value), &tools); err != nil {\n\t\t\treturn fmt.Errorf(\"invalid JSON array for %s: %w\", key, err)\n\t\t}\n\t\tseen := make(map[string]struct{}, len(tools))\n\t\tfiltered := make([]string, 0, len(tools))\n\t\tfor _, t := range tools {\n\t\t\tif t == \"\" {\n\t\t\t\treturn fmt.Errorf(\"tool names in %s must not be empty\", key)\n\t\t\t}\n\t\t\tif _, dup := seen[t]; dup {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tseen[t] = struct{}{}\n\t\t\tfiltered = append(filtered, t)","sourceCodeStart":885,"sourceCodeEnd":921,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/cmd/opencodereview/config_cmd.go#L885-L921","documentation":"setMCPServerValue wraps any failure from parseMCPHeaders with \"invalid headers for <server>: ...\" when the CLI user sets the `headers` field of an MCP server via `ocr config set mcp-servers.<name>.headers`. parseMCPHeaders requires a JSON object of string key-value pairs, so wrapping preserves the underlying cause (bad JSON, empty key, empty value).","triggerScenarios":"Running the config set command with headers value that is not a valid JSON object, e.g. `ocr config set mcp-servers.myserver.headers \"Bearer abc\"` (bare string instead of object) or JSON containing an empty key/value.","commonSituations":"Quoting mistakes in the shell that strip the JSON braces; hand-writing headers as a plain string; pasting a single Authorization header instead of an object; forgetting to escape inner quotes.","solutions":["Pass a JSON object string, e.g. `ocr config set mcp-servers.myserver.headers '{\"Authorization\":\"Bearer token\"}'`","Single-quote the value in the shell so braces and inner double quotes survive","Inspect the wrapped cause after `invalid headers for ...:` — it says whether the JSON was unparseable or a key/value was empty"],"exampleFix":"// before\nocr config set mcp-servers.remote.headers Authorization=Bearer\\ abc\n// after\nocr config set mcp-servers.remote.headers '{\"Authorization\": \"Bearer abc\"}'","handlingStrategy":"validation","validationCode":"func validHeaders(s string) bool {\n    var m map[string]string\n    if json.Unmarshal([]byte(s), &m) != nil { return false }\n    for k, v := range m { if k == \"\" || v == \"\" { return false } }\n    return true\n}","typeGuard":"func isStringMap(v any) bool { _, ok := v.(map[string]string); return ok }","tryCatchPattern":"if err := setMCPServerValue(cfg, name, \"headers\", raw); err != nil {\n    var perr *json.SyntaxError\n    if errors.As(err, &perr) { /* show syntax offset */ }\n    return err\n}","preventionTips":["Always pass headers as a single-quoted JSON object in the shell","Keep header values non-empty; interpolate env vars with ${VAR} defaults","Round-trip the value through `jq -c .` before setting it"],"tags":["cli","config","json","mcp"],"backgroundTag":"invalid-json-input","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}