{"record":{"id":"721ce024c25db20e","repo":"googleapis/mcp-toolbox","slug":"invalid-source-for-q-tool-source-q-is-not-a-com-721ce0","errorCode":null,"errorMessage":"invalid source for %q tool: source %q is not a compatible type","messagePattern":"invalid source for %q tool: source %q is not a compatible type","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/tools/cloudsql/cloudsqllistdatabases/cloudsqllistdatabases.go","lineNumber":100,"sourceCode":"}\n\n// Tool represents the list-databases tool.\ntype Tool struct {\n\ttools.BaseTool[Config]\n}\n\nfunc (t Tool) GetSourceName() string {\n\treturn t.Cfg.Source\n}\n\nfunc (t Tool) ToConfig() tools.ToolConfig {\n\treturn t.Cfg\n}\n\nfunc (t Tool) ValidateSource(source sources.Source) error {\n\t_, ok := source.(compatibleSource)\n\tif !ok {\n\t\treturn fmt.Errorf(\"invalid source for %q tool: source %q is not a compatible type\", t.Cfg.Type, t.Cfg.Source)\n\t}\n\treturn nil\n}\n\n// Invoke executes the tool's logic.\nfunc (t Tool) Invoke(ctx context.Context, s sources.Source, params parameters.ParamValues, accessToken tools.AccessToken) (any, util.ToolboxError) {\n\tsource, ok := s.(compatibleSource)\n\tif !ok {\n\t\treturn nil, util.NewClientServerError(\"source used is not compatible with the tool\", http.StatusInternalServerError, nil)\n\t}\n\tparamsMap := params.AsMap()\n\n\tproject, ok := paramsMap[\"project\"].(string)\n\tif !ok {\n\t\treturn nil, util.NewAgentError(\"missing 'project' parameter\", nil)\n\t}\n\tinstance, ok := paramsMap[\"instance\"].(string)\n\tif !ok {","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/tools/cloudsql/cloudsqllistdatabases/cloudsqllistdatabases.go#L82-L118","documentation":"ValidateSource for the cloud-sql-list-databases tool returns this error when the provided source does not satisfy the tool's compatibleSource interface, meaning the tool cannot operate on that source. The toolbox requires each Cloud SQL Admin tool's source to expose the Admin-API surface (project, client-authorization flag, list-databases operation). The error signals a config-level tool/source type mismatch that must be fixed before invocation.","triggerScenarios":"ValidateSource(source) (and the startup validation path that calls it) with a sources.Source that fails source.(compatibleSource) — for example pairing cloud-sql-list-databases with a postgres connection source or an alloydb admin source that does not implement ListDatabases/GetDefaultProject/UseClientAuthorization.","commonSituations":"Wrong source name in tools.yaml; a custom Cloud SQL source that lacks the newest interface methods after a toolbox upgrade; test harnesses passing partial mock sources.","solutions":["Ensure tools.yaml binds the tool to a Cloud SQL Admin-compatible source kind.","Complete compatibleSource implementation (GetDefaultProject, UseClientAuthorization, ListDatabases) on custom sources.","Upgrade source/tool packages together so interfaces match.","Call ValidateSource early in custom initialization to fail fast.","Verify the source's concrete type via %T before wiring it."],"exampleFix":"// before\nlistDatabases.ValidateSource(alloydbAdminSource) // incompatible\n// after\nlistDatabases.ValidateSource(cloudsqlAdminSource) // implements compatibleSource","handlingStrategy":"type-guard","validationCode":"if _, ok := src.(compatibleSource); !ok {\n\treturn fmt.Errorf(\"source %T incompatible with cloud-sql-list-databases\", src)\n}","typeGuard":"func isListDatabasesSource(s sources.Source) bool {\n\t_, ok := s.(interface {\n\t\tGetDefaultProject() string\n\t\tUseClientAuthorization() bool\n\t})\n\treturn ok\n}","tryCatchPattern":"if err := tool.ValidateSource(src); err != nil {\n\treturn fmt.Errorf(\"bad source binding for cloud-sql-list-databases: %w\", err)\n}","preventionTips":["Bind the tool to a Cloud SQL Admin source kind in tools.yaml","Compile-time assert custom sources: var _ compatibleSource = mySource{}","Validate every tool/source pair at startup","Avoid partial upgrades of toolbox packages","Log %T of sources during bootstrap"],"tags":["go","type-assertion","configuration","cloudsql","source-mismatch"],"backgroundTag":"incompatible-source-type","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"}