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

MCPg - Production-grade PostgreSQL MCP Server

Explain query

explain_query
Read-only

Inspect PostgreSQL execution plans without executing a query, or run it with buffers and I/O timing to diagnose query performance and plan behavior safely.

Instructions

Return the PostgreSQL execution plan for a query. By default uses EXPLAIN (FORMAT JSON) — plan only, the query is not executed. Set io=true to switch to EXPLAIN (ANALYZE, BUFFERS, TIMING) — runs the query and includes buffer + I/O timing per node (PG 19 additionally surfaces asynchronous-I/O block counts). Validated by the same safety allowlist as run_select, so writes / DDL are rejected.

Example: explain_query(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": "explain_query"
  }
}

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
planYes

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

A4.7/5.0
Behavior5/5

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

Adds real behavioral context beyond the annotations: the default is non-executing, io=true actually runs the query and returns per-node buffer and I/O timing (plus async-I/O block counts on PG 19), and the same safety allowlist as run_select applies, so writes and DDL are rejected. That last point matters because a query that gets executed under ANALYZE would otherwise look like a side effect contradicting readOnlyHint, and the description pre-empts that concern by stating writes are refused.

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?

Four tight sentences front-loaded with the core purpose, then the io toggle, then the safety boundary, then an example. Every sentence adds information; the PG 19 note is a small but relevant aside, not filler.

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 shape need not be described. For a three-parameter read tool, the description covers purpose, both modes, execution semantics, safety constraints, and a concrete invocation example. Nothing an agent needs in order to call it correctly is missing.

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 description coverage is only 33%, with sql and io carrying just titles, so the description has to carry the load. It fully explains io: false means plan-only, true means ANALYZE with buffers and timing. It supplies a worked sql example, but the database parameter (targeting a configured secondary) is left entirely to the schema.

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 ("Return the PostgreSQL execution plan for a query") and immediately distinguishes the two modes: default EXPLAIN (FORMAT JSON) is plan-only, while io=true switches to EXPLAIN (ANALYZE, BUFFERS, TIMING). That differentiates it from run_select, which executes queries outright, and the distinction is visible without opening the 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 clear guidance on when to leave the default (plan only, no execution) and when to set io=true (you want buffer and I/O timing per node, at the cost of running the query). It also sets a boundary: writes and DDL are rejected by the allowlist. It does not name sibling alternatives such as analyze_query_plan, optimize_query, or why_is_this_slow, so the routing signal is implicit rather than explicit.

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