googleapis/mcp-toolbox · error

errors encountered when converting values: %w

Error message

errors encountered when converting values: %w

What it means

This error is returned when mysqlcommon.ConvertToType fails to convert a raw driver value ([]byte) into the appropriate Go type for the column's declared type. The library scans values as raw bytes and converts them afterwards; when a value does not fit the column type reported by the server, conversion fails and the whole query result is abandoned.

Source

Thrown at internal/sources/mysql/mysql.go:172

	}

	out := []any{}
	for results.Next() {
		err := results.Scan(values...)
		if err != nil {
			return nil, fmt.Errorf("unable to parse row: %w", err)
		}
		row := orderedmap.Row{}
		for i, name := range cols {
			val := rawValues[i]
			if val == nil {
				row.Add(name, nil)
				continue
			}

			convertedValue, err := mysqlcommon.ConvertToType(colTypes[i], val)
			if err != nil {
				return nil, fmt.Errorf("errors encountered when converting values: %w", err)
			}
			row.Add(name, convertedValue)
		}
		out = append(out, row)
	}

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

	return out, nil
}

func initMySQLConnectionPool(ctx context.Context, tracer trace.Tracer, name, host, port, user, pass, dbname, queryTimeout string, queryParams map[string]string) (*sql.DB, error) {
	//nolint:all // Reassigned ctx
	ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceType, name)
	defer span.End()

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Fix the offending data at the source (the wrapped error identifies the column/value).
  2. Sanitize in SQL: use NULLIF, COALESCE, or CAST to avoid unparseable temporal/numeric values.
  3. Configure the MySQL server for zero-date handling that matches expectations (sql_mode NO_ZERO_DATE / convert zero dates).
  4. If driver conversion rules are the issue, upgrade github.com/go-sql-driver/mysql and the common conversion package.

Example fix

// before
SELECT updated_at FROM legacy_orders;
// after
SELECT NULLIF(updated_at, '0000-00-00 00:00:00') AS updated_at FROM legacy_orders;
Defensive patterns

Strategy: validation

Validate before calling

// Check temporal/numeric columns for unparseable values before conversion:
var bad int
err := db.QueryRow(`SELECT COUNT(*) FROM t WHERE updated_at = '0000-00-00 00:00:00' OR updated_at IS NULL`).Scan(&bad)
if err != nil { return err }
if bad > 0 {
    return fmt.Errorf("%d rows contain zero-dates; clean them or NULLIF in the query", bad)
}

Try / catch

out, err := toolboxClient.InvokeTool(ctx, "run-sql", params)
if err != nil && strings.Contains(err.Error(), "errors encountered when converting values") {
    // the wrapped error names the column/value; rewrite query with NULLIF/COALESCE and retry
    return fmt.Errorf("value conversion failed: %w", err)
}

Prevention

When it happens

Trigger: Running a query through the mysql run-sql tool where a returned column's value cannot be parsed according to its MySQL column type — e.g. a TIME value out of range, an invalid DATE/DATETIME string, or a numeric column containing non-numeric data.

Common situations: Servers returning zero or out-of-range temporal values ('0000-00-00', '803:20:05') with strict parsing enabled via parseTime=true, corrupted data in legacy tables, or replicas with divergent column types from the primary.

Related errors


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