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.

fix(aio): show MCP prompt for evaluation setup (#80721)

Radu Raicea2a49309c8817
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 58ffc0e42606..d831dd068908 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -1316,6 +1316,10 @@ snapshots:
hash: v1.k794b7964.e5991874972a9382c736026b9be0ba23f478f5cad7fb1a6c0b95ad697549b2b0.MlZppqkWPobycZrk6InXacMCB_Otr0Mh5rfsEaZl-6k
components-mcp-hint-toast--sql-execute--light:
hash: v1.k794b7964.0f1ab3bce13fe8842d1c1082aa3958d4f3036f45e22b446492de1ea952a1ddf2.I1aMoYXTWQHQ7HLM_sBl7E_ivm0w1OS4uyBXusN5xkQ
+ components-mcp-use-case-card--ai-observability-evaluations-create--dark:
+ hash: v1.k794b7964.4c2ec3fdb53e346b6d7b85968a96f05e8bef9cf0e4ed0d3e59774d544f420c3e.AyRsIVMIdQVCIuvWbROr4r4C7cLb1thsT0ngYxja9V4
+ components-mcp-use-case-card--ai-observability-evaluations-create--light:
+ hash: v1.k794b7964.c9f282f6b43684e6efc0b463e80d48cdaf6f86a548beb804fdc89c328e97c2ef.cafG-QYpXNUv3DfQrSVoLaOCAAhjVdHoJoQlBGT0IyQ
components-mcp-use-case-card--dashboards-create--dark:
hash: v1.k794b7964.f11cb9fd9e4bf81c9809fca5a6e01b60feb1504d84a6a49eef90ed5313f66063.Nqxa-pxylBl5wjNLEyblqWq8gIqrUty24HUzaMxa9tU
components-mcp-use-case-card--dashboards-create--light:
diff --git a/frontend/src/lib/components/MCPHint/MCPUseCaseCard.stories.tsx b/frontend/src/lib/components/MCPHint/MCPUseCaseCard.stories.tsx
index 938f22dbd60f..266ad74e41dd 100644
--- a/frontend/src/lib/components/MCPHint/MCPUseCaseCard.stories.tsx
+++ b/frontend/src/lib/components/MCPHint/MCPUseCaseCard.stories.tsx
@@ -32,3 +32,7 @@ export const SurveysCreate: Story = {
export const InsightsCreate: Story = {
args: { surfaceKey: 'insights.create', forceDisplay: true },
}
+
+export const AIObservabilityEvaluationsCreate: Story = {
+ args: { surfaceKey: 'ai_observability_evaluations.create', forceDisplay: true },
+}
diff --git a/frontend/src/lib/components/MCPHint/MCPUseCaseCard.test.tsx b/frontend/src/lib/components/MCPHint/MCPUseCaseCard.test.tsx
new file mode 100644
index 000000000000..0f9b81b620b1
--- /dev/null
+++ b/frontend/src/lib/components/MCPHint/MCPUseCaseCard.test.tsx
@@ -0,0 +1,43 @@
+import '@testing-library/jest-dom'
+
+import { cleanup, fireEvent, render, screen } from '@testing-library/react'
+
+import { copyToClipboard } from 'lib/utils/copyToClipboard'
+
+import { initKeaTests } from '~/test/init'
+
+import { mcpHintLogic } from './mcpHintLogic'
+import { MCPUseCaseCard } from './MCPUseCaseCard'
+import { getSurfacePrompts } from './prompts'
+
+jest.mock('lib/utils/copyToClipboard', () => ({
+ copyToClipboard: jest.fn().mockResolvedValue(true),
+}))
+
+describe('MCPUseCaseCard', () => {
+ beforeEach(() => {
+ initKeaTests()
+ jest.clearAllMocks()
+ mcpHintLogic.mount()
+ })
+
+ afterEach(cleanup)
+
+ it('copies a surface configured to display a prompt', () => {
+ const [prompt] = getSurfacePrompts('ai_observability_evaluations.create').examples
+
+ render(<MCPUseCaseCard surfaceKey="ai_observability_evaluations.create" forceDisplay />)
+ fireEvent.click(screen.getByLabelText('Copy to clipboard'))
+
+ expect(copyToClipboard).toHaveBeenCalledWith(prompt, 'prompt')
+ })
+
+ it('keeps a single dynamic SQL example in the list display', () => {
+ mcpHintLogic.actions.loadTopEventsSuccess(['signup_completed'])
+
+ render(<MCPUseCaseCard surfaceKey="sql.execute" forceDisplay />)
+
+ expect(screen.getByText('"How many users triggered signup_completed yesterday?"')).toBeInTheDocument()
+ expect(screen.queryByLabelText('Copy to clipboard')).not.toBeInTheDocument()
+ })
+})
diff --git a/frontend/src/lib/components/MCPHint/MCPUseCaseCard.tsx b/frontend/src/lib/components/MCPHint/MCPUseCaseCard.tsx
index 14117ba77bae..e07a07caca7b 100644
--- a/frontend/src/lib/components/MCPHint/MCPUseCaseCard.tsx
+++ b/frontend/src/lib/components/MCPHint/MCPUseCaseCard.tsx
@@ -3,6 +3,7 @@ import { useEffect, useRef, useState } from 'react'
import { IconSparkles } from '@posthog/icons'
+import { CodeSnippet } from 'lib/components/CodeSnippet/CodeSnippet'
import { cn } from 'lib/utils/css-classes'
import { AgentBadgeRotator } from './AgentBadgeRotator'
@@ -51,17 +52,17 @@ export function MCPUseCaseCard({
useEffect(() => {
// Only the SQL editor surface benefits from the team's real event names — keep the call narrow.
// Fetch at most once per mount; a failed call returns [] and must not retry on re-render.
- if (willRender && surfaceKey === 'sql.execute' && !triedLoadingEvents.current) {
+ if (willRender && surfaceKey === 'sql.execute' && topEvents.length === 0 && !triedLoadingEvents.current) {
triedLoadingEvents.current = true
loadTopEvents()
}
- }, [willRender, surfaceKey, loadTopEvents])
+ }, [willRender, surfaceKey, topEvents.length, loadTopEvents])
if (!willRender) {
return null
}
- const { examples } = getSurfacePrompts(surfaceKey, { role: userRole, topEvents })
+ const { display = 'list', examples } = getSurfacePrompts(surfaceKey, { role: userRole, topEvents })
return (
<div
@@ -77,11 +78,17 @@ export function MCPUseCaseCard({
<div className="text-sm text-default">
Ask <AgentBadgeRotator />:
</div>
- <ul className="m-0 pl-5 list-disc text-xs text-muted leading-relaxed">
- {examples.map((example) => (
- <li key={example}>{example}</li>
- ))}
- </ul>
+ {display === 'prompt' ? (
+ <CodeSnippet compact wrap thing="prompt" className="w-full">
+ {examples[0]}
+ </CodeSnippet>
+ ) : (
+ <ul className="m-0 pl-5 list-disc text-xs text-muted leading-relaxed">
+ {examples.map((example) => (
+ <li key={example}>{example}</li>
+ ))}
+ </ul>
+ )}
<div className="pt-1">
<MCPInstallCommand size="sm" />
</div>
diff --git a/frontend/src/lib/components/MCPHint/mcpHintLogic.tsx b/frontend/src/lib/components/MCPHint/mcpHintLogic.tsx
index 4e4feb0348ec..acc27fa18899 100644
--- a/frontend/src/lib/components/MCPHint/mcpHintLogic.tsx
+++ b/frontend/src/lib/components/MCPHint/mcpHintLogic.tsx
@@ -79,6 +79,7 @@ export interface mcpHintLogicActions {
dismissSurface: (surfaceKey: SurfaceKey) => {
surfaceKey:
| 'actions.create'
+ | 'ai_observability_evaluations.create'
| 'alerts.create'
| 'annotations.create'
| 'cohorts.create'
@@ -124,6 +125,7 @@ export interface mcpHintLogicActions {
derivedPrompt: string | undefined
surfaceKey:
| 'actions.create'
+ | 'ai_observability_evaluations.create'
| 'alerts.create'
| 'annotations.create'
| 'cohorts.create'
diff --git a/frontend/src/lib/components/MCPHint/prompts.ts b/frontend/src/lib/components/MCPHint/prompts.ts
index 0317f5399048..b12768e4d027 100644
--- a/frontend/src/lib/components/MCPHint/prompts.ts
+++ b/frontend/src/lib/components/MCPHint/prompts.ts
@@ -18,6 +18,7 @@ export const SURFACE_KEYS = [
'workflows.create',
'data_warehouse_sources.create',
'data_warehouse_sources.update',
+ 'ai_observability_evaluations.create',
] as const
export type SurfaceKey = (typeof SURFACE_KEYS)[number]
@@ -25,8 +26,12 @@ export type SurfaceKey = (typeof SURFACE_KEYS)[number]
export type SurfacePrompts = {
toast: string
examples: string[]
+ display?: 'list' | 'prompt'
}
+const AI_OBSERVABILITY_EVALUATION_PROMPT =
+ "Use the connected PostHog MCP server and this project's AI observability data to inspect recent traces. Identify and rank real failure modes, recommend one online evaluation per distinct failure mode, then ask which evaluations I want you to create before creating anything."
+
export const FALLBACK_PROMPTS: Record<SurfaceKey, SurfacePrompts> = {
'feature_flags.create': {
toast: '"Create a feature flag called new-checkout rolled out to 20% of users"',
@@ -164,6 +169,11 @@ export const FALLBACK_PROMPTS: Record<SurfaceKey, SurfacePrompts> = {
'"Switch my Stripe source to sync hourly"',
],
},
+ 'ai_observability_evaluations.create': {
+ toast: '"Find failure modes in my recent AI traces, then ask which evaluations to create"',
+ examples: [AI_OBSERVABILITY_EVALUATION_PROMPT],
+ display: 'prompt',
+ },
}
// Roles we tailor prompts for. Not every role is catered to; fallback to defaults for `sales`, `other`, and null.
diff --git a/products/ai_observability/frontend/evaluations/EvaluationTemplates.test.tsx b/products/ai_observability/frontend/evaluations/EvaluationTemplates.test.tsx
new file mode 100644
index 000000000000..6c4013bc092e
--- /dev/null
+++ b/products/ai_observability/frontend/evaluations/EvaluationTemplates.test.tsx
@@ -0,0 +1,33 @@
+import '@testing-library/jest-dom'
+
+import { cleanup, render, screen } from '@testing-library/react'
+
+import { FEATURE_FLAGS } from 'lib/constants'
+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
+import { preflightLogic } from 'lib/logic/preflightLogic'
+
+import { initKeaTests } from '~/test/init'
+import { PreflightStatus } from '~/types'
+
+import { EvaluationTemplatesEmptyState } from './EvaluationTemplates'
+
+describe('EvaluationTemplates', () => {
+ beforeEach(() => {
+ initKeaTests()
+ jest.clearAllMocks()
+ featureFlagLogic.mount()
+ featureFlagLogic.actions.setFeatureFlags([FEATURE_FLAGS.LLM_ANALYTICS_EVALUATIONS_START_WITH_AI], {
+ [FEATURE_FLAGS.LLM_ANALYTICS_EVALUATIONS_START_WITH_AI]: true,
+ })
+ preflightLogic.actions.loadPreflightSuccess({ cloud: true } as PreflightStatus)
+ })
+
+ afterEach(cleanup)
+
+ it('replaces Start with AI with the evaluation prompt card', () => {
+ render(<EvaluationTemplatesEmptyState />)
+
+ expect(screen.getByText(/Use the connected PostHog MCP server/)).toBeInTheDocument()
+ expect(screen.queryByText('Start with AI')).not.toBeInTheDocument()
+ })
+})
diff --git a/products/ai_observability/frontend/evaluations/EvaluationTemplates.tsx b/products/ai_observability/frontend/evaluations/EvaluationTemplates.tsx
index 39f3120d7f06..de478eb6cc3e 100644
--- a/products/ai_observability/frontend/evaluations/EvaluationTemplates.tsx
+++ b/products/ai_observability/frontend/evaluations/EvaluationTemplates.tsx
@@ -10,7 +10,6 @@ import {
IconEye,
IconPlus,
IconSearch,
- IconSparkles,
IconTarget,
IconThumbsUp,
IconWarning,
@@ -19,12 +18,11 @@ import {
import { LemonButton, LemonTag, LemonTagType, Link } from '@posthog/lemon-ui'
import { pngHoggie } from 'lib/brand/hoggies'
+import { MCPUseCaseCard } from 'lib/components/MCPHint/MCPUseCaseCard'
import { FEATURE_FLAGS } from 'lib/constants'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { SceneExport } from 'scenes/sceneTypes'
-import { useOpenAi } from '~/scenes/max/useOpenAi'
-
import { getEvaluationBackTarget, getEvaluationTemplateSelectionUrl } from './evaluationNavigation'
import { EvaluationTemplate, defaultEvaluationTemplates } from './templates'
@@ -144,28 +142,6 @@ function TemplateRow({ template }: TemplateRowProps): JSX.Element {
)
}
-function StartWithAiRow(): JSX.Element {
- const { openAi } = useOpenAi()
-
- const handleClick = (): void => {
- posthog.capture('llm evaluation template selected', { template_key: 'start_with_ai' })
- openAi(
- 'Create an online evaluation for me. First explore my recent AI traces to find failure modes worth evaluating, then set one up to catch the most important one.'
- )
- }
-
- return (
- <PickerRow
- dataAttr="start-with-ai-evaluation-template"
- description="Let PostHog AI explore your traces and build an evaluation for you"
- icon={<IconSparkles className="w-5 h-5 text-primary-3000" />}
- onClick={handleClick}
- tag={{ label: 'Beta', type: 'completion' }}
- title="Start with AI"
- />
- )
-}
-
interface TemplatePickerProps {
title: string
description: string
@@ -219,8 +195,11 @@ function TemplatePicker({
</p>
</div>
+ {showStartWithAi && (
+ <MCPUseCaseCard surfaceKey="ai_observability_evaluations.create" className="!mt-0" />
+ )}
+
<div className="flex flex-col border border-border rounded-lg divide-y divide-border overflow-hidden bg-bg-light">
- {showStartWithAi && <StartWithAiRow />}
<TemplateRow template="blank" />
{defaultEvaluationTemplates.map((template) => (
<TemplateRow key={template.key} template={template} />