siyuan-note/siyuan · error
duplicate variable
Error message
duplicate variable %q
What it means
validateMCPServerEnvironment rejects a server whose explicit Env map contains the same variable name twice. Keys in the Go map are already unique, so this triggers when two names normalize to the same environmentKey — i.e. on Windows, names differing only by case (PATH vs Path). Explicitly setting the same variable twice is ambiguous, so it fails fast.
Solutions
- Open the MCP server settings and remove one of the duplicated environment entries
- On Windows, check for case-only variants (PATH vs Path) and keep a single entry
- If the duplicate originates from an imported config, deduplicate the env object keys in conf.json and restart the server connection
Example fix
// before (Windows) server.Env["PATH"] = "C:\\tools" server.Env["Path"] = "C:\\other" // after server.Env["PATH"] = "C:\\tools;C:\\other"
Defensive patterns
Strategy: validation
Validate before calling
// normalize keys case-insensitively on Windows before building Env
key := name
if runtime.GOOS == "windows" { key = strings.ToUpper(name) }
if _, dup := envByKey[key]; dup { return fmt.Errorf("duplicate env %q", name) }
envByKey[key] = value Prevention
- On Windows, canonicalize env key casing (e.g. always uppercase) when creating entries
- Deduplicate env keys after config merge/import
- Validate with ValidateMCPServerEnvironment before saving
When it happens
Trigger: conf.MCPServer.Env has two keys that map to the same environmentKey (case-insensitive match on Windows) when ValidateMCPServerEnvironment runs or a stdio server is launched.
Common situations: On Windows, adding both 'Path' and 'PATH' as explicit env entries; a config merge/import producing near-duplicate keys; hand-editing conf.json with case-variant duplicates.
Understand the failure class
Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.
Related errors
- duplicate inherited variable
- invalid name
- variable contains NUL
- attr must be a string or null (got %T)
- command is required for stdio server
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/2c73085ae2fa5eda.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/mcp/client/mcp.go:568
return err
}
key := environmentKey(name, goos)
if inherited[key] {
return fmt.Errorf("duplicate inherited variable %q", name)
}
inherited[key] = true
}
explicit := map[string]bool{}
for name, value := range server.Env {
if err := validateEnvironmentName(name); err != nil {
return err
}
if strings.ContainsRune(value, '\x00') {
return fmt.Errorf("variable %q contains NUL", name)
}
key := environmentKey(name, goos)
if explicit[key] {
return fmt.Errorf("duplicate variable %q", name)
}
explicit[key] = true
}
return nil
}
// ValidateMCPServerEnvironment 校验当前平台上的 stdio 环境变量配置。
func ValidateMCPServerEnvironment(server conf.MCPServer) error {
return validateMCPServerEnvironment(server, runtime.GOOS)
}
func defaultMCPEnvironmentNames(goos string) []string {
if goos == "windows" {
return []string{"APPDATA", "HOMEDRIVE", "HOMEPATH", "LOCALAPPDATA", "PATH", "PATHEXT",
"PROCESSOR_ARCHITECTURE", "PROGRAMFILES", "SYSTEMDRIVE", "SYSTEMROOT", "TEMP", "USERNAME", "USERPROFILE"}
}
return []string{"HOME", "LOGNAME", "PATH", "SHELL", "TERM"}
}View on GitHub (pinned to 9f775e8a12)