googleapis/mcp-toolbox · error
unable to execute query: %w
Error message
unable to execute query: %w
What it means
RunSQL wraps any error returned by sql.DB.QueryContext with this message. The pool accepted the query but the driver failed to execute it — this includes connection-level failures at query time as well as SQL syntax and permission errors reported by SingleStore. No rows are returned; the whole invocation fails.
Source
Thrown at internal/sources/singlestore/singlestore.go:118
}
func (s *Source) SourceType() string {
return SourceType
}
func (s *Source) ToConfig() sources.SourceConfig {
return s.Config
}
// SingleStorePool returns the underlying *sql.DB connection pool for SingleStore.
func (s *Source) SingleStorePool() *sql.DB {
return s.Pool
}
func (s *Source) RunSQL(ctx context.Context, statement string, params []any) (any, error) {
results, err := s.SingleStorePool().QueryContext(ctx, statement, params...)
if err != nil {
return nil, fmt.Errorf("unable to execute query: %w", err)
}
cols, err := results.Columns()
if err != nil {
return nil, fmt.Errorf("unable to retrieve rows column name: %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]
}
defer results.Close()
colTypes, err := results.ColumnTypes()
if err != nil {
return nil, fmt.Errorf("unable to get column types: %w", err)View on GitHub (pinned to 8cc6e09de2)
Solutions
- Run the exact statement in the `mysql` CLI against the same database to see the underlying SQL error.
- Check the wrapped driver error in the message for the real cause (syntax, access denied, connection lost).
- Use `?` placeholders for parameters and pass values via the tool's params field.
- Ensure the configured user has privileges for the statement (SELECT/INSERT/DDL as needed).
- If the error is connection-related, reinitialize the source or enable keepalives / tune readTimeout.
Example fix
// before (invalid placeholder syntax)
{"statement": "SELECT * FROM t WHERE id = $1", "params": ["7"]}
// after
{"statement": "SELECT * FROM t WHERE id = ?", "params": ["7"]} Defensive patterns
Strategy: try-catch
Validate before calling
// Validate the statement shape before invoking run-sql
func validateStatement(stmt string) error {
s := strings.TrimSpace(stmt)
if s == "" { return errors.New("empty statement") }
if strings.Contains(s, "$"+"1") || strings.Contains(s, "%s") { return errors.New("use ? placeholders") }
return nil
} Try / catch
result, err := source.RunSQL(ctx, stmt, params)
if err != nil {
if strings.Contains(err.Error(), "connection refused") || strings.Contains(err.Error(), "driver: bad connection") {
// reconnect/reinitialize then retry once
}
return fmt.Errorf("run-sql failed: %w", err)
} Prevention
- Test statements in the mysql CLI first
- Always use ? placeholders
- Grant the configured user only the privileges it needs
- Enable keepalives / sane readTimeout for long queries
When it happens
Trigger: Calling the run-sql tool against a SingleStore source when the statement is invalid, the connection has dropped since initialization, the user lacks privileges, or params cannot be interpolated into the statement.
Common situations: Typos in SQL, referencing a non-existent table, executing DDL/DML without grants, using placeholder syntax the driver dislikes (should be `?`), or idle connection killed by a firewall between init and query.
Related errors
- unable to execute query: %w
- unable to retrieve rows column name: %w
- unable to get column types: %w
- unable to parse row: %w
- errors encountered when converting values: %w
AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05).
Data as JSON: /api/errors/7f76b37dfcc8355f.
Report an issue: GitHub.