{"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":"error","filePath":"kernel/mcp/client/mcp.go","lineNumber":554,"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":536,"sourceCodeEnd":572,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/mcp/client/mcp.go#L536-L572","documentation":"validateMCPServerEnvironment rejects a server whose InheritEnv list contains the same variable name more than once. On Windows comparison is case-insensitive (environmentKey uppercases the name), so 'Path' and 'PATH' also count as duplicates. Inheriting the same variable twice is meaningless and likely a config mistake, so it fails fast.","triggerScenarios":"conf.MCPServer.InheritEnv contains the same name (case-insensitively on Windows) twice when ValidateMCPServerEnvironment runs or a stdio server is started via buildStdioEnvironment.","commonSituations":"Adding the same inherit entry twice in the MCP settings UI; merging configs where both entries inherited PATH; on Windows, adding both 'Path' and 'PATH' from different sources.","solutions":["Open the MCP server settings and remove the duplicated entry from the inherit-environment list","Check for case-only duplicates when on Windows (Path vs PATH) and keep just one","If the duplicate comes from a synced/imported config, deduplicate the inheritEnv array in conf.json and reload"],"exampleFix":"// before\nserver.InheritEnv = []string{\"HOME\", \"PATH\", \"PATH\"}\n// after\nserver.InheritEnv = []string{\"HOME\", \"PATH\"}","handlingStrategy":"validation","validationCode":"seen := map[string]bool{}\nfor _, n := range server.InheritEnv {\n    k := strings.ToUpper(n) // match Windows semantics\n    if seen[k] { return fmt.Errorf(\"duplicate inherit %q\", n) }\n    seen[k] = true\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Deduplicate InheritEnv whenever config is merged or imported","Use case-insensitive comparison on Windows when adding inherit entries","Validate with ValidateMCPServerEnvironment before saving the server entry"],"tags":["mcp","environment-variables","duplicate-config"],"backgroundTag":"conflicting-config-options","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}