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(logs): add logs-impact mcp tool for affected sessions and users (#130219)

Jon McCallum463883dfc4b3
diff --git a/products/logs/frontend/posthogAiToolRenderers.tsx b/products/logs/frontend/posthogAiToolRenderers.tsx
index f59209745aee..2ce80b8cce2b 100644
--- a/products/logs/frontend/posthogAiToolRenderers.tsx
+++ b/products/logs/frontend/posthogAiToolRenderers.tsx
@@ -1,4 +1,13 @@
-import { IconBell, IconList, IconPulse, IconSearch, IconServer, IconStack, IconWarning } from '@posthog/icons'
+import {
+ IconBell,
+ IconList,
+ IconPeople,
+ IconPulse,
+ IconSearch,
+ IconServer,
+ IconStack,
+ IconWarning,
+} from '@posthog/icons'
import { lazyWithRetry } from 'lib/utils/retryImport'
@@ -39,6 +48,7 @@ export const posthogAiToolRenderers: ToolRegistryEntry[] = [
'Log attributes',
<IconList />
),
+ ...labelled(['logs-impact'], 'Logs impact', <IconPeople />),
...labelled(['logs-anomalies-scan', 'logs-anomalies-series-bands'], 'Log anomalies', <IconWarning />),
...labelled(
[
diff --git a/products/logs/mcp/tools.yaml b/products/logs/mcp/tools.yaml
index 0772edfd2dee..7827231f13a3 100644
--- a/products/logs/mcp/tools.yaml
+++ b/products/logs/mcp/tools.yaml
@@ -432,6 +432,39 @@ tools:
response:
exclude:
- groups.*.value
+ logs-impact:
+ operation: logs_impact_create
+ enabled: true
+ scopes:
+ - logs:read
+ annotations:
+ readOnly: true
+ destructive: false
+ idempotent: true
+ title: Count sessions and users affected by logs
+ description: >
+ Estimate how many sessions and users the logs matching a filter set touch. Use it when the user asks who an
+ error or log pattern affects, or how widespread it is.
+
+
+ Takes the same filters as `logs-count`, inside `query`, and defaults to the last hour:
+
+
+ ```json
+
+ { "query": { "serviceNames": ["api"], "dateRange": { "date_from": "-1h" } } }
+
+ ```
+
+
+ Returns the matching log total, unique `sessions` and `users` (HyperLogLog estimates), how many logs carry
+ each ID, and the top 5 session IDs and distinct IDs by log count. `sessionGroupKey` and `personGroupKey`
+ name the attribute that holds each ID: pass it to `logs-group-by` for the full breakdown.
+
+
+ Low `logsWithSessionId` or `logsWithDistinctId` means the service does not log those IDs, not that no one is
+ affected.
+ hooks: logs/redactCredentialsHooks
logs-patterns:
operation: logs_patterns_create
enabled: true
diff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.json
index 11bd82ebcdb5..0a737f284d20 100644
--- a/services/mcp/schema/generated-tool-definitions.json
+++ b/services/mcp/schema/generated-tool-definitions.json
@@ -10438,6 +10438,21 @@
},
"feature_flag": "logs-agent-tools"
},
+ "logs-impact": {
+ "description": "Estimate how many sessions and users the logs matching a filter set touch. Use it when the user asks who an error or log pattern affects, or how widespread it is.\n\nTakes the same filters as `logs-count`, inside `query`, and defaults to the last hour:\n\n```json\n{ \"query\": { \"serviceNames\": [\"api\"], \"dateRange\": { \"date_from\": \"-1h\" } } }\n```\n\nReturns the matching log total, unique `sessions` and `users` (HyperLogLog estimates), how many logs carry each ID, and the top 5 session IDs and distinct IDs by log count. `sessionGroupKey` and `personGroupKey` name the attribute that holds each ID: pass it to `logs-group-by` for the full breakdown.\n\nLow `logsWithSessionId` or `logsWithDistinctId` means the service does not log those IDs, not that no one is affected.",
+ "category": "Logs",
+ "feature": "logs",
+ "summary": "Count sessions and users affected by logs",
+ "title": "Count sessions and users affected by logs",
+ "required_scopes": ["logs:read"],
+ "api_operations": ["POST /api/projects/{project_id}/logs/impact/"],
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": true
+ }
+ },
"logs-patterns": {
"description": "Mine recurring log templates (\"patterns\") from the logs matching a filter set, ordered by frequency. Each pattern is a message template with the variable parts masked — e.g. `Connected to <ip> in <num>ms` — plus occurrence estimates, severity mix, the services it appears in, and a ready-made predicate for fetching its matching lines.\n\nAll parameters go inside `query` — top-level fields are rejected:\n\n```json\n{ \"query\": { \"serviceNames\": [\"api\"], \"dateRange\": { \"date_from\": \"-1h\" } } }\n```\n\nThis is the fastest way to understand what a log stream is _saying_ without reading raw rows: one call summarizes millions of lines into at most 200 templates.\n\n# When to use\n\n- To triage an unfamiliar or noisy stream: mine the last hour, scan the top templates by `estimated_count`, and look for anything with a non-zero error share in `severity_counts`.\n- To find what's new or dominant during an incident window: mine with `severityLevels: [\"error\", \"fatal\"]` and a `dateRange` covering the incident.\n- As the entry point of a drill-down loop: mine → pick a suspicious pattern → filter logs to exactly its lines using `match_patterns`, or `match_regex` and `match_literal` when it is empty (see below) → read the raw rows with `query-logs`.\n- To quantify repetition before proposing log sampling or cleanup: `volume_share_pct` tells you how much of the stream one template accounts for.\n\n## Pick the right tool\n\n- Raw log lines matching a filter → `query-logs`.\n- A single number (how many logs match) → `logs-count`; per-time-bucket counts → `logs-count-ranges`.\n- Distribution of a dimension (which services emit the errors?) → `logs-facet-values-create`.\n- Use **this** tool to summarize message _content_ — what distinct things the logs say and how often.\n\n# Reading the response\n\n- `source` reports what was used: `stored_patterns` for exact stored-pattern aggregation followed by Drain3 grouping, or `body_mining` for body masking and Drain3. Include this distinction in your answer.\n- `pattern_version` identifies the version used for stored patterns. `fallback_reason` explains body mining: flag disabled, insufficient version coverage, an empty window, or comparison mode.\n- The `logs_patterns_query_v2` flag enables the stored-pattern path only when one version supplies nonempty patterns for at least 99% of **all** matching rows. This is the dominant version, not necessarily the newest.\n- On the stored-pattern path, `represented_count` counts the rows in the returned groups. `remainder_count` accounts for other versions, unstamped rows, the long tail and groups outside the display limit. Report this remainder rather than implying the returned groups cover everything.\n- `pattern` — the template. Body mining masks `<uuid>`, `<ip>`, `<hex>`, `<num>`, and `<*>` for any word position that varied. Stored patterns use the ingestion vocabulary instead: `<N>`, `<TIMESTAMP>`, `<KLOGTIME>`, `<UUID>`, `<IP>`, `<HOST>`, `<HEX>`, `<ID>`, `<EMAIL>`, `<JSON_ARRAY>`, and `<JSON:keys>` for a JSON body reduced to its key set.\n- `estimated_count` / `estimated_error_count` — occurrences extrapolated to the full window. When `sampled` is false these are exact.\n- `severity_counts` — occurrences per severity, never extrapolated: sample counts when `sampled` is true, exact counts over every matching row otherwise. A template split across `info` and `error` often means the same code path logging both outcomes.\n- `services` — up to 4 service names the pattern was seen in.\n- `match_regex` — a regex over raw log bodies that matches this pattern's lines, pre-validated against the raw bodies of the pattern's own sampled rows. Always null on the stored-pattern path, which pivots with `match_patterns` instead, and null on the mining path when no trustworthy regex could be compiled. For JSON logs the pattern is mined from the extracted message field, so the regex may be unanchored, because the message is a substring of the raw line. It still targets the raw stored body.\n- `match_literal` — longest literal run of the template, a plain-text fallback when `match_regex` is null. Also null on the stored-pattern path.\n\nMining samples the window (`sampled: true` when it did): counts are estimates, and rare patterns (below roughly 1 in `scanned_count` of the volume) may be missing entirely. Narrow the `dateRange` or filters to mine a finer-grained sample.\n\n## Pivoting to a pattern's raw lines\n\nTo fetch the lines behind a pattern, call `query-logs` with the appropriate filters in `filterGroup`:\n\n- If `match_patterns` is nonempty, use **both** exact filters instead of a message predicate: `{ \"key\": \"pattern\", \"value\": [\"<canonical member>\", \"...\"], \"operator\": \"exact\", \"type\": \"log\" }` and `{ \"key\": \"pattern_version\", \"value\": 3, \"operator\": \"exact\", \"type\": \"log\" }`. Substitute the returned members and version, and combine the filters with AND. Keep the original time range and filters. Do not narrow these exact groups using example services or severities.\n- If `match_regex` is set: `{ \"key\": \"message\", \"value\": \"<match_regex>\", \"operator\": \"regex\", \"type\": \"log\" }`\n- Else if `match_literal` is set: `{ \"key\": \"message\", \"value\": \"<match_literal>\", \"operator\": \"icontains\", \"type\": \"log\" }`\n\nFor body-mined patterns, also pass the pattern's `services` as `serviceNames` and (when every entry is one of trace/debug/info/warn/error/fatal) the keys of `severity_counts` as `severityLevels` — both make the query dramatically cheaper.\n\n# Parameters\n\n## query.dateRange\n\nDate range to mine. Defaults to the last hour (`-1h`).\n\n- `date_from`: ISO 8601 timestamp or relative format: `-1h`, `-6h`, `-1d`, `-7d`.\n- `date_to`: Same format. Omit or null for \"now\".\n\n## query.severityLevels\n\nMine only these severities: `trace`, `debug`, `info`, `warn`, `error`, `fatal`. Omit to include all levels.\n\n## query.serviceNames\n\nRestrict mining to these services. Recommended once you know the target service — it prunes the scan and spends the whole sample budget on one service's templates.\n\n## query.searchTerm\n\nFull-text search over log bodies applied before mining. Useful to mine only the sub-stream around a keyword (e.g. `timeout`).\n\n## query.filterGroup\n\nProperty filters applied before mining. Same format as `query-logs` filters.\n\n# Examples\n\n## What is this stream saying? (last hour, everything)\n\n```json\n{ \"query\": { \"dateRange\": { \"date_from\": \"-1h\" } } }\n```\n\n## Dominant error templates during an incident\n\n```json\n{\n \"query\": {\n \"severityLevels\": [\"error\", \"fatal\"],\n \"dateRange\": { \"date_from\": \"2024-01-15T09:00:00Z\", \"date_to\": \"2024-01-15T11:00:00Z\" }\n }\n}\n```\n\n## Mine one service's logs around a keyword\n\n```json\n{\n \"query\": {\n \"serviceNames\": [\"checkout\"],\n \"searchTerm\": \"payment\",\n \"dateRange\": { \"date_from\": \"-6h\" }\n }\n}\n```",
"category": "Logs",
diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.json
index 9137998bfd1d..d8cea4678872 100644
--- a/services/mcp/schema/tool-definitions-all.json
+++ b/services/mcp/schema/tool-definitions-all.json
@@ -10882,6 +10882,21 @@
},
"feature_flag": "logs-agent-tools"
},
+ "logs-impact": {
+ "description": "Estimate how many sessions and users the logs matching a filter set touch. Use it when the user asks who an error or log pattern affects, or how widespread it is.\n\nTakes the same filters as `logs-count`, inside `query`, and defaults to the last hour:\n\n```json\n{ \"query\": { \"serviceNames\": [\"api\"], \"dateRange\": { \"date_from\": \"-1h\" } } }\n```\n\nReturns the matching log total, unique `sessions` and `users` (HyperLogLog estimates), how many logs carry each ID, and the top 5 session IDs and distinct IDs by log count. `sessionGroupKey` and `personGroupKey` name the attribute that holds each ID: pass it to `logs-group-by` for the full breakdown.\n\nLow `logsWithSessionId` or `logsWithDistinctId` means the service does not log those IDs, not that no one is affected.",
+ "category": "Logs",
+ "feature": "logs",
+ "summary": "Count sessions and users affected by logs",
+ "title": "Count sessions and users affected by logs",
+ "required_scopes": ["logs:read"],
+ "api_operations": ["POST /api/projects/{project_id}/logs/impact/"],
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": true
+ }
+ },
"logs-patterns": {
"description": "Mine recurring log templates (\"patterns\") from the logs matching a filter set, ordered by frequency. Each pattern is a message template with the variable parts masked — e.g. `Connected to <ip> in <num>ms` — plus occurrence estimates, severity mix, the services it appears in, and a ready-made predicate for fetching its matching lines.\n\nAll parameters go inside `query` — top-level fields are rejected:\n\n```json\n{ \"query\": { \"serviceNames\": [\"api\"], \"dateRange\": { \"date_from\": \"-1h\" } } }\n```\n\nThis is the fastest way to understand what a log stream is _saying_ without reading raw rows: one call summarizes millions of lines into at most 200 templates.\n\n# When to use\n\n- To triage an unfamiliar or noisy stream: mine the last hour, scan the top templates by `estimated_count`, and look for anything with a non-zero error share in `severity_counts`.\n- To find what's new or dominant during an incident window: mine with `severityLevels: [\"error\", \"fatal\"]` and a `dateRange` covering the incident.\n- As the entry point of a drill-down loop: mine → pick a suspicious pattern → filter logs to exactly its lines using `match_patterns`, or `match_regex` and `match_literal` when it is empty (see below) → read the raw rows with `query-logs`.\n- To quantify repetition before proposing log sampling or cleanup: `volume_share_pct` tells you how much of the stream one template accounts for.\n\n## Pick the right tool\n\n- Raw log lines matching a filter → `query-logs`.\n- A single number (how many logs match) → `logs-count`; per-time-bucket counts → `logs-count-ranges`.\n- Distribution of a dimension (which services emit the errors?) → `logs-facet-values-create`.\n- Use **this** tool to summarize message _content_ — what distinct things the logs say and how often.\n\n# Reading the response\n\n- `source` reports what was used: `stored_patterns` for exact stored-pattern aggregation followed by Drain3 grouping, or `body_mining` for body masking and Drain3. Include this distinction in your answer.\n- `pattern_version` identifies the version used for stored patterns. `fallback_reason` explains body mining: flag disabled, insufficient version coverage, an empty window, or comparison mode.\n- The `logs_patterns_query_v2` flag enables the stored-pattern path only when one version supplies nonempty patterns for at least 99% of **all** matching rows. This is the dominant version, not necessarily the newest.\n- On the stored-pattern path, `represented_count` counts the rows in the returned groups. `remainder_count` accounts for other versions, unstamped rows, the long tail and groups outside the display limit. Report this remainder rather than implying the returned groups cover everything.\n- `pattern` — the template. Body mining masks `<uuid>`, `<ip>`, `<hex>`, `<num>`, and `<*>` for any word position that varied. Stored patterns use the ingestion vocabulary instead: `<N>`, `<TIMESTAMP>`, `<KLOGTIME>`, `<UUID>`, `<IP>`, `<HOST>`, `<HEX>`, `<ID>`, `<EMAIL>`, `<JSON_ARRAY>`, and `<JSON:keys>` for a JSON body reduced to its key set.\n- `estimated_count` / `estimated_error_count` — occurrences extrapolated to the full window. When `sampled` is false these are exact.\n- `severity_counts` — occurrences per severity, never extrapolated: sample counts when `sampled` is true, exact counts over every matching row otherwise. A template split across `info` and `error` often means the same code path logging both outcomes.\n- `services` — up to 4 service names the pattern was seen in.\n- `match_regex` — a regex over raw log bodies that matches this pattern's lines, pre-validated against the raw bodies of the pattern's own sampled rows. Always null on the stored-pattern path, which pivots with `match_patterns` instead, and null on the mining path when no trustworthy regex could be compiled. For JSON logs the pattern is mined from the extracted message field, so the regex may be unanchored, because the message is a substring of the raw line. It still targets the raw stored body.\n- `match_literal` — longest literal run of the template, a plain-text fallback when `match_regex` is null. Also null on the stored-pattern path.\n\nMining samples the window (`sampled: true` when it did): counts are estimates, and rare patterns (below roughly 1 in `scanned_count` of the volume) may be missing entirely. Narrow the `dateRange` or filters to mine a finer-grained sample.\n\n## Pivoting to a pattern's raw lines\n\nTo fetch the lines behind a pattern, call `query-logs` with the appropriate filters in `filterGroup`:\n\n- If `match_patterns` is nonempty, use **both** exact filters instead of a message predicate: `{ \"key\": \"pattern\", \"value\": [\"<canonical member>\", \"...\"], \"operator\": \"exact\", \"type\": \"log\" }` and `{ \"key\": \"pattern_version\", \"value\": 3, \"operator\": \"exact\", \"type\": \"log\" }`. Substitute the returned members and version, and combine the filters with AND. Keep the original time range and filters. Do not narrow these exact groups using example services or severities.\n- If `match_regex` is set: `{ \"key\": \"message\", \"value\": \"<match_regex>\", \"operator\": \"regex\", \"type\": \"log\" }`\n- Else if `match_literal` is set: `{ \"key\": \"message\", \"value\": \"<match_literal>\", \"operator\": \"icontains\", \"type\": \"log\" }`\n\nFor body-mined patterns, also pass the pattern's `services` as `serviceNames` and (when every entry is one of trace/debug/info/warn/error/fatal) the keys of `severity_counts` as `severityLevels` — both make the query dramatically cheaper.\n\n# Parameters\n\n## query.dateRange\n\nDate range to mine. Defaults to the last hour (`-1h`).\n\n- `date_from`: ISO 8601 timestamp or relative format: `-1h`, `-6h`, `-1d`, `-7d`.\n- `date_to`: Same format. Omit or null for \"now\".\n\n## query.severityLevels\n\nMine only these severities: `trace`, `debug`, `info`, `warn`, `error`, `fatal`. Omit to include all levels.\n\n## query.serviceNames\n\nRestrict mining to these services. Recommended once you know the target service — it prunes the scan and spends the whole sample budget on one service's templates.\n\n## query.searchTerm\n\nFull-text search over log bodies applied before mining. Useful to mine only the sub-stream around a keyword (e.g. `timeout`).\n\n## query.filterGroup\n\nProperty filters applied before mining. Same format as `query-logs` filters.\n\n# Examples\n\n## What is this stream saying? (last hour, everything)\n\n```json\n{ \"query\": { \"dateRange\": { \"date_from\": \"-1h\" } } }\n```\n\n## Dominant error templates during an incident\n\n```json\n{\n \"query\": {\n \"severityLevels\": [\"error\", \"fatal\"],\n \"dateRange\": { \"date_from\": \"2024-01-15T09:00:00Z\", \"date_to\": \"2024-01-15T11:00:00Z\" }\n }\n}\n```\n\n## Mine one service's logs around a keyword\n\n```json\n{\n \"query\": {\n \"serviceNames\": [\"checkout\"],\n \"searchTerm\": \"payment\",\n \"dateRange\": { \"date_from\": \"-6h\" }\n }\n}\n```",
"category": "Logs",
diff --git a/services/mcp/src/generated/logs/api.ts b/services/mcp/src/generated/logs/api.ts
index a7d61589f5d9..f6e13c6c147f 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 22 enabled ops
+ * PostHog API - MCP 23 enabled ops
* OpenAPI spec version: 1.0.0
*/
import * as zod from 'zod'
@@ -6331,6 +6331,100 @@ export const LogsGroupByCreateBody = () => zod.object({
.describe('The group-by query to execute.'),
})
+export const LogsImpactCreateParams = () => 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 LogsImpactCreateBody = () => zod.object({
+ query: zod
+ .object({
+ dateRange: zod
+ .object({
+ date_from: zod
+ .string()
+ .nullish()
+ .describe(
+ 'Start of the date range. Accepts ISO 8601 timestamps or relative formats: -7d, -1h, -1mStart, etc.'
+ ),
+ date_to: zod
+ .string()
+ .nullish()
+ .describe('End of the date range. Same format as date_from. Omit or null for \"now\".'),
+ })
+ .optional()
+ .describe('Date range for the count. Defaults to last hour.'),
+ severityLevels: zod
+ .array(
+ zod
+ .enum(['trace', 'debug', 'info', 'warn', 'error', 'fatal'])
+ .describe(
+ '\* `trace` - trace\n\* `debug` - debug\n\* `info` - info\n\* `warn` - warn\n\* `error` - error\n\* `fatal` - fatal'
+ )
+ )
+ .optional()
+ .describe('Filter by log severity levels.'),
+ serviceNames: zod.array(zod.string()).optional().describe('Filter by service names.'),
+ searchTerm: zod.string().optional().describe('Full-text search term to filter log bodies.'),
+ filterGroup: zod
+ .array(
+ zod.object({
+ key: zod
+ .string()
+ .describe(
+ 'Attribute key. For type \"log\", use \"message\" for the body text, or a log column: \"pattern\" and \"pattern_version\" (the patterns pivot), \"severity_level\", \"service_name\", \"trace_id\", \"span_id\". For \"log_attribute\"\/\"log_resource_attribute\", use the attribute key (e.g. \"k8s.container.name\").'
+ ),
+ type: zod
+ .enum(['log', 'log_attribute', 'log_resource_attribute'])
+ .describe(
+ '\* `log` - log\n\* `log_attribute` - log_attribute\n\* `log_resource_attribute` - log_resource_attribute'
+ )
+ .describe(
+ '\"log\" filters the log body\/message. \"log_attribute\" filters log-level attributes. \"log_resource_attribute\" filters resource-level attributes.\n\n\* `log` - log\n\* `log_attribute` - log_attribute\n\* `log_resource_attribute` - log_resource_attribute'
+ ),
+ operator: zod
+ .enum([
+ 'exact',
+ 'is_not',
+ 'icontains',
+ 'not_icontains',
+ 'starts_with',
+ 'not_starts_with',
+ 'ends_with',
+ 'not_ends_with',
+ 'regex',
+ 'not_regex',
+ 'gt',
+ 'lt',
+ 'is_date_exact',
+ 'is_date_before',
+ 'is_date_after',
+ 'is_set',
+ 'is_not_set',
+ ])
+ .describe(
+ '\* `exact` - exact\n\* `is_not` - is_not\n\* `icontains` - icontains\n\* `not_icontains` - not_icontains\n\* `starts_with` - starts_with\n\* `not_starts_with` - not_starts_with\n\* `ends_with` - ends_with\n\* `not_ends_with` - not_ends_with\n\* `regex` - regex\n\* `not_regex` - not_regex\n\* `gt` - gt\n\* `lt` - lt\n\* `is_date_exact` - is_date_exact\n\* `is_date_before` - is_date_before\n\* `is_date_after` - is_date_after\n\* `is_set` - is_set\n\* `is_not_set` - is_not_set'
+ )
+ .describe(
+ 'Comparison operator.\n\n\* `exact` - exact\n\* `is_not` - is_not\n\* `icontains` - icontains\n\* `not_icontains` - not_icontains\n\* `starts_with` - starts_with\n\* `not_starts_with` - not_starts_with\n\* `ends_with` - ends_with\n\* `not_ends_with` - not_ends_with\n\* `regex` - regex\n\* `not_regex` - not_regex\n\* `gt` - gt\n\* `lt` - lt\n\* `is_date_exact` - is_date_exact\n\* `is_date_before` - is_date_before\n\* `is_date_after` - is_date_after\n\* `is_set` - is_set\n\* `is_not_set` - is_not_set'
+ ),
+ value: zod
+ .unknown()
+ .optional()
+ .describe(
+ 'Value to compare against. String, number, or array of strings. Omit for is_set\/is_not_set operators.'
+ ),
+ })
+ )
+ .optional()
+ .describe('Property filters for the query.'),
+ })
+ .describe('The impact query to execute. Takes the same filters as the count query.'),
+})
+
export const LogsPatternsCreateParams = () => zod.object({
project_id: zod
.string()
diff --git a/services/mcp/src/tools/generated/logs.ts b/services/mcp/src/tools/generated/logs.ts
index a4c2f5a7ee90..1a9d40898eb0 100644
--- a/services/mcp/src/tools/generated/logs.ts
+++ b/services/mcp/src/tools/generated/logs.ts
@@ -5,6 +5,7 @@ import type { Schemas } from '@/api/generated'
import * as orvalSchemas from '@/generated/logs/api'
import hooks_logsAttributeValuesList from '@/tools/logs/redactCredentialsHooks'
import hooks_logsFacetValuesCreate from '@/tools/logs/redactCredentialsHooks'
+import hooks_logsImpact from '@/tools/logs/redactCredentialsHooks'
import hooks_logsPatterns from '@/tools/logs/redactCredentialsHooks'
import hooks_logsPatternsDiff from '@/tools/logs/redactCredentialsHooks'
import hooks_queryLogs from '@/tools/logs/redactCredentialsHooks'
@@ -722,6 +723,32 @@ const logsGroupBy = (): ToolBase<ReturnType<typeof LogsGroupBySchema>, Schemas._
},
})
+const LogsImpactSchema = () => {
+ const LogsImpactCreateBody = orvalSchemas.LogsImpactCreateBody()
+ return LogsImpactCreateBody
+}
+
+const logsImpact = (): ToolBase<ReturnType<typeof LogsImpactSchema>, Schemas._LogsImpactResponse> => ({
+ name: 'logs-impact',
+ schema: LogsImpactSchema(),
+ handler: withToolHooks(
+ hooks_logsImpact,
+ async (context: Context, params: z.infer<ReturnType<typeof LogsImpactSchema>>) => {
+ const projectId = await context.stateManager.getProjectId()
+ const body: Record<string, unknown> = {}
+ if (params.query !== undefined) {
+ body['query'] = params.query
+ }
+ const result = await context.api.request<Schemas._LogsImpactResponse>({
+ method: 'POST',
+ path: `/api/projects/${encodeURIComponent(String(projectId))}/logs/impact/`,
+ body: await transformRequestBody(hooks_logsImpact, context, params, body),
+ })
+ return result
+ }
+ ),
+})
+
const LogsPatternsSchema = () => {
const LogsPatternsCreateBody = orvalSchemas.LogsPatternsCreateBody()
return LogsPatternsCreateBody
@@ -902,6 +929,7 @@ export const GENERATED_TOOLS: Record<string, () => ToolBase<ZodObjectAny>> = {
'logs-count-ranges': logsCountRanges,
'logs-facet-values-create': logsFacetValuesCreate,
'logs-group-by': logsGroupBy,
+ 'logs-impact': logsImpact,
'logs-patterns': logsPatterns,
'logs-patterns-diff': logsPatternsDiff,
'logs-services-create': logsServicesCreate,
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/logs-impact.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/logs-impact.json
new file mode 100644
index 000000000000..736c49767e18
--- /dev/null
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/logs-impact.json
@@ -0,0 +1,106 @@
+{
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
+ "properties": {
+ "query": {
+ "description": "The impact query to execute. Takes the same filters as the count query.",
+ "properties": {
+ "dateRange": {
+ "description": "Date range for the count. Defaults to last hour.",
+ "properties": {
+ "date_from": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Start of the date range. Accepts ISO 8601 timestamps or relative formats: -7d, -1h, -1mStart, etc."
+ },
+ "date_to": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "End of the date range. Same format as date_from. Omit or null for \"now\"."
+ }
+ },
+ "type": "object"
+ },
+ "filterGroup": {
+ "description": "Property filters for the query.",
+ "items": {
+ "properties": {
+ "key": {
+ "description": "Attribute key. For type \"log\", use \"message\" for the body text, or a log column: \"pattern\" and \"pattern_version\" (the patterns pivot), \"severity_level\", \"service_name\", \"trace_id\", \"span_id\". For \"log_attribute\"/\"log_resource_attribute\", use the attribute key (e.g. \"k8s.container.name\").",
+ "type": "string"
+ },
+ "operator": {
+ "description": "Comparison operator.\n\n* `exact` - exact\n* `is_not` - is_not\n* `icontains` - icontains\n* `not_icontains` - not_icontains\n* `starts_with` - starts_with\n* `not_starts_with` - not_starts_with\n* `ends_with` - ends_with\n* `not_ends_with` - not_ends_with\n* `regex` - regex\n* `not_regex` - not_regex\n* `gt` - gt\n* `lt` - lt\n* `is_date_exact` - is_date_exact\n* `is_date_before` - is_date_before\n* `is_date_after` - is_date_after\n* `is_set` - is_set\n* `is_not_set` - is_not_set",
+ "enum": [
+ "exact",
+ "is_not",
+ "icontains",
+ "not_icontains",
+ "starts_with",
+ "not_starts_with",
+ "ends_with",
+ "not_ends_with",
+ "regex",
+ "not_regex",
+ "gt",
+ "lt",
+ "is_date_exact",
+ "is_date_before",
+ "is_date_after",
+ "is_set",
+ "is_not_set"
+ ],
+ "type": "string"
+ },
+ "type": {
+ "description": "\"log\" filters the log body/message. \"log_attribute\" filters log-level attributes. \"log_resource_attribute\" filters resource-level attributes.\n\n* `log` - log\n* `log_attribute` - log_attribute\n* `log_resource_attribute` - log_resource_attribute",
+ "enum": ["log", "log_attribute", "log_resource_attribute"],
+ "type": "string"
+ },
+ "value": {
+ "description": "Value to compare against. String, number, or array of strings. Omit for is_set/is_not_set operators."
+ }
+ },
+ "required": ["key", "type", "operator"],
+ "type": "object"
+ },
+ "type": "array"
+ },
+ "searchTerm": {
+ "description": "Full-text search term to filter log bodies.",
+ "type": "string"
+ },
+ "serviceNames": {
+ "description": "Filter by service names.",
+ "items": {
+ "type": "string"
+ },
+ "type": "array"
+ },
+ "severityLevels": {
+ "description": "Filter by log severity levels.",
+ "items": {
+ "description": "* `trace` - trace\n* `debug` - debug\n* `info` - info\n* `warn` - warn\n* `error` - error\n* `fatal` - fatal",
+ "enum": ["trace", "debug", "info", "warn", "error", "fatal"],
+ "type": "string"
+ },
+ "type": "array"
+ }
+ },
+ "type": "object"
+ }
+ },
+ "required": ["query"],
+ "type": "object"
+}