: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
fix(alerts): let read-only tokens see the alert-simulate MCP tool (#105231)
posthog[bot]0b9059a25ccd
diff --git a/products/alerts/mcp/tools.yaml b/products/alerts/mcp/tools.yamlindex 2767e5b42380..37866dc5ebc5 100644--- a/products/alerts/mcp/tools.yaml+++ b/products/alerts/mcp/tools.yaml@@ -143,7 +143,8 @@ tools:operation: alerts_simulate_createenabled: truescopes:- - alert:write+ - alert:read+ - insight:readannotations:readOnly: falsedestructive: false@@ -156,13 +157,13 @@ tools:(threshold 0.95, window 90, first-difference preprocessing). To choose another detector, passdetector_config with a type (zscore, mad, iqr, copod, ecod, hbos, isolation_forest, knn, lof, ocsvm, pca,ensemble, or llm). Always send the type explicitly: a config with no type is read as a z-score detector, and- any llm-only field you sent with it is dropped without an error. The llm type makes a real model call per- simulation, which is why this tool needs the alert:write scope; it is rate limited per project, and takes- the same instructions, threshold (default 0.7), and window (default 90) as an llm alert; its scores are the- model's confidence, not a statistical probability. Optionally specify date_from (e.g. '-48h', '-30d') to- control how far back to simulate, and series_index to pick which series to analyze. Returns data values,- anomaly scores per point, triggered indices and dates, and for ensemble detectors, per-sub-detector score- breakdowns.+ any llm-only field you sent with it is dropped without an error. A statistical detector only reads, so+ alert:read and insight:read are enough for it. The llm type makes a real model call per simulation, so that+ type also needs the alert:write scope; it is rate limited per project, and takes the same instructions,+ threshold (default 0.7), and window (default 90) as an llm alert; its scores are the model's confidence, not+ a statistical probability. Optionally specify date_from (e.g. '-48h', '-30d') to control how far back to+ simulate, and series_index to pick which series to analyze. Returns data values, anomaly scores per point,+ triggered indices and dates, and for ensemble detectors, per-sub-detector score breakdowns.alert-update:operation: alerts_partial_updateenabled: truediff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.jsonindex 2994fff588fe..548a636d9941 100644--- a/services/mcp/schema/generated-tool-definitions.json+++ b/services/mcp/schema/generated-tool-definitions.json@@ -620,12 +620,12 @@}},"alert-simulate": {- "description": "Run an anomaly detector on an insight's historical data without creating any alert or check records. Use this to preview how a detector configuration would perform before saving it as an alert. Pass either the numeric insight ID or its saved short ID. Omit detector_config to use the default daily z-score detector (threshold 0.95, window 90, first-difference preprocessing). To choose another detector, pass detector_config with a type (zscore, mad, iqr, copod, ecod, hbos, isolation_forest, knn, lof, ocsvm, pca, ensemble, or llm). Always send the type explicitly: a config with no type is read as a z-score detector, and any llm-only field you sent with it is dropped without an error. The llm type makes a real model call per simulation, which is why this tool needs the alert:write scope; it is rate limited per project, and takes the same instructions, threshold (default 0.7), and window (default 90) as an llm alert; its scores are the model's confidence, not a statistical probability. Optionally specify date_from (e.g. '-48h', '-30d') to control how far back to simulate, and series_index to pick which series to analyze. Returns data values, anomaly scores per point, triggered indices and dates, and for ensemble detectors, per-sub-detector score breakdowns.",+ "description": "Run an anomaly detector on an insight's historical data without creating any alert or check records. Use this to preview how a detector configuration would perform before saving it as an alert. Pass either the numeric insight ID or its saved short ID. Omit detector_config to use the default daily z-score detector (threshold 0.95, window 90, first-difference preprocessing). To choose another detector, pass detector_config with a type (zscore, mad, iqr, copod, ecod, hbos, isolation_forest, knn, lof, ocsvm, pca, ensemble, or llm). Always send the type explicitly: a config with no type is read as a z-score detector, and any llm-only field you sent with it is dropped without an error. A statistical detector only reads, so alert:read and insight:read are enough for it. The llm type makes a real model call per simulation, so that type also needs the alert:write scope; it is rate limited per project, and takes the same instructions, threshold (default 0.7), and window (default 90) as an llm alert; its scores are the model's confidence, not a statistical probability. Optionally specify date_from (e.g. '-48h', '-30d') to control how far back to simulate, and series_index to pick which series to analyze. Returns data values, anomaly scores per point, triggered indices and dates, and for ensemble detectors, per-sub-detector score breakdowns.","category": "Alerts","feature": "alerts","summary": "Simulate detector on insight","title": "Simulate detector on insight",- "required_scopes": ["alert:write"],+ "required_scopes": ["alert:read", "insight:read"],"annotations": {"destructiveHint": false,"idempotentHint": false,diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.jsonindex e8943ba72d7b..08b91823c277 100644--- a/services/mcp/schema/tool-definitions-all.json+++ b/services/mcp/schema/tool-definitions-all.json@@ -635,12 +635,12 @@}},"alert-simulate": {- "description": "Run an anomaly detector on an insight's historical data without creating any alert or check records. Use this to preview how a detector configuration would perform before saving it as an alert. Pass either the numeric insight ID or its saved short ID. Omit detector_config to use the default daily z-score detector (threshold 0.95, window 90, first-difference preprocessing). To choose another detector, pass detector_config with a type (zscore, mad, iqr, copod, ecod, hbos, isolation_forest, knn, lof, ocsvm, pca, ensemble, or llm). Always send the type explicitly: a config with no type is read as a z-score detector, and any llm-only field you sent with it is dropped without an error. The llm type makes a real model call per simulation, which is why this tool needs the alert:write scope; it is rate limited per project, and takes the same instructions, threshold (default 0.7), and window (default 90) as an llm alert; its scores are the model's confidence, not a statistical probability. Optionally specify date_from (e.g. '-48h', '-30d') to control how far back to simulate, and series_index to pick which series to analyze. Returns data values, anomaly scores per point, triggered indices and dates, and for ensemble detectors, per-sub-detector score breakdowns.",+ "description": "Run an anomaly detector on an insight's historical data without creating any alert or check records. Use this to preview how a detector configuration would perform before saving it as an alert. Pass either the numeric insight ID or its saved short ID. Omit detector_config to use the default daily z-score detector (threshold 0.95, window 90, first-difference preprocessing). To choose another detector, pass detector_config with a type (zscore, mad, iqr, copod, ecod, hbos, isolation_forest, knn, lof, ocsvm, pca, ensemble, or llm). Always send the type explicitly: a config with no type is read as a z-score detector, and any llm-only field you sent with it is dropped without an error. A statistical detector only reads, so alert:read and insight:read are enough for it. The llm type makes a real model call per simulation, so that type also needs the alert:write scope; it is rate limited per project, and takes the same instructions, threshold (default 0.7), and window (default 90) as an llm alert; its scores are the model's confidence, not a statistical probability. Optionally specify date_from (e.g. '-48h', '-30d') to control how far back to simulate, and series_index to pick which series to analyze. Returns data values, anomaly scores per point, triggered indices and dates, and for ensemble detectors, per-sub-detector score breakdowns.","category": "Alerts","feature": "alerts","summary": "Simulate detector on insight","title": "Simulate detector on insight",- "required_scopes": ["alert:write"],+ "required_scopes": ["alert:read", "insight:read"],"annotations": {"destructiveHint": false,"idempotentHint": false,diff --git a/services/mcp/tests/unit/alert-simulate-scopes.test.ts b/services/mcp/tests/unit/alert-simulate-scopes.test.tsnew file mode 100644index 000000000000..c0b8940749e8--- /dev/null+++ b/services/mcp/tests/unit/alert-simulate-scopes.test.ts@@ -0,0 +1,27 @@+import { describe, expect, it } from 'vitest'++import { hasScopes } from '@/lib/api'+import { getToolDefinition } from '@/tools/toolDefinitions'++// The catalog filter is all-or-nothing (`hasScopes` requires every declared scope), so a scope+// stricter than AlertViewSet.simulate enforces hides the tool from a read-only scout instead of+// erroring. That viewset needs alert:read and insight:read; alert:write is demanded later, and+// only for the charged AI detector.+const READ_ONLY_SCOUT_SCOPES = ['alert:read', 'insight:read']++describe('alert simulate tool scopes', () => {+ it('stays visible to a read-only scout credential', () => {+ const required = getToolDefinition('alert-simulate').required_scopes ?? []++ expect(hasScopes(READ_ONLY_SCOUT_SCOPES, required)).toBe(true)+ })++ it.each(['alert-create', 'alert-update', 'alert-delete', 'alert-destinations-create', 'alert-destinations-delete'])(+ '%s stays hidden from a read-only scout credential',+ (toolName) => {+ const required = getToolDefinition(toolName).required_scopes ?? []++ expect(hasScopes(READ_ONLY_SCOUT_SCOPES, required)).toBe(false)+ }+ )+})