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(tracing): expose span aggregate and tree APIs as MCP tools (#58397)

Frank Hamand7c5c74d7e81e
diff --git a/products/tracing/mcp/prompts/apm-spans-aggregate.md b/products/tracing/mcp/prompts/apm-spans-aggregate.md
new file mode 100644
index 000000000000..7a325967f5ad
--- /dev/null
+++ b/products/tracing/mcp/prompts/apm-spans-aggregate.md
@@ -0,0 +1,152 @@
+Aggregate trace span statistics grouped by `(service_name, name)` over a date window.
+
+Returns one row per `(service_name, name)` pair with the following metrics:
+
+- `count` — number of spans matched
+- `total_duration_nano`, `avg_duration_nano`, `p50_duration_nano`, `p95_duration_nano` — duration stats in nanoseconds (1 second = 1,000,000,000 ns)
+- `error_count` — spans with OTel status code `Error` (status_code = 2)
+
+Rows are ordered by `total_duration_nano` DESC and capped at 5000.
+
+Use to answer:
+
+- "Which services/operations consume the most time?"
+- "What's the p95 latency of `GET /users`?"
+- "How many errors did the checkout service emit in the last day?"
+- "Did `POST /orders` get slower this week vs last week?" (with `compareFilter`)
+
+For per-call-tree breakdowns (parent → child relationships), use `apm-spans-tree` instead.
+
+All parameters must be nested inside a `query` object.
+
+# Comparison window
+
+Set `query.compareFilter.compare: true` to also fetch a comparison window. The response then includes a `compare` array of the same shape as `results`.
+
+- Omit `compare_to` (or set null) to compare against the immediately previous period of equal length (e.g. `dateRange: -1d` → compares vs the day before).
+- Set `compare_to: "-7d"` to compare against the window 7 days earlier (same length as the primary window).
+
+# Data narrowing
+
+## Property filters
+
+Use `query.filterGroup` to narrow results to spans matching specific attributes. Only include filters that are essential to the user's question.
+
+Filter `type` values:
+
+- `span` — built-in span fields (trace_id, span_id, duration, name, kind, status_code)
+- `span_attribute` — span-level attributes (e.g. "http.method", "http.status_code")
+- `span_resource_attribute` — resource-level attributes (e.g. k8s labels, deployment info)
+
+Use `apm-attributes-list` and `apm-attribute-values-list` to discover available attribute keys/values before guessing.
+
+Supported operators:
+
+- String: `exact`, `is_not`, `icontains`, `not_icontains`, `regex`, `not_regex`
+- Numeric: `exact`, `gt`, `lt`
+- Existence (no value needed): `is_set`, `is_not_set`
+
+## Time period
+
+Use `query.dateRange` to control the time window. Default is the last hour (`-1h`). Examples: `-1h`, `-6h`, `-1d`, `-7d`.
+
+# Parameters
+
+All parameters go inside `query`.
+
+## query.dateRange
+
+Date range for the primary window. Defaults to the last hour.
+
+- `date_from`: Start of the range. Accepts ISO 8601 timestamps or relative formats: `-1h`, `-6h`, `-1d`, `-7d`, `-30d`.
+- `date_to`: End of the range. Same format. Omit or null for "now".
+
+## query.compareFilter
+
+Optional comparison-window configuration. Omit when you only need the primary window.
+
+- `compare` (boolean): set to true to enable comparison.
+- `compare_to` (string, optional): relative offset for the comparison window (e.g. `-1d`, `-7d`). Defaults to the immediately previous period of equal length.
+
+## query.serviceNames
+
+List of service names to restrict the aggregation to. Use `apm-services-list` to discover available services.
+
+## query.filterGroup
+
+A flat list of property filters applied to both the primary and comparison windows. See the "Property filters" section.
+
+# Examples
+
+## Top operations by total time in the last hour
+
+```json
+{
+ "query": {}
+}
+```
+
+## p95 latency by operation in the last day
+
+```json
+{
+ "query": {
+ "dateRange": { "date_from": "-1d" }
+ }
+}
+```
+
+Inspect the `p95_duration_nano` field on each result.
+
+## Compare this hour vs the previous hour
+
+```json
+{
+ "query": {
+ "compareFilter": { "compare": true }
+ }
+}
+```
+
+Returns `results` for the last hour and `compare` for the hour before. Diff `total_duration_nano`, `avg_duration_nano`, etc. to find regressions.
+
+## Compare today vs same time last week
+
+```json
+{
+ "query": {
+ "dateRange": { "date_from": "-1d" },
+ "compareFilter": { "compare": true, "compare_to": "-7d" }
+ }
+}
+```
+
+## Aggregate only error spans
+
+```json
+{
+ "query": {
+ "filterGroup": [{ "key": "status_code", "operator": "exact", "type": "span", "value": 2 }],
+ "dateRange": { "date_from": "-6h" }
+ }
+}
+```
+
+## Aggregate within one service
+
+```json
+{
+ "query": {
+ "serviceNames": ["api-gateway"],
+ "dateRange": { "date_from": "-1d" }
+ }
+}
+```
+
+# Reminders
+
+- Duration values are in nanoseconds. Divide by 1,000,000 for ms, 1,000,000,000 for seconds.
+- Results are ordered by `total_duration_nano` DESC and capped at 5000 rows.
+- Use `apm-attributes-list` and `apm-attribute-values-list` to discover attribute keys/values before filtering.
+- Use `apm-services-list` to discover services before filtering by service name.
+- For parent → child breakdowns, use `apm-spans-tree` instead.
diff --git a/products/tracing/mcp/prompts/apm-spans-tree.md b/products/tracing/mcp/prompts/apm-spans-tree.md
new file mode 100644
index 000000000000..bbde3baac6df
--- /dev/null
+++ b/products/tracing/mcp/prompts/apm-spans-tree.md
@@ -0,0 +1,143 @@
+Aggregate trace span statistics as a call tree — one row per `(parent_service, parent_name) → (service_name, name)` edge.
+
+Requires a `spanName` to bound the matched trace set (the `(trace_id, parent_span_id)` self-join is unsafe at high cardinality without it). All traces that contain at least one span with the given name are included, and every span in those traces is aggregated against its parent.
+
+Returns rows with:
+
+- `parent_service`, `parent_name` — the parent span identity (`parent_name` is `"<ROOT>"` for root spans)
+- `service_name`, `name` — the child span identity
+- `count` — number of spans matched for this `(parent, child)` edge
+- `total_duration_nano`, `avg_duration_nano`, `p50_duration_nano`, `p95_duration_nano` — duration stats in nanoseconds
+- `error_count` — child spans with OTel status code `Error` (status_code = 2)
+- `avg_start_offset_nano` — average nanoseconds from the parent span's start to this child's start
+
+Rows are ordered by `total_duration_nano` DESC and capped at 5000.
+
+Use to answer:
+
+- "What does the `/checkout` flow actually call downstream?"
+- "Which child operation under `POST /orders` is the slowest?"
+- "Where is time spent inside `process_payment` — DB, external API, or something else?"
+- "Did the call tree under `/api/feed` change between last week and this week?" (with `compareFilter`)
+
+For a flat per-operation view (no parent linkage), use `apm-spans-aggregate` instead.
+
+All parameters must be nested inside a `query` object.
+
+# Comparison window
+
+Set `query.compareFilter.compare: true` to also fetch a comparison window. The response then includes a `compare` array of the same shape as `results`.
+
+- Omit `compare_to` (or set null) to compare against the immediately previous period of equal length.
+- Set `compare_to: "-7d"` to compare against the window 7 days earlier (same length as the primary window).
+
+# Data narrowing
+
+## Property filters
+
+`query.filterGroup` narrows the matched span set. Same filter shape and operators as `apm-spans-aggregate` / `query-apm-spans`:
+
+- `span` — built-in span fields (trace_id, span_id, duration, name, kind, status_code)
+- `span_attribute` — span-level attributes
+- `span_resource_attribute` — resource-level attributes
+
+Use `apm-attributes-list` and `apm-attribute-values-list` to discover available attribute keys/values.
+
+## Time period
+
+Use `query.dateRange` to control the time window. Default is the last hour (`-1h`).
+
+# Parameters
+
+All parameters go inside `query`.
+
+## query.spanName (required)
+
+The span name that anchors the matched trace set. Every trace containing at least one span with this name is included, and every span in those traces is aggregated.
+
+Pick a high-level entry-point span (e.g. an HTTP route or job name). Generic names (`HTTP`, `GET`) match too many traces and produce noisy aggregates. Use `query-apm-spans` first if you need to discover concrete span names.
+
+## query.dateRange
+
+Date range for the primary window. Defaults to the last hour.
+
+- `date_from`: Start of the range. ISO 8601 or relative: `-1h`, `-6h`, `-1d`, `-7d`.
+- `date_to`: End of the range. Same format. Omit or null for "now".
+
+## query.compareFilter
+
+Optional comparison-window configuration. Same shape as in `apm-spans-aggregate`.
+
+## query.serviceNames
+
+List of service names to filter the matched span set. Use `apm-services-list` to discover services.
+
+## query.filterGroup
+
+Property filters applied to both windows. See the "Property filters" section.
+
+# Examples
+
+## Call tree under a specific operation in the last hour
+
+```json
+{
+ "query": {
+ "spanName": "POST /api/orders"
+ }
+}
+```
+
+## Call tree over the last day
+
+```json
+{
+ "query": {
+ "spanName": "checkout_flow",
+ "dateRange": { "date_from": "-1d" }
+ }
+}
+```
+
+## Compare today's call tree vs last week
+
+```json
+{
+ "query": {
+ "spanName": "POST /api/orders",
+ "dateRange": { "date_from": "-1d" },
+ "compareFilter": { "compare": true, "compare_to": "-7d" }
+ }
+}
+```
+
+## Scope to a single service
+
+```json
+{
+ "query": {
+ "spanName": "render_dashboard",
+ "serviceNames": ["web-server"]
+ }
+}
+```
+
+## Restrict to error-bearing traces
+
+```json
+{
+ "query": {
+ "spanName": "POST /api/orders",
+ "filterGroup": [{ "key": "status_code", "operator": "exact", "type": "span", "value": 2 }]
+ }
+}
+```
+
+# Reminders
+
+- `spanName` is required. Bound to a specific high-level span; avoid generic names like `HTTP`.
+- Root spans have `parent_name = "<ROOT>"` and `avg_start_offset_nano = 0`.
+- Duration values are in nanoseconds.
+- Results are ordered by `total_duration_nano` DESC and capped at 5000 rows.
+- For a flat per-operation aggregate without parent linkage, use `apm-spans-aggregate`.
+- Use `apm-services-list`, `apm-attributes-list`, `apm-attribute-values-list` to discover values before filtering.
diff --git a/products/tracing/mcp/tools.yaml b/products/tracing/mcp/tools.yaml
index dad9608cbaa9..2f1eb7dee347 100644
--- a/products/tracing/mcp/tools.yaml
+++ b/products/tracing/mcp/tools.yaml
@@ -71,6 +71,38 @@ tools:
response:
include:
- results
+ apm-spans-aggregate:
+ operation: tracing_spans_aggregate_create
+ enabled: true
+ scopes:
+ - tracing:read
+ annotations:
+ readOnly: true
+ destructive: false
+ idempotent: true
+ title: Aggregate span statistics
+ description_file: ./prompts/apm-spans-aggregate.md
+ feature_flag: tracing
+ response:
+ include:
+ - results
+ - compare
+ apm-spans-tree:
+ operation: tracing_spans_tree_create
+ enabled: true
+ scopes:
+ - tracing:read
+ annotations:
+ readOnly: true
+ destructive: false
+ idempotent: true
+ title: Aggregate span call tree
+ description_file: ./prompts/apm-spans-tree.md
+ feature_flag: tracing
+ response:
+ include:
+ - results
+ - compare
apm-sparkline-query:
operation: tracing_spans_sparkline_create
enabled: false
@@ -109,9 +141,3 @@ tools:
response:
include:
- results
- tracing-spans-aggregate-create:
- operation: tracing_spans_aggregate_create
- enabled: false
- tracing-spans-tree-create:
- operation: tracing_spans_tree_create
- enabled: false
diff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.json
index 6c9c35d89c8b..ad6fa6dbb2ed 100644
--- a/services/mcp/schema/generated-tool-definitions.json
+++ b/services/mcp/schema/generated-tool-definitions.json
@@ -332,6 +332,38 @@
},
"feature_flag": "tracing"
},
+ "apm-spans-aggregate": {
+ "description": "Aggregate trace span statistics grouped by `(service_name, name)` over a date window.\n\nReturns one row per `(service_name, name)` pair with the following metrics:\n\n- `count` — number of spans matched\n- `total_duration_nano`, `avg_duration_nano`, `p50_duration_nano`, `p95_duration_nano` — duration stats in nanoseconds (1 second = 1,000,000,000 ns)\n- `error_count` — spans with OTel status code `Error` (status_code = 2)\n\nRows are ordered by `total_duration_nano` DESC and capped at 5000.\n\nUse to answer:\n\n- \"Which services/operations consume the most time?\"\n- \"What's the p95 latency of `GET /users`?\"\n- \"How many errors did the checkout service emit in the last day?\"\n- \"Did `POST /orders` get slower this week vs last week?\" (with `compareFilter`)\n\nFor per-call-tree breakdowns (parent → child relationships), use `apm-spans-tree` instead.\n\nAll parameters must be nested inside a `query` object.\n\n# Comparison window\n\nSet `query.compareFilter.compare: true` to also fetch a comparison window. The response then includes a `compare` array of the same shape as `results`.\n\n- Omit `compare_to` (or set null) to compare against the immediately previous period of equal length (e.g. `dateRange: -1d` → compares vs the day before).\n- Set `compare_to: \"-7d\"` to compare against the window 7 days earlier (same length as the primary window).\n\n# Data narrowing\n\n## Property filters\n\nUse `query.filterGroup` to narrow results to spans matching specific attributes. Only include filters that are essential to the user's question.\n\nFilter `type` values:\n\n- `span` — built-in span fields (trace_id, span_id, duration, name, kind, status_code)\n- `span_attribute` — span-level attributes (e.g. \"http.method\", \"http.status_code\")\n- `span_resource_attribute` — resource-level attributes (e.g. k8s labels, deployment info)\n\nUse `apm-attributes-list` and `apm-attribute-values-list` to discover available attribute keys/values before guessing.\n\nSupported operators:\n\n- String: `exact`, `is_not`, `icontains`, `not_icontains`, `regex`, `not_regex`\n- Numeric: `exact`, `gt`, `lt`\n- Existence (no value needed): `is_set`, `is_not_set`\n\n## Time period\n\nUse `query.dateRange` to control the time window. Default is the last hour (`-1h`). Examples: `-1h`, `-6h`, `-1d`, `-7d`.\n\n# Parameters\n\nAll parameters go inside `query`.\n\n## query.dateRange\n\nDate range for the primary window. Defaults to the last hour.\n\n- `date_from`: Start of the range. Accepts ISO 8601 timestamps or relative formats: `-1h`, `-6h`, `-1d`, `-7d`, `-30d`.\n- `date_to`: End of the range. Same format. Omit or null for \"now\".\n\n## query.compareFilter\n\nOptional comparison-window configuration. Omit when you only need the primary window.\n\n- `compare` (boolean): set to true to enable comparison.\n- `compare_to` (string, optional): relative offset for the comparison window (e.g. `-1d`, `-7d`). Defaults to the immediately previous period of equal length.\n\n## query.serviceNames\n\nList of service names to restrict the aggregation to. Use `apm-services-list` to discover available services.\n\n## query.filterGroup\n\nA flat list of property filters applied to both the primary and comparison windows. See the \"Property filters\" section.\n\n# Examples\n\n## Top operations by total time in the last hour\n\n```json\n{\n \"query\": {}\n}\n```\n\n## p95 latency by operation in the last day\n\n```json\n{\n \"query\": {\n \"dateRange\": { \"date_from\": \"-1d\" }\n }\n}\n```\n\nInspect the `p95_duration_nano` field on each result.\n\n## Compare this hour vs the previous hour\n\n```json\n{\n \"query\": {\n \"compareFilter\": { \"compare\": true }\n }\n}\n```\n\nReturns `results` for the last hour and `compare` for the hour before. Diff `total_duration_nano`, `avg_duration_nano`, etc. to find regressions.\n\n## Compare today vs same time last week\n\n```json\n{\n \"query\": {\n \"dateRange\": { \"date_from\": \"-1d\" },\n \"compareFilter\": { \"compare\": true, \"compare_to\": \"-7d\" }\n }\n}\n```\n\n## Aggregate only error spans\n\n```json\n{\n \"query\": {\n \"filterGroup\": [{ \"key\": \"status_code\", \"operator\": \"exact\", \"type\": \"span\", \"value\": 2 }],\n \"dateRange\": { \"date_from\": \"-6h\" }\n }\n}\n```\n\n## Aggregate within one service\n\n```json\n{\n \"query\": {\n \"serviceNames\": [\"api-gateway\"],\n \"dateRange\": { \"date_from\": \"-1d\" }\n }\n}\n```\n\n# Reminders\n\n- Duration values are in nanoseconds. Divide by 1,000,000 for ms, 1,000,000,000 for seconds.\n- Results are ordered by `total_duration_nano` DESC and capped at 5000 rows.\n- Use `apm-attributes-list` and `apm-attribute-values-list` to discover attribute keys/values before filtering.\n- Use `apm-services-list` to discover services before filtering by service name.\n- For parent → child breakdowns, use `apm-spans-tree` instead.",
+ "category": "Tracing",
+ "feature": "tracing",
+ "summary": "Aggregate span statistics",
+ "title": "Aggregate span statistics",
+ "required_scopes": ["tracing:read"],
+ "new_mcp": true,
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": true
+ },
+ "feature_flag": "tracing"
+ },
+ "apm-spans-tree": {
+ "description": "Aggregate trace span statistics as a call tree — one row per `(parent_service, parent_name) → (service_name, name)` edge.\n\nRequires a `spanName` to bound the matched trace set (the `(trace_id, parent_span_id)` self-join is unsafe at high cardinality without it). All traces that contain at least one span with the given name are included, and every span in those traces is aggregated against its parent.\n\nReturns rows with:\n\n- `parent_service`, `parent_name` — the parent span identity (`parent_name` is `\"<ROOT>\"` for root spans)\n- `service_name`, `name` — the child span identity\n- `count` — number of spans matched for this `(parent, child)` edge\n- `total_duration_nano`, `avg_duration_nano`, `p50_duration_nano`, `p95_duration_nano` — duration stats in nanoseconds\n- `error_count` — child spans with OTel status code `Error` (status_code = 2)\n- `avg_start_offset_nano` — average nanoseconds from the parent span's start to this child's start\n\nRows are ordered by `total_duration_nano` DESC and capped at 5000.\n\nUse to answer:\n\n- \"What does the `/checkout` flow actually call downstream?\"\n- \"Which child operation under `POST /orders` is the slowest?\"\n- \"Where is time spent inside `process_payment` — DB, external API, or something else?\"\n- \"Did the call tree under `/api/feed` change between last week and this week?\" (with `compareFilter`)\n\nFor a flat per-operation view (no parent linkage), use `apm-spans-aggregate` instead.\n\nAll parameters must be nested inside a `query` object.\n\n# Comparison window\n\nSet `query.compareFilter.compare: true` to also fetch a comparison window. The response then includes a `compare` array of the same shape as `results`.\n\n- Omit `compare_to` (or set null) to compare against the immediately previous period of equal length.\n- Set `compare_to: \"-7d\"` to compare against the window 7 days earlier (same length as the primary window).\n\n# Data narrowing\n\n## Property filters\n\n`query.filterGroup` narrows the matched span set. Same filter shape and operators as `apm-spans-aggregate` / `query-apm-spans`:\n\n- `span` — built-in span fields (trace_id, span_id, duration, name, kind, status_code)\n- `span_attribute` — span-level attributes\n- `span_resource_attribute` — resource-level attributes\n\nUse `apm-attributes-list` and `apm-attribute-values-list` to discover available attribute keys/values.\n\n## Time period\n\nUse `query.dateRange` to control the time window. Default is the last hour (`-1h`).\n\n# Parameters\n\nAll parameters go inside `query`.\n\n## query.spanName (required)\n\nThe span name that anchors the matched trace set. Every trace containing at least one span with this name is included, and every span in those traces is aggregated.\n\nPick a high-level entry-point span (e.g. an HTTP route or job name). Generic names (`HTTP`, `GET`) match too many traces and produce noisy aggregates. Use `query-apm-spans` first if you need to discover concrete span names.\n\n## query.dateRange\n\nDate range for the primary window. Defaults to the last hour.\n\n- `date_from`: Start of the range. ISO 8601 or relative: `-1h`, `-6h`, `-1d`, `-7d`.\n- `date_to`: End of the range. Same format. Omit or null for \"now\".\n\n## query.compareFilter\n\nOptional comparison-window configuration. Same shape as in `apm-spans-aggregate`.\n\n## query.serviceNames\n\nList of service names to filter the matched span set. Use `apm-services-list` to discover services.\n\n## query.filterGroup\n\nProperty filters applied to both windows. See the \"Property filters\" section.\n\n# Examples\n\n## Call tree under a specific operation in the last hour\n\n```json\n{\n \"query\": {\n \"spanName\": \"POST /api/orders\"\n }\n}\n```\n\n## Call tree over the last day\n\n```json\n{\n \"query\": {\n \"spanName\": \"checkout_flow\",\n \"dateRange\": { \"date_from\": \"-1d\" }\n }\n}\n```\n\n## Compare today's call tree vs last week\n\n```json\n{\n \"query\": {\n \"spanName\": \"POST /api/orders\",\n \"dateRange\": { \"date_from\": \"-1d\" },\n \"compareFilter\": { \"compare\": true, \"compare_to\": \"-7d\" }\n }\n}\n```\n\n## Scope to a single service\n\n```json\n{\n \"query\": {\n \"spanName\": \"render_dashboard\",\n \"serviceNames\": [\"web-server\"]\n }\n}\n```\n\n## Restrict to error-bearing traces\n\n```json\n{\n \"query\": {\n \"spanName\": \"POST /api/orders\",\n \"filterGroup\": [{ \"key\": \"status_code\", \"operator\": \"exact\", \"type\": \"span\", \"value\": 2 }]\n }\n}\n```\n\n# Reminders\n\n- `spanName` is required. Bound to a specific high-level span; avoid generic names like `HTTP`.\n- Root spans have `parent_name = \"<ROOT>\"` and `avg_start_offset_nano = 0`.\n- Duration values are in nanoseconds.\n- Results are ordered by `total_duration_nano` DESC and capped at 5000 rows.\n- For a flat per-operation aggregate without parent linkage, use `apm-spans-aggregate`.\n- Use `apm-services-list`, `apm-attributes-list`, `apm-attribute-values-list` to discover values before filtering.",
+ "category": "Tracing",
+ "feature": "tracing",
+ "summary": "Aggregate span call tree",
+ "title": "Aggregate span call tree",
+ "required_scopes": ["tracing:read"],
+ "new_mcp": true,
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": true
+ },
+ "feature_flag": "tracing"
+ },
"apm-trace-get": {
"description": "Fetch all spans for a specific trace by its hex trace ID. Returns the full span tree for the trace including parent-child relationships, timing, and status information. Use this to inspect a specific trace in detail after discovering it via the query tool.",
"category": "Tracing",
diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.json
index 15a8e93a9f81..8527fd1a384e 100644
--- a/services/mcp/schema/tool-definitions-all.json
+++ b/services/mcp/schema/tool-definitions-all.json
@@ -349,6 +349,38 @@
},
"feature_flag": "tracing"
},
+ "apm-spans-aggregate": {
+ "description": "Aggregate trace span statistics grouped by `(service_name, name)` over a date window.\n\nReturns one row per `(service_name, name)` pair with the following metrics:\n\n- `count` — number of spans matched\n- `total_duration_nano`, `avg_duration_nano`, `p50_duration_nano`, `p95_duration_nano` — duration stats in nanoseconds (1 second = 1,000,000,000 ns)\n- `error_count` — spans with OTel status code `Error` (status_code = 2)\n\nRows are ordered by `total_duration_nano` DESC and capped at 5000.\n\nUse to answer:\n\n- \"Which services/operations consume the most time?\"\n- \"What's the p95 latency of `GET /users`?\"\n- \"How many errors did the checkout service emit in the last day?\"\n- \"Did `POST /orders` get slower this week vs last week?\" (with `compareFilter`)\n\nFor per-call-tree breakdowns (parent → child relationships), use `apm-spans-tree` instead.\n\nAll parameters must be nested inside a `query` object.\n\n# Comparison window\n\nSet `query.compareFilter.compare: true` to also fetch a comparison window. The response then includes a `compare` array of the same shape as `results`.\n\n- Omit `compare_to` (or set null) to compare against the immediately previous period of equal length (e.g. `dateRange: -1d` → compares vs the day before).\n- Set `compare_to: \"-7d\"` to compare against the window 7 days earlier (same length as the primary window).\n\n# Data narrowing\n\n## Property filters\n\nUse `query.filterGroup` to narrow results to spans matching specific attributes. Only include filters that are essential to the user's question.\n\nFilter `type` values:\n\n- `span` — built-in span fields (trace_id, span_id, duration, name, kind, status_code)\n- `span_attribute` — span-level attributes (e.g. \"http.method\", \"http.status_code\")\n- `span_resource_attribute` — resource-level attributes (e.g. k8s labels, deployment info)\n\nUse `apm-attributes-list` and `apm-attribute-values-list` to discover available attribute keys/values before guessing.\n\nSupported operators:\n\n- String: `exact`, `is_not`, `icontains`, `not_icontains`, `regex`, `not_regex`\n- Numeric: `exact`, `gt`, `lt`\n- Existence (no value needed): `is_set`, `is_not_set`\n\n## Time period\n\nUse `query.dateRange` to control the time window. Default is the last hour (`-1h`). Examples: `-1h`, `-6h`, `-1d`, `-7d`.\n\n# Parameters\n\nAll parameters go inside `query`.\n\n## query.dateRange\n\nDate range for the primary window. Defaults to the last hour.\n\n- `date_from`: Start of the range. Accepts ISO 8601 timestamps or relative formats: `-1h`, `-6h`, `-1d`, `-7d`, `-30d`.\n- `date_to`: End of the range. Same format. Omit or null for \"now\".\n\n## query.compareFilter\n\nOptional comparison-window configuration. Omit when you only need the primary window.\n\n- `compare` (boolean): set to true to enable comparison.\n- `compare_to` (string, optional): relative offset for the comparison window (e.g. `-1d`, `-7d`). Defaults to the immediately previous period of equal length.\n\n## query.serviceNames\n\nList of service names to restrict the aggregation to. Use `apm-services-list` to discover available services.\n\n## query.filterGroup\n\nA flat list of property filters applied to both the primary and comparison windows. See the \"Property filters\" section.\n\n# Examples\n\n## Top operations by total time in the last hour\n\n```json\n{\n \"query\": {}\n}\n```\n\n## p95 latency by operation in the last day\n\n```json\n{\n \"query\": {\n \"dateRange\": { \"date_from\": \"-1d\" }\n }\n}\n```\n\nInspect the `p95_duration_nano` field on each result.\n\n## Compare this hour vs the previous hour\n\n```json\n{\n \"query\": {\n \"compareFilter\": { \"compare\": true }\n }\n}\n```\n\nReturns `results` for the last hour and `compare` for the hour before. Diff `total_duration_nano`, `avg_duration_nano`, etc. to find regressions.\n\n## Compare today vs same time last week\n\n```json\n{\n \"query\": {\n \"dateRange\": { \"date_from\": \"-1d\" },\n \"compareFilter\": { \"compare\": true, \"compare_to\": \"-7d\" }\n }\n}\n```\n\n## Aggregate only error spans\n\n```json\n{\n \"query\": {\n \"filterGroup\": [{ \"key\": \"status_code\", \"operator\": \"exact\", \"type\": \"span\", \"value\": 2 }],\n \"dateRange\": { \"date_from\": \"-6h\" }\n }\n}\n```\n\n## Aggregate within one service\n\n```json\n{\n \"query\": {\n \"serviceNames\": [\"api-gateway\"],\n \"dateRange\": { \"date_from\": \"-1d\" }\n }\n}\n```\n\n# Reminders\n\n- Duration values are in nanoseconds. Divide by 1,000,000 for ms, 1,000,000,000 for seconds.\n- Results are ordered by `total_duration_nano` DESC and capped at 5000 rows.\n- Use `apm-attributes-list` and `apm-attribute-values-list` to discover attribute keys/values before filtering.\n- Use `apm-services-list` to discover services before filtering by service name.\n- For parent → child breakdowns, use `apm-spans-tree` instead.",
+ "category": "Tracing",
+ "feature": "tracing",
+ "summary": "Aggregate span statistics",
+ "title": "Aggregate span statistics",
+ "required_scopes": ["tracing:read"],
+ "new_mcp": true,
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": true
+ },
+ "feature_flag": "tracing"
+ },
+ "apm-spans-tree": {
+ "description": "Aggregate trace span statistics as a call tree — one row per `(parent_service, parent_name) → (service_name, name)` edge.\n\nRequires a `spanName` to bound the matched trace set (the `(trace_id, parent_span_id)` self-join is unsafe at high cardinality without it). All traces that contain at least one span with the given name are included, and every span in those traces is aggregated against its parent.\n\nReturns rows with:\n\n- `parent_service`, `parent_name` — the parent span identity (`parent_name` is `\"<ROOT>\"` for root spans)\n- `service_name`, `name` — the child span identity\n- `count` — number of spans matched for this `(parent, child)` edge\n- `total_duration_nano`, `avg_duration_nano`, `p50_duration_nano`, `p95_duration_nano` — duration stats in nanoseconds\n- `error_count` — child spans with OTel status code `Error` (status_code = 2)\n- `avg_start_offset_nano` — average nanoseconds from the parent span's start to this child's start\n\nRows are ordered by `total_duration_nano` DESC and capped at 5000.\n\nUse to answer:\n\n- \"What does the `/checkout` flow actually call downstream?\"\n- \"Which child operation under `POST /orders` is the slowest?\"\n- \"Where is time spent inside `process_payment` — DB, external API, or something else?\"\n- \"Did the call tree under `/api/feed` change between last week and this week?\" (with `compareFilter`)\n\nFor a flat per-operation view (no parent linkage), use `apm-spans-aggregate` instead.\n\nAll parameters must be nested inside a `query` object.\n\n# Comparison window\n\nSet `query.compareFilter.compare: true` to also fetch a comparison window. The response then includes a `compare` array of the same shape as `results`.\n\n- Omit `compare_to` (or set null) to compare against the immediately previous period of equal length.\n- Set `compare_to: \"-7d\"` to compare against the window 7 days earlier (same length as the primary window).\n\n# Data narrowing\n\n## Property filters\n\n`query.filterGroup` narrows the matched span set. Same filter shape and operators as `apm-spans-aggregate` / `query-apm-spans`:\n\n- `span` — built-in span fields (trace_id, span_id, duration, name, kind, status_code)\n- `span_attribute` — span-level attributes\n- `span_resource_attribute` — resource-level attributes\n\nUse `apm-attributes-list` and `apm-attribute-values-list` to discover available attribute keys/values.\n\n## Time period\n\nUse `query.dateRange` to control the time window. Default is the last hour (`-1h`).\n\n# Parameters\n\nAll parameters go inside `query`.\n\n## query.spanName (required)\n\nThe span name that anchors the matched trace set. Every trace containing at least one span with this name is included, and every span in those traces is aggregated.\n\nPick a high-level entry-point span (e.g. an HTTP route or job name). Generic names (`HTTP`, `GET`) match too many traces and produce noisy aggregates. Use `query-apm-spans` first if you need to discover concrete span names.\n\n## query.dateRange\n\nDate range for the primary window. Defaults to the last hour.\n\n- `date_from`: Start of the range. ISO 8601 or relative: `-1h`, `-6h`, `-1d`, `-7d`.\n- `date_to`: End of the range. Same format. Omit or null for \"now\".\n\n## query.compareFilter\n\nOptional comparison-window configuration. Same shape as in `apm-spans-aggregate`.\n\n## query.serviceNames\n\nList of service names to filter the matched span set. Use `apm-services-list` to discover services.\n\n## query.filterGroup\n\nProperty filters applied to both windows. See the \"Property filters\" section.\n\n# Examples\n\n## Call tree under a specific operation in the last hour\n\n```json\n{\n \"query\": {\n \"spanName\": \"POST /api/orders\"\n }\n}\n```\n\n## Call tree over the last day\n\n```json\n{\n \"query\": {\n \"spanName\": \"checkout_flow\",\n \"dateRange\": { \"date_from\": \"-1d\" }\n }\n}\n```\n\n## Compare today's call tree vs last week\n\n```json\n{\n \"query\": {\n \"spanName\": \"POST /api/orders\",\n \"dateRange\": { \"date_from\": \"-1d\" },\n \"compareFilter\": { \"compare\": true, \"compare_to\": \"-7d\" }\n }\n}\n```\n\n## Scope to a single service\n\n```json\n{\n \"query\": {\n \"spanName\": \"render_dashboard\",\n \"serviceNames\": [\"web-server\"]\n }\n}\n```\n\n## Restrict to error-bearing traces\n\n```json\n{\n \"query\": {\n \"spanName\": \"POST /api/orders\",\n \"filterGroup\": [{ \"key\": \"status_code\", \"operator\": \"exact\", \"type\": \"span\", \"value\": 2 }]\n }\n}\n```\n\n# Reminders\n\n- `spanName` is required. Bound to a specific high-level span; avoid generic names like `HTTP`.\n- Root spans have `parent_name = \"<ROOT>\"` and `avg_start_offset_nano = 0`.\n- Duration values are in nanoseconds.\n- Results are ordered by `total_duration_nano` DESC and capped at 5000 rows.\n- For a flat per-operation aggregate without parent linkage, use `apm-spans-aggregate`.\n- Use `apm-services-list`, `apm-attributes-list`, `apm-attribute-values-list` to discover values before filtering.",
+ "category": "Tracing",
+ "feature": "tracing",
+ "summary": "Aggregate span call tree",
+ "title": "Aggregate span call tree",
+ "required_scopes": ["tracing:read"],
+ "new_mcp": true,
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": true
+ },
+ "feature_flag": "tracing"
+ },
"apm-trace-get": {
"description": "Fetch all spans for a specific trace by its hex trace ID. Returns the full span tree for the trace including parent-child relationships, timing, and status information. Use this to inspect a specific trace in detail after discovering it via the query tool.",
"category": "Tracing",
diff --git a/services/mcp/src/generated/tracing/api.ts b/services/mcp/src/generated/tracing/api.ts
index 2afec67d389c..79091b51d374 100644
--- a/services/mcp/src/generated/tracing/api.ts
+++ b/services/mcp/src/generated/tracing/api.ts
@@ -3,11 +3,109 @@
* MCP service uses these Zod schemas for generated tool handlers.
* To regenerate: hogli build:openapi
*
- * PostHog API - MCP 5 enabled ops
+ * PostHog API - MCP 7 enabled ops
* OpenAPI spec version: 1.0.0
*/
import * as zod from 'zod'
+export const TracingSpansAggregateCreateParams = /* @__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 tracingSpansAggregateCreateBodyQueryOneCompareFilterOneCompareDefault = false
+export const tracingSpansAggregateCreateBodyQueryOneFilterGroupDefault = []
+
+export const TracingSpansAggregateCreateBody = /* @__PURE__ */ 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: -1h, -6h, -1d, -7d, 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 primary window. Defaults to last hour.'),
+ compareFilter: zod
+ .object({
+ compare: zod
+ .boolean()
+ .default(tracingSpansAggregateCreateBodyQueryOneCompareFilterOneCompareDefault)
+ .describe(
+ 'When true, also fetch results for a comparison window and return them under `compare`.'
+ ),
+ compare_to: zod
+ .string()
+ .nullish()
+ .describe(
+ "Relative date offset for the comparison window (e.g. '-1h', '-1d', '-7d'). Defaults to the immediately previous period of equal length."
+ ),
+ })
+ .optional()
+ .describe(
+ 'Optional comparison-window configuration. When omitted, only the primary window is returned.'
+ ),
+ serviceNames: zod.array(zod.string()).optional().describe('Filter by service names.'),
+ filterGroup: zod
+ .array(
+ zod.object({
+ key: zod
+ .string()
+ .describe(
+ 'Attribute key. For type "span", use built-in fields (trace_id, span_id, duration, name, kind, status_code). For "span_attribute"/"span_resource_attribute", use the attribute key (e.g. "http.method").'
+ ),
+ type: zod
+ .enum(['span', 'span_attribute', 'span_resource_attribute'])
+ .describe(
+ '* `span` - span\n* `span_attribute` - span_attribute\n* `span_resource_attribute` - span_resource_attribute'
+ )
+ .describe(
+ '"span" filters built-in span fields. "span_attribute" filters span-level attributes. "span_resource_attribute" filters resource-level attributes.\n\n* `span` - span\n* `span_attribute` - span_attribute\n* `span_resource_attribute` - span_resource_attribute'
+ ),
+ operator: zod
+ .enum([
+ 'exact',
+ 'is_not',
+ 'icontains',
+ 'not_icontains',
+ 'regex',
+ 'not_regex',
+ 'gt',
+ 'lt',
+ '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_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_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.'
+ ),
+ })
+ )
+ .default(tracingSpansAggregateCreateBodyQueryOneFilterGroupDefault)
+ .describe('Property filters applied to spans in both windows.'),
+ })
+ .describe('The span aggregation query to execute.'),
+})
+
export const TracingSpansAttributesRetrieveParams = /* @__PURE__ */ zod.object({
project_id: zod
.string()
@@ -182,6 +280,109 @@ export const TracingSpansTraceCreateBody = /* @__PURE__ */ zod.object({
.describe('Date range for the query. Defaults to last 24 hours.'),
})
+export const TracingSpansTreeCreateParams = /* @__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 tracingSpansTreeCreateBodyQueryOneCompareFilterOneCompareDefault = false
+export const tracingSpansTreeCreateBodyQueryOneFilterGroupDefault = []
+
+export const TracingSpansTreeCreateBody = /* @__PURE__ */ zod.object({
+ query: zod
+ .object({
+ spanName: zod
+ .string()
+ .describe(
+ 'Span name to scope the matched trace set. Required because the (trace_id, parent_span_id) self-join is unsafe without bounding the matched traces.'
+ ),
+ dateRange: zod
+ .object({
+ date_from: zod
+ .string()
+ .nullish()
+ .describe(
+ 'Start of the date range. Accepts ISO 8601 timestamps or relative formats: -1h, -6h, -1d, -7d, 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 primary window. Defaults to last hour.'),
+ compareFilter: zod
+ .object({
+ compare: zod
+ .boolean()
+ .default(tracingSpansTreeCreateBodyQueryOneCompareFilterOneCompareDefault)
+ .describe(
+ 'When true, also fetch results for a comparison window and return them under `compare`.'
+ ),
+ compare_to: zod
+ .string()
+ .nullish()
+ .describe(
+ "Relative date offset for the comparison window (e.g. '-1h', '-1d', '-7d'). Defaults to the immediately previous period of equal length."
+ ),
+ })
+ .optional()
+ .describe(
+ 'Optional comparison-window configuration. When omitted, only the primary window is returned.'
+ ),
+ serviceNames: zod.array(zod.string()).optional().describe('Filter by service names.'),
+ filterGroup: zod
+ .array(
+ zod.object({
+ key: zod
+ .string()
+ .describe(
+ 'Attribute key. For type "span", use built-in fields (trace_id, span_id, duration, name, kind, status_code). For "span_attribute"/"span_resource_attribute", use the attribute key (e.g. "http.method").'
+ ),
+ type: zod
+ .enum(['span', 'span_attribute', 'span_resource_attribute'])
+ .describe(
+ '* `span` - span\n* `span_attribute` - span_attribute\n* `span_resource_attribute` - span_resource_attribute'
+ )
+ .describe(
+ '"span" filters built-in span fields. "span_attribute" filters span-level attributes. "span_resource_attribute" filters resource-level attributes.\n\n* `span` - span\n* `span_attribute` - span_attribute\n* `span_resource_attribute` - span_resource_attribute'
+ ),
+ operator: zod
+ .enum([
+ 'exact',
+ 'is_not',
+ 'icontains',
+ 'not_icontains',
+ 'regex',
+ 'not_regex',
+ 'gt',
+ 'lt',
+ '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_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_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.'
+ ),
+ })
+ )
+ .default(tracingSpansTreeCreateBodyQueryOneFilterGroupDefault)
+ .describe('Additional property filters applied to spans in both windows.'),
+ })
+ .describe('The span call-tree aggregation query to execute.'),
+})
+
export const TracingSpansValuesRetrieveParams = /* @__PURE__ */ zod.object({
project_id: zod
.string()
diff --git a/services/mcp/src/tools/generated/tracing.ts b/services/mcp/src/tools/generated/tracing.ts
index e8ad17f485bf..f74af240ec81 100644
--- a/services/mcp/src/tools/generated/tracing.ts
+++ b/services/mcp/src/tools/generated/tracing.ts
@@ -2,11 +2,13 @@
import { z } from 'zod'
import {
+ TracingSpansAggregateCreateBody,
TracingSpansAttributesRetrieveQueryParams,
TracingSpansQueryCreateBody,
TracingSpansServiceNamesRetrieveQueryParams,
TracingSpansTraceCreateBody,
TracingSpansTraceCreateParams,
+ TracingSpansTreeCreateBody,
TracingSpansValuesRetrieveQueryParams,
} from '@/generated/tracing/api'
import { withUiApp } from '@/resources/ui-apps'
@@ -78,6 +80,48 @@ const apmServicesList = (): ToolBase<typeof ApmServicesListSchema, unknown> => (
},
})
+const ApmSpansAggregateSchema = TracingSpansAggregateCreateBody
+
+const apmSpansAggregate = (): ToolBase<typeof ApmSpansAggregateSchema, unknown> => ({
+ name: 'apm-spans-aggregate',
+ schema: ApmSpansAggregateSchema,
+ handler: async (context: Context, params: z.infer<typeof ApmSpansAggregateSchema>) => {
+ 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<unknown>({
+ method: 'POST',
+ path: `/api/environments/${encodeURIComponent(String(projectId))}/tracing/spans/aggregate/`,
+ body,
+ })
+ const filtered = pickResponseFields(result, ['results', 'compare']) as typeof result
+ return filtered
+ },
+})
+
+const ApmSpansTreeSchema = TracingSpansTreeCreateBody
+
+const apmSpansTree = (): ToolBase<typeof ApmSpansTreeSchema, unknown> => ({
+ name: 'apm-spans-tree',
+ schema: ApmSpansTreeSchema,
+ handler: async (context: Context, params: z.infer<typeof ApmSpansTreeSchema>) => {
+ 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<unknown>({
+ method: 'POST',
+ path: `/api/environments/${encodeURIComponent(String(projectId))}/tracing/spans/tree/`,
+ body,
+ })
+ const filtered = pickResponseFields(result, ['results', 'compare']) as typeof result
+ return filtered
+ },
+})
+
const ApmTraceGetSchema = TracingSpansTraceCreateParams.omit({ project_id: true }).extend(
TracingSpansTraceCreateBody.shape
)
@@ -128,6 +172,8 @@ export const GENERATED_TOOLS: Record<string, () => ToolBase<ZodObjectAny>> = {
'apm-attribute-values-list': apmAttributeValuesList,
'apm-attributes-list': apmAttributesList,
'apm-services-list': apmServicesList,
+ 'apm-spans-aggregate': apmSpansAggregate,
+ 'apm-spans-tree': apmSpansTree,
'apm-trace-get': apmTraceGet,
'query-apm-spans': queryApmSpans,
}
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/common/apm-spans-aggregate.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/common/apm-spans-aggregate.json
new file mode 100644
index 000000000000..c3509c1b6141
--- /dev/null
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/common/apm-spans-aggregate.json
@@ -0,0 +1,109 @@
+{
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
+ "properties": {
+ "query": {
+ "description": "The span aggregation query to execute.",
+ "properties": {
+ "compareFilter": {
+ "description": "Optional comparison-window configuration. When omitted, only the primary window is returned.",
+ "properties": {
+ "compare": {
+ "default": false,
+ "description": "When true, also fetch results for a comparison window and return them under `compare`.",
+ "type": "boolean"
+ },
+ "compare_to": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Relative date offset for the comparison window (e.g. '-1h', '-1d', '-7d'). Defaults to the immediately previous period of equal length."
+ }
+ },
+ "type": "object"
+ },
+ "dateRange": {
+ "description": "Date range for the primary window. 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: -1h, -6h, -1d, -7d, 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": {
+ "default": [],
+ "description": "Property filters applied to spans in both windows.",
+ "items": {
+ "properties": {
+ "key": {
+ "description": "Attribute key. For type \"span\", use built-in fields (trace_id, span_id, duration, name, kind, status_code). For \"span_attribute\"/\"span_resource_attribute\", use the attribute key (e.g. \"http.method\").",
+ "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_set` - is_set\n* `is_not_set` - is_not_set",
+ "enum": [
+ "exact",
+ "is_not",
+ "icontains",
+ "not_icontains",
+ "regex",
+ "not_regex",
+ "gt",
+ "lt",
+ "is_set",
+ "is_not_set"
+ ],
+ "type": "string"
+ },
+ "type": {
+ "description": "\"span\" filters built-in span fields. \"span_attribute\" filters span-level attributes. \"span_resource_attribute\" filters resource-level attributes.\n\n* `span` - span\n* `span_attribute` - span_attribute\n* `span_resource_attribute` - span_resource_attribute",
+ "enum": ["span", "span_attribute", "span_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"
+ },
+ "serviceNames": {
+ "description": "Filter by service names.",
+ "items": {
+ "type": "string"
+ },
+ "type": "array"
+ }
+ },
+ "type": "object"
+ }
+ },
+ "required": ["query"],
+ "type": "object"
+}
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/common/apm-spans-tree.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/common/apm-spans-tree.json
new file mode 100644
index 000000000000..10334a686369
--- /dev/null
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/common/apm-spans-tree.json
@@ -0,0 +1,114 @@
+{
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
+ "properties": {
+ "query": {
+ "description": "The span call-tree aggregation query to execute.",
+ "properties": {
+ "compareFilter": {
+ "description": "Optional comparison-window configuration. When omitted, only the primary window is returned.",
+ "properties": {
+ "compare": {
+ "default": false,
+ "description": "When true, also fetch results for a comparison window and return them under `compare`.",
+ "type": "boolean"
+ },
+ "compare_to": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Relative date offset for the comparison window (e.g. '-1h', '-1d', '-7d'). Defaults to the immediately previous period of equal length."
+ }
+ },
+ "type": "object"
+ },
+ "dateRange": {
+ "description": "Date range for the primary window. 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: -1h, -6h, -1d, -7d, 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": {
+ "default": [],
+ "description": "Additional property filters applied to spans in both windows.",
+ "items": {
+ "properties": {
+ "key": {
+ "description": "Attribute key. For type \"span\", use built-in fields (trace_id, span_id, duration, name, kind, status_code). For \"span_attribute\"/\"span_resource_attribute\", use the attribute key (e.g. \"http.method\").",
+ "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_set` - is_set\n* `is_not_set` - is_not_set",
+ "enum": [
+ "exact",
+ "is_not",
+ "icontains",
+ "not_icontains",
+ "regex",
+ "not_regex",
+ "gt",
+ "lt",
+ "is_set",
+ "is_not_set"
+ ],
+ "type": "string"
+ },
+ "type": {
+ "description": "\"span\" filters built-in span fields. \"span_attribute\" filters span-level attributes. \"span_resource_attribute\" filters resource-level attributes.\n\n* `span` - span\n* `span_attribute` - span_attribute\n* `span_resource_attribute` - span_resource_attribute",
+ "enum": ["span", "span_attribute", "span_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"
+ },
+ "serviceNames": {
+ "description": "Filter by service names.",
+ "items": {
+ "type": "string"
+ },
+ "type": "array"
+ },
+ "spanName": {
+ "description": "Span name to scope the matched trace set. Required because the (trace_id, parent_span_id) self-join is unsafe without bounding the matched traces.",
+ "type": "string"
+ }
+ },
+ "required": ["spanName"],
+ "type": "object"
+ }
+ },
+ "required": ["query"],
+ "type": "object"
+}