{"record":{"id":"bf72c0432df311f4","repo":"alibaba/open-code-review","slug":"invalid-json-array-for-s-w","errorCode":null,"errorMessage":"invalid JSON array for %s: %w","messagePattern":"invalid JSON array for (.+?): %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/opencodereview/config_cmd.go","lineNumber":870,"sourceCode":"\t\tcfg.MCPServers = make(map[string]MCPServerConfig)\n\t}\n\tentry := cfg.MCPServers[name]\n\n\tswitch field {\n\tcase \"type\":\n\t\tif value != \"stdio\" && value != \"remote\" {\n\t\t\treturn fmt.Errorf(\"invalid MCP server type %q: must be \\\"stdio\\\" or \\\"remote\\\"\", value)\n\t\t}\n\t\tentry.Type = value\n\tcase \"command\":\n\t\tif value == \"\" {\n\t\t\treturn fmt.Errorf(\"MCP server command cannot be empty\")\n\t\t}\n\t\tentry.Command = value\n\tcase \"args\":\n\t\tvar args []string\n\t\tif err := json.Unmarshal([]byte(value), &args); err != nil {\n\t\t\treturn fmt.Errorf(\"invalid JSON array for %s: %w\", key, err)\n\t\t}\n\t\tentry.Args = args\n\tcase \"env\":\n\t\tvar env []string\n\t\tif err := json.Unmarshal([]byte(value), &env); err != nil {\n\t\t\treturn fmt.Errorf(\"invalid JSON array for %s: %w\", key, err)\n\t\t}\n\t\tfor _, e := range env {\n\t\t\tidx := strings.Index(e, \"=\")\n\t\t\tif idx <= 0 {\n\t\t\t\treturn fmt.Errorf(\"invalid env entry %q: must be in KEY=VALUE format\", e)\n\t\t\t}\n\t\t}\n\t\tentry.Env = env\n\tcase \"url\":\n\t\tif value == \"\" {\n\t\t\treturn fmt.Errorf(\"MCP server URL cannot be empty\")\n\t\t}","sourceCodeStart":852,"sourceCodeEnd":888,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/cmd/opencodereview/config_cmd.go#L852-L888","documentation":"Fires in setMCPServerValue when the value for the args field of an MCP server is not a JSON array of strings (json.Unmarshal into []string fails). CLI args for an MCP server must be a JSON array like [\"serve\",\"--port\",\"8080\"]; anything else would produce an unusable arg list, so the setter rejects it, wrapping the unmarshal error and naming the full key.","triggerScenarios":"Calling setMCPServerValue with field \"args\" and a value that is not valid JSON, not an array, or an array with non-string elements, e.g. \"-y @modelcontextprotocol/server\" (bare string), \"{\\\"a\\\":1}\" (object), or \"[1,2]\" (non-strings).","commonSituations":"Passing shell-style argument lists without JSON quoting; forgetting that quotes inside the value must survive shell escaping; using single quotes in JSON on Windows cmd.","solutions":["Wrap the arguments in a valid JSON array of strings, e.g. '[\"-y\",\"@modelcontextprotocol/server-filesystem\",\"/tmp\"]'","Validate the JSON with a linter or `echo '<value>' | jq .` before setting","Escape inner double quotes for your shell (e.g. use single quotes on POSIX shells)"],"exampleFix":"// before\nocr config set mcp_servers.fs.args -y server-filesystem\n// after\nocr config set mcp_servers.fs.args '[\"-y\",\"server-filesystem\",\"/tmp\"]'","handlingStrategy":"validation","validationCode":"var args []string\nif err := json.Unmarshal([]byte(value), &args); err != nil {\n\treturn fmt.Errorf(\"args must be a JSON string array: %w\", err)\n}","typeGuard":"func isStringArray(v string) bool {\n\tvar a []string\n\treturn json.Unmarshal([]byte(v), &a) == nil\n}","tryCatchPattern":"if err := setMCPServerValue(cfg, key, value); err != nil {\n\tvar jsonErr *json.SyntaxError\n\tif errors.As(err, &jsonErr) {\n\t\tfmt.Fprintf(os.Stderr, \"bad JSON at offset %d: %v\\n\", jsonErr.Offset, err)\n\t}\n\tos.Exit(1)\n}","preventionTips":["Wrap args in a JSON array of strings with double quotes","Use single quotes around the JSON in POSIX shells","Validate with `jq` before setting"],"tags":["config","mcp","json","validation"],"backgroundTag":"invalid-json","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}