Skip to main content
Glama
YawLabs

@yawlabs/postgres-mcp

by YawLabs

pg_explain

Destructive

Retrieve query plans for SQL statements. Optionally run EXPLAIN ANALYZE or test hypothetical indexes without persisting changes.

Instructions

Get the query plan for a SQL statement. By default, this uses plain EXPLAIN (no execution). Set analyze: true to run the query with EXPLAIN ANALYZE - for non-SELECT statements, ALLOW_WRITES=1 is required (since ANALYZE actually executes the statement). Writes executed during EXPLAIN ANALYZE are always rolled back, so you can inspect a plan for an INSERT/UPDATE/DELETE without persisting the mutation. Format is text (default) or json. Pass the raw SQL (not an EXPLAIN-prefixed statement). Set hypothetical_indexes to a list of {table, columns, using?} to ask the planner 'what would the plan be if these indexes existed?' -- requires the HypoPG extension (CREATE EXTENSION hypopg). The hypothetical indexes are torn down at the end of the call, never touching real disk.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sqlYesThe SQL statement to explain. Do NOT prefix with EXPLAIN.
formatNoOutput format.text
paramsNoPositional parameters referenced as $1, $2, ... in the SQL.
analyzeNoRun EXPLAIN ANALYZE (actually executes the query).
hypothetical_indexesNoList of indexes the planner should pretend exist for this EXPLAIN. Requires the HypoPG extension. Indexes are session-scoped and reset at the end of the call.
Behavior4/5

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

The description details that ANALYZE actually executes the query but writes are rolled back, and that hypothetical indexes are session-scoped and torn down. This adds context beyond annotations (destructiveHint=true, readOnlyHint=false) and clarifies safety.

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 purpose, but it is somewhat lengthy. Each sentence adds value, though it could be slightly more concise.

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?

The description covers all parameters, explains the return format (text/json), and provides key behavioral nuances (rollback, index teardown). Without an output schema, it sufficiently informs the agent.

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?

All 5 parameters have descriptions in the schema (100% coverage), and the description adds extra meaning for 'analyze' (rollback behavior), 'hypothetical_indexes' (HypoPG requirement and session-scoping), and format options.

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 'Get the query plan for a SQL statement,' which is a specific verb+resource. It distinguishes itself from sibling tools like pg_query (execution) and pg_readonly (read-only queries) by focusing on query planning.

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

Usage Guidelines4/5

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

The description explains when to use plain EXPLAIN vs EXPLAIN ANALYZE, notes the requirement for ALLOW_WRITES=1 for non-SELECT statements, and advises to pass raw SQL without EXPLAIN prefix. However, it does not explicitly compare with alternatives like pg_query.

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