Skip to main content
Glama
db-conn-mcp

db-conn-mcp

explain_query

Read-onlyIdempotent

Show a query's execution plan to confirm index usage or diagnose slow reads; optionally run read-only ANALYZE for real timings and buffer stats.

Instructions

Show the execution plan for a read-only query (EXPLAIN; optionally ANALYZE).

Use to confirm index usage or diagnose a slow query; to see what is indexed at all, use get_table_schema with include_indexes=true. analyze=true actually runs the (read-only, validated) query to collect real timings and buffer stats, so it takes as long as the query itself: avoid it on a query you already know is very slow, and it never changes data.

EXPLAIN the query you will ACTUALLY run: a plan for bound parameters can differ from the plan for the same SQL with the values pasted in. Pass params with the $1/$2/... placeholders exactly as you would to execute_read_query (real driver binds), instead of rewriting the query with literals just to explain it. params composes with analyze=true.

Returns meta and plan, the plan's lines in order.

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": {
      "database": "<database>",
      "sql": "<sql>"
    },
    "name": "explain_query"
  }
}

Input Schema

NameRequiredDescriptionDefault
sqlYesOne read-only SQL statement (SELECT, WITH, VALUES, ...). Put values in $1, $2, ... placeholders and pass them in `params`. Multiple statements are rejected.
paramsNoValues bound to the $1, $2, ... placeholders in `sql`, in order, as real driver bind parameters. Omit when the SQL has no placeholders.
analyzeNofalse (default): planner estimates only, nothing runs. true: run the query too and report real timings and buffer counts.
databaseYesName of a configured database, exactly as list_databases returns it (case-sensitive). Not a DSN, host or server-side database name. An unknown name is an error that lists the configured names.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed4 schema fields changedv0.8.1
    • addedInput schema / properties / analyze / description
      Added value: +"false (default): planner estimates only, nothing runs. true: run the query too and report real timings and buffer counts."
    • addedInput schema / properties / database / description
      Added value: +"Name of a configured database, exactly as list_databases returns it (case-sensitive). Not a DSN, host or server-side database name. An unknown name is an error that lists the configured names."
    • addedInput schema / properties / params / description
      Added value: +"Values bound to the $1, $2, ... placeholders in `sql`, in order, as real driver bind parameters. Omit when the SQL has no placeholders."
    • addedInput schema / properties / sql / description
      Added value: +"One read-only SQL statement (SELECT, WITH, VALUES, ...). Put values in $1, $2, ... placeholders and pass them in `params`. Multiple statements are rejected."
  2. First observed

TDQS

A4/5.0
Behavior3/5

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

Annotations already declare readOnlyHint=true, idempotentHint=true and destructiveHint=false, so safety is largely covered structurally. The description still adds real value beyond them by explaining that analyze=true actually executes the query, incurs full runtime cost, and never changes data. It does not cover error modes or plan size/limits, which keeps this above baseline but short of exceptional.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Front-loaded with the core action and well-paragraphed, but the params paragraph is somewhat verbose and partially restates the schema's own guidance about $1/$2 placeholders. Most sentences earn their place, yet the description runs longer than needed for a four-parameter tool.

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?

With no output schema, the description correctly compensates by naming the return shape ('meta' and 'plan', the plan's lines in order). Combined with the analyze-cost warning and bind-parameter guidance, an agent has enough to call it correctly; only error/limit behavior is left implicit.

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 the schema already documents all four parameters and baseline 3 applies. The description adds genuine meaning about `params` — real driver binds, composes with analyze=true, don't rewrite the query with literals just to explain it — but says nothing further about `database` or `analyze` beyond what the schema states.

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 execution plan for a read-only query (EXPLAIN; optionally ANALYZE)' — and immediately distinguishes it from get_table_schema, which covers index inventory rather than plans. An agent can tell this apart from execute_read_query and get_table_schema 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 explicit when-to-use cases (confirm index usage, diagnose a slow query) and an explicit alternative with its condition ('to see what is indexed at all, use get_table_schema with include_indexes=true'). It also sets a when-not condition for analyze=true: avoid it on a query you already know is very slow, since it takes as long as the query itself.

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