{"record":{"id":"cb6c11ad1aa20a1b","repo":"googleapis/mcp-toolbox","slug":"missing-name-field-or-it-is-not-a-string","errorCode":null,"errorMessage":"missing 'name' field or it is not a string","messagePattern":"missing 'name' field or it is not a string","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/server/config.go","lineNumber":226,"sourceCode":"\t\t}\n\t\tif name, ok = resource[\"name\"].(string); !ok {\n\t\t\t// A `kind: group` may omit `name` to target the default nameless group;\n\t\t\t// every other resource requires a name.\n\t\t\tif kind == \"group\" {\n\t\t\t\tif rawName, present := resource[\"name\"]; !present || rawName == nil {\n\t\t\t\t\tname, ok = \"\", true\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif !ok {\n\t\t\tif len(file.Docs) > 1 {\n\t\t\t\tfallbackToken := keyToken(doc.Body, \"name\")\n\t\t\t\tif fallbackToken == nil {\n\t\t\t\t\tfallbackToken = keyToken(doc.Body, \"kind\")\n\t\t\t\t}\n\t\t\t\treturn nil, nil, nil, nil, nil, nil, fmt.Errorf(\"%s missing 'name' field or it is not a string\", formatDocLocation(docIndex, fallbackToken, doc.Body))\n\t\t\t}\n\t\t\treturn nil, nil, nil, nil, nil, nil, fmt.Errorf(\"missing 'name' field or it is not a string\")\n\t\t}\n\t\t// remove 'kind' from map for strict unmarshaling\n\t\tdelete(resource, \"kind\")\n\n\t\tswitch kind {\n\t\tcase \"source\":\n\t\t\tc, err := UnmarshalYAMLSourceConfig(ctx, name, resource)\n\t\t\tif err != nil {\n\t\t\t\tif len(file.Docs) > 1 {\n\t\t\t\t\treturn nil, nil, nil, nil, nil, nil, fmt.Errorf(\"document %d: error unmarshaling %s %q: %w\", docIndex, kind, name, err)\n\t\t\t\t}\n\t\t\t\treturn nil, nil, nil, nil, nil, nil, fmt.Errorf(\"error unmarshaling %s: %w\", kind, err)\n\t\t\t}\n\t\t\tif sourceConfigs == nil {\n\t\t\t\tsourceConfigs = make(SourceConfigs)\n\t\t\t}\n\t\t\tif _, exists := sourceConfigs[name]; exists {\n\t\t\t\treturn nil, nil, nil, nil, nil, nil, fmt.Errorf(\"source %q declared more than once\", name)","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/server/config.go#L208-L244","documentation":"Single-document variant of the missing-'name' error: when the YAML file has only one document, UnmarshalPrimitiveConfig returns a bare 'missing 'name' field or it is not a string' without document-index decoration. The document's root map lacks a string 'name' key after kind was successfully resolved.","triggerScenarios":"ParseConfig on a single-document YAML where kind is a valid string but name is absent, null, or a non-string type.","commonSituations":"First-time config authors omitting name; templating engines emitting empty names; YAML like name: 42 (integer) failing the string assertion.","solutions":["Add 'name: <unique-string>' at the document root.","Quote the name if it could parse as a number or boolean (name: \"123\").","Ensure name is not indented under another key.","If the resource is a nameless default group, set kind: group explicitly."],"exampleFix":"// before\nkind: source\nsources: {...}\n// after\nkind: source\nname: my-source\nsources: {...}","handlingStrategy":"validation","validationCode":"var root map[string]any\nif err := yaml.Unmarshal([]byte(cfgText), &root); err != nil { return err }\nif k, ok := root[\"kind\"].(string); ok && k != \"group\" {\n    if _, ok := root[\"name\"].(string); !ok {\n        return fmt.Errorf(\"config with kind %q requires a top-level string 'name'\", k)\n    }\n}","typeGuard":"nameVal, ok := root[\"name\"]\nhasStringName := ok && func(v any) bool { _, isStr := v.(string); return isStr }(nameVal)","tryCatchPattern":"if err := server.ParseConfig(ctx, ...); err != nil {\n    if strings.Contains(err.Error(), \"missing 'name'\") {\n        log.Fatalf(\"add a top-level string 'name' to the document: %v\", err)\n    }\n    return err\n}","preventionTips":["Add name immediately after kind in every document template.","Never let templating engines emit empty name values ({{ .Name }} guarded).","Keep name at root indentation level.","Validate uniqueness of names alongside presence."],"tags":["yaml","config","validation"],"backgroundTag":"missing-yaml-name-field","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}