{"record":{"id":"b706b896d3049499","repo":"siyuan-note/siyuan","slug":"name-is-empty","errorCode":null,"errorMessage":"name is empty","messagePattern":"name is empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"kernel/mcp/client/mcp.go","lineNumber":536,"sourceCode":"\tsort.Strings(keys)\n\tret := make([]string, 0, len(keys))\n\tfor _, key := range keys {\n\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","sourceCodeStart":518,"sourceCodeEnd":554,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/mcp/client/mcp.go#L518-L554","documentation":"Validation sentinel from validateEnvironmentName: an empty string was supplied where an environment variable name is required. It fires inside validateMCPServerEnvironment while iterating either server.InheritEnv (a slice, so an empty element is possible) or server.Env (map keys, which can also be the empty string). This is a config-shape defect, not a runtime condition.","triggerScenarios":"server.InheritEnv contains an empty string element (e.g. [\"PATH\", \"\", \"HOME\"]) or server.Env has a key equal to \"\". validateMCPServerEnvironment calls validateEnvironmentName(\"\"), which returns this error before connectStdio can spawn the child.","commonSituations":"Hand-edited MCP config JSON with a trailing comma or empty array element like \"inheritEnv\": [\"PATH\", \"\"]; UI form that submitted an empty 'add variable' row; programmatic config generator that appended an empty identifier.","solutions":["Open the MCP server config and remove the empty entry from InheritEnv or the empty key from Env.","If config is built programmatically, filter out empty names before writing: inheritEnv = slices.DeleteFunc(inheritEnv, func(s string) bool { return s == \"\" }).","Validate with ValidateMCPServerEnvironment at config-save time so this is reported in the UI, not at server start."],"exampleFix":"// before\n\"inheritEnv\": [\"PATH\", \"\", \"HOME\"]\n// after\n\"inheritEnv\": [\"PATH\", \"HOME\"]","handlingStrategy":"validation","validationCode":"import \"slices\"\nfunc dropEmpty(names []string) []string {\n    return slices.DeleteFunc(append([]string(nil), names...), func(s string) bool { return s == \"\" })\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Filter empty names when building inheritEnv programmatically.","Validate config with ValidateMCPServerEnvironment before saving."],"tags":["mcp","environment","config-validation"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}