{"record":{"id":"da8babbdf7168b11","repo":"googleapis/mcp-toolbox","slug":"failed-to-find-default-credentials-w-da8bab","errorCode":null,"errorMessage":"failed to find default credentials: %w","messagePattern":"failed to find default credentials: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/cloudgda/cloud_gda.go","lineNumber":119,"sourceCode":"\treturn SourceType\n}\n\nfunc (s *Source) ToConfig() sources.SourceConfig {\n\treturn s.Config\n}\n\nfunc (s *Source) GetProjectID() string {\n\treturn s.ProjectID\n}\n\nfunc (s *Source) GoogleCloudTokenSourceWithScope(ctx context.Context, scope string) (oauth2.TokenSource, error) {\n\tif scope == \"\" {\n\t\tscope = CloudPlatformScope\n\t}\n\n\tcreds, err := google.FindDefaultCredentials(ctx, scope)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to find default credentials: %w\", err)\n\t}\n\treturn creds.TokenSource, nil\n}\n\nfunc (s *Source) UseClientAuthorization() bool {\n\treturn s.UseClientOAuth\n}\n\nfunc (s *Source) GetClient(ctx context.Context, tokenStr string) (*geminidataanalytics.DataChatClient, func(), error) {\n\tif s.UseClientOAuth {\n\t\tif tokenStr == \"\" {\n\t\t\treturn nil, nil, fmt.Errorf(\"client-side OAuth is enabled but no access token was provided\")\n\t\t}\n\t\ttoken := &oauth2.Token{AccessToken: tokenStr}\n\t\topts := []option.ClientOption{\n\t\t\toption.WithUserAgent(s.userAgent),\n\t\t\toption.WithTokenSource(oauth2.StaticTokenSource(token)),\n\t\t}","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/cloudgda/cloud_gda.go#L101-L137","documentation":"GoogleCloudTokenSourceWithScope calls google.FindDefaultCredentials to obtain a token source for calling Gemini Data Analytics, wrapping any failure. It means no Application Default Credentials could be located for the given scope.","triggerScenarios":"Calling RunQuery on a cloudgda source (server-OAuth path) in an environment where neither GOOGLE_APPLICATION_CREDENTIALS points to a valid key file, gcloud ADC exist, nor a GCE metadata server is reachable; scope falls back to CloudPlatformScope when empty.","commonSituations":"Local development outside GCP without running 'gcloud auth application-default login', Docker containers without the service-account key mounted, or a malformed credentials JSON file.","solutions":["Run 'gcloud auth application-default login' on dev machines","Set GOOGLE_APPLICATION_CREDENTIALS to a valid service-account JSON key in containers/CI","Verify the key file is readable and valid JSON with the required scopes","Alternatively configure the source with UseClientOAuth so the caller supplies the token"],"exampleFix":"// before\n# container has no credentials\nexport GOOGLE_APPLICATION_CREDENTIALS=/missing/key.json\n// after\ngcloud auth application-default login\n# or in Docker\ndocker run -v $HOME/.config/gcloud/application_default_credentials.json:/adc.json -e GOOGLE_APPLICATION_CREDENTIALS=/adc.json ...","handlingStrategy":"try-catch","validationCode":"import \"google.golang.org/api/option\"\n// pre-check before calling the tool\nif _, err := google.FindDefaultCredentials(ctx, \"https://www.googleapis.com/auth/cloud-platform\"); err != nil {\n    return fmt.Errorf(\"run 'gcloud auth application-default login' or set GOOGLE_APPLICATION_CREDENTIALS: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"// Go: detect ADC failure distinctly\nif err != nil {\n    var adcErr *google.Error\n    if strings.Contains(err.Error(), \"default credentials\") {\n        return fmt.Errorf(\"ADC not configured: %w\", err)\n    }\n    return err\n}","preventionTips":["Run gcloud auth application-default login on dev machines","Mount/point GOOGLE_APPLICATION_CREDENTIALS in Docker and CI","Validate the key JSON parses before deployment","Prefer UseClientOAuth in multi-tenant deployments"],"tags":["cloudgda","google-cloud","authentication","adc"],"backgroundTag":"adc-credentials-missing","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"}