Skip to main content
Glama

Run a read-only SQL query

pg_query
Read-onlyIdempotent

Run one read-only SQL query and return its rows safely, with statement validation, parameter binding, and row/cell limits to prevent unsafe or excessive results.

Instructions

Run one read-only SQL query (SELECT, WITH, VALUES, TABLE, SHOW) and return the rows.

The query is checked before it runs: one statement only, no writes, no functions with side effects, protected tables and columns respected, and always inside a read-only transaction with a time limit. Pass values through params ($1, $2, ...) instead of concatenating them into the SQL.

Results are limited: max_rows (default from the connection, typically 200) and long values are cut at max_cell_chars. When has_more is true, narrow the query or page with offset. Prefer explicit column lists and a WHERE clause on large tables.

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": "pg_query"
  }
}

Input Schema

NameRequiredDescriptionDefault
sqlYes
formatNojson
offsetNo
paramsNo
max_rowsNo
connectionNo
max_cell_charsNo

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A4.3/5.0
Behavior5/5

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

Annotations already declare readOnlyHint, idempotentHint, destructiveHint=false and openWorldHint=false, yet the description still adds substantial behavior: single-statement enforcement, rejection of side-effecting functions, protected table/column rules, execution inside a read-only transaction with a time limit, row caps and cell truncation. The `has_more` flag is called out as the signal for pagination, which is exactly the kind of runtime behavior annotations cannot express.

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

Conciseness5/5

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

The capability statement and its read-only guarantee lead, followed by enforcement details, then parameter guidance and result-limit advice. Three short paragraphs, no filler, with limits front-loaded before pagination advice.

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

Completeness4/5

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

For a tool with no output schema, the description adequately describes what comes back: rows, `has_more`, and truncated long values. The gaps are the undocumented `format` and `connection` parameters, plus no mention of how validation failures surface to the caller.

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 description coverage is 0% across 7 parameters, so the description has to carry the load, and it explains `params`, `max_rows` (default from the connection, typically 200), `max_cell_chars`, and `offset`/`has_more` interplay. The `format` enum (json/markdown/csv) and `connection` parameter are never mentioned, leaving two of seven parameters undefined in both places.

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

Purpose4/5

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

"Run one read-only SQL query (SELECT, WITH, VALUES, TABLE, SHOW) and return the rows" names a concrete verb and resource and enumerates the accepted statement types, which implicitly separates it from plan-oriented or validation-oriented siblings. It never explicitly routes the agent away from a tool like pg_explain or pg_validate_sql, so the differentiation stays implicit rather than stated.

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

Usage Guidelines4/5

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

Gives concrete usage advice: bind values through `params` ($1, $2, ...) instead of string concatenation, prefer explicit column lists and a WHERE clause on large tables, and narrow or page with `offset` when `has_more` is true. It stops short of naming when to use a sibling instead, so the guidance is contextual but not routing.

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