siyuan-note/siyuan · error

duplicate inherited variable

Error message

duplicate inherited variable %q

What it means

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.

Solutions

  1. Open the MCP server settings and remove the duplicated entry from the inherit-environment list
  2. Check for case-only duplicates when on Windows (Path vs PATH) and keep just one
  3. If the duplicate comes from a synced/imported config, deduplicate the inheritEnv array in conf.json and reload

Example fix

// before
server.InheritEnv = []string{"HOME", "PATH", "PATH"}
// after
server.InheritEnv = []string{"HOME", "PATH"}
Defensive patterns

Strategy: validation

Validate before calling

seen := map[string]bool{}
for _, n := range server.InheritEnv {
    k := strings.ToUpper(n) // match Windows semantics
    if seen[k] { return fmt.Errorf("duplicate inherit %q", n) }
    seen[k] = true
}

Prevention

When it happens

Trigger: conf.MCPServer.InheritEnv contains the same name (case-insensitively on Windows) twice when ValidateMCPServerEnvironment runs or a stdio server is started via buildStdioEnvironment.

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

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


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/edf7d8bd4922d957. Report an issue: GitHub.

Appendix: source

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

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 9f775e8a12)