:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(logs): expose the anomalies series-bands endpoint as an MCP tool (#95897)
Jon McCallum8c5d981e361a
diff --git a/products/logs/mcp/tools.yaml b/products/logs/mcp/tools.yamlindex fb9838b1c176..3b29482d4fe8 100644--- a/products/logs/mcp/tools.yaml+++ b/products/logs/mcp/tools.yaml@@ -290,7 +290,7 @@ tools:description: >Run anomaly detection on demand over one service's log volume for a time window of up to 7 days. Learnsper-severity baselines from up to 6 weeks of history and returns spike, drop, and silence issues plus- per-severity learning status. Requires a serviceName (use logs-services-list or the resource attribute+ per-severity learning status. Requires a serviceName (use logs-services-create or the resource attributevalues tool to discover services). Experimental; synchronous and read only, so prefer windows of a few hoursto a day. Per-bucket band evidence is omitted from the tool response to save tokens; the API endpointreturns it for charts.@@ -298,9 +298,27 @@ tools:response:exclude:- series.*.buckets- logs-anomalies-series-bands-create:+ logs-anomalies-series-bands:operation: logs_anomalies_series_bands_create- enabled: false+ enabled: true+ scopes:+ - logs:read+ annotations:+ readOnly: true+ destructive: false+ idempotent: true+ title: Per-series log volume with expected bands+ description: >+ Return log volume for every (namespace, environment, severity) series of one service, each with an expected+ band learned from the same time of week over the previous weeks of the volume rollup. This is the data+ behind the Anomalies tab in the logs UI. A bucket whose observed count sits above upper or below lower fell+ outside the expected range. lower and upper are null while a series is still learning; band_ready_at says+ when its band arrives. Omit intervalMinutes and the grain is picked from the window (7 days gives 60+ minutes, 1 day gives 15); pass 5, 15, 30 or 60 to choose. A series too sparse or too quiet for the requested+ grain comes back coarser, with its own interval_minutes and a coarsened_reason. Requires a serviceName (use+ logs-services-create or the resource attribute values tool to discover services). The window defaults to the+ last 7 days, may span at most 7 days, and may start at most 35 days ago. Synchronous and read only.+ feature_flag: logs-anomalieslogs-attribute-values-list:operation: logs_values_retrieveenabled: truediff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.jsonindex 231731910c40..8b9500b45977 100644--- a/services/mcp/schema/generated-tool-definitions.json+++ b/services/mcp/schema/generated-tool-definitions.json@@ -7279,7 +7279,7 @@}},"logs-anomalies-scan": {- "description": "Run anomaly detection on demand over one service's log volume for a time window of up to 7 days. Learns per-severity baselines from up to 6 weeks of history and returns spike, drop, and silence issues plus per-severity learning status. Requires a serviceName (use logs-services-list or the resource attribute values tool to discover services). Experimental; synchronous and read only, so prefer windows of a few hours to a day. Per-bucket band evidence is omitted from the tool response to save tokens; the API endpoint returns it for charts.",+ "description": "Run anomaly detection on demand over one service's log volume for a time window of up to 7 days. Learns per-severity baselines from up to 6 weeks of history and returns spike, drop, and silence issues plus per-severity learning status. Requires a serviceName (use logs-services-create or the resource attribute values tool to discover services). Experimental; synchronous and read only, so prefer windows of a few hours to a day. Per-bucket band evidence is omitted from the tool response to save tokens; the API endpoint returns it for charts.","category": "Logs","feature": "logs","summary": "Scan a service's logs for volume anomalies",@@ -7293,6 +7293,21 @@},"feature_flag": "logs-anomalies"},+ "logs-anomalies-series-bands": {+ "description": "Return log volume for every (namespace, environment, severity) series of one service, each with an expected band learned from the same time of week over the previous weeks of the volume rollup. This is the data behind the Anomalies tab in the logs UI. A bucket whose observed count sits above upper or below lower fell outside the expected range. lower and upper are null while a series is still learning; band_ready_at says when its band arrives. Omit intervalMinutes and the grain is picked from the window (7 days gives 60 minutes, 1 day gives 15); pass 5, 15, 30 or 60 to choose. A series too sparse or too quiet for the requested grain comes back coarser, with its own interval_minutes and a coarsened_reason. Requires a serviceName (use logs-services-create or the resource attribute values tool to discover services). The window defaults to the last 7 days, may span at most 7 days, and may start at most 35 days ago. Synchronous and read only.",+ "category": "Logs",+ "feature": "logs",+ "summary": "Per-series log volume with expected bands",+ "title": "Per-series log volume with expected bands",+ "required_scopes": ["logs:read"],+ "annotations": {+ "destructiveHint": false,+ "idempotentHint": true,+ "openWorldHint": true,+ "readOnlyHint": true+ },+ "feature_flag": "logs-anomalies"+ },"logs-attribute-values-list": {"description": "List values for a specific log attribute key. Use to discover what values exist before building filters. Defaults to attribute_type \"log\" (log-level attributes). To get values for resource-level attributes (e.g. service.name, k8s.pod.name), you MUST explicitly pass attribute_type: \"resource\". Accepts optional serviceNames, dateRange, and filterGroup to narrow which logs are scanned.","category": "Logs",diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.jsonindex 903bb5c9f272..89190c93b083 100644--- a/services/mcp/schema/tool-definitions-all.json+++ b/services/mcp/schema/tool-definitions-all.json@@ -7658,7 +7658,7 @@}},"logs-anomalies-scan": {- "description": "Run anomaly detection on demand over one service's log volume for a time window of up to 7 days. Learns per-severity baselines from up to 6 weeks of history and returns spike, drop, and silence issues plus per-severity learning status. Requires a serviceName (use logs-services-list or the resource attribute values tool to discover services). Experimental; synchronous and read only, so prefer windows of a few hours to a day. Per-bucket band evidence is omitted from the tool response to save tokens; the API endpoint returns it for charts.",+ "description": "Run anomaly detection on demand over one service's log volume for a time window of up to 7 days. Learns per-severity baselines from up to 6 weeks of history and returns spike, drop, and silence issues plus per-severity learning status. Requires a serviceName (use logs-services-create or the resource attribute values tool to discover services). Experimental; synchronous and read only, so prefer windows of a few hours to a day. Per-bucket band evidence is omitted from the tool response to save tokens; the API endpoint returns it for charts.","category": "Logs","feature": "logs","summary": "Scan a service's logs for volume anomalies",@@ -7672,6 +7672,21 @@},"feature_flag": "logs-anomalies"},+ "logs-anomalies-series-bands": {+ "description": "Return log volume for every (namespace, environment, severity) series of one service, each with an expected band learned from the same time of week over the previous weeks of the volume rollup. This is the data behind the Anomalies tab in the logs UI. A bucket whose observed count sits above upper or below lower fell outside the expected range. lower and upper are null while a series is still learning; band_ready_at says when its band arrives. Omit intervalMinutes and the grain is picked from the window (7 days gives 60 minutes, 1 day gives 15); pass 5, 15, 30 or 60 to choose. A series too sparse or too quiet for the requested grain comes back coarser, with its own interval_minutes and a coarsened_reason. Requires a serviceName (use logs-services-create or the resource attribute values tool to discover services). The window defaults to the last 7 days, may span at most 7 days, and may start at most 35 days ago. Synchronous and read only.",+ "category": "Logs",+ "feature": "logs",+ "summary": "Per-series log volume with expected bands",+ "title": "Per-series log volume with expected bands",+ "required_scopes": ["logs:read"],+ "annotations": {+ "destructiveHint": false,+ "idempotentHint": true,+ "openWorldHint": true,+ "readOnlyHint": true+ },+ "feature_flag": "logs-anomalies"+ },"logs-attribute-values-list": {"description": "List values for a specific log attribute key. Use to discover what values exist before building filters. Defaults to attribute_type \"log\" (log-level attributes). To get values for resource-level attributes (e.g. service.name, k8s.pod.name), you MUST explicitly pass attribute_type: \"resource\". Accepts optional serviceNames, dateRange, and filterGroup to narrow which logs are scanned.","category": "Logs",diff --git a/services/mcp/src/generated/logs/api.ts b/services/mcp/src/generated/logs/api.tsindex e4a8b5af9728..38f14674b03b 100644--- a/services/mcp/src/generated/logs/api.ts+++ b/services/mcp/src/generated/logs/api.ts@@ -3,7 +3,7 @@* MCP service uses these Zod schemas for generated tool handlers.* To regenerate: hogli build:openapi*- * PostHog API - MCP 20 enabled ops+ * PostHog API - MCP 21 enabled ops* OpenAPI spec version: 1.0.0*/import * as zod from 'zod'@@ -5430,6 +5430,50 @@ export const LogsAnomaliesScanCreateBody = () => zod.object({.describe('Evaluation window to scan for anomalies. May span at most 7 days.'),})+/**+ * Returns log volume over the requested window for every (namespace, environment, severity) series of one service, with a time-of-week expected band derived from the prior weeks of the volume rollup. The window defaults to the last 7 days and may span at most 7 days. Synchronous and read only.+ * @summary Per-series log volume with expected bands+ */+export const LogsAnomaliesSeriesBandsCreateParams = () => 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 LogsAnomaliesSeriesBandsCreateBody = () => zod.object({+ serviceName: zod.string().describe("Service whose per-series volume to chart (the log record's service_name)."),+ dateRange: zod+ .object({+ date_from: zod+ .string()+ .nullish()+ .describe(+ 'Start of the window. Accepts ISO 8601 timestamps or relative formats: -7d, -1h, -1wStart, etc.'+ ),+ date_to: zod+ .string()+ .nullish()+ .describe('End of the window. Same format as date_from. Omit or null for \"now\".'),+ })+ .optional()+ .describe(+ 'Window to chart. Defaults to the last 7 days. It may span at most 7 days and start at most 35 days ago, past which the volume rollup no longer reaches.'+ ),+ intervalMinutes: zod+ .union([+ zod+ .union([zod.literal(5), zod.literal(15), zod.literal(30), zod.literal(60)])+ .describe('\* `5` - 5\n\* `15` - 15\n\* `30` - 30\n\* `60` - 60'),+ zod.null(),+ ])+ .optional()+ .describe(+ "Display grain in minutes for buckets and bands. One of 5, 15, 30, 60. The window may hold at most 500 buckets per series at the chosen grain, so a finer grain needs a shorter window. Omit it to let the window pick its grain, the coarsest that still cuts it into about 168 buckets. A series too sparse to read at this grain is returned at a coarser one; see each series' interval_minutes.\n\n\* `5` - 5\n\* `15` - 15\n\* `30` - 30\n\* `60` - 60"+ ),+})+export const LogsAttributesRetrieveParams = () => zod.object({project_id: zod.string()diff --git a/services/mcp/src/tools/generated/logs.ts b/services/mcp/src/tools/generated/logs.tsindex dceec66a1764..cd69d487eb5c 100644--- a/services/mcp/src/tools/generated/logs.ts+++ b/services/mcp/src/tools/generated/logs.ts@@ -484,6 +484,38 @@ const logsAnomaliesScan = (): ToolBase<},})+const LogsAnomaliesSeriesBandsSchema = () => {+ const LogsAnomaliesSeriesBandsCreateBody = orvalSchemas.LogsAnomaliesSeriesBandsCreateBody()+ return LogsAnomaliesSeriesBandsCreateBody+}++const logsAnomaliesSeriesBands = (): ToolBase<+ ReturnType<typeof LogsAnomaliesSeriesBandsSchema>,+ Schemas.LogsSeriesBandsResponse+> => ({+ name: 'logs-anomalies-series-bands',+ schema: LogsAnomaliesSeriesBandsSchema(),+ handler: async (context: Context, params: z.infer<ReturnType<typeof LogsAnomaliesSeriesBandsSchema>>) => {+ const projectId = await context.stateManager.getProjectId()+ const body: Record<string, unknown> = {}+ if (params.serviceName !== undefined) {+ body['serviceName'] = params.serviceName+ }+ if (params.dateRange !== undefined) {+ body['dateRange'] = params.dateRange+ }+ if (params.intervalMinutes !== undefined) {+ body['intervalMinutes'] = params.intervalMinutes+ }+ const result = await context.api.request<Schemas.LogsSeriesBandsResponse>({+ method: 'POST',+ path: `/api/projects/${encodeURIComponent(String(projectId))}/logs/anomalies/series_bands/`,+ body,+ })+ return result+ },+})+const LogsAttributeValuesListSchema = () => {const LogsValuesRetrieveQueryParams = orvalSchemas.LogsValuesRetrieveQueryParams()return LogsValuesRetrieveQueryParams@@ -775,6 +807,7 @@ export const GENERATED_TOOLS: Record<string, () => ToolBase<ZodObjectAny>> = {'logs-alerts-retrieve': logsAlertsRetrieve,'logs-alerts-simulate-create': logsAlertsSimulateCreate,'logs-anomalies-scan': logsAnomaliesScan,+ 'logs-anomalies-series-bands': logsAnomaliesSeriesBands,'logs-attribute-values-list': logsAttributeValuesList,'logs-attributes-list': logsAttributesList,'logs-count': logsCount,