Skip to main content
Glama
amar141989-dev

readonly-postgres-mcp

pg_query_sql

Read-onlyIdempotent

Execute a single read-only SQL query (SELECT, WITH, EXPLAIN) on PostgreSQL with write protection, row limits, and bind parameters for safe data retrieval.

Instructions

Run a single read-only SQL query against a PostgreSQL database.

Only SELECT, WITH and EXPLAIN are permitted. Writes and DDL (INSERT, UPDATE, DELETE, MERGE, COPY, CREATE, DROP, ALTER, TRUNCATE) are rejected before reaching the database, as are data-modifying CTEs.

Exactly one statement per call — do not send two statements separated by a semicolon. A single trailing semicolon is fine.

Results are capped at 1000 rows and 15s. The response reports "truncated": true when more rows matched than were returned, and "rowCount" is the number of rows returned, not the number matched — use a COUNT(*) query if you need the true total.

Pass literals through "values" as $1, $2 placeholders rather than building them into the SQL string.

bigint and numeric columns are returned as JSON strings, not numbers.

Use pg_describe to discover tables and columns instead of guessing at names.

EXPLAIN ANALYZE is rejected by default because it executes the statement it explains; plain EXPLAIN always works.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sqlYesA single SELECT, WITH or EXPLAIN statement. Use $1, $2 for values.
valuesNoPositional bind parameters for the $1, $2 placeholders in sql.

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.3.0

TDQS

A4.9/5.0
Behavior5/5

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

Goes well beyond the readOnly/destructive annotations by disclosing the 1000-row and 15s caps, the 'truncated' flag semantics, that rowCount is returned not matched, and that bigint/numeric come back as JSON strings. The EXPLAIN ANALYZE rejection and pre-database write rejection are behavioral details 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?

Front-loads purpose and the allowlist before edge cases (trailing semicolon, truncation, type rendering), with zero filler sentences. Length is justified by the number of non-obvious behaviors it must convey.

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?

No output schema exists, yet the description covers return semantics (truncated, rowCount, string-typed numerics) and error behavior (rejected statements). An agent has everything needed to invoke this correctly and interpret results.

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 value: it tells the agent to pass literals via 'values' as $1/$2 placeholders rather than string-building. That is usage guidance the schema alone only hints at.

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?

States a specific verb and resource ('Run a single read-only SQL query against a PostgreSQL database') and immediately constrains it to read-only. It also names the sibling pg_describe and its distinct role, letting an agent separate the two without opening schemas.

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?

Explicitly enumerates what is permitted (SELECT, WITH, EXPLAIN) and what is rejected (writes, DDL, data-modifying CTEs, EXPLAIN ANALYZE). It also states the single-statement rule and routes schema discovery to pg_describe and true totals to COUNT(*).

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

Deploy Server

Other Tools