Skip to content

Render a chart for saved reports in chat instead of a fallback card - #480

Merged
lindesvard merged 1 commit into
mainfrom
agent/saved-report-chart-config
Sep 4, 2026
Merged

Render a chart for saved reports in chat instead of a fallback card#480
lindesvard merged 1 commit into
mainfrom
agent/saved-report-chart-config

Conversation

@lindesvard

@lindesvard lindesvard commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Ask the AI chat to run a saved report and you get the text "Report data returned but no renderable config" where the chart should be. The numbers are fetched correctly; the renderer just has nothing to draw with.

What changed

runReport now returns the saved report's config under a report key, alongside the meta and data it already returned. That is the same key runReportFromConfig returns for ad-hoc charts, which is why charts from generate_report have always rendered and saved ones have not.

The config comes from the report row runReport already loads, so there is no extra query. transformReport in the db package already maps the row onto IReport, including turning the events Json column into series, so the only field dropped is layout (the dashboard grid position, not part of a chart config). id is kept deliberately: the renderer uses !report.id to decide whether to offer a Save button, and a report that is already saved should not offer one.

The MCP get_report_data tool strips the config back off. An MCP client reads numbers out of the response and cannot draw a chart, so its output shape is unchanged and it does not pay tokens for a config it has no use for.

No change was needed in apps/api/src/agents/tools/base.ts — its get_report_data returns runReport's result directly, so the config flows through.

Evidence

  • packages/mcp/src/tools/analytics/reports.ts:287-296 (before this change) built the meta object with id, name, chartType, range, interval, startDate, endDate and dashboard_url. No report key anywhere in the function.
  • apps/api/src/agents/tools/base.ts:140-146 returns runReport(...) unmodified, so the gap reaches the frontend.
  • apps/start/src/components/chat/tool-results/chat-report-result.tsx:56-65 reads value.report and returns the "no renderable config" card when it is missing or has no chartType.
  • packages/mcp/src/tools/analytics/reports.ts:342 shows the shape that does work: report: { ...input.config, projectId }.
  • packages/db/src/services/reports.service.ts:83-116 is where the DB row becomes an IReport, report.eventsseries at line 98.
  • apps/start/src/components/report-chart/context.tsx:26 types the prop as IReportInput & { id?: string }, which the stored config satisfies.

Requested in

UserJot: "Chat conversation lost on refresh, and wants chat-generated reports insertable into a dashboard". Found while investigating that report; it is a separate bug in the same component area and ships on its own.

Deliberately left out

  • chat-report-result.tsx is untouched. The !report guard is correct defensive behaviour for genuinely malformed results, and the fix belongs in the data.
  • The Save button gating at chat-report-result.tsx:86 (value.dashboard_url &&) is a separate bug with its own root cause. Not fixed here.
  • The config carries the report's own range/startDate/endDate rather than the resolved dates the engine used, so the chart renders the same window the dashboard shows for that report. This matches how share.report.$shareId.tsx feeds a saved report to ReportChart.
  • Biome reports four pre-existing formatting and lint findings in reports.ts. They are identical before and after this change, so the file was left unformatted rather than reformatted in an unrelated diff.

Verification

pnpm typecheck passes clean in packages/mcp, apps/api and packages/db. The mcp unit tests pass (8 of 9 files); src/integration/tools.test.ts fails with 41 errors, identically on this branch and on the base commit, because it needs local Postgres and ClickHouse and there is no Docker in this environment.

Not verified by running: the end-to-end chat behaviour. A reviewer with a real project should ask the chat to run a saved report and confirm a chart renders, the "Open in dashboard" link still appears, no Save button appears, and reports using breakdowns or global filters render too.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Report execution results now include the saved report configuration in the response metadata and typed report field.
  • Bug Fixes

    • Report data responses no longer expose the saved report configuration to MCP clients.

Asking the chat to run a saved report showed "Report data returned but
no renderable config" where the chart belonged. The data was fetched
fine; the renderer just had nothing to draw with.

`runReport` returned only summary meta plus `data`, with no `report`
key. The chat renderer needs a `zReportInput`-shaped config to hand to
`ReportChart`, and bails early when it is missing. `runReportFromConfig`
already returns one, which is why ad-hoc charts render and saved ones
did not.

Attach the config `runReport` has already loaded. `transformReport` maps
the DB row onto `IReport` (the `events` column arrives as `series`), so
the only thing to drop is `layout`, the dashboard grid position. `id`
stays on so the renderer can tell a saved report from an ad-hoc one and
keep the Save button hidden.

The MCP tool strips the config again: an MCP client reads numbers and
should not pay tokens for a config it cannot draw.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: 97327ff1-71bc-41d7-b6f7-6f4f4e1ff645

📥 Commits

Reviewing files that changed from the base of the PR and between 2d4f21e and 6d1496a.

📒 Files selected for processing (1)
  • packages/mcp/src/tools/analytics/reports.ts

Included review availability: Your plan provides up to 8 included reviews per hour; 5 remain after this review.


📝 Walkthrough

Walkthrough

runReport now returns the saved report configuration without layout and includes it in meta. get_report_data removes this configuration before it validates and reshapes report data for the MCP client.

Changes

Report configuration flow

Layer / File(s) Summary
Expose saved report configuration
packages/mcp/src/tools/analytics/reports.ts
runReport now returns a typed report configuration without layout. The configuration also appears in meta.
Exclude configuration from MCP data
packages/mcp/src/tools/analytics/reports.ts
get_report_data removes report before it validates and reshapes funnel, metric, and series data.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 6d149

Saved reports now provide chart configuration to chat while MCP report-data responses retain their existing shape. No merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: rendering charts for saved reports in chat instead of showing a fallback card.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch agent/saved-report-chart-config

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@lindesvard
lindesvard merged commit a36345b into main Sep 4, 2026
13 checks passed
@lindesvard
lindesvard deleted the agent/saved-report-chart-config branch September 4, 2026 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant