siyuan-note/siyuan · error

invalid name

Error message

invalid name %q

What it means

validateEnvironmentName rejects MCP server environment variable names that are empty or contain '=' or NUL. Environment variable names cannot contain '=' or NUL bytes because the exec env block is a list of 'NAME=value' strings; such a name would corrupt the child process environment. The %q message is returned when the name contains '=' or a NUL byte.

Solutions

  1. Open the MCP server settings and edit the environment variable so the name field contains only the variable name (e.g. PATH) and move the value into the value field
  2. If editing conf.json manually, find the offending key in the server's env/inheritEnv list and remove '=' or NUL characters from the key
  3. Re-validate by restarting the MCP server connection after fixing the entry

Example fix

// before
server.Env["API_KEY=abc123"] = ""
// after
server.Env["API_KEY"] = "abc123"
Defensive patterns

Strategy: validation

Validate before calling

func validEnvName(name string) bool {
    return name != "" && !strings.ContainsAny(name, "=\x00")
}
// before saving config:
for _, n := range append(server.InheritEnv, keys(server.Env)...) {
    if !validEnvName(n) { return fmt.Errorf("bad env name %q", n) }
}

Prevention

When it happens

Trigger: A conf.MCPServer has an entry in InheritEnv or a key in Env whose name contains '=' or '\x00'; validation runs via validateMCPServerEnvironment (through ValidateMCPServerEnvironment or buildStdioEnvironment when starting a stdio server).

Common situations: Pasting a full 'KEY=value' pair into the variable-name field of the MCP server settings UI; importing a config where names and values were split incorrectly; programmatic config generation that accidentally includes the '=' separator in the name.

Understand the failure class

Background: "is not a valid" / "Invalid ... value" environment variable errors: how libraries validate env vars and what to do when they reject yours — this error's family across 48 libraries.

Related errors


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

Appendix: source

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

		entry := entries[key]
		ret = append(ret, entry.name+"="+entry.value)
	}
	return ret, nil
}

func environmentKey(name, goos string) string {
	if goos == "windows" {
		return strings.ToUpper(name)
	}
	return name
}

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 {

View on GitHub (pinned to 9f775e8a12)