chrome-devtools-mcp 1.5.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -0
- package/build/src/HeapSnapshotManager.js +23 -13
- package/build/src/McpContext.js +174 -365
- package/build/src/McpPage.js +242 -31
- package/build/src/McpResponse.js +113 -67
- package/build/src/PageCollector.js +48 -122
- package/build/src/TextSnapshot.js +20 -2
- package/build/src/ToolHandler.js +13 -3
- package/build/src/WaitForHelper.js +18 -8
- package/build/src/bin/chrome-devtools-cli-options.js +25 -1
- package/build/src/bin/chrome-devtools-mcp-cli-options.js +15 -6
- package/build/src/bin/chrome-devtools-mcp-main.js +2 -2
- package/build/src/browser.js +1 -1
- package/build/src/daemon/client.js +33 -3
- package/build/src/daemon/daemon.js +2 -1
- package/build/src/daemon/utils.js +1 -1
- package/build/src/devtools/DevtoolsUtils.js +2 -63
- package/build/src/{issue-descriptions.js → devtools/issueDescriptions.js} +2 -2
- package/build/src/formatters/IssueFormatter.js +2 -2
- package/build/src/index.js +12 -3
- package/build/src/telemetry/ClearcutLogger.js +1 -1
- package/build/src/telemetry/WatchdogClient.js +1 -1
- package/build/src/telemetry/metricsRegistry.js +2 -9
- package/build/src/telemetry/persistence.js +1 -1
- package/build/src/telemetry/transformation.js +20 -0
- package/build/src/telemetry/watchdog/ClearcutSender.js +1 -1
- package/build/src/telemetry/watchdog/main.js +1 -1
- package/build/src/third_party/THIRD_PARTY_NOTICES +13 -249
- package/build/src/third_party/bundled-packages.json +2 -3
- package/build/src/third_party/index.js +1527 -1514
- package/build/src/third_party/lighthouse-devtools-mcp-bundle.js +3082 -6343
- package/build/src/tools/emulation.js +2 -2
- package/build/src/tools/extensions.js +1 -1
- package/build/src/tools/input.js +17 -8
- package/build/src/tools/lighthouse.js +1 -1
- package/build/src/tools/memory.js +16 -2
- package/build/src/tools/network.js +4 -4
- package/build/src/tools/pages.js +21 -89
- package/build/src/tools/performance.js +2 -2
- package/build/src/tools/script.js +3 -0
- package/build/src/tools/snapshot.js +2 -2
- package/build/src/tools/thirdPartyDeveloper.js +1 -1
- package/build/src/tools/webmcp.js +1 -1
- package/build/src/trace-processing/parse.js +1 -1
- package/build/src/{logger.js → utils/logger.js} +1 -1
- package/build/src/{polyfill.js → utils/polyfill.js} +1 -1
- package/build/src/version.js +1 -1
- package/package.json +9 -5
- package/skills/memory-leak-debugging/SKILL.md +22 -14
- package/build/src/utils/types.js +0 -7
- /package/build/src/{Mutex.js → utils/Mutex.js} +0 -0
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import { logger } from './logger.js';
|
|
6
|
+
import { logger } from './utils/logger.js';
|
|
7
7
|
export class TextSnapshot {
|
|
8
8
|
static nextSnapshotId = 1;
|
|
9
9
|
static resetCounter() {
|
|
@@ -88,7 +88,7 @@ export class TextSnapshot {
|
|
|
88
88
|
const data = options.devtoolsData ?? (await page.getDevToolsData());
|
|
89
89
|
if (data?.cdpBackendNodeId) {
|
|
90
90
|
snapshot.hasSelectedElement = true;
|
|
91
|
-
snapshot.selectedElementUid =
|
|
91
|
+
snapshot.selectedElementUid = snapshot.resolveCdpElementId(data.cdpBackendNodeId);
|
|
92
92
|
}
|
|
93
93
|
// Clean up unique IDs that we did not see anymore.
|
|
94
94
|
for (const key of uniqueBackendNodeIdToMcpId.keys()) {
|
|
@@ -98,6 +98,24 @@ export class TextSnapshot {
|
|
|
98
98
|
}
|
|
99
99
|
return snapshot;
|
|
100
100
|
}
|
|
101
|
+
resolveCdpElementId(cdpBackendNodeId) {
|
|
102
|
+
if (!cdpBackendNodeId) {
|
|
103
|
+
logger?.('no cdpBackendNodeId');
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
// TODO: index by backendNodeId instead.
|
|
107
|
+
const queue = [this.root];
|
|
108
|
+
while (queue.length) {
|
|
109
|
+
const current = queue.pop();
|
|
110
|
+
if (current.backendNodeId === cdpBackendNodeId) {
|
|
111
|
+
return current.id;
|
|
112
|
+
}
|
|
113
|
+
for (const child of current.children) {
|
|
114
|
+
queue.push(child);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
101
119
|
// ExtraHandles represent DOM nodes which might not be part of the accessibility tree, e.g. DOM nodes
|
|
102
120
|
// returned by third-party developer tools. We insert them into the tree by finding the closest ancestor
|
|
103
121
|
// in the tree and inserting the node as a child. The ancestor's child nodes are re-parented if necessary.
|
package/build/src/ToolHandler.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
* Copyright 2026 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import { logger } from './logger.js';
|
|
7
6
|
import { McpResponse } from './McpResponse.js';
|
|
8
7
|
import { SlimMcpResponse } from './SlimMcpResponse.js';
|
|
9
8
|
import { ClearcutLogger } from './telemetry/ClearcutLogger.js';
|
|
@@ -11,6 +10,7 @@ import { bucketizeLatency } from './telemetry/transformation.js';
|
|
|
11
10
|
import { zod } from './third_party/index.js';
|
|
12
11
|
import { labels, OFF_BY_DEFAULT_CATEGORIES } from './tools/categories.js';
|
|
13
12
|
import { pageIdSchema } from './tools/ToolDefinition.js';
|
|
13
|
+
import { logger } from './utils/logger.js';
|
|
14
14
|
export function buildFlag(category) {
|
|
15
15
|
return `category${category.charAt(0).toUpperCase() + category.slice(1)}`;
|
|
16
16
|
}
|
|
@@ -142,11 +142,13 @@ export class ToolHandler {
|
|
|
142
142
|
logger?.(`${this.tool.name} request: ${JSON.stringify(params, null, ' ')}`);
|
|
143
143
|
const context = await this.getContext();
|
|
144
144
|
logger?.(`${this.tool.name} context: resolved`);
|
|
145
|
-
await context.detectOpenDevToolsWindows();
|
|
146
145
|
const response = this.serverArgs.slim
|
|
147
146
|
? new SlimMcpResponse(this.serverArgs)
|
|
148
147
|
: new McpResponse(this.serverArgs);
|
|
149
148
|
response.setRedactNetworkHeaders(this.serverArgs.redactNetworkHeaders);
|
|
149
|
+
if (context.consumeReconnectNotice()) {
|
|
150
|
+
response.setReconnectNotice();
|
|
151
|
+
}
|
|
150
152
|
try {
|
|
151
153
|
if (this.tool.verifyFilesSchema) {
|
|
152
154
|
for (const key of this.tool.verifyFilesSchema) {
|
|
@@ -179,7 +181,15 @@ export class ToolHandler {
|
|
|
179
181
|
catch (err) {
|
|
180
182
|
response.setError(err);
|
|
181
183
|
}
|
|
182
|
-
|
|
184
|
+
// Resolve data format: --experimentalDataFormat takes precedence, fall back to legacy --experimentalToonFormat
|
|
185
|
+
let dataFormat = 'default';
|
|
186
|
+
if (this.serverArgs.experimentalDataFormat) {
|
|
187
|
+
dataFormat = this.serverArgs.experimentalDataFormat;
|
|
188
|
+
}
|
|
189
|
+
else if (this.serverArgs.experimentalToonFormat) {
|
|
190
|
+
dataFormat = 'toon';
|
|
191
|
+
}
|
|
192
|
+
const { content, structuredContent } = await response.handle(this.tool.name, context, dataFormat);
|
|
183
193
|
const result = {
|
|
184
194
|
content,
|
|
185
195
|
};
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import { logger } from './logger.js';
|
|
6
|
+
import { logger } from './utils/logger.js';
|
|
7
7
|
export class WaitForHelper {
|
|
8
8
|
#abortController = new AbortController();
|
|
9
9
|
#page;
|
|
@@ -112,15 +112,24 @@ export class WaitForHelper {
|
|
|
112
112
|
}
|
|
113
113
|
if (options?.handleDialog) {
|
|
114
114
|
const dialogHandler = (dialog) => {
|
|
115
|
-
|
|
116
|
-
if (options.handleDialog === '
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
else if (options.handleDialog === 'accept') {
|
|
120
|
-
void dialog.accept();
|
|
115
|
+
let actionToTake;
|
|
116
|
+
if (typeof options.handleDialog === 'object') {
|
|
117
|
+
actionToTake = options.handleDialog[dialog.type()];
|
|
121
118
|
}
|
|
122
119
|
else {
|
|
123
|
-
|
|
120
|
+
actionToTake = options.handleDialog;
|
|
121
|
+
}
|
|
122
|
+
if (actionToTake) {
|
|
123
|
+
this.#dialogOpened = true;
|
|
124
|
+
if (actionToTake === 'dismiss') {
|
|
125
|
+
void dialog.dismiss();
|
|
126
|
+
}
|
|
127
|
+
else if (actionToTake === 'accept') {
|
|
128
|
+
void dialog.accept();
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
void dialog.accept(actionToTake);
|
|
132
|
+
}
|
|
124
133
|
}
|
|
125
134
|
};
|
|
126
135
|
this.#page.on('dialog', dialogHandler);
|
|
@@ -170,6 +179,7 @@ export class WaitForHelper {
|
|
|
170
179
|
...(urlAfterAction !== this.#initialUrl
|
|
171
180
|
? { navigatedToUrl: urlAfterAction }
|
|
172
181
|
: {}),
|
|
182
|
+
dialogHandled: this.#dialogOpened,
|
|
173
183
|
};
|
|
174
184
|
}
|
|
175
185
|
}
|
|
@@ -298,6 +298,18 @@ export const commands = {
|
|
|
298
298
|
description: 'The ID for the class, obtained from details.',
|
|
299
299
|
required: true,
|
|
300
300
|
},
|
|
301
|
+
filterName: {
|
|
302
|
+
name: 'filterName',
|
|
303
|
+
type: 'string',
|
|
304
|
+
description: 'An optional filter to apply to the nodes.',
|
|
305
|
+
required: false,
|
|
306
|
+
enum: [
|
|
307
|
+
'objectsRetainedByDetachedDomNodes',
|
|
308
|
+
'objectsRetainedByConsole',
|
|
309
|
+
'objectsRetainedByEventHandlers',
|
|
310
|
+
'objectsRetainedByContexts',
|
|
311
|
+
],
|
|
312
|
+
},
|
|
301
313
|
pageIdx: {
|
|
302
314
|
name: 'pageIdx',
|
|
303
315
|
type: 'number',
|
|
@@ -322,6 +334,18 @@ export const commands = {
|
|
|
322
334
|
description: 'A path to a .heapsnapshot file to read.',
|
|
323
335
|
required: true,
|
|
324
336
|
},
|
|
337
|
+
filterName: {
|
|
338
|
+
name: 'filterName',
|
|
339
|
+
type: 'string',
|
|
340
|
+
description: 'An optional filter to apply to the aggregates.',
|
|
341
|
+
required: false,
|
|
342
|
+
enum: [
|
|
343
|
+
'objectsRetainedByDetachedDomNodes',
|
|
344
|
+
'objectsRetainedByConsole',
|
|
345
|
+
'objectsRetainedByEventHandlers',
|
|
346
|
+
'objectsRetainedByContexts',
|
|
347
|
+
],
|
|
348
|
+
},
|
|
325
349
|
pageIdx: {
|
|
326
350
|
name: 'pageIdx',
|
|
327
351
|
type: 'number',
|
|
@@ -703,7 +727,7 @@ export const commands = {
|
|
|
703
727
|
type: 'string',
|
|
704
728
|
description: 'Whether to auto accept or beforeunload dialogs triggered by this navigation. Default is accept.',
|
|
705
729
|
required: false,
|
|
706
|
-
enum: ['accept', '
|
|
730
|
+
enum: ['accept', 'dismiss'],
|
|
707
731
|
},
|
|
708
732
|
initScript: {
|
|
709
733
|
name: 'initScript',
|
|
@@ -157,18 +157,19 @@ export const cliOptions = {
|
|
|
157
157
|
},
|
|
158
158
|
experimentalToonFormat: {
|
|
159
159
|
type: 'boolean',
|
|
160
|
-
describe: 'Whether to format structured data
|
|
160
|
+
describe: 'Deprecated: use --experimentalDataFormat=toon instead. Whether to format structured data using TOON (requires @toon-format/toon).',
|
|
161
|
+
hidden: true,
|
|
162
|
+
},
|
|
163
|
+
experimentalDataFormat: {
|
|
164
|
+
type: 'string',
|
|
165
|
+
describe: 'Override format for structured data in text responses. Default uses built-in formatters. "toon" (requires @toon-format/toon) or "gcf" (requires @blackwell-systems/gcf) replace structured content with the specified encoding.',
|
|
166
|
+
choices: ['default', 'toon', 'gcf'],
|
|
161
167
|
hidden: true,
|
|
162
168
|
},
|
|
163
169
|
experimentalIncludeAllPages: {
|
|
164
170
|
type: 'boolean',
|
|
165
171
|
describe: 'Whether to include all kinds of pages such as webviews or background pages as pages.',
|
|
166
172
|
},
|
|
167
|
-
experimentalNavigationAllowlist: {
|
|
168
|
-
type: 'boolean',
|
|
169
|
-
describe: 'Whether to enable navigation allowlist tool parameter.',
|
|
170
|
-
hidden: true,
|
|
171
|
-
},
|
|
172
173
|
experimentalInteropTools: {
|
|
173
174
|
type: 'boolean',
|
|
174
175
|
describe: 'Whether to enable interoperability tools',
|
|
@@ -314,6 +315,14 @@ export const cliOptions = {
|
|
|
314
315
|
describe: 'If true, redacts some of the network headers considered sensitive before returning to the client.',
|
|
315
316
|
default: false,
|
|
316
317
|
},
|
|
318
|
+
allowUnrestrictedPaths: {
|
|
319
|
+
type: 'boolean',
|
|
320
|
+
default: false,
|
|
321
|
+
describe: 'If set, disables the default path restriction that applies when the MCP client does not negotiate ' +
|
|
322
|
+
'the roots capability. By default, file-writing tools are restricted to the OS temp directory when ' +
|
|
323
|
+
'no roots are configured. Use this only when connecting a trusted local client that does not implement ' +
|
|
324
|
+
'MCP roots and requires access to paths outside the temp directory.',
|
|
325
|
+
},
|
|
317
326
|
};
|
|
318
327
|
export function parseArguments(version, argv = process.argv, env = process.env) {
|
|
319
328
|
const yargsInstance = yargs(hideBin(argv))
|
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import '../polyfill.js';
|
|
6
|
+
import '../utils/polyfill.js';
|
|
7
7
|
import process from 'node:process';
|
|
8
8
|
import { closeBrowser } from '../browser.js';
|
|
9
9
|
import { createMcpServer, logDisclaimers } from '../index.js';
|
|
10
|
-
import { logger, saveLogsToFile } from '../logger.js';
|
|
11
10
|
import { ClearcutLogger } from '../telemetry/ClearcutLogger.js';
|
|
12
11
|
import { computeFlagUsage } from '../telemetry/flagUtils.js';
|
|
13
12
|
import { StdioServerTransport } from '../third_party/index.js';
|
|
14
13
|
import { checkForUpdates } from '../utils/check-for-updates.js';
|
|
14
|
+
import { logger, saveLogsToFile } from '../utils/logger.js';
|
|
15
15
|
import { VERSION } from '../version.js';
|
|
16
16
|
import { cliOptions, parseArguments } from './chrome-devtools-mcp-cli-options.js';
|
|
17
17
|
await checkForUpdates('Run `npm install chrome-devtools-mcp@latest` to update.');
|
package/build/src/browser.js
CHANGED
|
@@ -7,8 +7,8 @@ import { execSync } from 'node:child_process';
|
|
|
7
7
|
import fs from 'node:fs';
|
|
8
8
|
import os from 'node:os';
|
|
9
9
|
import path from 'node:path';
|
|
10
|
-
import { logger } from './logger.js';
|
|
11
10
|
import { puppeteer } from './third_party/index.js';
|
|
11
|
+
import { logger } from './utils/logger.js';
|
|
12
12
|
let browser;
|
|
13
13
|
let browserMode;
|
|
14
14
|
function makeTargetFilter(enableExtensions = false) {
|
|
@@ -6,11 +6,13 @@
|
|
|
6
6
|
import { spawn } from 'node:child_process';
|
|
7
7
|
import fs from 'node:fs';
|
|
8
8
|
import net from 'node:net';
|
|
9
|
-
import { logger } from '../logger.js';
|
|
10
9
|
import { PipeTransport } from '../third_party/index.js';
|
|
11
10
|
import { getTempFilePath } from '../utils/files.js';
|
|
11
|
+
import { logger } from '../utils/logger.js';
|
|
12
12
|
import { DAEMON_SCRIPT_PATH, getSocketPath, getPidFilePath, isDaemonRunning, } from './utils.js';
|
|
13
13
|
const FILE_TIMEOUT = 10_000;
|
|
14
|
+
const READY_CHECK_INTERVAL = 100;
|
|
15
|
+
const READY_CHECK_COMMAND_TIMEOUT = 1_000;
|
|
14
16
|
/**
|
|
15
17
|
* Waits for a file to be created and populated (removed = false) or removed (removed = true).
|
|
16
18
|
*/
|
|
@@ -48,9 +50,36 @@ function waitForFile(filePath, removed = false) {
|
|
|
48
50
|
});
|
|
49
51
|
});
|
|
50
52
|
}
|
|
53
|
+
function delay(ms) {
|
|
54
|
+
return new Promise(resolve => {
|
|
55
|
+
setTimeout(resolve, ms);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
async function waitForDaemonReady(sessionId) {
|
|
59
|
+
const deadline = Date.now() + FILE_TIMEOUT;
|
|
60
|
+
let lastError;
|
|
61
|
+
while (Date.now() < deadline) {
|
|
62
|
+
try {
|
|
63
|
+
const response = await sendCommand({ method: 'status' }, sessionId, READY_CHECK_COMMAND_TIMEOUT);
|
|
64
|
+
if (response.success) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
lastError = new Error(String(response.error));
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
lastError = error;
|
|
71
|
+
}
|
|
72
|
+
const timeLeft = deadline - Date.now();
|
|
73
|
+
if (timeLeft > 0) {
|
|
74
|
+
await delay(Math.min(READY_CHECK_INTERVAL, timeLeft));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
throw new Error(`Timeout: daemon not ready within ${FILE_TIMEOUT}ms`, lastError === undefined ? undefined : { cause: lastError });
|
|
78
|
+
}
|
|
51
79
|
export async function startDaemon(mcpArgs = [], sessionId) {
|
|
52
80
|
if (isDaemonRunning(sessionId)) {
|
|
53
81
|
logger?.('Daemon is already running');
|
|
82
|
+
await waitForDaemonReady(sessionId);
|
|
54
83
|
return;
|
|
55
84
|
}
|
|
56
85
|
const pidFilePath = getPidFilePath(sessionId);
|
|
@@ -67,12 +96,13 @@ export async function startDaemon(mcpArgs = [], sessionId) {
|
|
|
67
96
|
});
|
|
68
97
|
child.unref();
|
|
69
98
|
await waitForFile(pidFilePath);
|
|
99
|
+
await waitForDaemonReady(sessionId);
|
|
70
100
|
}
|
|
71
101
|
const SEND_COMMAND_TIMEOUT = 60_000; // ms
|
|
72
102
|
/**
|
|
73
103
|
* `sendCommand` opens a socket connection sends a single command and disconnects.
|
|
74
104
|
*/
|
|
75
|
-
export async function sendCommand(command, sessionId) {
|
|
105
|
+
export async function sendCommand(command, sessionId, timeout = SEND_COMMAND_TIMEOUT) {
|
|
76
106
|
const socketPath = getSocketPath(sessionId);
|
|
77
107
|
const socket = net.createConnection({
|
|
78
108
|
path: socketPath,
|
|
@@ -81,7 +111,7 @@ export async function sendCommand(command, sessionId) {
|
|
|
81
111
|
const timer = setTimeout(() => {
|
|
82
112
|
socket.destroy();
|
|
83
113
|
reject(new Error('Timeout waiting for daemon response'));
|
|
84
|
-
},
|
|
114
|
+
}, timeout);
|
|
85
115
|
const transport = new PipeTransport(socket, socket);
|
|
86
116
|
transport.onmessage = async (message) => {
|
|
87
117
|
clearTimeout(timer);
|
|
@@ -9,8 +9,8 @@ import { createServer } from 'node:net';
|
|
|
9
9
|
import os from 'node:os';
|
|
10
10
|
import path from 'node:path';
|
|
11
11
|
import process from 'node:process';
|
|
12
|
-
import { logger } from '../logger.js';
|
|
13
12
|
import { Client, PipeTransport, StdioClientTransport, } from '../third_party/index.js';
|
|
13
|
+
import { logger } from '../utils/logger.js';
|
|
14
14
|
import { VERSION } from '../version.js';
|
|
15
15
|
import { DAEMON_CLIENT_NAME, getPidFilePath, getSocketPath, INDEX_SCRIPT_PATH, IS_WINDOWS, isDaemonRunning, } from './utils.js';
|
|
16
16
|
const sessionId = process.env.CHROME_DEVTOOLS_MCP_SESSION_ID || '';
|
|
@@ -133,6 +133,7 @@ async function handleRequest(msg) {
|
|
|
133
133
|
};
|
|
134
134
|
}
|
|
135
135
|
else if (msg.method === 'status') {
|
|
136
|
+
await started;
|
|
136
137
|
return {
|
|
137
138
|
success: true,
|
|
138
139
|
result: JSON.stringify({
|
|
@@ -7,7 +7,7 @@ import fs from 'node:fs';
|
|
|
7
7
|
import os from 'node:os';
|
|
8
8
|
import path from 'node:path';
|
|
9
9
|
import process from 'node:process';
|
|
10
|
-
import { logger } from '../logger.js';
|
|
10
|
+
import { logger } from '../utils/logger.js';
|
|
11
11
|
export const DAEMON_SCRIPT_PATH = path.join(import.meta.dirname, 'daemon.js');
|
|
12
12
|
export const INDEX_SCRIPT_PATH = path.join(import.meta.dirname, '..', 'bin', 'chrome-devtools-mcp.js');
|
|
13
13
|
const APP_NAME = 'chrome-devtools-mcp';
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import { Mutex } from '../Mutex.js';
|
|
7
6
|
import { DevTools } from '../third_party/index.js';
|
|
8
7
|
import { PuppeteerDevToolsConnection } from './DevToolsConnectionAdapter.js';
|
|
9
8
|
import { McpHostBindingAdapter } from './McpHostBindingAdapter.js';
|
|
@@ -93,66 +92,7 @@ export function overrideDevToolsGlobals({ loadResource, }) {
|
|
|
93
92
|
.resolve('../third_party/devtools-formatter-worker.js'),
|
|
94
93
|
});
|
|
95
94
|
}
|
|
96
|
-
export
|
|
97
|
-
#browser;
|
|
98
|
-
#createUniverseFor;
|
|
99
|
-
#universes = new WeakMap();
|
|
100
|
-
/** Guard access to #universes so we don't create unnecessary universes */
|
|
101
|
-
#mutex = new Mutex();
|
|
102
|
-
constructor(browser, factory = DEFAULT_FACTORY) {
|
|
103
|
-
this.#browser = browser;
|
|
104
|
-
this.#createUniverseFor = factory;
|
|
105
|
-
}
|
|
106
|
-
async init(pages) {
|
|
107
|
-
try {
|
|
108
|
-
await this.#mutex.acquire();
|
|
109
|
-
const promises = [];
|
|
110
|
-
for (const page of pages) {
|
|
111
|
-
promises.push(this.#createUniverseFor(page).then(targetUniverse => this.#universes.set(page, targetUniverse)));
|
|
112
|
-
}
|
|
113
|
-
this.#browser.on('targetcreated', this.#onTargetCreated);
|
|
114
|
-
this.#browser.on('targetdestroyed', this.#onTargetDestroyed);
|
|
115
|
-
await Promise.all(promises);
|
|
116
|
-
}
|
|
117
|
-
finally {
|
|
118
|
-
this.#mutex.release();
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
get(page) {
|
|
122
|
-
return this.#universes.get(page) ?? null;
|
|
123
|
-
}
|
|
124
|
-
dispose() {
|
|
125
|
-
this.#browser.off('targetcreated', this.#onTargetCreated);
|
|
126
|
-
this.#browser.off('targetdestroyed', this.#onTargetDestroyed);
|
|
127
|
-
}
|
|
128
|
-
#onTargetCreated = async (target) => {
|
|
129
|
-
const page = await target.page();
|
|
130
|
-
try {
|
|
131
|
-
await this.#mutex.acquire();
|
|
132
|
-
if (!page || this.#universes.has(page)) {
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
this.#universes.set(page, await this.#createUniverseFor(page));
|
|
136
|
-
}
|
|
137
|
-
finally {
|
|
138
|
-
this.#mutex.release();
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
#onTargetDestroyed = async (target) => {
|
|
142
|
-
const page = await target.page();
|
|
143
|
-
try {
|
|
144
|
-
await this.#mutex.acquire();
|
|
145
|
-
if (!page || !this.#universes.has(page)) {
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
this.#universes.delete(page);
|
|
149
|
-
}
|
|
150
|
-
finally {
|
|
151
|
-
this.#mutex.release();
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
const DEFAULT_FACTORY = async (page) => {
|
|
95
|
+
export async function createTargetUniverse(session) {
|
|
156
96
|
const settingStorage = new DevTools.Common.Settings.SettingsStorage({});
|
|
157
97
|
const universe = new DevTools.Foundation.Universe.Universe({
|
|
158
98
|
settingsCreationOptions: {
|
|
@@ -163,7 +103,6 @@ const DEFAULT_FACTORY = async (page) => {
|
|
|
163
103
|
},
|
|
164
104
|
overrideAutoStartModels: new Set([DevTools.DebuggerModel]),
|
|
165
105
|
});
|
|
166
|
-
const session = await page.createCDPSession();
|
|
167
106
|
const connection = new PuppeteerDevToolsConnection(session);
|
|
168
107
|
const targetManager = universe.context.get(DevTools.TargetManager);
|
|
169
108
|
targetManager.observeModels(DevTools.DebuggerModel, SKIP_ALL_PAUSES);
|
|
@@ -171,7 +110,7 @@ const DEFAULT_FACTORY = async (page) => {
|
|
|
171
110
|
const target = targetManager.createTarget('main', '', 'frame', // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
172
111
|
/* parentTarget */ null, session.id(), undefined, connection);
|
|
173
112
|
return { target, universe, session };
|
|
174
|
-
}
|
|
113
|
+
}
|
|
175
114
|
// We don't want to pause any DevTools universe session ever on the MCP side.
|
|
176
115
|
//
|
|
177
116
|
// Note that calling `setSkipAllPauses` only affects the session on which it was
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import * as fs from 'node:fs';
|
|
7
7
|
import * as path from 'node:path';
|
|
8
|
-
const DESCRIPTIONS_PATH = path.join(import.meta.dirname, 'third_party/issue-descriptions');
|
|
8
|
+
const DESCRIPTIONS_PATH = path.join(import.meta.dirname, '../third_party/issue-descriptions');
|
|
9
9
|
let issueDescriptions = {};
|
|
10
10
|
/**
|
|
11
11
|
* Reads all issue descriptions from the filesystem into memory.
|
|
@@ -39,4 +39,4 @@ export const ISSUE_UTILS = {
|
|
|
39
39
|
loadIssueDescriptions,
|
|
40
40
|
getIssueDescription,
|
|
41
41
|
};
|
|
42
|
-
//# sourceMappingURL=
|
|
42
|
+
//# sourceMappingURL=issueDescriptions.js.map
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
* Copyright 2026 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import { ISSUE_UTILS } from '../
|
|
7
|
-
import { logger } from '../logger.js';
|
|
6
|
+
import { ISSUE_UTILS } from '../devtools/issueDescriptions.js';
|
|
8
7
|
import { DevTools } from '../third_party/index.js';
|
|
8
|
+
import { logger } from '../utils/logger.js';
|
|
9
9
|
export class IssueFormatter {
|
|
10
10
|
#issue;
|
|
11
11
|
#options;
|
package/build/src/index.js
CHANGED
|
@@ -4,15 +4,15 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import { ensureBrowserConnected, ensureBrowserLaunched } from './browser.js';
|
|
7
|
-
import { loadIssueDescriptions } from './
|
|
8
|
-
import { logger } from './logger.js';
|
|
7
|
+
import { loadIssueDescriptions } from './devtools/issueDescriptions.js';
|
|
9
8
|
import { McpContext } from './McpContext.js';
|
|
10
|
-
import { Mutex } from './Mutex.js';
|
|
11
9
|
import { ClearcutLogger } from './telemetry/ClearcutLogger.js';
|
|
12
10
|
import { FilePersistence } from './telemetry/persistence.js';
|
|
13
11
|
import { McpServer, SetLevelRequestSchema, ListRootsResultSchema, RootsListChangedNotificationSchema, } from './third_party/index.js';
|
|
14
12
|
import { ToolHandler } from './ToolHandler.js';
|
|
15
13
|
import { createTools } from './tools/tools.js';
|
|
14
|
+
import { logger } from './utils/logger.js';
|
|
15
|
+
import { Mutex } from './utils/Mutex.js';
|
|
16
16
|
import { VERSION } from './version.js';
|
|
17
17
|
export { buildFlag } from './ToolHandler.js';
|
|
18
18
|
export async function createMcpServer(serverArgs, options) {
|
|
@@ -57,6 +57,12 @@ export async function createMcpServer(serverArgs, options) {
|
|
|
57
57
|
void updateRoots();
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
|
+
else if (!serverArgs.allowUnrestrictedPaths) {
|
|
61
|
+
console.warn('[chrome-devtools-mcp] The connecting client did not negotiate the MCP roots ' +
|
|
62
|
+
'capability. File-writing tools will be restricted to the OS temp directory. ' +
|
|
63
|
+
'To restore the previous unrestricted behavior, start the server with ' +
|
|
64
|
+
'--allow-unrestricted-paths.');
|
|
65
|
+
}
|
|
60
66
|
};
|
|
61
67
|
let context;
|
|
62
68
|
async function getContext() {
|
|
@@ -110,6 +116,9 @@ export async function createMcpServer(serverArgs, options) {
|
|
|
110
116
|
performanceCrux: serverArgs.performanceCrux,
|
|
111
117
|
allowList: allowlist,
|
|
112
118
|
blocklist: blocklist,
|
|
119
|
+
allowUnrestrictedPaths: serverArgs.allowUnrestrictedPaths,
|
|
120
|
+
// Surfaces a one-time note in the next response after a reconnect.
|
|
121
|
+
reconnected: context !== undefined,
|
|
113
122
|
});
|
|
114
123
|
await updateRoots();
|
|
115
124
|
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import process from 'node:process';
|
|
7
7
|
import { DAEMON_CLIENT_NAME } from '../daemon/utils.js';
|
|
8
|
-
import { logger } from '../logger.js';
|
|
8
|
+
import { logger } from '../utils/logger.js';
|
|
9
9
|
import { sanitizeParams, stripUnderscoreBeforeNumber } from './transformation.js';
|
|
10
10
|
import { McpClient, WatchdogMessageType, OsType, } from './types.js';
|
|
11
11
|
import { WatchdogClient } from './WatchdogClient.js';
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { spawn } from 'node:child_process';
|
|
7
7
|
import { fileURLToPath } from 'node:url';
|
|
8
|
-
import { logger } from '../logger.js';
|
|
8
|
+
import { logger } from '../utils/logger.js';
|
|
9
9
|
export class WatchdogClient {
|
|
10
10
|
#childProcess;
|
|
11
11
|
constructor(config, options) {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Copyright 2026 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import { transformArgName, transformArgType, getZodType, PARAM_BLOCKLIST, stripUnderscoreBeforeNumber, } from './transformation.js';
|
|
6
|
+
import { transformArgName, transformArgType, getZodType, getEnumValues, PARAM_BLOCKLIST, stripUnderscoreBeforeNumber, } from './transformation.js';
|
|
7
7
|
/**
|
|
8
8
|
* Validates that all values in an enum are of the homogeneous primitive type.
|
|
9
9
|
* Returns the primitive type string. Throws an error if heterogeneous.
|
|
@@ -66,14 +66,7 @@ export function generateToolMetrics(tools) {
|
|
|
66
66
|
const transformedName = transformArgName(zodType, name);
|
|
67
67
|
let argType = transformArgType(zodType);
|
|
68
68
|
if (argType === 'enum') {
|
|
69
|
-
|
|
70
|
-
if (schema._def.values?.length > 0) {
|
|
71
|
-
values = schema._def.values;
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
values = schema._def.innerType._def.values;
|
|
75
|
-
}
|
|
76
|
-
argType = validateEnumHomogeneity(values);
|
|
69
|
+
argType = validateEnumHomogeneity(getEnumValues(schema));
|
|
77
70
|
}
|
|
78
71
|
args.push({
|
|
79
72
|
name: transformedName,
|
|
@@ -7,7 +7,7 @@ import fs from 'node:fs/promises';
|
|
|
7
7
|
import os from 'node:os';
|
|
8
8
|
import path from 'node:path';
|
|
9
9
|
import process from 'node:process';
|
|
10
|
-
import { logger } from '../logger.js';
|
|
10
|
+
import { logger } from '../utils/logger.js';
|
|
11
11
|
import { ClearcutLogger } from './ClearcutLogger.js';
|
|
12
12
|
import { ErrorCode } from './errors.js';
|
|
13
13
|
const STATE_FILE_NAME = 'telemetry_state.json';
|
|
@@ -39,6 +39,26 @@ export function getZodType(zodType) {
|
|
|
39
39
|
}
|
|
40
40
|
throw new Error(`Unsupported zod type for tool parameter: ${typeName}`);
|
|
41
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Resolves the values of an enum parameter, unwrapping any optional/default/
|
|
44
|
+
* nullable/effects wrappers (in any order), mirroring {@link getZodType}.
|
|
45
|
+
*/
|
|
46
|
+
export function getEnumValues(zodType) {
|
|
47
|
+
const def = zodType._def;
|
|
48
|
+
const typeName = def.typeName;
|
|
49
|
+
if (typeName === 'ZodOptional' ||
|
|
50
|
+
typeName === 'ZodDefault' ||
|
|
51
|
+
typeName === 'ZodNullable') {
|
|
52
|
+
return getEnumValues(def.innerType);
|
|
53
|
+
}
|
|
54
|
+
if (typeName === 'ZodEffects') {
|
|
55
|
+
return getEnumValues(def.schema);
|
|
56
|
+
}
|
|
57
|
+
if (typeName === 'ZodEnum') {
|
|
58
|
+
return def.values;
|
|
59
|
+
}
|
|
60
|
+
throw new Error(`Cannot resolve enum values for zod type: ${typeName}`);
|
|
61
|
+
}
|
|
42
62
|
export function stripUnderscoreBeforeNumber(name) {
|
|
43
63
|
return name.replace(/_([0-9])/g, '$1');
|
|
44
64
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import crypto from 'node:crypto';
|
|
7
|
-
import { logger } from '../../logger.js';
|
|
7
|
+
import { logger } from '../../utils/logger.js';
|
|
8
8
|
const MAX_BUFFER_SIZE = 1000;
|
|
9
9
|
const DEFAULT_CLEARCUT_ENDPOINT = 'https://play.googleapis.com/log?format=json_proto';
|
|
10
10
|
const DEFAULT_FLUSH_INTERVAL_MS = 15 * 60 * 1000;
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import process from 'node:process';
|
|
7
7
|
import readline from 'node:readline';
|
|
8
8
|
import { parseArgs } from 'node:util';
|
|
9
|
-
import { logger, flushLogs, saveLogsToFile } from '../../logger.js';
|
|
9
|
+
import { logger, flushLogs, saveLogsToFile } from '../../utils/logger.js';
|
|
10
10
|
import { WatchdogMessageType } from '../types.js';
|
|
11
11
|
import { ClearcutSender } from './ClearcutSender.js';
|
|
12
12
|
function parseWatchdogArgs() {
|