{"record":{"id":"f9f338a5db46b997","repo":"googleapis/mcp-toolbox","slug":"s-missing-name-field-or-it-is-not-a-string","errorCode":null,"errorMessage":"%s 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":224,"sourceCode":"\t\t\t}\n\t\t\treturn nil, nil, nil, nil, nil, nil, fmt.Errorf(\"missing 'kind' field or it is not a string: %v\", resource)\n\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}","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/server/config.go#L206-L242","documentation":"Thrown by UnmarshalPrimitiveConfig after the kind is resolved: every resource (except a nameless 'kind: group') must have a top-level 'name' whose value is a string. When the file has multiple YAML documents, this error is prefixed with a document location (using a fallback token from the 'name' or 'kind' key) so the offending document can be identified.","triggerScenarios":"ParseConfig on a multi-document YAML file where a document has kind set but no string 'name' at the root (missing, null, numeric, or a non-scalar).","commonSituations":"Defining several tools/sources with --- separators and forgetting name on one; renaming a resource and deleting the name key; generating YAML where name resolves to null.","solutions":["Add a unique string 'name' field at the document root next to kind.","Confirm name is a scalar string, not a number or nested map.","For group documents that intentionally omit name, verify kind is exactly 'group' (the only kind allowed to omit name).","Check indentation so name is at the document root level.","Locate the document via the prefix/line info in the error message."],"exampleFix":"// before\ndocument 2:\nkind: tool\n# name missing\n// after\nkind: tool\nname: query-users","handlingStrategy":"validation","validationCode":"func validateDocsHaveNames(docs []map[string]any) error {\n    for i, doc := range docs {\n        kind, _ := doc[\"kind\"].(string)\n        if kind == \"group\" {\n            continue // group may omit name\n        }\n        if _, ok := doc[\"name\"].(string); !ok {\n            return fmt.Errorf(\"document %d (kind=%s): 'name' must be present and a string\", i+1, kind)\n        }\n    }\n    return nil\n}","typeGuard":"n, present := doc[\"name\"]\nhasStringName := present && func(v any) bool { _, isStr := v.(string); return isStr }(n)","tryCatchPattern":null,"preventionTips":["Give every source/tool/authService document a unique, descriptive name.","Quote names that could parse as numbers or booleans.","Treat 'group' as the only kind allowed to omit name.","Run a pre-deploy config parse (go run . --tools-file ...) in CI."],"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-08T10:18:20.063Z"}