{"record":{"id":"bd3b354806d55424","repo":"googleapis/mcp-toolbox","slug":"invalid-source-for-q-tool-source-q-is-not-a-com-bd3b35","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":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/tools/cloudloggingadmin/cloudloggingadminlistresourcetypes/cloudloggingadminlistresourcetypes.go","lineNumber":112,"sourceCode":"\tvar err error\n\tif source.UseClientAuthorization() {\n\t\ttokenString, err = accessToken.ParseBearerToken()\n\t\tif err != nil {\n\t\t\treturn nil, util.NewClientServerError(\"failed to parse access token\", http.StatusUnauthorized, err)\n\t\t}\n\t}\n\n\tresp, err := source.ListResourceTypes(ctx, tokenString)\n\tif err != nil {\n\t\treturn nil, util.ProcessGcpError(err)\n\t}\n\treturn resp, nil\n}\n\nfunc (t Tool) RequiresClientAuthorization(source sources.Source) (bool, error) {\n\ts, ok := source.(compatibleSource)\n\tif !ok {\n\t\treturn false, fmt.Errorf(\"invalid source for %q tool: source %q is not a compatible type\", t.Cfg.Type, t.Cfg.Source)\n\t}\n\treturn s.UseClientAuthorization(), nil\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","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/tools/cloudloggingadmin/cloudloggingadminlistresourcetypes/cloudloggingadminlistresourcetypes.go#L94-L130","documentation":"RequiresClientAuthorization on the cloudloggingadmin-list-resource-types tool asserts the injected source implements compatibleSource so it can query UseClientAuthorization(). A source of an incompatible Go type makes the assertion fail and the method returns this error instead of a boolean. The tool cannot determine its auth behavior without the right source type.","triggerScenarios":"Invoking the tool (server startup or per-call auth resolution) when the tool's configured source is not a Cloud Logging Admin-compatible source, e.g. a database source or a wrapped custom source missing UseClientAuthorization().","commonSituations":"Binding the tool to a source of the wrong kind in tools.yaml; custom sources implementing sources.Source but not the compatibleSource interface; refactors that changed the source's Go type after an upgrade.","solutions":["Bind the tool to a cloud-logging-admin source (one implementing compatibleSource).","If using a custom source wrapper, add a UseClientAuthorization() bool method so it satisfies compatibleSource.","Validate the config before serving so the mismatch surfaces at startup rather than during a request."],"exampleFix":"// before (custom source)\ntype mySource struct{}\nfunc (s mySource) SourceType() string { return \"my-source\" }\n// after\ntype mySource struct{ UseClientAuth bool }\nfunc (s mySource) SourceType() string { return \"my-source\" }\nfunc (s mySource) UseClientAuthorization() bool { return s.UseClientAuth }","handlingStrategy":"type-guard","validationCode":"// Go: assert source compatibility before invoking the tool\nif _, ok := src.(compatibleSource); !ok {\n    return false, fmt.Errorf(\"source %T does not support client authorization checks\", src)\n}","typeGuard":"func toCompatibleSource(s sources.Source) (compatibleSource, error) {\n    if cs, ok := s.(compatibleSource); ok {\n        return cs, nil\n    }\n    return nil, fmt.Errorf(\"incompatible source type %T\", s)\n}","tryCatchPattern":"useClientAuth, err := tool.RequiresClientAuthorization(src)\nif err != nil {\n    return fmt.Errorf(\"source binding invalid for tool %q: %w\", tool.GetName(), err)\n}","preventionTips":["Bind each tool only to sources of the matching kind.","Add compile-time assertions like `var _ compatibleSource = mySource{}` for custom sources.","Re-check source bindings after any refactor or toolbox version bump."],"tags":["go","auth","type-assertion","source-compatibility"],"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"}