Skip to main content
Glama
pg-perf-mcp

pg-perf-mcp

by dixitgurv

explain_query

Run EXPLAIN (ANALYZE, BUFFERS) on a SELECT query to find where time is spent and get fixes for seq scans, bad row estimates, disk sorts, and repeated nested loops.

Instructions

Run EXPLAIN (ANALYZE, BUFFERS) on one SELECT query and diagnose the plan.

The query runs in a read-only transaction that is rolled back. Returns total time,
the nodes where time was actually spent, and findings such as wasteful sequential
scans, row misestimates, sorts spilling to disk and repeated nested-loop scans,
each with a suggested fix.

Args:
    sql: A single SELECT / WITH query.
    analyze_query: False shows the estimated plan without executing the query.
    timeout_ms: Abort the query after this many milliseconds.

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
sqlYes
timeout_msNo
analyze_queryNo

Output Schema

NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A4.1/5.0
Behavior4/5

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

With no annotations, the description carries the safety burden well: it discloses that the query runs inside a read-only transaction that is rolled back, that it will actually execute unless analyze_query is false, and that timeout_ms aborts execution. It omits permission requirements and any statement about load impact on a production database, so it falls short of complete.

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?

Front-loaded with the core action, then a compact paragraph on returns and findings, then an Args list. Every sentence is informative, though the enumerated findings list is slightly longer than needed given an output schema exists.

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?

No annotations and 0% schema coverage mean the description must supply behavior, and it does cover execution model, returns, and all three parameters. Gaps remain around required database context/engine and permissions, but since an output schema exists, return-value detail is not strictly required.

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 0%, so the Args block is doing all the work, and it does explain each parameter: sql must be a single SELECT/WITH, analyze_query false yields the estimated plan without execution, timeout_ms aborts the query. It adds real meaning beyond the bare titles, though it doesn't restate defaults or clarify how timeout interacts with estimated-plan mode.

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 concrete verb and mechanism (EXPLAIN ANALYZE, BUFFERS) applied to a single SELECT query plus a diagnostic output, which is clearly distinct from the sibling listing tools like slow_queries and active_queries. An agent can tell this targets one supplied query rather than an aggregate view.

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?

Usage is implied — diagnose the plan of a query you already have — and the analyze_query flag clarifies when to avoid executing. But it never names an alternative (e.g., slow_queries) or states prerequisites such as needing a specific database connection, so routing guidance is only inferable.

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