execute_write_query
Run INSERT, UPDATE, DELETE, or DDL statements on a write-mode database with a dry-run preview before committing changes.
Instructions
Run an INSERT/UPDATE/DELETE/DDL statement on a write-mode database.
Know the schema before you write: if the exact table and column names are not already in this conversation, call get_table_schema first instead of guessing — a wrong name wastes a whole dry-run round-trip. Don't re-fetch a schema you already have.
SAFETY — the server enforces this flow; you cannot skip it silently:
Call with dry_run=true (the default): the statement executes inside a transaction and is ALWAYS rolled back, returning its would-be
rows_affected, or theRETURNINGrows. This records a preview grant for this exact statement.RETURNINGvalues from a dry-run are rolled back and are not the values the commit will produce (sequences advance, so generated ids differ): never quote a preview id as the real one.Show the user the exact SQL and the dry-run result; ask for permission (not needed if the database has yolo enabled).
Call again with dry_run=false (and user_consent=true unless yolo) to commit. Commits without a prior dry-run of the identical statement are REJECTED. The preview grant expires 10 minutes after the dry-run and is consumed by the commit ATTEMPT it authorizes — including a commit that FAILS, which may still have applied server-side, so you MUST dry-run again before retrying. Running the same statement twice means previewing it twice. Pass skip_dry_run=true ONLY if the user explicitly asked to skip the preview.
Pass values via params ($1/$2/... placeholders), not pasted into the SQL.
Returns meta and rows_affected, or columns and rows for a RETURNING
statement; a dry-run also carries dry_run and rolled_back.
Rows arrive on the text channel only, inside the untrusted-data banner: this tool emits no structuredContent.
Result shape: columns lists every column RETURNING named, but each row is
keyed by name, so a repeated name (RETURNING id, id) 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. An
error saying the statement ran but its rows could not be decoded means a commit is to be
treated as applied: check with a read before running it again.
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_write_query"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes | One INSERT, UPDATE, DELETE or DDL statement, with values in $1, $2, ... placeholders. The commit must send exactly the SQL and params the dry-run sent. | |
| 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. | |
| dry_run | No | true (default): run in a transaction that is always rolled back and report the effect. false: commit, allowed only after a dry-run of the same statement. | |
| 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. | |
| skip_dry_run | No | Commit without a prior dry-run. Only when the user explicitly asked to skip the preview. | |
| user_consent | No | Set true on the commit call only after the user approved this exact statement. Not needed when the database has yolo enabled. |