Run a read-only SQL query
postgres_queryRun one read-only PostgreSQL SELECT to return query results as JSON objects, limited to allowed schemas, 500 rows, and a 5000 ms timeout for controlled data reads.
Instructions
Run ONE read-only PostgreSQL SELECT and return the rows as JSON objects. Only tables in the allowed schemas (public) can be read. Rejected: anything that is not a single SELECT (INSERT/UPDATE/DELETE/DDL, multiple statements, SELECT INTO, FOR UPDATE), system catalogs (pg_*), and unsafe functions (pg_sleep, pg_read_file, dblink, set_config…). Results are capped at 500 rows (truncated=true means more rows exist) and the query is cancelled after 5000 ms, so aggregate in SQL (GROUP BY, ORDER BY … LIMIT) rather than fetching raw rows. Use postgres_describe_table first to get exact column names.
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": "postgres_query"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes | Exactly one PostgreSQL SELECT statement (WITH … SELECT and UNION are fine). | |
| max_rows | No | Return at most this many rows (1 to 500). Defaults to 500. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| rows | Yes | ||
| columns | Yes | ||
| max_rows | Yes | ||
| row_count | Yes | Rows returned (after the row cap). | |
| truncated | Yes | True if the query produced more rows than max_rows. | |
| duration_ms | Yes |