{"record":{"id":"7db6fd96f15cce26","repo":"googleapis/mcp-toolbox","slug":"invalid-source-for-q-tool-source-q-is-not-a-com-7db6fd","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/cloudsqlcreateusers/cloudsqlcreateusers.go","lineNumber":100,"sourceCode":"}\n\n// Tool represents the create-user 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/cloudsqlcreateusers/cloudsqlcreateusers.go#L82-L118","documentation":"This error is thrown by Tool.ValidateSource when the source bound to the cloud-sql-create-users tool does not implement the tool's private compatibleSource interface (GetDefaultProject, UseClientAuthorization, CreateUsers). MCP Toolbox tools are generic over sources.Source, so at config-resolution time each tool type-asserts its source; a mismatch means the tool was wired to a source kind it cannot operate on (e.g. a plain Postgres source instead of a cloudsql admin source). It is a configuration/typing failure, not a runtime network or SQL failure.","triggerScenarios":"Calling ValidateSource (via server toolset initialization or Invoke dispatch) with a sources.Source that fails the source.(compatibleSource) type assertion — e.g. a cloudsqlcreateusers Tool resolved against a postgres, mysql, or bigquery Source instead of a Cloud SQL Admin source whose type implements CreateUsers/GetDefaultProject/UseClientAuthorization.","commonSituations":"Developers hit this when their tools.yaml binds cloud-sql-create-users to the wrong source kind, when a custom/older source implementation does not implement the current compatibleSource interface (API surface changed across toolbox versions), or when programmatically constructing the tool and passing a source of the wrong concrete type.","solutions":["Check the tools.yaml: ensure the tool's source is a Cloud SQL Admin-compatible source (kind: cloud-sql-admin or equivalent that implements CreateUsers), not a database-connection source like postgres/mysql.","If using a custom source, implement all methods of the tool's compatibleSource interface: GetDefaultProject() string, UseClientAuthorization() bool, and CreateUsers(context.Context, string, string, string, string, bool, string) (any, error).","Upgrade the source package and tool package together so their interfaces match; the compatibleSource interface can change between versions.","Before calling Invoke/GetParameters, call tool.ValidateSource(yourSource) explicitly to fail fast with this same message.","Print the concrete type of the source (fmt.Printf(\"%T\", src)) and compare it with the source kind the tool expects."],"exampleFix":"// before (tools.yaml)\ntools:\n  create-users:\n    kind: cloud-sql-create-users\n    source: my-postgres-instance   # wrong source kind\n// after\ntools:\n  create-users:\n    kind: cloud-sql-create-users\n    source: my-cloudsql-admin      # source implementing compatibleSource","handlingStrategy":"type-guard","validationCode":"type compatibleSource interface {\n\tGetDefaultProject() string\n\tUseClientAuthorization() bool\n\tCreateUsers(context.Context, string, string, string, string, bool, string) (any, error)\n}\nif _, ok := src.(compatibleSource); !ok {\n\treturn fmt.Errorf(\"source %T is not compatible with cloud-sql-create-users\", src)\n}","typeGuard":"func isCreateUsersSource(s sources.Source) bool {\n\t_, ok := s.(interface {\n\t\tGetDefaultProject() string\n\t\tUseClientAuthorization() bool\n\t\tCreateUsers(context.Context, string, string, string, string, bool, string) (any, error)\n\t})\n\treturn ok\n}","tryCatchPattern":"if err := tool.ValidateSource(src); err != nil {\n\tvar typeErr *fmt.Errorf\n\tlog.Fatalf(\"source/tool mismatch: %v — check tools.yaml source binding\", err)\n}","preventionTips":["In tools.yaml, always pair cloud-sql-* Admin tools with a Cloud SQL Admin source, not a DB connection source","Call ValidateSource at startup for every tool/source pair so mismatches fail before serving traffic","When writing custom sources, compile against a throwaway assertion: var _ compatibleSource = mySource{}","Keep source and tool packages on the same version in go.mod","Log %T of the source during bootstrap to spot wrong bindings early"],"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"}