Skip to main content
Glama
Elekto MCP for SQL Server

Elekto MCP for SQL Server

Official

Find queries in the Query Store

find_query_store_queries
Read-onlyIdempotent

Find Query Store queries by text fragment or procedure, function, or trigger; with no filter, return queries ranked by total duration in a time window, with IDs, plans, and execution metrics.

Instructions

Finds Query Store queries by part of their text or by the procedure, function or trigger that runs them; with neither, the ones that took the most time in the window. Returns each one's query_id, the first 300 characters of its text, its number of plans, its executions in the window with their total and average duration, CPU and logical reads, maximum duration and failed executions, and its last execution. The variants of a parameter-sensitive query (SQL Server 2022+) count under it. Use it to get the query_id that get_query_store_history takes; to find what got slower use list_query_store_regressions. Needs VIEW DATABASE STATE (2022+: VIEW DATABASE PERFORMANCE STATE), which VIEW SERVER STATE implies.

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": "find_query_store_queries"
  }
}

Input Schema

NameRequiredDescriptionDefault
topNoMost queries to return (default 20, at most 100).
daysNoDays back to add up executions and time over (default 7).
schemaNoSchema of object_name, which it needs. Empty searches every schema. Example: 'Feeder'
databaseYesName of the database as registered in the configuration.
object_nameNoProcedure, function or trigger whose statements to list, bare, with no schema prefix. Empty means any query, inside a module or not. Example: 'LoadPrices'
text_patternNoPart of the query text, matched anywhere in it as written: brackets, % and _ are plain characters, so a fragment copied from a query_text finds it. At most 1000 characters. Empty means any text. Example: '[dbo].[GenericSecurity]'

Schema Changelog

Changes observed during successful MCP inspections.

  1. Addedv2.6.1

TDQS

A4.6/5.0
Behavior4/5

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

Annotations already establish readOnly, idempotent, non-destructive, so the description's real contribution is the permissions contract ('VIEW DATABASE STATE', 2022+ equivalent, implied by VIEW SERVER STATE) plus the default ranking rule and the note that parameter-sensitive query variants roll up under the parent. It does not discuss result caps beyond what the top parameter implies, but the safety and auth profile is well covered.

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-loaded with the three search modes, then returns, then permissions – a sensible order. The return-value sentence is long and comma-chained but each listed field is genuinely useful given there is no output schema; only minor tightening is possible.

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?

Covers selection modes, default behavior, return contents, downstream chaining, sibling alternatives, and the required permission level for a six-parameter read tool with no output schema. An agent has everything needed to decide to call it and to interpret the result.

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, but the description adds meaning the schema does not: the interaction between object_name and text_pattern being empty (fall back to highest-time queries in the window) and the coupling of schema to object_name. That ranking semantics is the single most decision-relevant detail and it lives only in the description.

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 ('Finds Query Store queries') and immediately narrows the three retrieval modes: by text fragment, by owning module, or by elapsed time when neither filter is given. That distinguishes it cleanly from get_query_store_history and find_cached_queries without requiring the schema to be opened.

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 downstream use ('get the query_id that get_query_store_history takes') and an explicit exclusion with a named alternative ('to find what got slower use list_query_store_regressions'). Both the when and the when-not are stated, so an agent can route without inference.

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