Skip to content

feat(mcp): Render Sentry time series charts inline in MCP Apps hosts - #2413

Merged
dcramer merged 23 commits into
mainfrom
feat/mcp-apps-chart
Nov 20, 2026
Merged

dcramer merged 23 commits into
mainfrom
feat/mcp-apps-chart

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Why

MCP Apps hosts (Claude, VS Code, ChatGPT/Codex) can render interactive charts inline, the way Datadog's MCP "Get Widget" does. Sentry MCP returns only text and JSON. This is v1 of #741, focused on charts.

What changed

  • defineTool passes _meta through to tools/list. A small ui-resources registry lists each ui:// view that a registered tool references, with mimeType text/html;profile=mcp-app (MCP Apps spec 2026-01-26).
  • New render_sentry_chart tool. It takes a query (dataset, query, yAxis, optional groupBy for the top 5 values, period or start/end) and fetches the series on the server. Values never pass through the model, and the full series is returned, not the 48 buckets search_events keeps.
  • The tool declares _meta.ui.resourceUri and openai/outputTemplate, both ui://sentry/chart/v1.html. It does not use ext-apps registerAppTool, which adds the deprecated flat ui/resourceUri key.
  • search_events time series results suggest render_sentry_chart with the same arguments.
  • The view (packages/mcp-core/chart-app/) is vanilla TS and SVG on the ext-apps App class. It has hover tooltips, hatched incomplete buckets, light/dark from the host, a 1h/24h/7d/14d picker that re-calls the tool through the host, and "Open in Sentry" via ui/open-link. It is self-contained, so the CSP declares no domains.
  • generate-chart-app bundles the view into a generated TS string, so stdio and the Worker need no file system. ci:policy fails on drift.
  • New verify-toolkit claim (map/mcp-apps.md, scripts/mcp-apps-host.mjs) mounts the view through ext-apps AppBridge in headless Chromium. Screenshots are in docs/evidence/mcp-apps-chart/.

Tradeoffs

  • The view is 407 KiB, mostly zod and the MCP client that ext-apps pulls in. It reuses the CLI's zodEnglishLocalesPlugin (down from 567 KiB).
  • The @sentry/mcp-server bundle budget rises from 3.75 to 4.4 MiB. The bundle is 4.10 MiB, about 3.70 MiB without the view.
  • The tool is listed in every client. Text-only clients still get the full series as data.
  • Tool definitions grow by about 1,200 tokens.

Blast Radius

Additive. Existing tools change only by the new suggested action on search_events time series results. The server now advertises the resources capability.

Open questions

  • Rendering in real Claude, VS Code, ChatGPT, and Codex desktop is unconfirmed.
  • Is the 4.4 MiB bundle budget acceptable, or should the view drop the ext-apps App class for a hand-rolled bridge to cut size?

via @dcramer.

--

View Session [Sentry]

sentry-junior Bot and others added 5 commits November 19, 2026 04:39
Tools can now declare MCP `_meta`, which the server sends in tools/list.
A tool that points `_meta.ui.resourceUri` at a view in the new UI resource
registry gets that `ui://` resource listed and readable, with the MCP Apps
mime type. The registry is empty until the chart view lands.

Refs #741

Co-Authored-By: David Cramer <23610+dcramer@users.noreply.github.com>
render_sentry_chart fetches an events time series for a query and returns
every bucket of each series, so values never round-trip through the model
and the chart is not capped at 48 buckets like search results are. With
groupBy it asks events-timeseries for the top 5 values of one attribute
(topEvents, without the Other series) and returns one series per value.

Time series results from the dataset search tools now suggest the same
chart as a callable render_sentry_chart action.

Refs #741

Co-Authored-By: David Cramer <23610+dcramer@users.noreply.github.com>
Add the chart view as the ui://sentry/chart/v1.html resource and link the
tool to it with _meta.ui.resourceUri (plus openai/outputTemplate for
ChatGPT). The view is vanilla TypeScript with hand-drawn SVG, uses the
ext-apps App class, follows the host theme, and calls the tool again
through the host for its 1h/24h/7d/14d range picker.

esbuild bundles chart-app/ into src/ui/chart-app.generated.ts so stdio
and the Worker serve it with no file system. ci:policy fails when the
generated file is stale.

