{"record":{"id":"9e653a6458ba062e","repo":"googleapis/mcp-toolbox","slug":"unable-to-retrieve-source-q-for-tool-q","errorCode":null,"errorMessage":"unable to retrieve source %q for tool %q","messagePattern":"unable to retrieve source %q for tool %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/server/server.go","lineNumber":295,"sourceCode":"\t\tvar src sources.Source\n\t\tt, err := func() (tools.Tool, error) {\n\t\t\t_, span := instrumentation.Tracer.Start(\n\t\t\t\tctx,\n\t\t\t\t\"toolbox/server/tool/init\",\n\t\t\t\ttrace.WithAttributes(attribute.String(\"tool_type\", tc.ToolConfigType())),\n\t\t\t\ttrace.WithAttributes(attribute.String(\"tool_name\", name)),\n\t\t\t)\n\t\t\tdefer span.End()\n\t\t\tt, err := tc.Initialize(ctx)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"unable to initialize tool %q: %w\", name, err)\n\t\t\t}\n\n\t\t\tif srcName := t.GetSourceName(); srcName != \"\" && sourcesMap != nil {\n\t\t\t\tvar ok bool\n\t\t\t\tsrc, ok = sourcesMap[srcName]\n\t\t\t\tif !ok && !cfg.SkipSourceValidation {\n\t\t\t\t\treturn nil, fmt.Errorf(\"unable to retrieve source %q for tool %q\", srcName, name)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif !cfg.SkipSourceValidation {\n\t\t\t\terr = t.ValidateSource(src)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, err\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn t, nil\n\t\t}()\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\n\t\tif tools.ShouldSuppress(ctx, t, src) {\n\t\t\tcontinue\n\t\t}","sourceCodeStart":277,"sourceCodeEnd":313,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/server/server.go#L277-L313","documentation":"After a tool initializes successfully, initializeTools looks up the tool's declared source (t.GetSourceName()) in the initialized sourcesMap. If the source name is not found and source validation is enabled (SkipSourceValidation is false), startup fails because the tool points at a source that does not exist in the config.","triggerScenarios":"A tool entry in the config declares `source: some_name` but no source with that key exists under `sources:` in tools.yml, and the server is started normally (not the offline path, which sets SkipSourceValidation=true).","commonSituations":"Renamed or deleted source entries while tools still reference the old name, typos in the source key (map keys are case-sensitive), or copy-pasting tools between config files whose sources differ.","solutions":["Add or fix the `source:` reference in the tool config to match an existing key under `sources:`.","List your sources section and confirm the exact spelling/case of the key.","If the source intentionally varies per environment, template the config (envsubst) so names stay consistent."],"exampleFix":"// before (tools.yml)\ntools:\n  search_users:\n    kind: postgres-sql\n    source: postgress  # typo\n\n// after\nsources:\n  postgres:\n    kind: postgres\n    uri: ...\ntools:\n  search_users:\n    kind: postgres-sql\n    source: postgres","handlingStrategy":"validation","validationCode":"sources := cfg.Sources // map[string]SourceConfig\nfor name, tc := range cfg.ToolConfigs {\n    if src := tc.SourceName(); src != \"\" {\n        if _, ok := sources[src]; !ok {\n            return fmt.Errorf(\"tool %q references unknown source %q\", name, src)\n        }\n    }\n}","typeGuard":"func sourceExists(cfg server.ServerConfig, name string) bool {\n    _, ok := cfg.Sources[name]\n    return ok\n}","tryCatchPattern":"if _, err := server.NewServer(ctx, cfg); err != nil {\n    var src, tool string\n    if _, e := fmt.Sscanf(err.Error(), \"unable to retrieve source %q for tool %q\", &src, &tool); e == nil {\n        log.Printf(\"add or fix source %q used by tool %q\", src, tool)\n    }\n    return err\n}","preventionTips":["Keep source keys and tool `source:` references in one reviewed config file.","Use consistent naming conventions and copy-paste the exact key.","Add a config lint step that cross-references tool source names against defined sources.","Remember map keys are case-sensitive."],"tags":["go","sources","configuration","startup"],"backgroundTag":"missing-referenced-source","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"}