Skip to main content
Glama

Explain a query plan

pg_explain
Read-onlyIdempotent

Inspect a read query’s execution plan without running it; see estimated cost, rows, tables, and sequential scans to understand and prevent slow queries.

Instructions

Show the execution plan of a read query (EXPLAIN) without running it.

Returns the plan plus a summary: estimated cost and rows, tables touched and which of them are read by sequential scan. Use it before running a heavy query and to understand why a query is slow.

analyze=true really executes the query to measure it (EXPLAIN ANALYZE). It is only available on connections configured with allow_explain_analyze.

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": "pg_explain"
  }
}

Input Schema

NameRequiredDescriptionDefault
sqlYes
formatNotext
paramsNo
analyzeNo
buffersNo
verboseNo
settingsNo
connectionNo

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A3.9/5.0
Behavior4/5

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

Annotations already declare read-only, idempotent, non-destructive, but the description adds real context: what the response contains (estimated cost and rows, tables touched, sequential scans) and the critical caveat that analyze=true actually executes the query. That caveat matters because readOnlyHint=true could otherwise lead an agent to assume analyze never touches data.

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?

Purpose, return shape, usage, and the analyze caveat are front-loaded in short blocks; every sentence adds information not already in the schema or annotations.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For an eight-parameter tool with 0% schema description coverage and no output schema, return values and the analyze precondition are covered well, but most parameters remain opaque, so an agent cannot reason about buffers, verbose, settings, params, or connection.

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

Parameters2/5

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

Schema coverage is 0% and only one of eight parameters (analyze) is explained. format, params, connection, buffers, verbose, and settings have no meaning documented anywhere, so the description does not compensate for the coverage gap.

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?

Names a specific verb (show) and resource (execution plan / EXPLAIN), and explicitly contrasts itself with actually executing the query ("without running it"), distinguishing it from pg_query without needing the sibling's schema.

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 concrete when-to-use guidance ("before running a heavy query", "to understand why a query is slow") and a hard precondition for analyze mode (allow_explain_analyze). It does not name the alternative tool or state when not to use it.

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