chrome-devtools-mcp icon indicating copy to clipboard operation
chrome-devtools-mcp copied to clipboard

Add memory analysis tools for heap snapshots

Open natorion opened this issue 2 months ago • 1 comments

Is your feature request related to a problem? Please describe.

FEEDBACK WANTED

1. Problem Statement

The MCP server currently provides excellent tools for performance tracing (e.g., performance_start_trace), which allows an AI agent to analyze runtime performance, LCP, TBT, etc.

However, there is no equivalent capability for memory debugging. An AI agent cannot investigate memory leaks, detached DOM nodes, or object allocation patterns. This is a significant gap, as memory issues are a critical class of web performance problems.

A full heap snapshot file is far too large for an AI agent to process, so we need tools that run the analysis on the server and return a small, actionable JSON summary.

2. Proposed Feature

This feature would introduce a new set of tools to the MCP server, enabling an AI to request heap analysis and comparison.

Tool 1: Analyze Current Heap

  • memory_analyze_heap()
    • Action: Takes a snapshot of the current heap.
    • Analysis: Immediately analyzes it on the server for common memory issues.
    • Returns: A structured JSON summary of the current state.
    • Example JSON Response:
      {
        "total_heap_size": 12345678,
        "detached_dom_nodes": 15,
        "top_objects_by_retained_size": [
          { "constructor": "(string)", "count": 1024, "retained_size": 2048576 },
          { "constructor": "MyCustomObject", "count": 50, "retained_size": 1024567 },
          { "constructor": "(array)", "count": 800, "retained_size": 800123 }
        ]
      }
      

Tool 2: Diff/Comparison Workflow

To find leaks caused by a specific action, a comparison workflow is needed.

  1. memory_start_diff()

    • Action: Takes a "baseline" heap snapshot and stores it temporarily on the server.
    • Returns: A diff_id (e.g., "diff-abc-123").
  2. memory_stop_diff(diff_id: string)

    • Action: Takes a "final" heap snapshot.
    • Analysis: Compares this new snapshot on the server against the baseline snapshot identified by diff_id.
    • Returns: A structured JSON summary of the differences (the delta).
    • Example JSON Response:
      {
        "diff_id": "diff-abc-123",
        "heap_size_delta": 512345,
        "new_detached_dom_nodes": 5,
        "object_deltas": [
          { "constructor": "ModalComponent", "delta": 1, "retained_size_delta": 45678 },
          { "constructor": "(string)", "delta": 50, "retained_size_delta": 10240 }
        ]
      }
      

3. Key Use Cases

  • As a... developer debugging a new feature, I want to... ask the AI to "call memory_start_diff(), then click the 'Open Modal' button, then call memory_stop_diff(), and tell me if new_detached_dom_nodes is greater than 0," so that I can... quickly find UI-related memory leaks.
  • As a... developer, I want to... ask the AI to "run this user flow, then call memory_analyze_heap() and list the top 3 objects by retained size," so that I can... identify which objects are consuming the most memory.
  • As a... QA engineer, I want to... have the AI run a test that "calls memory_start_diff(), adds 100 items to a list, then calls memory_stop_diff()," so that I can... verify that the memory increase (object_deltas) is reasonable and expected.

4. Feedback Requested

We are posting this idea to gather community feedback and track interest. We would love to know:

  • Would you use this feature?
    • (Please add a 👍 reaction to this issue if you would find this useful!)
  • Does this start_diff / stop_diff workflow make sense for programmatic analysis?
  • What key information would you want in the memory_analyze_heap() summary?
    • (e.g., Are 'detached DOM nodes' and 'top objects' the most important?)
  • What key information would you want in the memory_stop_diff() delta summary?
    • (e.g., Is the delta for retained_size the most critical metric for you?)

Describe the solution you'd like

s/o

Describe alternatives you've considered

s/o

Additional context

No response

natorion avatar Oct 17 '25 10:10 natorion

+1

deksden avatar Dec 04 '25 22:12 deksden