chrome-devtools-mcp 1.4.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 +20 -3
- package/build/src/HeapSnapshotManager.js +83 -16
- package/build/src/McpContext.js +218 -367
- package/build/src/McpPage.js +242 -31
- package/build/src/McpResponse.js +165 -60
- 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 +76 -4
- 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/bin/chrome-devtools.js +25 -1
- package/build/src/browser.js +1 -1
- package/build/src/daemon/client.js +33 -3
- package/build/src/daemon/daemon.js +3 -2
- 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} +8 -6
- package/build/src/formatters/HeapSnapshotFormatter.js +43 -0
- package/build/src/formatters/IssueFormatter.js +2 -2
- package/build/src/index.js +14 -5
- 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 -279
- package/build/src/third_party/bundled-packages.json +3 -5
- package/build/src/third_party/devtools-heap-snapshot-worker.js +81 -0
- package/build/src/third_party/index.js +2418 -2197
- 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 +76 -6
- 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/screencast.js +1 -2
- package/build/src/tools/script.js +6 -10
- package/build/src/tools/snapshot.js +2 -2
- package/build/src/tools/thirdPartyDeveloper.js +7 -7
- package/build/src/tools/webmcp.js +1 -1
- package/build/src/trace-processing/parse.js +1 -1
- package/build/src/utils/files.js +0 -4
- 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 +17 -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
|
@@ -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 || '';
|
|
@@ -23,7 +23,7 @@ const pidFilePath = getPidFilePath(sessionId);
|
|
|
23
23
|
const pidDir = path.dirname(pidFilePath);
|
|
24
24
|
const currentUserUid = os.userInfo().uid;
|
|
25
25
|
try {
|
|
26
|
-
fs.mkdirSync(pidDir, { recursive: true });
|
|
26
|
+
fs.mkdirSync(pidDir, { recursive: true, mode: 0o700 });
|
|
27
27
|
if (os.platform() !== 'win32') {
|
|
28
28
|
// POSIX specific checks
|
|
29
29
|
try {
|
|
@@ -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.
|
|
@@ -16,11 +16,13 @@ export async function loadIssueDescriptions() {
|
|
|
16
16
|
}
|
|
17
17
|
const files = await fs.promises.readdir(DESCRIPTIONS_PATH);
|
|
18
18
|
const descriptions = {};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
19
|
+
const results = await Promise.all(files
|
|
20
|
+
.filter(file => file.endsWith('.md'))
|
|
21
|
+
.map(async (file) => {
|
|
23
22
|
const content = await fs.promises.readFile(path.join(DESCRIPTIONS_PATH, file), 'utf-8');
|
|
23
|
+
return { file, content };
|
|
24
|
+
}));
|
|
25
|
+
for (const { file, content } of results) {
|
|
24
26
|
descriptions[file] = content;
|
|
25
27
|
}
|
|
26
28
|
issueDescriptions = descriptions;
|
|
@@ -37,4 +39,4 @@ export const ISSUE_UTILS = {
|
|
|
37
39
|
loadIssueDescriptions,
|
|
38
40
|
getIssueDescription,
|
|
39
41
|
};
|
|
40
|
-
//# sourceMappingURL=
|
|
42
|
+
//# sourceMappingURL=issueDescriptions.js.map
|
|
@@ -67,6 +67,16 @@ export class HeapSnapshotFormatter {
|
|
|
67
67
|
}
|
|
68
68
|
return lines.join('\n');
|
|
69
69
|
}
|
|
70
|
+
static formatDuplicateStrings(groups) {
|
|
71
|
+
const lines = [];
|
|
72
|
+
lines.push('value,count,totalSelfSize,totalRetainedSize,truncated,nodeIds');
|
|
73
|
+
for (const group of groups) {
|
|
74
|
+
const nodeIds = group.nodes.map(n => `@${n.id}`).join(' ');
|
|
75
|
+
const truncated = group.truncated ?? false;
|
|
76
|
+
lines.push(`${JSON.stringify(group.value)},${group.count},${DevTools.I18n.ByteUtilities.formatBytesToKb(group.totalSelfSize)},${DevTools.I18n.ByteUtilities.formatBytesToKb(group.totalRetainedSize)},${truncated},${nodeIds}`);
|
|
77
|
+
}
|
|
78
|
+
return lines.join('\n');
|
|
79
|
+
}
|
|
70
80
|
#getSortedAggregates() {
|
|
71
81
|
return Object.values(this.#aggregates).sort((a, b) => b.maxRet - a.maxRet);
|
|
72
82
|
}
|
|
@@ -93,5 +103,38 @@ export class HeapSnapshotFormatter {
|
|
|
93
103
|
static sort(aggregates) {
|
|
94
104
|
return Object.entries(aggregates).sort((a, b) => b[1].maxRet - a[1].maxRet);
|
|
95
105
|
}
|
|
106
|
+
static formatDiffSummary(diffs) {
|
|
107
|
+
const lines = [];
|
|
108
|
+
lines.push('index,className,addedCount,removedCount,countDelta,addedSize,removedSize,sizeDelta');
|
|
109
|
+
let index = 0;
|
|
110
|
+
for (const diff of diffs) {
|
|
111
|
+
lines.push(`${index},${diff.className},${diff.addedCount},${diff.removedCount},${diff.countDelta},${DevTools.I18n.ByteUtilities.formatBytesToKb(diff.addedSize)},${DevTools.I18n.ByteUtilities.formatBytesToKb(diff.removedSize)},${DevTools.I18n.ByteUtilities.formatBytesToKb(diff.sizeDelta)}`);
|
|
112
|
+
index++;
|
|
113
|
+
}
|
|
114
|
+
return lines.join('\n');
|
|
115
|
+
}
|
|
116
|
+
static formatDiffDetails(diff) {
|
|
117
|
+
const lines = [];
|
|
118
|
+
lines.push(`${diff.className}: # new: ${diff.addedCount}, # deleted: ${diff.removedCount}, # delta: ${formatSignedCount(diff.countDelta)}, alloc size: ${formatSignedSize(diff.addedSize)}, freed size: ${formatSignedSize(diff.removedSize)}, size delta: ${formatSignedSize(diff.sizeDelta)}`);
|
|
119
|
+
const addedIds = diff.addedIds;
|
|
120
|
+
const addedSelfSizes = diff.addedSelfSizes;
|
|
121
|
+
const deletedIds = diff.deletedIds;
|
|
122
|
+
const deletedSelfSizes = diff.deletedSelfSizes;
|
|
123
|
+
lines.push(`Objects:`);
|
|
124
|
+
for (let i = 0; i < addedIds.length; i++) {
|
|
125
|
+
lines.push(` + @${addedIds[i]} (self_size: ${DevTools.I18n.ByteUtilities.formatBytesToKb(addedSelfSizes[i])})`);
|
|
126
|
+
}
|
|
127
|
+
for (let i = 0; i < deletedIds.length; i++) {
|
|
128
|
+
lines.push(` - @${deletedIds[i]} (self_size: ${DevTools.I18n.ByteUtilities.formatBytesToKb(deletedSelfSizes[i])})`);
|
|
129
|
+
}
|
|
130
|
+
return lines.join('\n');
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function formatSignedCount(n) {
|
|
134
|
+
return n > 0 ? `+${n}` : `${n}`;
|
|
135
|
+
}
|
|
136
|
+
function formatSignedSize(bytes) {
|
|
137
|
+
const formatted = DevTools.I18n.ByteUtilities.formatBytesToKb(bytes);
|
|
138
|
+
return bytes > 0 ? `+${formatted}` : formatted;
|
|
96
139
|
}
|
|
97
140
|
//# sourceMappingURL=HeapSnapshotFormatter.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() {
|
|
@@ -108,8 +114,11 @@ export async function createMcpServer(serverArgs, options) {
|
|
|
108
114
|
experimentalDevToolsDebugging: devtools,
|
|
109
115
|
experimentalIncludeAllPages: serverArgs.experimentalIncludeAllPages,
|
|
110
116
|
performanceCrux: serverArgs.performanceCrux,
|
|
111
|
-
|
|
112
|
-
|
|
117
|
+
allowList: allowlist,
|
|
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() {
|