execute_read_query
Run read-only SELECT queries against a configured database using bound parameters to avoid injection, with optional timeout cancellation.
Instructions
Run a read-only SELECT query (enforced as a read-only transaction).
Know the schema before you query: if the exact table and column names are not already in this conversation, call get_table_schema (or list_tables / find_columns) first instead of guessing — a wrong name costs a failed round-trip. Don't re-fetch a schema you already have.
ALWAYS pass user-supplied values via params with $1/$2/... placeholders in the
SQL (real driver bind parameters — no quoting/injection pitfalls), not by pasting
them into the SQL string. Optional timeout_ms cancels an overrunning query.
Rows arrive on the text channel only, inside the untrusted-data banner: this tool emits no structuredContent.
Returns meta, columns and rows. There is no row cap: every row comes back in
one answer, so for a large result use open_query_cursor and fetch_rows instead.
A SELECT with no columns answers one empty object per row.
Result shape: columns lists every column the statement returned, but each row
is keyed by name, so a repeated name (SELECT 1 AS a, 2 AS a) keeps only its last
value: alias the columns to keep both. Rendering follows the server's column type:
bytea arrives as \x hex text, a "char" column (relkind, contype, prokind,
...) as its character (hex when the byte is not valid UTF-8), and a "char" inside
an anonymous ROW(...) as hex because the row description says only record. An
array of a domain over "char" also reads as hex, because that array has its own
type.
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": {
"database": "<database>",
"sql": "<sql>"
},
"name": "execute_read_query"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes | One read-only SQL statement (SELECT, WITH, VALUES, ...). Put values in $1, $2, ... placeholders and pass them in `params`. Multiple statements are rejected. | |
| params | No | Values bound to the $1, $2, ... placeholders in `sql`, in order, as real driver bind parameters. Omit when the SQL has no placeholders. | |
| database | Yes | Name of a configured database, exactly as list_databases returns it (case-sensitive). Not a DSN, host or server-side database name. An unknown name is an error that lists the configured names. | |
| timeout_ms | No | Cancel the statement if it runs longer than this many milliseconds (a positive integer). Omit for no per-call timeout. |