siyuan-note/siyuan · warning

duplicate inherited variable %q

Error message

duplicate inherited variable %q

What it means

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.

Source

Thrown at kernel/mcp/client/mcp.go:552

func validateEnvironmentName(name string) error {
	if name == "" {
		return errors.New("name is empty")
	}
	if strings.ContainsAny(name, "=\x00") {
		return fmt.Errorf("invalid name %q", name)
	}
	return nil
}

func validateMCPServerEnvironment(server conf.MCPServer, goos string) error {
	inherited := map[string]bool{}
	for _, name := range server.InheritEnv {
		if err := validateEnvironmentName(name); err != nil {
			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

View on GitHub (pinned to 251596fc0d)

Solutions

  1. Remove the duplicate entry from InheritEnv so each normalized key appears exactly once.
  2. On Windows, collapse case variants to a single canonical form (e.g. keep only PATH).
  3. If you need the variable to be explicitly set rather than inherited, remove it from InheritEnv and add it to Env instead.

Example fix

// before (windows)
"inheritEnv": ["PATH", "Path"]
// after
"inheritEnv": ["PATH"]
Defensive patterns

Strategy: validation

Validate before calling

import (
    "runtime"
    "strings"
)
func dedupeInherited(names []string) []string {
    seen := map[string]bool{}
    out := make([]string, 0, len(names))
    for _, n := range names {
        key := n
        if runtime.GOOS == "windows" { key = strings.ToUpper(n) }
        if seen[key] { continue }
        seen[key] = true
        out = append(out, n)
    }
    return out
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12). Data as JSON: /api/errors/edf7d8bd4922d957. Report an issue: GitHub.