Co-Authored-By: David Cramer <23610+dcramer@users.noreply.github.com>
Add scripts/mcp-apps-host.mjs and the mcp-apps verify-toolkit map. The
script starts the mock stdio server, reads render_sentry_chart's ui://
view, mounts it through the ext-apps AppBridge in headless Chromium under
the spec's default CSP, and screenshots light, dark, the range picker
round trip, and a grouped chart. Document MCP Apps views in the tool and
response design docs and contributor guides.

Co-Authored-By: David Cramer <23610+dcramer@users.noreply.github.com>
The inlined render_sentry_chart view adds 418 KB to dist/sentry-mcp.cjs,
which now measures 4.10 MiB. Raise the budget to 4.4 MiB so it keeps
about 300 KB of headroom, as before.

Co-Authored-By: David Cramer <23610+dcramer@users.noreply.github.com>
@sentry-junior
sentry-junior Bot requested a review from a team as a code owner November 19, 2026 05:24
@sentry-junior
sentry-junior Bot requested a review from dcramer November 19, 2026 05:24
@vercel

vercel Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cli Ready Ready Preview Nov 20, 2026 9:01pm UTC
sentry-local Ready Ready Preview Nov 20, 2026 9:01pm UTC

Request Review

@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 19, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 3 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 8b60aaa. Configure here.

Comment thread packages/mcp-core/chart-app/main.ts Resolved
Comment thread packages/mcp-core/chart-app/chart.ts Resolved
Comment thread packages/mcp-core/chart-app/main.ts Resolved
…n the chart view

Keep the rendered chart and clear the pending range when the host cancels
a tool call, enable Open in Sentry for http URLs from self-hosted installs,
and draw a point for a series with a single bucket.
Comment thread pnpm-lock.yaml Resolved

@MathurAditya724 MathurAditya724 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reproduced two correctness gaps with independent tests in addition to the seven passing tool tests. Please address the inline findings and add regressions for omitted project scope and negative/mixed-sign metric buckets. The dependency security finding also still needs a resolution before this can merge.

Comment thread packages/mcp-core/chart-app/chart.ts Resolved
Comment thread packages/mcp-core/chart-app/chart.ts Resolved
Without a project parameter, Sentry only covers projects whose teams the
user belongs to, so an org admin outside those teams got an empty chart.
Send project=-1 like the UI's All Projects, as #2415 does
for search_events.
The y domain assumed a zero minimum, so negative buckets were drawn below
the viewBox. Span the actual minimum and maximum, always including 0, and
draw gridlines across that range.
sentry-junior Bot and others added 2 commits November 19, 2026 06:56
Discover reads group-by columns from field, so Open in Sentry for a
grouped errors chart showed an ungrouped query.

Co-Authored-By: David Cramer <23610+dcramer@users.noreply.github.com>
Below the 280-unit minimum viewBox width, viewBox units and CSS pixels
differ, so the tooltip drifted from the crosshair.

Co-Authored-By: David Cramer <23610+dcramer@users.noreply.github.com>
…hart view

The ext-apps App class pulled zod and the MCP client SDK into the view,
which made it 414 KB of script for 11 KB of chart code. bridge.ts speaks
the stable MCP Apps protocol over postMessage directly (ui/initialize,
initialized, tool-input, tool-result, tool-cancelled, host-context-changed,
resource-teardown, size-changed, tools/call, ui/open-link), and parse.ts
replaces zod at the structuredContent boundary. The view drops from 408 KiB
to 16 KiB of HTML.
The server needs one MIME type string and two _meta shapes from the MCP
Apps spec, so declare them in ui-resources.ts. ext-apps stays a dev
dependency for the verify-toolkit host's AppBridge.
The chart view now adds 17 KB, not 418 KB, so the bundle is back to
3,901,981 bytes (3.72 MiB).
Sessions that never render a view, such as every text-only client, no
longer evaluate the inlined HTML module. Bundlers keep it in the same file
but defer its initialization.
generate-chart-app (and ci:policy) fails when a view is over its 24 KiB
budget or loads anything from the network. A vitest check fails when a
tool names an unknown view, a view has no tool, a ui:// URI has no
version, a csp allows an origin, or the HTML changes without a new
htmlSha256 next to its URI, which is the prompt to bump the version.
mcp-core and its views implement MCP Apps directly, so the server bundle
and views stay small. The rule leaves ext-apps to the verify-toolkit host,
and a fixture test runs Oxlint to prove it fires.
The reference AppBridge now also sends a theme change, a cancelled call,
and ui/resource-teardown, so the host run checks every message the
hand-written bridge handles. Evidence regenerated: 9 of 9 checks pass,
and the screenshots are byte-identical to the ext-apps App build.
design/mcp-apps.md owns the view rules: optional, query-driven, offline,
budgeted, versioned by URI, untrusted at the boundary, listed only with a
tool, and not gated on the client capability, with the reasons and the
gaps. mcp-tools, mcp-tool-responses, and the contributing guide point at
it instead of repeating the rules.
3,902,133 bytes after the view's HTML moved behind a lazy import.
@sentry-junior

