Skip to content

Commit 6cede74

Browse files
fix(mcp): Show the chart peak only for a single series
Across groups, the highest bucket headlines one group and reads as the chart's peak. Sentry's own chart widgets show no peak, so grouped charts now return peak null and the view omits it. Bumps the view to v3. Co-Authored-By: David Cramer <[email protected]>
1 parent 54933b4 commit 6cede74

11 files changed

Lines changed: 24 additions & 26 deletions

File tree

‎.agents/skills/verify-toolkit/map/mcp-apps.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ the host theme, and calls the tool again through the host. The goals are in
1515
- `view-theme` The view follows the host's light or dark theme. Proof: `drive`.
1616
- `range-roundtrip` The range picker calls `render_sentry_chart` through the host with the new period and redraws without remounting. Proof: `drive`.
1717
- `open-link` "Open in Sentry" asks the host to open the result's Sentry URL with `ui/open-link`. Proof: `drive`.
18-
- `grouped` A `groupBy` result draws one series per top group, with a legend that shows each group's short label and event count. Proof: `drive`.
18+
- `grouped` A `groupBy` result draws one series per top group, with a legend that shows each group's short label and event count, and no peak, since one group's bucket would read as the chart's peak. Proof: `drive`.
1919
- `top-by-volume` A grouped chart of a non-additive aggregate, such as p95 by release, plots the groups with the most events, not the sparse groups with the highest values. Proof: `drive`.
2020
- `null-gaps` A bucket with no data is null in the result, not 0, and the view draws it as a gap; a bucket with no data on either side is a dot, and its tooltip row reads "no data". Proof: `drive`.
2121
- `compact-result` The result for 5 series of 168 buckets (7 days at 1h) stays under 16 KiB, and its text content is the same JSON. Proof: `drive`.

‎.agents/skills/verify-toolkit/scripts/mcp-apps-host.mjs‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,14 @@ try {
305305

306306
await mount("dark", GROUPED_CHART, groupedResult);
307307
const legend = await frame.locator(".legend").innerText();
308+
const groupedStats = await frame.locator(".stats").innerText();
308309
const grouped = await shot("chart-grouped-dark.png");
309310
check(
310311
"grouped",
311-
legend.split("\n").filter(Boolean).length === 5,
312-
`top groups "${legend.replace(/\n/g, " | ")}" -> ${grouped}`,
312+
legend.split("\n").filter(Boolean).length === 5 &&
313+
groupedChart.peak === null &&
314+
!groupedStats.includes("Peak"),
315+
`top groups "${legend.replace(/\n/g, " | ")}", stats "${groupedStats.replace(/\n/g, " ")}", peak ${groupedChart.peak} -> ${grouped}`,
313316
);
314317

315318
// The sparsest charted release has data in 4 of 168 buckets. Its empty
-9.11 KB
Loading
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
PASS mcp-apps#tool-meta: render_sentry_chart _meta.ui.resourceUri=ui://sentry/chart/v2.html, openai/outputTemplate=ui://sentry/chart/v2.html
2-
PASS mcp-apps#view-resource: resources/read ui://sentry/chart/v2.html: text/html;profile=mcp-app, 17 KiB HTML
1+
PASS mcp-apps#tool-meta: render_sentry_chart _meta.ui.resourceUri=ui://sentry/chart/v3.html, openai/outputTemplate=ui://sentry/chart/v3.html
2+
PASS mcp-apps#view-resource: resources/read ui://sentry/chart/v3.html: text/html;profile=mcp-app, 17 KiB HTML
33
PASS mcp-apps#view-renders: light chart with hover tooltip "Sep 10, 16:00 UTC count() 91" -> docs/evidence/mcp-apps-chart/chart-light.png
44
PASS mcp-apps#view-theme: host theme light=rgb(255, 255, 255) dark=rgb(30, 26, 37) -> docs/evidence/mcp-apps-chart/chart-dark.png
55
PASS mcp-apps#range-roundtrip: "errors · level:error · Last 24 hours" -> view called render_sentry_chart period=7d through the host, got 56 buckets -> docs/evidence/mcp-apps-chart/chart-range-7d.png
66
PASS mcp-apps#open-link: ui/open-link https://sentry-mcp-evals.sentry.io/explore/discover/homepage/?dataset=errors&queryDataset=error-events&query=level%3Aerror&project=-1&field=count%28%29&sort=-count%28%29&statsPeriod=7d&mode=aggregate&yAxis=count%28%29
7-
PASS mcp-apps#compact-result: 5 series x 168 buckets: structuredContent 12387 bytes, text 12387 bytes (budget 16384)
7+
PASS mcp-apps#compact-result: 5 series x 168 buckets: structuredContent 12286 bytes, text 12286 bytes (budget 16384)
88
PASS mcp-apps#top-by-volume: p95 by release picks the releases with the most events: 3f9c2e1=20160, 8b41d07=10080, c05e9a3=3360, 1d7f4b2=57, e2a86c9=23
9-
PASS mcp-apps#grouped: top groups "3f9c2e1 · 20.2K events | 8b41d07 · 10.1K events | c05e9a3 · 3.4K events | 1d7f4b2 · 57 events | e2a86c9 · 23 events" -> docs/evidence/mcp-apps-chart/chart-grouped-dark.png
9+
PASS mcp-apps#grouped: top groups "3f9c2e1 · 20.2K events | 8b41d07 · 10.1K events | c05e9a3 · 3.4K events | 1d7f4b2 · 57 events | e2a86c9 · 23 events", stats "Interval 1h", peak null -> docs/evidence/mcp-apps-chart/chart-grouped-dark.png
1010
PASS mcp-apps#null-gaps: e2a86c9 has 4 of 168 buckets with data and no 0s; drawn as 4 dots and 0 lines; tooltip at the left edge "Sep 4, 01:00 UTC 3f9c2e1 6.44s 8b41d07 7.59s c05e9a3 8.04s 1d7f4b2 no data e2a86c9 no data"
1111
PASS mcp-apps#lifecycle: host-context-changed -> light, tool-cancelled -> "The chart request was cancelled.", ui/resource-teardown -> {}
1212
PASS mcp-apps#default-csp: 0 console errors under the default CSP

‎packages/mcp-core/chart-app/main.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ function render(): void {
162162
items.push(
163163
stat(
164164
"Peak",
165-
`${formatValue(chart.peak.value, chart)}${single ? "" : ` (${shortLabel(chart.peak.series)})`} at ${formatTooltipTime(Date.parse(chart.peak.time), format)}`,
165+
`${formatValue(chart.peak.value, chart)} at ${formatTooltipTime(Date.parse(chart.peak.time), format)}`,
166166
),
167167
);
168168
}

‎packages/mcp-core/src/server.ui-resources.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ vi.mock("@sentry/core/server", () => ({
1515
wrapMcpServerWithSentry: vi.fn((server) => server),
1616
}));
1717

18-
const CHART_URI = "ui://sentry/chart/v2.html";
18+
const CHART_URI = "ui://sentry/chart/v3.html";
1919
const MCP_APP_MIME_TYPE = "text/html;profile=mcp-app";
2020

2121
async function connect(skills: Skill[], experimentalMode = true) {

‎packages/mcp-core/src/tools/catalog/render-sentry-chart.test.ts‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,7 @@ describe("render_sentry_chart", () => {
155155
{ label: "2.4.1", count: 40, total: null, values: [120, null] },
156156
{ label: "(none)", count: 39, total: null, values: [119, null] },
157157
]);
158-
expect(chart.peak).toEqual({
159-
series: "2.4.1",
160-
time: "2025-09-10T23:00:00.000Z",
161-
value: 120,
162-
});
158+
expect(chart.peak).toBeNull();
163159
});
164160

