{"record":{"id":"70505c941dd6e7d7","repo":"googleapis/mcp-toolbox","slug":"error-creating-new-sqladmin-service-w","errorCode":null,"errorMessage":"error creating new sqladmin service: %w","messagePattern":"error creating new sqladmin service: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/sources/cloudsqladmin/cloud_sql_admin.go","lineNumber":99,"sourceCode":"\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}\n\nvar _ sources.Source = &Source{}\n\ntype Source struct {\n\tConfig\n\tBaseURL string\n\tService *sqladmin.Service\n}\n","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/cloudsqladmin/cloud_sql_admin.go#L81-L117","documentation":"Thrown in Source.Initialize when constructing the Cloud SQL Admin API client via sqladmin.NewService fails. This is the last step of source initialization, so any failure building the HTTP client wrapped around the ADC (Application Default Credentials) or the explicitly provided client surfaces here.","triggerScenarios":"Calling Initialize (e.g. at toolbox startup parsing the cloudsql-postgres/cloudsql-mysql source config) when sqladmin.NewService cannot build a base HTTP client: invalid ADC, malformed GOOGLE_APPLICATION_CREDENTIALS file, or a bad option.WithHTTPClient composition.","commonSituations":"Deploying without gcloud auth application-default login; a service-account key JSON file that is missing, unreadable, or has invalid JSON; running in an environment with no metadata server and no credentials configured.","solutions":["Run `gcloud auth application-default login` locally, or set GOOGLE_APPLICATION_CREDENTIALS to a valid service-account key path.","Validate the credentials JSON file exists and parses (e.g. `python -c \"import json;json.load(open('key.json'))\"`).","When using MyCBCredentials/client injection, verify the custom http.Client passed via option.WithHTTPClient is non-nil and has a working transport.","Check network/proxy access to oauth2.googleapis.com, since token fetching happens during client construction/first use."],"exampleFix":"// before (broken env)\nos.Setenv(\"GOOGLE_APPLICATION_CREDENTIALS\", \"/path/to/missing.json\")\n// after\nos.Setenv(\"GOOGLE_APPLICATION_CREDENTIALS\", \"/secure/path/service-account.json\") // file exists + valid JSON","handlingStrategy":"validation","validationCode":"credPath := os.Getenv(\"GOOGLE_APPLICATION_CREDENTIALS\")\nif credPath == \"\" {\n    // rely on ADC/metadata server; verify one exists\n    if _, err := google.FindDefaultCredentials(context.Background(), sqladmin.CloudPlatformScope); err != nil {\n        return fmt.Errorf(\"no GCP credentials available for Cloud SQL admin: %w\", err)\n    }\n} else if _, err := os.Stat(credPath); err != nil {\n    return fmt.Errorf(\"credential file not found: %w\", err)\n}","typeGuard":"func hasValidGCPCreds(ctx context.Context) bool {\n    _, err := google.FindDefaultCredentials(ctx, sqladmin.CloudPlatformScope)\n    return err == nil\n}","tryCatchPattern":"src, err := cloudsqladminSource.Initialize(ctx, cfg)\nif err != nil {\n    var gerr *googleapi.Error\n    if errors.As(err, &gerr) {\n        log.Printf(\"sqladmin init failed [%d]: %s\", gerr.Code, gerr.Message)\n    }\n    return fmt.Errorf(\"cloudsqladmin source init failed: %w\", err)\n}","preventionTips":["Run `gcloud auth application-default login` in dev before starting the toolbox.","Set GOOGLE_APPLICATION_CREDENTIALS in the deployment environment and mount the key file.","Use workload identity / attached service accounts in GCP instead of key files.","Smoke-test credentials with `gcloud sql instances list` before starting the server."],"tags":["gcp","authentication","cloud-sql","initialization"],"backgroundTag":"missing-application-default-credentials","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"}