: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
import { useActions, useValues } from 'kea'
import { useState } from 'react'
import { IconSparkles } from '@posthog/icons'
import { LemonButton, LemonModal } from '@posthog/lemon-ui'
import { CodeSnippet } from 'lib/components/CodeSnippet/CodeSnippet'
import { Card } from '../dashboard/Card'
import { mcpEarlyDataLogic } from './mcpEarlyDataLogic'
import type { NextStep } from './nextSteps'
import { WeeklyReportActions } from './WeeklyReportActions'
// Mirrors the empty state's "Install with your agent" modal so the two setup surfaces read the same.
function AgentPromptAction({
step,
prompt,
docsUrl,
}: {
step: NextStep
prompt: string
docsUrl: string
}): JSX.Element {
const { nextStepClicked } = useActions(mcpEarlyDataLogic)
const [open, setOpen] = useState(false)
return (
<>
<LemonButton
type="secondary"
size="small"
icon={<IconSparkles />}
onClick={() => {
nextStepClicked(step.key, 'open')
setOpen(true)
}}
data-attr={`mcp-analytics-activity-next-step-${step.key}`}
>
Fix with your agent
</LemonButton>
<LemonButton
type="tertiary"
size="small"
to={docsUrl}
targetBlank
onClick={() => nextStepClicked(step.key, 'docs')}
data-attr={`mcp-analytics-activity-next-step-${step.key}-docs`}
>
Docs
</LemonButton>
<LemonModal title={step.title} isOpen={open} onClose={() => setOpen(false)} width={640}>
<p>Open the repository containing your MCP server in your coding agent, then paste this prompt.</p>
<CodeSnippet wrap compact maxLinesWithoutExpansion={5} thing="prompt">
{prompt}
</CodeSnippet>
<p className="text-secondary mt-4 mb-0">
Once the change is deployed, new tool calls show up here with the extra data.
</p>
</LemonModal>
</>
)
}
function NextStepActions({ step }: { step: NextStep }): JSX.Element {
const { nextStepClicked } = useActions(mcpEarlyDataLogic)
if (step.action.kind === 'weekly-report') {
return <WeeklyReportActions offer={step.action.offer} />
}
if (step.action.kind === 'link') {
return (
<LemonButton
type="secondary"
size="small"
to={step.action.to}
onClick={() => nextStepClicked(step.key, 'open')}
data-attr={`mcp-analytics-activity-next-step-${step.key}`}
>
{step.action.label}
</LemonButton>
)
}
return <AgentPromptAction step={step} prompt={step.action.prompt} docsUrl={step.action.docsUrl} />
}
export function ActivityNextSteps(): JSX.Element | null {
const { nextSteps } = useValues(mcpEarlyDataLogic)
if (!nextSteps?.length) {
return null
}
return (
<Card title="Next steps">
<ul
className="m-0 flex list-none flex-col divide-y divide-primary p-0"
data-attr="mcp-analytics-activity-next-steps"
>
{nextSteps.map((step) => (
<li key={step.key} className="@container py-3 first:pt-0 last:pb-0">
<div className="flex flex-col gap-2 @2xl:flex-row @2xl:items-center @2xl:justify-between @2xl:gap-6">
<div className="min-w-0">
<div className="font-medium">{step.title}</div>
<div className="text-muted text-sm">{step.detail}</div>
{step.error ? (
<div className="text-danger text-sm" role="alert">
{step.error}
</div>
) : null}
</div>
<div className="flex shrink-0 flex-wrap items-center gap-1">
<NextStepActions step={step} />
</div>
</div>
</li>
))}
</ul>
</Card>
)
}