Skip to main content
Glama

explain_query

Read-only

Returns the JSON execution plan for a SQL statement via EXPLAIN. Set analyze=True to execute read-only SQL and capture real row counts and timing.

Instructions

[READ] Return the JSON execution plan for sql (EXPLAIN).

analyze=False (default) plans without executing; analyze=True runs the
statement to collect real timing — only use it for read-only SQL.

Args:
    sql: A single SQL statement to EXPLAIN.
    analyze: If True, execute the statement to gather real row counts/timing.
    target: Target name from config; omit for the default.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sqlYes
targetNo
analyzeNo

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A4.8/5.0
Behavior5/5

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

The readOnlyHint annotation only tells the agent the tool is safe; the description goes further by disclosing the key behavioral trait that the annotation cannot express — that analyze=True actually executes the statement to gather real timings, while the default does not execute at all. It also explains target resolution ('Target name from config; omit for the default').

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?

Front-loaded with the one-line purpose, then the default/analyze behavior, then a compact Args block. Every sentence adds information; the only cosmetic nit is the double-backtick around ``sql``.

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?

With no output schema, the description still names the return value (a JSON execution plan), and it covers the analyze safety caveat and the target default for a 3-parameter tool. Nothing needed to invoke it correctly is missing.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

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

Schema description coverage is 0%, so the description carries the full burden, and it does: sql is defined as a single statement to EXPLAIN, analyze as the execute-for-real-timing switch, and target as a config target name that can be omitted. All three parameters gain meaning absent from 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?

The description states a specific verb and resource: return the JSON execution plan for a given SQL statement (EXPLAIN). Combined with the '[READ]' tag and the explicit default-vs-analyze split, an agent can immediately tell this is the plan-inspection tool, distinct from the query-statistics siblings like top_queries or slow_query_rca.

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?

It clearly states the conditional behavior of the analyze flag and gives an explicit guardrail: 'only use it for read-only SQL'. That is strong when-to-use guidance for the main parameter decision, though it never mentions when to prefer sibling diagnostics over EXPLAIN.

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