Skip to main content
Glama
MCPg - Production-grade PostgreSQL MCP Server

MCPg - Production-grade PostgreSQL MCP Server

Analyze query plan

analyze_query_plan
Read-only

Summarize a query's execution plan to see estimated cost, row counts, node types, and sequential scans. Enable I/O mode to capture actual timing, buffer, and disk I/O metrics for tuning.

Instructions

Summarise a query's execution plan: total estimated cost, estimated rows, node types used, and any sequentially-scanned tables. Set io=true to run EXPLAIN (ANALYZE, BUFFERS, TIMING) instead of the plan-only variant — adds actual_total_time_ms, shared_blocks_read/hit, io_read_time_ms, io_write_time_ms, and (PG 19) aio_read_blocks / aio_write_blocks rolled up across the plan tree. Reasoning about AIO needs io=true.

Example: analyze_query_plan(sql='SELECT * FROM orders WHERE customer_id = 42', io=true)

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

Input Schema

NameRequiredDescriptionDefault
ioNo
sqlYes
databaseNoOptional: a database id from list_databases, to target a configured secondary (read-only) database; omit for the primary. Database names that are not configured ids are rejected.

Output Schema

NameRequiredDescriptionDefault
node_typesYes
total_costYes
actual_rowsNo
estimated_rowsYes
aio_read_blocksNo
io_read_time_msNo
aio_write_blocksNo
io_write_time_msNo
sequential_scansYes
shared_blocks_hitNo
shared_blocks_readNo
actual_total_time_msNo

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changedv0.8.4
    • changedInput schema / properties / database / description
      Previous value: -"Optional: target a configured secondary (read-only) database by name; omit for the primary. Call list_databases to see the configured ids."New value: +"Optional: a database id from list_databases, to target a configured secondary (read-only) database; omit for the primary. Database names that are not configured ids are rejected."
  2. First observedv0.6.8

TDQS

A3.6/5.0
Behavior3/5

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

Annotations already declare readOnlyHint=true and openWorldHint=false, so safety basics are covered, and the description does add genuine behavior detail about what the io variant returns and the PG 19 aio_* rollups. However, the most consequential behavioral fact is undisclosed: EXPLAIN ANALYZE actually executes the statement, so io=true incurs real runtime cost and can trigger side effects for volatile functions or writes — a caveat an agent needs before flipping that flag.

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 summary of outputs is front-loaded and the io toggle explanation follows logically, with a concrete example at the end. There is mild redundancy in the trailing sentence "Reasoning about AIO needs `io=true`," which restates what the preceding parenthetical already implies, but overall the text is dense and purposeful.

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

Completeness3/5

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

An output schema exists, so the description is not obliged to document return shapes, and it sensibly limits itself to flagging the extra io fields. The remaining gap is material for a plan-inspection tool: no statement of which statements are safe to analyze, no warning about execution cost under io=true, and no relation to the overlapping explain_query tool.

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 description coverage is only 33%: `database` is well documented in the schema, while `sql` and `io` carry no schema descriptions at all. The description compensates strongly for `io` (it explains precisely what extra fields the flag produces and why AIO reasoning requires it) and partially for `sql` via a worked example, but it never states whether `sql` must be a single statement, whether writes/DDL are permitted, or whether placeholders are supported.

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?

The description opens with a specific verb+resource ("Summarise a query's execution plan") and enumerates exactly what is summarised: total estimated cost, estimated rows, node types, and sequentially-scanned tables. It is clear what the tool produces, but it never distinguishes itself from nearby siblings such as explain_query, why_is_this_slow, or analyze_mpp_query_plan, so an agent must infer the boundary itself.

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?

It gives real mode-selection guidance for the io flag: use io=true to get EXPLAIN (ANALYZE, BUFFERS, TIMING) with actual timings and block I/O, and it names the specific case ("Reasoning about AIO needs io=true"). What it lacks is any when-to-use-this-vs-explain_query routing or a statement of when plan-only is preferred (e.g., for expensive or non-SELECT statements).

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

Deploy Server

Other Tools