Skip to main content
Glama
PG Sheets MCP
by hamza533

Run a read-only SQL query

postgres_query
Read-onlyIdempotent

Run 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

NameRequiredDescriptionDefault
sqlYesExactly one PostgreSQL SELECT statement (WITH … SELECT and UNION are fine).
max_rowsNoReturn at most this many rows (1 to 500). Defaults to 500.

Output Schema

NameRequiredDescriptionDefault
rowsYes
columnsYes
max_rowsYes
row_countYesRows returned (after the row cap).
truncatedYesTrue if the query produced more rows than max_rows.
duration_msYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A4.6/5.0
Behavior5/5

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

Annotations already declare readOnly/idempotent/non-destructive, but the description adds behavior well beyond them: an explicit rejection list (writes, DDL, multi-statement, SELECT INTO, FOR UPDATE, system catalogs, unsafe functions), the 500-row cap with the truncated=true signal, and the 5000 ms cancellation timeout. This is exactly the operational context an agent needs to avoid failed calls.

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?

Content is front-loaded with the verb and resource, then constraints, then the sibling pointer. The rejection clause is dense but each item carries distinct safety information; minor compression could still shorten the catalog/function enumeration without losing meaning.

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 read-only query tool with full annotation coverage, a fully described two-parameter schema, and an output schema, this description covers everything else an agent needs: scope limits, safety rejections, row cap, timeout, and a prepare step. Nothing material is missing.

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

Parameters3/5

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

Schema coverage is 100%, so both 'sql' and 'max_rows' are already documented in the schema, and the description does not restate their syntax or defaults. It adds adjacent guidance (shape queries with GROUP BY/LIMIT; truncated=true means more rows), which is useful but not parameter-level semantics beyond the schema.

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?

The opening sentence gives a specific verb and resource ('Run ONE read-only PostgreSQL SELECT') plus the return shape ('return the rows as JSON objects'), which clearly separates it from siblings like postgres_describe_table and postgres_list_tables that inspect rather than query.

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?

It routes the agent to a sibling explicitly ('Use postgres_describe_table first to get exact column names') and states the condition that changes the approach ('aggregate in SQL ... rather than fetching raw rows'). The rejection list also effectively defines when-not-to-use for a given SQL statement.

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