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(llma): enable clustering mcp tools (#66127)

Radu Raicea3e337ba31653
diff --git a/products/ai_observability/backend/api/clustering_config.py b/products/ai_observability/backend/api/clustering_config.py
index 3cfacc3317ec..14a833e990b8 100644
--- a/products/ai_observability/backend/api/clustering_config.py
+++ b/products/ai_observability/backend/api/clustering_config.py
@@ -1,5 +1,4 @@
-from drf_spectacular.types import OpenApiTypes
-from drf_spectacular.utils import extend_schema
+from drf_spectacular.utils import extend_schema, extend_schema_serializer
from rest_framework import serializers, status, viewsets
from rest_framework.decorators import action
from rest_framework.permissions import IsAuthenticated
@@ -15,7 +14,13 @@ from ..models.clustering_config import ClusteringConfig
from .metrics import llma_track_latency
+@extend_schema_serializer(many=False)
class ClusteringConfigSerializer(serializers.ModelSerializer):
+ event_filters = serializers.ListField(
+ child=serializers.DictField(child=serializers.JSONField()),
+ help_text="PostHog property filters that scope automated clustering jobs. Empty array means no saved filters.",
+ )
+
class Meta:
model = ClusteringConfig
fields = [
@@ -29,6 +34,13 @@ class ClusteringConfigSerializer(serializers.ModelSerializer):
]
+class ClusteringConfigSetEventFiltersSerializer(serializers.Serializer):
+ event_filters = serializers.ListField(
+ child=serializers.DictField(child=serializers.JSONField()),
+ help_text="PostHog property filters to save for automated clustering jobs. Pass an empty array to clear filters.",
+ )
+
+
class ClusteringConfigViewSet(TeamAndOrgViewSetMixin, viewsets.ViewSet):
"""Team-level clustering configuration (event filters for automated pipelines)."""
@@ -36,7 +48,7 @@ class ClusteringConfigViewSet(TeamAndOrgViewSetMixin, viewsets.ViewSet):
serializer_class = _FallbackSerializer
permission_classes = [IsAuthenticated]
- @extend_schema(responses={200: OpenApiTypes.OBJECT})
+ @extend_schema(responses={200: ClusteringConfigSerializer})
@llma_track_latency("llma_clustering_config_list")
@monitor(feature=None, endpoint="llma_clustering_config_list", method="GET")
def list(self, request: Request, **kwargs) -> Response:
@@ -44,7 +56,7 @@ class ClusteringConfigViewSet(TeamAndOrgViewSetMixin, viewsets.ViewSet):
serializer = ClusteringConfigSerializer(config)
return Response(serializer.data)
- @extend_schema(responses={200: OpenApiTypes.OBJECT})
+ @extend_schema(request=ClusteringConfigSetEventFiltersSerializer, responses={200: ClusteringConfigSerializer})
@action(detail=False, methods=["post"], required_scopes=["llm_analytics:write"])
@llma_track_latency("llma_clustering_config_set_event_filters")
@monitor(feature=None, endpoint="llma_clustering_config_set_event_filters", method="POST")
diff --git a/products/ai_observability/backend/api/clustering_job.py b/products/ai_observability/backend/api/clustering_job.py
index f07d3e98f472..ddc8cfa83b87 100644
--- a/products/ai_observability/backend/api/clustering_job.py
+++ b/products/ai_observability/backend/api/clustering_job.py
@@ -77,7 +77,7 @@ class ClusteringJobSerializer(serializers.ModelSerializer):
class ClusteringJobViewSet(TeamAndOrgViewSetMixin, viewsets.ModelViewSet):
- """CRUD for clustering job configurations (max 5 per team)."""
+ """CRUD for clustering job configurations (max 10 per team)."""
scope_object = "llm_analytics"
permission_classes = [IsAuthenticated]
diff --git a/products/ai_observability/frontend/generated/api.schemas.ts b/products/ai_observability/frontend/generated/api.schemas.ts
index 614908daddc7..eaf6f62a0330 100644
--- a/products/ai_observability/frontend/generated/api.schemas.ts
+++ b/products/ai_observability/frontend/generated/api.schemas.ts
@@ -621,6 +621,22 @@ export interface TestHogResponseApi {
message?: string
}
+export type ClusteringConfigApiEventFiltersItem = { [key: string]: unknown }
+
+export interface ClusteringConfigApi {
+ /** PostHog property filters that scope automated clustering jobs. Empty array means no saved filters. */
+ event_filters: ClusteringConfigApiEventFiltersItem[]
+ readonly created_at: string
+ readonly updated_at: string
+}
+
+export type ClusteringConfigSetEventFiltersApiEventFiltersItem = { [key: string]: unknown }
+
+export interface ClusteringConfigSetEventFiltersApi {
+ /** PostHog property filters to save for automated clustering jobs. Pass an empty array to clear filters. */
+ event_filters: ClusteringConfigSetEventFiltersApiEventFiltersItem[]
+}
+
/**
* * `trace` - trace
* * `generation` - generation
@@ -2325,10 +2341,6 @@ export const EvaluationsListEvaluationType = {
Sentiment: 'sentiment',
} as const
-export type LlmAnalyticsClusteringConfigRetrieve200 = { [key: string]: unknown }
-
-export type LlmAnalyticsClusteringConfigSetEventFiltersCreate200 = { [key: string]: unknown }
-
export type LlmAnalyticsClusteringJobsListParams = {
/**
* Number of results to return per page.
diff --git a/products/ai_observability/frontend/generated/api.ts b/products/ai_observability/frontend/generated/api.ts
index c3587624b14d..014530eca7cc 100644
--- a/products/ai_observability/frontend/generated/api.ts
+++ b/products/ai_observability/frontend/generated/api.ts
@@ -11,6 +11,8 @@ import { apiMutator } from '../../../../frontend/src/lib/api-orval-mutator'
import type {
BatchCheckRequestApi,
BatchCheckResponseApi,
+ ClusteringConfigApi,
+ ClusteringConfigSetEventFiltersApi,
ClusteringJobApi,
ClusteringRunRequestApi,
DatasetApi,
@@ -32,8 +34,6 @@ import type {
LLMPromptPublicApi,
LLMPromptResolveResponseApi,
LLMProviderKeyApi,
- LlmAnalyticsClusteringConfigRetrieve200,
- LlmAnalyticsClusteringConfigSetEventFiltersCreate200,
LlmAnalyticsClusteringJobsListParams,
LlmAnalyticsEvaluationReportsListParams,
LlmAnalyticsEvaluationReportsRunsListParams,
@@ -517,18 +517,18 @@ export const evaluationsTestHogCreate = async (
})
}
-export const getLlmAnalyticsClusteringConfigRetrieveUrl = (projectId: string) => {
+export const getLlmAnalyticsClusteringConfigListUrl = (projectId: string) => {
return `/api/projects/${projectId}/llm_analytics/clustering_config/`
}
/**
* Team-level clustering configuration (event filters for automated pipelines).
*/
-export const llmAnalyticsClusteringConfigRetrieve = async (
+export const llmAnalyticsClusteringConfigList = async (
projectId: string,
options?: RequestInit
-): Promise<LlmAnalyticsClusteringConfigRetrieve200> => {
- return apiMutator<LlmAnalyticsClusteringConfigRetrieve200>(getLlmAnalyticsClusteringConfigRetrieveUrl(projectId), {
+): Promise<ClusteringConfigApi> => {
+ return apiMutator<ClusteringConfigApi>(getLlmAnalyticsClusteringConfigListUrl(projectId), {
...options,
method: 'GET',
})
@@ -543,15 +543,15 @@ export const getLlmAnalyticsClusteringConfigSetEventFiltersCreateUrl = (projectI
*/
export const llmAnalyticsClusteringConfigSetEventFiltersCreate = async (
projectId: string,
+ clusteringConfigSetEventFiltersApi: ClusteringConfigSetEventFiltersApi,
options?: RequestInit
-): Promise<LlmAnalyticsClusteringConfigSetEventFiltersCreate200> => {
- return apiMutator<LlmAnalyticsClusteringConfigSetEventFiltersCreate200>(
- getLlmAnalyticsClusteringConfigSetEventFiltersCreateUrl(projectId),
- {
- ...options,
- method: 'POST',
- }
- )
+): Promise<ClusteringConfigApi> => {
+ return apiMutator<ClusteringConfigApi>(getLlmAnalyticsClusteringConfigSetEventFiltersCreateUrl(projectId), {
+ ...options,
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json', ...options?.headers },
+ body: JSON.stringify(clusteringConfigSetEventFiltersApi),
+ })
}
export const getLlmAnalyticsClusteringJobsListUrl = (
@@ -574,7 +574,7 @@ export const getLlmAnalyticsClusteringJobsListUrl = (
}
/**
- * CRUD for clustering job configurations (max 5 per team).
+ * CRUD for clustering job configurations (max 10 per team).
*/
export const llmAnalyticsClusteringJobsList = async (
projectId: string,
@@ -592,7 +592,7 @@ export const getLlmAnalyticsClusteringJobsCreateUrl = (projectId: string) => {
}
/**
- * CRUD for clustering job configurations (max 5 per team).
+ * CRUD for clustering job configurations (max 10 per team).
*/
export const llmAnalyticsClusteringJobsCreate = async (
projectId: string,
@@ -612,7 +612,7 @@ export const getLlmAnalyticsClusteringJobsRetrieveUrl = (projectId: string, id:
}
/**
- * CRUD for clustering job configurations (max 5 per team).
+ * CRUD for clustering job configurations (max 10 per team).
*/
export const llmAnalyticsClusteringJobsRetrieve = async (
projectId: string,
@@ -630,7 +630,7 @@ export const getLlmAnalyticsClusteringJobsUpdateUrl = (projectId: string, id: st
}
/**
- * CRUD for clustering job configurations (max 5 per team).
+ * CRUD for clustering job configurations (max 10 per team).
*/
export const llmAnalyticsClusteringJobsUpdate = async (
projectId: string,
@@ -651,7 +651,7 @@ export const getLlmAnalyticsClusteringJobsPartialUpdateUrl = (projectId: string,
}
/**
- * CRUD for clustering job configurations (max 5 per team).
+ * CRUD for clustering job configurations (max 10 per team).
*/
export const llmAnalyticsClusteringJobsPartialUpdate = async (
projectId: string,
@@ -672,7 +672,7 @@ export const getLlmAnalyticsClusteringJobsDestroyUrl = (projectId: string, id: s
}
/**
- * CRUD for clustering job configurations (max 5 per team).
+ * CRUD for clustering job configurations (max 10 per team).
*/
export const llmAnalyticsClusteringJobsDestroy = async (
projectId: string,
diff --git a/products/ai_observability/frontend/generated/api.zod.ts b/products/ai_observability/frontend/generated/api.zod.ts
index 7e43a1b4cb81..5c8860073875 100644
--- a/products/ai_observability/frontend/generated/api.zod.ts
+++ b/products/ai_observability/frontend/generated/api.zod.ts
@@ -501,7 +501,18 @@ export const EvaluationsTestHogCreateBody = /* @__PURE__ */ zod.object({
})
/**
- * CRUD for clustering job configurations (max 5 per team).
+ * Team-level clustering configuration (event filters for automated pipelines).
+ */
+export const LlmAnalyticsClusteringConfigSetEventFiltersCreateBody = /* @__PURE__ */ zod.object({
+ event_filters: zod
+ .array(zod.record(zod.string(), zod.unknown()))
+ .describe(
+ 'PostHog property filters to save for automated clustering jobs. Pass an empty array to clear filters.'
+ ),
+})
+
+/**
+ * CRUD for clustering job configurations (max 10 per team).
*/
export const llmAnalyticsClusteringJobsCreateBodyNameMax = 100
@@ -515,7 +526,7 @@ export const LlmAnalyticsClusteringJobsCreateBody = /* @__PURE__ */ zod.object({
})
/**
- * CRUD for clustering job configurations (max 5 per team).
+ * CRUD for clustering job configurations (max 10 per team).
*/
export const llmAnalyticsClusteringJobsUpdateBodyNameMax = 100
@@ -529,7 +540,7 @@ export const LlmAnalyticsClusteringJobsUpdateBody = /* @__PURE__ */ zod.object({
})
/**
- * CRUD for clustering job configurations (max 5 per team).
+ * CRUD for clustering job configurations (max 10 per team).
*/
export const llmAnalyticsClusteringJobsPartialUpdateBodyNameMax = 100
diff --git a/products/ai_observability/mcp/tools.yaml b/products/ai_observability/mcp/tools.yaml
index 9c18f4d829e3..7dc6ce5a2657 100644
--- a/products/ai_observability/mcp/tools.yaml
+++ b/products/ai_observability/mcp/tools.yaml
@@ -33,17 +33,61 @@ tools:
operation: llm_analytics_parser_recipes_retrieve
enabled: false
llma-clustering-config-get:
- operation: llm_analytics_clustering_config_retrieve
- enabled: false
+ operation: llm_analytics_clustering_config_list
+ enabled: true
+ scopes:
+ - llm_analytics:read
+ annotations:
+ readOnly: true
+ destructive: false
+ idempotent: true
+ title: Get clustering config
+ description: >
+ Retrieve the team's clustering event-filter configuration for automated AI observability clustering. New
+ scheduled clustering should usually use clustering jobs, but this remains useful when auditing existing
+ automation.
llma-clustering-config-set-event-filters:
operation: llm_analytics_clustering_config_set_event_filters_create
- enabled: false
+ enabled: true
+ scopes:
+ - llm_analytics:write
+ annotations:
+ readOnly: false
+ destructive: false
+ idempotent: true
+ title: Set clustering config filters
+ description: >
+ Replace the team's clustering event filters. Pass event_filters as a PostHog property-filter array, or an
+ empty array to clear the filters. Prefer clustering jobs for new trace, generation, or evaluation clustering
+ automation.
llma-clustering-job-create:
operation: llm_analytics_clustering_jobs_create
- enabled: false
+ enabled: true
+ scopes:
+ - llm_analytics:write
+ annotations:
+ readOnly: false
+ destructive: false
+ idempotent: false
+ title: Create clustering job
+ description: >
+ Create a scheduled AI observability clustering job for the current team. Jobs define the analysis level
+ (trace, generation, or evaluation), event filters that scope included items, and whether the job is enabled.
+ Creating a custom job disables the migration-created default job for the same analysis level.
llma-clustering-job-delete:
operation: llm_analytics_clustering_jobs_destroy
- enabled: false
+ enabled: true
+ scopes:
+ - llm_analytics:write
+ annotations:
+ readOnly: false
+ destructive: true
+ idempotent: true
+ title: Delete clustering job
+ description: >
+ Delete a scheduled AI observability clustering job by ID. This removes future scheduled clustering for that
+ job but does not delete historical $ai_trace_clusters, $ai_generation_clusters, or $ai_evaluation_clusters
+ events already emitted by previous runs.
llma-clustering-job-get:
operation: llm_analytics_clustering_jobs_retrieve
enabled: true
@@ -55,8 +99,8 @@ tools:
idempotent: true
title: Get clustering job
description: >
- Retrieve a specific clustering job configuration by ID. Returns the job name, analysis level (trace or
- generation), event filters, enabled status, and timestamps.
+ Retrieve a specific clustering job configuration by ID. Returns the job name, analysis level (trace,
+ generation, or evaluation), event filters, enabled status, and timestamps.
llma-clustering-job-list:
operation: llm_analytics_clustering_jobs_list
enabled: true
@@ -68,13 +112,23 @@ tools:
idempotent: true
title: List clustering jobs
description: >
- List all clustering job configurations for the current team (max 5 per team). Each job defines an analysis
- level (trace or generation) and event filters that scope which traces are included in clustering runs.
- Cluster results are stored as $ai_trace_clusters and $ai_generation_clusters events — use docs-search or
- execute-sql to query them.
+ List all clustering job configurations for the current team (max 10 per team). Each job defines an analysis
+ level (trace, generation, or evaluation) and event filters that scope which items are included in clustering
+ runs. To inspect emitted cluster results, use the exploring LLM clusters skill and query the cluster events
+ with execute-sql.
llma-clustering-job-update:
operation: llm_analytics_clustering_jobs_partial_update
- enabled: false
+ enabled: true
+ scopes:
+ - llm_analytics:write
+ annotations:
+ readOnly: false
+ destructive: false
+ idempotent: true
+ title: Update clustering job
+ description: >
+ Partially update a scheduled AI observability clustering job. Use this to rename a job, switch enabled
+ status, adjust event_filters, or change the analysis level (trace, generation, or evaluation).
llma-clustering-job-update-full:
operation: llm_analytics_clustering_jobs_update
enabled: false
diff --git a/products/ai_observability/skills/exploring-llm-clusters/SKILL.md b/products/ai_observability/skills/exploring-llm-clusters/SKILL.md
index 2543995a18bf..2751e0236443 100644
--- a/products/ai_observability/skills/exploring-llm-clusters/SKILL.md
+++ b/products/ai_observability/skills/exploring-llm-clusters/SKILL.md
@@ -21,16 +21,17 @@ comparing cluster behavior, and drilling into individual clusters.
## How clustering works
-PostHog clusters LLM traces (or individual generations) by embedding similarity.
+PostHog clusters LLM traces, individual generations, or evaluation events by embedding similarity.
A Temporal workflow runs periodically or on-demand, producing cluster events stored as
-`$ai_trace_clusters` (trace-level) or `$ai_generation_clusters` (generation-level).
+`$ai_trace_clusters` (trace-level), `$ai_generation_clusters` (generation-level), or
+`$ai_evaluation_clusters` (evaluation-level).
Each cluster event contains:
- `$ai_clustering_run_id` — unique run identifier (format: `<team_id>_<level>_<YYYYMMDD>_<HHMMSS>[_<job_id>]`)
-- `$ai_clustering_level` — `"trace"` or `"generation"`
+- `$ai_clustering_level` — `"trace"`, `"generation"`, or `"evaluation"`
- `$ai_window_start` / `$ai_window_end` — time window analyzed
-- `$ai_total_items_analyzed` — number of traces/generations processed
+- `$ai_total_items_analyzed` — number of traces, generations, or evaluations processed
- `$ai_clusters` — JSON array of cluster objects
- `$ai_clustering_params` — algorithm parameters used
@@ -59,20 +60,20 @@ Each cluster event contains:
```
- `cluster_id: -1` is the **noise/outlier** cluster (items that didn't fit any cluster)
-- Items in `traces` are keyed by trace ID (trace-level) or generation event UUID (generation-level)
+- Items in `traces` are keyed by trace ID (trace-level), generation event UUID (generation-level), or evaluation event UUID (evaluation-level)
- `rank` orders items by proximity to centroid (0 = closest)
- `x`, `y` are 2D coordinates for visualization (UMAP/PCA/t-SNE reduced)
## Clustering jobs
-Each team can have up to 5 clustering jobs. A job defines:
+Each team can have up to 10 clustering jobs. A job defines:
- **name** — human-readable label
-- **analysis_level** — `"trace"` or `"generation"`
-- **event_filters** — property filters scoping which traces are included
+- **analysis_level** — `"trace"`, `"generation"`, or `"evaluation"`
+- **event_filters** — property filters scoping which items are included
- **enabled** — whether the job runs on schedule
-Default jobs named `"Default - trace"` and `"Default - generation"` are auto-created
+Default jobs named `"Default - traces"`, `"Default - generations"`, and `"Default - evaluations"` are auto-created
and disabled when a custom job is created for the same level.
## Workflow: explore clusters
@@ -82,15 +83,17 @@ and disabled when a custom job is created for the same level.
```sql
posthog:execute-sql
SELECT
- properties.$ai_clustering_run_id as run_id,
- properties.$ai_clustering_level as level,
- properties.$ai_window_start as window_start,
- properties.$ai_window_end as window_end,
- toInt(properties.$ai_total_items_analyzed) as total_items,
+ toString(properties.$ai_clustering_run_id) AS run_id,
+ toString(properties.$ai_clustering_level) AS level,
+ toString(properties.$ai_clustering_job_id) AS job_id,
+ toString(properties.$ai_clustering_job_name) AS job_name,
+ toString(properties.$ai_window_start) AS window_start,
+ toString(properties.$ai_window_end) AS window_end,
+ toIntOrNull(toString(properties.$ai_total_items_analyzed)) AS total_items,
timestamp
FROM events
-WHERE event IN ('$ai_trace_clusters', '$ai_generation_clusters')
- AND timestamp >= now() - INTERVAL 7 DAY
+WHERE event IN ('$ai_trace_clusters', '$ai_generation_clusters', '$ai_evaluation_clusters')
+ AND timestamp >= now() - INTERVAL 14 DAY
ORDER BY timestamp DESC
LIMIT 10
```
@@ -100,24 +103,28 @@ LIMIT 10
```sql
posthog:execute-sql
SELECT
- properties.$ai_clustering_run_id as run_id,
- properties.$ai_clustering_level as level,
- properties.$ai_clustering_job_id as job_id,
- properties.$ai_clustering_job_name as job_name,
- properties.$ai_window_start as window_start,
- properties.$ai_window_end as window_end,
- toInt(properties.$ai_total_items_analyzed) as total_items,
- properties.$ai_clusters as clusters,
- properties.$ai_clustering_params as params
+ toString(properties.$ai_clustering_run_id) AS run_id,
+ toString(properties.$ai_clustering_level) AS level,
+ toString(properties.$ai_clustering_job_id) AS job_id,
+ toString(properties.$ai_clustering_job_name) AS job_name,
+ toString(properties.$ai_window_start) AS window_start,
+ toString(properties.$ai_window_end) AS window_end,
+ toIntOrNull(toString(properties.$ai_total_items_analyzed)) AS total_items,
+ properties.$ai_clusters AS clusters,
+ properties.$ai_clustering_params AS params,
+ timestamp
FROM events
-WHERE event IN ('$ai_trace_clusters', '$ai_generation_clusters')
- AND properties.$ai_clustering_run_id = '<run_id>'
+WHERE event IN ('$ai_trace_clusters', '$ai_generation_clusters', '$ai_evaluation_clusters')
+ AND timestamp >= parseDateTimeBestEffort('<window_start>')
+ AND timestamp <= parseDateTimeBestEffort('<window_end>')
+ AND toString(properties.$ai_clustering_run_id) = '<run_id>'
+ORDER BY timestamp DESC
LIMIT 1
```
-The `clusters` field is a JSON array. Parse it to see cluster titles, sizes, and descriptions.
+The `clusters` field is a JSON array. Parse it to see cluster titles, sizes, descriptions, optional `metrics`, and each cluster's `traces` map.
-**Important:** The clusters JSON can be very large (thousands of trace IDs with coordinates).
+**Important:** The clusters JSON can be very large (thousands of trace, generation, or evaluation IDs with coordinates).
When the result is too large for inline display, it auto-persists to a file.
Use `print_clusters.py` from [scripts/](./scripts/) to get a readable summary.
@@ -160,6 +167,26 @@ WHERE event = '$ai_generation'
AND uuid IN ('<gen_uuid_1>', '<gen_uuid_2>', ...)
```
+For evaluation-level clusters, first check each cluster's `metrics` field from `$ai_clusters` (for example pass rate, N/A rate, dominant evaluator name, and average judge cost). When you need individual evaluation rows, match by event UUID:
+
+```sql
+posthog:execute-sql
+SELECT
+ toString(uuid) AS evaluation_id,
+ toString(properties.$ai_trace_id) AS trace_id,
+ toString(properties.$ai_target_event_id) AS generation_id,
+ toString(properties.$ai_evaluation_name) AS evaluation_name,
+ toString(properties.$ai_evaluation_result) AS evaluation_result,
+ toString(properties.$ai_evaluation_reasoning) AS evaluation_reasoning,
+ toFloatOrNull(toString(properties.$ai_total_cost_usd)) AS judge_cost,
+ timestamp
+FROM events
+WHERE event = '$ai_evaluation'
+ AND timestamp >= parseDateTimeBestEffort('<window_start>')
+ AND timestamp <= parseDateTimeBestEffort('<window_end>')
+ AND uuid IN ('<eval_uuid_1>', '<eval_uuid_2>', ...)
+```
+
### Step 4 — Drill into specific traces
Once you've identified interesting clusters, use the trace tools to inspect individual traces:
@@ -172,6 +199,33 @@ posthog:query-llm-trace
}
```
+### When you need message content
+
+Use `events` for cluster events, IDs, cost/latency/token metrics, and evaluation rows.
+Do **not** query `events.properties.$ai_input`, `$ai_output`, or `$ai_output_choices` when you need user messages or full model inputs/outputs —
+those heavy fields live on `posthog.ai_events`.
+
+For a few representative examples, prefer `query-llm-trace`; it reads `posthog.ai_events` for you and returns the full event tree.
+For batch extraction, first get the trace IDs from the cluster, then query `posthog.ai_events` anchored on `trace_id`:
+
+```sql
+posthog:execute-sql
+SELECT
+ trace_id,
+ timestamp,
+ span_id,
+ event,
+ model,
+ input,
+ output_choices
+FROM posthog.ai_events
+WHERE trace_id IN ('<trace_id_1>', '<trace_id_2>', ...)
+ORDER BY trace_id, timestamp
+```
+
+`posthog.ai_events` has a shorter retention window than `events`; older clusters may still have metadata and metrics but no message content.
+For more detail, use the exploring LLM traces skill's [event reference](../exploring-llm-traces/references/events-and-properties.md).
+
## Investigation patterns
### "What kinds of LLM usage do we have?"
@@ -226,4 +280,5 @@ Always surface these links so the user can verify visually in the PostHog UI.
- The noise cluster (`cluster_id: -1`) contains outliers that didn't fit any pattern
- Use `llma-clustering-job-list` to understand what clustering configs are active
- Trace IDs in clusters can be used directly with `query-llm-trace` for deep inspection
+- Message content lives on `posthog.ai_events`, not `events.properties`; use `query-llm-trace` unless you need custom batch SQL
- For large clusters, inspect the top-ranked traces (closest to centroid) for representative examples
diff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.json
index af934311c601..3379e568bcb7 100644
--- a/services/mcp/schema/generated-tool-definitions.json
+++ b/services/mcp/schema/generated-tool-definitions.json
@@ -4037,8 +4037,64 @@
"readOnlyHint": true
}
},
+ "llma-clustering-config-get": {
+ "description": "Retrieve the team's clustering event-filter configuration for automated AI observability clustering. New scheduled clustering should usually use clustering jobs, but this remains useful when auditing existing automation.",
+ "category": "AI observability",
+ "feature": "llm_analytics",
+ "summary": "Get clustering config",
+ "title": "Get clustering config",
+ "required_scopes": ["llm_analytics:read"],
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": true
+ }
+ },
+ "llma-clustering-config-set-event-filters": {
+ "description": "Replace the team's clustering event filters. Pass event_filters as a PostHog property-filter array, or an empty array to clear the filters. Prefer clustering jobs for new trace, generation, or evaluation clustering automation.",
+ "category": "AI observability",
+ "feature": "llm_analytics",
+ "summary": "Set clustering config filters",
+ "title": "Set clustering config filters",
+ "required_scopes": ["llm_analytics:write"],
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": false
+ }
+ },
+ "llma-clustering-job-create": {
+ "description": "Create a scheduled AI observability clustering job for the current team. Jobs define the analysis level (trace, generation, or evaluation), event filters that scope included items, and whether the job is enabled. Creating a custom job disables the migration-created default job for the same analysis level.",
+ "category": "AI observability",
+ "feature": "llm_analytics",
+ "summary": "Create clustering job",
+ "title": "Create clustering job",
+ "required_scopes": ["llm_analytics:write"],
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": false,
+ "openWorldHint": true,
+ "readOnlyHint": false
+ }
+ },
+ "llma-clustering-job-delete": {
+ "description": "Delete a scheduled AI observability clustering job by ID. This removes future scheduled clustering for that job but does not delete historical $ai_trace_clusters, $ai_generation_clusters, or $ai_evaluation_clusters events already emitted by previous runs.",
+ "category": "AI observability",
+ "feature": "llm_analytics",
+ "summary": "Delete clustering job",
+ "title": "Delete clustering job",
+ "required_scopes": ["llm_analytics:write"],
+ "annotations": {
+ "destructiveHint": true,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": false
+ }
+ },
"llma-clustering-job-get": {
- "description": "Retrieve a specific clustering job configuration by ID. Returns the job name, analysis level (trace or generation), event filters, enabled status, and timestamps.",
+ "description": "Retrieve a specific clustering job configuration by ID. Returns the job name, analysis level (trace, generation, or evaluation), event filters, enabled status, and timestamps.",
"category": "AI observability",
"feature": "llm_analytics",
"summary": "Get clustering job",
@@ -4052,7 +4108,7 @@
}
},
"llma-clustering-job-list": {
- "description": "List all clustering job configurations for the current team (max 5 per team). Each job defines an analysis level (trace or generation) and event filters that scope which traces are included in clustering runs. Cluster results are stored as $ai_trace_clusters and $ai_generation_clusters events — use docs-search or execute-sql to query them.",
+ "description": "List all clustering job configurations for the current team (max 10 per team). Each job defines an analysis level (trace, generation, or evaluation) and event filters that scope which items are included in clustering runs. To inspect emitted cluster results, use the exploring LLM clusters skill and query the cluster events with execute-sql.",
"category": "AI observability",
"feature": "llm_analytics",
"summary": "List clustering jobs",
@@ -4065,6 +4121,20 @@
"readOnlyHint": true
}
},
+ "llma-clustering-job-update": {
+ "description": "Partially update a scheduled AI observability clustering job. Use this to rename a job, switch enabled status, adjust event_filters, or change the analysis level (trace, generation, or evaluation).",
+ "category": "AI observability",
+ "feature": "llm_analytics",
+ "summary": "Update clustering job",
+ "title": "Update clustering job",
+ "required_scopes": ["llm_analytics:write"],
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": false
+ }
+ },
"llma-evaluation-config-get": {
"description": "Retrieve the team's evaluation configuration, including the active LLM provider key used to run llm_judge evaluations and remaining trial credits. Call this before creating an llm_judge evaluation to verify the team has either trial credits available or an active provider key configured — without one, llm_judge runs will fail. Returns trial limits, the active provider key (or null if on trial credits), and timestamps.",
"category": "AI observability",
diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.json
index b8a94013c9fb..2fc5755087a5 100644
--- a/services/mcp/schema/tool-definitions-all.json
+++ b/services/mcp/schema/tool-definitions-all.json
@@ -4333,8 +4333,64 @@
"readOnlyHint": true
}
},
+ "llma-clustering-config-get": {
+ "description": "Retrieve the team's clustering event-filter configuration for automated AI observability clustering. New scheduled clustering should usually use clustering jobs, but this remains useful when auditing existing automation.",
+ "category": "AI observability",
+ "feature": "llm_analytics",
+ "summary": "Get clustering config",
+ "title": "Get clustering config",
+ "required_scopes": ["llm_analytics:read"],
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": true
+ }
+ },
+ "llma-clustering-config-set-event-filters": {
+ "description": "Replace the team's clustering event filters. Pass event_filters as a PostHog property-filter array, or an empty array to clear the filters. Prefer clustering jobs for new trace, generation, or evaluation clustering automation.",
+ "category": "AI observability",
+ "feature": "llm_analytics",
+ "summary": "Set clustering config filters",
+ "title": "Set clustering config filters",
+ "required_scopes": ["llm_analytics:write"],
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": false
+ }
+ },
+ "llma-clustering-job-create": {
+ "description": "Create a scheduled AI observability clustering job for the current team. Jobs define the analysis level (trace, generation, or evaluation), event filters that scope included items, and whether the job is enabled. Creating a custom job disables the migration-created default job for the same analysis level.",
+ "category": "AI observability",
+ "feature": "llm_analytics",
+ "summary": "Create clustering job",
+ "title": "Create clustering job",
+ "required_scopes": ["llm_analytics:write"],
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": false,
+ "openWorldHint": true,
+ "readOnlyHint": false
+ }
+ },
+ "llma-clustering-job-delete": {
+ "description": "Delete a scheduled AI observability clustering job by ID. This removes future scheduled clustering for that job but does not delete historical $ai_trace_clusters, $ai_generation_clusters, or $ai_evaluation_clusters events already emitted by previous runs.",
+ "category": "AI observability",
+ "feature": "llm_analytics",
+ "summary": "Delete clustering job",
+ "title": "Delete clustering job",
+ "required_scopes": ["llm_analytics:write"],
+ "annotations": {
+ "destructiveHint": true,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": false
+ }
+ },
"llma-clustering-job-get": {
- "description": "Retrieve a specific clustering job configuration by ID. Returns the job name, analysis level (trace or generation), event filters, enabled status, and timestamps.",
+ "description": "Retrieve a specific clustering job configuration by ID. Returns the job name, analysis level (trace, generation, or evaluation), event filters, enabled status, and timestamps.",
"category": "AI observability",
"feature": "llm_analytics",
"summary": "Get clustering job",
@@ -4348,7 +4404,7 @@
}
},
"llma-clustering-job-list": {
- "description": "List all clustering job configurations for the current team (max 5 per team). Each job defines an analysis level (trace or generation) and event filters that scope which traces are included in clustering runs. Cluster results are stored as $ai_trace_clusters and $ai_generation_clusters events — use docs-search or execute-sql to query them.",
+ "description": "List all clustering job configurations for the current team (max 10 per team). Each job defines an analysis level (trace, generation, or evaluation) and event filters that scope which items are included in clustering runs. To inspect emitted cluster results, use the exploring LLM clusters skill and query the cluster events with execute-sql.",
"category": "AI observability",
"feature": "llm_analytics",
"summary": "List clustering jobs",
@@ -4361,6 +4417,20 @@
"readOnlyHint": true
}
},
+ "llma-clustering-job-update": {
+ "description": "Partially update a scheduled AI observability clustering job. Use this to rename a job, switch enabled status, adjust event_filters, or change the analysis level (trace, generation, or evaluation).",
+ "category": "AI observability",
+ "feature": "llm_analytics",
+ "summary": "Update clustering job",
+ "title": "Update clustering job",
+ "required_scopes": ["llm_analytics:write"],
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": false
+ }
+ },
"llma-evaluation-config-get": {
"description": "Retrieve the team's evaluation configuration, including the active LLM provider key used to run llm_judge evaluations and remaining trial credits. Call this before creating an llm_judge evaluation to verify the team has either trial credits available or an active provider key configured — without one, llm_judge runs will fail. Returns trial limits, the active provider key (or null if on trial credits), and timestamps.",
"category": "AI observability",
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 833c3b5eaa13..9c3d89de6acb 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -12762,6 +12762,22 @@ export namespace Schemas {
truncated: boolean;
}
+ export type ClusteringConfigEventFiltersItem = { [key: string]: unknown };
+
+ export interface ClusteringConfig {
+ /** PostHog property filters that scope automated clustering jobs. Empty array means no saved filters. */
+ event_filters: ClusteringConfigEventFiltersItem[];
+ readonly created_at: string;
+ readonly updated_at: string;
+ }
+
+ export type ClusteringConfigSetEventFiltersEventFiltersItem = { [key: string]: unknown };
+
+ export interface ClusteringConfigSetEventFilters {
+ /** PostHog property filters to save for automated clustering jobs. Pass an empty array to clear filters. */
+ event_filters: ClusteringConfigSetEventFiltersEventFiltersItem[];
+ }
+
export interface ClusteringJob {
readonly id: string;
/** @maxLength 100 */
@@ -56104,10 +56120,6 @@ export namespace Schemas {
search?: string;
};
- export type EnvironmentsLlmAnalyticsClusteringConfigRetrieve200 = { [key: string]: unknown };
-
- export type EnvironmentsLlmAnalyticsClusteringConfigSetEventFiltersCreate200 = { [key: string]: unknown };
-
export type EnvironmentsLlmAnalyticsClusteringJobsListParams = {
/**
* Number of results to return per page.
@@ -62529,10 +62541,6 @@ export namespace Schemas {
offset?: number;
};
- export type LlmAnalyticsClusteringConfigRetrieve200 = { [key: string]: unknown };
-
- export type LlmAnalyticsClusteringConfigSetEventFiltersCreate200 = { [key: string]: unknown };
-
export type LlmAnalyticsClusteringJobsListParams = {
/**
* Number of results to return per page.
diff --git a/services/mcp/src/generated/ai_observability/api.ts b/services/mcp/src/generated/ai_observability/api.ts
index 76114fa1d00d..d5d4cc42188e 100644
--- a/services/mcp/src/generated/ai_observability/api.ts
+++ b/services/mcp/src/generated/ai_observability/api.ts
@@ -3,7 +3,7 @@
* MCP service uses these Zod schemas for generated tool handlers.
* To regenerate: hogli build:openapi
*
- * PostHog API - MCP 50 enabled ops
+ * PostHog API - MCP 55 enabled ops
* OpenAPI spec version: 1.0.0
*/
import * as zod from 'zod'
@@ -437,7 +437,37 @@ export const EvaluationsTestHogCreateBody = /* @__PURE__ */ zod.object({
})
/**
- * CRUD for clustering job configurations (max 5 per team).
+ * Team-level clustering configuration (event filters for automated pipelines).
+ */
+export const LlmAnalyticsClusteringConfigListParams = /* @__PURE__ */ zod.object({
+ project_id: zod
+ .string()
+ .describe(
+ "Project ID of the project you're trying to access. To find the ID of the project, make a call to /api/projects/."
+ ),
+})
+
+/**
+ * Team-level clustering configuration (event filters for automated pipelines).
+ */
+export const LlmAnalyticsClusteringConfigSetEventFiltersCreateParams = /* @__PURE__ */ zod.object({
+ project_id: zod
+ .string()
+ .describe(
+ "Project ID of the project you're trying to access. To find the ID of the project, make a call to /api/projects/."
+ ),
+})
+
+export const LlmAnalyticsClusteringConfigSetEventFiltersCreateBody = /* @__PURE__ */ zod.object({
+ event_filters: zod
+ .array(zod.record(zod.string(), zod.unknown()))
+ .describe(
+ 'PostHog property filters to save for automated clustering jobs. Pass an empty array to clear filters.'
+ ),
+})
+
+/**
+ * CRUD for clustering job configurations (max 10 per team).
*/
export const LlmAnalyticsClusteringJobsListParams = /* @__PURE__ */ zod.object({
project_id: zod
@@ -453,7 +483,29 @@ export const LlmAnalyticsClusteringJobsListQueryParams = /* @__PURE__ */ zod.obj
})
/**
- * CRUD for clustering job configurations (max 5 per team).
+ * CRUD for clustering job configurations (max 10 per team).
+ */
+export const LlmAnalyticsClusteringJobsCreateParams = /* @__PURE__ */ zod.object({
+ project_id: zod
+ .string()
+ .describe(
+ "Project ID of the project you're trying to access. To find the ID of the project, make a call to /api/projects/."
+ ),
+})
+
+export const llmAnalyticsClusteringJobsCreateBodyNameMax = 100
+
+export const LlmAnalyticsClusteringJobsCreateBody = /* @__PURE__ */ zod.object({
+ name: zod.string().max(llmAnalyticsClusteringJobsCreateBodyNameMax),
+ analysis_level: zod
+ .enum(['trace', 'generation', 'evaluation'])
+ .describe('* `trace` - trace\n* `generation` - generation\n* `evaluation` - evaluation'),
+ event_filters: zod.unknown().optional(),
+ enabled: zod.boolean().optional(),
+})
+
+/**
+ * CRUD for clustering job configurations (max 10 per team).
*/
export const LlmAnalyticsClusteringJobsRetrieveParams = /* @__PURE__ */ zod.object({
id: zod.string().describe('A UUID string identifying this clustering job.'),
@@ -464,6 +516,42 @@ export const LlmAnalyticsClusteringJobsRetrieveParams = /* @__PURE__ */ zod.obje
),
})
+/**
+ * CRUD for clustering job configurations (max 10 per team).
+ */
+export const LlmAnalyticsClusteringJobsPartialUpdateParams = /* @__PURE__ */ zod.object({
+ id: zod.string().describe('A UUID string identifying this clustering job.'),
+ project_id: zod
+ .string()
+ .describe(
+ "Project ID of the project you're trying to access. To find the ID of the project, make a call to /api/projects/."
+ ),
+})
+
+export const llmAnalyticsClusteringJobsPartialUpdateBodyNameMax = 100
+
+export const LlmAnalyticsClusteringJobsPartialUpdateBody = /* @__PURE__ */ zod.object({
+ name: zod.string().max(llmAnalyticsClusteringJobsPartialUpdateBodyNameMax).optional(),
+ analysis_level: zod
+ .enum(['trace', 'generation', 'evaluation'])
+ .optional()
+ .describe('* `trace` - trace\n* `generation` - generation\n* `evaluation` - evaluation'),
+ event_filters: zod.unknown().optional(),
+ enabled: zod.boolean().optional(),
+})
+
+/**
+ * CRUD for clustering job configurations (max 10 per team).
+ */
+export const LlmAnalyticsClusteringJobsDestroyParams = /* @__PURE__ */ zod.object({
+ id: zod.string().describe('A UUID string identifying this clustering job.'),
+ project_id: zod
+ .string()
+ .describe(
+ "Project ID of the project you're trying to access. To find the ID of the project, make a call to /api/projects/."
+ ),
+})
+
/**
* Get the evaluation config for this team
*/
diff --git a/services/mcp/src/tools/generated/ai_observability.ts b/services/mcp/src/tools/generated/ai_observability.ts
index 330b101465d0..219245c5ac05 100644
--- a/services/mcp/src/tools/generated/ai_observability.ts
+++ b/services/mcp/src/tools/generated/ai_observability.ts
@@ -11,7 +11,12 @@ import {
EvaluationsPartialUpdateParams,
EvaluationsRetrieveParams,
EvaluationsTestHogCreateBody,
+ LlmAnalyticsClusteringConfigSetEventFiltersCreateBody,
+ LlmAnalyticsClusteringJobsCreateBody,
+ LlmAnalyticsClusteringJobsDestroyParams,
LlmAnalyticsClusteringJobsListQueryParams,
+ LlmAnalyticsClusteringJobsPartialUpdateBody,
+ LlmAnalyticsClusteringJobsPartialUpdateParams,
LlmAnalyticsClusteringJobsRetrieveParams,
LlmAnalyticsEvaluationConfigSetActiveKeyCreateBody,
LlmAnalyticsEvaluationReportsCreateBody,
@@ -67,6 +72,89 @@ import { PromptListInputSchema, ScoreDefinitionConfigSchema } from '@/schema/too
import { withPostHogUrl, type WithPostHogUrl } from '@/tools/tool-utils'
import type { Context, ToolBase, ZodObjectAny } from '@/tools/types'
+const LlmaClusteringConfigGetSchema = z.object({})
+
+const llmaClusteringConfigGet = (): ToolBase<typeof LlmaClusteringConfigGetSchema, Schemas.ClusteringConfig> => ({
+ name: 'llma-clustering-config-get',
+ schema: LlmaClusteringConfigGetSchema,
+ // eslint-disable-next-line no-unused-vars
+ handler: async (context: Context, params: z.infer<typeof LlmaClusteringConfigGetSchema>) => {
+ const projectId = await context.stateManager.getProjectId()
+ const result = await context.api.request<Schemas.ClusteringConfig>({
+ method: 'GET',
+ path: `/api/projects/${encodeURIComponent(String(projectId))}/llm_analytics/clustering_config/`,
+ })
+ return result
+ },
+})
+
+const LlmaClusteringConfigSetEventFiltersSchema = LlmAnalyticsClusteringConfigSetEventFiltersCreateBody
+
+const llmaClusteringConfigSetEventFilters = (): ToolBase<
+ typeof LlmaClusteringConfigSetEventFiltersSchema,
+ Schemas.ClusteringConfig
+> => ({
+ name: 'llma-clustering-config-set-event-filters',
+ schema: LlmaClusteringConfigSetEventFiltersSchema,
+ handler: async (context: Context, params: z.infer<typeof LlmaClusteringConfigSetEventFiltersSchema>) => {
+ const projectId = await context.stateManager.getProjectId()
+ const body: Record<string, unknown> = {}
+ if (params.event_filters !== undefined) {
+ body['event_filters'] = params.event_filters
+ }
+ const result = await context.api.request<Schemas.ClusteringConfig>({
+ method: 'POST',
+ path: `/api/projects/${encodeURIComponent(String(projectId))}/llm_analytics/clustering_config/set_event_filters/`,
+ body,
+ })
+ return result
+ },
+})
+
+const LlmaClusteringJobCreateSchema = LlmAnalyticsClusteringJobsCreateBody
+
+const llmaClusteringJobCreate = (): ToolBase<typeof LlmaClusteringJobCreateSchema, Schemas.ClusteringJob> => ({
+ name: 'llma-clustering-job-create',
+ schema: LlmaClusteringJobCreateSchema,
+ handler: async (context: Context, params: z.infer<typeof LlmaClusteringJobCreateSchema>) => {
+ const projectId = await context.stateManager.getProjectId()
+ const body: Record<string, unknown> = {}
+ if (params.name !== undefined) {
+ body['name'] = params.name
+ }
+ if (params.analysis_level !== undefined) {
+ body['analysis_level'] = params.analysis_level
+ }
+ if (params.event_filters !== undefined) {
+ body['event_filters'] = params.event_filters
+ }
+ if (params.enabled !== undefined) {
+ body['enabled'] = params.enabled
+ }
+ const result = await context.api.request<Schemas.ClusteringJob>({
+ method: 'POST',
+ path: `/api/projects/${encodeURIComponent(String(projectId))}/llm_analytics/clustering_jobs/`,
+ body,
+ })
+ return result
+ },
+})
+
+const LlmaClusteringJobDeleteSchema = LlmAnalyticsClusteringJobsDestroyParams.omit({ project_id: true })
+
+const llmaClusteringJobDelete = (): ToolBase<typeof LlmaClusteringJobDeleteSchema, unknown> => ({
+ name: 'llma-clustering-job-delete',
+ schema: LlmaClusteringJobDeleteSchema,
+ handler: async (context: Context, params: z.infer<typeof LlmaClusteringJobDeleteSchema>) => {
+ const projectId = await context.stateManager.getProjectId()
+ const result = await context.api.request<unknown>({
+ method: 'DELETE',
+ path: `/api/projects/${encodeURIComponent(String(projectId))}/llm_analytics/clustering_jobs/${encodeURIComponent(String(params.id))}/`,
+ })
+ return result
+ },
+})
+
const LlmaClusteringJobGetSchema = LlmAnalyticsClusteringJobsRetrieveParams.omit({ project_id: true })
const llmaClusteringJobGet = (): ToolBase<typeof LlmaClusteringJobGetSchema, Schemas.ClusteringJob> => ({
@@ -101,6 +189,37 @@ const llmaClusteringJobList = (): ToolBase<typeof LlmaClusteringJobListSchema, S
},
})
+const LlmaClusteringJobUpdateSchema = LlmAnalyticsClusteringJobsPartialUpdateParams.omit({ project_id: true }).extend(
+ LlmAnalyticsClusteringJobsPartialUpdateBody.shape
+)
+
+const llmaClusteringJobUpdate = (): ToolBase<typeof LlmaClusteringJobUpdateSchema, Schemas.ClusteringJob> => ({
+ name: 'llma-clustering-job-update',
+ schema: LlmaClusteringJobUpdateSchema,
+ handler: async (context: Context, params: z.infer<typeof LlmaClusteringJobUpdateSchema>) => {
+ const projectId = await context.stateManager.getProjectId()
+ const body: Record<string, unknown> = {}
+ if (params.name !== undefined) {
+ body['name'] = params.name
+ }
+ if (params.analysis_level !== undefined) {
+ body['analysis_level'] = params.analysis_level
+ }
+ if (params.event_filters !== undefined) {
+ body['event_filters'] = params.event_filters
+ }
+ if (params.enabled !== undefined) {
+ body['enabled'] = params.enabled
+ }
+ const result = await context.api.request<Schemas.ClusteringJob>({
+ method: 'PATCH',
+ path: `/api/projects/${encodeURIComponent(String(projectId))}/llm_analytics/clustering_jobs/${encodeURIComponent(String(params.id))}/`,
+ body,
+ })
+ return result
+ },
+})
+
const LlmaEvaluationConfigGetSchema = z.object({})
const llmaEvaluationConfigGet = (): ToolBase<typeof LlmaEvaluationConfigGetSchema, Schemas.EvaluationConfig> => ({
@@ -1395,8 +1514,13 @@ const llmaTraceReviewUpdate = (): ToolBase<
})
export const GENERATED_TOOLS: Record<string, () => ToolBase<ZodObjectAny>> = {
+ 'llma-clustering-config-get': llmaClusteringConfigGet,
+ 'llma-clustering-config-set-event-filters': llmaClusteringConfigSetEventFilters,
+ 'llma-clustering-job-create': llmaClusteringJobCreate,
+ 'llma-clustering-job-delete': llmaClusteringJobDelete,
'llma-clustering-job-get': llmaClusteringJobGet,
'llma-clustering-job-list': llmaClusteringJobList,
+ 'llma-clustering-job-update': llmaClusteringJobUpdate,
'llma-evaluation-config-get': llmaEvaluationConfigGet,
'llma-evaluation-config-set-active-key': llmaEvaluationConfigSetActiveKey,
'llma-evaluation-create': llmaEvaluationCreate,
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/llma-clustering-config-get.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/llma-clustering-config-get.json
new file mode 100644
index 000000000000..7b7ea9186078
--- /dev/null
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/llma-clustering-config-get.json
@@ -0,0 +1,5 @@
+{
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
+ "properties": {},
+ "type": "object"
+}
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/llma-clustering-config-set-event-filters.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/llma-clustering-config-set-event-filters.json
new file mode 100644
index 000000000000..fc1d58749691
--- /dev/null
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/llma-clustering-config-set-event-filters.json
@@ -0,0 +1,18 @@
+{
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
+ "properties": {
+ "event_filters": {
+ "description": "PostHog property filters to save for automated clustering jobs. Pass an empty array to clear filters.",
+ "items": {
+ "additionalProperties": {},
+ "propertyNames": {
+ "type": "string"
+ },
+ "type": "object"
+ },
+ "type": "array"
+ }
+ },
+ "required": ["event_filters"],
+ "type": "object"
+}
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/llma-clustering-job-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/llma-clustering-job-create.json
new file mode 100644
index 000000000000..b72841666895
--- /dev/null
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/llma-clustering-job-create.json
@@ -0,0 +1,20 @@
+{
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
+ "properties": {
+ "analysis_level": {
+ "description": "* `trace` - trace\n* `generation` - generation\n* `evaluation` - evaluation",
+ "enum": ["trace", "generation", "evaluation"],
+ "type": "string"
+ },
+ "enabled": {
+ "type": "boolean"
+ },
+ "event_filters": {},
+ "name": {
+ "maxLength": 100,
+ "type": "string"
+ }
+ },
+ "required": ["name", "analysis_level"],
+ "type": "object"
+}
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/llma-clustering-job-delete.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/llma-clustering-job-delete.json
new file mode 100644
index 000000000000..f1f723dfeff3
--- /dev/null
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/llma-clustering-job-delete.json
@@ -0,0 +1,11 @@
+{
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
+ "properties": {
+ "id": {
+ "description": "A UUID string identifying this clustering job.",
+ "type": "string"
+ }
+ },
+ "required": ["id"],
+ "type": "object"
+}
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/llma-clustering-job-update.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/llma-clustering-job-update.json
new file mode 100644
index 000000000000..3da2a9a6f617
--- /dev/null
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/llma-clustering-job-update.json
@@ -0,0 +1,24 @@
+{
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
+ "properties": {
+ "analysis_level": {
+ "description": "* `trace` - trace\n* `generation` - generation\n* `evaluation` - evaluation",
+ "enum": ["trace", "generation", "evaluation"],
+ "type": "string"
+ },
+ "enabled": {
+ "type": "boolean"
+ },
+ "event_filters": {},
+ "id": {
+ "description": "A UUID string identifying this clustering job.",
+ "type": "string"
+ },
+ "name": {
+ "maxLength": 100,
+ "type": "string"
+ }
+ },
+ "required": ["id"],
+ "type": "object"
+}