Skip to main content
Glama
Elekto MCP for SQL Server

Elekto MCP for SQL Server

Official

Estimated plan of a procedure or a query

get_estimated_plan
Read-onlyIdempotent

Compiles a stored procedure or SELECT with supplied parameter values under SHOWPLAN_XML and summarizes the estimated plan SQL Server would use, including costs, warnings and missing indexes.

Instructions

Compiles a stored procedure for the parameter values given, or one SELECT, under SET SHOWPLAN_XML ON, and summarizes the plan SQL Server would use now, as get_query_plan_summary does for a Query Store plan: per statement the estimated rows, cost and share of the whole, parallelism, the compiled parameter values, the statistics used, warnings, missing indexes and the costliest operators. Nothing runs (but for a deterministic CLR function with constant arguments, which SQL Server evaluates while compiling), and the plan is neither cached nor recorded by the Query Store; but compiling creates missing statistics and updates stale ones, as running would (with AUTO_UPDATE_STATISTICS_ASYNC the update is queued), and the answer names any it changed. When the procedure already has a plan in the plan cache, SQL Server returns that plan, compiled for the values of the run that cached it, and the answer says so (plan_from_cache). Use it to see the plan a procedure gets for given values, or how a rewrite or a hint changes a statement; for the plans that actually ran use get_query_store_history and get_query_plan_summary. A procedure that fills a temporary table with SELECT ... INTO and then reads it cannot be compiled without running: pass its statements in 'query' instead. Statements reading a temporary table or table variable are estimated as if it were empty, dynamic SQL is not compiled, and a CLR procedure has no plan to compile. Needs SHOWPLAN on the database, plus EXECUTE on the procedure or SELECT on what the query reads.

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>"
    },
    "name": "get_estimated_plan"
  }
}

Input Schema

NameRequiredDescriptionDefault
queryNoOne SELECT to compile instead of a procedure, with literal values where a procedure would have parameters (a variable has no value here). CTEs, UNION, subqueries and query hints (OPTION) are accepted, and so are global temporary tables (##name); INTO, any other statement, local temporary tables (#name), linked servers and system functions that open files are refused. At most 32768 characters. Example: "SELECT SecurityId, SUM(Price) FROM dbo.Quote WHERE ReferenceDate = '2026-11-27' GROUP BY SecurityId"
schemaNoSchema of 'procedure'. Empty searches every schema, and fails naming them when the name exists in more than one. Example: 'AutoRegister'
databaseYesName of the database as registered in the configuration.
procedureNoStored procedure to compile, bare, with no schema prefix: every statement of it is compiled for the values in 'parameters'. Leave empty to compile 'query' instead. Example: 'AutoRegisterEquity'
statementNoNumber of one statement to return alone, its statement_number. 0 (default) returns every statement, or the 20 costliest, with statement_index listing them all, when there are more.
parametersNoThe procedure's values as they follow its name in an EXEC, by name or in order: "@referenceDate = '2026-11-27', @registerType = 'e'". Literals only (text and dates in quotes, numbers, 0x binary, NULL, DEFAULT; a text parameter takes only a value in quotes, since EXEC would pass 007 as '7'); each is converted to its parameter's declared type and sent as a typed parameter, never as SQL, and a value the conversion would change is refused. A parameter left out takes its default (one without a default is an error), an OUTPUT one left out goes as NULL where its type can carry NULL, and a table-valued one cannot be given and compiles empty.
max_operatorsNoHow many of the costliest operators to keep per statement (default 40, at most 200). Every operator above them comes too, so that the tree reads from the root, and operators_shown can exceed this.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Addedv2.6.1

TDQS

A4.8/5.0
Behavior5/5

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

Goes well past the readOnly/idempotent annotations by disclosing that compiling creates missing statistics and updates stale ones (queued under AUTO_UPDATE_STATISTICS_ASYNC), that the plan is not cached or recorded by Query Store, that a CLR function with constant arguments may actually be evaluated, and that an already-cached plan is returned and flagged as plan_from_cache. It also names the permission prerequisites (SHOWPLAN plus EXECUTE or SELECT) and the compile-time blind spots (temp tables treated as empty, dynamic SQL and CLR procedures skipped).

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?

The purpose and the SHOWPLAN mechanism are front-loaded, and the long middle clause is dense but every clause carries operational information. It is a single heavy paragraph with semicolon-chained caveats, so a reader must work to locate the permission note and the temp-table limitation, but there is little true filler.

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?

For a 7-parameter compilation tool with no output schema, the description covers what is returned, side effects on statistics, caching behavior, permissions, and the specific input shapes that cannot be compiled. An agent has everything needed to decide whether to call it and to interpret plan_from_cache or statement truncation correctly.

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; the description earns above that by clarifying the procedure/query mutual exclusivity in practice and by telling the agent to move statements into 'query' when the procedure cannot be compiled. It does not restate the per-parameter syntax, which the schema already handles thoroughly.

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?

Opens with a specific verb and resource: compiles a stored procedure for given parameter values, or one SELECT, under SET SHOWPLAN_XML ON, and summarizes the estimated plan. It then enumerates exactly what the summary contains (estimated rows, cost share, parallelism, statistics used, warnings, missing indexes) and explicitly contrasts itself with get_query_plan_summary, which reports plans that actually ran.

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?

States the use case directly ('see the plan a procedure gets for given values, or how a rewrite or a hint changes a statement') and routes the agent to the right siblings for actual executions (get_query_store_history, get_query_plan_summary). It also gives a negative case with a workaround: a procedure using SELECT ... INTO into a temp table cannot be compiled, so pass its statements in 'query'.

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