googleapis/mcp-toolbox · error
failed to read response body: %w
Error message
failed to read response body: %w
What it means
This error wraps a failure from io.ReadAll(resp.Body) in ExecuteMQL — the HTTP request succeeded and got a response, but the response body could not be fully read. This is rare and usually indicates the connection was reset or timed out mid-transfer, or the response body reader errored.
Source
Thrown at internal/sources/firestore/firestore.go:932
req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(bodyBytes))
if err != nil {
return nil, fmt.Errorf("failed to create HTTP request: %w", err)
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("User-Agent", userAgent)
req.Header.Set("x-goog-request-params", fmt.Sprintf("project_id=%s&database_id=%s", s.GetProjectId(), s.GetDatabaseId()))
req.Header.Set("x-goog-firestore-api-requester", "querydata")
resp, err := httpClient.Do(req)
if err != nil {
return nil, fmt.Errorf("failed to execute pipeline request: %w", err)
}
defer resp.Body.Close()
respBody, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("failed to read response body: %w", err)
}
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
return nil, fmt.Errorf("executePipeline API error (status %d): %s", resp.StatusCode, string(respBody))
}
var result any
if err := json.Unmarshal(respBody, &result); err != nil {
return string(respBody), nil
}
return result, nil
}
func initFirestoreConnection(
ctx context.Context,
tracer trace.Tracer,
name string,View on GitHub (pinned to 8cc6e09de2)
Solutions
- Retry the request — transient body-read failures usually resolve on a second attempt
- Check for proxies/load balancers truncating responses and increase their timeouts
- Increase the HTTP client/context timeout so large responses can finish streaming
Defensive patterns
Strategy: retry
Try / catch
res, err := src.ExecuteMQL(ctx, pipeline)
if err != nil && strings.Contains(err.Error(), "failed to read response body") {
// transient: safe to retry the whole request
res, err = src.ExecuteMQL(ctx, pipeline)
} Prevention
- Retry idempotent pipeline reads on body-read failures
- Check proxy/load-balancer timeouts for large responses
- Increase client/context timeout so the body can fully stream
When it happens
Trigger: io.ReadAll(resp.Body) returns non-nil err after httpClient.Do succeeded: the connection dropped while streaming the response, a decompression/reading error occurred, or the deadline expired during body read.
Common situations: Very large pipeline result sets truncated by an intermediate proxy; flaky network dropping keep-alive connections mid-body; timeout elapsing between receiving headers and finishing the body.
Related errors
- get_schema API error (status %d): %s
- failed to create HTTP request: %w
- failed to execute pipeline request: %w
- executePipeline API error (status %d): %s
- Toolbox binary not found
AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05).
Data as JSON: /api/errors/3d02c154aa9cb767.
Report an issue: GitHub.