: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-analytics): allow filtering by person properties (#106501)
Georgis Andonisf2478dd79916
diff --git a/products/mcp_analytics/backend/tests/test_api.py b/products/mcp_analytics/backend/tests/test_api.pyindex e6a4664c5e5c..d656b77225c7 100644--- a/products/mcp_analytics/backend/tests/test_api.py+++ b/products/mcp_analytics/backend/tests/test_api.py@@ -2,7 +2,7 @@ import hashlibfrom datetime import UTC, datetime, timedeltafrom typing import Any-from posthog.test.base import APIBaseTest, ClickhouseTestMixin, _create_event+from posthog.test.base import APIBaseTest, ClickhouseTestMixin, _create_event, flush_persons_and_eventsfrom unittest.mock import patchfrom django.core.cache import cache@@ -10,9 +10,10 @@ from django.test import SimpleTestCasefrom parameterized import parameterized-from posthog.schema import AnyPropertyFilterDiscriminated, EventPropertyFilter, PropertyOperator+from posthog.schema import AnyPropertyFilterDiscriminated, EventPropertyFilter, PersonPropertyFilter, PropertyOperatorfrom posthog.models.utils import uuid7+from posthog.test.persons import create_personfrom posthog.utils import generate_cache_keyfrom products.mcp_analytics.backend import intent_generation, mcp_harness@@ -28,6 +29,10 @@ def _tool_name_filter(tool: str) -> list[AnyPropertyFilterDiscriminated]:return [EventPropertyFilter(key="$mcp_tool_name", value=[tool], operator=PropertyOperator.EXACT)]+def _person_email_filter(email: str) -> list[AnyPropertyFilterDiscriminated]:+ return [PersonPropertyFilter(key="email", value=[email], operator=PropertyOperator.EXACT)]++def _sorted_uuid7s(n: int) -> list[str]:"""Generate ``n`` uuid7 strings sorted lexicographically.@@ -134,6 +139,7 @@ class TestListMCPSessions(_MCPAnalyticsTeamScopedTestMixin, ClickhouseTestMixin,@parameterized.expand([("property_filter", _tool_name_filter("query_run"), False, {"kept"}),+ ("person_property_filter", _person_email_filter("[email protected]"), False, {"kept"}),("test_accounts", None, True, {"kept"}),("both_together", _tool_name_filter("query_run"), True, {"kept"}),("neither", None, False, {"kept", "dropped"}),@@ -148,9 +154,12 @@ class TestListMCPSessions(_MCPAnalyticsTeamScopedTestMixin, ClickhouseTestMixin,) -> None:self.team.test_account_filters = TEST_ACCOUNT_FILTERSself.team.save()+ create_person(team=self.team, distinct_ids=["kept_user"], properties={"email": "[email protected]"})+ create_person(team=self.team, distinct_ids=["dropped_user"], properties={"email": "[email protected]"})by_name = {"kept": str(uuid7()), "dropped": str(uuid7())}- self._seed_session(by_name["kept"], ["query_run"])- self._seed_session(by_name["dropped"], ["docs_search"], client_name=INTERNAL_CLIENT)+ self._seed_session(by_name["kept"], ["query_run"], distinct_id="kept_user")+ self._seed_session(by_name["dropped"], ["docs_search"], client_name=INTERNAL_CLIENT, distinct_id="dropped_user")+ flush_persons_and_events()def listed(props: list[AnyPropertyFilterDiscriminated] | None, test_accounts: bool) -> set[str]:page = api.list_mcp_sessions(diff --git a/products/mcp_analytics/frontend/components/McpSharedFilters.tsx b/products/mcp_analytics/frontend/components/McpSharedFilters.tsxindex 0507afd512eb..f65db7aabd13 100644--- a/products/mcp_analytics/frontend/components/McpSharedFilters.tsx+++ b/products/mcp_analytics/frontend/components/McpSharedFilters.tsx@@ -15,6 +15,7 @@ import { McpInternalUsersFilter } from './McpInternalUsersFilter'const TAXONOMIC_GROUP_TYPES = [TaxonomicFilterGroupType.MCPProperties,TaxonomicFilterGroupType.EventProperties,+ TaxonomicFilterGroupType.PersonProperties,TaxonomicFilterGroupType.EventFeatureFlags,]