Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -433,10 +433,11 @@ If you run into any issues, checkout our [troubleshooting guide](./docs/troubles
- **Emulation** (2 tools)
- [`emulate`](docs/tool-reference.md#emulate)
- [`resize_page`](docs/tool-reference.md#resize_page)
- **Performance** (3 tools)
- **Performance** (4 tools)
- [`performance_analyze_insight`](docs/tool-reference.md#performance_analyze_insight)
- [`performance_start_trace`](docs/tool-reference.md#performance_start_trace)
- [`performance_stop_trace`](docs/tool-reference.md#performance_stop_trace)
- [`take_memory_snapshot`](docs/tool-reference.md#take_memory_snapshot)
- **Network** (2 tools)
- [`get_network_request`](docs/tool-reference.md#get_network_request)
- [`list_network_requests`](docs/tool-reference.md#list_network_requests)
Expand Down
15 changes: 13 additions & 2 deletions docs/tool-reference.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- AUTO GENERATED DO NOT EDIT - run 'npm run docs' to update-->

# Chrome DevTools MCP Tool Reference (~6719 cl100k_base tokens)
# Chrome DevTools MCP Tool Reference (~6885 cl100k_base tokens)

- **[Input automation](#input-automation)** (8 tools)
- [`click`](#click)
Expand All @@ -21,10 +21,11 @@
- **[Emulation](#emulation)** (2 tools)
- [`emulate`](#emulate)
- [`resize_page`](#resize_page)
- **[Performance](#performance)** (3 tools)
- **[Performance](#performance)** (4 tools)
- [`performance_analyze_insight`](#performance_analyze_insight)
- [`performance_start_trace`](#performance_start_trace)
- [`performance_stop_trace`](#performance_stop_trace)
- [`take_memory_snapshot`](#take_memory_snapshot)
- **[Network](#network)** (2 tools)
- [`get_network_request`](#get_network_request)
- [`list_network_requests`](#list_network_requests)
Expand Down Expand Up @@ -262,6 +263,16 @@

---

### `take_memory_snapshot`

**Description:** Capture a memory heapsnapshot of the currently selected page to memory leak debugging

**Parameters:**

- **filePath** (string) **(required)**: A path to a .heapsnapshot file to save the heapsnapshot to.

---

## Network

### `get_network_request`
Expand Down
36 changes: 36 additions & 0 deletions src/tools/memory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

import {zod} from '../third_party/index.js';

import {ToolCategory} from './categories.js';
import {defineTool} from './ToolDefinition.js';

export const takeMemorySnapshot = defineTool({
name: 'take_memory_snapshot',
description: `Capture a memory heapsnapshot of the currently selected page to memory leak debugging`,
annotations: {
category: ToolCategory.PERFORMANCE,
readOnlyHint: true,
},
schema: {
filePath: zod
.string()
.describe('A path to a .heapsnapshot file to save the heapsnapshot to.')
.endsWith('.heapsnapshot'),
},
handler: async (request, response, context) => {
const page = context.getSelectedPage();

await page.captureHeapSnapshot({
path: request.params.filePath,
});

response.appendResponseLine(
`Heap snapshot saved to ${request.params.filePath}`,
);
},
});
2 changes: 2 additions & 0 deletions src/tools/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as consoleTools from './console.js';
import * as emulationTools from './emulation.js';
import * as extensionTools from './extensions.js';
import * as inputTools from './input.js';
import * as memoryTools from './memory.js';
import * as networkTools from './network.js';
import * as pagesTools from './pages.js';
import * as performanceTools from './performance.js';
Expand All @@ -22,6 +23,7 @@ const tools = [
...Object.values(emulationTools),
...Object.values(extensionTools),
...Object.values(inputTools),
...Object.values(memoryTools),
...Object.values(networkTools),
...Object.values(pagesTools),
...Object.values(performanceTools),
Expand Down
39 changes: 39 additions & 0 deletions tests/tools/memory.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* @license
* Copyright 2026 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

import assert from 'node:assert';
import {existsSync} from 'node:fs';
import {rm} from 'node:fs/promises';
import {tmpdir} from 'node:os';
import {join} from 'node:path';
import {describe, it} from 'node:test';

import {takeMemorySnapshot} from '../../src/tools/memory.js';
import {withMcpContext} from '../utils.js';

describe('memory', () => {
describe('take_memory_snapshot', () => {
it('with default options', async () => {
await withMcpContext(async (response, context) => {
const filePath = join(tmpdir(), 'test-screenshot.heapsnapshot');
try {
await takeMemorySnapshot.handler(
{params: {filePath}},
response,
context,
);
assert.equal(
response.responseLines.at(0),
`Heap snapshot saved to ${filePath}`,
);
assert.ok(existsSync(filePath));
} finally {
await rm(filePath, {force: true});
}
});
});
});
});