run_query
Run a read-only SELECT query on a Postgres database with automatic safety checks that block modifications, returning bounded columnar results.
Instructions
Run a single read-only SELECT and return a bounded, columnar result.
Accepts one statement of any read-only shape: SELECT, WITH ... SELECT,
UNION / UNION ALL / INTERSECT / EXCEPT, and any nesting of those.
Rejected before execution: multiple statements, DML/DDL anywhere in the tree
(including data-modifying CTEs), SELECT ... INTO, COPY, row locking, and
any function not on the read-only allowlist (pg_read_file, dblink, ...).
The query is wrapped in SELECT * FROM (<sql>) sub LIMIT max_rows, so the
cap applies to the combined result of a set operation, not to one branch.
max_rows defaults to 100 and is capped at 1000. The response is separately
capped in bytes, in which case truncated is true.
Performance note: plain UNION deduplicates, which costs a sort or hash over
the full result of both branches before any row is returned — the outer LIMIT
cannot short-circuit it. On large tables that is the most likely way to hit
the server's statement timeout. Prefer UNION ALL when you do not need
duplicates removed.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"sql": "<sql>"
},
"name": "run_query"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes | ||
| max_rows | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| rows | Yes | ||
| columns | Yes | ||
| row_count | Yes | ||
| truncated | Yes |