googleapis/mcp-toolbox · error

failed to create request: %w

Error message

failed to create request: %w

What it means

After marshaling, getStream builds the HTTP POST request to the Conversational Analytics `:chat` endpoint with http.NewRequest. If the URL is malformed or the method/body is invalid, this wrapped error is returned. It indicates the request could not even be constructed, before any network I/O occurs.

Source

Thrown at internal/tools/bigquery/bigqueryconversationalanalytics/bigqueryconversationalanalytics.go:277

}

func (t Tool) RequiresClientAuthorization(source sources.Source) (bool, error) {
	s, ok := source.(compatibleSource)
	if !ok {
		return false, fmt.Errorf("invalid source for %q tool: source %q is not a compatible type", t.Cfg.Type, t.Cfg.Source)
	}
	return s.UseClientAuthorization(), nil
}

func getStream(client *http.Client, url string, payload CAPayload, headers map[string]string, maxRows int) (string, error) {
	payloadBytes, err := json.Marshal(payload)
	if err != nil {
		return "", fmt.Errorf("failed to marshal payload: %w", err)
	}

	req, err := http.NewRequest("POST", url, bytes.NewBuffer(payloadBytes))
	if err != nil {
		return "", fmt.Errorf("failed to create request: %w", err)
	}
	for k, v := range headers {
		req.Header.Set(k, v)
	}

	resp, err := client.Do(req)
	if err != nil {
		return "", fmt.Errorf("failed to send request: %w", err)
	}
	defer resp.Body.Close()

	if resp.StatusCode != http.StatusOK {
		body, _ := io.ReadAll(resp.Body)
		return "", fmt.Errorf("API returned non-200 status: %d %s", resp.StatusCode, string(body))
	}

	var messages []map[string]any
	decoder := json.NewDecoder(resp.Body)

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Check the environment variable controlling the GDA endpoint (util.GetGDAEndpoint) — unset it to use the default https://api.googleapis.com style endpoint.
  2. Ensure the endpoint value includes a valid scheme (https://) and no whitespace.
  3. Verify the source's BigQuery project and location strings are valid (no illegal URL characters), since they are interpolated into the URL.
  4. Log the final URL and paste it into a parser/curl to confirm validity.

Example fix

// before
export GDA_ENDPOINT="api.googleapis.com v1"
// after
unset GDA_ENDPOINT  # or export GDA_ENDPOINT="https://custom-endpoint.example.com"
Defensive patterns

Strategy: validation

Validate before calling

u, err := url.Parse(endpoint)
if err != nil || u.Scheme == "" || u.Host == "" {
    return fmt.Errorf("invalid GDA endpoint: %q", endpoint)
}

Try / catch

result, err := tool.Invoke(ctx, params)
if err != nil && strings.Contains(err.Error(), "failed to create request") {
    return fmt.Errorf("check endpoint configuration: %w", err)
}

Prevention

When it happens

Trigger: Invoke on the tool when the resolved endpoint URL (util.GetGDAEndpoint() formatted with project/location) is malformed — e.g. an invalid GDA endpoint override producing a non-parseable URL.

Common situations: Misconfigured endpoint environment variable (e.g. GDA endpoint override with spaces or missing scheme); proxy or region-poke endpoints with wrong formatting; typos when overriding the default googleapis endpoint for testing.

Related errors


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