{"record":{"id":"0051cbda126229ac","repo":"googleapis/mcp-toolbox","slug":"failed-to-find-default-credentials-w-0051cb","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/cloudsqladmin/cloud_sql_admin.go","lineNumber":90,"sourceCode":"}\n\n// Initialize initializes a CloudSQL Admin Source instance.\nfunc (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {\n\tua, err := util.UserAgentFromContext(ctx)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error in User Agent retrieval: %s\", err)\n\t}\n\n\tvar client *http.Client\n\tif r.UseClientOAuth {\n\t\tclient = &http.Client{\n\t\t\tTransport: util.NewUserAgentRoundTripper(ua, http.DefaultTransport),\n\t\t}\n\t} else {\n\t\t// Use Application Default Credentials\n\t\tcreds, err := google.FindDefaultCredentials(ctx, sqladmin.SqlserviceAdminScope)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to find default credentials: %w\", err)\n\t\t}\n\t\tbaseClient := oauth2.NewClient(ctx, creds.TokenSource)\n\t\tbaseClient.Transport = util.NewUserAgentRoundTripper(ua, baseClient.Transport)\n\t\tclient = baseClient\n\t}\n\n\tservice, err := sqladmin.NewService(ctx, option.WithHTTPClient(client))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error creating new sqladmin service: %w\", err)\n\t}\n\n\ts := &Source{\n\t\tConfig:  r,\n\t\tBaseURL: \"https://sqladmin.googleapis.com\",\n\t\tService: service,\n\t}\n\treturn s, nil\n}","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/cloudsqladmin/cloud_sql_admin.go#L72-L108","documentation":"This error wraps google.FindDefaultCredentials failing to locate Application Default Credentials for the Cloud SQL Admin API scope (sqladmin.SqlserviceAdminScope). It occurs in Initialize when UseClientOAuth is false and no ADC chain can be found in the environment.","triggerScenarios":"Initializing a cloudsqladmin source with UseClientOAuth=false while no credential source exists: GOOGLE_APPLICATION_CREDENTIALS unset or pointing to a missing/invalid key, no gcloud user credentials, and no GCE metadata server.","commonSituations":"Running the toolbox outside GCP without a service-account key; forgetting 'gcloud auth application-default login'; container images without credentials mounted; key files with wrong permissions.","solutions":["Run 'gcloud auth application-default login' for local development","Set GOOGLE_APPLICATION_CREDENTIALS to a valid Cloud SQL Admin-capable service-account JSON key","Enable UseClientOAuth and supply client access tokens instead of server ADC","Verify the Cloud SQL Admin API is enabled and the account has cloudsql Admin roles"],"exampleFix":"// before\ncreds, err := google.FindDefaultCredentials(ctx, sqladmin.SqlserviceAdminScope) // no ADC\n// after\nexport GOOGLE_APPLICATION_CREDENTIALS=/path/to/sa.json\ncreds, err := google.FindDefaultCredentials(ctx, sqladmin.SqlserviceAdminScope)","handlingStrategy":"fallback","validationCode":"creds, err := google.FindDefaultCredentials(ctx, sqladmin.SqlserviceAdminScope)\nif err != nil {\n    return fmt.Errorf(\"ADC unavailable before init: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err != nil {\n    if strings.Contains(err.Error(), \"could not find default credentials\") {\n        log.Fatal(\"run 'gcloud auth application-default login' or set GOOGLE_APPLICATION_CREDENTIALS\")\n    }\n    return err\n}","preventionTips":["Set GOOGLE_APPLICATION_CREDENTIALS in deployment manifests","Ensure the service account has Cloud SQL Admin roles","Run ADC login during local dev setup","Prefer attached service accounts on GCP runtimes over key files"],"tags":["gcp","cloud-sql","authentication","adc","go"],"backgroundTag":"google-default-credentials-not-found","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"}