Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(replay/mcp): add ui app for session summary (#57187)

Kim Svatos Dugan58dec2107725
diff --git a/products/replay/mcp/apps/SessionSummaryView.tsx b/products/replay/mcp/apps/SessionSummaryView.tsx
new file mode 100644
index 000000000000..4aa2b85afb65
--- /dev/null
+++ b/products/replay/mcp/apps/SessionSummaryView.tsx
@@ -0,0 +1,462 @@
+import { type ReactElement, useState } from 'react'
+
+import { Badge, Card, Stack } from '@posthog/mosaic'
+
+export interface SessionSummarySegment {
+ index?: number | null
+ name?: string | null
+ meta?: {
+ duration?: number | null
+ duration_percentage?: number | null
+ events_count?: number | null
+ events_percentage?: number | null
+ key_action_count?: number | null
+ failure_count?: number | null
+ abandonment_count?: number | null
+ confusion_count?: number | null
+ exception_count?: number | null
+ } | null
+}
+
+export interface SessionSummarySegmentOutcome {
+ segment_index?: number | null
+ summary?: string | null
+ success?: boolean | null
+}
+
+export interface SessionSummaryOutcome {
+ description?: string | null
+ success?: boolean | null
+}
+
+export interface SessionSummarySentiment {
+ frustration_score?: number | null
+ outcome?: string | null
+ sentiment_signals?: Array<{
+ signal_type?: string | null
+ segment_index?: number | null
+ description?: string | null
+ intensity?: number | null
+ }> | null
+}
+
+interface KeyActionEvent {
+ description?: string | null
+ abandonment?: boolean | null
+ confusion?: boolean | null
+ exception?: string | null
+ milliseconds_since_start?: number | null
+ current_url?: string | null
+}
+
+interface SessionSummaryEntry {
+ segments?: SessionSummarySegment[] | null
+ segment_outcomes?: SessionSummarySegmentOutcome[] | null
+ session_outcome?: SessionSummaryOutcome | null
+ sentiment?: SessionSummarySentiment | null
+ key_actions?: Array<{
+ segment_index?: number | null
+ events?: KeyActionEvent[] | null
+ }> | null
+}
+
+export interface SessionSummaryData {
+ [key: string]: unknown
+}
+
+function parseSummaries(data: SessionSummaryData): Record<string, SessionSummaryEntry> {
+ const summaries: Record<string, SessionSummaryEntry> = {}
+ for (const [key, value] of Object.entries(data)) {
+ if (key.startsWith('_')) {
+ continue
+ }
+ if (value && typeof value === 'object' && !Array.isArray(value)) {
+ summaries[key] = value as SessionSummaryEntry
+ }
+ }
+ return summaries
+}
+
+function formatDuration(seconds?: number | null): string {
+ if (seconds == null) {
+ return '\u2014'
+ }
+ const m = Math.floor(seconds / 60)
+ const s = Math.round(seconds % 60)
+ return `${m}m ${s}s`
+}
+
+function formatTimestamp(ms?: number | null): string {
+ if (ms == null) {
+ return ''
+ }
+ const totalSeconds = Math.floor(ms / 1000)
+ const h = Math.floor(totalSeconds / 3600)
+ const m = Math.floor((totalSeconds % 3600) / 60)
+ const s = totalSeconds % 60
+ if (h > 0) {
+ return `${String(h).padStart(2, '0')}:${String(m).padStart(2, '0')}:${String(s).padStart(2, '0')}`
+ }
+ return `${String(m).padStart(2, '0')}:${String(s).padStart(2, '0')}`
+}
+
+function formatPercentage(value?: number | null): string {
+ if (value == null) {
+ return ''
+ }
+ return `${(value * 100).toFixed(1)}%`
+}
+
+function SegmentTimelineBar({
+ offsetPercent,
+ widthPercent,
+ success,
+}: {
+ offsetPercent: number
+ widthPercent: number
+ success?: boolean | null | undefined
+}): ReactElement {
+ const barColor =
+ success === false
+ ? 'var(--color-danger, #ef4444)'
+ : success === true
+ ? 'var(--color-success, #22c55e)'
+ : 'var(--color-border-primary, #94a3b8)'
+
+ return (
+ <div className="w-full h-2 rounded-full" style={{ backgroundColor: 'var(--color-bg-tertiary, #f2f4f7)' }}>
+ <div
+ className="h-2 rounded-full"
+ style={{
+ marginLeft: `${offsetPercent}%`,
+ width: `${Math.max(widthPercent, 1)}%`,
+ backgroundColor: barColor,
+ }}
+ />
+ </div>
+ )
+}
+
+function ChevronIcon({ expanded }: { expanded: boolean }): ReactElement {
+ return (
+ <svg
+ width="16"
+ height="16"
+ viewBox="0 0 16 16"
+ fill="none"
+ style={{
+ transform: expanded ? 'rotate(90deg)' : 'rotate(0deg)',
+ transition: 'transform 0.15s ease',
+ flexShrink: 0,
+ }}
+ >
+ <path
+ d="M6 4l4 4-4 4"
+ stroke="currentColor"
+ strokeWidth="1.5"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ />
+ </svg>
+ )
+}
+
+function issueCount(segment: SessionSummarySegment): number {
+ return segment.meta?.failure_count ?? 0
+}
+
+export function SessionSummaryView({ data }: { data: SessionSummaryData }): ReactElement {
+ const summaries = parseSummaries(data)
+ const sessionIds = Object.keys(summaries)
+
+ if (sessionIds.length === 0) {
+ return <div className="p-4 text-sm text-text-secondary">No summary data available.</div>
+ }
+
+ return (
+ <div className="p-4">
+ <Stack gap="lg">
+ {sessionIds.map((sessionId) => {
+ const summary = summaries[sessionId]
+ if (!summary) {
+ return null
+ }
+ return <SingleSessionSummary key={sessionId} sessionId={sessionId} summary={summary} />
+ })}
+ </Stack>
+ </div>
+ )
+}
+
+function SingleSessionSummary({
+ sessionId,
+ summary,
+}: {
+ sessionId: string
+ summary: SessionSummaryEntry
+}): ReactElement {
+ const outcome = summary.session_outcome
+ const segments = summary.segments ?? []
+ const segmentOutcomes = summary.segment_outcomes ?? []
+ const keyActions = summary.key_actions ?? []
+
+ const outcomesByIndex = new Map(segmentOutcomes.map((o) => [o.segment_index, o]))
+ const keyActionsByIndex = new Map(keyActions.map((ka) => [ka.segment_index, ka]))
+
+ // Compute total session duration from segments for timeline bar positioning
+ const totalDurationSec = segments.reduce((sum, s) => sum + (s.meta?.duration ?? 0), 0)
+ const totalDurationMs = totalDurationSec * 1000
+
+ return (
+ <Stack gap="md">
+ <span className="text-xs font-mono text-text-secondary">{sessionId}</span>
+
+ {outcome && (
+ <div
+ className="rounded-lg p-3"
+ style={{
+ backgroundColor: outcome.success
+ ? 'var(--color-bg-success, #f0fdf4)'
+ : 'var(--color-bg-danger, #fef2f2)',
+ borderLeft: `4px solid ${outcome.success ? 'var(--color-success, #22c55e)' : 'var(--color-danger, #ef4444)'}`,
+ }}
+ >
+ <div className="flex items-start gap-2">
+ <span className="text-lg">{outcome.success ? '\u2713' : '\u26A0'}</span>
+ <div>
+ <span className="text-sm font-semibold text-text-primary">
+ {outcome.success ? 'Session successful' : 'Session abandoned'}
+ </span>
+ <div className="text-sm text-text-primary mt-1">{outcome.description ?? '\u2014'}</div>
+ </div>
+ </div>
+ </div>
+ )}
+
+ <span className="text-sm font-semibold text-text-primary">Journey</span>
+
+ {segments.map((segment, i) => {
+ const segOutcome = outcomesByIndex.get(segment.index ?? -1)
+ const segActions = keyActionsByIndex.get(segment.index ?? -1)
+ const widthPercent = (segment.meta?.duration_percentage ?? 0) * 100
+
+ // Use the first key action's absolute timestamp for bar offset.
+ // If that would overflow (offset + width > 100%), end-anchor it.
+ const firstEventMs = segActions?.events?.[0]?.milliseconds_since_start
+ let offsetPercent = 0
+ if (firstEventMs != null && totalDurationMs > 0) {
+ const eventOffset = (firstEventMs / totalDurationMs) * 100
+ offsetPercent = eventOffset + widthPercent > 100 ? 100 - widthPercent : eventOffset
+ }
+
+ return (
+ <SegmentCard
+ key={segment.index ?? `idx-${i}`}
+ segment={segment}
+ segOutcome={segOutcome}
+ segActions={segActions}
+ offsetPercent={offsetPercent}
+ widthPercent={widthPercent}
+ />
+ )
+ })}
+
+ {summary.sentiment && <SentimentSection sentiment={summary.sentiment} />}
+ </Stack>
+ )
+}
+
+function SegmentCard({
+ segment,
+ segOutcome,
+ segActions,
+ offsetPercent,
+ widthPercent,
+}: {
+ segment: SessionSummarySegment
+ segOutcome?: SessionSummarySegmentOutcome | undefined
+ segActions?: { segment_index?: number | null; events?: KeyActionEvent[] | null } | undefined
+ offsetPercent: number
+ widthPercent: number
+}): ReactElement {
+ const [expanded, setExpanded] = useState(false)
+ const issues = issueCount(segment)
+ const hasEvents = segActions?.events && segActions.events.length > 0
+
+ const borderColor =
+ segOutcome?.success === false
+ ? 'var(--color-danger, #ef4444)'
+ : segOutcome?.success === true
+ ? 'var(--color-success, #22c55e)'
+ : 'var(--color-border-primary, #e5e7eb)'
+
+ return (
+ <Card padding="none" className="overflow-hidden">
+ <div
+ onClick={hasEvents ? () => setExpanded(!expanded) : undefined}
+ style={{
+ borderLeft: `5px solid ${borderColor}`,
+ cursor: hasEvents ? 'pointer' : 'default',
+ padding: '12px',
+ paddingLeft: '15px',
+ }}
+ >
+ <Stack gap="sm">
+ <div className="flex items-center gap-2">
+ {hasEvents && (
+ <span className="text-text-secondary">
+ <ChevronIcon expanded={expanded} />
+ </span>
+ )}
+ <span className="text-sm font-semibold text-text-primary flex-1">
+ {segment.name ?? `Segment ${segment.index}`}
+ </span>
+ {issues > 0 && (
+ <Badge variant="danger" size="sm">
+ {issues} {issues === 1 ? 'issue' : 'issues'}
+ </Badge>
+ )}
+ {segOutcome?.success !== undefined && segOutcome?.success !== null && (
+ <Badge variant={segOutcome.success ? 'success' : 'danger'} size="sm">
+ {segOutcome.success ? 'success' : 'failed'}
+ </Badge>
+ )}
+ </div>
+
+ {segOutcome?.summary && <span className="text-sm text-text-secondary">{segOutcome.summary}</span>}
+
+ <div className="flex items-center gap-3">
+ <div className="flex-1">
+ <SegmentTimelineBar
+ offsetPercent={offsetPercent}
+ widthPercent={widthPercent}
+ success={segOutcome?.success}
+ />
+ </div>
+ <span className="text-xs text-text-secondary whitespace-nowrap">
+ {formatDuration(segment.meta?.duration)} &middot;{' '}
+ {formatPercentage(segment.meta?.duration_percentage)}
+ </span>
+ </div>
+ </Stack>
+ </div>
+
+ {expanded && hasEvents && (
+ <div
+ style={{
+ borderLeft: `5px solid ${borderColor}`,
+ borderTop: '1px solid var(--color-border-primary, #e5e7eb)',
+ padding: '8px 12px 12px 15px',
+ }}
+ >
+ <div className="flex flex-col gap-0">
+ {segActions.events!.map((event, i) => (
+ <div
+ key={i}
+ style={{
+ borderBottom:
+ i < segActions.events!.length - 1
+ ? '1px solid var(--color-border-primary, #e5e7eb)'
+ : 'none',
+ padding: '8px 0',
+ }}
+ >
+ <div className="flex items-start gap-3">
+ {event.milliseconds_since_start != null && (
+ <span
+ className="text-xs font-mono whitespace-nowrap"
+ style={{ color: 'var(--color-warning, #f59e0b)' }}
+ >
+ {formatTimestamp(event.milliseconds_since_start)}
+ </span>
+ )}
+ <div className="flex-1">
+ <div className="flex items-center gap-1 flex-wrap">
+ <span className="text-xs text-text-primary">{event.description}</span>
+ {event.exception && (
+ <Badge variant="danger" size="sm">
+ {event.exception}
+ </Badge>
+ )}
+ {event.abandonment && (
+ <Badge variant="warning" size="sm">
+ abandonment
+ </Badge>
+ )}
+ {event.confusion && (
+ <Badge variant="warning" size="sm">
+ confusion
+ </Badge>
+ )}
+ </div>
+ {event.current_url && (
+ <span className="text-xs text-text-secondary">{event.current_url}</span>
+ )}
+ </div>
+ </div>
+ </div>
+ ))}
+ </div>
+ </div>
+ )}
+ </Card>
+ )
+}
+
+function SentimentSection({ sentiment }: { sentiment: SessionSummarySentiment }): ReactElement {
+ const outcomeColors: Record<string, string> = {
+ successful: 'var(--color-success, #22c55e)',
+ friction: 'var(--color-warning, #f59e0b)',
+ frustrated: 'var(--color-danger, #ef4444)',
+ blocked: 'var(--color-danger, #ef4444)',
+ }
+
+ const color = outcomeColors[sentiment.outcome ?? ''] ?? 'var(--color-text-secondary)'
+
+ return (
+ <Card padding="md">
+ <Stack gap="sm">
+ <div className="flex items-center gap-3">
+ <span className="text-sm font-semibold text-text-primary">Sentiment</span>
+ {sentiment.outcome && (
+ <Badge
+ variant={
+ sentiment.outcome === 'successful'
+ ? 'success'
+ : sentiment.outcome === 'friction'
+ ? 'warning'
+ : 'danger'
+ }
+ size="sm"
+ >
+ {sentiment.outcome}
+ </Badge>
+ )}
+ </div>
+ {sentiment.frustration_score != null && (
+ <div className="flex items-center gap-2">
+ <span className="text-xs text-text-secondary">Frustration:</span>
+ <div
+ className="h-2 rounded-full"
+ style={{
+ width: '100px',
+ backgroundColor: 'var(--color-bg-tertiary, #f2f4f7)',
+ }}
+ >
+ <div
+ className="h-2 rounded-full"
+ style={{
+ width: `${Math.round(sentiment.frustration_score * 100)}%`,
+ backgroundColor: color,
+ }}
+ />
+ </div>
+ <span className="text-xs text-text-secondary">
+ {Math.round(sentiment.frustration_score * 100)}%
+ </span>
+ </div>
+ )}
+ </Stack>
+ </Card>
+ )
+}
diff --git a/products/replay/mcp/apps/index.ts b/products/replay/mcp/apps/index.ts
index 9f182e7cd754..6d16005dfa2e 100644
--- a/products/replay/mcp/apps/index.ts
+++ b/products/replay/mcp/apps/index.ts
@@ -1 +1,2 @@
export { SessionRecordingView, type SessionRecordingData } from './SessionRecordingView'
+export { SessionSummaryView, type SessionSummaryData } from './SessionSummaryView'
diff --git a/products/replay/mcp/tools.yaml b/products/replay/mcp/tools.yaml
index a8c6afa69c8b..32f68fe67225 100644
--- a/products/replay/mcp/tools.yaml
+++ b/products/replay/mcp/tools.yaml
@@ -11,6 +11,9 @@ ui_apps:
session-recording:
type: detail
view_prop: recording
+ session-summary:
+ type: detail
+ view_prop: data
tools:
session-recording-delete:
operation: session_recordings_destroy
@@ -165,6 +168,7 @@ tools:
include_params:
- session_ids
- focus_area
+ ui_app: session-summary
requires_ai_consent: true
feature_flag: replay-video-based-summarization
session-recordings-list:
diff --git a/services/mcp/src/resources/ui-apps.generated.ts b/services/mcp/src/resources/ui-apps.generated.ts
index 22015b854b7a..fd40905292ae 100644
--- a/services/mcp/src/resources/ui-apps.generated.ts
+++ b/services/mcp/src/resources/ui-apps.generated.ts
@@ -17,6 +17,7 @@ export const INSIGHT_ACTORS_RESOURCE_URI = 'ui://posthog/insight-actors.html'
export const LLM_COSTS_RESOURCE_URI = 'ui://posthog/llm-costs.html'
export const QUERY_RESULTS_RESOURCE_URI = 'ui://posthog/query-results.html'
export const SESSION_RECORDING_RESOURCE_URI = 'ui://posthog/session-recording.html'
+export const SESSION_SUMMARY_RESOURCE_URI = 'ui://posthog/session-summary.html'
export const SURVEY_RESOURCE_URI = 'ui://posthog/survey.html'
export const SURVEY_GLOBAL_STATS_RESOURCE_URI = 'ui://posthog/survey-global-stats.html'
export const SURVEY_LIST_RESOURCE_URI = 'ui://posthog/survey-list.html'
@@ -42,6 +43,7 @@ export type UiAppKey =
| 'llm-costs'
| 'query-results'
| 'session-recording'
+ | 'session-summary'
| 'survey'
| 'survey-global-stats'
| 'survey-list'
@@ -67,6 +69,7 @@ export const URI_MAP: Record<UiAppKey, string> = {
'llm-costs': LLM_COSTS_RESOURCE_URI,
'query-results': QUERY_RESULTS_RESOURCE_URI,
'session-recording': SESSION_RECORDING_RESOURCE_URI,
+ 'session-summary': SESSION_SUMMARY_RESOURCE_URI,
survey: SURVEY_RESOURCE_URI,
'survey-global-stats': SURVEY_GLOBAL_STATS_RESOURCE_URI,
'survey-list': SURVEY_LIST_RESOURCE_URI,
@@ -183,6 +186,12 @@ export const UI_APPS: Array<{
description: 'Session Recording detail view',
appDir: 'generated/session-recording',
},
+ {
+ name: 'PostHog Session Summary',
+ uri: SESSION_SUMMARY_RESOURCE_URI,
+ description: 'Session Summary detail view',
+ appDir: 'generated/session-summary',
+ },
{
name: 'PostHog Survey',
uri: SURVEY_RESOURCE_URI,
diff --git a/services/mcp/src/tools/generated/replay.ts b/services/mcp/src/tools/generated/replay.ts
index 9d0e8b11d89a..16f068bcdda3 100644
--- a/services/mcp/src/tools/generated/replay.ts
+++ b/services/mcp/src/tools/generated/replay.ts
@@ -173,26 +173,27 @@ const sessionRecordingPlaylistsList = (): ToolBase<
const SessionRecordingSummarizeSchema = CreateSessionSummariesIndividuallyBody
-const sessionRecordingSummarize = (): ToolBase<typeof SessionRecordingSummarizeSchema, Schemas.SessionSummaries> => ({
- name: 'session-recording-summarize',
- schema: SessionRecordingSummarizeSchema,
- handler: async (context: Context, params: z.infer<typeof SessionRecordingSummarizeSchema>) => {
- const projectId = await context.stateManager.getProjectId()
- const body: Record<string, unknown> = {}
- if (params.session_ids !== undefined) {
- body['session_ids'] = params.session_ids
- }
- if (params.focus_area !== undefined) {
- body['focus_area'] = params.focus_area
- }
- const result = await context.api.request<Schemas.SessionSummaries>({
- method: 'POST',
- path: `/api/environments/${encodeURIComponent(String(projectId))}/session_summaries/create_session_summaries_individually/`,
- body,
- })
- return result
- },
-})
+const sessionRecordingSummarize = (): ToolBase<typeof SessionRecordingSummarizeSchema, Schemas.SessionSummaries> =>
+ withUiApp('session-summary', {
+ name: 'session-recording-summarize',
+ schema: SessionRecordingSummarizeSchema,
+ handler: async (context: Context, params: z.infer<typeof SessionRecordingSummarizeSchema>) => {
+ const projectId = await context.stateManager.getProjectId()
+ const body: Record<string, unknown> = {}
+ if (params.session_ids !== undefined) {
+ body['session_ids'] = params.session_ids
+ }
+ if (params.focus_area !== undefined) {
+ body['focus_area'] = params.focus_area
+ }
+ const result = await context.api.request<Schemas.SessionSummaries>({
+ method: 'POST',
+ path: `/api/environments/${encodeURIComponent(String(projectId))}/session_summaries/create_session_summaries_individually/`,
+ body,
+ })
+ return result
+ },
+ })
// --- Query wrapper schemas from schema.json ---
diff --git a/services/mcp/src/ui-apps/apps/generated/session-summary.tsx b/services/mcp/src/ui-apps/apps/generated/session-summary.tsx
new file mode 100644
index 000000000000..0ac9046a1bd6
--- /dev/null
+++ b/services/mcp/src/ui-apps/apps/generated/session-summary.tsx
@@ -0,0 +1,21 @@
+// AUTO-GENERATED by generate-ui-apps.ts — do not edit
+import '../../styles/tailwind.css'
+
+import { createRoot } from 'react-dom/client'
+
+import { type SessionSummaryData, SessionSummaryView } from 'products/replay/mcp/apps'
+
+import { AppWrapper } from '../../components/AppWrapper'
+
+function SessionSummaryApp(): JSX.Element {
+ return (
+ <AppWrapper<SessionSummaryData> appName="PostHog Session Summary">
+ {({ data }) => <SessionSummaryView data={data!} />}
+ </AppWrapper>
+ )
+}
+
+const container = document.getElementById('root')
+if (container) {
+ createRoot(container).render(<SessionSummaryApp />)
+}
diff --git a/services/mcp/tests/unit/ui-apps.test.ts b/services/mcp/tests/unit/ui-apps.test.ts
index c5498ad30531..6dbfecbd2be1 100644
--- a/services/mcp/tests/unit/ui-apps.test.ts
+++ b/services/mcp/tests/unit/ui-apps.test.ts
@@ -101,7 +101,7 @@ describe('ui-apps', () => {
await registerUiAppResources(server as any, context as any)
- expect(server.registerResource).toHaveBeenCalledTimes(23)
+ expect(server.registerResource).toHaveBeenCalledTimes(24)
})
it('registers apps with correct names and URIs', async () => {