googleapis/mcp-toolbox · critical

failed to create BigQuery client for project %q: %w

Error message

failed to create BigQuery client for project %q: %w

What it means

This error is thrown when bigquery.NewClient (cloud.google.com/go/bigquery) fails to construct the high-level BigQuery client for the configured project, after credentials/token source resolution succeeded. The error wraps the underlying failure — usually an authentication option conflict, invalid client options, or an initial API/transport problem. The project ID is included for diagnosis.

Source

Thrown at internal/sources/bigquery/bigquery.go:818

		}
		tokenSource = cred.TokenSource
		opts = []option.ClientOption{
			option.WithUserAgent(userAgent),
			option.WithCredentials(cred),
		}
	}

	if endpoint != "" {
		opts = append(opts, option.WithEndpoint(endpoint))
	}
	if quotaProject != "" {
		opts = append(opts, option.WithQuotaProject(quotaProject))
	}

	// Initialize the high-level BigQuery client
	client, err := bigqueryapi.NewClient(ctx, project, opts...)
	if err != nil {
		return nil, nil, nil, fmt.Errorf("failed to create BigQuery client for project %q: %w", project, err)
	}
	client.Location = location

	// Initialize the low-level BigQuery REST service using the same credentials
	restService, err := bigqueryrestapi.NewService(ctx, opts...)
	if err != nil {
		return nil, nil, nil, fmt.Errorf("failed to create BigQuery v2 service: %w", err)
	}

	return client, restService, tokenSource, nil
}

// initBigQueryConnectionWithOAuthToken initialize a BigQuery client with an
// OAuth access token.
func initBigQueryConnectionWithOAuthToken(
	ctx context.Context,
	tracer trace.Tracer,
	project string,

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Verify the project ID in the source config exists and is spelled correctly (gcloud projects describe <id>).
  2. Confirm network/proxy access to bigquery.googleapis.com.
  3. Check that the configured quota project is valid and the caller has access to it.
  4. Inspect the wrapped error with errors.As (googleapi.Error) for precise HTTP status and message.
  5. Confirm credentials resolved earlier are valid for the project (bq ls --project_id=<id>).

Example fix

// before (my-sdk.yaml)
sources:
  my-bq:
    kind: bigquery
    project: my-projekt  // typo
// after
sources:
  my-bq:
    kind: bigquery
    project: my-project
Defensive patterns

Strategy: validation

Validate before calling

// Verify project and connectivity before client creation
project := "my-project"
out, err := exec.Command("gcloud", "projects", "describe", project, "--format=value(projectId)").CombinedOutput()
if err != nil {
  return fmt.Errorf("project %q invalid or inaccessible: %v: %s", project, err, out)
}
// And a smoke test that credentials + project work:
// bq ls --project_id=%s --max_results=1

Try / catch

// Go
client, rest, ts, err := initBigQueryConnection(ctx, cfg)
if err != nil && strings.Contains(err.Error(), "failed to create BigQuery client") {
  var gerr *googleapi.Error
  if errors.As(err, &gerr) {
    log.Fatalf("BigQuery client creation failed (HTTP %d): %v", gerr.Code, gerr)
  }
  log.Fatalf("BigQuery client creation failed: %v — check project id, network, and quota project", err)
}

Prevention

When it happens

Trigger: bigqueryapi.NewClient(ctx, project, opts...) fails with the assembled options (user agent, token source or credentials, quota project) — e.g. an invalid project ID, conflicting client options, or an inability to reach the BigQuery API endpoint during client initialization.

Common situations: Typo or nonexistent project ID in the source config; quota project misconfigured; running where googleapis.com is blocked by a firewall/proxy; invalid combined credentials (both token source and credentials set incorrectly by a code change); wrong location/project pairing.

Related errors


AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05). Data as JSON: /api/errors/b08939756ab50c98. Report an issue: GitHub.