Bug
When creating or updating alert rules via the alerting_manage_rules tool, the AlertQueryModel struct silently drops fields that are not explicitly defined in the Go struct. This causes alert rules with non-PromQL datasources (e.g., Graphite) and classic_conditions expressions to be created with incomplete query models, resulting in evaluation errors.
Steps to Reproduce
- Use
alerting_manage_rules with operation: create to create an alert rule with a Graphite datasource query and a classic_conditions expression
- Pass the full model including Graphite-specific fields (
target, datasource, textEditor) and classic_conditions fields (query.params, operator, reducer)
- The created rule fails evaluation with:
[sse.parseError] failed to parse expression [A]: condition 1 is missing the query RefID argument
Root Cause
In tools/alerting_manage_rules_types.go, AlertQueryModel only defines typed fields for PromQL-style queries:
type AlertQueryModel struct {
Expr string `json:"expr,omitempty"`
Type string `json:"type,omitempty"`
Expression string `json:"expression,omitempty"`
Reducer string `json:"reducer,omitempty"`
Conditions []AlertCondition `json:"conditions,omitempty"`
}
And AlertCondition only captures evaluator:
type AlertCondition struct {
Evaluator ConditionEvaluator `json:"evaluator"`
}
When convertAlertQueries() marshals q.Model to JSON and then to map[string]any, fields not in the struct are silently dropped:
- Graphite:
target, datasource, textEditor — query has no expression at all
- Classic conditions:
query.params (carries the RefID reference, e.g. ["C"]), operator, reducer — condition is incomplete and fails parsing
Affected Datasources
Any datasource that uses model fields beyond expr:
- Graphite (
target, datasource, textEditor)
- Classic conditions (
query.params, operator, reducer)
- Likely also: CloudWatch, Elasticsearch, InfluxDB, and others with custom model fields
Environment
- mcp-grafana v0.11.6
- Grafana (self-hosted)
Fix
#730
Bug
When creating or updating alert rules via the
alerting_manage_rulestool, theAlertQueryModelstruct silently drops fields that are not explicitly defined in the Go struct. This causes alert rules with non-PromQL datasources (e.g., Graphite) and classic_conditions expressions to be created with incomplete query models, resulting in evaluation errors.Steps to Reproduce
alerting_manage_ruleswithoperation: createto create an alert rule with a Graphite datasource query and a classic_conditions expressiontarget,datasource,textEditor) and classic_conditions fields (query.params,operator,reducer)Root Cause
In
tools/alerting_manage_rules_types.go,AlertQueryModelonly defines typed fields for PromQL-style queries:And
AlertConditiononly capturesevaluator:When
convertAlertQueries()marshalsq.Modelto JSON and then tomap[string]any, fields not in the struct are silently dropped:target,datasource,textEditor— query has no expression at allquery.params(carries the RefID reference, e.g.["C"]),operator,reducer— condition is incomplete and fails parsingAffected Datasources
Any datasource that uses model fields beyond
expr:target,datasource,textEditor)query.params,operator,reducer)Environment
Fix
#730