Skip to content

fix(mcp): stop the model restating results a chart already renders - #96020

Draft
GeneralistDev wants to merge 2 commits into
masterfrom
posthog/mcp-ui-resource-rendered-hint
Draft

fix(mcp): stop the model restating results a chart already renders#96020
GeneralistDev wants to merge 2 commits into
masterfrom
posthog/mcp-ui-resource-rendered-hint

Conversation

@GeneralistDev

Copy link
Copy Markdown
Member

Problem

People using an inline-exec UI-app host (PostHog Desktop, Claude Code, Cowork) see a query's chart render, then get a final reply that repeats the same numbers as a table underneath it.

The chart mounts entirely on the client. The model that writes the final reply never learns it rendered, so it answers from the same compact table it was handed and duplicates the chart in prose.

Changes

  • A tool response that carries a UI chart now ends with a short note telling the model a chart is already visible, so its reply can summarize instead of repeat the table.
  • The note only appears on the exact response that will actually render a chart (gated on the same flag the exec wrapper sets only for that case) — a client with no chart mounted sees no new text.

How did you test this code?

Added two assertions to services/mcp/tests/unit/build-tool-result.test.ts, in the existing buildToolResultPayload test blocks:

  • The note is present on the response that renders a chart (a formatted table on an inline-exec UI host) — guards a regression that silently drops the fix.
  • The note is absent when no chart renders (no includeUiResponseMeta) — guards a false "chart is shown" claim reaching a client that never mounts one.

Ran npx vitest run tests/unit/build-tool-result.test.ts (23 passed) and pnpm run fix (lint + format, clean). Not run: a full monorepo typecheck — this checkout's tsgo fails on missing @posthog/quill types in several unrelated MCP UI-app files that predate this change; confirmed none of the reported errors reference the two files this PR touches. Not run: an end-to-end check against a live MCP client.

Automatic notifications

  • Publish to changelog?

Docs update

None. Internal server-side prompt behavior with no documented setting.

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Split out from #95878, which fixed a PostHog Desktop-only bug where a chart never rendered for Codex-driven sessions. Once that chart started rendering, the reporting user noticed the model's final answer still duplicated the chart's data as text — this PR addresses that follow-on report. Opened separately because it touches services/mcp, the production MCP server every client connects to, rather than Desktop's own code.

Skills invoked: /writing-tests, /writing-pr-descriptions.

Inline-exec UI-app hosts (PostHog Desktop, Claude Code, Cowork) mount an
interactive chart from a tool result's `_meta.ui.resourceUri` entirely on the
client side. The model never learns whether that mount succeeded, so it still
writes its own final answer from the compact formatted table it was handed —
duplicating, in prose, the same data the chart already shows.

Appends a short footer to that response's text telling the model a chart is
already visible and to summarize instead of repeating the full results.
Scoped to exactly the case where a chart will actually render (gated on the
same flag the exec wrapper sets only for that branch), so it can't tell a
client with no chart that one exists.

Generated-By: PostHog Desktop
Task-Id: 7a47c916-8e28-4157-9782-3ed394d68232
@GeneralistDev GeneralistDev self-assigned this Sep 7, 2026
@trunk-io

trunk-io Bot commented Sep 7, 2026

Copy link
Copy Markdown

Merging to master in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

🤖 CI report

Trunk lane — non-backend lane (svc:mcp)

This PR is assigned to the non-backend lane (svc:mcp). It does not run backend Python tests and may merge in parallel with PRs in other lanes.

The exec wrapper now appends UI_RESOURCE_RENDERED_HINT to the text channel when a chart renders, which the three suppressStructuredContentForFormattedResults assertions didn't account for.

Generated-By: PostHog Desktop
Task-Id: 7a47c916-8e28-4157-9782-3ed394d68232
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