googleapis/mcp-toolbox · error

unexpected status code: %d, response body: %s

Error message

unexpected status code: %d, response body: %s

What it means

Error "unexpected status code: %d, response body: %s" thrown in googleapis/mcp-toolbox.

Source

Thrown at internal/sources/http/http.go:219

	return s.client
}

func (s *Source) RunRequest(ctx context.Context, req *http.Request) (any, error) {
	// Make request and fetch response
	resp, err := s.Client().Do(req)
	if err != nil {
		return nil, fmt.Errorf("error making HTTP request: %s", err)
	}
	defer resp.Body.Close()

	var body []byte
	body, err = io.ReadAll(resp.Body)
	if err != nil {
		return nil, err
	}
	if resp.StatusCode < 200 || resp.StatusCode > 299 {
		if s.ReturnFullError {
			return nil, fmt.Errorf("unexpected status code: %d, response body: %s", resp.StatusCode, string(body))
		}

		logger, err := util.LoggerFromContext(ctx)
		if err != nil {
			return nil, fmt.Errorf("unable to get logger from ctx: %s", err)
		}
		logger.DebugContext(ctx, "http source upstream error", "status", resp.StatusCode, "body", truncateForLog(body, maxErrorBodyLogBytes))

		statusText := http.StatusText(resp.StatusCode)
		if statusText != "" {
			return nil, fmt.Errorf("unexpected status code: %d (%s)", resp.StatusCode, statusText)
		}
		return nil, fmt.Errorf("unexpected status code: %d", resp.StatusCode)
	}

	var data any
	if err = json.Unmarshal(body, &data); err != nil {
		// if unable to unmarshal data, return result as string.

View on GitHub (pinned to 8cc6e09de2)

When it happens

Trigger: Thrown at internal/sources/http/http.go:219 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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