{"record":{"id":"6e4062aa6e50e012","repo":"alibaba/open-code-review","slug":"mcp-server-q-not-found","errorCode":null,"errorMessage":"MCP server %q not found","messagePattern":"MCP server %q not found","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/opencodereview/config_cmd.go","lineNumber":269,"sourceCode":"\t\treturn err\n\t}\n\n\tfmt.Printf(\"Deleted custom provider %q.\\n\", name)\n\tif wasActive {\n\t\tfmt.Fprintf(os.Stderr, \"[ocr] WARNING: active provider was deleted; 'provider' and 'model' have been cleared.\\n\")\n\t\tfmt.Fprintf(os.Stderr, \"[ocr] Run 'ocr config provider' to select a new provider.\\n\")\n\t}\n\treturn nil\n}\n\nfunc unsetMCPServer(configPath, name string) error {\n\tcfg, err := loadOrCreateConfig(configPath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"load config: %w\", err)\n\t}\n\n\tif cfg.MCPServers == nil {\n\t\treturn fmt.Errorf(\"MCP server %q not found\", name)\n\t}\n\tif _, exists := cfg.MCPServers[name]; !exists {\n\t\treturn fmt.Errorf(\"MCP server %q not found\", name)\n\t}\n\n\tdelete(cfg.MCPServers, name)\n\tif len(cfg.MCPServers) == 0 {\n\t\tcfg.MCPServers = nil\n\t}\n\n\tif err := saveConfig(configPath, cfg); err != nil {\n\t\treturn err\n\t}\n\n\tfmt.Printf(\"Deleted MCP server %q.\\n\", name)\n\treturn nil\n}\n","sourceCodeStart":251,"sourceCodeEnd":287,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/cmd/opencodereview/config_cmd.go#L251-L287","documentation":"unsetMCPServer returns this error when cfg.MCPServers is nil, i.e. the config has no MCP servers section at all. It is functionally the same 'not found' condition as the map-lookup miss below, but handles the uninitialized-map case explicitly to avoid a nil-map lookup inconsistency in messaging.","triggerScenarios":"Running 'ocr config unset mcp <name>' on a config file that has never had any MCP server configured (no \"mcpServers\" key in the JSON), so cfg.MCPServers is nil.","commonSituations":"Fresh installation where no MCP server was ever added; typo'd subcommand run before 'ocr config set mcp'; config file written by hand without the mcpServers key.","solutions":["List configured MCP servers first (e.g. 'ocr config get' or read the config) to confirm the section exists.","Add the MCP server with 'ocr config set mcp <name> ...' before trying to unset it.","If the server was already removed, treat this as success and adjust any scripts to tolerate the error."],"exampleFix":"// before: unsetting on empty config fails\n$ ocr config unset mcp myserver\n\n// after: add it first or guard in a script\n$ ocr config set mcp myserver --command ./mcp.sh\n$ ocr config unset mcp myserver","handlingStrategy":"validation","validationCode":"cfg, _ := LoadAppConfig(configPath)\nif cfg == nil || cfg.MCPServers == nil {\n    return fmt.Errorf(\"no MCP servers configured at %s\", configPath)\n}","typeGuard":"func hasMCPServer(cfg *Config, name string) bool {\n    return cfg != nil && cfg.MCPServers != nil\n}","tryCatchPattern":"if err := unsetMCPServer(configPath, name); err != nil && strings.Contains(err.Error(), \"not found\") {\n    // already absent: treat as success/idempotent\n    return nil\n}","preventionTips":["Check 'ocr config get' output before unsetting.","Make unset scripts idempotent by tolerating not-found errors.","Add the MCP server before attempting to remove it."],"tags":["go","cli","config","mcp"],"backgroundTag":"mcp-server-not-found","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}