: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(user_interviews): expose invite preview as an MCP tool with a UI app (#61286)
Paul D'Ambra22d67cbd19fd
diff --git a/products/user_interviews/mcp/apps/InviteEmailPreviewView.tsx b/products/user_interviews/mcp/apps/InviteEmailPreviewView.tsxnew file mode 100644index 000000000000..0b7dde752cbe--- /dev/null+++ b/products/user_interviews/mcp/apps/InviteEmailPreviewView.tsx@@ -0,0 +1,50 @@+import type { ReactElement } from 'react'++import { Badge, Card, CardContent, CardHeader, CardTitle } from '@posthog/quill'++export interface InviteEmailPreviewData {+ interviewee_identifier: string+ user_name: string+ email?: string | null+ subject: string+ html: string+ interview_url: string+ emailable: boolean+ is_preview_link: boolean+ _posthogUrl?: string+}++export interface InviteEmailPreviewViewProps {+ data: InviteEmailPreviewData+}++export function InviteEmailPreviewView({ data }: InviteEmailPreviewViewProps): ReactElement {+ return (+ <Card>+ <CardHeader>+ <CardTitle>{data.subject}</CardTitle>+ <div className="flex flex-col gap-1">+ <span className="text-sm text-muted-foreground">+ To {data.user_name}+ {data.email ? ` <${data.email}>` : ''}+ </span>+ <div className="flex items-center gap-2 flex-wrap">+ {!data.emailable && <Badge variant="warning">No email address — can't be sent</Badge>}+ {data.is_preview_link && <Badge>Link is a placeholder until invites are sent</Badge>}+ </div>+ </div>+ </CardHeader>+ <CardContent>+ {/* The HTML is server-rendered and sanitized at the source; render it isolated in a+ sandboxed iframe (no scripts, no same-origin) as an extra layer of safety. */}+ <iframe+ srcDoc={data.html}+ sandbox=""+ title="Invite email preview"+ className="w-full border-0"+ style={{ height: '70vh' }}+ />+ </CardContent>+ </Card>+ )+}diff --git a/products/user_interviews/mcp/apps/index.ts b/products/user_interviews/mcp/apps/index.tsnew file mode 100644index 000000000000..e684c91f0ec2--- /dev/null+++ b/products/user_interviews/mcp/apps/index.ts@@ -0,0 +1,5 @@+export {+ InviteEmailPreviewView,+ type InviteEmailPreviewData,+ type InviteEmailPreviewViewProps,+} from './InviteEmailPreviewView'diff --git a/products/user_interviews/mcp/tools.yaml b/products/user_interviews/mcp/tools.yamlindex c44d013ff9c5..7b11702a959a 100644--- a/products/user_interviews/mcp/tools.yaml+++ b/products/user_interviews/mcp/tools.yaml@@ -7,7 +7,10 @@category: User interview topicsfeature: user_interviewsurl_prefix: /user_interviews-ui_apps: {}+ui_apps:+ invite-email-preview:+ type: detail+ view_prop: datatools:user-interview-topics-add-interviewee:operation: user_interview_topics_add_interviewee_create@@ -224,6 +227,26 @@ tools:- invite_subject- invite_messagefeature_flag: user-interviews+ user-interview-topics-preview-invite:+ operation: user_interview_topics_preview_invite_create+ enabled: true+ scopes:+ - user_interview:read+ annotations:+ readOnly: true+ destructive: false+ idempotent: true+ title: Preview the invite email for a targeted interviewee+ description: >+ Render the invitation email exactly as a specific targeted interviewee would receive it — the personalized+ subject and HTML body — without sending anything and without creating any share links. Pass+ interviewee_identifier (an email or distinct ID already on the topic) to preview for a particular person, or+ omit it to preview for the first targeted interviewee. The response includes the rendered subject and html,+ the recipient, whether they are emailable, and whether the embedded link is a placeholder.+ include_params:+ - interviewee_identifier+ ui_app: invite-email-preview+ feature_flag: user-interviewsuser-interview-topics-preview-invite-create:operation: user_interview_topics_preview_invite_createenabled: falsediff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.jsonindex 075638b7ed60..b6b80b420640 100644--- a/services/mcp/schema/generated-tool-definitions.json+++ b/services/mcp/schema/generated-tool-definitions.json@@ -5965,6 +5965,21 @@},"feature_flag": "user-interviews"},+ "user-interview-topics-preview-invite": {+ "description": "Render the invitation email exactly as a specific targeted interviewee would receive it — the personalized subject and HTML body — without sending anything and without creating any share links. Pass interviewee_identifier (an email or distinct ID already on the topic) to preview for a particular person, or omit it to preview for the first targeted interviewee. The response includes the rendered subject and html, the recipient, whether they are emailable, and whether the embedded link is a placeholder.",+ "category": "User interview topics",+ "feature": "user_interviews",+ "summary": "Preview the invite email for a targeted interviewee",+ "title": "Preview the invite email for a targeted interviewee",+ "required_scopes": ["user_interview:read"],+ "annotations": {+ "destructiveHint": false,+ "idempotentHint": true,+ "openWorldHint": true,+ "readOnlyHint": true+ },+ "feature_flag": "user-interviews"+ },"user-interview-topics-remove-interviewee": {"description": "Remove an interviewee identifier from a topic's targeting. Drops the identifier from both `interviewee_emails` and `interviewee_distinct_ids`, and disables any active SharingConfiguration tied to that interviewee on this topic so the removed person can no longer open their interview link. Idempotent — removing an identifier that isn't present is a no-op. Returns the updated topic.","category": "User interview topics",diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.jsonindex 1b8aa3a3568e..3cf442437d88 100644--- a/services/mcp/schema/tool-definitions-all.json+++ b/services/mcp/schema/tool-definitions-all.json@@ -6334,6 +6334,21 @@},"feature_flag": "user-interviews"},+ "user-interview-topics-preview-invite": {+ "description": "Render the invitation email exactly as a specific targeted interviewee would receive it — the personalized subject and HTML body — without sending anything and without creating any share links. Pass interviewee_identifier (an email or distinct ID already on the topic) to preview for a particular person, or omit it to preview for the first targeted interviewee. The response includes the rendered subject and html, the recipient, whether they are emailable, and whether the embedded link is a placeholder.",+ "category": "User interview topics",+ "feature": "user_interviews",+ "summary": "Preview the invite email for a targeted interviewee",+ "title": "Preview the invite email for a targeted interviewee",+ "required_scopes": ["user_interview:read"],+ "annotations": {+ "destructiveHint": false,+ "idempotentHint": true,+ "openWorldHint": true,+ "readOnlyHint": true+ },+ "feature_flag": "user-interviews"+ },"user-interview-topics-remove-interviewee": {"description": "Remove an interviewee identifier from a topic's targeting. Drops the identifier from both `interviewee_emails` and `interviewee_distinct_ids`, and disables any active SharingConfiguration tied to that interviewee on this topic so the removed person can no longer open their interview link. Idempotent — removing an identifier that isn't present is a no-op. Returns the updated topic.","category": "User interview topics",diff --git a/services/mcp/src/generated/user_interviews/api.ts b/services/mcp/src/generated/user_interviews/api.tsindex 4ae8646e1d86..1873ca24a5b2 100644--- a/services/mcp/src/generated/user_interviews/api.ts+++ b/services/mcp/src/generated/user_interviews/api.ts@@ -3,7 +3,7 @@* MCP service uses these Zod schemas for generated tool handlers.* To regenerate: hogli build:openapi*- * PostHog API - MCP 18 enabled ops+ * PostHog API - MCP 19 enabled ops* OpenAPI spec version: 1.0.0*/import * as zod from 'zod'@@ -191,6 +191,30 @@ export const UserInterviewTopicsLinksCsvCreateParams = /* @__PURE__ */ zod.objec),})+/**+ * Render the invite email exactly as a specific targeted interviewee would receive it — personalized subject and body — without sending anything and without creating or reading any share links. Pass `interviewee_identifier` to preview for a particular person, or omit it to preview for the first targeted interviewee. The body always shows an illustrative placeholder link (`is_preview_link: true`), never a live interview URL.+ */+export const UserInterviewTopicsPreviewInviteCreateParams = /* @__PURE__ */ zod.object({+ id: zod.string().describe('A UUID string identifying this user interview topic.'),+ project_id: zod+ .string()+ .describe(+ "Project ID of the project you're trying to access. To find the ID of the project, make a call to /api/projects/."+ ),+})++export const userInterviewTopicsPreviewInviteCreateBodyIntervieweeIdentifierMax = 400++export const UserInterviewTopicsPreviewInviteCreateBody = /* @__PURE__ */ zod.object({+ interviewee_identifier: zod+ .string()+ .max(userInterviewTopicsPreviewInviteCreateBodyIntervieweeIdentifierMax)+ .optional()+ .describe(+ 'Which targeted interviewee to render the preview for (an email or PostHog distinct ID already on the topic). Leave blank to preview for the first targeted interviewee.'+ ),+})+/*** Remove an interviewee from this topic. Drops the identifier from both `interviewee_emails` and `interviewee_distinct_ids`, and disables any active SharingConfiguration linked to an IntervieweeContext for that identifier on this topic so the removed person can no longer open their interview link. Idempotent — removing an identifier that isn't present is a no-op. Returns the updated topic.*/diff --git a/services/mcp/src/resources/ui-apps.generated.ts b/services/mcp/src/resources/ui-apps.generated.tsindex 5741c7b71050..c46a2b27a5a2 100644--- a/services/mcp/src/resources/ui-apps.generated.ts+++ b/services/mcp/src/resources/ui-apps.generated.ts@@ -15,6 +15,7 @@ export const FEATURE_FLAG_RESOURCE_URI = 'ui://posthog/feature-flag.html'export const FEATURE_FLAG_LIST_RESOURCE_URI = 'ui://posthog/feature-flag-list.html'export const FEATURE_FLAG_TESTING_RESOURCE_URI = 'ui://posthog/feature-flag-testing.html'export const INSIGHT_ACTORS_RESOURCE_URI = 'ui://posthog/insight-actors.html'+export const INVITE_EMAIL_PREVIEW_RESOURCE_URI = 'ui://posthog/invite-email-preview.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 RENDER_UI_RESOURCE_URI = 'ui://posthog/render-ui.html'@@ -46,6 +47,7 @@ export type UiAppKey =| 'feature-flag-list'| 'feature-flag-testing'| 'insight-actors'+ | 'invite-email-preview'| 'llm-costs'| 'query-results'| 'render-ui'@@ -77,6 +79,7 @@ export const URI_MAP: Record<UiAppKey, string> = {'feature-flag-list': FEATURE_FLAG_LIST_RESOURCE_URI,'feature-flag-testing': FEATURE_FLAG_TESTING_RESOURCE_URI,'insight-actors': INSIGHT_ACTORS_RESOURCE_URI,+ 'invite-email-preview': INVITE_EMAIL_PREVIEW_RESOURCE_URI,'llm-costs': LLM_COSTS_RESOURCE_URI,'query-results': QUERY_RESULTS_RESOURCE_URI,'render-ui': RENDER_UI_RESOURCE_URI,@@ -221,6 +224,12 @@ export const UI_APPS: Array<{description: 'Insight Actors detail view',appDir: 'generated/insight-actors',},+ {+ name: 'PostHog Invite Email Preview',+ uri: INVITE_EMAIL_PREVIEW_RESOURCE_URI,+ description: 'Invite Email Preview detail view',+ appDir: 'generated/invite-email-preview',+ },{name: 'PostHog Llm Costs',uri: LLM_COSTS_RESOURCE_URI,diff --git a/services/mcp/src/tools/generated/user_interviews.ts b/services/mcp/src/tools/generated/user_interviews.tsindex 0393d9c3ea84..d73fb545ed35 100644--- a/services/mcp/src/tools/generated/user_interviews.ts+++ b/services/mcp/src/tools/generated/user_interviews.ts@@ -20,6 +20,8 @@ import {UserInterviewTopicsListQueryParams,UserInterviewTopicsPartialUpdateBody,UserInterviewTopicsPartialUpdateParams,+ UserInterviewTopicsPreviewInviteCreateBody,+ UserInterviewTopicsPreviewInviteCreateParams,UserInterviewTopicsRemoveIntervieweeCreateBody,UserInterviewTopicsRemoveIntervieweeCreateParams,UserInterviewTopicsRetrieveParams,@@ -31,6 +33,7 @@ import {UserInterviewsRetrieveParams,UserInterviewsSearchCreateBody,} from '@/generated/user_interviews/api'+import { withUiApp } from '@/resources/ui-apps'import { withPostHogUrl, type WithPostHogUrl } from '@/tools/tool-utils'import type { Context, ToolBase, ZodObjectAny } from '@/tools/types'@@ -318,6 +321,32 @@ const userInterviewTopicsPartialUpdate = (): ToolBase<},})+const UserInterviewTopicsPreviewInviteSchema = UserInterviewTopicsPreviewInviteCreateParams.omit({+ project_id: true,+}).extend(UserInterviewTopicsPreviewInviteCreateBody.shape)++const userInterviewTopicsPreviewInvite = (): ToolBase<+ typeof UserInterviewTopicsPreviewInviteSchema,+ Schemas.PreviewInviteResult+> =>+ withUiApp('invite-email-preview', {+ name: 'user-interview-topics-preview-invite',+ schema: UserInterviewTopicsPreviewInviteSchema,+ handler: async (context: Context, params: z.infer<typeof UserInterviewTopicsPreviewInviteSchema>) => {+ const projectId = await context.stateManager.getProjectId()+ const body: Record<string, unknown> = {}+ if (params.interviewee_identifier !== undefined) {+ body['interviewee_identifier'] = params.interviewee_identifier+ }+ const result = await context.api.request<Schemas.PreviewInviteResult>({+ method: 'POST',+ path: `/api/projects/${encodeURIComponent(String(projectId))}/user_interview_topics/${encodeURIComponent(String(params.id))}/preview_invite/`,+ body,+ })+ return result+ },+ })+const UserInterviewTopicsRemoveIntervieweeSchema = UserInterviewTopicsRemoveIntervieweeCreateParams.omit({project_id: true,}).extend(UserInterviewTopicsRemoveIntervieweeCreateBody.shape)@@ -497,6 +526,7 @@ export const GENERATED_TOOLS: Record<string, () => ToolBase<ZodObjectAny>> = {'user-interview-topics-links-csv': userInterviewTopicsLinksCsv,'user-interview-topics-list': userInterviewTopicsList,'user-interview-topics-partial-update': userInterviewTopicsPartialUpdate,+ 'user-interview-topics-preview-invite': userInterviewTopicsPreviewInvite,'user-interview-topics-remove-interviewee': userInterviewTopicsRemoveInterviewee,'user-interview-topics-retrieve': userInterviewTopicsRetrieve,'user-interview-topics-send-invites': userInterviewTopicsSendInvites,diff --git a/services/mcp/src/ui-apps/apps/generated/invite-email-preview.tsx b/services/mcp/src/ui-apps/apps/generated/invite-email-preview.tsxnew file mode 100644index 000000000000..a3584bd8298c--- /dev/null+++ b/services/mcp/src/ui-apps/apps/generated/invite-email-preview.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 InviteEmailPreviewData, InviteEmailPreviewView } from 'products/user_interviews/mcp/apps'++import { AppWrapper } from '../../components/AppWrapper'++function InviteEmailPreviewApp(): JSX.Element {+ return (+ <AppWrapper<InviteEmailPreviewData> appName="PostHog Invite Email Preview">+ {({ data }) => <InviteEmailPreviewView data={data!} />}+ </AppWrapper>+ )+}++const container = document.getElementById('root')+if (container) {+ createRoot(container).render(<InviteEmailPreviewApp />)+}