googleapis/mcp-toolbox · error
failed to read response body: %w
Error message
failed to read response body: %w
What it means
RunQuery performs an HTTP call to the Cloud Monitoring API and reads the entire response body with io.ReadAll. If that read fails (connection reset mid-response, truncated body, timeouts, interrupted transfer), the error is wrapped with this message.
Source
Thrown at internal/sources/cloudmonitoring/cloud_monitoring.go:163
if err != nil {
return nil, err
}
q := req.URL.Query()
q.Add("query", query)
req.URL.RawQuery = q.Encode()
req.Header.Set("User-Agent", s.UserAgent())
resp, err := s.Client().Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("failed to read response body: %w", err)
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("request failed: %s, body: %s", resp.Status, string(body))
}
if len(body) == 0 {
return nil, nil
}
var result map[string]any
if err := json.Unmarshal(body, &result); err != nil {
return nil, fmt.Errorf("failed to unmarshal json: %w, body: %s", err, string(body))
}
return result, nil
}
View on GitHub (pinned to 8cc6e09de2)
Solutions
- Retry the query; the failure is often transient
- Set/raise HTTP client timeouts and keep-alive settings
- Bypass or reconfigure intermediate proxies that truncate responses
- Check Cloud Monitoring API status and response size (narrow the query time window or filters)
Example fix
// before
body, err := io.ReadAll(resp.Body)
if err != nil { return nil, fmt.Errorf("failed to read response body: %w", err) }
// after
// retry the request with backoff
client.Timeout = 120 * time.Second
body, err := io.ReadAll(resp.Body) Defensive patterns
Strategy: retry
Try / catch
var result map[string]any
err := retry(3, backoff, func() error {
result, err = src.RunQuery(ctx, query)
if err != nil && strings.Contains(err.Error(), "failed to read response body") {
return err // retryable
}
return nil
}) Prevention
- Set generous HTTP client timeouts for large queries
- Narrow query time ranges to reduce response size
- Check proxy idle-timeout settings
- Monitor network reliability in the deployment environment
When it happens
Trigger: Executing a monitoring query where the HTTP response body cannot be fully read — server closes connection early, proxy truncates the response, or transient network failure during body transfer.
Common situations: Flaky networks or long-running queries hitting idle timeouts; corporate proxies/CDNs dropping large responses; server-side 5xx with abrupt connection termination.
Related errors
- failed to fetch OIDC config: %w
- failed to read introspection response: %w
- request failed: %s, body: %s
- failed to unmarshal json: %w, body: %s
- failed to execute request: %w
AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05).
Data as JSON: /api/errors/b4ee486a0523f855.
Report an issue: GitHub.