Skip to main content
Glama
YawLabs

@yawlabs/postgres-mcp

by YawLabs

pg_readonly

Read-onlyIdempotent

Execute read-only SQL statements (SELECT, EXPLAIN, SHOW, etc.) inside a BEGIN READ ONLY transaction that rejects writes and always rolls back, ensuring no persistent data changes.

Instructions

Run a SQL statement with no persistent data changes. Always executes inside a BEGIN READ ONLY transaction regardless of ALLOW_WRITES, so postgres itself rejects any INSERT/UPDATE/DELETE/DDL and the transaction is always rolled back. Use this whenever the goal is to read - SELECT, EXPLAIN, SHOW, VALUES, WITH ... SELECT, etc. Scope caveat for hosts that auto-allow this tool: READ ONLY constrains writes to the DATABASE, not every side effect. Functions whose effect is outside the table data - pg_cancel_backend / pg_terminate_backend, pg_read_file, lo_export, COPY ... TO PROGRAM - are NOT blocked here and are NOT behind the ALLOW_WRITES gate that pg_kill sits behind. They still require the privileges the DATABASE_URL role holds, so a least-privileged role (e.g. pg_read_all_data) is what actually bounds this tool. Use params for parameterized queries to avoid SQL injection. Params can be strings, numbers, booleans, null, arrays (for postgres arrays / ANY), or objects (for json/jsonb columns). Large result sets are truncated to POSTGRES_MAX_ROWS (default 1000) with a truncated: true flag.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sqlYesThe SQL statement to execute. Hard cap of 1 MB.
paramsNoPositional parameters referenced as $1, $2, ... in the SQL.
Behavior5/5

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

Goes well beyond the annotations by explaining the BEGIN READ ONLY mechanism, transaction rollback, the DATABASE-level scope caveat, and listing specific functions that are NOT blocked. It also discloses result truncation behavior with a `truncated: true` flag. This adds critical context that annotations alone do not provide.

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 description is long but every sentence provides essential information. It is well-structured: starts with purpose, then mechanism, usage, caveats, parameters, and truncation. No redundancy or irrelevant content.

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 (arbitrary SQL execution) and lack of output schema, the description is remarkably complete. It covers safety guarantees, side-effect caveats, privilege considerations, parameter usage, and result size limits, making it self-sufficient for agent decision-making.

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?

While the schema already covers parameter types comprehensively, the description adds practical semantics by mapping arrays to postgres arrays/ANY and objects to json/jsonb columns. This helps agents understand how to construct params for specific query patterns, adding value 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 description clearly states the tool runs SQL with no persistent data changes and always executes inside a BEGIN READ ONLY transaction. It explicitly lists read-only statement types (SELECT, EXPLAIN, SHOW, VALUES, WITH ... SELECT) and distinguishes itself from write-capable tools by emphasizing the read-only constraint.

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?

Provides explicit guidance: 'Use this whenever the goal is to read' and warns about side-effect functions (pg_cancel_backend, pg_terminate_backend, etc.) that are not blocked, effectively saying when not to rely on this tool. It also mentions parameterized queries for safety, which is a practical usage directive.

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/YawLabs/postgres-mcp'

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