googleapis/mcp-toolbox · error

unable to retrieve column names: %w

Error message

unable to retrieve column names: %w

What it means

Trino RunSQL wraps results.Columns() failures. Columns() asks the driver for the result-set column metadata and fails only if the rows handle is invalid or the driver hit a protocol error while fetching metadata. This is rare because the query already succeeded at submission.

Source

Thrown at internal/sources/trino/trino.go:125

func (s *Source) ToConfig() sources.SourceConfig {
	return s.Config
}

func (s *Source) TrinoDB() *sql.DB {
	return s.Pool
}

func (s *Source) RunSQL(ctx context.Context, statement string, params []any) (any, error) {
	results, err := s.TrinoDB().QueryContext(ctx, statement, params...)
	if err != nil {
		return nil, fmt.Errorf("unable to execute query: %w", err)
	}
	defer results.Close()

	cols, err := results.Columns()
	if err != nil {
		return nil, fmt.Errorf("unable to retrieve column names: %w", err)
	}

	// create an array of values for each column, which can be re-used to scan each row
	rawValues := make([]any, len(cols))
	values := make([]any, len(cols))
	for i := range rawValues {
		values[i] = &rawValues[i]
	}

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

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Check the wrapped error and retry the query — this is often transient
  2. Upgrade the trino-go-client driver to the latest version
  3. Avoid exotic result shapes (very wide rows, complex types) if reproducible
  4. Verify coordinator stability and proxy timeouts between client and Trino

Example fix

// before
// no retry on metadata errors
// after
cols, err := results.Columns()
if err != nil && isTransient(err) {
    cols, err = retryQuery(ctx, statement, params)
}
Defensive patterns

Strategy: try-catch

Try / catch

out, err := src.RunSQL(ctx, stmt, params)
if err != nil && strings.Contains(err.Error(), "unable to retrieve column names") {
    // usually transient: retry once with a fresh query
    out, err = src.RunSQL(ctx, stmt, params)
}

Prevention

When it happens

Trigger: Source.RunSQL after a successful QueryContext where results.Columns() fails: result set already closed/corrupted, driver protocol error, or the underlying connection dropped between query submission and metadata fetch.

Common situations: Coordinator restart mid-query killing the HTTP session; driver bug with unusual column types (complex Trino types like map/row); extremely wide result sets causing metadata fetch issues.

Related errors


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