sentry-junior Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

Answering both comments. The view is tight now, and the principles and checks are in, as of 42df212.

Size. The view is 16.9 KB of HTML, down from ~408 KiB. The esbuild metafile showed where the old bytes went: zod (193 KB) plus the MCP client and core packages that ext-apps' App class pulls in (~210 KB), and only 11 KB of our own code. The view now uses a ~2.5 KB hand-written bridge (chart-app/bridge.ts) that speaks only the spec messages it uses: ui/initialize and initialized, tool-input, result and cancelled, host-context-changed, teardown, size-changed, tools/call and ui/open-link. A small boundary parser replaces zod. Its test checks that it agrees with the output schema on a valid result and on 12 malformed ones. The server declares the mime type and _meta.ui types itself. @modelcontextprotocol/ext-apps is now only a dev dependency, used by the verify script's reference AppBridge, which doubles as our conformance check for the bridge. The @sentry/mcp-server bundle is 3.72 MiB, so its budget is back at 3.75 MiB (4.4 before).

Loading. The HTML is behind a dynamic import and loads only on the first resources/read, so text-only sessions never parse it. I didn't gate the surface on the client's io.modelcontextprotocol/ui capability. Claude, VS Code, ChatGPT and the Codex app do advertise it. But the Worker builds a fresh server for each request, so tools/list can't see what the client sent in initialize, and gating there would hide the view from exactly those hosts. That's recorded as a Gap to revisit once per-request client capabilities reach the Worker.

Principles: design/mcp-apps.md.

  • Views are optional, and every tool stays complete as text.
  • Render tools take a query, so the server fetches the data and the model never relays values.
  • Views are self-contained HTML with an empty CSP.
  • Each view has a size budget.
  • ui:// URIs are versioned.
  • structuredContent is untrusted and parsed at the view boundary.
  • A view is listed only when a tool references it.

Checks. Each one has a test that fails on a bad input.

  • A 24 KiB per-view budget, enforced by generate-chart-app and ci:policy.
  • An Oxlint no-restricted-imports rule that bans ext-apps in mcp-core runtime code.
  • Tool resourceUri and registered views must match one-to-one, with no duplicate URIs.
  • The generated HTML may not load anything external (src/href, @import, remote url(), fetch, XHR, WebSocket, and so on), and a view's CSP may list no domains.
  • Each view records htmlSha256 next to its URI, so changing the HTML without updating the hash fails and prompts a version bump.

Verification. The headless host script now passes 9 of 9 checks against the reference AppBridge, including a new lifecycle check for theme change, cancel and teardown, and the screenshots match the old build byte for byte. The mcp-core suite (2509 tests) and test:bundle (26/26) pass. Real Claude, VS Code, ChatGPT and Codex rendering is still unverified and listed as a Gap.

sentry-junior Bot and others added 3 commits November 20, 2026 20:44
UiResource.budgetBytes holds the budget that generate-chart-app enforces, so the generator, the policy test, and a size report read one value instead of copying 24 KiB.

Co-Authored-By: David Cramer <23610+dcramer@users.noreply.github.com>
measure-ui builds the server with every skill, reads each listed ui:// resource through resources/read, and reports raw, gzip, and brotli bytes against the view's budget, as a table, JSON, or a markdown section. A new view shows up without a script change.

Co-Authored-By: David Cramer <23610+dcramer@users.noreply.github.com>
The Token Cost workflow now runs measure-ui, adds an MCP Apps views section to the PR comment and job summary, and uploads ui-stats.json with token-stats.json. It also runs when a view's sources change.

The PR comment now posts on every same-repo PR run instead of only when the tool token count moved, since a view can grow while the token count stays the same.

Co-Authored-By: David Cramer <23610+dcramer@users.noreply.github.com>
@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

