{"record":{"id":"edf7d8bd4922d957","repo":"siyuan-note/siyuan","slug":"duplicate-inherited-variable-q","errorCode":null,"errorMessage":"duplicate inherited variable %q","messagePattern":"duplicate inherited variable %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"kernel/mcp/client/mcp.go","lineNumber":552,"sourceCode":"func validateEnvironmentName(name string) error {\n\tif name == \"\" {\n\t\treturn errors.New(\"name is empty\")\n\t}\n\tif strings.ContainsAny(name, \"=\\x00\") {\n\t\treturn fmt.Errorf(\"invalid name %q\", name)\n\t}\n\treturn nil\n}\n\nfunc validateMCPServerEnvironment(server conf.MCPServer, goos string) error {\n\tinherited := map[string]bool{}\n\tfor _, name := range server.InheritEnv {\n\t\tif err := validateEnvironmentName(name); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tkey := environmentKey(name, goos)\n\t\tif inherited[key] {\n\t\t\treturn fmt.Errorf(\"duplicate inherited variable %q\", name)\n\t\t}\n\t\tinherited[key] = true\n\t}\n\texplicit := map[string]bool{}\n\tfor name, value := range server.Env {\n\t\tif err := validateEnvironmentName(name); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif strings.ContainsRune(value, '\\x00') {\n\t\t\treturn fmt.Errorf(\"variable %q contains NUL\", name)\n\t\t}\n\t\tkey := environmentKey(name, goos)\n\t\tif explicit[key] {\n\t\t\treturn fmt.Errorf(\"duplicate variable %q\", name)\n\t\t}\n\t\texplicit[key] = true\n\t}\n\treturn nil","sourceCodeStart":534,"sourceCodeEnd":570,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/mcp/client/mcp.go#L534-L570","documentation":"Validation error from validateMCPServerEnvironment: the same variable name appears more than once in server.InheritEnv. De-duplication is done via environmentKey, which on Windows upper-cases the name, so case-variant duplicates (PATH vs Path) also collide. The duplicated name is quoted via %q.","triggerScenarios":"server.InheritEnv contains two elements that normalize to the same key, e.g. [\"PATH\", \"PATH\"] on any OS or [\"PATH\", \"Path\"] on Windows. The first occurrence is recorded in the inherited map; the second triggers this error.","commonSituations":"Hand-edited JSON with a duplicate; merging multiple config fragments without de-duplication; cross-platform config that explicitly listed both casings to 'cover' Windows and Unix.","solutions":["Remove the duplicate entry from InheritEnv so each normalized key appears exactly once.","On Windows, collapse case variants to a single canonical form (e.g. keep only PATH).","If you need the variable to be explicitly set rather than inherited, remove it from InheritEnv and add it to Env instead."],"exampleFix":"// before (windows)\n\"inheritEnv\": [\"PATH\", \"Path\"]\n// after\n\"inheritEnv\": [\"PATH\"]","handlingStrategy":"validation","validationCode":"import (\n    \"runtime\"\n    \"strings\"\n)\nfunc dedupeInherited(names []string) []string {\n    seen := map[string]bool{}\n    out := make([]string, 0, len(names))\n    for _, n := range names {\n        key := n\n        if runtime.GOOS == \"windows\" { key = strings.ToUpper(n) }\n        if seen[key] { continue }\n        seen[key] = true\n        out = append(out, n)\n    }\n    return out\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["On Windows, use one canonical casing per variable.","De-duplicate inheritEnv at config-build time."],"tags":["mcp","environment","config-validation","windows"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}