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(mcp-analytics): accept shared filters on tool detail queries (#105212)

Georgis Andonisb9b80d7444df
diff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.json
index 50d4e331f9b1..8058498a8ead 100644
--- a/frontend/src/queries/schema.json
+++ b/frontend/src/queries/schema.json
@@ -32736,6 +32736,9 @@
"dateRange": {
"$ref": "#/definitions/DateRange"
},
+ "filterTestAccounts": {
+ "type": "boolean"
+ },
"interval": {
"$ref": "#/definitions/IntervalType",
"description": "Bucket granularity for the series. The frontend passes getDefaultInterval so a sub-day window buckets by hour/minute instead of collapsing to a single day point. Defaults to day."
@@ -32748,6 +32751,12 @@
"$ref": "#/definitions/HogQLQueryModifiers",
"description": "Modifiers used when performing the query"
},
+ "properties": {
+ "items": {
+ "$ref": "#/definitions/MCPAnalyticsPropertyFilter"
+ },
+ "type": "array"
+ },
"response": {
"$ref": "#/definitions/MCPToolDailyStatsQueryResponse"
},
@@ -32852,6 +32861,9 @@
"dateRange": {
"$ref": "#/definitions/DateRange"
},
+ "filterTestAccounts": {
+ "type": "boolean"
+ },
"kind": {
"const": "MCPToolDescriptionsQuery",
"type": "string"
@@ -32860,6 +32872,12 @@
"$ref": "#/definitions/HogQLQueryModifiers",
"description": "Modifiers used when performing the query"
},
+ "properties": {
+ "items": {
+ "$ref": "#/definitions/MCPAnalyticsPropertyFilter"
+ },
+ "type": "array"
+ },
"response": {
"$ref": "#/definitions/MCPToolDescriptionsQueryResponse"
},
@@ -33033,6 +33051,9 @@
"description": "Raw $mcp_error_type bucket; \"unknown\" selects errored events without an error type.",
"type": "string"
},
+ "filterTestAccounts": {
+ "type": "boolean"
+ },
"kind": {
"const": "MCPToolFailureOccurrencesQuery",
"type": "string"
@@ -33041,6 +33062,12 @@
"$ref": "#/definitions/HogQLQueryModifiers",
"description": "Modifiers used when performing the query"
},
+ "properties": {
+ "items": {
+ "$ref": "#/definitions/MCPAnalyticsPropertyFilter"
+ },
+ "type": "array"
+ },
"response": {
"$ref": "#/definitions/MCPToolFailureOccurrencesQueryResponse"
},
@@ -33131,6 +33158,9 @@
"dateRange": {
"$ref": "#/definitions/DateRange"
},
+ "filterTestAccounts": {
+ "type": "boolean"
+ },
"kind": {
"const": "MCPToolFailuresQuery",
"type": "string"
@@ -33139,6 +33169,12 @@
"$ref": "#/definitions/HogQLQueryModifiers",
"description": "Modifiers used when performing the query"
},
+ "properties": {
+ "items": {
+ "$ref": "#/definitions/MCPAnalyticsPropertyFilter"
+ },
+ "type": "array"
+ },
"response": {
"$ref": "#/definitions/MCPToolFailuresQueryResponse"
},
@@ -33243,6 +33279,9 @@
"dateRange": {
"$ref": "#/definitions/DateRange"
},
+ "filterTestAccounts": {
+ "type": "boolean"
+ },
"kind": {
"const": "MCPToolNeighborsQuery",
"type": "string"
@@ -33256,6 +33295,12 @@
"enum": ["before", "after"],
"type": "string"
},
+ "properties": {
+ "items": {
+ "$ref": "#/definitions/MCPAnalyticsPropertyFilter"
+ },
+ "type": "array"
+ },
"response": {
"$ref": "#/definitions/MCPToolNeighborsQueryResponse"
},
@@ -33716,6 +33761,9 @@
"dateRange": {
"$ref": "#/definitions/DateRange"
},
+ "filterTestAccounts": {
+ "type": "boolean"
+ },
"kind": {
"const": "MCPToolSampleIntentsQuery",
"type": "string"
@@ -33724,6 +33772,12 @@
"$ref": "#/definitions/HogQLQueryModifiers",
"description": "Modifiers used when performing the query"
},
+ "properties": {
+ "items": {
+ "$ref": "#/definitions/MCPAnalyticsPropertyFilter"
+ },
+ "type": "array"
+ },
"response": {
"$ref": "#/definitions/MCPToolSampleIntentsQueryResponse"
},
@@ -33844,6 +33898,9 @@
"dateRange": {
"$ref": "#/definitions/DateRange"
},
+ "filterTestAccounts": {
+ "type": "boolean"
+ },
"kind": {
"const": "MCPToolStatsQuery",
"type": "string"
@@ -33852,6 +33909,12 @@
"$ref": "#/definitions/HogQLQueryModifiers",
"description": "Modifiers used when performing the query"
},
+ "properties": {
+ "items": {
+ "$ref": "#/definitions/MCPAnalyticsPropertyFilter"
+ },
+ "type": "array"
+ },
"response": {
"$ref": "#/definitions/MCPToolStatsQueryResponse"
},
@@ -33985,6 +34048,9 @@
"dateRange": {
"$ref": "#/definitions/DateRange"
},
+ "filterTestAccounts": {
+ "type": "boolean"
+ },
"kind": {
"const": "MCPToolTopUsersQuery",
"type": "string"
@@ -33993,6 +34059,12 @@
"$ref": "#/definitions/HogQLQueryModifiers",
"description": "Modifiers used when performing the query"
},
+ "properties": {
+ "items": {
+ "$ref": "#/definitions/MCPAnalyticsPropertyFilter"
+ },
+ "type": "array"
+ },
"response": {
"$ref": "#/definitions/MCPToolTopUsersQueryResponse"
},
diff --git a/frontend/src/queries/schema/schema-general.ts b/frontend/src/queries/schema/schema-general.ts
index 8f3c4ef5b786..08713d041e72 100644
--- a/frontend/src/queries/schema/schema-general.ts
+++ b/frontend/src/queries/schema/schema-general.ts
@@ -3570,6 +3570,8 @@ export interface MCPToolTopUsersQuery extends DataNode<MCPToolTopUsersQueryRespo
/** The effective tool name to scope to (matched against the single-exec-resolved tool name). */
toolName: string
dateRange?: DateRange
+ properties?: MCPAnalyticsPropertyFilter[]
+ filterTestAccounts?: boolean
}
export type CachedMCPToolTopUsersQueryResponse = CachedQueryResponse<MCPToolTopUsersQueryResponse>
@@ -3598,6 +3600,8 @@ export interface MCPToolFailuresQuery extends DataNode<MCPToolFailuresQueryRespo
/** The effective tool name to scope to (matched against the single-exec-resolved tool name). */
toolName: string
dateRange?: DateRange
+ properties?: MCPAnalyticsPropertyFilter[]
+ filterTestAccounts?: boolean
}
export type CachedMCPToolFailuresQueryResponse = CachedQueryResponse<MCPToolFailuresQueryResponse>
@@ -3632,6 +3636,8 @@ export interface MCPToolFailureOccurrencesQuery extends DataNode<MCPToolFailureO
/** When set, only events with this HTTP status match; when unset, only events without a status match. */
errorStatus?: string
dateRange?: DateRange
+ properties?: MCPAnalyticsPropertyFilter[]
+ filterTestAccounts?: boolean
}
export type CachedMCPToolFailureOccurrencesQueryResponse = CachedQueryResponse<MCPToolFailureOccurrencesQueryResponse>
@@ -3659,6 +3665,8 @@ export interface MCPToolStatsQuery extends DataNode<MCPToolStatsQueryResponse> {
/** The effective tool name to scope to (matched against the single-exec-resolved tool name). */
toolName: string
dateRange?: DateRange
+ properties?: MCPAnalyticsPropertyFilter[]
+ filterTestAccounts?: boolean
}
export type CachedMCPToolStatsQueryResponse = CachedQueryResponse<MCPToolStatsQueryResponse>
@@ -3684,6 +3692,8 @@ export interface MCPToolDailyStatsQuery extends DataNode<MCPToolDailyStatsQueryR
/** The effective tool name to scope to (matched against the single-exec-resolved tool name). */
toolName: string
dateRange?: DateRange
+ properties?: MCPAnalyticsPropertyFilter[]
+ filterTestAccounts?: boolean
/** Bucket granularity for the series. The frontend passes getDefaultInterval so a sub-day window
* buckets by hour/minute instead of collapsing to a single day point. Defaults to day. */
interval?: IntervalType
@@ -3853,6 +3863,8 @@ export interface MCPToolDescriptionsQuery extends DataNode<MCPToolDescriptionsQu
/** The effective tool name to scope to (matched against the single-exec-resolved tool name). */
toolName: string
dateRange?: DateRange
+ properties?: MCPAnalyticsPropertyFilter[]
+ filterTestAccounts?: boolean
}
export type CachedMCPToolDescriptionsQueryResponse = CachedQueryResponse<MCPToolDescriptionsQueryResponse>
@@ -3877,6 +3889,8 @@ export interface MCPToolSampleIntentsQuery extends DataNode<MCPToolSampleIntents
/** The effective tool name to scope to (matched against the single-exec-resolved tool name). */
toolName: string
dateRange?: DateRange
+ properties?: MCPAnalyticsPropertyFilter[]
+ filterTestAccounts?: boolean
}
export type CachedMCPToolSampleIntentsQueryResponse = CachedQueryResponse<MCPToolSampleIntentsQueryResponse>
@@ -3899,6 +3913,8 @@ export interface MCPToolNeighborsQuery extends DataNode<MCPToolNeighborsQueryRes
/** Whether to count tools called immediately before or after the target tool. */
neighborDirection: 'before' | 'after'
dateRange?: DateRange
+ properties?: MCPAnalyticsPropertyFilter[]
+ filterTestAccounts?: boolean
}
export type CachedMCPToolNeighborsQueryResponse = CachedQueryResponse<MCPToolNeighborsQueryResponse>
diff --git a/posthog/schema.py b/posthog/schema.py
index 553a016df75d..0c5eb73929a6 100644
--- a/posthog/schema.py
+++ b/posthog/schema.py
@@ -27683,6 +27683,7 @@ class MCPToolDailyStatsQuery(BaseModel):
extra="forbid",
)
dateRange: DateRange | None = None
+ filterTestAccounts: bool | None = None
interval: IntervalType | None = Field(
default=None,
description=(
@@ -27693,6 +27694,7 @@ class MCPToolDailyStatsQuery(BaseModel):
)
kind: Literal["MCPToolDailyStatsQuery"] = "MCPToolDailyStatsQuery"
modifiers: HogQLQueryModifiers | None = Field(default=None, description="Modifiers used when performing the query")
+ properties: list[EventPropertyFilter | PersonPropertyFilter | SessionPropertyFilter] | None = None
response: MCPToolDailyStatsQueryResponse | None = None
tags: QueryLogTags | None = None
toolName: str = Field(
@@ -27707,8 +27709,10 @@ class MCPToolDescriptionsQuery(BaseModel):
extra="forbid",
)
dateRange: DateRange | None = None
+ filterTestAccounts: bool | None = None
kind: Literal["MCPToolDescriptionsQuery"] = "MCPToolDescriptionsQuery"
modifiers: HogQLQueryModifiers | None = Field(default=None, description="Modifiers used when performing the query")
+ properties: list[EventPropertyFilter | PersonPropertyFilter | SessionPropertyFilter] | None = None
response: MCPToolDescriptionsQueryResponse | None = None
tags: QueryLogTags | None = None
toolName: str = Field(
@@ -27733,8 +27737,10 @@ class MCPToolFailureOccurrencesQuery(BaseModel):
...,
description=('Raw $mcp_error_type bucket; "unknown" selects errored events without an error type.'),
)
+ filterTestAccounts: bool | None = None
kind: Literal["MCPToolFailureOccurrencesQuery"] = "MCPToolFailureOccurrencesQuery"
modifiers: HogQLQueryModifiers | None = Field(default=None, description="Modifiers used when performing the query")
+ properties: list[EventPropertyFilter | PersonPropertyFilter | SessionPropertyFilter] | None = None
response: MCPToolFailureOccurrencesQueryResponse | None = None
tags: QueryLogTags | None = None
toolName: str = Field(
@@ -27749,8 +27755,10 @@ class MCPToolFailuresQuery(BaseModel):
extra="forbid",
)
dateRange: DateRange | None = None
+ filterTestAccounts: bool | None = None
kind: Literal["MCPToolFailuresQuery"] = "MCPToolFailuresQuery"
modifiers: HogQLQueryModifiers | None = Field(default=None, description="Modifiers used when performing the query")
+ properties: list[EventPropertyFilter | PersonPropertyFilter | SessionPropertyFilter] | None = None
response: MCPToolFailuresQueryResponse | None = None
tags: QueryLogTags | None = None
toolName: str = Field(
@@ -27765,12 +27773,14 @@ class MCPToolNeighborsQuery(BaseModel):
extra="forbid",
)
dateRange: DateRange | None = None
+ filterTestAccounts: bool | None = None
kind: Literal["MCPToolNeighborsQuery"] = "MCPToolNeighborsQuery"
modifiers: HogQLQueryModifiers | None = Field(default=None, description="Modifiers used when performing the query")
neighborDirection: NeighborDirection = Field(
...,
description=("Whether to count tools called immediately before or after the target tool."),
)
+ properties: list[EventPropertyFilter | PersonPropertyFilter | SessionPropertyFilter] | None = None
response: MCPToolNeighborsQueryResponse | None = None
tags: QueryLogTags | None = None
toolName: str = Field(
@@ -27845,8 +27855,10 @@ class MCPToolSampleIntentsQuery(BaseModel):
extra="forbid",
)
dateRange: DateRange | None = None
+ filterTestAccounts: bool | None = None
kind: Literal["MCPToolSampleIntentsQuery"] = "MCPToolSampleIntentsQuery"
modifiers: HogQLQueryModifiers | None = Field(default=None, description="Modifiers used when performing the query")
+ properties: list[EventPropertyFilter | PersonPropertyFilter | SessionPropertyFilter] | None = None
response: MCPToolSampleIntentsQueryResponse | None = None
tags: QueryLogTags | None = None
toolName: str = Field(
@@ -27861,8 +27873,10 @@ class MCPToolStatsQuery(BaseModel):
extra="forbid",
)
dateRange: DateRange | None = None
+ filterTestAccounts: bool | None = None
kind: Literal["MCPToolStatsQuery"] = "MCPToolStatsQuery"
modifiers: HogQLQueryModifiers | None = Field(default=None, description="Modifiers used when performing the query")
+ properties: list[EventPropertyFilter | PersonPropertyFilter | SessionPropertyFilter] | None = None
response: MCPToolStatsQueryResponse | None = None
tags: QueryLogTags | None = None
toolName: str = Field(
@@ -27877,8 +27891,10 @@ class MCPToolTopUsersQuery(BaseModel):
extra="forbid",
)
dateRange: DateRange | None = None
+ filterTestAccounts: bool | None = None
kind: Literal["MCPToolTopUsersQuery"] = "MCPToolTopUsersQuery"
modifiers: HogQLQueryModifiers | None = Field(default=None, description="Modifiers used when performing the query")
+ properties: list[EventPropertyFilter | PersonPropertyFilter | SessionPropertyFilter] | None = None
response: MCPToolTopUsersQueryResponse | None = None
tags: QueryLogTags | None = None
toolName: str = Field(
diff --git a/products/mcp_analytics/backend/hogql_queries/tool_tables.py b/products/mcp_analytics/backend/hogql_queries/tool_tables.py
index 448d054a8500..087a0f553962 100644
--- a/products/mcp_analytics/backend/hogql_queries/tool_tables.py
+++ b/products/mcp_analytics/backend/hogql_queries/tool_tables.py
@@ -60,11 +60,13 @@ from products.mcp_analytics.backend.hogql_queries.base import (
NEW_SDK_SOURCE,
display_person_properties,
mcp_query_date_range,
+ shared_filter_exprs,
tool_scope_exprs,
validate_mcp_analytics_access,
)
if TYPE_CHECKING:
+ from posthog.models.team import Team
from posthog.models.user import User
# The effective-description expression lives in base.py so the intent-clustering
@@ -89,17 +91,37 @@ _RAW_ERROR_STATUS = "substring(coalesce(toString(properties.$mcp_error_status),
_COMPOSED_FAILURE_LABEL = "concat(error_type, if(empty(error_status), '', concat(' (HTTP ', error_status, ')')))"
-def _tool_call_where(tool: str, date_range: QueryDateRange, *, extra: list[ast.Expr] | None = None) -> ast.Expr:
+# Takes the whole query, not a tool name, so a table added here cannot accept the shared filters
+# in its schema and then drop them from its WHERE.
+_ToolDetailQuery = (
+ MCPToolDailyStatsQuery
+ | MCPToolDescriptionsQuery
+ | MCPToolFailureOccurrencesQuery
+ | MCPToolFailuresQuery
+ | MCPToolSampleIntentsQuery
+ | MCPToolStatsQuery
+ | MCPToolTopUsersQuery
+)
+
+
+def _tool_call_where(
+ query: _ToolDetailQuery,
+ date_range: QueryDateRange,
+ team: "Team",
+ *,
+ extra: list[ast.Expr] | None = None,
+) -> ast.Expr:
"""WHERE for new-SDK $mcp_tool_call events scoped to one effective tool and window.
- `tool` is bound as an ast.Constant, never interpolated. `extra` appends
+ The tool name is bound as an ast.Constant, never interpolated. `extra` appends
query-specific predicates (e.g. notEmpty(description)).
"""
exprs: list[ast.Expr] = [
parse_expr("event = {event}", placeholders={"event": ast.Constant(value=MCP_TOOL_CALL_EVENT)}),
parse_expr("timestamp >= {date_from}", placeholders={"date_from": date_range.date_from_as_hogql()}),
parse_expr("timestamp <= {date_to}", placeholders={"date_to": date_range.date_to_as_hogql()}),
- *tool_scope_exprs(tool),
+ *tool_scope_exprs(query.toolName),
+ *shared_filter_exprs(team, query.properties, query.filterTestAccounts),
]
if extra:
exprs.extend(extra)
@@ -118,7 +140,7 @@ class MCPToolTopUsersQueryRunner(AnalyticsQueryRunner[MCPToolTopUsersQueryRespon
return mcp_query_date_range(self.team, self.query.dateRange)
def _where(self) -> ast.Expr:
- return _tool_call_where(self.query.toolName, self.query_date_range)
+ return _tool_call_where(self.query, self.query_date_range, self.team)
def to_query(self) -> ast.SelectQuery | ast.SelectSetQuery:
return parse_select(
@@ -209,8 +231,9 @@ class MCPToolFailuresQueryRunner(AnalyticsQueryRunner[MCPToolFailuresQueryRespon
# two can never disagree. (Previously this read $exception events, which don't carry MCP
# tool markers, so the table was always empty while the error rate showed failures.)
return _tool_call_where(
- self.query.toolName,
+ self.query,
self.query_date_range,
+ self.team,
extra=[parse_expr("toBool(properties.$mcp_is_error)")],
)
@@ -326,7 +349,7 @@ class MCPToolFailureOccurrencesQueryRunner(AnalyticsQueryRunner[MCPToolFailureOc
)
else:
extra.append(parse_expr("empty({raw_status})", placeholders={"raw_status": parse_expr(_RAW_ERROR_STATUS)}))
- return _tool_call_where(self.query.toolName, self.query_date_range, extra=extra)
+ return _tool_call_where(self.query, self.query_date_range, self.team, extra=extra)
def to_query(self) -> ast.SelectQuery | ast.SelectSetQuery:
return parse_select(
@@ -436,7 +459,7 @@ class MCPToolStatsQueryRunner(AnalyticsQueryRunner[MCPToolStatsQueryResponse]):
"_IS_ERROR": parse_expr(_IS_ERROR),
"_P50": parse_expr(_P50),
"_P95": parse_expr(_P95),
- "where": _tool_call_where(self.query.toolName, self.query_date_range),
+ "where": _tool_call_where(self.query, self.query_date_range, self.team),
},
)
@@ -521,7 +544,7 @@ class MCPToolDailyStatsQueryRunner(AnalyticsQueryRunner[MCPToolDailyStatsQueryRe
"_IS_ERROR": parse_expr(_IS_ERROR),
"_P50": parse_expr(_P50),
"_P95": parse_expr(_P95),
- "where": _tool_call_where(self.query.toolName, self.query_date_range),
+ "where": _tool_call_where(self.query, self.query_date_range, self.team),
},
)
@@ -574,8 +597,9 @@ class MCPToolDescriptionsQueryRunner(AnalyticsQueryRunner[MCPToolDescriptionsQue
def to_query(self) -> ast.SelectQuery | ast.SelectSetQuery:
where = _tool_call_where(
- self.query.toolName,
+ self.query,
self.query_date_range,
+ self.team,
extra=[
parse_expr("notEmpty({description})", placeholders={"description": parse_expr(_EFFECTIVE_DESCRIPTION)})
],
@@ -635,8 +659,9 @@ class MCPToolSampleIntentsQueryRunner(AnalyticsQueryRunner[MCPToolSampleIntentsQ
def to_query(self) -> ast.SelectQuery | ast.SelectSetQuery:
where = _tool_call_where(
- self.query.toolName,
+ self.query,
self.query_date_range,
+ self.team,
extra=[
parse_expr("notEmpty(toString(properties.$mcp_intent))"),
parse_expr("toString(properties.$mcp_intent) != '{}'"),
@@ -743,6 +768,8 @@ class MCPToolNeighborsQueryRunner(AnalyticsQueryRunner[MCPToolNeighborsQueryResp
"properties.$mcp_source = {source}", placeholders={"source": ast.Constant(value=NEW_SDK_SOURCE)}
),
parse_expr("notEmpty({conv_id})", placeholders={"conv_id": parse_expr(_CONVERSATION_ID)}),
+ # In the CTE so a filtered-out call cannot count as a neighbour either.
+ *shared_filter_exprs(self.team, self.query.properties, self.query.filterTestAccounts),
]
)
return parse_select(
diff --git a/products/mcp_analytics/backend/tests/test_tool_tables.py b/products/mcp_analytics/backend/tests/test_tool_tables.py
index abab52174de7..3243ea926c58 100644
--- a/products/mcp_analytics/backend/tests/test_tool_tables.py
+++ b/products/mcp_analytics/backend/tests/test_tool_tables.py
@@ -7,6 +7,7 @@ from parameterized import parameterized
from posthog.schema import (
DateRange,
+ EventPropertyFilter,
IntervalType,
MCPToolDailyStatsQuery,
MCPToolDescriptionsQuery,
@@ -17,6 +18,7 @@ from posthog.schema import (
MCPToolStatsQuery,
MCPToolTopUsersQuery,
NeighborDirection,
+ PropertyOperator,
)
from posthog.models.personal_api_key import PersonalAPIKey
@@ -617,3 +619,149 @@ class TestMCPToolNeighborsQueryRunner(_MCPAnalyticsTeamScopedTestMixin, Clickhou
assert len(rows) == 1
assert rows[0].neighbor_tool == expected_neighbor
assert rows[0].co_occurrences == 1
+
+
+# Shaped so every table on the tool detail page has a row to drop once the filters apply.
+def _setup_included_and_excluded_calls(team: Any) -> None:
+ now = datetime.now(tz=UTC)
+ for distinct_id, client_name, neighbor_tool in (
+ ("d_included", "claude-ai", "neighbor_included"),
+ ("d_excluded", "cursor-vscode", "neighbor_excluded"),
+ ):
+ _emit_tool_call(
+ team,
+ distinct_id=distinct_id,
+ client_name=client_name,
+ session_id=f"conv_{distinct_id}",
+ is_error=True,
+ description=f"description seen by {client_name}",
+ intent='{"goal":"x"}',
+ timestamp=now - timedelta(minutes=1),
+ )
+ _emit_tool_call(
+ team,
+ tool_name=neighbor_tool,
+ distinct_id=distinct_id,
+ client_name=client_name,
+ session_id=f"conv_{distinct_id}",
+ timestamp=now,
+ )
+
+
+# One case per runner, because a runner that accepts the shared filters and drops them from its
+# WHERE shows unfiltered data behind filter controls that claim otherwise.
+class TestMCPToolDetailSharedFilters(_MCPAnalyticsTeamScopedTestMixin, ClickhouseTestMixin, APIBaseTest):
+ @parameterized.expand(
+ [
+ (
+ "top_users",
+ MCPToolTopUsersQueryRunner,
+ MCPToolTopUsersQuery,
+ {},
+ lambda rows: {r.distinct_id for r in rows},
+ {"d_included", "d_excluded"},
+ {"d_included"},
+ ),
+ (
+ "failures",
+ MCPToolFailuresQueryRunner,
+ MCPToolFailuresQuery,
+ {},
+ lambda rows: sum(r.occurrences for r in rows),
+ 2,
+ 1,
+ ),
+ (
+ "failure_occurrences",
+ MCPToolFailureOccurrencesQueryRunner,
+ MCPToolFailureOccurrencesQuery,
+ {"errorType": "unknown"},
+ len,
+ 2,
+ 1,
+ ),
+ (
+ "stats",
+ MCPToolStatsQueryRunner,
+ MCPToolStatsQuery,
+ {},
+ lambda rows: rows[0].calls,
+ 2,
+ 1,
+ ),
+ (
+ "daily_stats",
+ MCPToolDailyStatsQueryRunner,
+ MCPToolDailyStatsQuery,
+ {},
+ lambda rows: sum(r.calls for r in rows),
+ 2,
+ 1,
+ ),
+ (
+ "descriptions",
+ MCPToolDescriptionsQueryRunner,
+ MCPToolDescriptionsQuery,
+ {},
+ len,
+ 2,
+ 1,
+ ),
+ (
+ "sample_intents",
+ MCPToolSampleIntentsQueryRunner,
+ MCPToolSampleIntentsQuery,
+ {},
+ len,
+ 2,
+ 1,
+ ),
+ (
+ "neighbors",
+ MCPToolNeighborsQueryRunner,
+ MCPToolNeighborsQuery,
+ {"neighborDirection": NeighborDirection.AFTER},
+ lambda rows: {r.neighbor_tool for r in rows},
+ {"neighbor_included", "neighbor_excluded"},
+ {"neighbor_included"},
+ ),
+ ]
+ )
+ def test_property_filter_and_test_accounts_narrow_the_results(
+ self,
+ _name: str,
+ runner_cls: Any,
+ query_cls: Any,
+ query_kwargs: dict[str, Any],
+ metric_fn: Any,
+ expected_unfiltered: Any,
+ expected_filtered: Any,
+ ) -> None:
+ _setup_included_and_excluded_calls(self.team)
+ flush_persons_and_events()
+
+ def run(**filter_kwargs: Any) -> Any:
+ query = query_cls(
+ toolName="query_run",
+ dateRange=DateRange(date_from="-7d"),
+ **query_kwargs,
+ **filter_kwargs,
+ )
+ return metric_fn(runner_cls(query=query, team=self.team).calculate().results)
+
+ assert run() == expected_unfiltered
+
+ assert (
+ run(
+ properties=[
+ EventPropertyFilter(key="$mcp_client_name", value=["claude-ai"], operator=PropertyOperator.EXACT)
+ ]
+ )
+ == expected_filtered
+ )
+
+ self.team.test_account_filters = [
+ {"key": "$mcp_client_name", "value": ["cursor-vscode"], "operator": "is_not", "type": "event"}
+ ]
+ self.team.save()
+ assert run(filterTestAccounts=True) == expected_filtered
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index c1b363b453bf..e2eab2475ed1 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -51709,9 +51709,11 @@ export namespace Schemas {
export interface MCPToolTopUsersQuery {
dateRange?: DateRange | null;
+ filterTestAccounts?: boolean | null;
kind?: 'MCPToolTopUsersQuery';
/** Modifiers used when performing the query */
modifiers?: HogQLQueryModifiers | null;
+ properties?: (EventPropertyFilter | PersonPropertyFilter | SessionPropertyFilter)[] | null;
response?: MCPToolTopUsersQueryResponse | null;
tags?: QueryLogTags | null;
/** The effective tool name to scope to (matched against the single-exec-resolved tool name). */
@@ -51757,9 +51759,11 @@ export namespace Schemas {
export interface MCPToolFailuresQuery {
dateRange?: DateRange | null;
+ filterTestAccounts?: boolean | null;
kind?: 'MCPToolFailuresQuery';
/** Modifiers used when performing the query */
modifiers?: HogQLQueryModifiers | null;
+ properties?: (EventPropertyFilter | PersonPropertyFilter | SessionPropertyFilter)[] | null;
response?: MCPToolFailuresQueryResponse | null;
tags?: QueryLogTags | null;
/** The effective tool name to scope to (matched against the single-exec-resolved tool name). */
@@ -51811,9 +51815,11 @@ export namespace Schemas {
errorStatus?: string | null;
/** Raw $mcp_error_type bucket; "unknown" selects errored events without an error type. */
errorType: string;
+ filterTestAccounts?: boolean | null;
kind?: 'MCPToolFailureOccurrencesQuery';
/** Modifiers used when performing the query */
modifiers?: HogQLQueryModifiers | null;
+ properties?: (EventPropertyFilter | PersonPropertyFilter | SessionPropertyFilter)[] | null;
response?: MCPToolFailureOccurrencesQueryResponse | null;
tags?: QueryLogTags | null;
/** The effective tool name to scope to (matched against the single-exec-resolved tool name). */
@@ -51858,9 +51864,11 @@ export namespace Schemas {
export interface MCPToolStatsQuery {
dateRange?: DateRange | null;
+ filterTestAccounts?: boolean | null;
kind?: 'MCPToolStatsQuery';
/** Modifiers used when performing the query */
modifiers?: HogQLQueryModifiers | null;
+ properties?: (EventPropertyFilter | PersonPropertyFilter | SessionPropertyFilter)[] | null;
response?: MCPToolStatsQueryResponse | null;
tags?: QueryLogTags | null;
/** The effective tool name to scope to (matched against the single-exec-resolved tool name). */
@@ -51903,11 +51911,13 @@ export namespace Schemas {
export interface MCPToolDailyStatsQuery {
dateRange?: DateRange | null;
+ filterTestAccounts?: boolean | null;
/** Bucket granularity for the series. The frontend passes getDefaultInterval so a sub-day window buckets by hour/minute instead of collapsing to a single day point. Defaults to day. */
interval?: IntervalType | null;
kind?: 'MCPToolDailyStatsQuery';
/** Modifiers used when performing the query */
modifiers?: HogQLQueryModifiers | null;
+ properties?: (EventPropertyFilter | PersonPropertyFilter | SessionPropertyFilter)[] | null;
response?: MCPToolDailyStatsQueryResponse | null;
tags?: QueryLogTags | null;
/** The effective tool name to scope to (matched against the single-exec-resolved tool name). */
@@ -52197,9 +52207,11 @@ export namespace Schemas {
export interface MCPToolDescriptionsQuery {
dateRange?: DateRange | null;
+ filterTestAccounts?: boolean | null;
kind?: 'MCPToolDescriptionsQuery';
/** Modifiers used when performing the query */
modifiers?: HogQLQueryModifiers | null;
+ properties?: (EventPropertyFilter | PersonPropertyFilter | SessionPropertyFilter)[] | null;
response?: MCPToolDescriptionsQueryResponse | null;
tags?: QueryLogTags | null;
/** The effective tool name to scope to (matched against the single-exec-resolved tool name). */
@@ -52241,9 +52253,11 @@ export namespace Schemas {
export interface MCPToolSampleIntentsQuery {
dateRange?: DateRange | null;
+ filterTestAccounts?: boolean | null;
kind?: 'MCPToolSampleIntentsQuery';
/** Modifiers used when performing the query */
modifiers?: HogQLQueryModifiers | null;
+ properties?: (EventPropertyFilter | PersonPropertyFilter | SessionPropertyFilter)[] | null;
response?: MCPToolSampleIntentsQueryResponse | null;
tags?: QueryLogTags | null;
/** The effective tool name to scope to (matched against the single-exec-resolved tool name). */
@@ -52289,11 +52303,13 @@ export namespace Schemas {
export interface MCPToolNeighborsQuery {
dateRange?: DateRange | null;
+ filterTestAccounts?: boolean | null;
kind?: 'MCPToolNeighborsQuery';
/** Modifiers used when performing the query */
modifiers?: HogQLQueryModifiers | null;
/** Whether to count tools called immediately before or after the target tool. */
neighborDirection: NeighborDirection;
+ properties?: (EventPropertyFilter | PersonPropertyFilter | SessionPropertyFilter)[] | null;
response?: MCPToolNeighborsQueryResponse | null;
tags?: QueryLogTags | null;
/** The effective tool name to scope to (matched against the single-exec-resolved tool name). */
diff --git a/services/mcp/src/tools/generated/mcp_analytics.ts b/services/mcp/src/tools/generated/mcp_analytics.ts
index 745bb4295a7d..fc90e437ce56 100644
--- a/services/mcp/src/tools/generated/mcp_analytics.ts
+++ b/services/mcp/src/tools/generated/mcp_analytics.ts
@@ -321,7 +321,9 @@ const MCPHarnessBreakdownQuery = z.object({
const MCPToolStatsQuery = z.object({
dateRange: DateRange.optional(),
+ filterTestAccounts: z.coerce.boolean().optional(),
kind: z.literal('MCPToolStatsQuery').default('MCPToolStatsQuery'),
+ properties: z.array(MCPAnalyticsPropertyFilter).optional(),
toolName: z
.string()
.describe('The effective tool name to scope to (matched against the single-exec-resolved tool name).'),
@@ -331,10 +333,12 @@ const IntervalType = z.enum(['second', 'minute', 'hour', 'day', 'week', 'month',
const MCPToolDailyStatsQuery = z.object({
dateRange: DateRange.optional(),
+ filterTestAccounts: z.coerce.boolean().optional(),
interval: IntervalType.describe(
'Bucket granularity for the series. The frontend passes getDefaultInterval so a sub-day window buckets by hour/minute instead of collapsing to a single day point. Defaults to day.'
).optional(),
kind: z.literal('MCPToolDailyStatsQuery').default('MCPToolDailyStatsQuery'),
+ properties: z.array(MCPAnalyticsPropertyFilter).optional(),
toolName: z
.string()
.describe('The effective tool name to scope to (matched against the single-exec-resolved tool name).'),
@@ -342,7 +346,9 @@ const MCPToolDailyStatsQuery = z.object({
const MCPToolFailuresQuery = z.object({
dateRange: DateRange.optional(),
+ filterTestAccounts: z.coerce.boolean().optional(),
kind: z.literal('MCPToolFailuresQuery').default('MCPToolFailuresQuery'),
+ properties: z.array(MCPAnalyticsPropertyFilter).optional(),
toolName: z
.string()
.describe('The effective tool name to scope to (matched against the single-exec-resolved tool name).'),
@@ -357,7 +363,9 @@ const MCPToolFailureOccurrencesQuery = z.object({
errorType: z
.string()
.describe('Raw $mcp_error_type bucket; "unknown" selects errored events without an error type.'),
+ filterTestAccounts: z.coerce.boolean().optional(),
kind: z.literal('MCPToolFailureOccurrencesQuery').default('MCPToolFailureOccurrencesQuery'),
+ properties: z.array(MCPAnalyticsPropertyFilter).optional(),
toolName: z
.string()
.describe('The effective tool name to scope to (matched against the single-exec-resolved tool name).'),
@@ -365,7 +373,9 @@ const MCPToolFailureOccurrencesQuery = z.object({
const MCPToolTopUsersQuery = z.object({
dateRange: DateRange.optional(),
+ filterTestAccounts: z.coerce.boolean().optional(),
kind: z.literal('MCPToolTopUsersQuery').default('MCPToolTopUsersQuery'),
+ properties: z.array(MCPAnalyticsPropertyFilter).optional(),
toolName: z
.string()
.describe('The effective tool name to scope to (matched against the single-exec-resolved tool name).'),
@@ -373,10 +383,12 @@ const MCPToolTopUsersQuery = z.object({
const MCPToolNeighborsQuery = z.object({
dateRange: DateRange.optional(),
+ filterTestAccounts: z.coerce.boolean().optional(),
kind: z.literal('MCPToolNeighborsQuery').default('MCPToolNeighborsQuery'),
neighborDirection: z
.enum(['before', 'after'])
.describe('Whether to count tools called immediately before or after the target tool.'),
+ properties: z.array(MCPAnalyticsPropertyFilter).optional(),
toolName: z
.string()
.describe('The effective tool name to scope to (matched against the single-exec-resolved tool name).'),
@@ -384,7 +396,9 @@ const MCPToolNeighborsQuery = z.object({
const MCPToolSampleIntentsQuery = z.object({
dateRange: DateRange.optional(),
+ filterTestAccounts: z.coerce.boolean().optional(),
kind: z.literal('MCPToolSampleIntentsQuery').default('MCPToolSampleIntentsQuery'),
+ properties: z.array(MCPAnalyticsPropertyFilter).optional(),
toolName: z
.string()
.describe('The effective tool name to scope to (matched against the single-exec-resolved tool name).'),
@@ -392,7 +406,9 @@ const MCPToolSampleIntentsQuery = z.object({
const MCPToolDescriptionsQuery = z.object({
dateRange: DateRange.optional(),
+ filterTestAccounts: z.coerce.boolean().optional(),
kind: z.literal('MCPToolDescriptionsQuery').default('MCPToolDescriptionsQuery'),
+ properties: z.array(MCPAnalyticsPropertyFilter).optional(),
toolName: z
.string()
.describe('The effective tool name to scope to (matched against the single-exec-resolved tool name).'),