googleapis/mcp-toolbox · error
unable to execute query: %w
Error message
unable to execute query: %w
What it means
YugabyteDB Source.RunSQL executes the statement via the pool's Query; if pgx returns an error issuing the query (SQL syntax error, missing relation, permission denied, cancelled context, connection dropped mid-query), it is wrapped as 'unable to execute query: %w'. The pool connected fine; the failure is at query execution time.
Source
Thrown at internal/sources/yugabytedb/yugabytedb.go:110
return false
}
func (s *Source) SourceType() string {
return SourceType
}
func (s *Source) ToConfig() sources.SourceConfig {
return s.Config
}
func (s *Source) YugabyteDBPool() *pgxpool.Pool {
return s.Pool
}
func (s *Source) RunSQL(ctx context.Context, statement string, params []any) (any, error) {
results, err := s.YugabyteDBPool().Query(ctx, statement, params...)
if err != nil {
return nil, fmt.Errorf("unable to execute query: %w", err)
}
fields := results.FieldDescriptions()
out := []any{}
for results.Next() {
v, err := results.Values()
if err != nil {
return nil, fmt.Errorf("unable to parse row: %w", err)
}
vMap := make(map[string]any)
for i, f := range fields {
val := sources.NormalizeValue(v[i], f.DataTypeOID)
vMap[f.Name] = val
}
out = append(out, vMap)
}
View on GitHub (pinned to 8cc6e09de2)
Solutions
- Fix the SQL syntax and verify table/column names exist in the target database
- Check the database user has privileges for the operation (SELECT/INSERT/etc.)
- Ensure the number and types of parameters match the placeholders in the statement
- Test the statement directly with 'ysqlsh' or 'psql' to see the raw server error
- Read the wrapped '%w' cause for the exact Postgres error code
Example fix
// before SELECT * FROM order WHERE id = $1 // after (orders table, correct name) SELECT * FROM orders WHERE id = $1
Defensive patterns
Strategy: try-catch
Validate before calling
// Basic client-side checks before invoking the tool
if (typeof statement !== "string" || statement.trim() === "")
throw new Error("statement must be a non-empty SQL string");
if (statement.includes("order ")) console.warn("verify table names exist in the database"); Try / catch
try {
const result = await runYugabyteSQL(statement, params);
} catch (err) {
const cause = err.cause ?? err;
if (/syntax error|does not exist|permission denied/i.test(String(cause))) {
console.error("SQL failed server-side:", cause.message);
// fix statement or permissions, then retry once
}
throw err;
} Prevention
- Test generated SQL in ysqlsh/psql against the target schema before shipping prompts
- Grant the configured database user only the privileges it needs, and know what they are
- Match parameter count/types to placeholders exactly
- Set sensible statement timeouts and keep queries within them
When it happens
Trigger: RunSQL invoked with a statement that fails server-side: syntax error, referencing a nonexistent table/column, insufficient privileges, parameter count/type mismatch, statement timeout, or context cancellation while running.
Common situations: LLM agent generating invalid SQL against Yugabyte schemas; querying tables that don't exist in the configured database; read-only user attempting writes; long queries hitting timeouts; parameter placeholders count not matching provided params.
Related errors
- unable to execute query: %w
- unable to parse row: %w
- unable to execute query: %w
- unable to execute query: %w
- unable to parse row: %w
AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05).
Data as JSON: /api/errors/bc1d7438c7378894.
Report an issue: GitHub.