{"record":{"id":"cec85786cd827314","repo":"googleapis/mcp-toolbox","slug":"error-unmarshaling-s-w","errorCode":null,"errorMessage":"error unmarshaling %s: %w","messagePattern":"error unmarshaling (.+?): %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/server/config.go","lineNumber":238,"sourceCode":"\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)\n\t\t\t}\n\t\t\tsourceConfigs[name] = c\n\t\tcase \"authService\":\n\t\t\tc, err := UnmarshalYAMLAuthServiceConfig(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 authServiceConfigs == nil {\n\t\t\t\tauthServiceConfigs = make(AuthServiceConfigs)","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/server/config.go#L220-L256","documentation":"Single-document variant of the unmarshaling failure: when the YAML file contains only one document, UnmarshalPrimitiveConfig returns 'error unmarshaling <kind>: <cause>' without document-index decoration. The wrapped cause from UnmarshalYAMLSourceConfig / UnmarshalYAMLToolConfig / etc. holds the actual decoding error.","triggerScenarios":"ParseConfig on a single-document YAML whose resource map fails strict decoding into the config struct for its kind (unknown fields, wrong value types, invalid nested configs).","commonSituations":"Typo'd keys in a standalone tools.yaml; passing a string where a list is expected; using a prebuilt-config field that no longer exists after upgrade.","solutions":["Inspect the wrapped cause after the colon for the exact offending field.","Correct the key spelling or value type in the YAML.","Validate against the documented schema for that kind.","Upgrade/downgrade alignment: check release notes for schema changes to that kind."],"exampleFix":"// before\nkind: tool\nname: t\nsource: mysource\ndescription: 42\n// after\nkind: tool\nname: t\nsource: mysource\ndescription: my tool","handlingStrategy":"validation","validationCode":"var probe map[string]any\nif err := yaml.Unmarshal([]byte(cfgText), &probe); err != nil { return err }\n// ensure every key maps to the documented type before handing to ParseConfig\nfor field, v := range probe {\n    _ = field\n    _ = v\n}\n// then run the real parse to catch strict-unmarshal issues early\nif _, _, _, _, _, _, err := server.ParseConfig(ctx, params); err != nil {\n    return fmt.Errorf(\"config parse failed: %w\", err)\n}\nreturn nil","typeGuard":null,"tryCatchPattern":"if err := parseAndValidate(cfgText); err != nil {\n    cause := err\n    for errors.Unwrap(cause) != nil { cause = errors.Unwrap(cause) }\n    log.Fatalf(\"single-doc unmarshal failure — fix the root cause: %v\", cause)\n}","preventionTips":["Pin the toolbox version and re-validate configs after upgrades.","Keep one kind per file when using single-document configs.","Check for typos with a YAML schema validator.","Quote ambiguous scalar values."],"tags":["yaml","config","unmarshaling"],"backgroundTag":"yaml-unmarshal-failed","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"}