Skip to main content
Glama
db-conn-mcp

db-conn-mcp

execute_write_query

Destructive

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:

  1. 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 the RETURNING rows. This records a preview grant for this exact statement. RETURNING values 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.

  2. Show the user the exact SQL and the dry-run result; ask for permission (not needed if the database has yolo enabled).

  3. 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

NameRequiredDescriptionDefault
sqlYesOne 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.
paramsNoValues bound to the $1, $2, ... placeholders in `sql`, in order, as real driver bind parameters. Omit when the SQL has no placeholders.
dry_runNotrue (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.
databaseYesName 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_msNoCancel the statement if it runs longer than this many milliseconds (a positive integer). Omit for no per-call timeout.
skip_dry_runNoCommit without a prior dry-run. Only when the user explicitly asked to skip the preview.
user_consentNoSet true on the commit call only after the user approved this exact statement. Not needed when the database has yolo enabled.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed7 schema fields changedv0.8.1
    • addedInput schema / properties / database / description
      Added value: +"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."
    • addedInput schema / properties / dry_run / description
      Added value: +"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."
    • addedInput schema / properties / params / description
      Added value: +"Values bound to the $1, $2, ... placeholders in `sql`, in order, as real driver bind parameters. Omit when the SQL has no placeholders."
    • addedInput schema / properties / skip_dry_run / description
      Added value: +"Commit without a prior dry-run. Only when the user explicitly asked to skip the preview."
    • addedInput schema / properties / sql / description
      Added value: +"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."
    • addedInput schema / properties / timeout_ms / description
      Added value: +"Cancel the statement if it runs longer than this many milliseconds (a positive integer). Omit for no per-call timeout."
    • addedInput schema / properties / user_consent / description
      Added value: +"Set true on the commit call only after the user approved this exact statement. Not needed when the database has yolo enabled."
  2. First observed

TDQS

A4.6/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already declare destructiveHint=true, readOnlyHint=false and idempotentHint=false, but the description goes well beyond them: the preview-grant model, the 10-minute expiry, grant consumption by a commit ATTEMPT even when it fails, mandatory re-dry-run before retry, and server-side enforcement of the flow. It also discloses that rows arrive only on the text channel inside an untrusted-data banner with no structuredContent. The only shortfall is the dense tail of column-type rendering caveats, which is more trivia than behavior an agent must act on, pushing this below a 5.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Front-loads purpose, then the safety flow as a numbered sequence, then result shape, then rendering edge cases. The ordering is deliberate and most sentences carry actionable information, but the closing paragraph on bytea/"char"/ROW rendering is long relative to its practical weight and slightly dilutes the core flow.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a destructive, 7-parameter write tool with no output schema, the description covers everything an agent needs: the enforced two-step flow, consent requirements, retry semantics after failure, result shape for both meta and RETURNING cases, and the text-channel-only delivery. Return values are explained despite the absence of an output schema, which is exactly the burden this description must carry.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the baseline is 3, but the description adds real meaning the schema does not: values must go through `params` placeholders rather than pasted SQL, the commit must send exactly the SQL and params the dry-run sent, and skip_dry_run is constrained to an explicit user request. The `database`-name semantics are left to the schema, which already covers them, so this is not a 5.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Opens with a specific verb and resource: 'Run an INSERT/UPDATE/DELETE/DDL statement on a write-mode database.' That immediately separates it from the read sibling execute_read_query and from schema-introspection siblings like get_table_schema, which the description itself names as a prerequisite.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives explicit when-to-use guidance (call get_table_schema first if the schema isn't already in context, don't re-fetch one you have) and a fully enumerated when-not/alternative path: dry_run=true first, dry_run=false with user_consent only after approval, skip_dry_run=true only on explicit user request. It also names the yolo exception, so the agent knows when the consent step does not apply.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.