googleapis/mcp-toolbox · error

email field is not a string

Error message

email field is not a string

What it means

The `email` field in the tokeninfo response was present but not a JSON string (the type assertion to string failed) — an unexpected tokeninfo payload shape.

Source

Thrown at internal/sources/util.go:122

		return "", fmt.Errorf("tokeninfo endpoint returned non-OK status %d: %s", resp.StatusCode, string(bodyBytes))
	}

	// Unmarshal response body and get `email`
	var responseJSON map[string]any
	err = json.Unmarshal(bodyBytes, &responseJSON)
	if err != nil {

		return "", fmt.Errorf("error parsing JSON: %v", err)
	}

	emailValue, ok := responseJSON["email"]
	if !ok {
		return "", fmt.Errorf("email not found in response: %v", err)
	}

	fullEmail, ok := emailValue.(string)
	if !ok {
		return "", fmt.Errorf("email field is not a string")
	}

	var username string
	// Format the username based on Database Type
	switch strings.ToLower(dbType) {
	case "mysql":
		username, _, _ = strings.Cut(fullEmail, "@")

	case "postgres":
		// service account email used for IAM should trim the suffix
		username = strings.TrimSuffix(fullEmail, ".gserviceaccount.com")

	default:
		return "", fmt.Errorf("unsupported dbType: %s. Use 'mysql' or 'postgres'", dbType)
	}

	if username == "" {
		return "", fmt.Errorf("username from ADC cannot be an empty string")

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Inspect the actual JSON type of the email field
  2. Retry after anomalous endpoint responses
  3. Report upstream if the payload format changed
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at internal/sources/util.go:122 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/7084b2586db09193. Report an issue: GitHub.