Skip to main content
Glama
hangdo-merkle

postgres-mcp

execute_query

Run read-only SQL queries against PostgreSQL and return JSON results. Mutating statements are blocked, enabling safe schema inspection and data exploration.

Instructions

Execute a read-only SQL query and return results as JSON.

The query must be a SELECT (or WITH … SELECT / EXPLAIN / SHOW / TABLE / VALUES). Mutating statements are rejected before they reach the database.

Args: sql: The SQL query to execute. limit: Maximum number of rows to return (default: 500, max: 5000).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sqlYes
limitNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A4.3/5.0
Behavior4/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It explicitly reveals that the tool is read-only, that mutating statements are rejected pre-database, and that results are returned as JSON with a configurable row limit. This is strong context, though it does not mention error handling, timeouts, or authentication requirements.

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 concise and front-loaded, opening with the core action and output format, then adding restrictions, then documenting parameters. Every sentence contributes meaningful information with no redundancy or filler.

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?

Given a straightforward two-parameter tool and the presence of an output schema, the description covers the essential operational details: allowed query types, mutation rejection, row limit constraints, and JSON result format. It is complete enough for an agent to invoke correctly, though it could optionally add an example or pointer to sibling explain_query for plan-only analysis.

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

Parameters5/5

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

Schema description coverage is 0%, so the description must compensate for the schema's lack of per-property descriptions. It does so for both parameters: sql is defined as the SQL query to execute, and limit is explained as the maximum number of rows with default and maximum values. This fully covers the parameter semantics.

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 states a specific verb and resource: 'Execute a read-only SQL query and return results as JSON.' It clearly distinguishes this from sibling metadata tools by emphasizing arbitrary SQL execution with explicit allowed statement types (SELECT, WITH, EXPLAIN, SHOW, TABLE, VALUES) and by noting mutating statements are rejected.

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

Usage Guidelines3/5

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

The description gives clear boundaries for use by listing accepted statement types and stating that mutating statements are rejected before reaching the database. However, it does not explicitly say when to use this tool versus sibling alternatives like explain_query or list_tables, so the usage guidance is implied rather than fully explicit.

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