Skip to main content
Glama

optimize_query

Read-onlyIdempotent

Rewrites a slow read-only SQL query to run faster by testing model-proposed variants that return identical rows under the caller's roles, then returns the quickest with timings and every attempt.

Instructions

Make a slow read faster: the server's model proposes rewrites, each must return identical rows and pass run_query's checks, and the fastest one is returned with both timings and every attempt. If nothing is both identical and faster, the original comes back. Runs the query several times (bounded by a time budget). Only available when the server has a model configured; otherwise use explain_query and compare_queries 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": {
      "sql": "<sql>"
    },
    "name": "optimize_query"
  }
}

Input Schema

NameRequiredDescriptionDefault
sqlYesOne 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.
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.
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.4/5.0
Behavior4/5

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

Annotations already cover the safety profile (readOnly, idempotent, non-destructive), and the description adds genuinely new behavior: the query is executed several times under a time budget, every rewrite must return identical rows and pass run_query's checks, and the original is returned when no candidate is both identical and faster. The only minor gap is that per-attempt failure detail is left to the output schema, which exists.

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 description is front-loaded with the outcome, followed by mechanism, verification rule, fallback, and availability constraint—every sentence carries information. It is dense in a single unbroken paragraph, but no sentence is 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 tool with non-obvious costs (multiple executions) and a server-side gating condition, the description covers execution semantics, correctness guarantees, fallback behavior, and the unavailability case. Return-value details are correctly delegated to the existing output schema and parameter semantics to the schema.

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%, with sql, roles, and principal each documented in detail inside the schema, including the read-only SELECT restriction and visibility semantics. The description adds no parameter-level information beyond that, so the baseline of 3 applies.

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?

"Make a slow read faster" states the goal with a specific verb-and-resource framing, then names the mechanism (server model proposes rewrites, verified for identical rows, fastest returned). It is clearly distinguishable from explain_query and compare_queries, which it explicitly identifies as the manual alternatives.

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 gives an explicit availability condition (only when the server has a model configured) and names the fallback path: use explain_query and compare_queries with your own model otherwise. The opening clause also signals the triggering situation (a slow read), so the agent knows both when to call it and when not to.

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