googleapis/mcp-toolbox · error
%s: %s
Error message
%s: %s
What it means
wrapGCPProjectHint decorates errors raised while creating the GCP cloud trace/meter exporters. When the underlying error indicates Application Default Credentials could not detect a project, the error is prefixed with a hint to set --telemetry-gcp-project or GOOGLE_CLOUD_PROJECT and point GOOGLE_APPLICATION_CREDENTIALS at valid ADC credentials.
Source
Thrown at internal/telemetry/telemetry.go:203
metric.Instrument{Name: name},
metric.Stream{
Aggregation: metric.AggregationExplicitBucketHistogram{
Boundaries: durationBuckets,
},
},
))
}
metricOpts = append(metricOpts, metric.WithView(views...))
meterProvider := metric.NewMeterProvider(metricOpts...)
return meterProvider, nil
}
func wrapGCPProjectHint(err error) error {
message := err.Error()
if strings.Contains(message, "no project found with application default credentials") {
projectHint := "please ensure that `--telemetry-gcp-project` flag or `GOOGLE_CLOUD_PROJECT` env var is set, and `GOOGLE_APPLICATION_CREDENTIALS` points to valid ADC credentials"
return fmt.Errorf("%s: %s", projectHint, message)
}
return err
}
View on GitHub (pinned to 8cc6e09de2)
Solutions
- Set the --telemetry-gcp-project flag or the GOOGLE_CLOUD_PROJECT env var
- Point GOOGLE_APPLICATION_CREDENTIALS at a valid ADC credentials file containing project_id
- Run `gcloud auth application-default login` to establish ADC locally
- If GCP telemetry is unintended, switch the --telemetry output to a non-GCP exporter
Example fix
// before export GOOGLE_APPLICATION_CREDENTIALS=/path/key.json // after export GOOGLE_APPLICATION_CREDENTIALS=/path/key.json export GOOGLE_CLOUD_PROJECT=my-gcp-project
Defensive patterns
Strategy: validation
Validate before calling
if os.Getenv("GOOGLE_CLOUD_PROJECT") == "" && !flagSet("telemetry-gcp-project") &&
os.Getenv("GOOGLE_APPLICATION_CREDENTIALS") == "" {
log.Fatal("GCP telemetry requires GOOGLE_CLOUD_PROJECT (or --telemetry-gcp-project) and valid ADC credentials")
} Try / catch
if err := telemetry.SetupOTel(...); err != nil {
if strings.Contains(err.Error(), "no project found with application default credentials") {
log.Fatalf("GCP project hint: %v", err)
}
return err
} Prevention
- Always set GOOGLE_CLOUD_PROJECT when using GCP telemetry
- Verify ADC credentials contain a project_id claim
- Prefer workload identity on GCP over key files
When it happens
Trigger: Starting the server with GCP telemetry (newTracerProvider/newMeterProvider using cloud trace or monitoring exporters) when ADC finds no project: no --telemetry-gcp-project flag, no GOOGLE_CLOUD_PROJECT env var, and credentials without a project_id.
Common situations: Local/on-prem deployments with GCP telemetry configured; service-account key files missing project_id; GOOGLE_APPLICATION_CREDENTIALS lost after a container rebuild; workload identity not attached.
Related errors
- unable to get AlloyDB connection config: %w
- error creating client from ADC: %w
- failed to find default Google Cloud credentials: %w
- unable to create client: %w
- unable to create instance admin client: %w
AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05).
Data as JSON: /api/errors/2f6d257ef6dcffbd.
Report an issue: GitHub.