Skip to main content
Glama
MadlyFriese

pg-readonly-mcp

by MadlyFriese

run_query

Run a read-only SELECT query on a Postgres database with automatic safety checks that block modifications, returning bounded columnar results.

Instructions

Run a single read-only SELECT and return a bounded, columnar result.

Accepts one statement of any read-only shape: SELECT, WITH ... SELECT, UNION / UNION ALL / INTERSECT / EXCEPT, and any nesting of those. Rejected before execution: multiple statements, DML/DDL anywhere in the tree (including data-modifying CTEs), SELECT ... INTO, COPY, row locking, and any function not on the read-only allowlist (pg_read_file, dblink, ...).

The query is wrapped in SELECT * FROM (<sql>) sub LIMIT max_rows, so the cap applies to the combined result of a set operation, not to one branch. max_rows defaults to 100 and is capped at 1000. The response is separately capped in bytes, in which case truncated is true.

Performance note: plain UNION deduplicates, which costs a sort or hash over the full result of both branches before any row is returned — the outer LIMIT cannot short-circuit it. On large tables that is the most likely way to hit the server's statement timeout. Prefer UNION ALL when you do not need duplicates removed.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sqlYes
max_rowsNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
rowsYes
columnsYes
row_countYes
truncatedYes
Behavior5/5

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

The description thoroughly discloses behavioral traits: read-only constraint, accepted/rejected SQL constructs, the wrapping with LIMIT and max_rows default/cap, byte cap and truncation flag, and a performance note about UNION versus UNION ALL. With no annotations provided, the description fully compensates.

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?

The description is well-structured and front-loaded with the main purpose. It is slightly long but every sentence adds value, including technical constraints and performance advice. It earns its length.

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?

Given the tool's complexity and the presence of an output schema, the description is very complete. It covers input constraints, behavior (wrapping, truncation), and performance considerations. No gaps are evident.

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%, so the description compensates well. It explains that 'sql' accepts read-only SELECT statements of various shapes, and details 'max_rows' default (100) and cap (1000). This adds significant meaning beyond the bare 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 description starts with 'Run a single read-only SELECT and return a bounded, columnar result,' which clearly states the tool's specific action and resource. It distinguishes from sibling tools (list_schemas, list_tables, etc.) which are metadata operations, making the purpose unambiguous.

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

Usage Guidelines2/5

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

The description does not explicitly state when to use this tool versus alternatives. It mentions accepted/rejected statement types and a performance note, but lacks guidance on when to prefer run_query over sibling tools like sample_table for quick data previews or describe_table for schema info.

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

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/MadlyFriese/pg-readonly-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server