{"record":{"id":"a45816e410f9035f","repo":"googleapis/mcp-toolbox","slug":"embeddingmodel-q-declared-more-than-once","errorCode":null,"errorMessage":"embeddingModel %q declared more than once","messagePattern":"embeddingModel %q declared more than once","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/server/config.go","lineNumber":307,"sourceCode":"\t\t\t\ttoolsetGroups = make(map[string]group.GroupConfig)\n\t\t\t}\n\t\t\tif _, exists := toolsetGroups[name]; exists {\n\t\t\t\treturn nil, nil, nil, nil, nil, nil, fmt.Errorf(\"toolset %q declared more than once\", name)\n\t\t\t}\n\t\t\ttoolsetGroups[name] = group.GroupConfig{Name: name, ToolNames: c.ToolNames}\n\t\tcase \"embeddingModel\":\n\t\t\tc, err := UnmarshalYAMLEmbeddingModelConfig(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 embeddingModelConfigs == nil {\n\t\t\t\tembeddingModelConfigs = make(EmbeddingModelConfigs)\n\t\t\t}\n\t\t\tif _, exists := embeddingModelConfigs[name]; exists {\n\t\t\t\treturn nil, nil, nil, nil, nil, nil, fmt.Errorf(\"embeddingModel %q declared more than once\", name)\n\t\t\t}\n\t\t\tembeddingModelConfigs[name] = c\n\t\tcase \"prompt\":\n\t\t\tc, err := UnmarshalYAMLPromptConfig(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 promptConfigs == nil {\n\t\t\t\tpromptConfigs = make(PromptConfigs)\n\t\t\t}\n\t\t\tif _, exists := promptConfigs[name]; exists {\n\t\t\t\treturn nil, nil, nil, nil, nil, nil, fmt.Errorf(\"prompt %q declared more than once\", name)\n\t\t\t}\n\t\t\tpromptConfigs[name] = c\n\t\tcase \"group\":","sourceCodeStart":289,"sourceCodeEnd":325,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/server/config.go#L289-L325","documentation":"UnmarshalPrimitiveConfig rejects duplicate embeddingModel names: after unmarshaling an \"embeddingModel\" resource, it checks `embeddingModelConfigs[name]` and errors if the name already exists. Model names are map keys; a duplicate would silently overwrite the earlier model, so parsing fails.","triggerScenarios":"Calling ParseConfig with a YAML file (single or multi-document) that declares two `embeddingModel` resources with the same name, hitting the `exists` check on `embeddingModelConfigs`.","commonSituations":"Adding a second embedding model block and reusing the earlier name; merging config fragments where both define `my-embed`.","solutions":["Rename one of the two embeddingModels named in the error to a unique name.","Remove the redundant duplicate model definition.","Search all `---` documents for the duplicated name.","Update toolset/tool references to point at the retained model name."],"exampleFix":"// before\nembeddingModels:\n  my-embed:\n    provider: gemini\n    modelId: text-embedding-004\n  my-embed:\n    provider: gemini\n    modelId: text-embedding-005\n// after\nembeddingModels:\n  my-embed:\n    provider: gemini\n    modelId: text-embedding-004\n  my-embed-v5:\n    provider: gemini\n    modelId: text-embedding-005","handlingStrategy":"validation","validationCode":"func rawDuplicateEmbeddingModelNames(data string) []string {\n    var seen, dups []string\n    inSection := false\n    for _, line := range strings.Split(data, \"\\n\") {\n        trimmed := strings.TrimSpace(line)\n        if strings.HasPrefix(line, \"embeddingModels:\") { inSection = true; continue }\n        if inSection && !strings.HasPrefix(line, \" \") && strings.HasSuffix(trimmed, \":\") && !strings.HasPrefix(trimmed, \"-\") { inSection = false }\n        if inSection && strings.HasSuffix(trimmed, \":\") && !strings.HasPrefix(trimmed, \"-\") {\n            name := strings.TrimSuffix(trimmed, \":\")\n            if slices.Contains(seen, name) { dups = append(dups, name) }\n            seen = append(seen, name)\n        }\n    }\n    return dups\n}","typeGuard":"func isDuplicateEmbeddingModelErr(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"embeddingModel\") && strings.Contains(err.Error(), \"declared more than once\")\n}","tryCatchPattern":"cfg, err := server.ParseConfig(ctx, yamlBytes)\nif err != nil {\n    if strings.Contains(err.Error(), \"declared more than once\") {\n        return fmt.Errorf(\"embedding model names must be unique: %w\", err)\n    }\n    return err\n}","preventionTips":["Version model names (my-embed-v1, my-embed-v2) instead of reusing one name.","Grep for the model name across all documents before adding a new block.","Update any references (e.g., tool/model bindings) after renaming a model."],"tags":["config","duplicate","embedding-model","yaml"],"backgroundTag":"duplicate-resource-definition","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"}