Skip to main content
Glama

Explain query plan

explain
Read-onlyIdempotent

Diagnose slow queries by viewing the database's execution plan and index usage. Optionally execute with analyze=true to measure real timings.

Instructions

Show how the database will execute a SELECT (its query plan) to diagnose slow queries or check index use — use it instead of query when the question is about performance, not data. With analyze=true the statement is actually executed to report real timings (can be slow on big tables). Returns the plan as rows plus a hint: MySQL type=ALL or PostgreSQL 'Seq Scan' means a full table scan (consider an index or a narrower WHERE). SQLite uses EXPLAIN QUERY PLAN. On failure returns isError with 'error: ' (e.g. refused statement, unknown table, SQL error).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sqlYesThe SELECT statement to analyze (without EXPLAIN).
analyzeNotrue = execute the statement to measure real timings and row counts (EXPLAIN ANALYZE); default false = estimate only, nothing is executed.
databaseNoOptional database to use instead of the connection's default (names from `databases`). Omit to use the default.
connectionYesConnection name exactly as returned by `connections` (e.g. "shop"). Unknown or unexposed names return an error.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed4 schema fields changedv0.2.2
    • addedInput schema / properties / analyze / description
      Added value: +"true = execute the statement to measure real timings and row counts (EXPLAIN ANALYZE); default false = estimate only, nothing is executed."
    • changedInput schema / properties / connection / description
      Previous value: -"Connection name (from `connections`)"New value: +"Connection name exactly as returned by `connections` (e.g. \"shop\"). Unknown or unexposed names return an error."
    • changedInput schema / properties / database / description
      Previous value: -"Database name to use instead of the connection's default (optional)"New value: +"Optional database to use instead of the connection's default (names from `databases`). Omit to use the default."
    • changedInput schema / properties / sql / description
      Previous value: -"SELECT statement"New value: +"The SELECT statement to analyze (without EXPLAIN)."
  2. First observedv0.1.0

TDQS

A4.8/5.0
Behavior5/5

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

Annotations declare read-only/idempotent, and the description adds traits they cannot convey: that analyze=true actually executes the statement with real timings and can be slow on large tables, what the output rows mean (type=ALL / Seq Scan = full table scan), DB-specific plan dialect, and the failure shape ('isError with error: <reason>'). It also resolves the tension an agent might feel between readOnlyHint and 'the statement is actually executed' by making clear the input is a SELECT.

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-loads purpose and the sibling alternative in the first clause, then layers the analyze caveat and error contract. Dense but every sentence carries information; the per-dialect plan-hint sentence is the only part that leans toward verbosity, though it is genuinely useful for interpretation.

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?

There is no output schema, and the description compensates by describing the return shape (plan as rows plus a hint), how to interpret it, and the error format. Combined with 100% schema coverage and clear annotations, an agent has everything needed to call and read this tool.

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 baseline is 3, but the description adds genuine meaning for `analyze` beyond the schema (executes the statement, real timings vs estimate, performance cost) and explains how to read the returned plan. The other two params (connection, database) get no added detail, but the schema already documents them.

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+resource ('Show how the database will execute a SELECT (its query plan)') plus the diagnostic purpose, and explicitly contrasts itself with the sibling `query` tool. An agent can distinguish it from `query`/`sample`/`count` without opening any 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 routing rule: 'use it instead of `query` when the question is about performance, not data.' It also states when the costly mode applies ('analyze=true ... can be slow on big tables'), covering both selection and a cost caveat.

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