Skip to main content
Glama

Explain a query plan

db_explain
Read-onlyIdempotent

Return a statement's execution plan without running it. Detect full table scans and missing indexes safely before executing your query.

Instructions

Return the execution plan for a statement WITHOUT running it. Read-only by construction: the statement is planned and not executed, so this is the safe way to catch a sequential scan over a large table and the cheapest way to find a missing index. ANALYZE variants are refused here on purpose, because "EXPLAIN ANALYZE" runs the statement it plans. MongoDB: pass "collection" and a find filter as "query"; a pipeline cannot be explained, use db_query action "aggregate" with a small limit. Redis has no plans, so this tool refuses it.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
uriNoConnection string, for example postgres://user@host/db, mysql://user@host/db, sqlite:///path/to/app.db, mongodb://host/db or redis://host. Pass "profile" wherever db_list shows one.
queryYesThe statement to plan, without a leading EXPLAIN: this tool adds the right prefix per dialect. Passing EXPLAIN yourself is refused, and so is EXPLAIN ANALYZE in any spelling. For MongoDB it is the find filter as JSON.
paramsNoValues bound to placeholders in "query" instead of pasted into it: ? for MySQL and SQLite, $n for PostgreSQL. Prefer this: a bound value never reaches the statement text, the log, or a plan cache. SQL only.
profileNoA profile name from db_list. Exactly one of "profile" (a name from db_list) or "uri" (an ad-hoc connection string). Prefer "profile": it keeps the password out of the transcript.
timeoutNoMilliseconds before giving up on the planner (default 30000, between 1 and 86400000).
collectionNoMongoDB only, and required there: a plan is a plan for one collection. Ignored elsewhere, where the statement names its own tables.

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
okYesFalse when the call failed; read "error" then.
hintNo
rowsYesThe result. Null if a result limit dropped it.
bytesYes
errorNoPresent only when "ok" is false.
driverNo
formatYesRendering used for the text content block.
profileNo
rowCountYes
timezoneNo
elapsedMsYes
truncatedYesTrue when a limit removed something: the result is a prefix, not the answer.
nextCursorNo
limitReasonNomaxRows or maxBytes, when the result was truncated.

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv3.0.4

TDQS

A4.9/5.0
Behavior5/5

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

Annotations already declare readOnlyHint/destructiveHint, but the description adds real behavioral context: the statement is planned and not executed, ANALYZE is refused by design because it would execute, and Redis is unsupported. This explains *why* it is safe, not just that it is safe.

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 dense sentences, each earning its place: safety guarantee, use cases, the refusal rationale, and the per-dialect exceptions. The safety claim is front-loaded ahead of the detail.

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 values need not be described. For a 6-parameter, multi-dialect tool, the description covers the refusal cases, the dialect requirements, and the safety profile, leaving nothing an agent needs 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 coverage is 100%, so the baseline is 3, but the description adds dialect-specific binding semantics — which parameters apply under MongoDB ('collection' plus a find filter as 'query') versus SQL — that the schema documents only per-field, not as cross-dialect behavior.

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 execution plan for a statement' — plus the critical scope qualifier 'WITHOUT running it'. This immediately distinguishes it from the sibling db_query, which does execute statements.

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?

Names concrete use cases (catch a sequential scan over a large table, find a missing index) and explicitly routes away from EXPLAIN ANALYZE and toward db_query action 'aggregate' for MongoDB pipelines. It also states when the tool refuses (ANALYZE, Redis), which is rare and valuable guidance.

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