googleapis/mcp-toolbox · error
request failed with status
Error message
request failed with status %s: %s
What it means
The Database Insights API returned a non-200 status for queryStats:fetch. The error includes the HTTP status line and the raw response body so the caller can see the API's error payload (e.g. permission denied, resource not found).
Solutions
- Read the response body in the error — it contains the Google API error explanation
- Verify IAM permissions (e.g. roles/databaseinsights.viewer or cloudplatform scope authorization) on the parent project
- Confirm the API (databaseinsights.googleapis.com) is enabled and the parent project/location/instance exist
- Check req.Parent format: projects/PROJECT/locations/REGION (and any required segments)
- Retry with backoff on 5xx; fix request/permissions on 4xx
Example fix
// before req.Parent = "projects/wrong-proj/locations/us-central1" // 403/404 // after req.Parent = "projects/my-actual-project/locations/us-central1"
Defensive patterns
Strategy: try-catch
Validate before calling
// preflight IAM check with the same credentials
creds, _ := google.FindDefaultCredentials(ctx, "https://www.googleapis.com/auth/cloud-platform")
tok, _ := creds.TokenSource.Token()
req2, _ := http.NewRequestWithContext(ctx, "GET", "https://databaseinsights.googleapis.com/v1beta/"+parent, nil)
req2.Header.Set("Authorization", "Bearer "+tok.AccessToken)
resp, _ := http.DefaultClient.Do(req2)
if resp.StatusCode != 200 { return fmt.Errorf("preflight failed: %s", resp.Status) } Try / catch
resp, err := src.FetchQueryStats(ctx, req)
if err != nil {
var apiErr struct{ Status string; Body string }
if strings.Contains(err.Error(), "request failed with status") {
if strings.Contains(err.Error(), "403") { /* fix IAM permissions */ }
if strings.Contains(err.Error(), "404") { /* verify parent resource exists */ }
if strings.Contains(err.Error(), " 5") { /* retry with backoff */ }
}
return err
} Prevention
- Grant the service account Database Insights viewer roles before deployment
- Enable the databaseinsights.googleapis.com API on the project
- Validate project IDs and regions in configuration
- Implement backoff retry for 5xx statuses
When it happens
Trigger: Server responded 4xx/5xx: invalid or unauthorized parent resource, missing databaseinsights.roles/viewer permissions, nonexistent project/location, malformed request rejected by the API, or API outage (5xx).
Common situations: Service account lacking the required Database Insights IAM roles; typo in project ID or region in req.Parent; API not enabled on the project; querying an instance that doesn't exist.
Related errors
- get_schema API error
- API returned non-200 status
- executePipeline API error
- failed to search for VM
- request failed: , body
AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05).
Data as JSON: /api/errors/f663222555aad00b.
Report an issue: GitHub.
Appendix: source
Thrown at internal/sources/databaseinsights/databaseinsights.go:385
if err != nil {
return nil, fmt.Errorf("failed to marshal request: %w", err)
}
httpReq, err := http.NewRequestWithContext(ctx, "POST", url, bytes.NewBuffer(bodyBytes))
if err != nil {
return nil, fmt.Errorf("failed to create http request: %w", err)
}
httpReq.Header.Set("Content-Type", "application/json")
resp, err := s.httpClient.Do(httpReq)
if err != nil {
return nil, fmt.Errorf("failed to execute request: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
respBody, _ := io.ReadAll(resp.Body)
return nil, fmt.Errorf("request failed with status %s: %s", resp.Status, string(respBody))
}
var fetchResp FetchQueryStatsResponse
if err := json.NewDecoder(resp.Body).Decode(&fetchResp); err != nil {
return nil, fmt.Errorf("failed to decode response: %w", err)
}
return &fetchResp, nil
}
// FetchWaitEventStats executes the FetchWaitEventStats REST API method.
func (s *Source) FetchWaitEventStats(ctx context.Context, req *FetchWaitEventStatsRequest) (*FetchWaitEventStatsResponse, error) {
url := fmt.Sprintf("%s/v1beta/%s/waitEventStats:fetch", s.getEndpointForParent(req.Parent), req.Parent)
bodyBytes, err := json.Marshal(req)
if err != nil {
return nil, fmt.Errorf("failed to marshal request: %w", err)
}View on GitHub (pinned to 8cc6e09de2)