: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): let a render-ui view receive the host link opener (#119217)
Sam Penningtona8a6c98edb28
diff --git a/.agents/skills/implementing-mcp-ui-apps/SKILL.md b/.agents/skills/implementing-mcp-ui-apps/SKILL.mdindex 01b7b21c8b63..f9a377dca495 100644--- a/.agents/skills/implementing-mcp-ui-apps/SKILL.md+++ b/.agents/skills/implementing-mcp-ui-apps/SKILL.md@@ -285,6 +285,7 @@ configuration also adds it to the `render-ui` umbrella tool.| `view_component` | React component name that renders the tool result. || `view_prop` | Prop name that receives the tool result. || `data_type` | TypeScript type for the tool result. Omit when the component accepts `unknown`. |+| `link_prop` | Prop name that receives the host's link opener, for a view that opens links. |**Example:**diff --git a/services/mcp/CONTRIBUTING.md b/services/mcp/CONTRIBUTING.mdindex cfe15238789e..5b8213915e4e 100644--- a/services/mcp/CONTRIBUTING.md+++ b/services/mcp/CONTRIBUTING.md@@ -342,6 +342,8 @@ For apps that need fully custom logic (like `debug.tsx` or `query-results.tsx`):view_prop: data```+ A view that opens links also names `link_prop`, the prop that receives the host's link opener.+2. **Create the entry point** manually at `src/ui-apps/apps/my-custom-app.tsx`.This file will NOT be overwritten by the generator.diff --git a/services/mcp/scripts/generate-ui-apps.ts b/services/mcp/scripts/generate-ui-apps.tsindex fddb5ee5dfd2..efccf8975d8b 100644--- a/services/mcp/scripts/generate-ui-apps.ts+++ b/services/mcp/scripts/generate-ui-apps.ts@@ -302,9 +302,11 @@ function generateDispatchModule(apps: DispatchApp[]): string {return ` '${app.appKey}': ({ data }) => <${view_component} ${view_prop}={data as ${data_type}} />,`}if (app.type === 'custom') {- const { data_type, view_component, view_prop } = app.config.render_ui+ const { data_type, view_component, view_prop, link_prop } = app.config.render_uiconst dataExpression = data_type ? `data as ${data_type}` : 'data'- return ` '${app.appKey}': ({ data }) => <${view_component} ${view_prop}={${dataExpression}} />,`+ const args = link_prop ? 'data, openLink' : 'data'+ const extraProps = link_prop ? ` ${link_prop}={openLink}` : ''+ return ` '${app.appKey}': ({ ${args} }) => <${view_component} ${view_prop}={${dataExpression}}${extraProps} />,`}const pascalName = kebabToPascal(app.appKey)return ` '${app.appKey}': ({ data, app }) => <${pascalName}Content data={data as ${app.config.list_data_type}} app={app} />,`diff --git a/services/mcp/scripts/yaml-config-schema.ts b/services/mcp/scripts/yaml-config-schema.tsindex 69a716947473..89c09c9b4487 100644--- a/services/mcp/scripts/yaml-config-schema.ts+++ b/services/mcp/scripts/yaml-config-schema.ts@@ -477,6 +477,8 @@ const CustomUiAppSchema = zview_prop: z.string(),/** TypeScript type for the tool result. Omit when the component accepts unknown. */data_type: z.string().optional(),+ /** Prop name that receives the host's link opener, for a view that opens links. */+ link_prop: z.string().optional(),}).strict().optional(),@@ -526,6 +528,7 @@ export interface ResolvedCustomUiApp {view_component: stringview_prop: stringdata_type?: string+ link_prop?: string}}diff --git a/services/mcp/tests/unit/ui-apps.test.ts b/services/mcp/tests/unit/ui-apps.test.tsindex ccd8466adb53..ada3d865531f 100644--- a/services/mcp/tests/unit/ui-apps.test.ts+++ b/services/mcp/tests/unit/ui-apps.test.ts@@ -275,6 +275,21 @@ describe('ui-apps', () => {if (!queryResultsConfig.render_ui) {throw new Error('Expected query results to configure render-ui dispatch')}+ const storyConfig = resolveCustomApp({+ type: 'custom',+ app_name: 'Chart Walkthrough',+ description: 'A walkthrough of a chart',+ render_ui: {+ component_import: '../components/InsightStory',+ view_component: 'InsightStory',+ view_prop: 'data',+ data_type: 'InsightStoryData',+ link_prop: 'openLink',+ },+ })+ if (!storyConfig.render_ui) {+ throw new Error('Expected the walkthrough to configure render-ui dispatch')+ }const code = generateDispatchModule([{@@ -291,6 +306,11 @@ describe('ui-apps', () => {type: 'custom',config: { ...queryResultsConfig, render_ui: queryResultsConfig.render_ui },},+ {+ appKey: 'insight-story',+ type: 'custom',+ config: { ...storyConfig, render_ui: storyConfig.render_ui },+ },{appKey: 'survey-list',type: 'list',@@ -305,6 +325,9 @@ describe('ui-apps', () => {expect(code).toContain("'survey': ({ data }) => <SurveyView survey={data as SurveyData} />")expect(code).toContain("import { Component } from '../components/Component'")expect(code).toContain("'query-results': ({ data }) => <Component data={data} />")+ expect(code).toContain(+ "'insight-story': ({ data, openLink }) => <InsightStory data={data as InsightStoryData} openLink={openLink} />"+ )expect(code).toContain("'survey-list': ({ data, app }) => <SurveyListContent data={data as SurveyListData} app={app} />")