siyuan-note/siyuan · error

variable contains NUL

Error message

variable %q contains NUL

What it means

A value in conf.MCPServer.Env contains a NUL byte ('\x00'). Environment blocks passed to exec are NUL-delimited 'NAME=value' strings, so a NUL inside a value would truncate or corrupt the variable for the child stdio MCP server process. validateMCPServerEnvironment rejects it before spawning.

Solutions

  1. Open the MCP server settings and re-enter the variable value without the invisible NUL character (delete and retype the value)
  2. If editing conf.json, locate the value containing \u0000 and clean or regenerate it
  3. Verify the source of the value (token file, clipboard) is plain text and re-copy it

Example fix

// before
server.Env["TOKEN"] = "abc\x00def"
// after
server.Env["TOKEN"] = "abcdef"
Defensive patterns

Strategy: validation

Validate before calling

for name, v := range server.Env {
    if strings.ContainsRune(v, '\x00') {
        return fmt.Errorf("value of %q contains NUL", name)
    }
}

Prevention

When it happens

Trigger: A value of an entry in server.Env contains a literal NUL character when ValidateMCPServerEnvironment runs or buildStdioEnvironment prepares the child environment.

Common situations: Pasting binary data or a corrupted token into an env value field; config file corruption introducing NUL bytes; programmatic config generation embedding a NUL-terminated string.

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/2afc1a34bb3a7558. Report an issue: GitHub.

Appendix: source

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

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
}

// 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",

View on GitHub (pinned to 9f775e8a12)