{"record":{"id":"d3699252064ef655","repo":"googleapis/mcp-toolbox","slug":"source-q-declared-more-than-once","errorCode":null,"errorMessage":"source %q declared more than once","messagePattern":"source %q declared more than once","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/server/config.go","lineNumber":244,"sourceCode":"\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)\n\t\t\t}\n\t\t\tif _, exists := authServiceConfigs[name]; exists {\n\t\t\t\treturn nil, nil, nil, nil, nil, nil, fmt.Errorf(\"authService %q declared more than once\", name)\n\t\t\t}\n\t\t\tauthServiceConfigs[name] = c\n\t\tcase \"tool\":","sourceCodeStart":226,"sourceCodeEnd":262,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/server/config.go#L226-L262","documentation":"Thrown by UnmarshalPrimitiveConfig when two documents in the parsed YAML declare a source with the same 'name'. SourceConfigs is a map keyed by name, so duplicate declarations would silently overwrite each other; the parser rejects them instead.","triggerScenarios":"ParseConfig on a multi-document YAML file where two 'kind: source' documents share the identical name string.","commonSituations":"Copy-pasting a source document and forgetting to rename it; merging config files that both define 'my-pg'; templating loops emitting duplicate names.","solutions":["Rename one of the duplicate sources so each name is unique.","If both documents are identical, delete one.","If you intended one source reused by many tools, declare it once and reference it by name from tools.","Search the file (or concatenated files passed to --tools-file/--sources-file) for duplicated source names."],"exampleFix":"// before\nkind: source\nname: my-pg\n...\n---\nkind: source\nname: my-pg\n// after\nkind: source\nname: my-pg\n...\n---\nkind: source\nname: my-pg-replica","handlingStrategy":"validation","validationCode":"func checkUniqueSourceNames(docs []map[string]any) error {\n    seen := map[string]int{}\n    for i, doc := range docs {\n        if k, _ := doc[\"kind\"].(string); k == \"source\" {\n            n, _ := doc[\"name\"].(string)\n            if prev, dup := seen[n]; dup {\n                return fmt.Errorf(\"source %q declared in documents %d and %d\", n, prev+1, i+1)\n            }\n            seen[n] = i\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep a naming convention prefix per environment (e.g. prod-, dev-).","Grep for 'name:' under kind: source blocks before merging config changes.","Declare a shared source once and reference it from tools.","Add a uniqueness check script to CI for multi-document YAML files."],"tags":["yaml","config","duplicate"],"backgroundTag":"duplicate-config-name","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"}