{"record":{"id":"b4f53d3612d623ea","repo":"alibaba/open-code-review","slug":"invalid-mcp-server-key-q-expected-mcp-servers-n","errorCode":null,"errorMessage":"invalid MCP server key %q: expected mcp_servers.<name>.<field>","messagePattern":"invalid MCP server key %q: expected mcp_servers\\.<name>\\.<field>","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/opencodereview/config_cmd.go","lineNumber":847,"sourceCode":"\tif _, exists := cfg.CustomProviders[name]; isAuxiliaryProviderField(field) && !exists {\n\t\tproviderKey := strings.TrimSuffix(key, \".\"+field)\n\t\treturn fmt.Errorf(\"provider %q is not configured; set a core field first (protocol is required for every custom provider):\\n  ocr config set %s.protocol <protocol>\", name, providerKey)\n\t}\n\tif cfg.CustomProviders == nil {\n\t\tcfg.CustomProviders = make(map[string]ProviderEntry)\n\t}\n\tentry := cfg.CustomProviders[name]\n\tif err := applyProviderField(name, &entry, field, key, value); err != nil {\n\t\treturn err\n\t}\n\tcfg.CustomProviders[name] = entry\n\treturn nil\n}\n\nfunc setMCPServerValue(cfg *Config, key, value string) error {\n\tparts := strings.SplitN(key, \".\", 3)\n\tif len(parts) != 3 || parts[1] == \"\" || parts[2] == \"\" {\n\t\treturn fmt.Errorf(\"invalid MCP server key %q: expected mcp_servers.<name>.<field>\", key)\n\t}\n\tname, field := parts[1], parts[2]\n\n\tif cfg.MCPServers == nil {\n\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}","sourceCodeStart":829,"sourceCodeEnd":865,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/cmd/opencodereview/config_cmd.go#L829-L865","documentation":"setMCPServerValue validates the dotted key used by `ocr config set` for MCP server entries. The key must have exactly three non-empty segments: mcp_servers.<name>.<field>. This error is returned when the key splits into fewer or more segments or has an empty name/field segment.","triggerScenarios":"Calling setMCPServerValue (via `ocr config set`) with a key like \"mcp_servers\" (1 part), \"mcp_servers.myserver\" (2 parts), \"mcp_servers..command\" (empty name), \"mcp_servers.myserver.\" (empty field), or a key with more than 3 dot-separated parts since SplitN with limit 3 leaves extra dots in the field segment.","commonSituations":"Typos in the config key, forgetting the field segment (e.g. `ocr config set mcp_servers.myserver` without a field), accidentally including extra dots, or pasting a key from docs for a different config section.","solutions":["Use the full three-segment key format: mcp_servers.<server-name>.<field>, e.g. mcp_servers.filesystem.type","Ensure the server name and field segments are both non-empty","Avoid extra dots in the key; extra dots land in the field segment and produce unknown-field errors downstream","Run `ocr config --help` to see the accepted key formats"],"exampleFix":"// before\nocr config set mcp_servers.myserver\n// after\nocr config set mcp_servers.myserver.type stdio","handlingStrategy":"validation","validationCode":"parts := strings.Split(key, \".\")\nif len(parts) != 3 || parts[1] == \"\" || parts[2] == \"\" {\n\treturn fmt.Errorf(\"key must be mcp_servers.<name>.<field>, got %q\", key)\n}","typeGuard":"func isValidMCPServerKey(key string) bool {\n\tparts := strings.Split(key, \".\")\n\treturn len(parts) == 3 && parts[1] != \"\" && parts[2] != \"\"\n}","tryCatchPattern":"if err := setMCPServerValue(cfg, key, value); err != nil {\n\tfmt.Fprintf(os.Stderr, \"config set failed: %v\\n\", err)\n\tos.Exit(1)\n}","preventionTips":["Always pass the full three-segment key: mcp_servers.<name>.<field>","Quote keys containing dots for your shell","Check `ocr config --help` for the key grammar before scripting"],"tags":["config","mcp","validation"],"backgroundTag":"invalid-config-key-format","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}