165161
// The busy releases have steady traffic; the sparse ones have 1 to 57
@@ -196,8 +192,7 @@ describe("render_sentry_chart", () => {
196192
}
197193
const sparse = chart.series[4]?.values ?? [];
198194
expect(sparse.filter((value) => value === null)).toHaveLength(164);
199-
expect(chart.peak?.series).toBe(chart.series[0]?.label);
200-
expect(chart.peak?.value).toBeLessThan(30_000);
195+
expect(chart.peak).toBeNull();
201196
// 5 series of 168 buckets is about 12 KB; one object per bucket, as
202197
// before, came to about 200 KB.
203198
expect(JSON.stringify(chart).length).toBeLessThan(16 * 1024);

‎packages/mcp-core/src/tools/catalog/render-sentry-chart.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,18 +124,18 @@ function toChart(
124124
};
125125
});
126126

127-
// The peak describes the first series, which has the most events, so a
128-
// sparse group's outlier bucket never headlines the chart.
127+
// Only a single-series chart has a peak. Across groups, any one bucket
128+
// would headline a single group, which reads as the chart's peak.
129129
let peak: ChartResult["peak"] = null;
130-
const first = series[0];
131-
for (const [index, value] of (first?.values ?? []).entries()) {
130+
const only = series.length === 1 ? series[0] : undefined;
131+
for (const [index, value] of (only?.values ?? []).entries()) {
132132
const bucket = buckets[index];
133-
if (!first || value === null || !bucket || incomplete.includes(index)) {
133+
if (!only || value === null || !bucket || incomplete.includes(index)) {
134134
continue;
135135
}
136136
if (!peak || value > peak.value) {
137137
peak = {
138-
series: first.label,
138+
series: only.label,
139139
time: new Date(bucket.timestamp).toISOString(),
140140
value,
141141
};

‎packages/mcp-core/src/tools/support/chart/schema.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export const renderSentryChartOutputSchema = z.object({
6262
.object({ series: z.string(), time: z.string(), value: z.number() })
6363
.nullable()
6464
.describe(
65-
"Highest bucket of the first series that is no longer receiving data.",
65+
"Highest bucket that is no longer receiving data; null for grouped charts.",
6666
),
6767
ingestion: ingestionSchema,
6868
});

‎packages/mcp-core/src/ui-resources.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ export interface UiResource {
5454

5555
/** The render_sentry_chart view. Built from chart-app/ by generate-chart-app. */
5656
export const CHART_UI_RESOURCE: UiResource = {
57-
uri: "ui://sentry/chart/v2.html",
57+
uri: "ui://sentry/chart/v3.html",
5858
name: "sentry_chart",
5959
title: "Sentry Chart",
6060
description:
6161
"Interactive time series chart for render_sentry_chart results, with a range picker and a link to Sentry.",
6262
htmlSha256:
63-
"7ae4d2a0e01f03f9e167d4ffc61f8a254532dd518548aa18707a6e45887ae904",
63+
"5383b9d3a0f90695bd6811f4f4ed0a8c5a31edef6a3073c1e84990dd38ef5d39",
6464
// About 1.5x the current view, so a new dependency cannot slip in.
6565
budgetBytes: 24 * 1024,
6666
loadHtml: async () =>

0 commit comments

Comments
 (0)