googleapis/mcp-toolbox · error
failed to create BigQuery v2 service
Error message
failed to create BigQuery v2 service: %w
What it means
This error is thrown when the low-level BigQuery REST service (google.golang.org/api/bigquery/v2) fails to initialize via bigqueryrestapi.NewService using the same client options as the high-level client. The toolbox builds both a high-level bigquery.Client and a raw REST service; failure here means the REST layer could not be created even though the high-level client succeeded. Wrapped causes are usually option validation or transport setup failures.
Solutions
- Inspect the wrapped error with errors.As/Unwrap to identify the exact cause.
- Verify any custom endpoint/base-URL option is a valid BigQuery v2 API URL.
- Ensure only one credential mechanism (token source or credentials) is applied consistently.
- Check network/proxy access to bigquery.googleapis.com and retry if transient.
Example fix
// before
opts := []option.ClientOption{
option.WithUserAgent(userAgent),
option.WithTokenSource(ts),
option.WithCredentials(cred), // conflicting credential options
}
// after
opts := []option.ClientOption{
option.WithUserAgent(userAgent),
option.WithTokenSource(ts), // single credential mechanism
} Defensive patterns
Strategy: try-catch
Validate before calling
// Validate connectivity to the BigQuery v2 endpoint first
resp, err := http.Get("https://bigquery.googleapis.com/")
if err != nil {
return fmt.Errorf("BigQuery API endpoint unreachable: %w", err)
}
resp.Body.Close() Try / catch
// Go
client, rest, ts, err := initBigQueryConnection(ctx, cfg)
if err != nil && strings.Contains(err.Error(), "failed to create BigQuery v2 service") {
// transient? retry once with backoff before failing startup
time.Sleep(2 * time.Second)
client, rest, ts, err = initBigQueryConnection(ctx, cfg)
if err != nil {
log.Fatalf("BigQuery v2 REST service init failed: %v — check endpoint/proxy and credential options", err)
}
} Prevention
- Avoid mixing option.WithTokenSource and option.WithCredentials in the same options slice.
- Check network/proxy access to bigquery.googleapis.com.
- If using a custom endpoint, verify it is a valid BigQuery v2 API URL.
- Retry service construction once on transient transport errors.
When it happens
Trigger: bigqueryrestapi.NewService(ctx, opts...) returns an error while constructing the REST client from the same opts (user agent, token source/credentials, quota project) — e.g. invalid option combination, failure resolving the API endpoint, or transport/credentials setup errors inside the google-api-go-client.
Common situations: Custom base URL / endpoint misconfiguration; proxy or firewall interfering with API endpoint resolution; incompatible or conflicting option.WithTokenSource plus option.WithCredentials values; intermittent transport errors during service construction.
Related errors
- failed to create BigQuery client for project
- error creating client from OAuth access token
- error decoding raw message
- failed to insert dry run job
- failed to send request
AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05).
Data as JSON: /api/errors/f38fadca13233342.
Report an issue: GitHub.
Appendix: source
Thrown at internal/sources/bigquery/bigquery.go:825
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,
location string,
quotaProject string,
name string,
userAgent string,
tokenString string,
wantRestService bool,
endpoint string,View on GitHub (pinned to 8cc6e09de2)