Skip to main content
Glama

preview_alert_rule

The preview→save gateway: validates and normalizes a candidate rule spec and, when valid, backtests how often it WOULD have fired over the last N days (default 7). READ: never persists anything, never throws for an invalid spec.

Call this before save_alert_rule to calibrate. IMPORTANT: check backtest.dataCoverage first, before reading totalWouldFire — dataCoverage.status = NO_MATCHING_DATA means the filter matched zero rows over the whole window (likely a typo'd field or wrong value in the filter), NOT a calibrated threshold; fix the filter, don't touch the threshold. Only when status = EVALUATED (rows were matched) does totalWouldFire being 0 suggest the threshold may be too high — if it fires every window, too low. Fix any entries in problems[] before saving — save_alert_rule re-runs this exact validation and will reject the same way.

Two modes — supply EITHER the structured measurement fields OR fromQuerySql (a raw QuerySQL SELECT parsed into a measurement draft, e.g. for "alert on this query"); when fromQuerySql is set the structured fields are ignored.

groupBy takes plain field names only, e.g. service. To group by a computed value, pass derivedGroupBy entries instead, each an object {"expression": "...", "label": "..."}, e.g. {"expression": "regexp_extract(message, 'customerId=([0-9a-f-]+)', 1)", "label": "customer"}. Both fields are required and non-blank, and the label is what rule pages and alert titles show, so give it a short readable name. A groupBy string that looks like an expression (it contains a parenthesis or a space) is rejected in problems[], because the rule page and the alert title would otherwise show the raw expression as the group name. groupBy and derivedGroupBy can be used together.

Static condition: comparator + warningThreshold (+ optional criticalThreshold escalation). Anomaly condition: zScoreThreshold + direction instead of comparator/warningThreshold; groupBy must be empty. Anomaly backtest is not yet supported — backtest is null for those.

Returns normalizedSpec (best-effort echo of the compiled spec), problems[] (empty when valid), backtest (would-fire counts, per-series observed values, and dataCoverage — rowsMatched/firstEventAt/lastEventAt/status over the backtest window — only when valid), seasonality (a 0-1 daily-periodicity score of the backtest's primary series plus a suggestedMode of ANOMALY/THRESHOLD/UNKNOWN — a data-driven nudge on baseline vs fixed-threshold rules; null when there was no backtest), and warnings[] (calibration hints, NEVER a reason to withhold saving — unlike problems[], a non-empty warnings[] still saves fine). warnings[] currently carries one code, FIELD_NEVER_OBSERVED: a filter/groupBy field that querysql couldn't resolve to a known column (so it silently reads from the JSON catch-all) and that has never appeared in this customer's recent telemetry. FIELD_NEVER_OBSERVED together with dataCoverage.status = NO_MATCHING_DATA is a strong signal of a typo'd field name — fix the spelling and re-preview rather than loosening the threshold.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fnNoCatalog measure function: count, error_rate, p95, error_burn_rate, ...
argNoOptional field the measure operates on, e.g. duration_ms
unitNoExplicit display unit for the measure, e.g. BYTES or DURATION_MS — set it when the metric name doesn't self-describe its unit (OTel names like jvm.memory.used or http.server.request.duration carry no unit suffix); omit to let the server infer the unit from the metric name or measure function
filterNoOptional QuerySQL boolean filter, e.g. service = 'my-svc'
paramsNoOptional named measure params, e.g. {"budget":"0.001"}
sourceNoTelemetry source: LOGS, SPANS, METRICS
groupByNoOptional plain field names to group the series by, e.g. service. Field names only: a string that looks like an expression is rejected, pass it in derivedGroupBy instead
directionNoAnomaly direction: HIGH or LOW
comparatorNoThreshold comparator: GT, GTE, LT, LTE (static rules)
metricNameNoMetric name (required only when source is METRICS)
metricTypeNoMetric type: GAUGE, SUM, HISTOGRAM, ... (only when source is METRICS)
fromQuerySqlNoRaw QuerySQL SELECT to derive the spec from, instead of the structured fields
lookbackDaysNoDays of history to backtest (default 7, clamped to [1, maxBacktestDays])
windowMinutesNoRolling window length in minutes; values below the configured minimum (5) are clamped up
derivedGroupByNoOptional computed group keys, each an object with an expression and a label, e.g. {"expression": "regexp_extract(message, 'customerId=([0-9a-f-]+)', 1)", "label": "customer"}. The label is what rule pages and alert titles show
zScoreThresholdNoAnomaly z-score threshold (> 0) — supply instead of comparator/warningThreshold
warningThresholdNoWarning-tier threshold (static rules)
criticalThresholdNoOptional critical-tier threshold (escalation)
anomalyConsecutiveWindowsNoConsecutive anomalous windows required (>= 1)
warningConsecutiveWindowsNoConsecutive breaching windows for the warning tier (default 1)
criticalConsecutiveWindowsNoConsecutive breaching windows for the critical tier (default 1)

Schema Changelog

Changes observed during successful MCP inspections.

  1. Added
  2. Removed
  3. Changed2 schema fields changed
    • addedInput schema / properties / derivedGroupBy
      Added value: +{
      +  "description": "Optional computed group keys, each an object with an expression and a label, e.g. {\"expression\": \"regexp_extract(message, 'customerId=([0-9a-f-]+)', 1)\", \"label\": \"customer\"}. The label is what rule pages and alert titles show",
      +  "items": {
      +    "properties": {
      +      "expression": {
      +        "description": "QuerySQL expression whose value the series are grouped by, e.g. regexp_extract(message, 'customerId=([0-9a-f-]+)', 1)",
      +        "type": "string"
      +      },
      +      "label": {
      +        "description": "Short readable name for the expression, e.g. customer. This is what rule pages and alert titles show, never the expression itself.",
      +        "type": "string"
      +      }
      +    },
      +    "required": [
      +      "expression",
      +      "label"
      +    ],
      +    "type": "object"
      +  },
      +  "type": "array"
      +}
    • changedInput schema / properties / groupBy / description
      Previous value: -"Optional fields to group the series by"New value: +"Optional plain field names to group the series by, e.g. service. Field names only: a string that looks like an expression is rejected, pass it in derivedGroupBy instead"
  4. Changed1 schema field changed
    • addedInput schema / properties / unit
      Added value: +{
      +  "description": "Explicit display unit for the measure, e.g. BYTES or DURATION_MS — set it when the metric name doesn't self-describe its unit (OTel names like jvm.memory.used or http.server.request.duration carry no unit suffix); omit to let the server infer the unit from the metric name or measure function",
      +  "type": "string"
      +}
  5. First observed

TDQS

A5/5.0
Behavior5/5

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

With no annotations and no output schema, the description carries the full behavioral burden and handles it thoroughly: never persists, never throws, structured fields ignored when fromQuerySql is set, anomaly backtest is null, and warnings[] never blocks saving. It also details rejection behavior and the FIELD_NEVER_OBSERVED signal.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is long but every sentence adds operational value, and it is front-loaded with the core purpose, then usage guidance, then parameter modes and return semantics. Despite its length, there is no filler or repetition.

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 21-parameter, no-output-schema tool, this is exceptionally complete. It documents the full return surface—normalizedSpec, problems[], backtest, seasonality, warnings[]—including dataCoverage statuses and how to interpret NO_MATCHING_DATA vs EVALUATED. Nothing an agent needs to call and interpret this tool is missing.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, but the description still adds crucial semantics: the mutual exclusivity of fromQuerySql vs structured fields, groupBy plain-name restrictions, derivedGroupBy expression/label requirements, static vs anomaly condition modes, and clamping/defaulting behavior for lookbackDays and windowMinutes. This goes far beyond the 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 description names a specific verb ('validates and normalizes') and resource ('a candidate rule spec') and immediately frames it as the 'preview→save gateway', distinguishing it from sibling save_alert_rule. It also states the read-only nature and that it never persists or throws.

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?

Explicitly instructs 'Call this before save_alert_rule to calibrate' and explains how to interpret backtest results before adjusting thresholds. It also tells the agent to fix problems[] before saving, and that save_alert_rule re-runs the same validation, making the usage workflow unambiguous.

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

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.

Resources