googleapis/mcp-toolbox · error

expected []byte for text-like column, but got %T

Error message

expected []byte for text-like column, but got %T

What it means

RunSQL's text-like column branch (TEXT/VARCHAR/NVARCHAR) found the scanned value is not []byte — the type assertion failed, so the value cannot be cast back to a string as expected from the MySQL driver.

Source

Thrown at internal/sources/tidb/tidb.go:169

			// mysql driver return []uint8 type for "TEXT", "VARCHAR", and "NVARCHAR"
			// we'll need to cast it back to string
			switch colTypes[i].DatabaseTypeName() {
			case "JSON":
				// unmarshal JSON data before storing to prevent double
				// marshaling
				byteVal, ok := val.([]byte)
				if !ok {
					return nil, fmt.Errorf("expected []byte for JSON column, but got %T", val)
				}
				var unmarshaledData any
				if err := json.Unmarshal(byteVal, &unmarshaledData); err != nil {
					return nil, fmt.Errorf("unable to unmarshal json data %s", val)
				}
				vMap[name] = unmarshaledData
			case "TEXT", "VARCHAR", "NVARCHAR":
				byteVal, ok := val.([]byte)
				if !ok {
					return nil, fmt.Errorf("expected []byte for text-like column, but got %T", val)
				}
				vMap[name] = string(byteVal)
			default:
				vMap[name] = val
			}
		}
		out = append(out, vMap)
	}

	if err := results.Err(); err != nil {
		return nil, fmt.Errorf("errors encountered during row iteration: %w", err)
	}

	return out, nil
}

func IsTiDBCloudHost(host string) bool {
	pattern := `gateway\d{2}\.(.+)\.(prod|dev|staging)\.(.+)\.tidbcloud\.com`

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Check the actual Go type reported by %T in the message
  2. Avoid configurations where the driver returns strings already typed
  3. Adjust the column type or conversion path
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at internal/sources/tidb/tidb.go:169 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/1e495d4f4a3bf743. Report an issue: GitHub.