Skip to main content
Glama

compare_queries

Read-onlyIdempotent

Verify that a rewritten SQL query returns the same rows as the original, including ORDER BY order, and compare execution time to guide safe query optimization.

Instructions

Check a rewrite: do 'original' and 'candidate' return exactly the same rows (order too, when the original has ORDER BY), and how fast is each? Returns identical, reason, row counts, original_ms, candidate_ms and speedup; rows are compared inside the database and never returned. Both go through run_query's checks. 'new_literals' lists constants the candidate adds: a rewrite that hard-codes values from the data is only correct for today's rows, so do not add them. Use it with explain_query to make a slow query faster with your own model.

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": {
      "original": "<original>",
      "candidate": "<candidate>"
    },
    "name": "compare_queries"
  }
}

Input Schema

NameRequiredDescriptionDefault
rolesNoThe caller's roles or groups, e.g. ['finance', 'payroll']. Objects and columns restricted to a role are visible only when it is listed here. Omitted = no roles.
originalYesOne read-only SELECT (or WITH ... SELECT) written against the DDL select_schema returned. Writes, DDL and multiple statements are refused, as is any table or column this caller may not read.
candidateYesOne read-only SELECT (or WITH ... SELECT) written against the DDL select_schema returned. Writes, DDL and multiple statements are refused, as is any table or column this caller may not read.
principalNoWho is asking, as an identity string such as 'okta:jdoe'. Pass it whenever you know the user: visibility is decided for this identity. Omitted = anonymous, which sees only unrestricted objects.

Output Schema

NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. Addedv1.20.0

TDQS

A4.3/5.0
Behavior4/5

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

Annotations already declare readOnlyHint, idempotentHint, and destructiveHint=false, and the description adds real value beyond that: comparison happens inside the database and rows are never returned (privacy/cost), and both statements are subjected to run_query's validation. It doesn't discuss cost of running both queries twice or timeout behavior, keeping it below 5.

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 question the tool answers, then return fields, then the validation caveat, then the workflow hint. Dense but nearly every sentence carries information; the 'new_literals' warning is slightly tangential to invoking the tool but still prevents misuse.

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 an output schema present, enumerating returns (identical, reason, row counts, timing, speedup) is mild duplication but reinforces what to check. The definition covers validation, data exposure, and the practical workflow, leaving only minor gaps like error behavior when either query fails run_query checks.

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 semantic framing the schema lacks: original is the baseline and candidate is the rewrite whose equivalence is being tested, and ORDER BY in the original changes what 'identical' means. It says nothing specific about roles/principal handling, which remains schema-only.

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?

Names a specific verb and resource ('Check a rewrite') and defines the exact semantics: same rows, with order enforced when the original has ORDER BY, plus timing. It distinguishes itself from run_query by noting both queries go through its checks, so an agent can tell which tool actually performs the verification.

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?

Gives a concrete workflow: pair this with explain_query when rewriting a slow query, and warns not to hard-code data-derived constants because correctness only holds for today's rows. It stops short of stating explicit exclusions (e.g., not for comparing queries against different schemas or for validating writes), so a 4 rather than 5.

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