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.

feat(marketing): expose setup source recommendations through mcp (#114268)

Javier Bahamondes757f4e53b01f
diff --git a/docs/internal/marketing-source-suggestions.md b/docs/internal/marketing-source-suggestions.md
index 231774f4645c..7f339486b737 100644
--- a/docs/internal/marketing-source-suggestions.md
+++ b/docs/internal/marketing-source-suggestions.md
@@ -11,6 +11,13 @@ It ranks below a source with 25 paid events, regardless of that source's total t
These counts guide connection suggestions; they do not change report attribution or connected-source sync checks.
+## MCP setup recommendations
+
+The `marketing-analytics-setup-plan-mcp` feature flag controls whether the MCP server exposes the read-only `marketing-analytics-setup-plan` tool.
+The tool returns ranked source connection recommendations with evidence and confidence, alongside other setup improvements.
+It supports `refresh=true` for an explicit rescan and does not connect accounts or apply changes.
+Incomplete or truncated scan results must be presented as such.
+
## Search performance
Spend and conversions require a synced ad platform source in the current search filters.
diff --git a/products/marketing_analytics/mcp/tools.yaml b/products/marketing_analytics/mcp/tools.yaml
index 3c92d8d7a1d2..ab730881a402 100644
--- a/products/marketing_analytics/mcp/tools.yaml
+++ b/products/marketing_analytics/mcp/tools.yaml
@@ -115,6 +115,27 @@ tools:
short-circuit with a note. Requires conversion_goal_id — call marketing-analytics-conversion-goals first and
pass the conversion_goal_id of the goal you want.
feature_flag: marketing-analytics-mcp
+ marketing-analytics-setup-plan:
+ operation: marketing_analytics_setup_plan_retrieve
+ enabled: true
+ scopes:
+ - marketing_analytics:read
+ annotations:
+ readOnly: true
+ destructive: false
+ idempotent: true
+ title: Suggest marketing sources and setup improvements
+ description: >
+ Scan the project's marketing analytics setup and return ranked recommendations. Use when the user asks which
+ data sources or ad platforms to connect, or what to fix next. Suggestions with kind connect_source identify
+ missing integrations inferred from observed traffic, with evidence, confidence, event volume, and a optional
+ deep_link to the connection flow. Present these as recommendations, not proof that the user owns an account
+ on that platform. Other suggestions cover existing integration health, UTM mappings, and conversion goals.
+ This tool only reads data; it does not connect a platform or apply changes. Direct the user to the returned
+ connection link, when provided, to complete authorization. Use refresh=true for an explicit rescan. If
+ degraded is non-empty, explain that some checks failed. If truncated is true, describe totals as
+ approximate. Requires a project with the Marketing analytics setup plan enabled.
+ feature_flag: marketing-analytics-setup-plan-mcp
marketing-analytics-suggest-conversion-goals:
operation: marketing_analytics_suggest_conversion_goals_retrieve
enabled: true
diff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.json
index 925a35d665a5..08fb2782d53b 100644
--- a/services/mcp/schema/generated-tool-definitions.json
+++ b/services/mcp/schema/generated-tool-definitions.json
@@ -9402,6 +9402,21 @@
},
"feature_flag": "marketing-analytics-mcp"
},
+ "marketing-analytics-setup-plan": {
+ "description": "Scan the project's marketing analytics setup and return ranked recommendations. Use when the user asks which data sources or ad platforms to connect, or what to fix next. Suggestions with kind connect_source identify missing integrations inferred from observed traffic, with evidence, confidence, event volume, and a optional deep_link to the connection flow. Present these as recommendations, not proof that the user owns an account on that platform. Other suggestions cover existing integration health, UTM mappings, and conversion goals. This tool only reads data; it does not connect a platform or apply changes. Direct the user to the returned connection link, when provided, to complete authorization. Use refresh=true for an explicit rescan. If degraded is non-empty, explain that some checks failed. If truncated is true, describe totals as approximate. Requires a project with the Marketing analytics setup plan enabled.",
+ "category": "Marketing analytics",
+ "feature": "marketing_analytics",
+ "summary": "Suggest marketing sources and setup improvements",
+ "title": "Suggest marketing sources and setup improvements",
+ "required_scopes": ["marketing_analytics:read"],
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": true
+ },
+ "feature_flag": "marketing-analytics-setup-plan-mcp"
+ },
"marketing-analytics-suggest-conversion-goals": {
"description": "Suggest custom events that are good candidates for becoming conversion goals. Ranks by volume, UTM tag coverage, and uniqueness of users. Excludes autocapture / system events and events that are already configured as goals.",
"category": "Marketing analytics",
diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.json
index 6bcde147b72c..62fbbda718b3 100644
--- a/services/mcp/schema/tool-definitions-all.json
+++ b/services/mcp/schema/tool-definitions-all.json
@@ -9799,6 +9799,21 @@
},
"feature_flag": "marketing-analytics-mcp"
},
+ "marketing-analytics-setup-plan": {
+ "description": "Scan the project's marketing analytics setup and return ranked recommendations. Use when the user asks which data sources or ad platforms to connect, or what to fix next. Suggestions with kind connect_source identify missing integrations inferred from observed traffic, with evidence, confidence, event volume, and a optional deep_link to the connection flow. Present these as recommendations, not proof that the user owns an account on that platform. Other suggestions cover existing integration health, UTM mappings, and conversion goals. This tool only reads data; it does not connect a platform or apply changes. Direct the user to the returned connection link, when provided, to complete authorization. Use refresh=true for an explicit rescan. If degraded is non-empty, explain that some checks failed. If truncated is true, describe totals as approximate. Requires a project with the Marketing analytics setup plan enabled.",
+ "category": "Marketing analytics",
+ "feature": "marketing_analytics",
+ "summary": "Suggest marketing sources and setup improvements",
+ "title": "Suggest marketing sources and setup improvements",
+ "required_scopes": ["marketing_analytics:read"],
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": true
+ },
+ "feature_flag": "marketing-analytics-setup-plan-mcp"
+ },
"marketing-analytics-suggest-conversion-goals": {
"description": "Suggest custom events that are good candidates for becoming conversion goals. Ranks by volume, UTM tag coverage, and uniqueness of users. Excludes autocapture / system events and events that are already configured as goals.",
"category": "Marketing analytics",
diff --git a/services/mcp/src/generated/marketing_analytics/api.ts b/services/mcp/src/generated/marketing_analytics/api.ts
index ab070b36b1f3..409aee4ad454 100644
--- a/services/mcp/src/generated/marketing_analytics/api.ts
+++ b/services/mcp/src/generated/marketing_analytics/api.ts
@@ -3,7 +3,7 @@
* MCP service uses these Zod schemas for generated tool handlers.
* To regenerate: hogli build:openapi
*
- * PostHog API - MCP 10 enabled ops
+ * PostHog API - MCP 11 enabled ops
* OpenAPI spec version: 1.0.0
*/
import * as zod from 'zod'
@@ -21506,6 +21506,36 @@ export const MarketingAnalyticsExplainConversionGoalRetrieveQueryParams = () =>
date_to: zod.string().nullish().describe('ISO end; defaults to now'),
})
+/**
+ * Rank everything wrong with a team's marketing analytics setup into concrete suggestions, each carrying the evidence behind it and — where one exists — an `apply` operation to pass straight to apply_setup_ops, plus a `readiness` block saying which capabilities (cost, ROAS, cost per customer, retention by channel) are unlocked and which suggestion is blocking each. Prefer this over `diagnose` when the question is 'what should I fix next': diagnose explains what is wrong, setup_plan says what to do about it in a form you can act on. Read-only.
+ * @summary Get the marketing analytics setup plan
+ */
+export const MarketingAnalyticsSetupPlanRetrieveParams = () => zod.object({
+ 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 marketingAnalyticsSetupPlanRetrieveQueryDateFromDefault = `-30d`
+
+export const marketingAnalyticsSetupPlanRetrieveQueryRefreshDefault = false
+
+export const MarketingAnalyticsSetupPlanRetrieveQueryParams = () => zod.object({
+ date_from: zod
+ .string()
+ .min(1)
+ .default(marketingAnalyticsSetupPlanRetrieveQueryDateFromDefault)
+ .describe(
+ "Window for campaign spend and the UTM catalogue, as a relative range (e.g. '-30d'); defaults to -30d"
+ ),
+ refresh: zod
+ .boolean()
+ .default(marketingAnalyticsSetupPlanRetrieveQueryRefreshDefault)
+ .describe('Re-run every check instead of serving a recent result. Use right after changing something.'),
+})
+
/**
* Rank existing custom events as conversion-goal candidates by volume, UTM-tag coverage, and unique users, excluding system/autocaptured events. Read-only.
* @summary Suggest conversion goals
diff --git a/services/mcp/src/tools/generated/marketing_analytics.ts b/services/mcp/src/tools/generated/marketing_analytics.ts
index 3464b7eeb9e0..f0b3e3f2ecd6 100644
--- a/services/mcp/src/tools/generated/marketing_analytics.ts
+++ b/services/mcp/src/tools/generated/marketing_analytics.ts
@@ -159,6 +159,31 @@ const marketingAnalyticsExplainConversionGoal = (): ToolBase<
},
})
+const MarketingAnalyticsSetupPlanSchema = () => {
+ const MarketingAnalyticsSetupPlanRetrieveQueryParams = orvalSchemas.MarketingAnalyticsSetupPlanRetrieveQueryParams()
+ return MarketingAnalyticsSetupPlanRetrieveQueryParams
+}
+
+const marketingAnalyticsSetupPlan = (): ToolBase<
+ ReturnType<typeof MarketingAnalyticsSetupPlanSchema>,
+ Schemas.SetupPlanResponse
+> => ({
+ name: 'marketing-analytics-setup-plan',
+ schema: MarketingAnalyticsSetupPlanSchema(),
+ handler: async (context: Context, params: z.infer<ReturnType<typeof MarketingAnalyticsSetupPlanSchema>>) => {
+ const projectId = await context.stateManager.getProjectId()
+ const result = await context.api.request<Schemas.SetupPlanResponse>({
+ method: 'GET',
+ path: `/api/projects/${encodeURIComponent(String(projectId))}/marketing_analytics/setup_plan/`,
+ query: {
+ date_from: params.date_from,
+ refresh: params.refresh,
+ },
+ })
+ return result
+ },
+})
+
const MarketingAnalyticsSuggestConversionGoalsSchema = () => {
const MarketingAnalyticsSuggestConversionGoalsRetrieveQueryParams =
orvalSchemas.MarketingAnalyticsSuggestConversionGoalsRetrieveQueryParams()
@@ -283,6 +308,7 @@ export const GENERATED_TOOLS: Record<string, () => ToolBase<ZodObjectAny>> = {
'marketing-analytics-delete-conversion-goal': marketingAnalyticsDeleteConversionGoal,
'marketing-analytics-diagnose': marketingAnalyticsDiagnose,
'marketing-analytics-explain-conversion-goal': marketingAnalyticsExplainConversionGoal,
+ 'marketing-analytics-setup-plan': marketingAnalyticsSetupPlan,
'marketing-analytics-suggest-conversion-goals': marketingAnalyticsSuggestConversionGoals,
'marketing-analytics-suggest-utm-mappings': marketingAnalyticsSuggestUtmMappings,
'marketing-analytics-update-conversion-goal': marketingAnalyticsUpdateConversionGoal,
diff --git a/services/mcp/tests/unit/tool-filtering.test.ts b/services/mcp/tests/unit/tool-filtering.test.ts
index 74202b979f14..4194696e7f80 100644
--- a/services/mcp/tests/unit/tool-filtering.test.ts
+++ b/services/mcp/tests/unit/tool-filtering.test.ts
@@ -1099,10 +1099,11 @@ describe('Tool Filtering - Feature Flags', () => {
'warehouse-multi-destination',
'autoresearch',
'today-rail-nav',
+ 'marketing-analytics-setup-plan-mcp',
])
)
expect(flags).toContain('ai-observability-offline-evaluations')
- expect(flags).toHaveLength(38)
+ expect(flags).toHaveLength(39)
})
it('every loops tool is gated on the loops flag', () => {