Skip to main content
Glama

Explain query plan

explain_query
Read-onlyIdempotent

Inspect PostgreSQL query plans to debug performance: show the planner's JSON plan for one SQL statement without executing it, or run EXPLAIN ANALYZE on read-only queries for real timings.

Instructions

Show the planner's JSON plan for one statement (SELECT/WITH/VALUES/TABLE, or INSERT/UPDATE/DELETE/MERGE — not executed). analyze: true executes read statements inside a rolled-back READ ONLY transaction for real timings. Refused while POSTGRES_SCHEMA_ALLOWLIST is set.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "sql": "<sql>"
    },
    "name": "explain_query"
  }
}

Input Schema

NameRequiredDescriptionDefault
sqlYesThe statement to explain
paramsNoValues for $1, $2 … placeholders
analyzeNoRun EXPLAIN ANALYZE, BUFFERS (read statements only; default false)

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A4.4/5.0
Behavior5/5

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

Goes well beyond the readOnly/idempotent annotations: it discloses that statements are not executed by default, that analyze runs inside a rolled-back READ ONLY transaction, and that an allowlist configuration blocks the tool outright. Those are exactly the safety and side-effect details an agent needs before calling.

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?

Three tight sentences, each front-loaded with the key fact: default behavior first, then the analyze opt-in, then the refusal condition. No filler and no repetition of the title.

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?

Comprehensive for a three-parameter diagnostic tool with no output schema — the return artifact is described as a JSON plan and the guards are disclosed. One gap remains: it does not say what happens if `analyze: true` is combined with a write statement, which is the sharpest edge case given the read-only transaction claim.

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

Parameters3/5

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

Schema coverage is 100%, so the schema already documents all three parameters. The description adds real meaning for `analyze` (actual timings, read-only rolled-back transaction) and broadens the scope of `sql` to specific statement types, but says nothing about how `params` bind to $1/$2 placeholders beyond the schema's own note.

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?

States a specific verb and resource — show the planner's JSON plan for one statement — and enumerates the accepted statement classes. The phrase 'not executed' crisply separates it from a sibling like run_query without naming it.

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?

Gives clear conditions: default is plan-only, `analyze: true` is for real timings on read statements, and the tool is refused when POSTGRES_SCHEMA_ALLOWLIST is set. It never explicitly names run_query or select_rows as the execution alternatives, so the when-not path is implied rather than stated.

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