Skip to main content
Glama
Elekto MCP for SQL Server

Elekto MCP for SQL Server

Official

Query Store history of one query

get_query_store_history
Read-onlyIdempotent

Retrieve a query's Query Store history: text, compile SET options, plans, and per-interval runtime stats and waits to diagnose performance changes.

Instructions

Returns the Query Store history of one query: its text (the first 4000 characters); the SET options it compiled with, such as ARITHABORT, which explain a query fast in SSMS and slow in the application; its plans (the 20 that ran most in the window, when it has more) with when each was first and last compiled and whether it is forced; and, per plan and per day, hour or Query Store interval, the executions (aborted and failed ones included, and also counted apart), average and maximum duration, average CPU, logical and physical reads, average and maximum DOP, and average rows, memory and tempdb, plus each plan's waits by category over the whole window. Use it with a query_id from list_query_store_regressions or find_query_store_queries; to see what a plan does use get_query_plan_summary with its plan_id. The Query Store keeps each plan's first and last compile time, not every recompilation.

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

Input Schema

NameRequiredDescriptionDefault
daysNoDays back to cover (default 7).
databaseYesName of the database as registered in the configuration.
query_idYesQuery Store query id, from list_query_store_regressions or find_query_store_queries.
granularityNoOne row per plan and per 'day' (default), 'hour' or 'interval', the Query Store's own interval. Rows are capped at 400, the newest kept.day

Schema Changelog

Changes observed during successful MCP inspections.

  1. Addedv2.6.1

TDQS

A4.7/5.0
Behavior5/5

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

Annotations already establish it is a read-only, idempotent, non-destructive, closed operation, yet the description still adds substantive behavior: aborted and failed executions are included and counted separately, only the 20 most-run plans are returned, and the Query Store stores only first/last compile time rather than every recompilation. The truncation at 4000 characters and the row cap are exactly the kind of caveats an agent needs before interpreting results.

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?

Everything stated is relevant and the purpose is front-loaded, but the body is a single ~130-word run-on sentence stitched together with semicolons, which makes the list of returned metrics hard to scan. Splitting the output inventory from the usage/caveat sentences would cost nothing and improve comprehension.

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, so the description carries the full burden of describing return values, and it does so field by field. Combined with the truncation and row-cap caveats, an agent has enough to call it correctly and interpret the results without further context.

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?

With 100% schema coverage the baseline is 3, and the description does add meaning: it spells out what a 'granularity' row actually contains (executions, duration, CPU, reads, DOP, rows, memory, tempdb per plan per bucket) and that 'days' is the covered window. It does not add syntax or edge-case detail for database or query_id beyond the schema, so it sits just above baseline.

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 definition opens with a specific verb and resource ('Returns the Query Store history of one query') and then enumerates exactly what is returned: query text truncated to 4000 characters, SET options, up to 20 plans with compile times and forced status, and per-plan/per-bucket runtime metrics plus wait categories. This makes it clearly distinguishable from siblings like list_query_store_regressions and get_query_plan_summary, which are named as the source of query_id and the drill-down for plan bodies.

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?

It states the prerequisite explicitly ('Use it with a query_id from list_query_store_regressions or find_query_store_queries') and routes the agent elsewhere for a different need ('to see what a plan does use get_query_plan_summary with its plan_id'). That covers both when to use it and which alternative to pick.

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