📊 MCP Server Token Cost Report

Summary

  • Total Tokens: 65205 tokens
  • Tool Count: 74 tools
  • Average: 881 tokens/tool

Per-Tool Breakdown

Tool Tokens % of Total
get_issue_details 3938 6%
get_alert_rule 2245 3.4%
find_releases 1805 2.8%
get_issue_activity 1759 2.7%
update_alert_rule 1653 2.5%
get_replay_details 1602 2.5%
create_alert_rule 1506 2.3%
get_monitor_details 1501 2.3%
update_metric_monitor 1479 2.3%
create_metric_monitor 1458 2.2%
get_event_stacktrace 1381 2.1%
update_issue 1380 2.1%
get_snapshot 1308 2%
get_profile 1291 2%
get_agent_conversation_details 1278 2%
find_monitors 1261 1.9%
search_logs 1248 1.9%
search_traces 1246 1.9%
get_alert_options 1236 1.9%
search_profiles 1228 1.9%
search_metrics 1216 1.9%
search_errors 1214 1.9%
get_profile_details 1200 1.8%
get_uptime_monitor_details 1163 1.8%
create_monitor 1135 1.7%
onboarding_status_update 1109 1.7%
search_issue_events 1103 1.7%
search_replays 1095 1.7%
find_related_issues 1068 1.6%
get_release_details 1056 1.6%
get_dashboard_details 1052 1.6%
search_issues 977 1.5%
search_docs 973 1.5%
find_alert_rules 908 1.4%
update_uptime_monitor 873 1.3%
create_uptime_monitor 871 1.3%
search_agent_conversations 830 1.3%
find_dropped_events 819 1.3%
get_metric_monitor_details 797 1.2%
create_project 793 1.2%
update_dsn 765 1.2%
get_issue_user_reports 630 1%
get_latest_base_snapshot 623 1%
find_dashboards 553 0.8%
link_issue 545 0.8%
find_uptime_monitors 537 0.8%
get_issue_breadcrumbs 492 0.8%
unlink_issue 476 0.7%
find_metric_monitors 471 0.7%
get_issue_tag_values 469 0.7%
update_project 441 0.7%
get_sentry_resource 429 0.7%
submit_feedback_to_sentry_team 426 0.7%
add_issue_note 404 0.6%
delete_monitor_environment 363 0.6%
find_teams 351 0.5%
find_projects 346 0.5%
delete_alert_rule 345 0.5%
delete_uptime_monitor 333 0.5%
delete_metric_monitor 331 0.5%
create_dsn 326 0.5%
add_team_to_project 324 0.5%
remove_team_from_project 320 0.5%
find_dsns 319 0.5%
find_organizations 311 0.5%
get_snapshot_image 302 0.5%
analyze_issue_with_seer 300 0.5%
get_event_attachment 299 0.5%
get_trace_details 282 0.4%
create_team 266 0.4%
get_span_details 263 0.4%
whoami 261 0.4%
get_sentry_mcp_info 142 0.2%
get_doc 102 0.2%

Note: This measures the static overhead of tool definitions sent to LLM clients with every request. Lower is better.

MCP Apps views

Each ui:// view as a host receives it from resources/read.

View MIME type Raw Gzip Brotli Budget % of budget
ui://sentry/chart/v1.html text/html;profile=mcp-app 16,861 B 7,018 B 6,200 B 24,576 B 68.6%

The budget applies to raw bytes, and the view's generator fails over it.

Mark render_sentry_chart experimental and keep it out of generated skill
prompts. Stable sessions list neither the tool nor its ui:// view, and
declare no resources capability, since resources follow the registered
tools. The search_events chart suggestion already routes only to
available tools.

Co-Authored-By: David Cramer <23610+dcramer@users.noreply.github.com>
@dcramer
dcramer enabled auto-merge (squash) November 20, 2026 21:02
@dcramer
dcramer merged commit 41c5410 into main Nov 20, 2026
42 checks passed
@dcramer
dcramer deleted the feat/mcp-apps-chart branch November 20, 2026 21:15

This branch was successfully deployed

3 active deployments
Preview – sentry-local — 3b32e93e Deployed Nov 20, 2026 by vercel[bot]
Preview – cli — 3b32e93e Deployed Nov 20, 2026 by vercel[bot]
Actions — 3b32e93e Deployed Nov 20, 2026 by sentry-junior[bot] via eval #2001
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants