Skip to content

Group identical console messages in list_console_messages#1025

Closed
vamgan wants to merge 1 commit intoChromeDevTools:mainfrom
vamgan:fix/group-identical-console-messages
Closed

Group identical console messages in list_console_messages#1025
vamgan wants to merge 1 commit intoChromeDevTools:mainfrom
vamgan:fix/group-identical-console-messages

Conversation

@vamgan
Copy link
Copy Markdown

@vamgan vamgan commented Feb 23, 2026

Fixes #904\n\n- Collapse consecutive identical console messages in list_console_messages output and annotate with "[N times]".\n- Preserve the first msgid and expose grouped msgids/count in structuredContent.\n- Add a unit test for grouping behavior.

@google-cla
Copy link
Copy Markdown

google-cla Bot commented Feb 23, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@Lightning00Blade Lightning00Blade self-requested a review February 24, 2026 08:11
Copy link
Copy Markdown
Collaborator

@Lightning00Blade Lightning00Blade left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks you PR!
While I think may solve the issue and pagination one.
As described in #963 (review)
we should probably do this when we are collecting the data, rather then when we are formatting the response.

@OrKoN
Copy link
Copy Markdown
Collaborator

OrKoN commented Mar 4, 2026

Closing as stale.

@OrKoN OrKoN closed this Mar 4, 2026
pull Bot pushed a commit to oogalieboogalie/chrome-devtools-mcp that referenced this pull request Apr 23, 2026
…ssages (ChromeDevTools#1939)

## Summary

Group consecutive identical console messages in `list_console_messages`,
similar to Chrome DevTools' console grouping behavior.

Fixes ChromeDevTools#904

## Changes

- Introduce `GroupedConsoleFormatter` subclass that extends
`ConsoleFormatter` and overrides `toString()` / `toJSON()` for
count-aware formatting
- Add `ConsoleFormatter.groupConsecutive()` static method that groups
consecutive messages with the same type, text, and argument count
- Apply grouping **before pagination** so grouped counts are accurate
and page sizes reflect the collapsed view
- Add unit tests for grouping logic, string formatting, and JSON output

## Key design decisions

- **`GroupedConsoleFormatter` subclass**: Keeps the existing formatter
interface clean — no new methods added to `ConsoleFormatter`.
`ConsoleFormatter` and `GroupedConsoleFormatter` are interchangeable via
the same interface.
- **Grouping before pagination** (not at format time): This was the
feedback on ChromeDevTools#963 and ChromeDevTools#1025 — grouping at format time breaks pagination
counts. This implementation groups in `McpResponse` before calling
`paginate()`.
- **No `lastId`**: Since grouped messages are truly identical, only the
first message's ID is needed.
- **`argCount` matching**: Prevents false grouping of messages with the
same text but different argument counts.

## Output example

```
msgid=1 [log] hello world (1 args) [5 times]
```

## Testing

- Unit tests in `tests/formatters/ConsoleFormatterGrouping.test.ts`
- Manual verification: identical messages (×5), mixed pattern (A,A,B,A,A
→ A×2, B×1, A×2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Identical console messages should be grouped together in the list_console_messages tool

3 participants