{"record":{"id":"e29b81db3beab479","repo":"googleapis/mcp-toolbox","slug":"invalid-source-for-q-tool-source-q-is-not-a-com-e29b81","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/cloudsqllistinstances/cloudsqllistinstances.go","lineNumber":100,"sourceCode":"}\n\n// Tool represents the list-instance 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\tresp, err := source.ListInstance(ctx, project, string(accessToken))\n\tif err != nil {","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/tools/cloudsql/cloudsqllistinstances/cloudsqllistinstances.go#L82-L118","documentation":"ValidateSource for the cloud-sql-list-instances tool checks that the bound source implements its compatibleSource interface and returns this error when the type assertion fails. The tool cannot run against sources lacking the Cloud SQL Admin surface (project lookup, client-authorization flag, ListInstances operation). The error always indicates the tool was paired with an incompatible source kind in configuration or programmatic setup.","triggerScenarios":"ValidateSource(source) during startup toolset validation or immediately before Invoke, with a sources.Source that does not implement the tool's compatibleSource methods — e.g. a postgres or bigquery source referenced by cloud-sql-list-instances in tools.yaml.","commonSituations":"tools.yaml pointing the tool at a DB connection source instead of a Cloud SQL Admin source; custom source missing required interface methods after a version bump; test stubs not implementing the full interface.","solutions":["Correct the tools.yaml source reference to a Cloud SQL Admin-compatible source.","Implement the complete compatibleSource interface (GetDefaultProject, UseClientAuthorization, ListInstances) on custom sources.","Keep tool and source package versions synchronized to avoid interface drift.","Call ValidateSource explicitly in custom initialization to fail fast.","Confirm the source's concrete type with fmt.Printf(\"%T\", src)."],"exampleFix":"// before\nlistInstances.ValidateSource(postgresSource) // incompatible\n// after\nlistInstances.ValidateSource(cloudsqlAdminSource) // implements compatibleSource","handlingStrategy":"type-guard","validationCode":"if _, ok := src.(compatibleSource); !ok {\n\treturn fmt.Errorf(\"source %T cannot back cloud-sql-list-instances\", src)\n}","typeGuard":"func isListInstancesSource(s sources.Source) bool {\n\t_, ok := s.(compatibleSource)\n\treturn ok\n}","tryCatchPattern":"if err := tool.ValidateSource(src); err != nil {\n\treturn fmt.Errorf(\"cloud-sql-list-instances bound to wrong source: %w\", err)\n}","preventionTips":["Verify the tools.yaml source reference points to a Cloud SQL Admin source","Add compile-time interface assertions to custom source implementations","Call ValidateSource for each tool at startup before serving","Upgrade tool and source packages together","Print the source's concrete type during bootstrap diagnostics"],"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"}