Skip to main content
Glama

explain_query

Inspect PostgreSQL execution plans as parsed trees, flag sequential scans and stale statistics, and optionally execute the statement with ANALYZE for actual row counts and timings.

Instructions

Execution plan via EXPLAIN (FORMAT JSON), parsed into a tree with warnings for sequential scans and stale statistics. analyze=true physically executes the statement to get actual row counts and timings; without it there are planner estimates and no timings.

Input Schema

NameRequiredDescriptionDefault
paramsNoPositional PostgreSQL parameters ($1, $2, ...).
analyzeNoRun EXPLAIN ANALYZE, executing the statement.
statementYesSQL statement to analyze.
connection_idYesConnection id. See list_connections.

Output Schema

NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A4/5.0
Behavior4/5

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

With no annotations present, the description carries the full burden and does disclose the most consequential behavior: analyze=true physically executes the statement, and the plan is post-processed into a tree with sequential-scan and stale-statistics warnings. It stops short of stating that executing a DML statement under analyze=true mutates data, or what permissions the connection needs.

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?

Two sentences, no filler, and the core output shape is front-loaded before the mode tradeoff. Every clause conveys information an agent could act on.

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?

An output schema exists, so return values need not be spelled out, and the description still characterizes them (parsed tree plus warnings). Combined with fully documented parameters, an agent has enough to invoke this correctly.

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, and the description earns more by clarifying what `analyze` changes in the output: actual row counts and timings versus planner estimates with no timings. `params` and `connection_id` are left entirely to the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and resource: it produces an execution plan via EXPLAIN (FORMAT JSON) parsed into a tree with warnings. That is far more precise than a generic 'explain' label. It never names the sibling `query` tool, so the agent must infer the boundary between running a statement and planning one.

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 guidance on choosing between the two modes (analyze=true executes, false uses planner estimates), which is useful. It gives no guidance on when to pick this tool over `query` or `analyze_db_health`, and no prerequisites such as required connection state or read-only expectations.

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