Skip to main content
Glama
db-conn-mcp

db-conn-mcp

execute_read_query

Read-onlyIdempotent

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

NameRequiredDescriptionDefault
sqlYesOne read-only SQL statement (SELECT, WITH, VALUES, ...). Put values in $1, $2, ... placeholders and pass them in `params`. Multiple statements are rejected.
paramsNoValues bound to the $1, $2, ... placeholders in `sql`, in order, as real driver bind parameters. Omit when the SQL has no placeholders.
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.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed4 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 / 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 / sql / description
      Added value: +"One read-only SQL statement (SELECT, WITH, VALUES, ...). Put values in $1, $2, ... placeholders and pass them in `params`. Multiple statements are rejected."
    • 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."
  2. First observed

TDQS

A4.8/5.0
Behavior5/5

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

Annotations already declare readOnly/idempotent/non-destructive, and the description adds substantial context beyond them: rows arrive only on the text channel inside an untrusted-data banner, there is no structuredContent, there is no row cap, and a column-less SELECT returns one empty object per row. These are behaviors an agent cannot learn from the annotations or schema.

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-loaded and well-sectioned: purpose, then schema advice, then binding rules, then output behavior. It is long, and the closing type-rendering paragraph (bytea hex, "char" in ROW(...), arrays of domains over "char") is dense enough to test the reader's attention, though each sentence carries real information.

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?

With no output schema, the description carries the full burden and does: it documents the meta/columns/rows envelope, duplicate column-name collapsing, and per-type rendering. An agent has everything needed to call it and interpret the result without a follow-up round trip.

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; the description still adds rationale the schema lacks by explaining that $1/$2 placeholders are real driver bind parameters with "no quoting/injection pitfalls" and that timeout_ms cancels an overrunning statement. It stops short of adding new constraints, but it meaningfully motivates correct parameter use.

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 a read-only SELECT query", immediately qualified as "enforced as a read-only transaction". That framing cleanly separates it from execute_write_query and from the cursor-based pair open_query_cursor/fetch_rows named later.

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 routing rules: call get_table_schema (or list_tables/find_columns) first if names aren't already known, don't re-fetch a schema you already have, and switch to open_query_cursor plus fetch_rows for large results. Both when-to-use and when-to-use-something-else are stated, not inferred.

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