: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): logs-anomalies-scan MCP tool (#77650)
Jon McCallum464a9ce3c7eb
diff --git a/products/logs/mcp/tools.yaml b/products/logs/mcp/tools.yamlindex 949d5b91f60d..46d945e2f5a9 100644--- a/products/logs/mcp/tools.yaml+++ b/products/logs/mcp/tools.yaml@@ -282,9 +282,27 @@ tools:logs-alerts-update:operation: logs_alerts_updateenabled: false- logs-anomalies-scan-create:+ logs-anomalies-scan:operation: logs_anomalies_scan_create- enabled: false+ enabled: true+ scopes:+ - logs:read+ annotations:+ readOnly: true+ destructive: false+ idempotent: true+ title: Scan a service's logs for volume anomalies+ 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.+ feature_flag: logs-anomalies+ response:+ exclude:+ - series.*.bucketslogs-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 f42c2564a46f..d354733831b1 100644--- a/services/mcp/schema/generated-tool-definitions.json+++ b/services/mcp/schema/generated-tool-definitions.json@@ -6270,6 +6270,21 @@},"feature_flag": "logs-alerting"},+ "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.",+ "category": "Logs",+ "feature": "logs",+ "summary": "Scan a service's logs for volume anomalies",+ "title": "Scan a service's logs for volume anomalies",+ "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 2486b867d112..f9c694d000b0 100644--- a/services/mcp/schema/tool-definitions-all.json+++ b/services/mcp/schema/tool-definitions-all.json@@ -6705,6 +6705,21 @@},"feature_flag": "logs-alerting"},+ "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.",+ "category": "Logs",+ "feature": "logs",+ "summary": "Scan a service's logs for volume anomalies",+ "title": "Scan a service's logs for volume anomalies",+ "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 1bcda2e0b0ee..731f15f7a31a 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 19 enabled ops+ * PostHog API - MCP 20 enabled ops* OpenAPI spec version: 1.0.0*/import * as zod from 'zod'@@ -4148,6 +4148,38 @@ export const LogsAlertsSimulateCreateBody = /* @__PURE__ */ zod.object({date_from: zod.string().describe("Relative date string for how far back to simulate (e.g. '-24h', '-7d', '-30d')."),})+/**+ * Runs anomaly detection on demand over one service's log volume for the given window. Learns per severity baselines from up to 6 weeks of history and returns per bucket expected bands plus any spike, drop, or silence issues. Synchronous and read only.+ * @summary Scan a service's logs for volume anomalies+ */+export const LogsAnomaliesScanCreateParams = /* @__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 LogsAnomaliesScanCreateBody = /* @__PURE__ */ zod.object({+ serviceName: zod+ .string()+ .describe(+ "Service to scan (the log record's service_name). Required: the scan aggregates weeks of baseline history from raw logs, so it is scoped to one service per call."+ ),+ dateRange: zod+ .object({+ date_from: zod.iso+ .datetime({ offset: true })+ .describe(+ 'Start of the evaluation window (ISO 8601). Buckets before this are only used as baseline history.'+ ),+ date_to: zod.iso+ .datetime({ offset: true })+ .describe('End of the evaluation window (ISO 8601), clamped to now.'),+ })+ .describe('Evaluation window to scan for anomalies. May span at most 7 days.'),+})+export const LogsAttributesRetrieveParams = /* @__PURE__ */ zod.object({project_id: zod.string()diff --git a/services/mcp/src/tools/generated/logs.ts b/services/mcp/src/tools/generated/logs.tsindex 540bcf677dd2..3ece7cf4bf2e 100644--- a/services/mcp/src/tools/generated/logs.ts+++ b/services/mcp/src/tools/generated/logs.ts@@ -16,6 +16,7 @@ import {LogsAlertsPartialUpdateParams,LogsAlertsRetrieveParams,LogsAlertsSimulateCreateBody,+ LogsAnomaliesScanCreateBody,LogsAttributesRetrieveQueryParams,LogsCountCreateBody,LogsCountRangesCreateBody,@@ -432,6 +433,30 @@ const logsAlertsSimulateCreate = (): ToolBase<},})+const LogsAnomaliesScanSchema = LogsAnomaliesScanCreateBody++const logsAnomaliesScan = (): ToolBase<typeof LogsAnomaliesScanSchema, Schemas.LogsAnomalyScanResponse> => ({+ name: 'logs-anomalies-scan',+ schema: LogsAnomaliesScanSchema,+ handler: async (context: Context, params: z.infer<typeof LogsAnomaliesScanSchema>) => {+ 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+ }+ const result = await context.api.request<Schemas.LogsAnomalyScanResponse>({+ method: 'POST',+ path: `/api/projects/${encodeURIComponent(String(projectId))}/logs/anomalies/scan/`,+ body,+ })+ const filtered = omitResponseFields(result, ['series.*.buckets']) as typeof result+ return filtered+ },+})+const LogsAttributeValuesListSchema = LogsValuesRetrieveQueryParamsconst logsAttributeValuesList = (): ToolBase<typeof LogsAttributeValuesListSchema, Schemas._LogsValuesResponse> => ({@@ -674,6 +699,7 @@ export const GENERATED_TOOLS: Record<string, () => ToolBase<ZodObjectAny>> = {'logs-alerts-partial-update': logsAlertsPartialUpdate,'logs-alerts-retrieve': logsAlertsRetrieve,'logs-alerts-simulate-create': logsAlertsSimulateCreate,+ 'logs-anomalies-scan': logsAnomaliesScan,'logs-attribute-values-list': logsAttributeValuesList,'logs-attributes-list': logsAttributesList,'logs-count': logsCount,diff --git a/services/mcp/tests/unit/tool-filtering.test.ts b/services/mcp/tests/unit/tool-filtering.test.tsindex b3076769c802..7056486d4313 100644--- a/services/mcp/tests/unit/tool-filtering.test.ts+++ b/services/mcp/tests/unit/tool-filtering.test.ts@@ -831,6 +831,7 @@ describe('Tool Filtering - Feature Flags', () => {expect(flags).toEqual(expect.arrayContaining(['logs-alerting',+ 'logs-anomalies','logs-patterns-view','llm-analytics-datasets','replay-video-based-summarization',@@ -862,7 +863,7 @@ describe('Tool Filtering - Feature Flags', () => {'posthog-connect',]))- expect(flags).toHaveLength(30)+ expect(flags).toHaveLength(31)})it('every loops tool is gated on the loops flag', () => {