{"record":{"id":"f17a3873e1f3eadd","repo":"siyuan-note/siyuan","slug":"invalid-name-q","errorCode":null,"errorMessage":"invalid name %q","messagePattern":"invalid name %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/mcp/client/mcp.go","lineNumber":541,"sourceCode":"\t\tentry := entries[key]\n\t\tret = append(ret, entry.name+\"=\"+entry.value)\n\t}\n\treturn ret, nil\n}\n\nfunc environmentKey(name, goos string) string {\n\tif goos == \"windows\" {\n\t\treturn strings.ToUpper(name)\n\t}\n\treturn name\n}\n\nfunc validateEnvironmentName(name string) error {\n\tif name == \"\" {\n\t\treturn errors.New(\"name is empty\")\n\t}\n\tif strings.ContainsAny(name, \"=\\x00\") {\n\t\treturn fmt.Errorf(\"invalid name %q\", name)\n\t}\n\treturn nil\n}\n\nfunc validateMCPServerEnvironment(server conf.MCPServer, goos string) error {\n\tinherited := map[string]bool{}\n\tfor _, name := range server.InheritEnv {\n\t\tif err := validateEnvironmentName(name); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tkey := environmentKey(name, goos)\n\t\tif inherited[key] {\n\t\t\treturn fmt.Errorf(\"duplicate inherited variable %q\", name)\n\t\t}\n\t\tinherited[key] = true\n\t}\n\texplicit := map[string]bool{}\n\tfor name, value := range server.Env {","sourceCodeStart":523,"sourceCodeEnd":559,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/mcp/client/mcp.go#L523-L559","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["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","If editing conf.json manually, find the offending key in the server's env/inheritEnv list and remove '=' or NUL characters from the key","Re-validate by restarting the MCP server connection after fixing the entry"],"exampleFix":"// before\nserver.Env[\"API_KEY=abc123\"] = \"\"\n// after\nserver.Env[\"API_KEY\"] = \"abc123\"","handlingStrategy":"validation","validationCode":"func validEnvName(name string) bool {\n    return name != \"\" && !strings.ContainsAny(name, \"=\\x00\")\n}\n// before saving config:\nfor _, n := range append(server.InheritEnv, keys(server.Env)...) {\n    if !validEnvName(n) { return fmt.Errorf(\"bad env name %q\", n) }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Enter only the variable name in name fields; keep '=' and values in the value field","Run conf.MCPClient ValidateMCPServerEnvironment before persisting server config","Reject any name from user input that fails validEnvName at input time"],"tags":["mcp","environment-variables","config-validation"],"backgroundTag":"invalid-env-var-value","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}