{"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":"error","filePath":"kernel/mcp/client/mcp.go","lineNumber":538,"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":520,"sourceCodeEnd":556,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/mcp/client/mcp.go#L520-L556","documentation":"validateEnvironmentName is part of stdio MCP server environment validation: every InheritEnv and Env key must be a non-empty string that contains no '=' or NUL byte, because these characters cannot appear in a NAME=VALUE environment entry. An empty key triggers this bare \"name is empty\" error before the subprocess starts.","triggerScenarios":"validateMCPServerEnvironment iterates server.InheritEnv or server.Env and passes an empty-string name to validateEnvironmentName — e.g. an InheritEnv array containing \"\" or an Env JSON object with an empty key.","commonSituations":"Malformed config JSON with {\"\": \"value\"}, an InheritEnv list with a trailing empty entry, programmatic config generation that left a name unset, or hand-editing that removed the variable name but kept the value.","solutions":["Remove empty-string entries from InheritEnv and delete any \"\" key from the Env map","Provide the actual variable name, e.g. {\"Env\": {\"MY_VAR\": \"value\"}}","Re-save the MCP server configuration through the UI so the environment fields are rebuilt correctly","Add a pre-save check that every env name is non-empty and free of '=' and NUL"],"exampleFix":"// before\n\"inheritEnv\": [\"PATH\", \"\"]\n// after\n\"inheritEnv\": [\"PATH\"]","handlingStrategy":"validation","validationCode":"func validEnvNames(names []string) bool {\n    for _, n := range names {\n        if n == \"\" || strings.ContainsAny(n, \"=\\x00\") {\n            return false\n        }\n    }\n    return true\n}","typeGuard":"null","tryCatchPattern":"if err := validateMCPServerEnvironment(server, runtime.GOOS); err != nil {\n    return fmt.Errorf(\"environment config invalid for server %q: %w\", server.Name, err)\n}","preventionTips":["Reject empty-string keys when serializing Env config to JSON","Run the same name validation in the settings UI before persisting","Generate config programmatically with schema checks that require non-empty map keys"],"tags":["mcp","environment","validation","empty-field"],"backgroundTag":"empty-required-field","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"}