Skip to main content
Glama

Preview Alert Rule

preview_alert_rule
Read-onlyIdempotent

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 rules get a backtest too, with the same fields. Its would-fire counts are approximate: the backtest scores each window against the whole lookback, while the live rule compares against the same time of day 7, 14 and 21 days back. Both read a window with no data as 0 for counts, sums and counter rates, and leave it out for latencies, averages, minimums, maximums, error rates and burn rates.

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

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, 30])
windowMinutesNoRolling window length in minutes; values below 1 are clamped up to 1
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. Changed2 schema fields changed
    • changedInput schema / properties / lookbackDays / description
      Previous value: -"Days of history to backtest (default 7, clamped to [1, maxBacktestDays])"New value: +"Days of history to backtest (default 7, clamped to [1, 30])"
    • changedInput schema / properties / windowMinutes / description
      Previous value: -"Rolling window length in minutes; values below the configured minimum (5) are clamped up"New value: +"Rolling window length in minutes; values below 1 are clamped up to 1"
  2. Changed10 schema fields changed
    • addedInput schema / $schema
      Added value: +"https://json-schema.org/draft/2020-12/schema"
    • removedInput schema / additionalProperties
      Removed value: -false
    • addedInput schema / properties / anomalyConsecutiveWindows / format
      Added value: +"int32"
    • addedInput schema / properties / criticalConsecutiveWindows / format
      Added value: +"int32"
    • addedInput schema / properties / criticalThreshold / format
      Added value: +"double"
    • addedInput schema / properties / lookbackDays / format
      Added value: +"int32"
    • addedInput schema / properties / warningConsecutiveWindows / format
      Added value: +"int32"
    • addedInput schema / properties / warningThreshold / format
      Added value: +"double"
    • addedInput schema / properties / windowMinutes / format
      Added value: +"int32"
    • addedInput schema / properties / zScoreThreshold / format
      Added value: +"double"
  3. Added
  4. Removed
  5. 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"
  6. 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"
      +}
  7. First observed

TDQS

A4.9/5.0
Behavior5/5

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

Annotations already declare readOnly/idempotent/non-destructive, but the description adds meaning beyond them: 'never persists anything, never throws for an invalid spec,' and the critical problems[] vs warnings[] distinction (warnings never block saving). The FIELD_NEVER_OBSERVED + NO_MATCHING_DATA diagnostic and the anomaly-backtest approximation caveat are exactly the kind of behavior an agent cannot get from annotations.

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?

Key routing ('call this before save_alert_rule') and the most dangerous trap (dataCoverage before totalWouldFire) are correctly front-loaded, and the dense length is partly justified by 21 parameters. It loses a point for redundancy: the derivedGroupBy example and the 'label is what rule pages and alert titles show' point are duplicated verbatim from the schema description, and the 'Both fields are required and non-blank' note restates the schema's required array.

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?

No output schema exists, so the description carries full burden for return values — and it enumerates every field (normalizedSpec, problems[], backtest with dataCoverage and per-series values, seasonality with suggestedMode, warnings[]) plus how to interpret them. For a 21-parameter, nested-object tool with no annotations on failure behavior, nothing an agent needs to invoke it correctly 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%, so 3 would be the baseline, but the description adds cross-parameter semantics the schema cannot express: fromQuerySql overrides the structured fields, groupBy and derivedGroupBy compose, anomaly conditions replace comparator/warningThreshold and require an empty groupBy, and a parenthesis/space in a groupBy string is rejected. These are interaction rules, not restated field meanings.

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 first sentence gives a specific verb+resource with scope: it 'validates and normalizes a candidate rule spec and, when valid, backtests how often it WOULD have fired.' The 'preview→save gateway' framing and the explicit 'Call this before save_alert_rule' line make it unmistakable against the sibling that actually persists rules.

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 exactly when to call it (before save_alert_rule, to calibrate), when-not to act (fix problems[] before saving; don't loosen the threshold on NO_MATCHING_DATA), and the exclusive modes (structured fields vs fromQuerySql). It even explains downstream behavior — save_alert_rule re-runs identical validation — removing guesswork.

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