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(mcp-analytics): add tool sample-intents and neighbors runners (#66088)

Paul D'Ambra10cd25b6a634
diff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.json
index a767f23b0c20..f35640ae161e 100644
--- a/frontend/src/queries/schema.json
+++ b/frontend/src/queries/schema.json
@@ -930,6 +930,12 @@
},
{
"$ref": "#/definitions/MCPToolDescriptionsQuery"
+ },
+ {
+ "$ref": "#/definitions/MCPToolSampleIntentsQuery"
+ },
+ {
+ "$ref": "#/definitions/MCPToolNeighborsQuery"
}
]
},
@@ -8146,6 +8152,178 @@
],
"type": "object"
},
+ "CachedMCPToolNeighborsQueryResponse": {
+ "additionalProperties": false,
+ "properties": {
+ "cache_key": {
+ "type": "string"
+ },
+ "cache_target_age": {
+ "format": "date-time",
+ "type": "string"
+ },
+ "calculation_trigger": {
+ "description": "What triggered the calculation of the query, leave empty if user/immediate",
+ "type": "string"
+ },
+ "error": {
+ "description": "Query error. Returned only if 'explain' or `modifiers.debug` is true. Throws an error otherwise.",
+ "type": "string"
+ },
+ "hogql": {
+ "description": "Generated HogQL query.",
+ "type": "string"
+ },
+ "is_cached": {
+ "type": "boolean"
+ },
+ "last_refresh": {
+ "format": "date-time",
+ "type": "string"
+ },
+ "modifiers": {
+ "$ref": "#/definitions/HogQLQueryModifiers",
+ "description": "Modifiers used when performing the query"
+ },
+ "next_allowed_client_refresh": {
+ "format": "date-time",
+ "type": "string"
+ },
+ "query_metadata": {
+ "type": "object"
+ },
+ "query_status": {
+ "$ref": "#/definitions/QueryStatus",
+ "description": "Query status indicates whether next to the provided data, a query is still running."
+ },
+ "resolved_compare_date_range": {
+ "$ref": "#/definitions/ResolvedDateRangeResponse",
+ "description": "The resolved previous/comparison period date range, when comparing against another period"
+ },
+ "resolved_date_range": {
+ "$ref": "#/definitions/ResolvedDateRangeResponse",
+ "description": "The date range used for the query"
+ },
+ "results": {
+ "items": {
+ "$ref": "#/definitions/MCPToolNeighborItem"
+ },
+ "type": "array"
+ },
+ "timezone": {
+ "type": "string"
+ },
+ "timings": {
+ "description": "Measured timings for different parts of the query generation process",
+ "items": {
+ "$ref": "#/definitions/QueryTiming"
+ },
+ "type": "array"
+ },
+ "warnings": {
+ "description": "Warnings about data warehouse sources referenced by the query whose latest sync failed, is paused, hit a billing limit, or is otherwise stale. Results may not reflect current source data. Accumulated across every HogQL execution that contributes to this response — so insights backed by warehouse tables (Trends, Funnels, etc.) receive the same warnings as raw HogQL queries.",
+ "items": {
+ "$ref": "#/definitions/DataWarehouseSyncWarning"
+ },
+ "type": "array"
+ }
+ },
+ "required": [
+ "cache_key",
+ "is_cached",
+ "last_refresh",
+ "next_allowed_client_refresh",
+ "results",
+ "timezone"
+ ],
+ "type": "object"
+ },
+ "CachedMCPToolSampleIntentsQueryResponse": {
+ "additionalProperties": false,
+ "properties": {
+ "cache_key": {
+ "type": "string"
+ },
+ "cache_target_age": {
+ "format": "date-time",
+ "type": "string"
+ },
+ "calculation_trigger": {
+ "description": "What triggered the calculation of the query, leave empty if user/immediate",
+ "type": "string"
+ },
+ "error": {
+ "description": "Query error. Returned only if 'explain' or `modifiers.debug` is true. Throws an error otherwise.",
+ "type": "string"
+ },
+ "hogql": {
+ "description": "Generated HogQL query.",
+ "type": "string"
+ },
+ "is_cached": {
+ "type": "boolean"
+ },
+ "last_refresh": {
+ "format": "date-time",
+ "type": "string"
+ },
+ "modifiers": {
+ "$ref": "#/definitions/HogQLQueryModifiers",
+ "description": "Modifiers used when performing the query"
+ },
+ "next_allowed_client_refresh": {
+ "format": "date-time",
+ "type": "string"
+ },
+ "query_metadata": {
+ "type": "object"
+ },
+ "query_status": {
+ "$ref": "#/definitions/QueryStatus",
+ "description": "Query status indicates whether next to the provided data, a query is still running."
+ },
+ "resolved_compare_date_range": {
+ "$ref": "#/definitions/ResolvedDateRangeResponse",
+ "description": "The resolved previous/comparison period date range, when comparing against another period"
+ },
+ "resolved_date_range": {
+ "$ref": "#/definitions/ResolvedDateRangeResponse",
+ "description": "The date range used for the query"
+ },
+ "results": {
+ "items": {
+ "$ref": "#/definitions/MCPToolSampleIntentItem"
+ },
+ "type": "array"
+ },
+ "timezone": {
+ "type": "string"
+ },
+ "timings": {
+ "description": "Measured timings for different parts of the query generation process",
+ "items": {
+ "$ref": "#/definitions/QueryTiming"
+ },
+ "type": "array"
+ },
+ "warnings": {
+ "description": "Warnings about data warehouse sources referenced by the query whose latest sync failed, is paused, hit a billing limit, or is otherwise stale. Results may not reflect current source data. Accumulated across every HogQL execution that contributes to this response — so insights backed by warehouse tables (Trends, Funnels, etc.) receive the same warnings as raw HogQL queries.",
+ "items": {
+ "$ref": "#/definitions/DataWarehouseSyncWarning"
+ },
+ "type": "array"
+ }
+ },
+ "required": [
+ "cache_key",
+ "is_cached",
+ "last_refresh",
+ "next_allowed_client_refresh",
+ "results",
+ "timezone"
+ ],
+ "type": "object"
+ },
"CachedMCPToolStatsQueryResponse": {
"additionalProperties": false,
"properties": {
@@ -27540,6 +27718,215 @@
"required": ["results"],
"type": "object"
},
+ "MCPToolNeighborItem": {
+ "additionalProperties": false,
+ "description": "One tool frequently called adjacent to the target tool within the same conversation.",
+ "properties": {
+ "co_occurrences": {
+ "$ref": "#/definitions/integer"
+ },
+ "neighbor_tool": {
+ "type": "string"
+ }
+ },
+ "required": ["neighbor_tool", "co_occurrences"],
+ "type": "object"
+ },
+ "MCPToolNeighborsQuery": {
+ "additionalProperties": false,
+ "description": "Tools most often called immediately before or after a single MCP tool within a conversation.",
+ "properties": {
+ "dateRange": {
+ "$ref": "#/definitions/DateRange"
+ },
+ "kind": {
+ "const": "MCPToolNeighborsQuery",
+ "type": "string"
+ },
+ "modifiers": {
+ "$ref": "#/definitions/HogQLQueryModifiers",
+ "description": "Modifiers used when performing the query"
+ },
+ "neighborDirection": {
+ "description": "Whether to count tools called immediately before or after the target tool.",
+ "enum": ["before", "after"],
+ "type": "string"
+ },
+ "response": {
+ "$ref": "#/definitions/MCPToolNeighborsQueryResponse"
+ },
+ "tags": {
+ "$ref": "#/definitions/QueryLogTags"
+ },
+ "toolName": {
+ "description": "The effective tool name to scope to (matched against the single-exec-resolved tool name).",
+ "type": "string"
+ },
+ "version": {
+ "description": "version of the node, used for schema migrations",
+ "type": "number"
+ }
+ },
+ "required": ["kind", "neighborDirection", "toolName"],
+ "type": "object"
+ },
+ "MCPToolNeighborsQueryResponse": {
+ "additionalProperties": false,
+ "properties": {
+ "error": {
+ "description": "Query error. Returned only if 'explain' or `modifiers.debug` is true. Throws an error otherwise.",
+ "type": "string"
+ },
+ "hogql": {
+ "description": "Generated HogQL query.",
+ "type": "string"
+ },
+ "modifiers": {
+ "$ref": "#/definitions/HogQLQueryModifiers",
+ "description": "Modifiers used when performing the query"
+ },
+ "query_status": {
+ "$ref": "#/definitions/QueryStatus",
+ "description": "Query status indicates whether next to the provided data, a query is still running."
+ },
+ "resolved_compare_date_range": {
+ "$ref": "#/definitions/ResolvedDateRangeResponse",
+ "description": "The resolved previous/comparison period date range, when comparing against another period"
+ },
+ "resolved_date_range": {
+ "$ref": "#/definitions/ResolvedDateRangeResponse",
+ "description": "The date range used for the query"
+ },
+ "results": {
+ "items": {
+ "$ref": "#/definitions/MCPToolNeighborItem"
+ },
+ "type": "array"
+ },
+ "timings": {
+ "description": "Measured timings for different parts of the query generation process",
+ "items": {
+ "$ref": "#/definitions/QueryTiming"
+ },
+ "type": "array"
+ },
+ "warnings": {
+ "description": "Warnings about data warehouse sources referenced by the query whose latest sync failed, is paused, hit a billing limit, or is otherwise stale. Results may not reflect current source data. Accumulated across every HogQL execution that contributes to this response — so insights backed by warehouse tables (Trends, Funnels, etc.) receive the same warnings as raw HogQL queries.",
+ "items": {
+ "$ref": "#/definitions/DataWarehouseSyncWarning"
+ },
+ "type": "array"
+ }
+ },
+ "required": ["results"],
+ "type": "object"
+ },
+ "MCPToolSampleIntentItem": {
+ "additionalProperties": false,
+ "description": "One sampled call of a single MCP tool that carried a non-empty intent.",
+ "properties": {
+ "harness": {
+ "description": "Resolved harness label for the call.",
+ "type": "string"
+ },
+ "intent": {
+ "description": "JSON-encoded intent payload as reported by the client.",
+ "type": "string"
+ },
+ "intent_source": {
+ "type": "string"
+ },
+ "timestamp": {
+ "type": "string"
+ }
+ },
+ "required": ["timestamp", "intent", "intent_source", "harness"],
+ "type": "object"
+ },
+ "MCPToolSampleIntentsQuery": {
+ "additionalProperties": false,
+ "description": "Recent sampled intents for a single MCP tool over the last 7 days, with a resolved harness label.",
+ "properties": {
+ "dateRange": {
+ "$ref": "#/definitions/DateRange"
+ },
+ "kind": {
+ "const": "MCPToolSampleIntentsQuery",
+ "type": "string"
+ },
+ "modifiers": {
+ "$ref": "#/definitions/HogQLQueryModifiers",
+ "description": "Modifiers used when performing the query"
+ },
+ "response": {
+ "$ref": "#/definitions/MCPToolSampleIntentsQueryResponse"
+ },
+ "tags": {
+ "$ref": "#/definitions/QueryLogTags"
+ },
+ "toolName": {
+ "description": "The effective tool name to scope to (matched against the single-exec-resolved tool name).",
+ "type": "string"
+ },
+ "version": {
+ "description": "version of the node, used for schema migrations",
+ "type": "number"
+ }
+ },
+ "required": ["kind", "toolName"],
+ "type": "object"
+ },
+ "MCPToolSampleIntentsQueryResponse": {
+ "additionalProperties": false,
+ "properties": {
+ "error": {
+ "description": "Query error. Returned only if 'explain' or `modifiers.debug` is true. Throws an error otherwise.",
+ "type": "string"
+ },
+ "hogql": {
+ "description": "Generated HogQL query.",
+ "type": "string"
+ },
+ "modifiers": {
+ "$ref": "#/definitions/HogQLQueryModifiers",
+ "description": "Modifiers used when performing the query"
+ },
+ "query_status": {
+ "$ref": "#/definitions/QueryStatus",
+ "description": "Query status indicates whether next to the provided data, a query is still running."
+ },
+ "resolved_compare_date_range": {
+ "$ref": "#/definitions/ResolvedDateRangeResponse",
+ "description": "The resolved previous/comparison period date range, when comparing against another period"
+ },
+ "resolved_date_range": {
+ "$ref": "#/definitions/ResolvedDateRangeResponse",
+ "description": "The date range used for the query"
+ },
+ "results": {
+ "items": {
+ "$ref": "#/definitions/MCPToolSampleIntentItem"
+ },
+ "type": "array"
+ },
+ "timings": {
+ "description": "Measured timings for different parts of the query generation process",
+ "items": {
+ "$ref": "#/definitions/QueryTiming"
+ },
+ "type": "array"
+ },
+ "warnings": {
+ "description": "Warnings about data warehouse sources referenced by the query whose latest sync failed, is paused, hit a billing limit, or is otherwise stale. Results may not reflect current source data. Accumulated across every HogQL execution that contributes to this response — so insights backed by warehouse tables (Trends, Funnels, etc.) receive the same warnings as raw HogQL queries.",
+ "items": {
+ "$ref": "#/definitions/DataWarehouseSyncWarning"
+ },
+ "type": "array"
+ }
+ },
+ "required": ["results"],
+ "type": "object"
+ },
"MCPToolStatsItem": {
"additionalProperties": false,
"description": "Summary scalars for a single MCP tool: activity, latency, reach, and intent coverage.",
@@ -30782,6 +31169,8 @@
"MCPToolStatsQuery",
"MCPToolDailyStatsQuery",
"MCPToolDescriptionsQuery",
+ "MCPToolSampleIntentsQuery",
+ "MCPToolNeighborsQuery",
"PropertyValuesQuery"
],
"type": "string"
@@ -38471,6 +38860,108 @@
"required": ["results"],
"type": "object"
},
+ {
+ "additionalProperties": false,
+ "properties": {
+ "error": {
+ "description": "Query error. Returned only if 'explain' or `modifiers.debug` is true. Throws an error otherwise.",
+ "type": "string"
+ },
+ "hogql": {
+ "description": "Generated HogQL query.",
+ "type": "string"
+ },
+ "modifiers": {
+ "$ref": "#/definitions/HogQLQueryModifiers",
+ "description": "Modifiers used when performing the query"
+ },
+ "query_status": {
+ "$ref": "#/definitions/QueryStatus",
+ "description": "Query status indicates whether next to the provided data, a query is still running."
+ },
+ "resolved_compare_date_range": {
+ "$ref": "#/definitions/ResolvedDateRangeResponse",
+ "description": "The resolved previous/comparison period date range, when comparing against another period"
+ },
+ "resolved_date_range": {
+ "$ref": "#/definitions/ResolvedDateRangeResponse",
+ "description": "The date range used for the query"
+ },
+ "results": {
+ "items": {
+ "$ref": "#/definitions/MCPToolSampleIntentItem"
+ },
+ "type": "array"
+ },
+ "timings": {
+ "description": "Measured timings for different parts of the query generation process",
+ "items": {
+ "$ref": "#/definitions/QueryTiming"
+ },
+ "type": "array"
+ },
+ "warnings": {
+ "description": "Warnings about data warehouse sources referenced by the query whose latest sync failed, is paused, hit a billing limit, or is otherwise stale. Results may not reflect current source data. Accumulated across every HogQL execution that contributes to this response — so insights backed by warehouse tables (Trends, Funnels, etc.) receive the same warnings as raw HogQL queries.",
+ "items": {
+ "$ref": "#/definitions/DataWarehouseSyncWarning"
+ },
+ "type": "array"
+ }
+ },
+ "required": ["results"],
+ "type": "object"
+ },
+ {
+ "additionalProperties": false,
+ "properties": {
+ "error": {
+ "description": "Query error. Returned only if 'explain' or `modifiers.debug` is true. Throws an error otherwise.",
+ "type": "string"
+ },
+ "hogql": {
+ "description": "Generated HogQL query.",
+ "type": "string"
+ },
+ "modifiers": {
+ "$ref": "#/definitions/HogQLQueryModifiers",
+ "description": "Modifiers used when performing the query"
+ },
+ "query_status": {
+ "$ref": "#/definitions/QueryStatus",
+ "description": "Query status indicates whether next to the provided data, a query is still running."
+ },
+ "resolved_compare_date_range": {
+ "$ref": "#/definitions/ResolvedDateRangeResponse",
+ "description": "The resolved previous/comparison period date range, when comparing against another period"
+ },
+ "resolved_date_range": {
+ "$ref": "#/definitions/ResolvedDateRangeResponse",
+ "description": "The date range used for the query"
+ },
+ "results": {
+ "items": {
+ "$ref": "#/definitions/MCPToolNeighborItem"
+ },
+ "type": "array"
+ },
+ "timings": {
+ "description": "Measured timings for different parts of the query generation process",
+ "items": {
+ "$ref": "#/definitions/QueryTiming"
+ },
+ "type": "array"
+ },
+ "warnings": {
+ "description": "Warnings about data warehouse sources referenced by the query whose latest sync failed, is paused, hit a billing limit, or is otherwise stale. Results may not reflect current source data. Accumulated across every HogQL execution that contributes to this response — so insights backed by warehouse tables (Trends, Funnels, etc.) receive the same warnings as raw HogQL queries.",
+ "items": {
+ "$ref": "#/definitions/DataWarehouseSyncWarning"
+ },
+ "type": "array"
+ }
+ },
+ "required": ["results"],
+ "type": "object"
+ },
{
"additionalProperties": false,
"properties": {
@@ -38784,6 +39275,12 @@
{
"$ref": "#/definitions/MCPToolDescriptionsQuery"
},
+ {
+ "$ref": "#/definitions/MCPToolSampleIntentsQuery"
+ },
+ {
+ "$ref": "#/definitions/MCPToolNeighborsQuery"
+ },
{
"$ref": "#/definitions/PropertyValuesQuery"
}
diff --git a/frontend/src/queries/schema/schema-general.ts b/frontend/src/queries/schema/schema-general.ts
index dc5087e17365..9dfc36c56e5b 100644
--- a/frontend/src/queries/schema/schema-general.ts
+++ b/frontend/src/queries/schema/schema-general.ts
@@ -199,6 +199,8 @@ export enum NodeKind {
MCPToolStatsQuery = 'MCPToolStatsQuery',
MCPToolDailyStatsQuery = 'MCPToolDailyStatsQuery',
MCPToolDescriptionsQuery = 'MCPToolDescriptionsQuery',
+ MCPToolSampleIntentsQuery = 'MCPToolSampleIntentsQuery',
+ MCPToolNeighborsQuery = 'MCPToolNeighborsQuery',
// Property values
PropertyValuesQuery = 'PropertyValuesQuery',
@@ -269,6 +271,8 @@ export type AnyDataNode =
| MCPToolStatsQuery
| MCPToolDailyStatsQuery
| MCPToolDescriptionsQuery
+ | MCPToolSampleIntentsQuery
+ | MCPToolNeighborsQuery
/**
* @discriminator kind
@@ -386,6 +390,8 @@ export type QuerySchema =
| MCPToolStatsQuery
| MCPToolDailyStatsQuery
| MCPToolDescriptionsQuery
+ | MCPToolSampleIntentsQuery
+ | MCPToolNeighborsQuery
// Property values
| PropertyValuesQuery
@@ -2687,6 +2693,52 @@ export interface MCPToolDescriptionsQuery extends DataNode<MCPToolDescriptionsQu
export type CachedMCPToolDescriptionsQueryResponse = CachedQueryResponse<MCPToolDescriptionsQueryResponse>
+/** One sampled call of a single MCP tool that carried a non-empty intent. */
+export interface MCPToolSampleIntentItem {
+ timestamp: string
+ /** JSON-encoded intent payload as reported by the client. */
+ intent: string
+ intent_source: string
+ /** Resolved harness label for the call. */
+ harness: string
+}
+
+export interface MCPToolSampleIntentsQueryResponse extends AnalyticsQueryResponseBase {
+ results: MCPToolSampleIntentItem[]
+}
+
+/** Recent sampled intents for a single MCP tool over the last 7 days, with a resolved harness label. */
+export interface MCPToolSampleIntentsQuery extends DataNode<MCPToolSampleIntentsQueryResponse> {
+ kind: NodeKind.MCPToolSampleIntentsQuery
+ /** The effective tool name to scope to (matched against the single-exec-resolved tool name). */
+ toolName: string
+ dateRange?: DateRange
+}
+
+export type CachedMCPToolSampleIntentsQueryResponse = CachedQueryResponse<MCPToolSampleIntentsQueryResponse>
+
+/** One tool frequently called adjacent to the target tool within the same conversation. */
+export interface MCPToolNeighborItem {
+ neighbor_tool: string
+ co_occurrences: integer
+}
+
+export interface MCPToolNeighborsQueryResponse extends AnalyticsQueryResponseBase {
+ results: MCPToolNeighborItem[]
+}
+
+/** Tools most often called immediately before or after a single MCP tool within a conversation. */
+export interface MCPToolNeighborsQuery extends DataNode<MCPToolNeighborsQueryResponse> {
+ kind: NodeKind.MCPToolNeighborsQuery
+ /** The effective tool name to scope to (matched against the single-exec-resolved tool name). */
+ toolName: string
+ /** Whether to count tools called immediately before or after the target tool. */
+ neighborDirection: 'before' | 'after'
+ dateRange?: DateRange
+}
+
+export type CachedMCPToolNeighborsQueryResponse = CachedQueryResponse<MCPToolNeighborsQueryResponse>
+
export enum WebStatsBreakdown {
Page = 'Page',
InitialPage = 'InitialPage',
diff --git a/frontend/src/scenes/saved-insights/SavedInsights.tsx b/frontend/src/scenes/saved-insights/SavedInsights.tsx
index 6c1d19f6aaea..a816a4698fe6 100644
--- a/frontend/src/scenes/saved-insights/SavedInsights.tsx
+++ b/frontend/src/scenes/saved-insights/SavedInsights.tsx
@@ -633,6 +633,18 @@ export const QUERY_TYPES_METADATA: Record<NodeKind, InsightTypeMetadata> = {
icon: IconPieChart,
inMenu: false,
},
+ [NodeKind.MCPToolSampleIntentsQuery]: {
+ name: 'MCP tool sample intents',
+ description: 'Recent sampled intents for a single MCP tool.',
+ icon: IconPieChart,
+ inMenu: false,
+ },
+ [NodeKind.MCPToolNeighborsQuery]: {
+ name: 'MCP tool neighbors',
+ description: 'Tools called adjacent to a single MCP tool within a conversation.',
+ icon: IconPieChart,
+ inMenu: false,
+ },
[NodeKind.MCPToolStatsQuery]: {
name: 'MCP tool stats',
description: 'Summary stats for a single MCP tool.',
diff --git a/posthog/clickhouse/query_tagging.py b/posthog/clickhouse/query_tagging.py
index 04ddfa0b3923..9693af849287 100644
--- a/posthog/clickhouse/query_tagging.py
+++ b/posthog/clickhouse/query_tagging.py
@@ -269,6 +269,8 @@ def kind_fallback_tags(kind: NodeKind) -> FallbackTags | None:
| NodeKind.MCP_TOOL_STATS_QUERY
| NodeKind.MCP_TOOL_DAILY_STATS_QUERY
| NodeKind.MCP_TOOL_DESCRIPTIONS_QUERY
+ | NodeKind.MCP_TOOL_SAMPLE_INTENTS_QUERY
+ | NodeKind.MCP_TOOL_NEIGHBORS_QUERY
):
return {"product": Product.MCP_ANALYTICS}
case (
diff --git a/posthog/hogql_queries/query_runner.py b/posthog/hogql_queries/query_runner.py
index a945cd867160..31210afe3c5d 100644
--- a/posthog/hogql_queries/query_runner.py
+++ b/posthog/hogql_queries/query_runner.py
@@ -47,6 +47,8 @@ from posthog.schema import (
MCPToolDailyStatsQuery,
MCPToolDescriptionsQuery,
MCPToolFailuresQuery,
+ MCPToolNeighborsQuery,
+ MCPToolSampleIntentsQuery,
MCPToolStatsQuery,
MCPToolTopUsersQuery,
NodeKind,
@@ -322,6 +324,8 @@ RunnableQueryNode = Union[
MCPToolStatsQuery,
MCPToolDailyStatsQuery,
MCPToolDescriptionsQuery,
+ MCPToolSampleIntentsQuery,
+ MCPToolNeighborsQuery,
]
@@ -1017,6 +1021,28 @@ def get_query_runner(
modifiers=modifiers,
user=user,
)
+ if kind == "MCPToolSampleIntentsQuery":
+ from products.mcp_analytics.backend.facade.queries import MCPToolSampleIntentsQueryRunner
+
+ return MCPToolSampleIntentsQueryRunner(
+ query=cast(MCPToolSampleIntentsQuery | dict[str, Any], query),
+ team=team,
+ timings=timings,
+ limit_context=limit_context,
+ modifiers=modifiers,
+ user=user,
+ )
+ if kind == "MCPToolNeighborsQuery":
+ from products.mcp_analytics.backend.facade.queries import MCPToolNeighborsQueryRunner
+
+ return MCPToolNeighborsQueryRunner(
+ query=cast(MCPToolNeighborsQuery | dict[str, Any], query),
+ team=team,
+ timings=timings,
+ limit_context=limit_context,
+ modifiers=modifiers,
+ user=user,
+ )
if kind == "TraceQuery":
from .ai.trace_query_runner import TraceQueryRunner
diff --git a/posthog/schema.py b/posthog/schema.py
index 002a4df263df..f0bd98ec5771 100644
--- a/posthog/schema.py
+++ b/posthog/schema.py
@@ -181,6 +181,7 @@ from posthog.schema_enums import (
MultiQuestionFormFieldType as MultiQuestionFormFieldType,
MultiQuestionFormQuestionType as MultiQuestionFormQuestionType,
NativeMarketingSource as NativeMarketingSource,
+ NeighborDirection as NeighborDirection,
NodeKind as NodeKind,
NonIntegratedConversionsColumnsSchemaNames as NonIntegratedConversionsColumnsSchemaNames,
Operator as Operator,
@@ -1683,6 +1684,16 @@ class MCPToolDescriptionItem(BaseModel):
last_seen: str
+class MCPToolSampleIntentItem(BaseModel):
+ model_config = ConfigDict(
+ extra="forbid",
+ )
+ harness: str = Field(..., description="Resolved harness label for the call.")
+ intent: str = Field(..., description="JSON-encoded intent payload as reported by the client.")
+ intent_source: str
+ timestamp: str
+
+
class MarkdownBlock(BaseModel):
model_config = ConfigDict(
extra="forbid",
@@ -5789,6 +5800,14 @@ class MCPToolFailureItem(BaseModel):
occurrences: int
+class MCPToolNeighborItem(BaseModel):
+ model_config = ConfigDict(
+ extra="forbid",
+ )
+ co_occurrences: int
+ neighbor_tool: str
+
+
class MCPToolStatsItem(BaseModel):
model_config = ConfigDict(
extra="forbid",
@@ -11113,6 +11132,110 @@ class CachedMCPToolFailuresQueryResponse(BaseModel):
)
+class CachedMCPToolNeighborsQueryResponse(BaseModel):
+ model_config = ConfigDict(
+ extra="forbid",
+ )
+ cache_key: str
+ cache_target_age: AwareDatetime | None = None
+ calculation_trigger: str | None = Field(
+ default=None,
+ description=("What triggered the calculation of the query, leave empty if user/immediate"),
+ )
+ error: str | None = Field(
+ default=None,
+ description=(
+ "Query error. Returned only if 'explain' or `modifiers.debug` is true. Throws an error otherwise."
+ ),
+ )
+ hogql: str | None = Field(default=None, description="Generated HogQL query.")
+ is_cached: bool
+ last_refresh: AwareDatetime
+ modifiers: HogQLQueryModifiers | None = Field(default=None, description="Modifiers used when performing the query")
+ next_allowed_client_refresh: AwareDatetime
+ query_metadata: dict[str, Any] | None = None
+ query_status: QueryStatus | None = Field(
+ default=None,
+ description=("Query status indicates whether next to the provided data, a query is still running."),
+ )
+ resolved_compare_date_range: ResolvedDateRangeResponse | None = Field(
+ default=None,
+ description=("The resolved previous/comparison period date range, when comparing against another period"),
+ )
+ resolved_date_range: ResolvedDateRangeResponse | None = Field(
+ default=None, description="The date range used for the query"
+ )
+ results: list[MCPToolNeighborItem]
+ timezone: str
+ timings: list[QueryTiming] | None = Field(
+ default=None,
+ description=("Measured timings for different parts of the query generation process"),
+ )
+ warnings: list[DataWarehouseSyncWarning] | None = Field(
+ default=None,
+ description=(
+ "Warnings about data warehouse sources referenced by the query whose latest"
+ " sync failed, is paused, hit a billing limit, or is otherwise stale."
+ " Results may not reflect current source data. Accumulated across every"
+ " HogQL execution that contributes to this response — so insights backed by"
+ " warehouse tables (Trends, Funnels, etc.) receive the same warnings as raw"
+ " HogQL queries."
+ ),
+ )
+
+
+class CachedMCPToolSampleIntentsQueryResponse(BaseModel):
+ model_config = ConfigDict(
+ extra="forbid",
+ )
+ cache_key: str
+ cache_target_age: AwareDatetime | None = None
+ calculation_trigger: str | None = Field(
+ default=None,
+ description=("What triggered the calculation of the query, leave empty if user/immediate"),
+ )
+ error: str | None = Field(
+ default=None,
+ description=(
+ "Query error. Returned only if 'explain' or `modifiers.debug` is true. Throws an error otherwise."
+ ),
+ )
+ hogql: str | None = Field(default=None, description="Generated HogQL query.")
+ is_cached: bool
+ last_refresh: AwareDatetime
+ modifiers: HogQLQueryModifiers | None = Field(default=None, description="Modifiers used when performing the query")
+ next_allowed_client_refresh: AwareDatetime
+ query_metadata: dict[str, Any] | None = None
+ query_status: QueryStatus | None = Field(
+ default=None,
+ description=("Query status indicates whether next to the provided data, a query is still running."),
+ )
+ resolved_compare_date_range: ResolvedDateRangeResponse | None = Field(
+ default=None,
+ description=("The resolved previous/comparison period date range, when comparing against another period"),
+ )
+ resolved_date_range: ResolvedDateRangeResponse | None = Field(
+ default=None, description="The date range used for the query"
+ )
+ results: list[MCPToolSampleIntentItem]
+ timezone: str
+ timings: list[QueryTiming] | None = Field(
+ default=None,
+ description=("Measured timings for different parts of the query generation process"),
+ )
+ warnings: list[DataWarehouseSyncWarning] | None = Field(
+ default=None,
+ description=(
+ "Warnings about data warehouse sources referenced by the query whose latest"
+ " sync failed, is paused, hit a billing limit, or is otherwise stale."
+ " Results may not reflect current source data. Accumulated across every"
+ " HogQL execution that contributes to this response — so insights backed by"
+ " warehouse tables (Trends, Funnels, etc.) receive the same warnings as raw"
+ " HogQL queries."
+ ),
+ )
+
+
class CachedMCPToolStatsQueryResponse(BaseModel):
model_config = ConfigDict(
extra="forbid",
@@ -16823,6 +16946,88 @@ class MCPToolFailuresQueryResponse(BaseModel):
)
+class MCPToolNeighborsQueryResponse(BaseModel):
+ model_config = ConfigDict(
+ extra="forbid",
+ )
+ error: str | None = Field(
+ default=None,
+ description=(
+ "Query error. Returned only if 'explain' or `modifiers.debug` is true. Throws an error otherwise."
+ ),
+ )
+ hogql: str | None = Field(default=None, description="Generated HogQL query.")
+ modifiers: HogQLQueryModifiers | None = Field(default=None, description="Modifiers used when performing the query")
+ query_status: QueryStatus | None = Field(
+ default=None,
+ description=("Query status indicates whether next to the provided data, a query is still running."),
+ )
+ resolved_compare_date_range: ResolvedDateRangeResponse | None = Field(
+ default=None,
+ description=("The resolved previous/comparison period date range, when comparing against another period"),
+ )
+ resolved_date_range: ResolvedDateRangeResponse | None = Field(
+ default=None, description="The date range used for the query"
+ )
+ results: list[MCPToolNeighborItem]
+ timings: list[QueryTiming] | None = Field(
+ default=None,
+ description=("Measured timings for different parts of the query generation process"),
+ )
+ warnings: list[DataWarehouseSyncWarning] | None = Field(
+ default=None,
+ description=(
+ "Warnings about data warehouse sources referenced by the query whose latest"
+ " sync failed, is paused, hit a billing limit, or is otherwise stale."
+ " Results may not reflect current source data. Accumulated across every"
+ " HogQL execution that contributes to this response — so insights backed by"
+ " warehouse tables (Trends, Funnels, etc.) receive the same warnings as raw"
+ " HogQL queries."
+ ),
+ )
+
+
+class MCPToolSampleIntentsQueryResponse(BaseModel):
+ model_config = ConfigDict(
+ extra="forbid",
+ )
+ error: str | None = Field(
+ default=None,
+ description=(
+ "Query error. Returned only if 'explain' or `modifiers.debug` is true. Throws an error otherwise."
+ ),
+ )
+ hogql: str | None = Field(default=None, description="Generated HogQL query.")
+ modifiers: HogQLQueryModifiers | None = Field(default=None, description="Modifiers used when performing the query")
+ query_status: QueryStatus | None = Field(
+ default=None,
+ description=("Query status indicates whether next to the provided data, a query is still running."),
+ )
+ resolved_compare_date_range: ResolvedDateRangeResponse | None = Field(
+ default=None,
+ description=("The resolved previous/comparison period date range, when comparing against another period"),
+ )
+ resolved_date_range: ResolvedDateRangeResponse | None = Field(
+ default=None, description="The date range used for the query"
+ )
+ results: list[MCPToolSampleIntentItem]
+ timings: list[QueryTiming] | None = Field(
+ default=None,
+ description=("Measured timings for different parts of the query generation process"),
+ )
+ warnings: list[DataWarehouseSyncWarning] | None = Field(
+ default=None,
+ description=(
+ "Warnings about data warehouse sources referenced by the query whose latest"
+ " sync failed, is paused, hit a billing limit, or is otherwise stale."
+ " Results may not reflect current source data. Accumulated across every"
+ " HogQL execution that contributes to this response — so insights backed by"
+ " warehouse tables (Trends, Funnels, etc.) receive the same warnings as raw"
+ " HogQL queries."
+ ),
+ )
+
+
class MCPToolStatsQueryResponse(BaseModel):
model_config = ConfigDict(
extra="forbid",
@@ -20906,6 +21111,88 @@ class QueryResponseAlternative101(BaseModel):
class QueryResponseAlternative102(BaseModel):
+ model_config = ConfigDict(
+ extra="forbid",
+ )
+ error: str | None = Field(
+ default=None,
+ description=(
+ "Query error. Returned only if 'explain' or `modifiers.debug` is true. Throws an error otherwise."
+ ),
+ )
+ hogql: str | None = Field(default=None, description="Generated HogQL query.")
+ modifiers: HogQLQueryModifiers | None = Field(default=None, description="Modifiers used when performing the query")
+ query_status: QueryStatus | None = Field(
+ default=None,
+ description=("Query status indicates whether next to the provided data, a query is still running."),
+ )
+ resolved_compare_date_range: ResolvedDateRangeResponse | None = Field(
+ default=None,
+ description=("The resolved previous/comparison period date range, when comparing against another period"),
+ )
+ resolved_date_range: ResolvedDateRangeResponse | None = Field(
+ default=None, description="The date range used for the query"
+ )
+ results: list[MCPToolSampleIntentItem]
+ timings: list[QueryTiming] | None = Field(
+ default=None,
+ description=("Measured timings for different parts of the query generation process"),
+ )
+ warnings: list[DataWarehouseSyncWarning] | None = Field(
+ default=None,
+ description=(
+ "Warnings about data warehouse sources referenced by the query whose latest"
+ " sync failed, is paused, hit a billing limit, or is otherwise stale."
+ " Results may not reflect current source data. Accumulated across every"
+ " HogQL execution that contributes to this response — so insights backed by"
+ " warehouse tables (Trends, Funnels, etc.) receive the same warnings as raw"
+ " HogQL queries."
+ ),
+ )
+
+
+class QueryResponseAlternative103(BaseModel):
+ model_config = ConfigDict(
+ extra="forbid",
+ )
+ error: str | None = Field(
+ default=None,
+ description=(
+ "Query error. Returned only if 'explain' or `modifiers.debug` is true. Throws an error otherwise."
+ ),
+ )
+ hogql: str | None = Field(default=None, description="Generated HogQL query.")
+ modifiers: HogQLQueryModifiers | None = Field(default=None, description="Modifiers used when performing the query")
+ query_status: QueryStatus | None = Field(
+ default=None,
+ description=("Query status indicates whether next to the provided data, a query is still running."),
+ )
+ resolved_compare_date_range: ResolvedDateRangeResponse | None = Field(
+ default=None,
+ description=("The resolved previous/comparison period date range, when comparing against another period"),
+ )
+ resolved_date_range: ResolvedDateRangeResponse | None = Field(
+ default=None, description="The date range used for the query"
+ )
+ results: list[MCPToolNeighborItem]
+ timings: list[QueryTiming] | None = Field(
+ default=None,
+ description=("Measured timings for different parts of the query generation process"),
+ )
+ warnings: list[DataWarehouseSyncWarning] | None = Field(
+ default=None,
+ description=(
+ "Warnings about data warehouse sources referenced by the query whose latest"
+ " sync failed, is paused, hit a billing limit, or is otherwise stale."
+ " Results may not reflect current source data. Accumulated across every"
+ " HogQL execution that contributes to this response — so insights backed by"
+ " warehouse tables (Trends, Funnels, etc.) receive the same warnings as raw"
+ " HogQL queries."
+ ),
+ )
+
+
+class QueryResponseAlternative104(BaseModel):
model_config = ConfigDict(
extra="forbid",
)
@@ -23313,6 +23600,42 @@ class MCPToolFailuresQuery(BaseModel):
version: float | None = Field(default=None, description="version of the node, used for schema migrations")
+class MCPToolNeighborsQuery(BaseModel):
+ model_config = ConfigDict(
+ extra="forbid",
+ )
+ dateRange: DateRange | 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."),
+ )
+ response: MCPToolNeighborsQueryResponse | None = None
+ tags: QueryLogTags | None = None
+ toolName: str = Field(
+ ...,
+ description=("The effective tool name to scope to (matched against the single-exec-resolved tool name)."),
+ )
+ version: float | None = Field(default=None, description="version of the node, used for schema migrations")
+
+
+class MCPToolSampleIntentsQuery(BaseModel):
+ model_config = ConfigDict(
+ extra="forbid",
+ )
+ dateRange: DateRange | None = None
+ kind: Literal["MCPToolSampleIntentsQuery"] = "MCPToolSampleIntentsQuery"
+ modifiers: HogQLQueryModifiers | None = Field(default=None, description="Modifiers used when performing the query")
+ response: MCPToolSampleIntentsQueryResponse | None = None
+ tags: QueryLogTags | None = None
+ toolName: str = Field(
+ ...,
+ description=("The effective tool name to scope to (matched against the single-exec-resolved tool name)."),
+ )
+ version: float | None = Field(default=None, description="version of the node, used for schema migrations")
+
+
class MCPToolStatsQuery(BaseModel):
model_config = ConfigDict(
extra="forbid",
@@ -25990,6 +26313,8 @@ class QueryResponseAlternative(
| QueryResponseAlternative100
| QueryResponseAlternative101
| QueryResponseAlternative102
+ | QueryResponseAlternative103
+ | QueryResponseAlternative104
]
):
root: (
@@ -26091,6 +26416,8 @@ class QueryResponseAlternative(
| QueryResponseAlternative100
| QueryResponseAlternative101
| QueryResponseAlternative102
+ | QueryResponseAlternative103
+ | QueryResponseAlternative104
)
@@ -27141,6 +27468,8 @@ class HogQLAutocomplete(BaseModel):
| MCPToolStatsQuery
| MCPToolDailyStatsQuery
| MCPToolDescriptionsQuery
+ | MCPToolSampleIntentsQuery
+ | MCPToolNeighborsQuery
| None
) = Field(default=None, description="Query in whose context to validate.")
startPosition: int = Field(..., description="Start position of the editor word")
@@ -27236,6 +27565,8 @@ class HogQLMetadata(BaseModel):
| MCPToolStatsQuery
| MCPToolDailyStatsQuery
| MCPToolDescriptionsQuery
+ | MCPToolSampleIntentsQuery
+ | MCPToolNeighborsQuery
| None
) = Field(
default=None,
@@ -27366,6 +27697,8 @@ class MaxInsightContext(BaseModel):
| MCPToolStatsQuery
| MCPToolDailyStatsQuery
| MCPToolDescriptionsQuery
+ | MCPToolSampleIntentsQuery
+ | MCPToolNeighborsQuery
| PropertyValuesQuery
) = Field(..., discriminator="kind")
type: Literal["insight"] = "insight"
@@ -27493,6 +27826,8 @@ class QueryRequest(BaseModel):
| MCPToolStatsQuery
| MCPToolDailyStatsQuery
| MCPToolDescriptionsQuery
+ | MCPToolSampleIntentsQuery
+ | MCPToolNeighborsQuery
| PropertyValuesQuery
) = Field(
...,
@@ -27612,6 +27947,8 @@ class QuerySchemaRoot(
| MCPToolStatsQuery
| MCPToolDailyStatsQuery
| MCPToolDescriptionsQuery
+ | MCPToolSampleIntentsQuery
+ | MCPToolNeighborsQuery
| PropertyValuesQuery
]
):
@@ -27701,6 +28038,8 @@ class QuerySchemaRoot(
| MCPToolStatsQuery
| MCPToolDailyStatsQuery
| MCPToolDescriptionsQuery
+ | MCPToolSampleIntentsQuery
+ | MCPToolNeighborsQuery
| PropertyValuesQuery
) = Field(..., discriminator="kind")
@@ -27795,6 +28134,8 @@ class QueryUpgradeRequest(BaseModel):
| MCPToolStatsQuery
| MCPToolDailyStatsQuery
| MCPToolDescriptionsQuery
+ | MCPToolSampleIntentsQuery
+ | MCPToolNeighborsQuery
| PropertyValuesQuery
) = Field(..., discriminator="kind")
@@ -27889,6 +28230,8 @@ class QueryUpgradeResponse(BaseModel):
| MCPToolStatsQuery
| MCPToolDailyStatsQuery
| MCPToolDescriptionsQuery
+ | MCPToolSampleIntentsQuery
+ | MCPToolNeighborsQuery
| PropertyValuesQuery
) = Field(..., discriminator="kind")
@@ -28160,6 +28503,8 @@ class VisualizationArtifactContent(BaseModel):
| MCPToolStatsQuery
| MCPToolDailyStatsQuery
| MCPToolDescriptionsQuery
+ | MCPToolSampleIntentsQuery
+ | MCPToolNeighborsQuery
| PropertyValuesQuery
)
diff --git a/posthog/schema_enums.py b/posthog/schema_enums.py
index 9552369fed6e..bbce3709c5ca 100644
--- a/posthog/schema_enums.py
+++ b/posthog/schema_enums.py
@@ -2298,6 +2298,11 @@ class LogsSparklineBreakdownBy(StrEnum):
SERVICE = "service"
+class NeighborDirection(StrEnum):
+ BEFORE = "before"
+ AFTER = "after"
+
+
class MarketingAnalyticsBaseColumns(StrEnum):
ID = "ID"
CAMPAIGN = "Campaign"
@@ -2571,6 +2576,8 @@ class NodeKind(StrEnum):
MCP_TOOL_STATS_QUERY = "MCPToolStatsQuery"
MCP_TOOL_DAILY_STATS_QUERY = "MCPToolDailyStatsQuery"
MCP_TOOL_DESCRIPTIONS_QUERY = "MCPToolDescriptionsQuery"
+ MCP_TOOL_SAMPLE_INTENTS_QUERY = "MCPToolSampleIntentsQuery"
+ MCP_TOOL_NEIGHBORS_QUERY = "MCPToolNeighborsQuery"
PROPERTY_VALUES_QUERY = "PropertyValuesQuery"
diff --git a/products/mcp_analytics/backend/facade/queries.py b/products/mcp_analytics/backend/facade/queries.py
index 44bf395be395..b9ad278b1270 100644
--- a/products/mcp_analytics/backend/facade/queries.py
+++ b/products/mcp_analytics/backend/facade/queries.py
@@ -10,6 +10,8 @@ from products.mcp_analytics.backend.hogql_queries.tool_tables import (
MCPToolDailyStatsQueryRunner,
MCPToolDescriptionsQueryRunner,
MCPToolFailuresQueryRunner,
+ MCPToolNeighborsQueryRunner,
+ MCPToolSampleIntentsQueryRunner,
MCPToolStatsQueryRunner,
MCPToolTopUsersQueryRunner,
)
@@ -19,6 +21,8 @@ __all__ = [
"MCPToolDailyStatsQueryRunner",
"MCPToolDescriptionsQueryRunner",
"MCPToolFailuresQueryRunner",
+ "MCPToolNeighborsQueryRunner",
+ "MCPToolSampleIntentsQueryRunner",
"MCPToolStatsQueryRunner",
"MCPToolTopUsersQueryRunner",
]
diff --git a/products/mcp_analytics/backend/hogql_queries/tool_tables.py b/products/mcp_analytics/backend/hogql_queries/tool_tables.py
index 5c3ca1507db7..035fff4e2af6 100644
--- a/products/mcp_analytics/backend/hogql_queries/tool_tables.py
+++ b/products/mcp_analytics/backend/hogql_queries/tool_tables.py
@@ -13,6 +13,8 @@ from posthog.schema import (
CachedMCPToolDailyStatsQueryResponse,
CachedMCPToolDescriptionsQueryResponse,
CachedMCPToolFailuresQueryResponse,
+ CachedMCPToolNeighborsQueryResponse,
+ CachedMCPToolSampleIntentsQueryResponse,
CachedMCPToolStatsQueryResponse,
CachedMCPToolTopUsersQueryResponse,
MCPToolDailyStatItem,
@@ -24,12 +26,19 @@ from posthog.schema import (
MCPToolFailureItem,
MCPToolFailuresQuery,
MCPToolFailuresQueryResponse,
+ MCPToolNeighborItem,
+ MCPToolNeighborsQuery,
+ MCPToolNeighborsQueryResponse,
+ MCPToolSampleIntentItem,
+ MCPToolSampleIntentsQuery,
+ MCPToolSampleIntentsQueryResponse,
MCPToolStatsItem,
MCPToolStatsQuery,
MCPToolStatsQueryResponse,
MCPToolTopUserItem,
MCPToolTopUsersQuery,
MCPToolTopUsersQueryResponse,
+ NeighborDirection,
)
from posthog.hogql import ast
@@ -483,3 +492,185 @@ class MCPToolDescriptionsQueryRunner(AnalyticsQueryRunner[MCPToolDescriptionsQue
hogql=response.hogql,
modifiers=self.modifiers,
)
+
+
+class MCPToolSampleIntentsQueryRunner(AnalyticsQueryRunner[MCPToolSampleIntentsQueryResponse]):
+ query: MCPToolSampleIntentsQuery
+ cached_response: CachedMCPToolSampleIntentsQueryResponse
+
+ def validate_query_runner_access(self, user: "User") -> bool:
+ return validate_mcp_analytics_access(self.team, user)
+
+ @cached_property
+ def query_date_range(self) -> QueryDateRange:
+ return mcp_query_date_range(self.team, self.query.dateRange)
+
+ def to_query(self) -> ast.SelectQuery | ast.SelectSetQuery:
+ where = _tool_call_where(
+ self.query.toolName,
+ self.query_date_range,
+ extra=[
+ parse_expr("notEmpty(toString(properties.$mcp_intent))"),
+ parse_expr("toString(properties.$mcp_intent) != '{}'"),
+ ],
+ )
+ return parse_select(
+ """
+ SELECT
+ toString(timestamp) AS timestamp,
+ intent,
+ intent_source,
+ {harness_label} AS harness
+ FROM (
+ SELECT
+ timestamp,
+ toString(properties.$mcp_intent) AS intent,
+ toString(properties.$mcp_intent_source) AS intent_source,
+ {token} AS h
+ FROM events
+ WHERE {where}
+ )
+ ORDER BY timestamp DESC
+ LIMIT 5
+ """,
+ placeholders={
+ "harness_label": parse_expr(mcp_harness.harness_label_sql("h")),
+ "token": parse_expr(mcp_harness.HARNESS_TOKEN_SQL),
+ "where": where,
+ },
+ )
+
+ def _calculate(self) -> MCPToolSampleIntentsQueryResponse:
+ with tags_context(
+ product=Product.MCP_ANALYTICS,
+ feature=Feature.QUERY,
+ team_id=self.team.id,
+ name="mcp_tool_sample_intents_query",
+ ):
+ response = execute_hogql_query(
+ query=self.to_query(),
+ team=self.team,
+ query_type="mcp_tool_sample_intents_query",
+ timings=self.timings,
+ modifiers=self.modifiers,
+ limit_context=self.limit_context,
+ )
+
+ results = [
+ MCPToolSampleIntentItem(
+ timestamp=str(row[0] or ""),
+ intent=str(row[1] or ""),
+ intent_source=str(row[2] or ""),
+ harness=str(row[3] or ""),
+ )
+ for row in (response.results or [])
+ ]
+ return MCPToolSampleIntentsQueryResponse(
+ results=results,
+ timings=response.timings,
+ hogql=response.hogql,
+ modifiers=self.modifiers,
+ )
+
+
+_WINDOW_FN: dict[NeighborDirection, str] = {
+ NeighborDirection.BEFORE: "lagInFrame",
+ NeighborDirection.AFTER: "leadInFrame",
+}
+
+
+class MCPToolNeighborsQueryRunner(AnalyticsQueryRunner[MCPToolNeighborsQueryResponse]):
+ query: MCPToolNeighborsQuery
+ cached_response: CachedMCPToolNeighborsQueryResponse
+
+ def validate_query_runner_access(self, user: "User") -> bool:
+ return validate_mcp_analytics_access(self.team, user)
+
+ @cached_property
+ def query_date_range(self) -> QueryDateRange:
+ return mcp_query_date_range(self.team, self.query.dateRange)
+
+ def to_query(self) -> ast.SelectQuery | ast.SelectSetQuery:
+ # The CTE collects every tool call in qualifying conversations (not just the target
+ # tool) so the window function can see each call's neighbour; the target tool is
+ # selected in the outer WHERE. window_fn is chosen from a fixed map, never input.
+ window_fn = _WINDOW_FN[self.query.neighborDirection]
+ # Built from a fixed function name + hardcoded window, never user input; passed to
+ # parse_expr as a variable (not a literal f-string) so hogql-fstring-audit stays clean.
+ neighbor_expr = (
+ f"{window_fn}(tool) OVER ("
+ "PARTITION BY conv_id ORDER BY timestamp "
+ "ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)"
+ )
+ cte_where = ast.And(
+ exprs=[
+ parse_expr("event = {event}", placeholders={"event": ast.Constant(value=MCP_TOOL_CALL_EVENT)}),
+ parse_expr(
+ "timestamp >= {date_from}", placeholders={"date_from": self.query_date_range.date_from_as_hogql()}
+ ),
+ parse_expr(
+ "timestamp <= {date_to}", placeholders={"date_to": self.query_date_range.date_to_as_hogql()}
+ ),
+ parse_expr(
+ "properties.$mcp_source = {source}", placeholders={"source": ast.Constant(value=_NEW_SDK_SOURCE)}
+ ),
+ parse_expr("notEmpty({conv_id})", placeholders={"conv_id": parse_expr(_CONVERSATION_ID)}),
+ ]
+ )
+ return parse_select(
+ """
+ WITH tool_calls AS (
+ SELECT
+ {_CONVERSATION_ID} AS conv_id,
+ timestamp,
+ {_EFFECTIVE_TOOL} AS tool
+ FROM events
+ WHERE {cte_where}
+ )
+ SELECT neighbor_tool, count() AS co_occurrences
+ FROM (
+ SELECT
+ tool,
+ {neighbor_expr} AS neighbor_tool
+ FROM tool_calls
+ )
+ WHERE tool = {tool} AND neighbor_tool IS NOT NULL AND neighbor_tool != '' AND neighbor_tool != tool
+ GROUP BY neighbor_tool
+ ORDER BY co_occurrences DESC
+ LIMIT 5
+ """,
+ placeholders={
+ "_CONVERSATION_ID": parse_expr(_CONVERSATION_ID),
+ "_EFFECTIVE_TOOL": parse_expr(_EFFECTIVE_TOOL),
+ "neighbor_expr": parse_expr(neighbor_expr),
+ "cte_where": cte_where,
+ "tool": ast.Constant(value=self.query.toolName),
+ },
+ )
+
+ def _calculate(self) -> MCPToolNeighborsQueryResponse:
+ with tags_context(
+ product=Product.MCP_ANALYTICS,
+ feature=Feature.QUERY,
+ team_id=self.team.id,
+ name="mcp_tool_neighbors_query",
+ ):
+ response = execute_hogql_query(
+ query=self.to_query(),
+ team=self.team,
+ query_type="mcp_tool_neighbors_query",
+ timings=self.timings,
+ modifiers=self.modifiers,
+ limit_context=self.limit_context,
+ )
+
+ results = [
+ MCPToolNeighborItem(neighbor_tool=str(row[0] or ""), co_occurrences=int(row[1] or 0))
+ for row in (response.results or [])
+ ]
+ return MCPToolNeighborsQueryResponse(
+ results=results,
+ timings=response.timings,
+ hogql=response.hogql,
+ modifiers=self.modifiers,
+ )
diff --git a/products/mcp_analytics/backend/tests/test_tool_tables.py b/products/mcp_analytics/backend/tests/test_tool_tables.py
index e85be9ff09df..9949685ab034 100644
--- a/products/mcp_analytics/backend/tests/test_tool_tables.py
+++ b/products/mcp_analytics/backend/tests/test_tool_tables.py
@@ -10,14 +10,19 @@ from posthog.schema import (
MCPToolDailyStatsQuery,
MCPToolDescriptionsQuery,
MCPToolFailuresQuery,
+ MCPToolNeighborsQuery,
+ MCPToolSampleIntentsQuery,
MCPToolStatsQuery,
MCPToolTopUsersQuery,
+ NeighborDirection,
)
from products.mcp_analytics.backend.hogql_queries.tool_tables import (
MCPToolDailyStatsQueryRunner,
MCPToolDescriptionsQueryRunner,
MCPToolFailuresQueryRunner,
+ MCPToolNeighborsQueryRunner,
+ MCPToolSampleIntentsQueryRunner,
MCPToolStatsQueryRunner,
MCPToolTopUsersQueryRunner,
)
@@ -206,7 +211,9 @@ def _emit_tool_call(
is_error: bool = False,
duration_ms: float | None = None,
intent: str | None = None,
+ intent_source: str | None = None,
description: str | None = None,
+ client_name: str | None = None,
session_id: str | None = None,
exec_tool: str | None = None,
timestamp: datetime | None = None,
@@ -218,8 +225,12 @@ def _emit_tool_call(
properties["$mcp_duration_ms"] = duration_ms
if intent is not None:
properties["$mcp_intent"] = intent
+ if intent_source is not None:
+ properties["$mcp_intent_source"] = intent_source
if description is not None:
properties["$mcp_tool_description"] = description
+ if client_name is not None:
+ properties["$mcp_client_name"] = client_name
if session_id is not None:
properties["$mcp_session_id"] = session_id
if exec_tool is not None:
@@ -322,3 +333,69 @@ class TestMCPToolDescriptionsQueryRunner(_MCPAnalyticsTeamScopedTestMixin, Click
rows = self._run()
assert [r.description for r in rows] == ["real"]
+
+
+class TestMCPToolSampleIntentsQueryRunner(_MCPAnalyticsTeamScopedTestMixin, ClickhouseTestMixin, APIBaseTest):
+ def _run(self, tool_name: str = "query_run") -> list[Any]:
+ runner = MCPToolSampleIntentsQueryRunner(
+ query=MCPToolSampleIntentsQuery(toolName=tool_name, dateRange=DateRange(date_from="-7d")),
+ team=self.team,
+ )
+ return runner.calculate().results
+
+ def test_resolves_harness_label_and_carries_source(self) -> None:
+ _emit_tool_call(
+ self.team, intent='{"goal":"x"}', intent_source="llm", client_name="claude-ai (via mcp-remote 0.1.37)"
+ )
+ flush_persons_and_events()
+
+ rows = self._run()
+
+ assert len(rows) == 1
+ assert rows[0].harness == "Claude.ai"
+ assert rows[0].intent_source == "llm"
+ # intent round-trips through ClickHouse JSON storage (re-serialized), so assert content not bytes.
+ assert "goal" in rows[0].intent
+
+ def test_excludes_empty_or_blank_intent(self) -> None:
+ _emit_tool_call(self.team, distinct_id="d1", intent="", client_name="claude-ai")
+ _emit_tool_call(self.team, distinct_id="d2", intent="{}", client_name="claude-ai")
+ _emit_tool_call(self.team, distinct_id="d3", intent='{"goal":"y"}', client_name="claude-ai")
+ flush_persons_and_events()
+
+ rows = self._run()
+
+ assert len(rows) == 1
+ assert "goal" in rows[0].intent
+
+
+class TestMCPToolNeighborsQueryRunner(_MCPAnalyticsTeamScopedTestMixin, ClickhouseTestMixin, APIBaseTest):
+ def _run(self, direction: NeighborDirection, tool_name: str = "query_run") -> list[Any]:
+ runner = MCPToolNeighborsQueryRunner(
+ query=MCPToolNeighborsQuery(
+ toolName=tool_name, neighborDirection=direction, dateRange=DateRange(date_from="-7d")
+ ),
+ team=self.team,
+ )
+ return runner.calculate().results
+
+ @parameterized.expand(
+ [
+ ("before", NeighborDirection.BEFORE, "tool_a"),
+ ("after", NeighborDirection.AFTER, "tool_b"),
+ ]
+ )
+ def test_finds_adjacent_tool_in_conversation(
+ self, _name: str, direction: NeighborDirection, expected_neighbor: str
+ ) -> None:
+ now = datetime.now(tz=UTC)
+ _emit_tool_call(self.team, tool_name="tool_a", session_id="conv1", timestamp=now - timedelta(minutes=2))
+ _emit_tool_call(self.team, tool_name="query_run", session_id="conv1", timestamp=now - timedelta(minutes=1))
+ _emit_tool_call(self.team, tool_name="tool_b", session_id="conv1", timestamp=now)
+ flush_persons_and_events()
+
+ rows = self._run(direction)
+
+ assert len(rows) == 1
+ assert rows[0].neighbor_tool == expected_neighbor
+ assert rows[0].co_occurrences == 1
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 405bc36c4df7..77c0cae73f6b 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -26716,6 +26716,96 @@ export namespace Schemas {
version?: number | null;
}
+ export interface MCPToolSampleIntentItem {
+ /** Resolved harness label for the call. */
+ harness: string;
+ /** JSON-encoded intent payload as reported by the client. */
+ intent: string;
+ intent_source: string;
+ timestamp: string;
+ }
+
+ export interface MCPToolSampleIntentsQueryResponse {
+ /** Query error. Returned only if 'explain' or `modifiers.debug` is true. Throws an error otherwise. */
+ error?: string | null;
+ /** Generated HogQL query. */
+ hogql?: string | null;
+ /** Modifiers used when performing the query */
+ modifiers?: HogQLQueryModifiers | null;
+ /** Query status indicates whether next to the provided data, a query is still running. */
+ query_status?: QueryStatus | null;
+ /** The resolved previous/comparison period date range, when comparing against another period */
+ resolved_compare_date_range?: ResolvedDateRangeResponse | null;
+ /** The date range used for the query */
+ resolved_date_range?: ResolvedDateRangeResponse | null;
+ results: MCPToolSampleIntentItem[];
+ /** Measured timings for different parts of the query generation process */
+ timings?: QueryTiming[] | null;
+ /** Warnings about data warehouse sources referenced by the query whose latest sync failed, is paused, hit a billing limit, or is otherwise stale. Results may not reflect current source data. Accumulated across every HogQL execution that contributes to this response — so insights backed by warehouse tables (Trends, Funnels, etc.) receive the same warnings as raw HogQL queries. */
+ warnings?: DataWarehouseSyncWarning[] | null;
+ }
+
+ export interface MCPToolSampleIntentsQuery {
+ dateRange?: DateRange | null;
+ kind?: 'MCPToolSampleIntentsQuery';
+ /** Modifiers used when performing the query */
+ modifiers?: HogQLQueryModifiers | null;
+ response?: MCPToolSampleIntentsQueryResponse | null;
+ tags?: QueryLogTags | null;
+ /** The effective tool name to scope to (matched against the single-exec-resolved tool name). */
+ toolName: string;
+ /** version of the node, used for schema migrations */
+ version?: number | null;
+ }
+
+ export type NeighborDirection = typeof NeighborDirection[keyof typeof NeighborDirection];
+
+
+ export const NeighborDirection = {
+ Before: 'before',
+ After: 'after',
+ } as const;
+
+ export interface MCPToolNeighborItem {
+ co_occurrences: number;
+ neighbor_tool: string;
+ }
+
+ export interface MCPToolNeighborsQueryResponse {
+ /** Query error. Returned only if 'explain' or `modifiers.debug` is true. Throws an error otherwise. */
+ error?: string | null;
+ /** Generated HogQL query. */
+ hogql?: string | null;
+ /** Modifiers used when performing the query */
+ modifiers?: HogQLQueryModifiers | null;
+ /** Query status indicates whether next to the provided data, a query is still running. */
+ query_status?: QueryStatus | null;
+ /** The resolved previous/comparison period date range, when comparing against another period */
+ resolved_compare_date_range?: ResolvedDateRangeResponse | null;
+ /** The date range used for the query */
+ resolved_date_range?: ResolvedDateRangeResponse | null;
+ results: MCPToolNeighborItem[];
+ /** Measured timings for different parts of the query generation process */
+ timings?: QueryTiming[] | null;
+ /** Warnings about data warehouse sources referenced by the query whose latest sync failed, is paused, hit a billing limit, or is otherwise stale. Results may not reflect current source data. Accumulated across every HogQL execution that contributes to this response — so insights backed by warehouse tables (Trends, Funnels, etc.) receive the same warnings as raw HogQL queries. */
+ warnings?: DataWarehouseSyncWarning[] | null;
+ }
+
+ export interface MCPToolNeighborsQuery {
+ dateRange?: DateRange | 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;
+ response?: MCPToolNeighborsQueryResponse | null;
+ tags?: QueryLogTags | null;
+ /** The effective tool name to scope to (matched against the single-exec-resolved tool name). */
+ toolName: string;
+ /** version of the node, used for schema migrations */
+ version?: number | null;
+ }
+
/**
* Extra globals for the query
*/
@@ -26744,7 +26834,7 @@ export namespace Schemas {
query: string;
response?: HogQLMetadataResponse | null;
/** Query within which "expr" and "template" are validated. Defaults to "select * from events" */
- sourceQuery?: EventsNode | ActionsNode | PersonsNode | EventsQuery | SessionsQuery | ActorsQuery | GroupsQuery | InsightActorsQuery | InsightActorsQueryOptions | SessionsTimelineQuery | HogQuery | HogQLQuery | HogQLMetadata | HogQLAutocomplete | RevenueAnalyticsGrossRevenueQuery | RevenueAnalyticsMetricsQuery | RevenueAnalyticsMRRQuery | RevenueAnalyticsOverviewQuery | RevenueAnalyticsTopCustomersQuery | MarketingAnalyticsTableQuery | MarketingAnalyticsAggregatedQuery | NonIntegratedConversionsTableQuery | WebOverviewQuery | WebStatsTableQuery | WebExternalClicksTableQuery | WebGoalsQuery | WebVitalsQuery | WebVitalsPathBreakdownQuery | WebPageURLSearchQuery | WebAnalyticsExternalSummaryQuery | WebNotableChangesQuery | SessionAttributionExplorerQuery | RevenueExampleEventsQuery | RevenueExampleDataWarehouseTablesQuery | ErrorTrackingQuery | ErrorTrackingSimilarIssuesQuery | ErrorTrackingBreakdownsQuery | ErrorTrackingIssueCorrelationQuery | LogsQuery | LogAttributesQuery | LogValuesQuery | TraceSpansQuery | TraceSpansAggregationQuery | TraceSpansTreeQuery | TraceSpansAttributeBreakdownQuery | ExperimentFunnelsQuery | ExperimentTrendsQuery | CalendarHeatmapQuery | RecordingsQuery | TracesQuery | TraceQuery | TraceNeighborsQuery | VectorSearchQuery | UsageMetricsQuery | AccountsQuery | EndpointsUsageOverviewQuery | EndpointsUsageTableQuery | EndpointsUsageTrendsQuery | MCPHarnessBreakdownQuery | MCPToolTopUsersQuery | MCPToolFailuresQuery | MCPToolStatsQuery | MCPToolDailyStatsQuery | MCPToolDescriptionsQuery | null;
+ sourceQuery?: EventsNode | ActionsNode | PersonsNode | EventsQuery | SessionsQuery | ActorsQuery | GroupsQuery | InsightActorsQuery | InsightActorsQueryOptions | SessionsTimelineQuery | HogQuery | HogQLQuery | HogQLMetadata | HogQLAutocomplete | RevenueAnalyticsGrossRevenueQuery | RevenueAnalyticsMetricsQuery | RevenueAnalyticsMRRQuery | RevenueAnalyticsOverviewQuery | RevenueAnalyticsTopCustomersQuery | MarketingAnalyticsTableQuery | MarketingAnalyticsAggregatedQuery | NonIntegratedConversionsTableQuery | WebOverviewQuery | WebStatsTableQuery | WebExternalClicksTableQuery | WebGoalsQuery | WebVitalsQuery | WebVitalsPathBreakdownQuery | WebPageURLSearchQuery | WebAnalyticsExternalSummaryQuery | WebNotableChangesQuery | SessionAttributionExplorerQuery | RevenueExampleEventsQuery | RevenueExampleDataWarehouseTablesQuery | ErrorTrackingQuery | ErrorTrackingSimilarIssuesQuery | ErrorTrackingBreakdownsQuery | ErrorTrackingIssueCorrelationQuery | LogsQuery | LogAttributesQuery | LogValuesQuery | TraceSpansQuery | TraceSpansAggregationQuery | TraceSpansTreeQuery | TraceSpansAttributeBreakdownQuery | ExperimentFunnelsQuery | ExperimentTrendsQuery | CalendarHeatmapQuery | RecordingsQuery | TracesQuery | TraceQuery | TraceNeighborsQuery | VectorSearchQuery | UsageMetricsQuery | AccountsQuery | EndpointsUsageOverviewQuery | EndpointsUsageTableQuery | EndpointsUsageTrendsQuery | MCPHarnessBreakdownQuery | MCPToolTopUsersQuery | MCPToolFailuresQuery | MCPToolStatsQuery | MCPToolDailyStatsQuery | MCPToolDescriptionsQuery | MCPToolSampleIntentsQuery | MCPToolNeighborsQuery | null;
tags?: QueryLogTags | null;
/** Variables to be subsituted into the query */
variables?: HogQLMetadataVariables;
@@ -26770,7 +26860,7 @@ export namespace Schemas {
query: string;
response?: HogQLAutocompleteResponse | null;
/** Query in whose context to validate. */
- sourceQuery?: EventsNode | ActionsNode | PersonsNode | EventsQuery | SessionsQuery | ActorsQuery | GroupsQuery | InsightActorsQuery | InsightActorsQueryOptions | SessionsTimelineQuery | HogQuery | HogQLQuery | HogQLMetadata | HogQLAutocomplete | RevenueAnalyticsGrossRevenueQuery | RevenueAnalyticsMetricsQuery | RevenueAnalyticsMRRQuery | RevenueAnalyticsOverviewQuery | RevenueAnalyticsTopCustomersQuery | MarketingAnalyticsTableQuery | MarketingAnalyticsAggregatedQuery | NonIntegratedConversionsTableQuery | WebOverviewQuery | WebStatsTableQuery | WebExternalClicksTableQuery | WebGoalsQuery | WebVitalsQuery | WebVitalsPathBreakdownQuery | WebPageURLSearchQuery | WebAnalyticsExternalSummaryQuery | WebNotableChangesQuery | SessionAttributionExplorerQuery | RevenueExampleEventsQuery | RevenueExampleDataWarehouseTablesQuery | ErrorTrackingQuery | ErrorTrackingSimilarIssuesQuery | ErrorTrackingBreakdownsQuery | ErrorTrackingIssueCorrelationQuery | LogsQuery | LogAttributesQuery | LogValuesQuery | TraceSpansQuery | TraceSpansAggregationQuery | TraceSpansTreeQuery | TraceSpansAttributeBreakdownQuery | ExperimentFunnelsQuery | ExperimentTrendsQuery | CalendarHeatmapQuery | RecordingsQuery | TracesQuery | TraceQuery | TraceNeighborsQuery | VectorSearchQuery | UsageMetricsQuery | AccountsQuery | EndpointsUsageOverviewQuery | EndpointsUsageTableQuery | EndpointsUsageTrendsQuery | MCPHarnessBreakdownQuery | MCPToolTopUsersQuery | MCPToolFailuresQuery | MCPToolStatsQuery | MCPToolDailyStatsQuery | MCPToolDescriptionsQuery | null;
+ sourceQuery?: EventsNode | ActionsNode | PersonsNode | EventsQuery | SessionsQuery | ActorsQuery | GroupsQuery | InsightActorsQuery | InsightActorsQueryOptions | SessionsTimelineQuery | HogQuery | HogQLQuery | HogQLMetadata | HogQLAutocomplete | RevenueAnalyticsGrossRevenueQuery | RevenueAnalyticsMetricsQuery | RevenueAnalyticsMRRQuery | RevenueAnalyticsOverviewQuery | RevenueAnalyticsTopCustomersQuery | MarketingAnalyticsTableQuery | MarketingAnalyticsAggregatedQuery | NonIntegratedConversionsTableQuery | WebOverviewQuery | WebStatsTableQuery | WebExternalClicksTableQuery | WebGoalsQuery | WebVitalsQuery | WebVitalsPathBreakdownQuery | WebPageURLSearchQuery | WebAnalyticsExternalSummaryQuery | WebNotableChangesQuery | SessionAttributionExplorerQuery | RevenueExampleEventsQuery | RevenueExampleDataWarehouseTablesQuery | ErrorTrackingQuery | ErrorTrackingSimilarIssuesQuery | ErrorTrackingBreakdownsQuery | ErrorTrackingIssueCorrelationQuery | LogsQuery | LogAttributesQuery | LogValuesQuery | TraceSpansQuery | TraceSpansAggregationQuery | TraceSpansTreeQuery | TraceSpansAttributeBreakdownQuery | ExperimentFunnelsQuery | ExperimentTrendsQuery | CalendarHeatmapQuery | RecordingsQuery | TracesQuery | TraceQuery | TraceNeighborsQuery | VectorSearchQuery | UsageMetricsQuery | AccountsQuery | EndpointsUsageOverviewQuery | EndpointsUsageTableQuery | EndpointsUsageTrendsQuery | MCPHarnessBreakdownQuery | MCPToolTopUsersQuery | MCPToolFailuresQuery | MCPToolStatsQuery | MCPToolDailyStatsQuery | MCPToolDescriptionsQuery | MCPToolSampleIntentsQuery | MCPToolNeighborsQuery | null;
/** Start position of the editor word */
startPosition: number;
tags?: QueryLogTags | null;
@@ -44290,7 +44380,7 @@ export namespace Schemas {
* ```
*
* For more details on HogQL queries, see the [PostHog HogQL documentation](/docs/hogql#api-access). */
- query: EventsNode | ActionsNode | PersonsNode | DataWarehouseNode | FunnelsDataWarehouseNode | LifecycleDataWarehouseNode | EventsQuery | SessionsQuery | ActorsQuery | GroupsQuery | InsightActorsQuery | InsightActorsQueryOptions | SessionsTimelineQuery | HogQuery | HogQLQuery | HogQLMetadata | HogQLAutocomplete | SessionAttributionExplorerQuery | RevenueExampleEventsQuery | RevenueExampleDataWarehouseTablesQuery | ErrorTrackingQuery | ErrorTrackingSimilarIssuesQuery | ErrorTrackingBreakdownsQuery | ErrorTrackingIssueCorrelationQuery | ExperimentFunnelsQuery | ExperimentTrendsQuery | ExperimentQuery | ExperimentExposureQuery | DocumentSimilarityQuery | WebOverviewQuery | WebStatsTableQuery | WebExternalClicksTableQuery | WebGoalsQuery | WebVitalsQuery | WebVitalsPathBreakdownQuery | WebPageURLSearchQuery | WebAnalyticsExternalSummaryQuery | WebNotableChangesQuery | RevenueAnalyticsGrossRevenueQuery | RevenueAnalyticsMetricsQuery | RevenueAnalyticsMRRQuery | RevenueAnalyticsOverviewQuery | RevenueAnalyticsTopCustomersQuery | MarketingAnalyticsTableQuery | MarketingAnalyticsAggregatedQuery | NonIntegratedConversionsTableQuery | DataVisualizationNode | DataTableNode | SavedInsightNode | InsightVizNode | TrendsQuery | FunnelsQuery | RetentionQuery | PathsQuery | StickinessQuery | LifecycleQuery | FunnelCorrelationQuery | DatabaseSchemaQuery | RecordingsQuery | LogsQuery | LogAttributesQuery | LogValuesQuery | TraceSpansQuery | TraceSpansAggregationQuery | TraceSpansTreeQuery | TraceSpansAttributeBreakdownQuery | SuggestedQuestionsQuery | TeamTaxonomyQuery | EventTaxonomyQuery | ActorsPropertyTaxonomyQuery | TracesQuery | TraceQuery | TraceNeighborsQuery | VectorSearchQuery | UsageMetricsQuery | AccountsQuery | EndpointsUsageOverviewQuery | EndpointsUsageTableQuery | EndpointsUsageTrendsQuery | MCPHarnessBreakdownQuery | MCPToolTopUsersQuery | MCPToolFailuresQuery | MCPToolStatsQuery | MCPToolDailyStatsQuery | MCPToolDescriptionsQuery | PropertyValuesQuery;
+ query: EventsNode | ActionsNode | PersonsNode | DataWarehouseNode | FunnelsDataWarehouseNode | LifecycleDataWarehouseNode | EventsQuery | SessionsQuery | ActorsQuery | GroupsQuery | InsightActorsQuery | InsightActorsQueryOptions | SessionsTimelineQuery | HogQuery | HogQLQuery | HogQLMetadata | HogQLAutocomplete | SessionAttributionExplorerQuery | RevenueExampleEventsQuery | RevenueExampleDataWarehouseTablesQuery | ErrorTrackingQuery | ErrorTrackingSimilarIssuesQuery | ErrorTrackingBreakdownsQuery | ErrorTrackingIssueCorrelationQuery | ExperimentFunnelsQuery | ExperimentTrendsQuery | ExperimentQuery | ExperimentExposureQuery | DocumentSimilarityQuery | WebOverviewQuery | WebStatsTableQuery | WebExternalClicksTableQuery | WebGoalsQuery | WebVitalsQuery | WebVitalsPathBreakdownQuery | WebPageURLSearchQuery | WebAnalyticsExternalSummaryQuery | WebNotableChangesQuery | RevenueAnalyticsGrossRevenueQuery | RevenueAnalyticsMetricsQuery | RevenueAnalyticsMRRQuery | RevenueAnalyticsOverviewQuery | RevenueAnalyticsTopCustomersQuery | MarketingAnalyticsTableQuery | MarketingAnalyticsAggregatedQuery | NonIntegratedConversionsTableQuery | DataVisualizationNode | DataTableNode | SavedInsightNode | InsightVizNode | TrendsQuery | FunnelsQuery | RetentionQuery | PathsQuery | StickinessQuery | LifecycleQuery | FunnelCorrelationQuery | DatabaseSchemaQuery | RecordingsQuery | LogsQuery | LogAttributesQuery | LogValuesQuery | TraceSpansQuery | TraceSpansAggregationQuery | TraceSpansTreeQuery | TraceSpansAttributeBreakdownQuery | SuggestedQuestionsQuery | TeamTaxonomyQuery | EventTaxonomyQuery | ActorsPropertyTaxonomyQuery | TracesQuery | TraceQuery | TraceNeighborsQuery | VectorSearchQuery | UsageMetricsQuery | AccountsQuery | EndpointsUsageOverviewQuery | EndpointsUsageTableQuery | EndpointsUsageTrendsQuery | MCPHarnessBreakdownQuery | MCPToolTopUsersQuery | MCPToolFailuresQuery | MCPToolStatsQuery | MCPToolDailyStatsQuery | MCPToolDescriptionsQuery | MCPToolSampleIntentsQuery | MCPToolNeighborsQuery | PropertyValuesQuery;
/** Whether results should be calculated sync or async, and how much to rely on the cache:
* - `'blocking'` - calculate synchronously (returning only when the query is done), UNLESS there are very fresh results in the cache
* - `'async'` - kick off background calculation (returning immediately with a query status), UNLESS there are very fresh results in the cache
@@ -46418,6 +46508,46 @@ export namespace Schemas {
}
export interface QueryResponseAlternative102 {
+ /** Query error. Returned only if 'explain' or `modifiers.debug` is true. Throws an error otherwise. */
+ error?: string | null;
+ /** Generated HogQL query. */
+ hogql?: string | null;
+ /** Modifiers used when performing the query */
+ modifiers?: HogQLQueryModifiers | null;
+ /** Query status indicates whether next to the provided data, a query is still running. */
+ query_status?: QueryStatus | null;
+ /** The resolved previous/comparison period date range, when comparing against another period */
+ resolved_compare_date_range?: ResolvedDateRangeResponse | null;
+ /** The date range used for the query */
+ resolved_date_range?: ResolvedDateRangeResponse | null;
+ results: MCPToolSampleIntentItem[];
+ /** Measured timings for different parts of the query generation process */
+ timings?: QueryTiming[] | null;
+ /** Warnings about data warehouse sources referenced by the query whose latest sync failed, is paused, hit a billing limit, or is otherwise stale. Results may not reflect current source data. Accumulated across every HogQL execution that contributes to this response — so insights backed by warehouse tables (Trends, Funnels, etc.) receive the same warnings as raw HogQL queries. */
+ warnings?: DataWarehouseSyncWarning[] | null;
+ }
+
+ export interface QueryResponseAlternative103 {
+ /** Query error. Returned only if 'explain' or `modifiers.debug` is true. Throws an error otherwise. */
+ error?: string | null;
+ /** Generated HogQL query. */
+ hogql?: string | null;
+ /** Modifiers used when performing the query */
+ modifiers?: HogQLQueryModifiers | null;
+ /** Query status indicates whether next to the provided data, a query is still running. */
+ query_status?: QueryStatus | null;
+ /** The resolved previous/comparison period date range, when comparing against another period */
+ resolved_compare_date_range?: ResolvedDateRangeResponse | null;
+ /** The date range used for the query */
+ resolved_date_range?: ResolvedDateRangeResponse | null;
+ results: MCPToolNeighborItem[];
+ /** Measured timings for different parts of the query generation process */
+ timings?: QueryTiming[] | null;
+ /** Warnings about data warehouse sources referenced by the query whose latest sync failed, is paused, hit a billing limit, or is otherwise stale. Results may not reflect current source data. Accumulated across every HogQL execution that contributes to this response — so insights backed by warehouse tables (Trends, Funnels, etc.) receive the same warnings as raw HogQL queries. */
+ warnings?: DataWarehouseSyncWarning[] | null;
+ }
+
+ export interface QueryResponseAlternative104 {
/** Query error. Returned only if 'explain' or `modifiers.debug` is true. Throws an error otherwise. */
error?: string | null;
/** Generated HogQL query. */
@@ -46437,18 +46567,18 @@ export namespace Schemas {
warnings?: DataWarehouseSyncWarning[] | null;
}
- export type QueryResponseAlternative = { [key: string]: unknown } | QueryResponseAlternative1 | QueryResponseAlternative2 | QueryResponseAlternative3 | QueryResponseAlternative4 | QueryResponseAlternative5 | QueryResponseAlternative6 | QueryResponseAlternative7 | QueryResponseAlternative8 | QueryResponseAlternative9 | QueryResponseAlternative10 | QueryResponseAlternative11 | QueryResponseAlternative14 | QueryResponseAlternative15 | QueryResponseAlternative16 | QueryResponseAlternative17 | QueryResponseAlternative18 | QueryResponseAlternative19 | QueryResponseAlternative20 | QueryResponseAlternative21 | QueryResponseAlternative22 | QueryResponseAlternative23 | QueryResponseAlternative24 | QueryResponseAlternative25 | QueryResponseAlternative26 | QueryResponseAlternative27 | QueryResponseAlternative28 | QueryResponseAlternative29 | QueryResponseAlternative30 | QueryResponseAlternative31 | QueryResponseAlternative32 | QueryResponseAlternative33 | QueryResponseAlternative34 | QueryResponseAlternative35 | QueryResponseAlternative36 | QueryResponseAlternative37 | QueryResponseAlternative38 | unknown | QueryResponseAlternative39 | QueryResponseAlternative40 | QueryResponseAlternative41 | QueryResponseAlternative42 | QueryResponseAlternative43 | QueryResponseAlternative44 | QueryResponseAlternative45 | QueryResponseAlternative46 | QueryResponseAlternative47 | QueryResponseAlternative48 | QueryResponseAlternative49 | QueryResponseAlternative50 | QueryResponseAlternative51 | QueryResponseAlternative52 | QueryResponseAlternative53 | QueryResponseAlternative54 | QueryResponseAlternative55 | QueryResponseAlternative57 | QueryResponseAlternative58 | QueryResponseAlternative59 | QueryResponseAlternative60 | QueryResponseAlternative62 | QueryResponseAlternative63 | QueryResponseAlternative64 | QueryResponseAlternative65 | QueryResponseAlternative66 | QueryResponseAlternative67 | QueryResponseAlternative68 | QueryResponseAlternative69 | QueryResponseAlternative70 | QueryResponseAlternative71 | QueryResponseAlternative73 | QueryResponseAlternative74 | QueryResponseAlternative75 | QueryResponseAlternative76 | QueryResponseAlternative77 | QueryResponseAlternative78 | QueryResponseAlternative79 | QueryResponseAlternative80 | QueryResponseAlternative81 | QueryResponseAlternative82 | QueryResponseAlternative83 | QueryResponseAlternative84 | QueryResponseAlternative85 | QueryResponseAlternative86 | QueryResponseAlternative87 | QueryResponseAlternative89 | QueryResponseAlternative90 | QueryResponseAlternative91 | QueryResponseAlternative92 | QueryResponseAlternative93 | QueryResponseAlternative94 | QueryResponseAlternative95 | QueryResponseAlternative96 | QueryResponseAlternative97 | QueryResponseAlternative98 | QueryResponseAlternative99 | QueryResponseAlternative100 | QueryResponseAlternative101 | QueryResponseAlternative102;
+ export type QueryResponseAlternative = { [key: string]: unknown } | QueryResponseAlternative1 | QueryResponseAlternative2 | QueryResponseAlternative3 | QueryResponseAlternative4 | QueryResponseAlternative5 | QueryResponseAlternative6 | QueryResponseAlternative7 | QueryResponseAlternative8 | QueryResponseAlternative9 | QueryResponseAlternative10 | QueryResponseAlternative11 | QueryResponseAlternative14 | QueryResponseAlternative15 | QueryResponseAlternative16 | QueryResponseAlternative17 | QueryResponseAlternative18 | QueryResponseAlternative19 | QueryResponseAlternative20 | QueryResponseAlternative21 | QueryResponseAlternative22 | QueryResponseAlternative23 | QueryResponseAlternative24 | QueryResponseAlternative25 | QueryResponseAlternative26 | QueryResponseAlternative27 | QueryResponseAlternative28 | QueryResponseAlternative29 | QueryResponseAlternative30 | QueryResponseAlternative31 | QueryResponseAlternative32 | QueryResponseAlternative33 | QueryResponseAlternative34 | QueryResponseAlternative35 | QueryResponseAlternative36 | QueryResponseAlternative37 | QueryResponseAlternative38 | unknown | QueryResponseAlternative39 | QueryResponseAlternative40 | QueryResponseAlternative41 | QueryResponseAlternative42 | QueryResponseAlternative43 | QueryResponseAlternative44 | QueryResponseAlternative45 | QueryResponseAlternative46 | QueryResponseAlternative47 | QueryResponseAlternative48 | QueryResponseAlternative49 | QueryResponseAlternative50 | QueryResponseAlternative51 | QueryResponseAlternative52 | QueryResponseAlternative53 | QueryResponseAlternative54 | QueryResponseAlternative55 | QueryResponseAlternative57 | QueryResponseAlternative58 | QueryResponseAlternative59 | QueryResponseAlternative60 | QueryResponseAlternative62 | QueryResponseAlternative63 | QueryResponseAlternative64 | QueryResponseAlternative65 | QueryResponseAlternative66 | QueryResponseAlternative67 | QueryResponseAlternative68 | QueryResponseAlternative69 | QueryResponseAlternative70 | QueryResponseAlternative71 | QueryResponseAlternative73 | QueryResponseAlternative74 | QueryResponseAlternative75 | QueryResponseAlternative76 | QueryResponseAlternative77 | QueryResponseAlternative78 | QueryResponseAlternative79 | QueryResponseAlternative80 | QueryResponseAlternative81 | QueryResponseAlternative82 | QueryResponseAlternative83 | QueryResponseAlternative84 | QueryResponseAlternative85 | QueryResponseAlternative86 | QueryResponseAlternative87 | QueryResponseAlternative89 | QueryResponseAlternative90 | QueryResponseAlternative91 | QueryResponseAlternative92 | QueryResponseAlternative93 | QueryResponseAlternative94 | QueryResponseAlternative95 | QueryResponseAlternative96 | QueryResponseAlternative97 | QueryResponseAlternative98 | QueryResponseAlternative99 | QueryResponseAlternative100 | QueryResponseAlternative101 | QueryResponseAlternative102 | QueryResponseAlternative103 | QueryResponseAlternative104;
export interface QueryStatusResponse {
query_status: QueryStatus;
}
export interface QueryUpgradeRequest {
- query: EventsNode | ActionsNode | PersonsNode | DataWarehouseNode | FunnelsDataWarehouseNode | LifecycleDataWarehouseNode | EventsQuery | SessionsQuery | ActorsQuery | GroupsQuery | InsightActorsQuery | InsightActorsQueryOptions | SessionsTimelineQuery | HogQuery | HogQLQuery | HogQLMetadata | HogQLAutocomplete | SessionAttributionExplorerQuery | RevenueExampleEventsQuery | RevenueExampleDataWarehouseTablesQuery | ErrorTrackingQuery | ErrorTrackingSimilarIssuesQuery | ErrorTrackingBreakdownsQuery | ErrorTrackingIssueCorrelationQuery | ExperimentFunnelsQuery | ExperimentTrendsQuery | ExperimentQuery | ExperimentExposureQuery | DocumentSimilarityQuery | WebOverviewQuery | WebStatsTableQuery | WebExternalClicksTableQuery | WebGoalsQuery | WebVitalsQuery | WebVitalsPathBreakdownQuery | WebPageURLSearchQuery | WebAnalyticsExternalSummaryQuery | WebNotableChangesQuery | RevenueAnalyticsGrossRevenueQuery | RevenueAnalyticsMetricsQuery | RevenueAnalyticsMRRQuery | RevenueAnalyticsOverviewQuery | RevenueAnalyticsTopCustomersQuery | MarketingAnalyticsTableQuery | MarketingAnalyticsAggregatedQuery | NonIntegratedConversionsTableQuery | DataVisualizationNode | DataTableNode | SavedInsightNode | InsightVizNode | TrendsQuery | FunnelsQuery | RetentionQuery | PathsQuery | StickinessQuery | LifecycleQuery | FunnelCorrelationQuery | DatabaseSchemaQuery | RecordingsQuery | LogsQuery | LogAttributesQuery | LogValuesQuery | TraceSpansQuery | TraceSpansAggregationQuery | TraceSpansTreeQuery | TraceSpansAttributeBreakdownQuery | SuggestedQuestionsQuery | TeamTaxonomyQuery | EventTaxonomyQuery | ActorsPropertyTaxonomyQuery | TracesQuery | TraceQuery | TraceNeighborsQuery | VectorSearchQuery | UsageMetricsQuery | AccountsQuery | EndpointsUsageOverviewQuery | EndpointsUsageTableQuery | EndpointsUsageTrendsQuery | MCPHarnessBreakdownQuery | MCPToolTopUsersQuery | MCPToolFailuresQuery | MCPToolStatsQuery | MCPToolDailyStatsQuery | MCPToolDescriptionsQuery | PropertyValuesQuery;
+ query: EventsNode | ActionsNode | PersonsNode | DataWarehouseNode | FunnelsDataWarehouseNode | LifecycleDataWarehouseNode | EventsQuery | SessionsQuery | ActorsQuery | GroupsQuery | InsightActorsQuery | InsightActorsQueryOptions | SessionsTimelineQuery | HogQuery | HogQLQuery | HogQLMetadata | HogQLAutocomplete | SessionAttributionExplorerQuery | RevenueExampleEventsQuery | RevenueExampleDataWarehouseTablesQuery | ErrorTrackingQuery | ErrorTrackingSimilarIssuesQuery | ErrorTrackingBreakdownsQuery | ErrorTrackingIssueCorrelationQuery | ExperimentFunnelsQuery | ExperimentTrendsQuery | ExperimentQuery | ExperimentExposureQuery | DocumentSimilarityQuery | WebOverviewQuery | WebStatsTableQuery | WebExternalClicksTableQuery | WebGoalsQuery | WebVitalsQuery | WebVitalsPathBreakdownQuery | WebPageURLSearchQuery | WebAnalyticsExternalSummaryQuery | WebNotableChangesQuery | RevenueAnalyticsGrossRevenueQuery | RevenueAnalyticsMetricsQuery | RevenueAnalyticsMRRQuery | RevenueAnalyticsOverviewQuery | RevenueAnalyticsTopCustomersQuery | MarketingAnalyticsTableQuery | MarketingAnalyticsAggregatedQuery | NonIntegratedConversionsTableQuery | DataVisualizationNode | DataTableNode | SavedInsightNode | InsightVizNode | TrendsQuery | FunnelsQuery | RetentionQuery | PathsQuery | StickinessQuery | LifecycleQuery | FunnelCorrelationQuery | DatabaseSchemaQuery | RecordingsQuery | LogsQuery | LogAttributesQuery | LogValuesQuery | TraceSpansQuery | TraceSpansAggregationQuery | TraceSpansTreeQuery | TraceSpansAttributeBreakdownQuery | SuggestedQuestionsQuery | TeamTaxonomyQuery | EventTaxonomyQuery | ActorsPropertyTaxonomyQuery | TracesQuery | TraceQuery | TraceNeighborsQuery | VectorSearchQuery | UsageMetricsQuery | AccountsQuery | EndpointsUsageOverviewQuery | EndpointsUsageTableQuery | EndpointsUsageTrendsQuery | MCPHarnessBreakdownQuery | MCPToolTopUsersQuery | MCPToolFailuresQuery | MCPToolStatsQuery | MCPToolDailyStatsQuery | MCPToolDescriptionsQuery | MCPToolSampleIntentsQuery | MCPToolNeighborsQuery | PropertyValuesQuery;
}
export interface QueryUpgradeResponse {
- query: EventsNode | ActionsNode | PersonsNode | DataWarehouseNode | FunnelsDataWarehouseNode | LifecycleDataWarehouseNode | EventsQuery | SessionsQuery | ActorsQuery | GroupsQuery | InsightActorsQuery | InsightActorsQueryOptions | SessionsTimelineQuery | HogQuery | HogQLQuery | HogQLMetadata | HogQLAutocomplete | SessionAttributionExplorerQuery | RevenueExampleEventsQuery | RevenueExampleDataWarehouseTablesQuery | ErrorTrackingQuery | ErrorTrackingSimilarIssuesQuery | ErrorTrackingBreakdownsQuery | ErrorTrackingIssueCorrelationQuery | ExperimentFunnelsQuery | ExperimentTrendsQuery | ExperimentQuery | ExperimentExposureQuery | DocumentSimilarityQuery | WebOverviewQuery | WebStatsTableQuery | WebExternalClicksTableQuery | WebGoalsQuery | WebVitalsQuery | WebVitalsPathBreakdownQuery | WebPageURLSearchQuery | WebAnalyticsExternalSummaryQuery | WebNotableChangesQuery | RevenueAnalyticsGrossRevenueQuery | RevenueAnalyticsMetricsQuery | RevenueAnalyticsMRRQuery | RevenueAnalyticsOverviewQuery | RevenueAnalyticsTopCustomersQuery | MarketingAnalyticsTableQuery | MarketingAnalyticsAggregatedQuery | NonIntegratedConversionsTableQuery | DataVisualizationNode | DataTableNode | SavedInsightNode | InsightVizNode | TrendsQuery | FunnelsQuery | RetentionQuery | PathsQuery | StickinessQuery | LifecycleQuery | FunnelCorrelationQuery | DatabaseSchemaQuery | RecordingsQuery | LogsQuery | LogAttributesQuery | LogValuesQuery | TraceSpansQuery | TraceSpansAggregationQuery | TraceSpansTreeQuery | TraceSpansAttributeBreakdownQuery | SuggestedQuestionsQuery | TeamTaxonomyQuery | EventTaxonomyQuery | ActorsPropertyTaxonomyQuery | TracesQuery | TraceQuery | TraceNeighborsQuery | VectorSearchQuery | UsageMetricsQuery | AccountsQuery | EndpointsUsageOverviewQuery | EndpointsUsageTableQuery | EndpointsUsageTrendsQuery | MCPHarnessBreakdownQuery | MCPToolTopUsersQuery | MCPToolFailuresQuery | MCPToolStatsQuery | MCPToolDailyStatsQuery | MCPToolDescriptionsQuery | PropertyValuesQuery;
+ query: EventsNode | ActionsNode | PersonsNode | DataWarehouseNode | FunnelsDataWarehouseNode | LifecycleDataWarehouseNode | EventsQuery | SessionsQuery | ActorsQuery | GroupsQuery | InsightActorsQuery | InsightActorsQueryOptions | SessionsTimelineQuery | HogQuery | HogQLQuery | HogQLMetadata | HogQLAutocomplete | SessionAttributionExplorerQuery | RevenueExampleEventsQuery | RevenueExampleDataWarehouseTablesQuery | ErrorTrackingQuery | ErrorTrackingSimilarIssuesQuery | ErrorTrackingBreakdownsQuery | ErrorTrackingIssueCorrelationQuery | ExperimentFunnelsQuery | ExperimentTrendsQuery | ExperimentQuery | ExperimentExposureQuery | DocumentSimilarityQuery | WebOverviewQuery | WebStatsTableQuery | WebExternalClicksTableQuery | WebGoalsQuery | WebVitalsQuery | WebVitalsPathBreakdownQuery | WebPageURLSearchQuery | WebAnalyticsExternalSummaryQuery | WebNotableChangesQuery | RevenueAnalyticsGrossRevenueQuery | RevenueAnalyticsMetricsQuery | RevenueAnalyticsMRRQuery | RevenueAnalyticsOverviewQuery | RevenueAnalyticsTopCustomersQuery | MarketingAnalyticsTableQuery | MarketingAnalyticsAggregatedQuery | NonIntegratedConversionsTableQuery | DataVisualizationNode | DataTableNode | SavedInsightNode | InsightVizNode | TrendsQuery | FunnelsQuery | RetentionQuery | PathsQuery | StickinessQuery | LifecycleQuery | FunnelCorrelationQuery | DatabaseSchemaQuery | RecordingsQuery | LogsQuery | LogAttributesQuery | LogValuesQuery | TraceSpansQuery | TraceSpansAggregationQuery | TraceSpansTreeQuery | TraceSpansAttributeBreakdownQuery | SuggestedQuestionsQuery | TeamTaxonomyQuery | EventTaxonomyQuery | ActorsPropertyTaxonomyQuery | TracesQuery | TraceQuery | TraceNeighborsQuery | VectorSearchQuery | UsageMetricsQuery | AccountsQuery | EndpointsUsageOverviewQuery | EndpointsUsageTableQuery | EndpointsUsageTrendsQuery | MCPHarnessBreakdownQuery | MCPToolTopUsersQuery | MCPToolFailuresQuery | MCPToolStatsQuery | MCPToolDailyStatsQuery | MCPToolDescriptionsQuery | MCPToolSampleIntentsQuery | MCPToolNeighborsQuery | PropertyValuesQuery;
}
export interface QuotaResourceLimit {