Skip to main content
Glama

explain_query

Read-onlyIdempotent

Show a read-only SELECT query plan with real row counts and timings to diagnose slow queries, then validate rewrites with compare_queries.

Instructions

Show the query plan for one read-only SELECT, with real row counts and timings where the database gives them (PostgreSQL: EXPLAIN ANALYZE, which runs the query; everything is rolled back). Same checks as run_query. Use it to see why a query is slow before rewriting it, then check your rewrite with compare_queries.

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
sqlYesOne read-only SELECT (or WITH ... SELECT) written against the DDL select_schema returned. Writes, DDL and multiple statements are refused, as is any table or column this caller may not read.
rolesNoThe caller's roles or groups, e.g. ['finance', 'payroll']. Objects and columns restricted to a role are visible only when it is listed here. Omitted = no roles.
principalNoWho is asking, as an identity string such as 'okta:jdoe'. Pass it whenever you know the user: visibility is decided for this identity. Omitted = anonymous, which sees only unrestricted objects.

Output Schema

NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. Addedv1.20.0

TDQS

A4.5/5.0
Behavior4/5

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

Annotations already declare readOnlyHint=true and destructiveHint=false, but the description adds the one fact that matters most and that annotations cannot convey: on PostgreSQL, EXPLAIN ANALYZE actually executes the query yet everything is rolled back. That resolves the apparent tension between executing a statement and the read-only hint. It stops short of discussing cost, latency, or output shape, but the output schema covers returns.

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, front-loaded with what the tool returns, followed by the engine-specific caveat and the workflow. No filler, and the parenthetical is the only elaboration, which is warranted.

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?

Given an output schema, full parameter documentation, and rich annotations, the description covers the remaining gaps: execution semantics, rollback behavior, restriction to reads, and how the result feeds into a rewrite/compare loop. 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.

Parameters3/5

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

Schema description coverage is 100%, so all three parameters (sql, roles, principal) are already documented in the input schema. The description only reinforces the 'one read-only SELECT' constraint on sql, which the schema also states. It adds no additional syntax, formatting, or identity-resolution nuance beyond the structured fields.

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 query plan for one read-only SELECT') plus the distinctive payload (real row counts and timings). The EXPLAIN ANALYZE detail and the pointer to compare_queries separate it cleanly from run_query and optimize_query without the agent needing to open another schema.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives an explicit workflow: use it to diagnose slowness before rewriting, then validate the rewrite with compare_queries. It also constrains inputs to a single read-only SELECT and defers shared validation to 'same checks as run_query', so the agent knows when this tool applies and when the sibling does.

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