You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
MCP: compact default responses for list_traces, list_structured_logs, list_console_logs and list_resources - #22580
The CLI MCP telemetry tools filled the 8k-token list budget on every call (list_traces {} ≈ 32 KB, list_structured_logs {} ≈ 33 KB, list_console_logs up to ≈ 35 KB, list_resources ≈ 10 KB), and search only changed which items filled the budget. Common agent harnesses spill tool results over ~20 KB to a file (Copilot CLI shows only the first 500 characters), so agents read these responses through extra file reads. This PR makes default responses compact and lets agents ask for less.
list_traces: defaults to one summary per trace: traceId, title, timestamp, durationMs, spanCount, resources, hasError, rootSpan, slowestSpan (the child span with the most self time, plus its db.query.text/db.statement), firstErrorSpan (with status message and exception.type: exception.message), and dashboardUrl. New arguments:
limit (1–800, default 20): number of most recent traces to return.
traceId: returns every span of one trace from /api/telemetry/traces/{id}. Other filters are ignored.
format: summary (default) or full. full returns the previous per-span shape and keeps the previous 8k-token budget.
list_structured_logs: severity (minimum level: Trace…Critical, passed to the Dashboard API) and limit (1–800, default 50).
list_console_logs: limit (1–2000, default 100) and from: tail (default) or head for startup failures. head reads the whole stream, so it can report how many later lines it skipped.
list_resources: by default, commands are listed as { "state": ..., "has_arguments": true? }. The new includeCommandDetails: true argument restores descriptions and argument_inputs.
Example summary entry (from the new snapshot test):
{"traceId":"0af7…319c","title":"GET /orders","durationMs":1200,"spanCount":4,"resources":["frontend","api"],"hasError":true,
"rootSpan":{"name":"GET /orders","kind":"Server","source":"frontend","durationMs":1200,"status":"Error","httpStatus":"500 Internal Server Error"},
"slowestSpan":{"name":"postgres","kind":"Client","source":"api","durationMs":900,"status":"Ok","statement":"SELECT * FROM orders WHERE customer_id = $1"},
"firstErrorSpan":{"name":"postgres","source":"api","durationMs":70,"status":"Error","statusMessage":"permission denied","statement":"UPDATE orders SET status = 'seen'","exception":"Npgsql.PostgresException: 25006: cannot execute UPDATE in a read-only transaction"}}
The default list responses (trace summaries, structured logs and console logs) now use a 4,096-token (~16 KB) budget, SharedAIHelpers.CompactListTokenLength. Tests check that 300 large traces and 800 large logs each stay under 20 KB. An invalid limit, format, severity, from or includeCommandDetails value returns InvalidParams instead of being silently ignored. SharedAIHelpers is compiled only into the CLI, so this does not affect the Dashboard. list_trace_structured_logs keeps its current limits.
Behavior changes
The default list_traces shape changed; format: "full" returns the previous shape, but it now also defaults to 20 traces (pass limit for more).
list_traces now returns one summary per trace (root span, slowest span by
self time with its database statement, first failed span) and accepts limit,
traceId and format: full. list_structured_logs accepts limit and severity,
list_console_logs accepts limit and from (tail/head), and list_resources
omits command descriptions and argument inputs unless includeCommandDetails
is set. Default list responses use a ~16 KB token budget so they stay under
common agent harness spill limits.
Fixes#22507
Co-authored-by: Copilot App <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Log and trace limits can discard the newest records or earlier replica startup failures because trimming follows grouping or arrival order rather than timestamp order.
This PR makes Aspire CLI MCP telemetry responses more compact, reducing the need for agent harnesses to spill results to files. It addresses #22507 within the agent-facing improvements tracked by #22511.
Changes:
Defaults trace listings to summaries, with explicit full-format and single-trace detail options.
… time
- list_structured_logs and list_traces sort records/traces by time before
applying limits, so interleaved resources don't drop the newest items.
- list_console_logs from: head keeps the earliest lines by parsed timestamp
across interleaved replica streams.
- Trace summary self time subtracts the union of child intervals, and the
summary title is length-limited like rootSpan.name.
Co-authored-by: Copilot App <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The reduced budget can cause an attribute-rich newest log to yield an empty result and hide earlier logs, requiring bounded optional attributes and a regression test.
A single log with many large attributes could exceed the list budget and
hide every log. Attribute values of such entries are shortened and extra
attributes dropped, keeping message, severity and identifiers, and the
entry is marked attributesTruncated.
Co-authored-by: Copilot App <[email protected]>
With from: "head" and a search filter, dropping nonmatching lines before InsertSorted loses the timestamp anchors needed to order untimestamped continuation lines. For example, an unmatched 00:00:03 line followed by a matching untimestamped line from replica A is retained ahead of replica B's matching 00:00:01 failure when limit: 1. Preserve the nonmatching ordering context while selecting the earliest matches, and add a mixed-timestamp, interleaved-replica regression test.
Prevent dangling duplicate references in compact responses
The compact budget can return dangling Duplicate of ... references because GetLimitFromEndWithSummary deduplicates entries before removing older entries to meet the token limit. Nine distinct 2,048-character messages followed by a repeat of the first fit the old budget, but the compact budget drops the original while retaining the newest message's reference to it. Coordinate entry selection with deduplication, or regenerate retained entries with a fresh context and recheck their size; add a regression where the referenced entry falls outside the budget.
Enforce the response budget using serialized UTF-8 bytes
src/Shared/ConsoleLogs/SharedAIHelpers.cs:38
This budget still uses EstimateTokenCount, which counts UTF-16 characters rather than UTF-8 bytes. With relaxed JSON escaping, nine distinct 1,500-character CJK log messages fit within the 4,096-token estimate but produce roughly 42 KB of UTF-8 output, exceeding the advertised 20 KB target. Add a serialized-byte limit alongside the token budget, and cover non-ASCII payloads with Encoding.UTF8.GetByteCount assertions; the current ASCII-only text.Length checks cannot catch this.
Bound summary resources without dropping older traces
src/Shared/ConsoleLogs/SharedAIHelpers.cs:248
The summary's resource array is unbounded: 300 distinct 64-character resource names exceed the compact budget by themselves. If that trace is newest, GetLimitFromEndWithSummary stops immediately and returns an empty list, hiding older traces too—even with limit: 1. Bound the resource list's serialized size and report omitted resources while retaining the trace ID and diagnostic summary so callers can request full detail.
Budget attributes by their escaped serialized size
src/Shared/ConsoleLogs/SharedAIHelpers.cs:1070
The attribute budget counts unescaped strings, but the list budget counts serialized JSON: seven distinct 512-character values containing control characters can bypass attribute truncation yet serialize beyond the compact budget. When that log is newest, the entire list becomes [], although the entry fit the previous budget. Measure escaped attribute keys and values using the output serializer, and add a compact-response regression test for this case.
- Budget by serialized UTF-8 bytes, including JSON escapes, so non-ASCII
and control characters can't exceed the ~16 KB compact budget.
- Convert newest items first so deduplication references always point to
an entry that is returned.
- Bound trace summary resources (reporting resourcesOmitted) and span
summary strings, and bound log message/exception/attributes by
serialized size, so the newest item can't empty the list.
- list_console_logs from: head anchors untimestamped lines to their
replica's previous timestamp before applying search.
Co-authored-by: Copilot App <[email protected]>
Addressed the five findings from review 6044739693 in 0e01939:
Head results with search (ListConsoleLogsTool): every line now gets its sort key before filtering. An untimestamped line uses the latest timestamp from the same replica, and ties keep arrival order. Only the limit earliest matches are kept, so memory is bounded. Added the mixed-timestamp, interleaved-replica regression.
Dangling duplicate references:GetLimitFromEndWithSummary now converts items newest to oldest. A repeated value is written in full in the newest entry that has it, and older entries refer to that newer entry. Because the returned entries are always the newest ones, the referenced entry is always returned. Added a regression where the original entry falls outside the budget.
UTF-8 budget:EstimateTokenCount and EstimateSerializedJsonTokenSize now count serialized UTF-8 bytes. Log message and exception are each bounded by their serialized size. The tests use Encoding.UTF8.GetByteCount with CJK payloads for logs and traces.
Summary resources: capped at 16 names of at most 128 bytes, with resourcesOmitted reporting how many were dropped. Span source and destination are bounded as well, so a summary stays well under the budget. Trace and span IDs are kept whole so callers can request full detail. Added a 300-resource regression.
Escaped attribute size: attributes are measured by their escaped, serialized size with the output encoder, both when deciding whether to truncate and when adding up the budget. Added a control-character regression.
…tail unbounded
- list_traces always removes spans of ExcludeFromMcp resources, including
resource-filtered lists, since the API returns whole traces.
- traceId selects detail mode before list-only options are parsed; a
whitespace-only or non-string traceId is rejected.
- Per-field bounding of structured log entries is opt-in, so
list_trace_structured_logs keeps full entries.
- Bound attribute keys in compact duplicate references and truncated
attributes so references never exceed the values they replace.
Co-authored-by: Copilot App <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Attribute-key truncation can create ambiguous value references, while trace detail responses omit exception events and lack regression coverage for excluded spans.
- Attributes with keys longer than the reference cap are written as capped
values and never deduplicated, so references always name exact keys.
- list_traces with traceId includes span events, so the full exception
message and stack trace are available on drill-down.
- Add exclusion tests for the traceId detail path.
Co-authored-by: Copilot App <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The trace-ID detail response still truncates long exception messages and stack traces through a processing PromptContext; it needs a non-processing context and a regression test exceeding 2,048 characters.
Exception messages and stack traces recorded as span events are written
without the prompt context's length cap and duplicate-line removal, so
drilling down from a truncated summary returns the full exception.
Co-authored-by: Copilot App <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed because deduplication can undermine size checks and hide older logs, while truncation at emoji boundaries can fail the entire tool call.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The CLI MCP telemetry tools filled the 8k-token list budget on every call (
list_traces {}≈ 32 KB,list_structured_logs {}≈ 33 KB,list_console_logsup to ≈ 35 KB,list_resources≈ 10 KB), andsearchonly changed which items filled the budget. Common agent harnesses spill tool results over ~20 KB to a file (Copilot CLI shows only the first 500 characters), so agents read these responses through extra file reads. This PR makes default responses compact and lets agents ask for less.Part of epic #22511.
User-facing usage (MCP tool arguments)
list_traces: defaults to one summary per trace:traceId,title,timestamp,durationMs,spanCount,resources,hasError,rootSpan,slowestSpan(the child span with the most self time, plus itsdb.query.text/db.statement),firstErrorSpan(with status message andexception.type: exception.message), anddashboardUrl. New arguments:limit(1–800, default 20): number of most recent traces to return.traceId: returns every span of one trace from/api/telemetry/traces/{id}. Other filters are ignored.format:summary(default) orfull.fullreturns the previous per-span shape and keeps the previous 8k-token budget.list_structured_logs:severity(minimum level: Trace…Critical, passed to the Dashboard API) andlimit(1–800, default 50).list_console_logs:limit(1–2000, default 100) andfrom:tail(default) orheadfor startup failures.headreads the whole stream, so it can report how many later lines it skipped.list_resources: by default, commands are listed as{ "state": ..., "has_arguments": true? }. The newincludeCommandDetails: trueargument restores descriptions andargument_inputs.Example summary entry (from the new snapshot test):
{"traceId":"0af7…319c","title":"GET /orders","durationMs":1200,"spanCount":4,"resources":["frontend","api"],"hasError":true, "rootSpan":{"name":"GET /orders","kind":"Server","source":"frontend","durationMs":1200,"status":"Error","httpStatus":"500 Internal Server Error"}, "slowestSpan":{"name":"postgres","kind":"Client","source":"api","durationMs":900,"status":"Ok","statement":"SELECT * FROM orders WHERE customer_id = $1"}, "firstErrorSpan":{"name":"postgres","source":"api","durationMs":70,"status":"Error","statusMessage":"permission denied","statement":"UPDATE orders SET status = 'seen'","exception":"Npgsql.PostgresException: 25006: cannot execute UPDATE in a read-only transaction"}}The default list responses (trace summaries, structured logs and console logs) now use a 4,096-token (~16 KB) budget,
SharedAIHelpers.CompactListTokenLength. Tests check that 300 large traces and 800 large logs each stay under 20 KB. An invalidlimit,format,severity,fromorincludeCommandDetailsvalue returnsInvalidParamsinstead of being silently ignored.SharedAIHelpersis compiled only into the CLI, so this does not affect the Dashboard.list_trace_structured_logskeeps its current limits.Behavior changes
list_tracesshape changed;format: "full"returns the previous shape, but it now also defaults to 20 traces (passlimitfor more).list_resourcesomits command descriptions and argument inputs unlessincludeCommandDetailsis set. This should merge cleanly with Flag OTLP-configured resources that have sent no telemetry in describe and MCP list_resources #22579, which addstelemetry_receivedand a constructor parameter.Validation
dotnet test --project tests/Aspire.Cli.Tests/Aspire.Cli.Tests.csproj --no-launch-profile -- --filter-namespace "Aspire.Cli.Tests.Mcp" --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true": passed (278 tests).dotnet test --project tests/Aspire.Cli.Tests/Aspire.Cli.Tests.csproj --no-launch-profile -- --filter-class "*.Telemetry*" --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true": passed (636 tests).Fixes #22507
Checklist
<remarks />and<code />elements on your triple slash comments?