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(insights): expose trending endpoint via MCP (#57568)

Andrew Maguire94be97bb1555
diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.ts
index bc0cfbd11c2c..86b4d79ec68b 100644
--- a/frontend/src/lib/api.ts
+++ b/frontend/src/lib/api.ts
@@ -2229,11 +2229,13 @@ const api = {
return await new ApiRequest().insights().withAction('generate_metadata').create({ data: { query } })
},
async trending(params?: { days?: number; limit?: number }): Promise<InsightModel[]> {
- return await new ApiRequest()
+ const response = await new ApiRequest()
.insights()
.withAction('trending')
.withQueryString(toParams(params || {}))
.get()
+ // Endpoint returns the standard {count, next, previous, results} envelope.
+ return response.results ?? response
},
},
diff --git a/posthog/api/insight.py b/posthog/api/insight.py
index 4d575b71cb64..0b3ba16ddc5c 100644
--- a/posthog/api/insight.py
+++ b/posthog/api/insight.py
@@ -98,7 +98,7 @@ from posthog.models.activity_logging.activity_log import (
load_activity,
log_activity,
)
-from posthog.models.activity_logging.activity_page import activity_page_response
+from posthog.models.activity_logging.activity_page import ActivityLogPaginatedResponseSerializer, activity_page_response
from posthog.models.alert import AlertConfiguration
from posthog.models.filters.utils import get_filter
from posthog.models.insight import InsightViewed
@@ -387,6 +387,32 @@ class InsightBasicSerializer(
return [tile.dashboard_id for tile in instance.dashboard_tiles.all()]
+class TrendingInsightSerializer(InsightBasicSerializer):
+ """Insight enriched with view-count and recent-viewer fields, used by the trending action."""
+
+ view_count = serializers.IntegerField(
+ read_only=True,
+ help_text=(
+ "Number of distinct viewers in the time window. Higher values indicate insights that more people "
+ "in the project actively look at, which is a strong proxy for which insights matter."
+ ),
+ )
+ viewers = UserBasicSerializer(
+ many=True,
+ read_only=True,
+ help_text="Up to 3 of the most recent users who viewed this insight in the time window.",
+ )
+ # Surfaced here (not on InsightBasicSerializer) so agents ranking trending insights can see
+ # who is currently iterating on each — useful context alongside the view-count signal.
+ last_modified_by = UserBasicSerializer(
+ read_only=True,
+ help_text="User who last modified this insight, or null if never modified after creation.",
+ )
+
+ class Meta(InsightBasicSerializer.Meta):
+ fields = [*InsightBasicSerializer.Meta.fields, "view_count", "viewers", "last_modified_by"]
+
+
class _InsightQuerySchema(RootModel):
"""The query definition for this insight. The `kind` field determines the query type:
- `InsightVizNode` — product analytics (trends, funnels, retention, paths, stickiness, lifecycle)
@@ -1472,14 +1498,39 @@ class InsightViewSet(
response = InsightBasicSerializer(recently_viewed, many=True)
return Response(data=response.data, status=status.HTTP_200_OK)
- @action(methods=["GET"], detail=False)
+ @extend_schema(
+ operation_id="insights_trending_retrieve",
+ filters=False,
+ parameters=[
+ OpenApiParameter(
+ name="days",
+ type=OpenApiTypes.INT,
+ location=OpenApiParameter.QUERY,
+ description=(
+ "Time window in days to compute view counts over. Defaults to 7. Larger windows surface "
+ "consistently popular insights; smaller windows surface what's hot right now."
+ ),
+ required=False,
+ ),
+ OpenApiParameter(
+ name="limit",
+ type=OpenApiTypes.INT,
+ location=OpenApiParameter.QUERY,
+ description="Maximum number of insights to return. Defaults to 10. Capped at 100.",
+ required=False,
+ ),
+ ],
+ responses={200: TrendingInsightSerializer(many=True)},
+ description=(
+ "Returns insights ranked by view count over the last N days (default 7), highest first. Each "
+ "result includes the same metadata as the standard insights list, plus a `view_count` and up to "
+ "3 recent `viewers`. Useful for surfacing the most-used insights in a project."
+ ),
+ )
+ @action(methods=["GET"], detail=False, required_scopes=["insight:read"])
def trending(self, request: request.Request, *args, **kwargs) -> Response:
- """
- Returns trending insights based on view count in the last N days (default 7).
- Defaults to returning top 10 insights.
- """
try:
- days = int(request.GET.get("days", "1"))
+ days = int(request.GET.get("days", "7"))
limit = min(int(request.GET.get("limit", "10")), 100)
except (ValueError, TypeError):
raise ValidationError("days and limit must be valid integers")
@@ -1488,6 +1539,7 @@ class InsightViewSet(
queryset = (
Insight.objects.filter(team__project_id=self.team.project_id)
+ .select_related("created_by", "last_modified_by", "team")
.annotate(
view_count=Count(
"insightviewed",
@@ -1501,16 +1553,13 @@ class InsightViewSet(
queryset = self._filter_queryset_by_access_level(queryset)
queryset = queryset[:limit]
queryset = queryset.annotate(last_viewed_at=Max("insightviewed__last_viewed_at"))
+ insights = list(queryset)
- response = InsightBasicSerializer(queryset, many=True)
- data = response.data
-
- # Batch fetch all viewers to avoid N+1 queries
- insight_ids = [item["id"] for item in data]
+ # Batch fetch viewers once to avoid N+1 queries
all_viewers = (
InsightViewed.objects.filter(
team=self.team,
- insight_id__in=insight_ids,
+ insight_id__in=[insight.pk for insight in insights],
last_viewed_at__gte=cutoff_date,
user__isnull=False,
)
@@ -1521,18 +1570,19 @@ class InsightViewSet(
viewers_by_insight: dict[int, list] = {}
for viewer in all_viewers:
iid = viewer.insight_id
- if iid not in viewers_by_insight:
- viewers_by_insight[iid] = []
- if len(viewers_by_insight[iid]) < 3:
- viewers_by_insight[iid].append(viewer.user)
+ bucket = viewers_by_insight.setdefault(iid, [])
+ if len(bucket) < 3:
+ bucket.append(viewer.user)
- instance_map = {instance.pk: instance for instance in queryset}
- for item in data:
- item["viewers"] = UserBasicSerializer(viewers_by_insight.get(item["id"], []), many=True).data
- instance = instance_map.get(item["id"])
- item["view_count"] = getattr(instance, "view_count", 0) if instance else 0
+ for insight in insights:
+ insight.viewers = viewers_by_insight.get(insight.pk, [])
- return Response(data=data, status=status.HTTP_200_OK)
+ data = TrendingInsightSerializer(insights, many=True, context=self.get_serializer_context()).data
+ # Wrap in the standard paginated envelope so the response shape matches the auto-generated
+ # OpenAPI schema (drf-spectacular wraps `many=True` responses as `Paginated*List` when the
+ # viewset has a paginator). This keeps the MCP-generated client and any other typed consumer
+ # happy. There's no real pagination — `limit` already caps the result set.
+ return Response({"count": len(data), "next": None, "previous": None, "results": data})
@staticmethod
@tracer.start_as_current_span("InsightViewSet._apply_search")
@@ -2050,7 +2100,31 @@ When set, the specified dashboard's filters and date range override will be appl
return Response(status=status.HTTP_201_CREATED)
- @extend_schema(operation_id="insights_all_activity_retrieve")
+ @extend_schema(
+ operation_id="insights_all_activity_retrieve",
+ parameters=[
+ OpenApiParameter(
+ name="limit",
+ type=OpenApiTypes.INT,
+ location=OpenApiParameter.QUERY,
+ description="Page size. Defaults to 10.",
+ required=False,
+ ),
+ OpenApiParameter(
+ name="page",
+ type=OpenApiTypes.INT,
+ location=OpenApiParameter.QUERY,
+ description="1-indexed page number. Defaults to 1.",
+ required=False,
+ ),
+ ],
+ responses={200: ActivityLogPaginatedResponseSerializer},
+ description=(
+ "Project-wide audit trail across all insights — who created, edited, deleted, or restored insights, "
+ "what changed (with before/after diffs), and when. Useful for surfacing what people (or agents) have "
+ "been working on recently."
+ ),
+ )
@action(methods=["GET"], url_path="activity", detail=False, required_scopes=["activity_log:read"])
def all_activity(self, request: request.Request, **kwargs):
limit = int(request.query_params.get("limit", "10"))
@@ -2059,6 +2133,29 @@ When set, the specified dashboard's filters and date range override will be appl
activity_page = load_activity(scope="Insight", team_id=self.team_id, limit=limit, page=page)
return activity_page_response(activity_page, limit, page, request)
+ @extend_schema(
+ parameters=[
+ OpenApiParameter(
+ name="limit",
+ type=OpenApiTypes.INT,
+ location=OpenApiParameter.QUERY,
+ description="Page size. Defaults to 10.",
+ required=False,
+ ),
+ OpenApiParameter(
+ name="page",
+ type=OpenApiTypes.INT,
+ location=OpenApiParameter.QUERY,
+ description="1-indexed page number. Defaults to 1.",
+ required=False,
+ ),
+ ],
+ responses={200: ActivityLogPaginatedResponseSerializer},
+ description=(
+ "Audit trail for a single insight — every change made to it, by whom, and when. Use this when you "
+ "want the change history of a specific insight; use the project-wide activity endpoint for a broader view."
+ ),
+ )
@action(methods=["GET"], detail=True, required_scopes=["activity_log:read"])
def activity(self, request: request.Request, **kwargs):
limit = int(request.query_params.get("limit", "10"))
diff --git a/posthog/api/test/test_insight.py b/posthog/api/test/test_insight.py
index 55830507502c..0605e903869a 100644
--- a/posthog/api/test/test_insight.py
+++ b/posthog/api/test/test_insight.py
@@ -2997,6 +2997,94 @@ class TestInsight(ClickhouseTestMixin, APIBaseTest, QueryMatchingTest):
self.assertEqual(response.status_code, status.HTTP_200_OK)
assert [r["id"] for r in response_data] == [insight_1_id, insight_2_id]
+ def test_trending_insights_orders_by_view_count_then_recency(self) -> None:
+ # Bypass the API for the unviewed insight — `dashboard_api.create_insight` auto-creates
+ # an InsightViewed row, which would defeat the "no views = excluded" assertion below.
+ unviewed = Insight.objects.create(team=self.team, short_id="trnd0001", filters={"events": [{"id": "$pv"}]})
+ one_view_id, _ = self.dashboard_api.create_insight({"short_id": "trnd0002"})
+ two_views_id, _ = self.dashboard_api.create_insight({"short_id": "trnd0003"})
+
+ other_user = User.objects.create_and_join(self.organization, "[email protected]", None)
+ viewed_at = timezone.now()
+ InsightViewed.objects.update_or_create(
+ team=self.team, user=self.user, insight_id=one_view_id, defaults={"last_viewed_at": viewed_at}
+ )
+ InsightViewed.objects.update_or_create(
+ team=self.team, user=self.user, insight_id=two_views_id, defaults={"last_viewed_at": viewed_at}
+ )
+ InsightViewed.objects.update_or_create(
+ team=self.team, user=other_user, insight_id=two_views_id, defaults={"last_viewed_at": viewed_at}
+ )
+
+ response = self.client.get(f"/api/projects/{self.team.id}/insights/trending")
+ self.assertEqual(response.status_code, status.HTTP_200_OK)
+ body = response.json()
+ results = body["results"]
+ assert body["count"] == len(results)
+
+ ids = [r["id"] for r in results]
+ assert two_views_id in ids and one_view_id in ids
+ assert unviewed.pk not in ids
+ assert ids.index(two_views_id) < ids.index(one_view_id)
+
+ two_views_row = next(r for r in results if r["id"] == two_views_id)
+ assert two_views_row["view_count"] == 2
+ assert len(two_views_row["viewers"]) == 2
+
+ def test_trending_insights_respects_days_window(self) -> None:
+ recent_id, _ = self.dashboard_api.create_insight({"short_id": "trndR001"})
+ old_id, _ = self.dashboard_api.create_insight({"short_id": "trndO001"})
+
+ InsightViewed.objects.update_or_create(
+ team=self.team, user=self.user, insight_id=recent_id, defaults={"last_viewed_at": timezone.now()}
+ )
+ InsightViewed.objects.update_or_create(
+ team=self.team,
+ user=self.user,
+ insight_id=old_id,
+ defaults={"last_viewed_at": timezone.now() - timedelta(days=14)},
+ )
+
+ response = self.client.get(f"/api/projects/{self.team.id}/insights/trending?days=7")
+ ids = [r["id"] for r in response.json()["results"]]
+ assert ids == [recent_id]
+
+ response = self.client.get(f"/api/projects/{self.team.id}/insights/trending?days=30")
+ ids = [r["id"] for r in response.json()["results"]]
+ assert set(ids) == {recent_id, old_id}
+
+ def test_trending_insights_excludes_deleted(self) -> None:
+ kept_id, _ = self.dashboard_api.create_insight({"short_id": "trndK001"})
+ deleted_id, _ = self.dashboard_api.create_insight({"short_id": "trndD001"})
+
+ InsightViewed.objects.update_or_create(
+ team=self.team, user=self.user, insight_id=kept_id, defaults={"last_viewed_at": timezone.now()}
+ )
+ InsightViewed.objects.update_or_create(
+ team=self.team, user=self.user, insight_id=deleted_id, defaults={"last_viewed_at": timezone.now()}
+ )
+ self.dashboard_api.soft_delete(deleted_id, "insights")
+
+ response = self.client.get(f"/api/projects/{self.team.id}/insights/trending")
+ ids = [r["id"] for r in response.json()["results"]]
+ assert ids == [kept_id]
+
+ def test_trending_insights_respects_limit(self) -> None:
+ for short_id in ("trndL001", "trndL002", "trndL003"):
+ insight_id, _ = self.dashboard_api.create_insight({"short_id": short_id})
+ InsightViewed.objects.update_or_create(
+ team=self.team, user=self.user, insight_id=insight_id, defaults={"last_viewed_at": timezone.now()}
+ )
+
+ response = self.client.get(f"/api/projects/{self.team.id}/insights/trending?limit=2")
+ body = response.json()
+ assert len(body["results"]) == 2
+ assert body["count"] == 2
+
+ def test_trending_insights_rejects_invalid_params(self) -> None:
+ response = self.client.get(f"/api/projects/{self.team.id}/insights/trending?days=abc")
+ assert response.status_code == status.HTTP_400_BAD_REQUEST
+
def test_get_recent_insights_with_feature_flag(self) -> None:
filter_dict = {
"events": [{"id": "$pageview"}],
diff --git a/products/product_analytics/frontend/generated/api.schemas.ts b/products/product_analytics/frontend/generated/api.schemas.ts
index 3802129e1d70..eb81b1e51635 100644
--- a/products/product_analytics/frontend/generated/api.schemas.ts
+++ b/products/product_analytics/frontend/generated/api.schemas.ts
@@ -9768,6 +9768,64 @@ export interface PatchedInsightApi {
readonly last_viewed_at?: string | null
}
+export interface ChangeApi {
+ readonly type: string
+ readonly action: string
+ readonly field: string
+ readonly before: unknown
+ readonly after: unknown
+}
+
+export interface MergeApi {
+ readonly type: string
+ readonly source: unknown
+ readonly target: unknown
+}
+
+export interface TriggerApi {
+ readonly job_type: string
+ readonly job_id: string
+ readonly payload: unknown
+}
+
+export interface DetailApi {
+ readonly id: string
+ changes?: ChangeApi[]
+ merge?: MergeApi
+ trigger?: TriggerApi
+ readonly name: string
+ readonly short_id: string
+ readonly type: string
+}
+
+/**
+ * @nullable
+ */
+export type ActivityLogEntryApiUser = { [key: string]: unknown } | null | null
+
+export interface ActivityLogEntryApi {
+ readonly id: string
+ /** @nullable */
+ readonly user: ActivityLogEntryApiUser
+ readonly activity: string
+ readonly scope: string
+ readonly item_id: string
+ detail?: DetailApi
+ readonly created_at: string
+}
+
+/**
+ * Response shape for paginated activity log endpoints.
+ */
+export interface ActivityLogPaginatedResponseApi {
+ results: ActivityLogEntryApi[]
+ /** @nullable */
+ next: string | null
+ /** @nullable */
+ previous: string | null
+ total_count: number
+}
+
/**
* * `add` - add
* `remove` - remove
@@ -9812,6 +9870,64 @@ export interface BulkUpdateTagsResponseApi {
skipped: BulkUpdateTagsErrorApi[]
}
+/**
+ * Insight enriched with view-count and recent-viewer fields, used by the trending action.
+ */
+export interface TrendingInsightApi {
+ readonly id: number
+ readonly short_id: string
+ /**
+ * @maxLength 400
+ * @nullable
+ */
+ name?: string | null
+ /**
+ * @maxLength 400
+ * @nullable
+ */
+ derived_name?: string | null
+ query?: unknown | null
+ readonly dashboards: readonly number[]
+ readonly dashboard_tiles: readonly DashboardTileBasicApi[]
+ /**
+ * @maxLength 400
+ * @nullable
+ */
+ description?: string | null
+ /** @nullable */
+ readonly last_refresh: string | null
+ readonly refreshing: boolean
+ tags?: unknown[]
+ readonly updated_at: string
+ readonly created_by: UserBasicApi
+ /** @nullable */
+ readonly created_at: string | null
+ last_modified_at?: string
+ favorited?: boolean
+ /**
+ * The effective access level the user has for this object
+ * @nullable
+ */
+ readonly user_access_level: string | null
+ /** @nullable */
+ readonly last_viewed_at: string | null
+ /** Number of distinct viewers in the time window. Higher values indicate insights that more people in the project actively look at, which is a strong proxy for which insights matter. */
+ readonly view_count: number
+ /** Up to 3 of the most recent users who viewed this insight in the time window. */
+ readonly viewers: readonly UserBasicApi[]
+ /** User who last modified this insight, or null if never modified after creation. */
+ readonly last_modified_by: UserBasicApi
+}
+
+export interface PaginatedTrendingInsightListApi {
+ count: number
+ /** @nullable */
+ next?: string | null
+ /** @nullable */
+ previous?: string | null
+ results: TrendingInsightApi[]
+}
+
export type ColumnConfigurationsListParams = {
/**
* Number of results to return per page.
@@ -10046,6 +10162,14 @@ export const InsightsDestroyFormat = {
export type InsightsActivityRetrieveParams = {
format?: InsightsActivityRetrieveFormat
+ /**
+ * Page size. Defaults to 10.
+ */
+ limit?: number
+ /**
+ * 1-indexed page number. Defaults to 1.
+ */
+ page?: number
}
export type InsightsActivityRetrieveFormat =
@@ -10094,6 +10218,14 @@ export const InsightsSuggestionsCreateFormat = {
export type InsightsAllActivityRetrieveParams = {
format?: InsightsAllActivityRetrieveFormat
+ /**
+ * Page size. Defaults to 10.
+ */
+ limit?: number
+ /**
+ * 1-indexed page number. Defaults to 1.
+ */
+ page?: number
}
export type InsightsAllActivityRetrieveFormat =
@@ -10152,7 +10284,19 @@ export const InsightsMyLastViewedRetrieveFormat = {
} as const
export type InsightsTrendingRetrieveParams = {
+ /**
+ * Time window in days to compute view counts over. Defaults to 7. Larger windows surface consistently popular insights; smaller windows surface what's hot right now.
+ */
+ days?: number
format?: InsightsTrendingRetrieveFormat
+ /**
+ * Maximum number of insights to return. Defaults to 10. Capped at 100.
+ */
+ limit?: number
+ /**
+ * The initial index from which to return the results.
+ */
+ offset?: number
}
export type InsightsTrendingRetrieveFormat =
diff --git a/products/product_analytics/frontend/generated/api.ts b/products/product_analytics/frontend/generated/api.ts
index f46848fe058f..f99b5591ea60 100644
--- a/products/product_analytics/frontend/generated/api.ts
+++ b/products/product_analytics/frontend/generated/api.ts
@@ -9,6 +9,7 @@ import { apiMutator } from '../../../../frontend/src/lib/api-orval-mutator'
* OpenAPI spec version: 1.0.0
*/
import type {
+ ActivityLogPaginatedResponseApi,
BulkUpdateTagsRequestApi,
BulkUpdateTagsResponseApi,
ColumnConfigurationApi,
@@ -36,6 +37,7 @@ import type {
PaginatedColumnConfigurationListApi,
PaginatedElementListApi,
PaginatedInsightListApi,
+ PaginatedTrendingInsightListApi,
PatchedColumnConfigurationApi,
PatchedElementApi,
PatchedInsightApi,
@@ -521,12 +523,7 @@ export const insightsDestroy = async (
}
/**
- * DRF ViewSet mixin that gates coalesced responses behind permission checks.
-
-The QueryCoalescingMiddleware attaches cached response data to
-request.META["_coalesced_response"] for followers. This mixin runs DRF's
-initial() (auth + permissions + throttling) before returning the
-cached response, ensuring the request is authorized.
+ * Audit trail for a single insight — every change made to it, by whom, and when. Use this when you want the change history of a specific insight; use the project-wide activity endpoint for a broader view.
*/
export const getInsightsActivityRetrieveUrl = (
projectId: string,
@@ -553,8 +550,8 @@ export const insightsActivityRetrieve = async (
id: number,
params?: InsightsActivityRetrieveParams,
options?: RequestInit
-): Promise<void> => {
- return apiMutator<void>(getInsightsActivityRetrieveUrl(projectId, id, params), {
+): Promise<ActivityLogPaginatedResponseApi> => {
+ return apiMutator<ActivityLogPaginatedResponseApi>(getInsightsActivityRetrieveUrl(projectId, id, params), {
...options,
method: 'GET',
})
@@ -684,12 +681,7 @@ export const insightsSuggestionsCreate = async (
}
/**
- * DRF ViewSet mixin that gates coalesced responses behind permission checks.
-
-The QueryCoalescingMiddleware attaches cached response data to
-request.META["_coalesced_response"] for followers. This mixin runs DRF's
-initial() (auth + permissions + throttling) before returning the
-cached response, ensuring the request is authorized.
+ * Project-wide audit trail across all insights — who created, edited, deleted, or restored insights, what changed (with before/after diffs), and when. Useful for surfacing what people (or agents) have been working on recently.
*/
export const getInsightsAllActivityRetrieveUrl = (projectId: string, params?: InsightsAllActivityRetrieveParams) => {
const normalizedParams = new URLSearchParams()
@@ -711,8 +703,8 @@ export const insightsAllActivityRetrieve = async (
projectId: string,
params?: InsightsAllActivityRetrieveParams,
options?: RequestInit
-): Promise<void> => {
- return apiMutator<void>(getInsightsAllActivityRetrieveUrl(projectId, params), {
+): Promise<ActivityLogPaginatedResponseApi> => {
+ return apiMutator<ActivityLogPaginatedResponseApi>(getInsightsAllActivityRetrieveUrl(projectId, params), {
...options,
method: 'GET',
})
@@ -864,8 +856,7 @@ export const insightsMyLastViewedRetrieve = async (
}
/**
- * Returns trending insights based on view count in the last N days (default 7).
-Defaults to returning top 10 insights.
+ * Returns insights ranked by view count over the last N days (default 7), highest first. Each result includes the same metadata as the standard insights list, plus a `view_count` and up to 3 recent `viewers`. Useful for surfacing the most-used insights in a project.
*/
export const getInsightsTrendingRetrieveUrl = (projectId: string, params?: InsightsTrendingRetrieveParams) => {
const normalizedParams = new URLSearchParams()
@@ -887,8 +878,8 @@ export const insightsTrendingRetrieve = async (
projectId: string,
params?: InsightsTrendingRetrieveParams,
options?: RequestInit
-): Promise<void> => {
- return apiMutator<void>(getInsightsTrendingRetrieveUrl(projectId, params), {
+): Promise<PaginatedTrendingInsightListApi> => {
+ return apiMutator<PaginatedTrendingInsightListApi>(getInsightsTrendingRetrieveUrl(projectId, params), {
...options,
method: 'GET',
})
diff --git a/products/product_analytics/mcp/tools.yaml b/products/product_analytics/mcp/tools.yaml
index af20e4f5641b..6dd244c98822 100644
--- a/products/product_analytics/mcp/tools.yaml
+++ b/products/product_analytics/mcp/tools.yaml
@@ -178,13 +178,53 @@ tools:
- types
insights-activity-retrieve:
operation: insights_activity_retrieve
- enabled: false
+ enabled: true
+ scopes:
+ - activity_log:read
+ annotations:
+ readOnly: true
+ destructive: false
+ idempotent: true
+ list: true
+ title: Get insight activity log
+ description: >
+ Audit trail for a single insight by numeric `id`. Returns a paginated list of every change made to it
+ (created, edited, deleted, restored), including who made each change and which fields changed. The full
+ `before`/`after` diff blobs are omitted to keep responses agent-friendly — to inspect the current state of
+ the insight after a change, call `insight-get` with the insight's `short_id`. Paginate with `limit` and
+ `page`.
+ response:
+ exclude:
+ - detail.changes.*.before
+ - detail.changes.*.after
+ - detail.trigger
+ - detail.type
insights-activity-retrieve-2:
operation: insights_activity_retrieve
enabled: false
insights-all-activity-retrieve:
operation: insights_all_activity_retrieve
- enabled: false
+ enabled: true
+ scopes:
+ - activity_log:read
+ annotations:
+ readOnly: true
+ destructive: false
+ idempotent: true
+ list: true
+ title: Get recent insight activity across the project
+ description: >
+ Project-wide audit trail of changes to all insights, most recent first. Returns who created, edited,
+ deleted, or restored each insight and which fields changed. Useful for surfacing what people (or agents)
+ have been working on recently. The full `before`/`after` diff blobs are omitted to keep responses
+ agent-friendly — drill into a specific insight with `insights-activity-retrieve` (or `insight-get` for
+ current state). Paginate with `limit` and `page`.
+ response:
+ exclude:
+ - detail.changes.*.before
+ - detail.changes.*.after
+ - detail.trigger
+ - detail.type
insights-analyze-retrieve:
operation: insights_analyze_retrieve
enabled: false
@@ -244,7 +284,38 @@ tools:
enabled: false
insights-trending-retrieve:
operation: insights_trending_retrieve
- enabled: false
+ enabled: true
+ scopes:
+ - insight:read
+ annotations:
+ readOnly: true
+ destructive: false
+ idempotent: true
+ enrich_url: '{short_id}'
+ list: true
+ title: Get most-viewed insights
+ description: >
+ Returns the most-viewed insights in the project, ranked by view count over the last N days (default 7). Use
+ this to surface the insights that matter most to the team — the ones people actually open. Each result
+ includes standard insight metadata plus `view_count` and up to 3 recent `viewers`. Returns metadata only —
+ call `insight-query` with the returned `short_id` to fetch the actual data for any of them.
+ response:
+ include:
+ - id
+ - short_id
+ - name
+ - derived_name
+ - description
+ - tags
+ - favorited
+ - dashboards
+ - created_at
+ - created_by
+ - last_modified_at
+ - last_modified_by
+ - last_viewed_at
+ - view_count
+ - viewers
insights-update:
operation: insights_update
enabled: false
diff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.json
index 0c53dc2337a9..f26807dd583f 100644
--- a/services/mcp/schema/generated-tool-definitions.json
+++ b/services/mcp/schema/generated-tool-definitions.json
@@ -2253,6 +2253,36 @@
"readOnlyHint": false
}
},
+ "insights-activity-retrieve": {
+ "description": "Audit trail for a single insight by numeric `id`. Returns a paginated list of every change made to it (created, edited, deleted, restored), including who made each change and which fields changed. The full `before`/`after` diff blobs are omitted to keep responses agent-friendly — to inspect the current state of the insight after a change, call `insight-get` with the insight's `short_id`. Paginate with `limit` and `page`.",
+ "category": "Product analytics",
+ "feature": "product_analytics",
+ "summary": "Get insight activity log",
+ "title": "Get insight activity log",
+ "required_scopes": ["activity_log:read"],
+ "new_mcp": true,
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": true
+ }
+ },
+ "insights-all-activity-retrieve": {
+ "description": "Project-wide audit trail of changes to all insights, most recent first. Returns who created, edited, deleted, or restored each insight and which fields changed. Useful for surfacing what people (or agents) have been working on recently. The full `before`/`after` diff blobs are omitted to keep responses agent-friendly — drill into a specific insight with `insights-activity-retrieve` (or `insight-get` for current state). Paginate with `limit` and `page`.",
+ "category": "Product analytics",
+ "feature": "product_analytics",
+ "summary": "Get recent insight activity across the project",
+ "title": "Get recent insight activity across the project",
+ "required_scopes": ["activity_log:read"],
+ "new_mcp": true,
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": true
+ }
+ },
"insights-list": {
"description": "List saved insights in the project with optional filtering by favorited status or search term. Returns metadata only (name, description, tags, dashboards, ownership) — NOT the query results. To retrieve the actual data for any insight in the list, call the insight-query tool with its `short_id` or numeric `id`.",
"category": "Product analytics",
@@ -2268,6 +2298,21 @@
"readOnlyHint": true
}
},
+ "insights-trending-retrieve": {
+ "description": "Returns the most-viewed insights in the project, ranked by view count over the last N days (default 7). Use this to surface the insights that matter most to the team — the ones people actually open. Each result includes standard insight metadata plus `view_count` and up to 3 recent `viewers`. Returns metadata only — call `insight-query` with the returned `short_id` to fetch the actual data for any of them.",
+ "category": "Product analytics",
+ "feature": "product_analytics",
+ "summary": "Get most-viewed insights",
+ "title": "Get most-viewed insights",
+ "required_scopes": ["insight:read"],
+ "new_mcp": true,
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": true
+ }
+ },
"integration-delete": {
"description": "Permanently delete an integration by ID. This removes the connection to the third-party service. Any features relying on this integration (alerts, workflow destinations, etc.) will stop working.",
"category": "Integrations",
diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.json
index 97859ed8c9cb..b39f58c03980 100644
--- a/services/mcp/schema/tool-definitions-all.json
+++ b/services/mcp/schema/tool-definitions-all.json
@@ -2566,6 +2566,36 @@
"readOnlyHint": false
}
},
+ "insights-activity-retrieve": {
+ "description": "Audit trail for a single insight by numeric `id`. Returns a paginated list of every change made to it (created, edited, deleted, restored), including who made each change and which fields changed. The full `before`/`after` diff blobs are omitted to keep responses agent-friendly — to inspect the current state of the insight after a change, call `insight-get` with the insight's `short_id`. Paginate with `limit` and `page`.",
+ "category": "Product analytics",
+ "feature": "product_analytics",
+ "summary": "Get insight activity log",
+ "title": "Get insight activity log",
+ "required_scopes": ["activity_log:read"],
+ "new_mcp": true,
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": true
+ }
+ },
+ "insights-all-activity-retrieve": {
+ "description": "Project-wide audit trail of changes to all insights, most recent first. Returns who created, edited, deleted, or restored each insight and which fields changed. Useful for surfacing what people (or agents) have been working on recently. The full `before`/`after` diff blobs are omitted to keep responses agent-friendly — drill into a specific insight with `insights-activity-retrieve` (or `insight-get` for current state). Paginate with `limit` and `page`.",
+ "category": "Product analytics",
+ "feature": "product_analytics",
+ "summary": "Get recent insight activity across the project",
+ "title": "Get recent insight activity across the project",
+ "required_scopes": ["activity_log:read"],
+ "new_mcp": true,
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": true
+ }
+ },
"insights-list": {
"description": "List saved insights in the project with optional filtering by favorited status or search term. Returns metadata only (name, description, tags, dashboards, ownership) — NOT the query results. To retrieve the actual data for any insight in the list, call the insight-query tool with its `short_id` or numeric `id`.",
"category": "Product analytics",
@@ -2581,6 +2611,21 @@
"readOnlyHint": true
}
},
+ "insights-trending-retrieve": {
+ "description": "Returns the most-viewed insights in the project, ranked by view count over the last N days (default 7). Use this to surface the insights that matter most to the team — the ones people actually open. Each result includes standard insight metadata plus `view_count` and up to 3 recent `viewers`. Returns metadata only — call `insight-query` with the returned `short_id` to fetch the actual data for any of them.",
+ "category": "Product analytics",
+ "feature": "product_analytics",
+ "summary": "Get most-viewed insights",
+ "title": "Get most-viewed insights",
+ "required_scopes": ["insight:read"],
+ "new_mcp": true,
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": true
+ }
+ },
"integration-delete": {
"description": "Permanently delete an integration by ID. This removes the connection to the third-party service. Any features relying on this integration (alerts, workflow destinations, etc.) will stop working.",
"category": "Integrations",
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 956d9ed1a679..bde0f8bbc097 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -26886,6 +26886,64 @@ export namespace Schemas {
results: TraceReview[];
}
+ /**
+ * Insight enriched with view-count and recent-viewer fields, used by the trending action.
+ */
+ export interface TrendingInsight {
+ readonly id: number;
+ readonly short_id: string;
+ /**
+ * @maxLength 400
+ * @nullable
+ */
+ name?: string | null;
+ /**
+ * @maxLength 400
+ * @nullable
+ */
+ derived_name?: string | null;
+ query?: unknown | null;
+ readonly dashboards: readonly number[];
+ readonly dashboard_tiles: readonly DashboardTileBasic[];
+ /**
+ * @maxLength 400
+ * @nullable
+ */
+ description?: string | null;
+ /** @nullable */
+ readonly last_refresh: string | null;
+ readonly refreshing: boolean;
+ tags?: unknown[];
+ readonly updated_at: string;
+ readonly created_by: UserBasic;
+ /** @nullable */
+ readonly created_at: string | null;
+ last_modified_at?: string;
+ favorited?: boolean;
+ /**
+ * The effective access level the user has for this object
+ * @nullable
+ */
+ readonly user_access_level: string | null;
+ /** @nullable */
+ readonly last_viewed_at: string | null;
+ /** Number of distinct viewers in the time window. Higher values indicate insights that more people in the project actively look at, which is a strong proxy for which insights matter. */
+ readonly view_count: number;
+ /** Up to 3 of the most recent users who viewed this insight in the time window. */
+ readonly viewers: readonly UserBasic[];
+ /** User who last modified this insight, or null if never modified after creation. */
+ readonly last_modified_by: UserBasic;
+ }
+
+ export interface PaginatedTrendingInsightList {
+ count: number;
+ /** @nullable */
+ next?: string | null;
+ /** @nullable */
+ previous?: string | null;
+ results: TrendingInsight[];
+ }
+
export interface UserGitHubAccount {
/**
* GitHub account type for the installation (e.g. User or Organization).
@@ -40719,6 +40777,14 @@ export namespace Schemas {
export type EnvironmentsInsightsActivityRetrieveParams = {
format?: EnvironmentsInsightsActivityRetrieveFormat;
+ /**
+ * Page size. Defaults to 10.
+ */
+ limit?: number;
+ /**
+ * 1-indexed page number. Defaults to 1.
+ */
+ page?: number;
};
export type EnvironmentsInsightsActivityRetrieveFormat = typeof EnvironmentsInsightsActivityRetrieveFormat[keyof typeof EnvironmentsInsightsActivityRetrieveFormat];
@@ -40767,6 +40833,14 @@ export namespace Schemas {
export type EnvironmentsInsightsAllActivityRetrieveParams = {
format?: EnvironmentsInsightsAllActivityRetrieveFormat;
+ /**
+ * Page size. Defaults to 10.
+ */
+ limit?: number;
+ /**
+ * 1-indexed page number. Defaults to 1.
+ */
+ page?: number;
};
export type EnvironmentsInsightsAllActivityRetrieveFormat = typeof EnvironmentsInsightsAllActivityRetrieveFormat[keyof typeof EnvironmentsInsightsAllActivityRetrieveFormat];
@@ -40826,7 +40900,19 @@ export namespace Schemas {
} as const;
export type EnvironmentsInsightsTrendingRetrieveParams = {
+ /**
+ * Time window in days to compute view counts over. Defaults to 7. Larger windows surface consistently popular insights; smaller windows surface what's hot right now.
+ */
+ days?: number;
format?: EnvironmentsInsightsTrendingRetrieveFormat;
+ /**
+ * Maximum number of insights to return. Defaults to 10. Capped at 100.
+ */
+ limit?: number;
+ /**
+ * The initial index from which to return the results.
+ */
+ offset?: number;
};
export type EnvironmentsInsightsTrendingRetrieveFormat = typeof EnvironmentsInsightsTrendingRetrieveFormat[keyof typeof EnvironmentsInsightsTrendingRetrieveFormat];
@@ -45414,6 +45500,14 @@ export namespace Schemas {
export type InsightsActivityRetrieveParams = {
format?: InsightsActivityRetrieveFormat;
+ /**
+ * Page size. Defaults to 10.
+ */
+ limit?: number;
+ /**
+ * 1-indexed page number. Defaults to 1.
+ */
+ page?: number;
};
export type InsightsActivityRetrieveFormat = typeof InsightsActivityRetrieveFormat[keyof typeof InsightsActivityRetrieveFormat];
@@ -45462,6 +45556,14 @@ export namespace Schemas {
export type InsightsAllActivityRetrieveParams = {
format?: InsightsAllActivityRetrieveFormat;
+ /**
+ * Page size. Defaults to 10.
+ */
+ limit?: number;
+ /**
+ * 1-indexed page number. Defaults to 1.
+ */
+ page?: number;
};
export type InsightsAllActivityRetrieveFormat = typeof InsightsAllActivityRetrieveFormat[keyof typeof InsightsAllActivityRetrieveFormat];
@@ -45521,7 +45623,19 @@ export namespace Schemas {
} as const;
export type InsightsTrendingRetrieveParams = {
+ /**
+ * Time window in days to compute view counts over. Defaults to 7. Larger windows surface consistently popular insights; smaller windows surface what's hot right now.
+ */
+ days?: number;
format?: InsightsTrendingRetrieveFormat;
+ /**
+ * Maximum number of insights to return. Defaults to 10. Capped at 100.
+ */
+ limit?: number;
+ /**
+ * The initial index from which to return the results.
+ */
+ offset?: number;
};
export type InsightsTrendingRetrieveFormat = typeof InsightsTrendingRetrieveFormat[keyof typeof InsightsTrendingRetrieveFormat];
diff --git a/services/mcp/src/generated/product_analytics/api.ts b/services/mcp/src/generated/product_analytics/api.ts
index 34cfcf239701..142d08069f98 100644
--- a/services/mcp/src/generated/product_analytics/api.ts
+++ b/services/mcp/src/generated/product_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 5 enabled ops
+ * PostHog API - MCP 8 enabled ops
* OpenAPI spec version: 1.0.0
*/
import * as zod from 'zod'
@@ -287,3 +287,61 @@ export const InsightsDestroyParams = /* @__PURE__ */ zod.object({
export const InsightsDestroyQueryParams = /* @__PURE__ */ zod.object({
format: zod.enum(['csv', 'json']).optional(),
})
+
+/**
+ * Audit trail for a single insight — every change made to it, by whom, and when. Use this when you want the change history of a specific insight; use the project-wide activity endpoint for a broader view.
+ */
+export const InsightsActivityRetrieveParams = /* @__PURE__ */ zod.object({
+ id: zod.number().describe('A unique integer value identifying this insight.'),
+ 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 InsightsActivityRetrieveQueryParams = /* @__PURE__ */ zod.object({
+ format: zod.enum(['csv', 'json']).optional(),
+ limit: zod.number().optional().describe('Page size. Defaults to 10.'),
+ page: zod.number().optional().describe('1-indexed page number. Defaults to 1.'),
+})
+
+/**
+ * Project-wide audit trail across all insights — who created, edited, deleted, or restored insights, what changed (with before/after diffs), and when. Useful for surfacing what people (or agents) have been working on recently.
+ */
+export const InsightsAllActivityRetrieveParams = /* @__PURE__ */ 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 InsightsAllActivityRetrieveQueryParams = /* @__PURE__ */ zod.object({
+ format: zod.enum(['csv', 'json']).optional(),
+ limit: zod.number().optional().describe('Page size. Defaults to 10.'),
+ page: zod.number().optional().describe('1-indexed page number. Defaults to 1.'),
+})
+
+/**
+ * Returns insights ranked by view count over the last N days (default 7), highest first. Each result includes the same metadata as the standard insights list, plus a `view_count` and up to 3 recent `viewers`. Useful for surfacing the most-used insights in a project.
+ */
+export const InsightsTrendingRetrieveParams = /* @__PURE__ */ 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 InsightsTrendingRetrieveQueryParams = /* @__PURE__ */ zod.object({
+ days: zod
+ .number()
+ .optional()
+ .describe(
+ "Time window in days to compute view counts over. Defaults to 7. Larger windows surface consistently popular insights; smaller windows surface what's hot right now."
+ ),
+ format: zod.enum(['csv', 'json']).optional(),
+ limit: zod.number().optional().describe('Maximum number of insights to return. Defaults to 10. Capped at 100.'),
+ offset: zod.number().optional().describe('The initial index from which to return the results.'),
+})
diff --git a/services/mcp/src/tools/generated/product_analytics.ts b/services/mcp/src/tools/generated/product_analytics.ts
index 40c493b898ef..f35cc78430ec 100644
--- a/services/mcp/src/tools/generated/product_analytics.ts
+++ b/services/mcp/src/tools/generated/product_analytics.ts
@@ -3,6 +3,9 @@ import { z } from 'zod'
import type { Schemas } from '@/api/generated'
import {
+ InsightsActivityRetrieveParams,
+ InsightsActivityRetrieveQueryParams,
+ InsightsAllActivityRetrieveQueryParams,
InsightsCreateBody,
InsightsDestroyParams,
InsightsListQueryParams,
@@ -10,6 +13,7 @@ import {
InsightsPartialUpdateParams,
InsightsRetrieveParams,
InsightsRetrieveQueryParams,
+ InsightsTrendingRetrieveQueryParams,
} from '@/generated/product_analytics/api'
import { withPostHogUrl, omitResponseFields, pickResponseFields, type WithPostHogUrl } from '@/tools/tool-utils'
import type { Context, ToolBase, ZodObjectAny } from '@/tools/types'
@@ -291,6 +295,74 @@ const insightUpdate = (): ToolBase<typeof InsightUpdateSchema, WithPostHogUrl<Sc
},
})
+const InsightsActivityRetrieveSchema = InsightsActivityRetrieveParams.omit({ project_id: true }).extend(
+ InsightsActivityRetrieveQueryParams.omit({ format: true }).shape
+)
+
+const insightsActivityRetrieve = (): ToolBase<
+ typeof InsightsActivityRetrieveSchema,
+ WithPostHogUrl<Schemas.ActivityLogPaginatedResponse>
+> => ({
+ name: 'insights-activity-retrieve',
+ schema: InsightsActivityRetrieveSchema,
+ handler: async (context: Context, params: z.infer<typeof InsightsActivityRetrieveSchema>) => {
+ const projectId = await context.stateManager.getProjectId()
+ const result = await context.api.request<Schemas.ActivityLogPaginatedResponse>({
+ method: 'GET',
+ path: `/api/projects/${encodeURIComponent(String(projectId))}/insights/${encodeURIComponent(String(params.id))}/activity/`,
+ query: {
+ limit: params.limit,
+ page: params.page,
+ },
+ })
+ const filtered = {
+ ...result,
+ results: (result.results ?? []).map((item: any) =>
+ omitResponseFields(item, [
+ 'detail.changes.*.before',
+ 'detail.changes.*.after',
+ 'detail.trigger',
+ 'detail.type',
+ ])
+ ),
+ } as typeof result
+ return await withPostHogUrl(context, filtered, '/insights')
+ },
+})
+
+const InsightsAllActivityRetrieveSchema = InsightsAllActivityRetrieveQueryParams.omit({ format: true })
+
+const insightsAllActivityRetrieve = (): ToolBase<
+ typeof InsightsAllActivityRetrieveSchema,
+ WithPostHogUrl<Schemas.ActivityLogPaginatedResponse>
+> => ({
+ name: 'insights-all-activity-retrieve',
+ schema: InsightsAllActivityRetrieveSchema,
+ handler: async (context: Context, params: z.infer<typeof InsightsAllActivityRetrieveSchema>) => {
+ const projectId = await context.stateManager.getProjectId()
+ const result = await context.api.request<Schemas.ActivityLogPaginatedResponse>({
+ method: 'GET',
+ path: `/api/projects/${encodeURIComponent(String(projectId))}/insights/activity/`,
+ query: {
+ limit: params.limit,
+ page: params.page,
+ },
+ })
+ const filtered = {
+ ...result,
+ results: (result.results ?? []).map((item: any) =>
+ omitResponseFields(item, [
+ 'detail.changes.*.before',
+ 'detail.changes.*.after',
+ 'detail.trigger',
+ 'detail.type',
+ ])
+ ),
+ } as typeof result
+ return await withPostHogUrl(context, filtered, '/insights')
+ },
+})
+
const InsightsListSchema = InsightsListQueryParams.omit({ format: true, basic: true, refresh: true })
const insightsList = (): ToolBase<typeof InsightsListSchema, WithPostHogUrl<Schemas.PaginatedInsightList>> => ({
@@ -355,10 +427,67 @@ const insightsList = (): ToolBase<typeof InsightsListSchema, WithPostHogUrl<Sche
},
})
+const InsightsTrendingRetrieveSchema = InsightsTrendingRetrieveQueryParams.omit({ format: true })
+
+const insightsTrendingRetrieve = (): ToolBase<
+ typeof InsightsTrendingRetrieveSchema,
+ WithPostHogUrl<Schemas.PaginatedTrendingInsightList>
+> => ({
+ name: 'insights-trending-retrieve',
+ schema: InsightsTrendingRetrieveSchema,
+ handler: async (context: Context, params: z.infer<typeof InsightsTrendingRetrieveSchema>) => {
+ const projectId = await context.stateManager.getProjectId()
+ const result = await context.api.request<Schemas.PaginatedTrendingInsightList>({
+ method: 'GET',
+ path: `/api/projects/${encodeURIComponent(String(projectId))}/insights/trending/`,
+ query: {
+ days: params.days,
+ limit: params.limit,
+ offset: params.offset,
+ },
+ })
+ const filtered = {
+ ...result,
+ results: (result.results ?? []).map((item: any) =>
+ pickResponseFields(item, [
+ 'id',
+ 'short_id',
+ 'name',
+ 'derived_name',
+ 'description',
+ 'tags',
+ 'favorited',
+ 'dashboards',
+ 'created_at',
+ 'created_by',
+ 'last_modified_at',
+ 'last_modified_by',
+ 'last_viewed_at',
+ 'view_count',
+ 'viewers',
+ ])
+ ),
+ } as typeof result
+ return await withPostHogUrl(
+ context,
+ {
+ ...filtered,
+ results: await Promise.all(
+ (filtered.results ?? []).map((item) => withPostHogUrl(context, item, `/insights/${item.short_id}`))
+ ),
+ },
+ '/insights'
+ )
+ },
+})
+
export const GENERATED_TOOLS: Record<string, () => ToolBase<ZodObjectAny>> = {
'insight-create': insightCreate,
'insight-delete': insightDelete,
'insight-get': insightGet,
'insight-update': insightUpdate,
+ 'insights-activity-retrieve': insightsActivityRetrieve,
+ 'insights-all-activity-retrieve': insightsAllActivityRetrieve,
'insights-list': insightsList,
+ 'insights-trending-retrieve': insightsTrendingRetrieve,
}
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/common/insights-activity-retrieve.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/common/insights-activity-retrieve.json
new file mode 100644
index 000000000000..eea0875241f1
--- /dev/null
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/common/insights-activity-retrieve.json
@@ -0,0 +1,19 @@
+{
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
+ "properties": {
+ "id": {
+ "description": "A unique integer value identifying this insight.",
+ "type": "number"
+ },
+ "limit": {
+ "description": "Page size. Defaults to 10.",
+ "type": "number"
+ },
+ "page": {
+ "description": "1-indexed page number. Defaults to 1.",
+ "type": "number"
+ }
+ },
+ "required": ["id"],
+ "type": "object"
+}
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/common/insights-all-activity-retrieve.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/common/insights-all-activity-retrieve.json
new file mode 100644
index 000000000000..4385bde9237b
--- /dev/null
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/common/insights-all-activity-retrieve.json
@@ -0,0 +1,14 @@
+{
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
+ "properties": {
+ "limit": {
+ "description": "Page size. Defaults to 10.",
+ "type": "number"
+ },
+ "page": {
+ "description": "1-indexed page number. Defaults to 1.",
+ "type": "number"
+ }
+ },
+ "type": "object"
+}
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/common/insights-trending-retrieve.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/common/insights-trending-retrieve.json
new file mode 100644
index 000000000000..79b9abe12acc
--- /dev/null
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/common/insights-trending-retrieve.json
@@ -0,0 +1,18 @@
+{
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
+ "properties": {
+ "days": {
+ "description": "Time window in days to compute view counts over. Defaults to 7. Larger windows surface consistently popular insights; smaller windows surface what's hot right now.",
+ "type": "number"
+ },
+ "limit": {
+ "description": "Maximum number of insights to return. Defaults to 10. Capped at 100.",
+ "type": "number"
+ },
+ "offset": {
+ "description": "The initial index from which to return the results.",
+ "type": "number"
+ }
+ },
+ "type": "object"
+}