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(marketing): align setup plan API with mcp rollout (#116130)

Javier Bahamondes5faa2c8b3a6d
diff --git a/docs/internal/marketing-source-suggestions.md b/docs/internal/marketing-source-suggestions.md
index c64c0d64daac..7ab48d9aa23d 100644
--- a/docs/internal/marketing-source-suggestions.md
+++ b/docs/internal/marketing-source-suggestions.md
@@ -14,6 +14,8 @@ These counts guide connection suggestions; they do not change report attribution
## 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 same flag also enables the read-only setup plan API independently of the Setup tab, dashboard, and source onboarding rollouts.
+Applying setup operations still requires the Setup or dashboard flag and the existing write permissions.
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.
diff --git a/products/marketing_analytics/backend/api.py b/products/marketing_analytics/backend/api.py
index d48a1572c714..9bf8b556b7ba 100644
--- a/products/marketing_analytics/backend/api.py
+++ b/products/marketing_analytics/backend/api.py
@@ -97,7 +97,7 @@ from products.warehouse_sources.backend.facade.models import DataWarehouseTable
logger = structlog.get_logger(__name__)
-def _setup_enabled(request: Request, team: Team, *, include_onboarding: bool = False) -> bool:
+def _setup_enabled(request: Request, team: Team, *, include_read_only: bool = False) -> bool:
"""Evaluate eligible marketing flags once per request.
Evaluated for the requesting person, because the flag's release conditions target
@@ -107,7 +107,7 @@ def _setup_enabled(request: Request, team: Team, *, include_onboarding: bool = F
condition matches too. Cached on the request because a second call in the same one
would fire a redundant `$feature_flag_called`.
"""
- cache_attribute = "_ma_onboarding_flag" if include_onboarding else "_ma_setup_flag"
+ cache_attribute = "_ma_read_only_setup_flag" if include_read_only else "_ma_setup_flag"
cached = getattr(request, cache_attribute, None)
if cached is not None:
return cached
@@ -128,7 +128,11 @@ def _setup_enabled(request: Request, team: Team, *, include_onboarding: bool = F
for flag in (
"marketing-analytics-setup",
"new-marketing-analytics-dashboard",
- *(("marketing-analytics-source-onboarding",) if include_onboarding else ()),
+ *(
+ ("marketing-analytics-source-onboarding", "marketing-analytics-setup-plan-mcp")
+ if include_read_only
+ else ()
+ ),
)
)
setattr(request, cache_attribute, enabled)
@@ -1636,7 +1640,7 @@ class MarketingAnalyticsViewSet(TeamAndOrgViewSetMixin, GenericViewSet):
@action(methods=["GET"], detail=False, url_path="setup_plan", required_scopes=["marketing_analytics:read"])
def setup_plan(self, request: Request, *args, **kwargs) -> Response:
# 404 rather than 403: an unreleased endpoint should look absent, not forbidden.
- if not _setup_enabled(request, self.team, include_onboarding=True):
+ if not _setup_enabled(request, self.team, include_read_only=True):
raise NotFound("Marketing analytics setup is not enabled for this project.")
date_from = request.validated_query_data["date_from"]
diff --git a/products/marketing_analytics/backend/test_api_apply_setup_ops.py b/products/marketing_analytics/backend/test_api_apply_setup_ops.py
index 17ddccd994eb..33962bc9f285 100644
--- a/products/marketing_analytics/backend/test_api_apply_setup_ops.py
+++ b/products/marketing_analytics/backend/test_api_apply_setup_ops.py
@@ -419,11 +419,17 @@ class TestApplySetupOpsFeatureFlag(APIBaseTest):
get_or_create_team_extension(self.team, TeamMarketingAnalyticsConfig)
cache.clear()
- @parameterized.expand([(False, False), (False, True), (True, False), (True, True)])
- def test_setup_availability(self, setup: bool, dashboard: bool) -> None:
+ @parameterized.expand(
+ [(False, False, False), (False, False, True), (False, True, False), (True, False, False), (True, True, True)]
+ )
+ def test_setup_availability(self, setup: bool, dashboard: bool, mcp: bool) -> None:
self.organization_membership.level = OrganizationMembership.Level.ADMIN
self.organization_membership.save()
- flags = {"marketing-analytics-setup": setup, "new-marketing-analytics-dashboard": dashboard}
+ flags = {
+ "marketing-analytics-setup": setup,
+ "new-marketing-analytics-dashboard": dashboard,
+ "marketing-analytics-setup-plan-mcp": mcp,
+ }
with patch(_FLAG_TARGET, side_effect=lambda flag, *args, **kwargs: flags[flag]):
response = self.client.post(
self.url,
diff --git a/products/marketing_analytics/backend/test_api_setup_plan.py b/products/marketing_analytics/backend/test_api_setup_plan.py
index 3b4f131e285b..e5d2d206ce8c 100644
--- a/products/marketing_analytics/backend/test_api_setup_plan.py
+++ b/products/marketing_analytics/backend/test_api_setup_plan.py
@@ -154,13 +154,21 @@ class TestSetupPlanFeatureFlag(APIBaseTest):
cache.clear()
@parameterized.expand(
- [(False, False, False), (False, False, True), (False, True, False), (True, False, False), (True, True, True)]
+ [
+ (False, False, False, False),
+ (False, False, False, True),
+ (False, False, True, False),
+ (False, True, False, False),
+ (True, False, False, False),
+ (True, True, True, True),
+ ]
)
- def test_setup_availability(self, setup: bool, dashboard: bool, onboarding: bool) -> None:
+ def test_setup_availability(self, setup: bool, dashboard: bool, onboarding: bool, mcp: bool) -> None:
flags = {
"marketing-analytics-setup": setup,
"new-marketing-analytics-dashboard": dashboard,
"marketing-analytics-source-onboarding": onboarding,
+ "marketing-analytics-setup-plan-mcp": mcp,
}
with (
patch(_FLAG_TARGET, side_effect=lambda flag, *args, **kwargs: flags[flag]),
@@ -168,8 +176,8 @@ class TestSetupPlanFeatureFlag(APIBaseTest):
):
response = self.client.get(self.url)
- assert response.status_code == (200 if setup or dashboard or onboarding else 404)
- assert build.call_count == int(setup or dashboard or onboarding)
+ assert response.status_code == (200 if setup or dashboard or onboarding or mcp else 404)
+ assert build.call_count == int(setup or dashboard or onboarding or mcp)
def test_marketing_access_does_not_enable_source_onboarding(self) -> None:
with (