googleapis/mcp-toolbox · error
unable to parse row: %w
Error message
unable to parse row: %w
What it means
RunSQL in the cloud-sql-postgres source wraps any error pgx returns while decoding a result row into Go values. After a query succeeds and iteration begins, results.Values() decodes each column; if a value cannot be scanned into the expected type (or a protocol/timeout error interrupts iteration), the row parse fails and this error is returned. It is distinct from query execution errors, which are caught after the loop via results.Err().
Source
Thrown at internal/sources/cloudsqlpg/cloud_sql_pg.go:131
func (s *Source) PostgresPool() *pgxpool.Pool {
return s.Pool
}
func (s *Source) RunSQL(ctx context.Context, statement string, params []any) (any, error) {
statement = sqlcommenter.PrependComment(ctx, statement, SourceType, s.SQLCommenter)
results, err := s.PostgresPool().Query(ctx, statement, params...)
if err != nil {
return nil, fmt.Errorf("unable to execute query: %w", err)
}
defer results.Close()
fields := results.FieldDescriptions()
out := []any{}
for results.Next() {
values, err := results.Values()
if err != nil {
return nil, fmt.Errorf("unable to parse row: %w", err)
}
row := orderedmap.Row{}
for i, f := range fields {
val := sources.NormalizeValue(values[i], f.DataTypeOID)
row.Add(f.Name, val)
}
out = append(out, row)
}
// this will catch actual query execution errors
if err := results.Err(); err != nil {
return nil, fmt.Errorf("unable to execute query: %w", err)
}
return out, nil
}
func getConnectionConfig(ctx context.Context, user, pass, dbname string, readOnly bool) (string, bool, error) {
userAgent, err := util.UserAgentFromContext(ctx)
if err != nil {View on GitHub (pinned to 8cc6e09de2)
Solutions
- Inspect the wrapped pgx error to identify which column/type failed; cast the problematic column in SQL (e.g. col::text) so it decodes to a simple type.
- Check the context deadline/cancellation and network stability; increase timeouts if rows are being cut off mid-stream.
- Update the pgx library version in case of a known decoding bug for the offending type OID.
- If decoding custom types, avoid selecting them or use a view that coerces them to supported types.
Example fix
// before: SELECT custom_composite_col FROM my_table // after: SELECT custom_composite_col::text AS custom_composite_col FROM my_table
Defensive patterns
Strategy: try-catch
Try / catch
out, err := source.RunSQL(ctx, stmt, params)
if err != nil {
var pgErr *pgconn.PgError
if errors.As(err, &pgErr) {
// inspect pgErr.Message / pgErr.Code for the decoding cause
}
return fmt.Errorf("row decode failed: %w", err)
} Prevention
- Cast exotic columns to ::text or scalar types in generated SQL
- Keep pgx/v5 up to date for type-decoding fixes
- Set generous context timeouts for large result sets
- Test queries returning all column types of your schema
When it happens
Trigger: Calling RunSQL (directly or via the execute-sql tool) where a result row fails to decode: column types pgx cannot map to Go values, data corruption mid-stream, cancelled context during iteration, or a connection drop while fetching rows.
Common situations: Selecting unusual column types (e.g. custom composite/enum OIDs, huge blobs) that fail normalization; an LLM-issued query returning exotic types; network interruption or statement timeout while streaming rows; running on a connection killed by Cloud SQL idle timeout mid-result.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- unable to parse row: %w
- unable to execute query: %w
- unable to parse connection uri: %w
- unable to parse connection uri: %w
- unable to execute query: %w
AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05).
Data as JSON: /api/errors/2dbe672542f172fc.
Report an issue: GitHub.