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): expose facet values as an MCP tool (#67326)

Jon McCallum63efb616adb6
diff --git a/products/logs/mcp/prompts/logs-facet-values.md b/products/logs/mcp/prompts/logs-facet-values.md
new file mode 100644
index 000000000000..debe3763ebe2
--- /dev/null
+++ b/products/logs/mcp/prompts/logs-facet-values.md
@@ -0,0 +1,105 @@
+Return per-value counts for a single facet — the distribution of a log dimension across a filter set, ordered by count descending. This is the cheap way to see the _shape_ of a log stream (e.g. "which services produce the errors?") without pulling raw rows.
+
+Counts are cross-filtered: every active filter is applied _except the faceted field's own filter_, so you see the full distribution rather than collapsing to your own selection. Faceting `service_name` with `serviceNames: ["api"]` still returns every service, not just `api`.
+
+All parameters must be nested inside a `query` object. You must provide **exactly one** of `query.facetField` or `query.facetResourceAttribute` — not both, not neither.
+
+# When to use
+
+- To find how log volume is distributed across severity or service under a filter — e.g. "of the logs matching 'timeout', which services emit them?" Facet `service_name` with `searchTerm: "timeout"`.
+- As the drill-down loop for an investigation: facet `service_name` filtered to `severity=error` → find the hot service → add it to `serviceNames` → facet a resource attribute like `k8s.pod.name` → find the bad pod. Each call is one cheap aggregation that narrows the search space before you pull raw rows with `query-logs`.
+- To confirm the severity mix in a window before committing to a query: facet `severity_text`.
+
+## Pick the right tool
+
+- Counts for an arbitrary **attribute** value (any log or resource attribute key) → use `logs-attribute-values-list`. It returns `{value, count}` for any key and is the general-purpose choice for attributes.
+- Per-service log/error counts and error rates with a sparkline → use `logs-services-create`.
+- Use **this** tool for `severity_text` / `service_name` distribution cross-filtered by the full query (severity + body `searchTerm` + `filterGroup`) — the one thing the tools above can't do.
+
+# Parameters
+
+## query.facetField
+
+Top-level column to facet on: `severity_text` or `service_name`. Provide this OR `facetResourceAttribute`, not both. Counts are grouped on the raw logs table with all _other_ filters applied — so this path honors `severityLevels`, `serviceNames`, `searchTerm`, and `filterGroup`.
+
+## query.facetResourceAttribute
+
+Resource attribute key to facet on, e.g. `k8s.namespace.name`, `k8s.pod.name`, `host.name`. Provide this OR `facetField`, not both.
+
+**Limitation:** this path is served from a pre-aggregated rollup that has no severity or body dimension. It honors only `serviceNames` and other resource-attribute filters — `severityLevels`, `searchTerm`, and log-attribute filters are **ignored**. If you need those applied, facet a column instead, or narrow with `logs-attribute-values-list`.
+
+## query.facetSearch
+
+Case-insensitive substring match over the faceted field's _own_ values (e.g. return only service names containing `kafka`). Distinct from `searchTerm`, which searches log bodies. Use it to search past the 100-value result cap.
+
+## query.dateRange
+
+Date range for the counts. Defaults to the last hour (`-1h`).
+
+- `date_from`: Start of the range. ISO 8601 timestamps or relative formats: `-1h`, `-6h`, `-1d`, `-7d`.
+- `date_to`: End of the range. Same format. Omit or null for "now".
+
+## query.severityLevels
+
+Filter by log severity: `trace`, `debug`, `info`, `warn`, `error`, `fatal`. Omit to include all levels. Ignored when faceting on `severity_text` (that field's own filter is excluded) and when faceting a resource attribute (rollup has no severity dimension).
+
+## query.serviceNames
+
+Filter by service names. Ignored when faceting on `service_name` (that field's own filter is excluded).
+
+## query.searchTerm
+
+Full-text search across log bodies. Ignored when faceting a resource attribute.
+
+## query.filterGroup
+
+Property filters to narrow results. Same format as `query-logs` filters.
+
+# Examples
+
+## Severity distribution in the last hour
+
+```json
+{
+ "query": {
+ "facetField": "severity_text",
+ "dateRange": { "date_from": "-1h" }
+ }
+}
+```
+
+## Which services produce errors over the last day
+
+```json
+{
+ "query": {
+ "facetField": "service_name",
+ "severityLevels": ["error", "fatal"],
+ "dateRange": { "date_from": "-1d" }
+ }
+}
+```
+
+## Which pods a service's logs come from
+
+```json
+{
+ "query": {
+ "facetResourceAttribute": "k8s.pod.name",
+ "serviceNames": ["checkout"],
+ "dateRange": { "date_from": "-6h" }
+ }
+}
+```
+
+## Which services emit a specific error message
+
+```json
+{
+ "query": {
+ "facetField": "service_name",
+ "searchTerm": "connection reset",
+ "dateRange": { "date_from": "-1d" }
+ }
+}
+```
diff --git a/products/logs/mcp/tools.yaml b/products/logs/mcp/tools.yaml
index 36025545584d..e510807554a7 100644
--- a/products/logs/mcp/tools.yaml
+++ b/products/logs/mcp/tools.yaml
@@ -343,7 +343,18 @@ tools:
enabled: false
logs-facet-values-create:
operation: logs_facet_values_create
- enabled: false
+ enabled: true
+ scopes:
+ - logs:read
+ annotations:
+ readOnly: true
+ destructive: false
+ idempotent: true
+ title: Facet log counts
+ description_file: ./prompts/logs-facet-values.md
+ response:
+ include:
+ - results
logs-has-logs-retrieve:
operation: logs_has_logs_retrieve
enabled: false
diff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.json
index 9fc1d2d99249..09cc4ce355d4 100644
--- a/services/mcp/schema/generated-tool-definitions.json
+++ b/services/mcp/schema/generated-tool-definitions.json
@@ -5345,6 +5345,20 @@
"readOnlyHint": true
}
},
+ "logs-facet-values-create": {
+ "description": "Return per-value counts for a single facet — the distribution of a log dimension across a filter set, ordered by count descending. This is the cheap way to see the _shape_ of a log stream (e.g. \"which services produce the errors?\") without pulling raw rows.\n\nCounts are cross-filtered: every active filter is applied _except the faceted field's own filter_, so you see the full distribution rather than collapsing to your own selection. Faceting `service_name` with `serviceNames: [\"api\"]` still returns every service, not just `api`.\n\nAll parameters must be nested inside a `query` object. You must provide **exactly one** of `query.facetField` or `query.facetResourceAttribute` — not both, not neither.\n\n# When to use\n\n- To find how log volume is distributed across severity or service under a filter — e.g. \"of the logs matching 'timeout', which services emit them?\" Facet `service_name` with `searchTerm: \"timeout\"`.\n- As the drill-down loop for an investigation: facet `service_name` filtered to `severity=error` → find the hot service → add it to `serviceNames` → facet a resource attribute like `k8s.pod.name` → find the bad pod. Each call is one cheap aggregation that narrows the search space before you pull raw rows with `query-logs`.\n- To confirm the severity mix in a window before committing to a query: facet `severity_text`.\n\n## Pick the right tool\n\n- Counts for an arbitrary **attribute** value (any log or resource attribute key) → use `logs-attribute-values-list`. It returns `{value, count}` for any key and is the general-purpose choice for attributes.\n- Per-service log/error counts and error rates with a sparkline → use `logs-services-create`.\n- Use **this** tool for `severity_text` / `service_name` distribution cross-filtered by the full query (severity + body `searchTerm` + `filterGroup`) — the one thing the tools above can't do.\n\n# Parameters\n\n## query.facetField\n\nTop-level column to facet on: `severity_text` or `service_name`. Provide this OR `facetResourceAttribute`, not both. Counts are grouped on the raw logs table with all _other_ filters applied — so this path honors `severityLevels`, `serviceNames`, `searchTerm`, and `filterGroup`.\n\n## query.facetResourceAttribute\n\nResource attribute key to facet on, e.g. `k8s.namespace.name`, `k8s.pod.name`, `host.name`. Provide this OR `facetField`, not both.\n\n**Limitation:** this path is served from a pre-aggregated rollup that has no severity or body dimension. It honors only `serviceNames` and other resource-attribute filters — `severityLevels`, `searchTerm`, and log-attribute filters are **ignored**. If you need those applied, facet a column instead, or narrow with `logs-attribute-values-list`.\n\n## query.facetSearch\n\nCase-insensitive substring match over the faceted field's _own_ values (e.g. return only service names containing `kafka`). Distinct from `searchTerm`, which searches log bodies. Use it to search past the 100-value result cap.\n\n## query.dateRange\n\nDate range for the counts. Defaults to the last hour (`-1h`).\n\n- `date_from`: Start of the range. ISO 8601 timestamps or relative formats: `-1h`, `-6h`, `-1d`, `-7d`.\n- `date_to`: End of the range. Same format. Omit or null for \"now\".\n\n## query.severityLevels\n\nFilter by log severity: `trace`, `debug`, `info`, `warn`, `error`, `fatal`. Omit to include all levels. Ignored when faceting on `severity_text` (that field's own filter is excluded) and when faceting a resource attribute (rollup has no severity dimension).\n\n## query.serviceNames\n\nFilter by service names. Ignored when faceting on `service_name` (that field's own filter is excluded).\n\n## query.searchTerm\n\nFull-text search across log bodies. Ignored when faceting a resource attribute.\n\n## query.filterGroup\n\nProperty filters to narrow results. Same format as `query-logs` filters.\n\n# Examples\n\n## Severity distribution in the last hour\n\n```json\n{\n \"query\": {\n \"facetField\": \"severity_text\",\n \"dateRange\": { \"date_from\": \"-1h\" }\n }\n}\n```\n\n## Which services produce errors over the last day\n\n```json\n{\n \"query\": {\n \"facetField\": \"service_name\",\n \"severityLevels\": [\"error\", \"fatal\"],\n \"dateRange\": { \"date_from\": \"-1d\" }\n }\n}\n```\n\n## Which pods a service's logs come from\n\n```json\n{\n \"query\": {\n \"facetResourceAttribute\": \"k8s.pod.name\",\n \"serviceNames\": [\"checkout\"],\n \"dateRange\": { \"date_from\": \"-6h\" }\n }\n}\n```\n\n## Which services emit a specific error message\n\n```json\n{\n \"query\": {\n \"facetField\": \"service_name\",\n \"searchTerm\": \"connection reset\",\n \"dateRange\": { \"date_from\": \"-1d\" }\n }\n}\n```",
+ "category": "Logs",
+ "feature": "logs",
+ "summary": "Facet log counts",
+ "title": "Facet log counts",
+ "required_scopes": ["logs:read"],
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": true
+ }
+ },
"logs-services-create": {
"description": "Return the top-25 services by log volume in the window, each with log_count, error_count, and error_rate, plus a per-service sparkline. Use this as the entry point when triaging which services are worth alerting on — high volume × non-zero error_rate is the natural alert candidate. Far cheaper than walking attribute-values + per-service counts.",
"category": "Logs",
diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.json
index 185a5200c26a..d61e537d090d 100644
--- a/services/mcp/schema/tool-definitions-all.json
+++ b/services/mcp/schema/tool-definitions-all.json
@@ -5781,6 +5781,20 @@
"readOnlyHint": true
}
},
+ "logs-facet-values-create": {
+ "description": "Return per-value counts for a single facet — the distribution of a log dimension across a filter set, ordered by count descending. This is the cheap way to see the _shape_ of a log stream (e.g. \"which services produce the errors?\") without pulling raw rows.\n\nCounts are cross-filtered: every active filter is applied _except the faceted field's own filter_, so you see the full distribution rather than collapsing to your own selection. Faceting `service_name` with `serviceNames: [\"api\"]` still returns every service, not just `api`.\n\nAll parameters must be nested inside a `query` object. You must provide **exactly one** of `query.facetField` or `query.facetResourceAttribute` — not both, not neither.\n\n# When to use\n\n- To find how log volume is distributed across severity or service under a filter — e.g. \"of the logs matching 'timeout', which services emit them?\" Facet `service_name` with `searchTerm: \"timeout\"`.\n- As the drill-down loop for an investigation: facet `service_name` filtered to `severity=error` → find the hot service → add it to `serviceNames` → facet a resource attribute like `k8s.pod.name` → find the bad pod. Each call is one cheap aggregation that narrows the search space before you pull raw rows with `query-logs`.\n- To confirm the severity mix in a window before committing to a query: facet `severity_text`.\n\n## Pick the right tool\n\n- Counts for an arbitrary **attribute** value (any log or resource attribute key) → use `logs-attribute-values-list`. It returns `{value, count}` for any key and is the general-purpose choice for attributes.\n- Per-service log/error counts and error rates with a sparkline → use `logs-services-create`.\n- Use **this** tool for `severity_text` / `service_name` distribution cross-filtered by the full query (severity + body `searchTerm` + `filterGroup`) — the one thing the tools above can't do.\n\n# Parameters\n\n## query.facetField\n\nTop-level column to facet on: `severity_text` or `service_name`. Provide this OR `facetResourceAttribute`, not both. Counts are grouped on the raw logs table with all _other_ filters applied — so this path honors `severityLevels`, `serviceNames`, `searchTerm`, and `filterGroup`.\n\n## query.facetResourceAttribute\n\nResource attribute key to facet on, e.g. `k8s.namespace.name`, `k8s.pod.name`, `host.name`. Provide this OR `facetField`, not both.\n\n**Limitation:** this path is served from a pre-aggregated rollup that has no severity or body dimension. It honors only `serviceNames` and other resource-attribute filters — `severityLevels`, `searchTerm`, and log-attribute filters are **ignored**. If you need those applied, facet a column instead, or narrow with `logs-attribute-values-list`.\n\n## query.facetSearch\n\nCase-insensitive substring match over the faceted field's _own_ values (e.g. return only service names containing `kafka`). Distinct from `searchTerm`, which searches log bodies. Use it to search past the 100-value result cap.\n\n## query.dateRange\n\nDate range for the counts. Defaults to the last hour (`-1h`).\n\n- `date_from`: Start of the range. ISO 8601 timestamps or relative formats: `-1h`, `-6h`, `-1d`, `-7d`.\n- `date_to`: End of the range. Same format. Omit or null for \"now\".\n\n## query.severityLevels\n\nFilter by log severity: `trace`, `debug`, `info`, `warn`, `error`, `fatal`. Omit to include all levels. Ignored when faceting on `severity_text` (that field's own filter is excluded) and when faceting a resource attribute (rollup has no severity dimension).\n\n## query.serviceNames\n\nFilter by service names. Ignored when faceting on `service_name` (that field's own filter is excluded).\n\n## query.searchTerm\n\nFull-text search across log bodies. Ignored when faceting a resource attribute.\n\n## query.filterGroup\n\nProperty filters to narrow results. Same format as `query-logs` filters.\n\n# Examples\n\n## Severity distribution in the last hour\n\n```json\n{\n \"query\": {\n \"facetField\": \"severity_text\",\n \"dateRange\": { \"date_from\": \"-1h\" }\n }\n}\n```\n\n## Which services produce errors over the last day\n\n```json\n{\n \"query\": {\n \"facetField\": \"service_name\",\n \"severityLevels\": [\"error\", \"fatal\"],\n \"dateRange\": { \"date_from\": \"-1d\" }\n }\n}\n```\n\n## Which pods a service's logs come from\n\n```json\n{\n \"query\": {\n \"facetResourceAttribute\": \"k8s.pod.name\",\n \"serviceNames\": [\"checkout\"],\n \"dateRange\": { \"date_from\": \"-6h\" }\n }\n}\n```\n\n## Which services emit a specific error message\n\n```json\n{\n \"query\": {\n \"facetField\": \"service_name\",\n \"searchTerm\": \"connection reset\",\n \"dateRange\": { \"date_from\": \"-1d\" }\n }\n}\n```",
+ "category": "Logs",
+ "feature": "logs",
+ "summary": "Facet log counts",
+ "title": "Facet log counts",
+ "required_scopes": ["logs:read"],
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": true
+ }
+ },
"logs-services-create": {
"description": "Return the top-25 services by log volume in the window, each with log_count, error_count, and error_rate, plus a per-service sparkline. Use this as the entry point when triaging which services are worth alerting on — high volume × non-zero error_rate is the natural alert candidate. Far cheaper than walking attribute-values + per-service counts.",
"category": "Logs",
diff --git a/services/mcp/src/generated/logs/api.ts b/services/mcp/src/generated/logs/api.ts
index 93dcbb8ca45b..18aeb61222f8 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 16 enabled ops
+ * PostHog API - MCP 17 enabled ops
* OpenAPI spec version: 1.0.0
*/
import * as zod from 'zod'
@@ -3879,6 +3879,122 @@ export const LogsCountRangesCreateBody = /* @__PURE__ */ zod.object({
.describe('The bucketed-count query to execute.'),
})
+export const LogsFacetValuesCreateParams = /* @__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 LogsFacetValuesCreateBody = /* @__PURE__ */ zod.object({
+ query: zod
+ .object({
+ facetField: zod
+ .union([
+ zod
+ .enum(['severity_text', 'service_name'])
+ .describe('* `severity_text` - severity_text\n* `service_name` - service_name'),
+ zod.null(),
+ ])
+ .optional()
+ .describe(
+ 'Top-level column to facet on. Provide exactly one of facetField or facetResourceAttribute. Its own filter is excluded so counts reflect the other active filters.\n\n* `severity_text` - severity_text\n* `service_name` - service_name'
+ ),
+ facetResourceAttribute: zod
+ .string()
+ .nullish()
+ .describe(
+ "Resource attribute key to facet on (e.g. 'k8s.namespace.name'). Provide exactly one of facetField or facetResourceAttribute. Its own log_resource_attribute filter is excluded so counts reflect the other active filters."
+ ),
+ 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. 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 (ignored when faceting on severity_text).'),
+ serviceNames: zod
+ .array(zod.string())
+ .optional()
+ .describe('Filter by service names (ignored when faceting on service_name).'),
+ searchTerm: zod.string().optional().describe('Full-text search term to filter log bodies.'),
+ facetSearch: zod
+ .string()
+ .optional()
+ .describe(
+ "Type-ahead filter over the faceted field's own values (case-insensitive substring match). Distinct from searchTerm, which searches log bodies."
+ ),
+ filterGroup: zod
+ .array(
+ zod.object({
+ key: zod
+ .string()
+ .describe(
+ 'Attribute key. For type "log", use "message". 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',
+ '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* `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* `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 facet values query to execute.'),
+})
+
export const LogsQueryCreateParams = /* @__PURE__ */ 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 427fd0115965..2654413f4c56 100644
--- a/services/mcp/src/tools/generated/logs.ts
+++ b/services/mcp/src/tools/generated/logs.ts
@@ -19,6 +19,7 @@ import {
LogsAttributesRetrieveQueryParams,
LogsCountCreateBody,
LogsCountRangesCreateBody,
+ LogsFacetValuesCreateBody,
LogsQueryCreateBody,
LogsServicesCreateBody,
LogsSparklineCreateBody,
@@ -504,6 +505,27 @@ const logsCountRanges = (): ToolBase<typeof LogsCountRangesSchema, Schemas._Logs
},
})
+const LogsFacetValuesCreateSchema = LogsFacetValuesCreateBody
+
+const logsFacetValuesCreate = (): ToolBase<typeof LogsFacetValuesCreateSchema, Schemas._LogsFacetValuesResponse> => ({
+ name: 'logs-facet-values-create',
+ schema: LogsFacetValuesCreateSchema,
+ handler: async (context: Context, params: z.infer<typeof LogsFacetValuesCreateSchema>) => {
+ 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._LogsFacetValuesResponse>({
+ method: 'POST',
+ path: `/api/projects/${encodeURIComponent(String(projectId))}/logs/facet_values/`,
+ body,
+ })
+ const filtered = pickResponseFields(result, ['results']) as typeof result
+ return filtered
+ },
+})
+
const LogsServicesCreateSchema = LogsServicesCreateBody
const logsServicesCreate = (): ToolBase<typeof LogsServicesCreateSchema, Schemas._LogsServicesResponse> => ({
@@ -581,6 +603,7 @@ export const GENERATED_TOOLS: Record<string, () => ToolBase<ZodObjectAny>> = {
'logs-attributes-list': logsAttributesList,
'logs-count': logsCount,
'logs-count-ranges': logsCountRanges,
+ 'logs-facet-values-create': logsFacetValuesCreate,
'logs-services-create': logsServicesCreate,
'logs-sparkline-query': logsSparklineQuery,
'query-logs': queryLogs,
diff --git a/services/mcp/tests/tools/logs.integration.test.ts b/services/mcp/tests/tools/logs.integration.test.ts
index a04bc6707258..f2e3dcc28c61 100644
--- a/services/mcp/tests/tools/logs.integration.test.ts
+++ b/services/mcp/tests/tools/logs.integration.test.ts
@@ -235,6 +235,27 @@ describe('Logs', { concurrent: false }, () => {
})
})
+ describe('logs-facet-values-create tool', () => {
+ const facetTool = GENERATED_TOOLS['logs-facet-values-create']!()
+
+ it.each([
+ { name: 'column facet', query: { facetField: 'service_name' as const } },
+ { name: 'resource-attribute facet', query: { facetResourceAttribute: 'k8s.namespace.name' } },
+ ])('should return per-value counts for a $name', async ({ query }) => {
+ const result = await facetTool.handler(context, {
+ query: { ...query, dateRange: { date_from: '-24h' } },
+ })
+ const facetData = parseToolResponse(result)
+
+ expect(facetData).toHaveProperty('results')
+ expect(Array.isArray(facetData.results)).toBe(true)
+ for (const facet of facetData.results) {
+ expect(facet.value).not.toBeUndefined()
+ expect(typeof facet.count).toBe('number')
+ }
+ })
+ })
+
describe('Logs workflow', () => {
it('should support attribute discovery and query workflow', async () => {
const attributesTool = GENERATED_TOOLS['logs-attributes-list']!()
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/logs-facet-values-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/logs-facet-values-create.json
new file mode 100644
index 000000000000..4c7e4c4bdbd1
--- /dev/null
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/logs-facet-values-create.json
@@ -0,0 +1,130 @@
+{
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
+ "properties": {
+ "query": {
+ "description": "The facet values query to execute.",
+ "properties": {
+ "dateRange": {
+ "description": "Date range. 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"
+ },
+ "facetField": {
+ "anyOf": [
+ {
+ "description": "* `severity_text` - severity_text\n* `service_name` - service_name",
+ "enum": ["severity_text", "service_name"],
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Top-level column to facet on. Provide exactly one of facetField or facetResourceAttribute. Its own filter is excluded so counts reflect the other active filters.\n\n* `severity_text` - severity_text\n* `service_name` - service_name"
+ },
+ "facetResourceAttribute": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Resource attribute key to facet on (e.g. 'k8s.namespace.name'). Provide exactly one of facetField or facetResourceAttribute. Its own log_resource_attribute filter is excluded so counts reflect the other active filters."
+ },
+ "facetSearch": {
+ "description": "Type-ahead filter over the faceted field's own values (case-insensitive substring match). Distinct from searchTerm, which searches log bodies.",
+ "type": "string"
+ },
+ "filterGroup": {
+ "description": "Property filters for the query.",
+ "items": {
+ "properties": {
+ "key": {
+ "description": "Attribute key. For type \"log\", use \"message\". 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* `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",
+ "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 (ignored when faceting on service_name).",
+ "items": {
+ "type": "string"
+ },
+ "type": "array"
+ },
+ "severityLevels": {
+ "description": "Filter by log severity levels (ignored when faceting on severity_text).",
+ "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"
+}