googleapis/mcp-toolbox · error
failed to create Cloud Logging Admin client for project %q:
Error message
failed to create Cloud Logging Admin client for project %q: %w
What it means
This error wraps failures from logadmin.NewClient when creating a Cloud Logging Admin client for a specific GCP project. It is thrown by initLogAdminConnection during source initialization when the underlying Google Cloud Logging client cannot be constructed. The wrapped error (%w) carries the root cause, typically credential, option, or project-ID problems.
Source
Thrown at internal/sources/cloudloggingadmin/cloud_logging_admin.go:404
option.WithUserAgent(userAgent),
option.WithTokenSource(cloudPlatformTokenSource),
}
} else {
// Use default credentials
cred, err := google.FindDefaultCredentials(ctx, logging.AdminScope)
if err != nil {
return nil, nil, fmt.Errorf("failed to find default Google Cloud credentials with scope %q: %w", logging.AdminScope, err)
}
tokenSource = cred.TokenSource
opts = []option.ClientOption{
option.WithUserAgent(userAgent),
option.WithCredentials(cred),
}
}
client, err := logadmin.NewClient(ctx, project, opts...)
if err != nil {
return nil, nil, fmt.Errorf("failed to create Cloud Logging Admin client for project %q: %w", project, err)
}
return client, tokenSource, nil
}
func initLogAdminConnectionWithOAuthToken(
ctx context.Context,
tracer trace.Tracer,
project, name, userAgent, tokenString string,
) (*logadmin.Client, error) {
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceType, name)
defer span.End()
token := &oauth2.Token{
AccessToken: string(tokenString),
}
ts := oauth2.StaticTokenSource(token)
// Initialize the logadmin client with tokenSourceView on GitHub (pinned to 8cc6e09de2)
Solutions
- Check the wrapped %w cause and fix the underlying credential/project issue (usually ADC setup)
- Set GOOGLE_APPLICATION_CREDENTIALS to a valid service-account key file or run 'gcloud auth application-default login'
- Verify the project ID string is correct and the Logging API (logging.googleapis.com) is enabled
- Confirm network/proxy reachability to googleapis.com
Example fix
// before
client, err := logadmin.NewClient(ctx, project) // no creds configured
// after
os.Setenv("GOOGLE_APPLICATION_CREDENTIALS", "/path/to/sa.json")
client, err := logadmin.NewClient(ctx, project, option.WithCredentialsFile("/path/to/sa.json")) Defensive patterns
Strategy: validation
Validate before calling
if os.Getenv("GOOGLE_APPLICATION_CREDENTIALS") == "" {
if _, err := os.Stat(os.Getenv("HOME") + "/.config/gcloud/application_default_credentials.json"); err != nil {
return fmt.Errorf("no ADC available: run 'gcloud auth application-default login'")
}
}
if project == "" { return fmt.Errorf("project ID must not be empty") } Try / catch
if err != nil {
var wrapped error
if errors.As(err, &wrapped) {
log.Printf("logadmin client creation failed: %v", wrapped)
}
return err
} Prevention
- Validate ADC availability at startup before creating sources
- Validate the project ID format (non-empty, lowercase, hyphens)
- Enable the Cloud Logging API on the target project
- Test connectivity to googleapis.com from the deployment environment
When it happens
Trigger: Calling Initialize on a cloudloggingadmin source where logadmin.NewClient(ctx, project, opts...) returns an error — e.g. invalid credentials in opts, malformed project ID, or failure building gRPC/REST transport options.
Common situations: Missing or invalid Application Default Credentials (GOOGLE_APPLICATION_CREDENTIALS not set, malformed service-account JSON); wrong project ID; network/DNS failure reaching the Logging API; unsupported credential option combination.
Related errors
- failed to create logadmin client for project %q: %w
- failed to find default credentials: %w
- failed to find default credentials: %w
- unable to connect successfully: %w
- password is provided without a username. Please provide both
AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05).
Data as JSON: /api/errors/6a8c8bfe87bfea11.
Report an issue: GitHub.