Skip to content

feat(promql): a query_promql MCP tool - #2665

Open
Makisuo wants to merge 30 commits into
promql/3-pushdownfrom
promql/4-mcp
Open

Makisuo wants to merge 30 commits into
promql/3-pushdownfrom
promql/4-mcp

fix(promql): query_promql's min/avg/max cover every point, not only t…

bb15f5f
Select commit
Loading
Failed to load commit list.
Maple Review Bot / Maple / review succeeded Nov 16, 2026 in 4m 38s

Confidence 10/10 · No issues found

🟢 Confidence 10/10 · safe to merge. Whole diff read; range, instant, step gate, truncation, stats and escaping are each pinned by a tool test — only the MAX_STEPS boundary arithmetic is untested and harmless.
no findings · tests covered · risk medium · 1/1 new units observable

Adds the query_promql MCP tool: range or instant PromQL through PromqlQueryService, capped at 20 series and 200 points, with min/avg/max over every point. The earlier stats defect (F10) is fixed; the open McpQueryError issues in registry.ts are untouched — that file only gains a registration line.

  • query_promql evaluates PromQL over a range or once at end_time
  • defaultStepSeconds picks the smallest round step keeping about 120 points
  • capSeries keeps the 20 highest-peak series and each one's last 200 points
  • PromQL parse and evaluation errors become McpInvalidInputError on query

Fixed since the last review

  • ✅ F10 · stats summarises the last 200 points, not the series it reports

Production impact

Open errors in the changed files (2)
Issue Service Occurrences File
@maple/mcp/errors/McpQueryError (7 issues) maple-ai 30 apps/ai/src/mcp/tools/registry.ts
@maple/mcp/errors/McpQueryError (3 issues) maple-chat 12 apps/ai/src/mcp/tools/registry.ts

After this merges, Maple checks whether they stop.

Telemetry this change adds and removes (3)
  • ➕ span name McpTool.queryPromql · apps/ai/src/mcp/tools/query-promql.ts:38
  • ➕ attribute maple.ai.promql.instant · apps/ai/src/mcp/tools/query-promql.ts:64
  • ➕ attribute maple.ai.promql.step_seconds · apps/ai/src/mcp/tools/query-promql.ts:65
What was checked
  • resolveWindow rejects width <= 0, so no reversed or zero window reaches the step maths
  • Series names and note text go through tableCell in list items, pinned by the a|b test
  • Spans carry org id, flags, step and query length only — never the PromQL text
Observability coverage: 1 of 1 changes observable
Change Kind Observable Evidence
query_promql MCP tool handler inbound MCP tool entrypoint yes Effect.fn("McpTool.queryPromql") span plus maple.ai.promql.* attributes on it, query-promql.ts:58-70

bb15f5f · Reply "won't fix" to dismiss a finding, or mention @maple-review-bot to ask about one.