: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(mcp-analytics): add the first-call reveal and make-it-useful steps (#128673)
Lucas Faria725a144fc4d6
diff --git a/products/mcp_analytics/frontend/earlyData/nextSteps.ts b/products/mcp_analytics/frontend/earlyData/nextSteps.tsindex e7441cacdd83..2557885c8244 100644--- a/products/mcp_analytics/frontend/earlyData/nextSteps.ts+++ b/products/mcp_analytics/frontend/earlyData/nextSteps.ts@@ -70,7 +70,7 @@ function createdReportDetail(report: SubscriptionApi): string {}// The tool health report has something to say on day one. The intent roundup needs intent capture first.-function weeklyReportStep(offer: ActionableWeeklyReportOffer): NextStep {+export function weeklyReportStep(offer: ActionableWeeklyReportOffer): NextStep {return {key: 'weekly-report',title: offer.state === 'created' ? 'Your weekly report is set up' : 'Get a weekly report in your inbox',diff --git a/products/mcp_analytics/frontend/setupMode/SetupFirstCallStep.tsx b/products/mcp_analytics/frontend/setupMode/SetupFirstCallStep.tsxnew file mode 100644index 000000000000..b610fca5dd25--- /dev/null+++ b/products/mcp_analytics/frontend/setupMode/SetupFirstCallStep.tsx@@ -0,0 +1,119 @@+import * as errorPng from '@posthog/brand/hoggies/png/error'+import * as partyPng from '@posthog/brand/hoggies/png/party'+import { IconArrowRight } from '@posthog/icons'+import { LemonBanner, LemonButton, Spinner } from '@posthog/lemon-ui'++import { pngHoggie } from 'lib/brand/hoggies'++import type { MCPActivityRecentCallApi } from '../generated/api.schemas'+import { SetupCallsPanel } from './SetupCallsPanel'+import { SetupStepHero } from './SetupStepHero'+import { SetupStepLayout } from './SetupStepLayout'+import { ToolCallHeroCard } from './ToolCallHeroCard'+import { ToolCallRevealCard } from './ToolCallRevealCard'++const HedgehogParty = pngHoggie(partyPng)+const HedgehogError = pngHoggie(errorPng)++/** The newest call as a hero card and the one before it as a smaller card. Later calls go to the panel. */+const REVEALED_CALLS = 2++const COPY = {+ loading: 'Loading your first tool call',+ failedToLoad: "Couldn't load your tool calls. This page tries again in a few seconds.",+ none: {+ title: 'No tool calls in the last 30 days',+ lead: 'Call a tool from your agent and it shows up here.',+ },+ success: {+ title: (count: number) =>+ count > 1 ? 'Your first tool calls just landed' : 'Your first tool call just landed',+ lead: 'This is what every call looks like in PostHog: which client called which tool, why, and how it went.',+ next: 'Make it useful',+ },+ failure: {+ title: (count: number, failed: number) =>+ count === 1+ ? 'Your first tool call failed'+ : failed === count+ ? 'Both of your first tool calls failed'+ : 'Two calls in, and one already needs you',+ lead: "PostHog caught the error your agent got back. Failures like this are the ones you'll want to hear about.",+ next: 'Catch these automatically',+ },+ live: 'New calls keep arriving here.',+}++interface SetupFirstCallStepProps {+ calls: MCPActivityRecentCallApi[] | null+ loadFailed: boolean+ onNext: () => void+}++function FirstCallBody({ calls, loadFailed, onNext }: SetupFirstCallStepProps): JSX.Element {+ if (calls === null) {+ return loadFailed ? (+ <LemonBanner type="error">{COPY.failedToLoad}</LemonBanner>+ ) : (+ <div className="flex items-center gap-2 text-secondary">+ <Spinner />+ <span>{COPY.loading}</span>+ </div>+ )+ }++ const revealed = calls.slice(0, REVEALED_CALLS)+ const failed = revealed.filter((call) => call.is_error).length+ const copy = failed > 0 ? COPY.failure : COPY.success+ const next = (+ <div className="flex justify-end">+ <LemonButton+ type="primary"+ sideIcon={<IconArrowRight />}+ onClick={onNext}+ data-attr="mcp-analytics-setup-mode-next"+ >+ {copy.next}+ </LemonButton>+ </div>+ )++ if (calls.length === 0) {+ return (+ <>+ <SetupStepHero Hedgehog={HedgehogParty} title={COPY.none.title} lead={COPY.none.lead} />+ {next}+ </>+ )+ }++ const [newest, previous] = revealed+ return (+ <>+ <SetupStepHero+ Hedgehog={failed > 0 ? HedgehogError : HedgehogParty}+ title={failed > 0 ? COPY.failure.title(revealed.length, failed) : COPY.success.title(revealed.length)}+ lead={copy.lead}+ />+ <ToolCallHeroCard call={newest} />+ {previous ? <ToolCallRevealCard call={previous} /> : null}+ {next}+ </>+ )+}++export function SetupFirstCallStep(props: SetupFirstCallStepProps): JSX.Element {+ return (+ <SetupStepLayout+ aside={+ <SetupCallsPanel+ calls={props.calls?.slice(REVEALED_CALLS) ?? null}+ status={{ kind: 'live', text: COPY.live }}+ empty={null}+ />+ }+ >+ <FirstCallBody {...props} />+ </SetupStepLayout>+ )+}diff --git a/products/mcp_analytics/frontend/setupMode/SetupUsefulStep.tsx b/products/mcp_analytics/frontend/setupMode/SetupUsefulStep.tsxnew file mode 100644index 000000000000..8a0ead6f5046--- /dev/null+++ b/products/mcp_analytics/frontend/setupMode/SetupUsefulStep.tsx@@ -0,0 +1,203 @@+import { useActions, useValues } from 'kea'+import type { ComponentType, ReactNode } from 'react'++import * as lifeguardPng from '@posthog/brand/hoggies/png/lifeguard'+import * as mailboxPng from '@posthog/brand/hoggies/png/mailbox'+import { IconArrowRight, IconSparkles } from '@posthog/icons'+import { LemonButton, LemonCard, Spinner } from '@posthog/lemon-ui'++import { type HoggiePngProps, pngHoggie } from 'lib/brand/hoggies'+import { urls } from 'scenes/urls'++import { mcpEarlyDataLogic } from '../earlyData/mcpEarlyDataLogic'+import { weeklyReportStep } from '../earlyData/nextSteps'+import { WeeklyReportActions } from '../earlyData/WeeklyReportActions'+import { SetupCallsPanel } from './SetupCallsPanel'+import { SetupStepHero } from './SetupStepHero'+import { SetupStepLayout } from './SetupStepLayout'++const HedgehogMailbox = pngHoggie(mailboxPng)+const HedgehogLifeguard = pngHoggie(lifeguardPng)++const COPY = {+ title: 'Hear from your server without opening PostHog',+ lead: 'Pick one or both. You can change them later in Notifications.',+ report: {+ // Shown while the report offer resolves, and when this project can't get the one-click report.+ title: 'Get a weekly report',+ detail: 'Volume, error rate and latency per tool, delivered where you choose.',+ hasReport: 'Your project already has a weekly report. Change it or add another in Notifications.',+ open: 'Open notifications',+ },+ alert: {+ title: 'Get alerted when a tool call fails',+ detail: 'Send new failures to Slack, Discord, Microsoft Teams, or a webhook.',+ detailAfterFailure: (tool: string) =>+ `A call to ${tool} failed. Send the next failure to Slack, Discord, Microsoft Teams, or a webhook.`,+ set: 'Set up an alert',+ alreadySet: 'You already get an alert when a tool call fails.',+ manage: 'Manage alerts',+ },+ expect: {+ title: 'What to expect',+ detail: 'Every tool call shows up here live from now on. Trends, tool quality and intent clusters fill in once your server has a few hundred calls.',+ },+ askAI: 'Ask PostHog AI what you can do',+ // Sent to PostHog AI as the first message. A question about the product rather than the data, because+ // a server this new has only a few calls to analyze.+ aiPrompt: 'What can MCP analytics tell me about my MCP server, and what should I look at as tool calls come in?',+ finish: 'Open MCP analytics',+}++function OptionCard({+ Hedgehog,+ title,+ detail,+ error,+ actions,+}: {+ Hedgehog: ComponentType<Pick<HoggiePngProps, 'className'>>+ title: string+ detail: string+ error?: string+ actions: ReactNode+}): JSX.Element {+ return (+ <LemonCard hoverEffect={false} className="flex flex-col gap-4 p-5">+ <Hedgehog className="h-20 w-auto self-start" />+ <div className="flex flex-1 flex-col gap-1">+ <h3 className="m-0 text-base font-semibold">{title}</h3>+ <p className="m-0 text-sm text-secondary">{detail}</p>+ {error ? (+ <p className="m-0 text-sm text-danger" role="alert">+ {error}+ </p>+ ) : null}+ </div>+ <div className="flex flex-wrap items-center gap-1">{actions}</div>+ </LemonCard>+ )+}++// Reads the offer itself rather than the activity next steps, which also wait on the overview request.+function WeeklyReportOption(): JSX.Element {+ const { weeklyReportOffer } = useValues(mcpEarlyDataLogic)+ const { nextStepClicked } = useActions(mcpEarlyDataLogic)++ if (weeklyReportOffer.state === 'loading') {+ return (+ <OptionCard+ Hedgehog={HedgehogMailbox}+ title={COPY.report.title}+ detail={COPY.report.detail}+ actions={<Spinner />}+ />+ )+ }+ if (weeklyReportOffer.state !== 'hidden') {+ const reportStep = weeklyReportStep(weeklyReportOffer)+ return (+ <OptionCard+ Hedgehog={HedgehogMailbox}+ title={reportStep.title}+ detail={reportStep.detail}+ error={reportStep.error}+ actions={<WeeklyReportActions offer={weeklyReportOffer} />}+ />+ )+ }+ const hasReport = weeklyReportOffer.reason === 'has-report'+ return (+ <OptionCard+ Hedgehog={HedgehogMailbox}+ title={COPY.report.title}+ detail={hasReport ? COPY.report.hasReport : COPY.report.detail}+ actions={+ <LemonButton+ type="secondary"+ size="small"+ to={urls.mcpAnalyticsNotifications()}+ onClick={() => nextStepClicked('weekly-report', 'more-options')}+ data-attr="mcp-analytics-activity-next-step-weekly-report-options"+ >+ {COPY.report.open}+ </LemonButton>+ }+ />+ )+}++function FailureAlertOption(): JSX.Element {+ const { overview, hasFailureNotification } = useValues(mcpEarlyDataLogic)+ const { nextStepClicked } = useActions(mcpEarlyDataLogic)+ const failedTool = overview?.recent_calls.find((call) => call.is_error)?.tool+ return (+ <OptionCard+ Hedgehog={HedgehogLifeguard}+ title={COPY.alert.title}+ detail={+ hasFailureNotification+ ? COPY.alert.alreadySet+ : failedTool+ ? COPY.alert.detailAfterFailure(failedTool)+ : COPY.alert.detail+ }+ actions={+ <LemonButton+ type="secondary"+ size="small"+ to={urls.mcpAnalyticsNotifications()}+ onClick={() => nextStepClicked('notification', 'open')}+ data-attr="mcp-analytics-activity-next-step-notification"+ >+ {hasFailureNotification ? COPY.alert.manage : COPY.alert.set}+ </LemonButton>+ }+ />+ )+}++export function SetupUsefulStep({+ onFinish,+ onAskPostHogAI,+}: {+ onFinish: () => void+ onAskPostHogAI: (prompt: string) => void+}): JSX.Element {+ const { overview } = useValues(mcpEarlyDataLogic)+ return (+ <SetupStepLayout aside={<SetupCallsPanel calls={overview?.recent_calls ?? null} />}>+ <SetupStepHero title={COPY.title} lead={COPY.lead} />+ <div className="@container">+ <div className="grid gap-4 @min-[34rem]:grid-cols-2">+ <WeeklyReportOption />+ <FailureAlertOption />+ </div>+ </div>+ <div className="flex flex-col gap-1">+ <h3 className="m-0 text-sm font-semibold">{COPY.expect.title}</h3>+ <p className="m-0 text-sm text-secondary">{COPY.expect.detail}</p>+ </div>+ <div className="flex flex-wrap items-center justify-end gap-2">+ <LemonButton+ type="secondary"+ size="large"+ sideIcon={<IconArrowRight />}+ onClick={onFinish}+ data-attr="mcp-analytics-setup-mode-finish"+ >+ {COPY.finish}+ </LemonButton>+ <LemonButton+ type="primary"+ size="large"+ icon={<IconSparkles />}+ onClick={() => onAskPostHogAI(COPY.aiPrompt)}+ data-attr="mcp-analytics-setup-mode-ask-ai"+ >+ {COPY.askAI}+ </LemonButton>+ </div>+ </SetupStepLayout>+ )+}diff --git a/products/mcp_analytics/frontend/setupMode/ToolCallHeroCard.tsx b/products/mcp_analytics/frontend/setupMode/ToolCallHeroCard.tsxnew file mode 100644index 000000000000..cea2ecb34c93--- /dev/null+++ b/products/mcp_analytics/frontend/setupMode/ToolCallHeroCard.tsx@@ -0,0 +1,91 @@+import type { ReactNode } from 'react'++import { IconCheckCircle, IconWarning } from '@posthog/icons'+import { LemonCard } from '@posthog/lemon-ui'++import { TZLabel } from 'lib/components/TZLabel'+import { cn } from 'lib/utils/css-classes'++import { BrandMark } from '../components/BrandMark'+import { harnessMark } from '../dashboard/harnessRegistry'+import type { MCPActivityRecentCallApi } from '../generated/api.schemas'+import { formatDuration } from '../sessions/utils'+import { callClientLabel } from './callClient'++const COPY = {+ called: (client: string) => `${client} called`,+ intent: 'What the agent was trying to do',+ status: 'Status',+ ok: 'OK',+ failed: 'Failed',+ latency: 'Latency',+ response: 'What came back',+}++function Stat({ label, children }: { label: string; children: ReactNode }): JSX.Element {+ return (+ <div className="flex min-w-0 flex-col gap-0.5">+ <dt className="text-xs font-semibold text-secondary">{label}</dt>+ <dd className="m-0 flex items-center gap-1.5 text-2xl font-semibold">{children}</dd>+ </div>+ )+}++/** The newest tool call, shown large: the moment the user first sees their own data. */+export function ToolCallHeroCard({ call }: { call: MCPActivityRecentCallApi }): JSX.Element {+ const client = callClientLabel(call)+ return (+ <LemonCard+ hoverEffect={false}+ className={cn('flex flex-col gap-5 p-5 @min-[36rem]/setup-mode:p-6', call.is_error && 'border-danger')}+ data-attr="mcp-analytics-setup-mode-call"+ >+ <div className="flex items-start gap-3">+ <span className="flex size-12 shrink-0 items-center justify-center rounded border border-primary bg-surface-secondary">+ <BrandMark name={harnessMark(client)} className="size-7" />+ </span>+ <div className="flex min-w-0 flex-1 flex-col">+ <span className="text-sm text-secondary">{COPY.called(client)}</span>+ <span className="truncate font-mono text-2xl font-semibold">{call.tool}</span>+ </div>+ <span className="shrink-0 text-xs text-secondary">+ <TZLabel time={call.timestamp} />+ </span>+ </div>+ {call.intent ? (+ <figure className="m-0 flex flex-col gap-1.5">+ <figcaption className="text-xs font-semibold text-secondary">{COPY.intent}</figcaption>+ <blockquote className="m-0 border-l-4 border-primary pl-4 text-xl leading-snug">+ “{call.intent}”+ </blockquote>+ </figure>+ ) : null}+ <dl className="m-0 flex flex-wrap gap-x-10 gap-y-3 border-t border-primary pt-4">+ <Stat label={COPY.status}>+ {call.is_error ? (+ <>+ <IconWarning className="text-danger" />+ <span className="text-danger">{COPY.failed}</span>+ </>+ ) : (+ <>+ <IconCheckCircle className="text-success" />+ <span className="text-success">{COPY.ok}</span>+ </>+ )}+ </Stat>+ {call.duration_ms !== null ? (+ <Stat label={COPY.latency}>{formatDuration(Math.round(call.duration_ms))}</Stat>+ ) : null}+ </dl>+ {call.is_error && call.error_message ? (+ <div className="flex flex-col gap-1.5">+ <span className="text-xs font-semibold text-secondary">{COPY.response}</span>+ <code className="block whitespace-pre-wrap break-words rounded border border-danger bg-fill-error-highlight p-3 text-sm text-danger">+ {call.error_message}+ </code>+ </div>+ ) : null}+ </LemonCard>+ )+}diff --git a/products/mcp_analytics/frontend/setupMode/ToolCallRevealCard.tsx b/products/mcp_analytics/frontend/setupMode/ToolCallRevealCard.tsxnew file mode 100644index 000000000000..9583730274f4--- /dev/null+++ b/products/mcp_analytics/frontend/setupMode/ToolCallRevealCard.tsx@@ -0,0 +1,50 @@+import { LemonCard, LemonTag } from '@posthog/lemon-ui'++import { TZLabel } from 'lib/components/TZLabel'++import { BrandMark } from '../components/BrandMark'+import { harnessMark } from '../dashboard/harnessRegistry'+import type { MCPActivityRecentCallApi } from '../generated/api.schemas'+import { formatDuration } from '../sessions/utils'+import { callClientLabel } from './callClient'++/** One tool call shown in full: who called which tool, why, and how it went. */+export function ToolCallRevealCard({ call }: { call: MCPActivityRecentCallApi }): JSX.Element {+ const client = callClientLabel(call)+ return (+ <LemonCard hoverEffect={false} className="flex flex-col gap-3 p-4" data-attr="mcp-analytics-setup-mode-call">+ <div className="flex flex-wrap items-center gap-x-2 gap-y-1">+ <span className="inline-flex min-w-0 items-center gap-1.5 font-semibold">+ <BrandMark name={harnessMark(client)} />+ <span className="truncate">{client}</span>+ </span>+ <span className="text-secondary">called</span>+ <span className="min-w-0 truncate font-mono font-semibold">{call.tool}</span>+ <LemonTag type={call.is_error ? 'danger' : 'success'}>+ {call.is_error+ ? 'Failed'+ : call.duration_ms !== null+ ? `OK in ${formatDuration(Math.round(call.duration_ms))}`+ : 'OK'}+ </LemonTag>+ <span className="ml-auto text-xs text-secondary">+ <TZLabel time={call.timestamp} />+ </span>+ </div>+ {call.intent ? (+ <div className="flex flex-col gap-0.5">+ <span className="text-xs font-semibold text-secondary">What the agent was trying to do</span>+ <span>{call.intent}</span>+ </div>+ ) : null}+ {call.is_error && call.error_message ? (+ <div className="flex flex-col gap-0.5">+ <span className="text-xs font-semibold text-secondary">What came back</span>+ <code className="block whitespace-pre-wrap break-words rounded bg-surface-secondary p-2 text-xs text-danger">+ {call.error_message}+ </code>+ </div>+ ) : null}+ </LemonCard>+ )+}