chrome-devtools-mcp 1.10.1 → 1.12.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 +72 -20
- package/build/src/BrowserManager.js +155 -27
- package/build/src/McpContext.js +598 -200
- package/build/src/McpPage.js +513 -131
- package/build/src/McpResponse.js +291 -116
- package/build/src/McpWorker.js +66 -0
- package/build/src/SlimMcpResponse.js +5 -1
- package/build/src/TextSnapshot.js +40 -20
- package/build/src/ToolHandler.js +306 -147
- package/build/src/bin/chrome-devtools-mcp-main.js +13 -10
- package/build/src/bin/chrome-devtools-mcp.js +1 -1
- package/build/src/bin/chrome-devtools.js +34 -44
- package/build/src/collectors/PageCollector.js +13 -9
- package/build/src/collectors/ServiceWorkerCollector.js +20 -13
- package/build/src/collectors/constants.js +7 -0
- package/build/src/config/ConfigLocator.js +70 -0
- package/build/src/config/ConfigParser.js +159 -0
- package/build/src/config/ConfigWatcher.js +94 -0
- package/build/src/config/ServerConfig.js +251 -0
- package/build/src/config/browser-options.js +15 -17
- package/build/src/config/category-options.js +15 -30
- package/build/src/config/cli-commands.js +165 -5
- package/build/src/config/cli-options.js +441 -58
- package/build/src/config/mcp-options.js +212 -264
- package/build/src/config/puppeteer-options.js +67 -0
- package/build/src/config/tool-options.js +60 -0
- package/build/src/daemon/client.js +84 -44
- package/build/src/daemon/daemon.js +59 -45
- package/build/src/daemon/utils.js +46 -12
- package/build/src/devtools/DevToolsCommentBridge.js +71 -11
- package/build/src/devtools/DevtoolsUtils.js +52 -15
- package/build/src/devtools/McpHostBindingAdapter.js +0 -1
- package/build/src/formatters/CommentFormatter.js +4 -13
- package/build/src/formatters/ConsoleFormatter.js +29 -2
- package/build/src/formatters/CssFormatter.js +3 -2
- package/build/src/formatters/HeapSnapshotFormatter.js +111 -57
- package/build/src/formatters/IssueFormatter.js +33 -32
- package/build/src/formatters/NetworkFormatter.js +62 -22
- package/build/src/formatters/RemoteObjectFormatter.js +231 -0
- package/build/src/formatters/SnapshotFormatter.js +44 -7
- package/build/src/index.js +285 -88
- package/build/src/processors/ChunkedTraceParser.js +11 -11
- package/build/src/processors/HeapSnapshotManager.js +455 -156
- package/build/src/processors/PerformanceTrace.js +9 -9
- package/build/src/telemetry/ClearcutLogger.js +1 -1
- package/build/src/telemetry/transformation.js +7 -11
- package/build/src/telemetry/watchdog/main.js +1 -1
- package/build/src/third_party/THIRD_PARTY_NOTICES +399 -689
- package/build/src/third_party/bundled-packages.json +7 -8
- package/build/src/third_party/cli.js +9239 -0
- package/build/src/third_party/devtools-formatter-worker.js +4299 -2517
- package/build/src/third_party/devtools-heap-snapshot-worker.js +1298 -22
- package/build/src/third_party/index.js +132003 -146852
- package/build/src/third_party/issue-descriptions/cookieWarnMetadataGrantRead.md +0 -1
- package/build/src/third_party/issue-descriptions/cookieWarnMetadataGrantReadOptOut.md +5 -0
- package/build/src/third_party/issue-descriptions/cookieWarnMetadataGrantSet.md +0 -1
- package/build/src/third_party/issue-descriptions/cookieWarnMetadataGrantSetOptOut.md +5 -0
- package/build/src/third_party/issue-descriptions/deprecation.md +1 -1
- package/build/src/third_party/issue-descriptions/genericGeolocationPromptWithoutUserGesture.md +5 -0
- package/build/src/third_party/issue-descriptions/sriValidationFailedIntegrityMismatch.md +2 -0
- package/build/src/third_party/lighthouse-devtools-mcp-bundle.js +54576 -52174
- package/build/src/tools/ToolDefinition.js +102 -12
- package/build/src/tools/comments.js +62 -4
- package/build/src/tools/console.js +6 -4
- package/build/src/tools/css.js +5 -2
- package/build/src/tools/emulation.js +22 -8
- package/build/src/tools/extensions.js +5 -0
- package/build/src/tools/input.js +29 -9
- package/build/src/tools/lighthouse.js +136 -12
- package/build/src/tools/memory.js +166 -59
- package/build/src/tools/network.js +5 -4
- package/build/src/tools/pages.js +52 -7
- package/build/src/tools/performance.js +28 -7
- package/build/src/tools/pwa.js +7 -0
- package/build/src/tools/screencast.js +74 -33
- package/build/src/tools/screenshot.js +52 -21
- package/build/src/tools/script.js +125 -40
- package/build/src/tools/slim/tools.js +27 -13
- package/build/src/tools/snapshot.js +13 -3
- package/build/src/tools/thirdPartyDeveloper.js +9 -5
- package/build/src/tools/tools.js +35 -22
- package/build/src/tools/webmcp.js +11 -6
- package/build/src/types.js +11 -0
- package/build/src/utils/TaskRunner.js +136 -0
- package/build/src/utils/WaitForHelper.js +15 -2
- package/build/src/utils/bytes.js +2 -12
- package/build/src/utils/check-for-updates.js +2 -2
- package/build/src/utils/disclaimers.js +27 -0
- package/build/src/utils/errorHandling.js +20 -0
- package/build/src/utils/keyboard.js +14 -2
- package/build/src/utils/logger.js +84 -5
- package/build/src/utils/resourceType.js +27 -0
- package/build/src/utils/text.js +44 -0
- package/build/src/utils/timeout.js +14 -0
- package/build/src/utils/url.js +140 -3
- package/build/src/version.js +1 -1
- package/package.json +16 -11
- package/skills/a11y-debugging/SKILL.md +7 -12
- package/skills/chrome-devtools/SKILL.md +2 -2
- package/skills/chrome-devtools-cli/SKILL.md +18 -15
- package/skills/cookie-debugging/SKILL.md +8 -5
- package/skills/debug-optimize-lcp/SKILL.md +1 -1
- package/skills/troubleshooting/SKILL.md +5 -6
package/build/src/index.js
CHANGED
|
@@ -3,58 +3,140 @@
|
|
|
3
3
|
* Copyright 2026 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
+
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
7
|
+
if (value !== null && value !== void 0) {
|
|
8
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
9
|
+
var dispose, inner;
|
|
10
|
+
if (async) {
|
|
11
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
12
|
+
dispose = value[Symbol.asyncDispose];
|
|
13
|
+
}
|
|
14
|
+
if (dispose === void 0) {
|
|
15
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
16
|
+
dispose = value[Symbol.dispose];
|
|
17
|
+
if (async) inner = dispose;
|
|
18
|
+
}
|
|
19
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
20
|
+
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
21
|
+
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
22
|
+
}
|
|
23
|
+
else if (async) {
|
|
24
|
+
env.stack.push({ async: true });
|
|
25
|
+
}
|
|
26
|
+
return value;
|
|
27
|
+
};
|
|
28
|
+
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
29
|
+
return function (env) {
|
|
30
|
+
function fail(e) {
|
|
31
|
+
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
32
|
+
env.hasError = true;
|
|
33
|
+
}
|
|
34
|
+
var r, s = 0;
|
|
35
|
+
function next() {
|
|
36
|
+
while (r = env.stack.pop()) {
|
|
37
|
+
try {
|
|
38
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
39
|
+
if (r.dispose) {
|
|
40
|
+
var result = r.dispose.call(r.value);
|
|
41
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
42
|
+
}
|
|
43
|
+
else s |= 1;
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
fail(e);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
50
|
+
if (env.hasError) throw env.error;
|
|
51
|
+
}
|
|
52
|
+
return next();
|
|
53
|
+
};
|
|
54
|
+
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
55
|
+
var e = new Error(message);
|
|
56
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
57
|
+
});
|
|
6
58
|
import path from 'node:path';
|
|
7
59
|
import { pathToFileURL } from 'node:url';
|
|
8
60
|
import { BrowserManager } from './BrowserManager.js';
|
|
61
|
+
import { ConfigParser } from './config/ConfigParser.js';
|
|
62
|
+
import { ConfigWatcher } from './config/ConfigWatcher.js';
|
|
63
|
+
import { DEFAULT_FILESYSTEM_ROOT, } from './config/mcp-options.js';
|
|
64
|
+
import { ServerConfig } from './config/ServerConfig.js';
|
|
9
65
|
import { loadIssueDescriptions } from './devtools/issueDescriptions.js';
|
|
10
66
|
import { McpContext } from './McpContext.js';
|
|
67
|
+
import { HeapSnapshotManager } from './processors/HeapSnapshotManager.js';
|
|
11
68
|
import { ClearcutLogger } from './telemetry/ClearcutLogger.js';
|
|
12
69
|
import { FilePersistence } from './telemetry/persistence.js';
|
|
13
|
-
import { McpServer as SdkMcpServer,
|
|
70
|
+
import { McpServer as SdkMcpServer, ProtocolError, ProtocolErrorCode, puppeteer, } from './third_party/index.js';
|
|
14
71
|
import { ToolHandler } from './ToolHandler.js';
|
|
15
72
|
import { createTools } from './tools/tools.js';
|
|
73
|
+
import { logCruxDisclaimer } from './utils/disclaimers.js';
|
|
74
|
+
import { getErrorMessage } from './utils/errorHandling.js';
|
|
16
75
|
import { logger } from './utils/logger.js';
|
|
76
|
+
import { TaskRunner } from './utils/TaskRunner.js';
|
|
17
77
|
import { VERSION } from './version.js';
|
|
18
78
|
puppeteer.setFollowSymlinks(false);
|
|
19
79
|
/**
|
|
20
80
|
* Timeout for a `roots/list` that a tool call is waiting on, matching the 5s
|
|
21
|
-
* default used for page operations. `getContext()` awaits it
|
|
22
|
-
* `ToolHandler`
|
|
23
|
-
* that negotiates `roots` but does not answer
|
|
81
|
+
* default used for page operations. `getContext()` awaits it before
|
|
82
|
+
* `ToolHandler` enters the task runner, so leaving it unbounded lets a client
|
|
83
|
+
* that negotiates `roots` but does not answer delay every tool for the SDK's
|
|
24
84
|
* default of 60s. Background refreshes are not bounded by this, so roots a
|
|
25
85
|
* slow client sends late still land.
|
|
26
86
|
*/
|
|
27
87
|
const ROOTS_REQUEST_TIMEOUT = 5_000;
|
|
28
88
|
export class McpServer {
|
|
29
89
|
server;
|
|
30
|
-
#
|
|
90
|
+
#config;
|
|
31
91
|
#browserManager;
|
|
32
92
|
#context;
|
|
93
|
+
/** Runs every tool call and config reload. */
|
|
94
|
+
#taskRunner = new TaskRunner();
|
|
95
|
+
#heapSnapshotManager = new HeapSnapshotManager(this.#taskRunner);
|
|
33
96
|
/**
|
|
34
97
|
* Client roots stay valid across browser reconnects and only the client can
|
|
35
98
|
* invalidate them through a `roots/list_changed` notification. CLI-configured
|
|
36
|
-
* roots are read from `#
|
|
99
|
+
* roots are read from `#config` when combining roots.
|
|
37
100
|
*/
|
|
38
101
|
#lastClientRoots;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
102
|
+
/**
|
|
103
|
+
* The bounded initial `roots/list` request. Every tool call that starts
|
|
104
|
+
* before the client answered waits on the same request, so a client that
|
|
105
|
+
* negotiates roots but never answers only delays the first calls.
|
|
106
|
+
*/
|
|
107
|
+
#initialRoots;
|
|
108
|
+
#configWatcher;
|
|
109
|
+
#tools = new Map();
|
|
110
|
+
constructor(config, options) {
|
|
111
|
+
this.#config = config;
|
|
42
112
|
this.#browserManager = options.browserManager;
|
|
43
|
-
|
|
113
|
+
const serverArgs = this.#config.resolved;
|
|
114
|
+
if (serverArgs.usageStatistics) {
|
|
44
115
|
ClearcutLogger.initialize({
|
|
45
116
|
persistence: new FilePersistence(),
|
|
46
|
-
logFile:
|
|
117
|
+
logFile: serverArgs.logFile,
|
|
47
118
|
appVersion: VERSION,
|
|
48
|
-
clearcutEndpoint:
|
|
49
|
-
clearcutForceFlushIntervalMs:
|
|
50
|
-
clearcutIncludePidHeader:
|
|
119
|
+
clearcutEndpoint: serverArgs.clearcutEndpoint,
|
|
120
|
+
clearcutForceFlushIntervalMs: serverArgs.clearcutForceFlushIntervalMs,
|
|
121
|
+
clearcutIncludePidHeader: serverArgs.clearcutIncludePidHeader,
|
|
51
122
|
});
|
|
52
123
|
}
|
|
53
124
|
this.server = new SdkMcpServer({
|
|
54
125
|
name: 'chrome_devtools',
|
|
55
126
|
title: 'Chrome DevTools MCP server',
|
|
56
127
|
version: VERSION,
|
|
57
|
-
}, {
|
|
128
|
+
}, {
|
|
129
|
+
capabilities: { logging: {}, tools: { listChanged: true } },
|
|
130
|
+
// Enabling or updating many tools at once sends a single notification.
|
|
131
|
+
debouncedNotificationMethods: ['notifications/tools/list_changed'],
|
|
132
|
+
});
|
|
133
|
+
this.#context = McpContext.create(logger, {
|
|
134
|
+
config: this.#config,
|
|
135
|
+
heapSnapshotManager: this.#heapSnapshotManager,
|
|
136
|
+
taskRunner: this.#taskRunner,
|
|
137
|
+
getBrowser: () => this.#browserManager.ensureBrowser(),
|
|
138
|
+
});
|
|
139
|
+
this.#context.setRoots(this.#combinedRoots());
|
|
58
140
|
this.server.server.setRequestHandler('logging/setLevel', () => {
|
|
59
141
|
return {};
|
|
60
142
|
});
|
|
@@ -69,31 +151,161 @@ export class McpServer {
|
|
|
69
151
|
void this.#updateRoots();
|
|
70
152
|
});
|
|
71
153
|
}
|
|
72
|
-
else if (!this.#
|
|
73
|
-
(this.#
|
|
154
|
+
else if (!this.#config.resolved.allowUnrestrictedPaths &&
|
|
155
|
+
((this.#config.resolved.filesystemRoot ?? []).length === 0 ||
|
|
156
|
+
this.#config.resolved.filesystemRoot === DEFAULT_FILESYSTEM_ROOT)) {
|
|
74
157
|
console.warn('[chrome-devtools-mcp] The connecting client did not negotiate the MCP roots ' +
|
|
75
|
-
'capability.
|
|
158
|
+
'capability. Tools that read or write local files will be restricted to the OS temp directory. ' +
|
|
76
159
|
'To restore the previous unrestricted behavior, start the server with ' +
|
|
77
160
|
'--allow-unrestricted-paths.');
|
|
78
161
|
}
|
|
79
162
|
};
|
|
80
163
|
}
|
|
81
164
|
async connect(transport) {
|
|
165
|
+
if (this.#config.resolved.watchConfig) {
|
|
166
|
+
this.watchConfig();
|
|
167
|
+
}
|
|
82
168
|
return await this.server.connect(transport);
|
|
83
169
|
}
|
|
170
|
+
async callTool(name, args = {}) {
|
|
171
|
+
const toolHandler = this.#tools.get(name)?.handler;
|
|
172
|
+
if (!toolHandler) {
|
|
173
|
+
return {
|
|
174
|
+
content: [
|
|
175
|
+
{
|
|
176
|
+
type: 'text',
|
|
177
|
+
text: `Tool ${name} not found`,
|
|
178
|
+
},
|
|
179
|
+
],
|
|
180
|
+
isError: true,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
return await toolHandler.handle(args);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Applies a new config to the running server. Only reloadable options are
|
|
187
|
+
* applied, all other options keep the value the server was started with.
|
|
188
|
+
* Tools are updated in place and only tools whose listing changed notify
|
|
189
|
+
* the client, which results in at most one `tools/list_changed`
|
|
190
|
+
* notification.
|
|
191
|
+
*/
|
|
192
|
+
async applyConfig(config) {
|
|
193
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
194
|
+
try {
|
|
195
|
+
// Goes ahead of waiting tool calls and waits for running ones, so every
|
|
196
|
+
// waiting call runs with the new config.
|
|
197
|
+
const guard = __addDisposableResource(env_1, await this.#taskRunner.pause(), false);
|
|
198
|
+
await this.#applyConfigLocked(this.#config.mergeReloadable(config));
|
|
199
|
+
}
|
|
200
|
+
catch (e_1) {
|
|
201
|
+
env_1.error = e_1;
|
|
202
|
+
env_1.hasError = true;
|
|
203
|
+
}
|
|
204
|
+
finally {
|
|
205
|
+
__disposeResources(env_1);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
async #applyConfigLocked(nextConfig) {
|
|
209
|
+
const previousArgs = this.#config.resolved;
|
|
210
|
+
const nextArgs = nextConfig.resolved;
|
|
211
|
+
// Build everything before committing so that a throwing tool factory
|
|
212
|
+
// leaves the server untouched.
|
|
213
|
+
const updates = [];
|
|
214
|
+
for (const tool of createTools(nextArgs)) {
|
|
215
|
+
const entry = this.#tools.get(tool.name);
|
|
216
|
+
if (entry) {
|
|
217
|
+
updates.push({ entry, tool });
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
this.#config.commit(nextConfig);
|
|
221
|
+
for (const { entry, tool } of updates) {
|
|
222
|
+
if (entry.handler.update(tool)) {
|
|
223
|
+
entry.registeredTool.update({
|
|
224
|
+
description: tool.description,
|
|
225
|
+
paramsSchema: entry.handler.registeredInputSchema,
|
|
226
|
+
annotations: tool.annotations,
|
|
227
|
+
enabled: !entry.handler.disabled,
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
if (!previousArgs.performanceCrux || previousArgs.slim) {
|
|
232
|
+
logCruxDisclaimer(nextArgs);
|
|
233
|
+
}
|
|
234
|
+
this.#context.setRoots(this.#combinedRoots());
|
|
235
|
+
await this.#context.onConfigChanged(previousArgs);
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Watches the config file and applies its changes to the running server.
|
|
239
|
+
*/
|
|
240
|
+
watchConfig() {
|
|
241
|
+
const configPath = this.#config.configPath;
|
|
242
|
+
if (!configPath) {
|
|
243
|
+
console.error('--watchConfig has no effect because no config file was found.');
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
this.#configWatcher?.dispose();
|
|
247
|
+
this.#configWatcher = undefined;
|
|
248
|
+
const watcher = new ConfigWatcher(configPath, content => this.#reloadConfig(watcher, configPath, content));
|
|
249
|
+
try {
|
|
250
|
+
watcher.start();
|
|
251
|
+
}
|
|
252
|
+
catch (err) {
|
|
253
|
+
watcher.dispose();
|
|
254
|
+
console.error(`Failed to watch ${configPath}: ${getErrorMessage(err)}`);
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
this.#configWatcher = watcher;
|
|
258
|
+
}
|
|
259
|
+
async #reloadConfig(watcher, configPath, content) {
|
|
260
|
+
const env_2 = { stack: [], error: void 0, hasError: false };
|
|
261
|
+
try {
|
|
262
|
+
const guard = __addDisposableResource(env_2, await this.#taskRunner.pause(), false);
|
|
263
|
+
if (this.#configWatcher !== watcher) {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
let config;
|
|
267
|
+
let nextConfig;
|
|
268
|
+
try {
|
|
269
|
+
const fileArgs = ConfigParser.parseConfigFile(configPath, content);
|
|
270
|
+
config = this.#config.withFileArgs(fileArgs);
|
|
271
|
+
nextConfig = this.#config.mergeReloadable(config);
|
|
272
|
+
}
|
|
273
|
+
catch (err) {
|
|
274
|
+
const message = `Keeping the previous configuration, failed to reload ${configPath}: ${getErrorMessage(err)}`;
|
|
275
|
+
logger?.(message);
|
|
276
|
+
console.error(message);
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
await this.#applyConfigLocked(nextConfig);
|
|
280
|
+
const restartRequired = this.#config.getRestartRequiredChanges(config);
|
|
281
|
+
logger?.(`Applied config changes from ${configPath}`);
|
|
282
|
+
if (restartRequired.length > 0) {
|
|
283
|
+
const message = `Restart chrome-devtools-mcp to fully apply changes to ${restartRequired.map(name => `--${name}`).join(', ')} from ${configPath}.`;
|
|
284
|
+
logger?.(message);
|
|
285
|
+
console.error(message);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
catch (e_2) {
|
|
289
|
+
env_2.error = e_2;
|
|
290
|
+
env_2.hasError = true;
|
|
291
|
+
}
|
|
292
|
+
finally {
|
|
293
|
+
__disposeResources(env_2);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
84
296
|
/**
|
|
85
297
|
* Closes the MCP connection and disposes internal context/listeners.
|
|
86
298
|
*/
|
|
87
299
|
async close() {
|
|
300
|
+
this.#configWatcher?.dispose();
|
|
301
|
+
this.#configWatcher = undefined;
|
|
88
302
|
try {
|
|
89
|
-
this.#context
|
|
303
|
+
this.#context.dispose();
|
|
90
304
|
}
|
|
91
305
|
catch (err) {
|
|
92
306
|
logger?.('Failed to dispose context', err);
|
|
93
307
|
}
|
|
94
|
-
|
|
95
|
-
this.#context = undefined;
|
|
96
|
-
}
|
|
308
|
+
this.#heapSnapshotManager.dispose();
|
|
97
309
|
await Promise.allSettled([
|
|
98
310
|
this.#browserManager.close(),
|
|
99
311
|
this.server.close(),
|
|
@@ -107,22 +319,22 @@ export class McpServer {
|
|
|
107
319
|
async [Symbol.asyncDispose]() {
|
|
108
320
|
await this.close();
|
|
109
321
|
}
|
|
110
|
-
static async from(
|
|
111
|
-
const server = new McpServer(
|
|
322
|
+
static async from(config, options) {
|
|
323
|
+
const server = new McpServer(config, options);
|
|
112
324
|
await server.#init();
|
|
113
325
|
return server;
|
|
114
326
|
}
|
|
115
327
|
async #init() {
|
|
116
|
-
|
|
117
|
-
for (const tool of
|
|
328
|
+
// Tool definitions take a ParsedArguments snapshot; reload recreates them.
|
|
329
|
+
for (const tool of createTools(this.#config.resolved)) {
|
|
118
330
|
this.#registerTool(tool);
|
|
119
331
|
}
|
|
332
|
+
this.#setToolCallRequestHandler();
|
|
120
333
|
await loadIssueDescriptions();
|
|
121
334
|
}
|
|
122
335
|
#combinedRoots() {
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
: (this.#serverArgs.filesystemRoot ?? [])).map(root => {
|
|
336
|
+
const serverArgs = this.#config.resolved;
|
|
337
|
+
const configuredRoots = (serverArgs.allowUnrestrictedPaths ? [] : (serverArgs.filesystemRoot ?? [])).map(root => {
|
|
126
338
|
const rootPath = path.resolve(root);
|
|
127
339
|
return {
|
|
128
340
|
uri: pathToFileURL(rootPath).href,
|
|
@@ -136,8 +348,9 @@ export class McpServer {
|
|
|
136
348
|
}
|
|
137
349
|
/**
|
|
138
350
|
* `timeout` is only passed where a tool call is waiting on the result – the
|
|
139
|
-
* background refreshes
|
|
140
|
-
* roots a slow client was about
|
|
351
|
+
* background refreshes (on initialization and `roots/list_changed`) block
|
|
352
|
+
* nobody, so bounding them would just discard roots a slow client was about
|
|
353
|
+
* to send
|
|
141
354
|
*/
|
|
142
355
|
async #updateRoots(timeout) {
|
|
143
356
|
if (!this.server.server.getClientCapabilities()?.roots) {
|
|
@@ -146,62 +359,51 @@ export class McpServer {
|
|
|
146
359
|
try {
|
|
147
360
|
const result = await this.server.server.request({ method: 'roots/list' }, timeout === undefined ? undefined : { timeout });
|
|
148
361
|
this.#lastClientRoots = result.roots;
|
|
149
|
-
this.#context
|
|
362
|
+
this.#context.setRoots(this.#combinedRoots());
|
|
150
363
|
}
|
|
151
364
|
catch (e) {
|
|
152
365
|
logger?.('Failed to list roots', e);
|
|
153
366
|
}
|
|
154
367
|
}
|
|
155
368
|
async #getContext() {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
this.#
|
|
160
|
-
|
|
161
|
-
experimentalIncludeAllPages: this.#serverArgs.experimentalIncludeAllPages,
|
|
162
|
-
performanceCrux: this.#serverArgs.performanceCrux,
|
|
163
|
-
sourceMaps: this.#serverArgs.sourceMaps,
|
|
164
|
-
allowlist: this.#serverArgs.allowedUrlPattern,
|
|
165
|
-
blocklist: this.#serverArgs.blockedUrlPattern,
|
|
166
|
-
allowUnrestrictedPaths: this.#serverArgs.allowUnrestrictedPaths,
|
|
167
|
-
// Surfaces a one-time note in the next response after a reconnect.
|
|
168
|
-
reconnected: this.#context !== undefined,
|
|
169
|
-
categoryExtensions: this.#serverArgs.categoryExtensions,
|
|
170
|
-
onNotification: (message) => {
|
|
171
|
-
void this.server
|
|
172
|
-
.sendLoggingMessage({
|
|
173
|
-
level: 'info',
|
|
174
|
-
data: message,
|
|
175
|
-
})
|
|
176
|
-
.catch(e => {
|
|
177
|
-
logger?.('Failed to send MCP notification', e);
|
|
178
|
-
});
|
|
179
|
-
},
|
|
180
|
-
});
|
|
181
|
-
this.#context.setRoots(this.#combinedRoots());
|
|
182
|
-
if (this.#lastClientRoots === undefined) {
|
|
183
|
-
// Nothing listed yet, so this call has to wait – bounded, since it is
|
|
184
|
-
// holding the tool mutex, and a later background refresh still lands
|
|
185
|
-
await this.#updateRoots(ROOTS_REQUEST_TIMEOUT);
|
|
186
|
-
}
|
|
187
|
-
else {
|
|
188
|
-
// Carry the known roots over and refresh out of band, so a reconnect
|
|
189
|
-
// never pays for a client round-trip
|
|
190
|
-
void this.#updateRoots();
|
|
191
|
-
}
|
|
369
|
+
if (this.#lastClientRoots === undefined) {
|
|
370
|
+
// Nothing listed yet, so this call has to wait – bounded, since every
|
|
371
|
+
// tool call waits on it, and a later background refresh still lands
|
|
372
|
+
this.#initialRoots ??= this.#updateRoots(ROOTS_REQUEST_TIMEOUT);
|
|
373
|
+
await this.#initialRoots;
|
|
192
374
|
}
|
|
193
375
|
return this.#context;
|
|
194
376
|
}
|
|
377
|
+
#createToolHandler(tool) {
|
|
378
|
+
return new ToolHandler(tool, this.#config, () => this.#getContext(), () => this.#browserManager.abandonPendingAttempt());
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Overrides the SDK's `tools/call` handler so enabled and input-schema
|
|
382
|
+
* checks run inside `ToolHandler.handle()` inside the task runner.
|
|
383
|
+
*/
|
|
384
|
+
#setToolCallRequestHandler() {
|
|
385
|
+
this.server.server.setRequestHandler('tools/call', async (request) => {
|
|
386
|
+
const entry = this.#tools.get(request.params.name);
|
|
387
|
+
if (!entry) {
|
|
388
|
+
throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Tool ${request.params.name} not found`);
|
|
389
|
+
}
|
|
390
|
+
const result = await entry.handler.handle(request.params.arguments, {
|
|
391
|
+
viaMcp: true,
|
|
392
|
+
});
|
|
393
|
+
return this.server.server.projectCallToolResult(result, undefined);
|
|
394
|
+
});
|
|
395
|
+
}
|
|
195
396
|
#registerTool(tool) {
|
|
196
|
-
const
|
|
397
|
+
const handler = this.#createToolHandler(tool);
|
|
197
398
|
const registeredTool = this.server.registerTool(tool.name, {
|
|
198
399
|
description: tool.description,
|
|
199
|
-
inputSchema:
|
|
400
|
+
inputSchema: handler.registeredInputSchema,
|
|
200
401
|
annotations: tool.annotations,
|
|
201
|
-
},
|
|
202
|
-
if (
|
|
402
|
+
}, args => handler.handle(args));
|
|
403
|
+
if (handler.disabled) {
|
|
203
404
|
registeredTool.disable();
|
|
204
405
|
}
|
|
406
|
+
this.#tools.set(tool.name, { handler, registeredTool });
|
|
205
407
|
}
|
|
206
408
|
}
|
|
207
409
|
/**
|
|
@@ -209,29 +411,24 @@ export class McpServer {
|
|
|
209
411
|
*
|
|
210
412
|
* Maintained as a public API for backwards compatibility because external
|
|
211
413
|
* consumers and integrations rely on `createMcpServer()`. For new code,
|
|
212
|
-
* prefer using `McpServer.from(
|
|
414
|
+
* prefer using `McpServer.from(config, options)`.
|
|
213
415
|
*/
|
|
214
416
|
export async function createMcpServer(serverArgs, options) {
|
|
215
|
-
|
|
417
|
+
// createMcpServer takes a flat ParsedArguments snapshot and only returns
|
|
418
|
+
// SdkMcpServer, so instances created here are never reloaded.
|
|
419
|
+
const serverConfig = new ServerConfig({
|
|
420
|
+
cliArgs: {},
|
|
421
|
+
fileArgs: {},
|
|
422
|
+
configPath: undefined,
|
|
423
|
+
resolved: serverArgs,
|
|
424
|
+
});
|
|
425
|
+
const browserManager = new BrowserManager(serverConfig, {
|
|
216
426
|
logFile: options.logFile,
|
|
217
427
|
});
|
|
218
|
-
const server = await McpServer.from(
|
|
428
|
+
const server = await McpServer.from(serverConfig, {
|
|
219
429
|
browserManager,
|
|
220
430
|
...options,
|
|
221
431
|
});
|
|
222
432
|
return { server: server.server };
|
|
223
433
|
}
|
|
224
|
-
export const logDisclaimers = (args) => {
|
|
225
|
-
console.error(`chrome-devtools-mcp exposes content of the browser instance to the MCP clients allowing them to inspect,
|
|
226
|
-
debug, and modify any data in the browser or DevTools.
|
|
227
|
-
Avoid sharing sensitive or personal information that you do not want to share with MCP clients.`);
|
|
228
|
-
if (!args.slim && args.performanceCrux) {
|
|
229
|
-
console.error(`Performance tools may send trace URLs to the Google CrUX API to fetch real-user experience data. To disable, run with --no-performance-crux.`);
|
|
230
|
-
}
|
|
231
|
-
if (!args.slim && args.usageStatistics) {
|
|
232
|
-
console.error(`
|
|
233
|
-
Google collects usage statistics to improve Chrome DevTools MCP. To opt-out, run with --no-usage-statistics.
|
|
234
|
-
For more details, visit: https://github.com/ChromeDevTools/chrome-devtools-mcp#usage-statistics`);
|
|
235
|
-
}
|
|
236
|
-
};
|
|
237
434
|
//# sourceMappingURL=index.js.map
|
|
@@ -20,8 +20,8 @@ const BYTE_COMMA = 0x2c;
|
|
|
20
20
|
/**
|
|
21
21
|
* Advances past any RFC 8259 JSON whitespace bytes.
|
|
22
22
|
*
|
|
23
|
-
* @param buffer
|
|
24
|
-
* @param start
|
|
23
|
+
* @param buffer The trace byte buffer to inspect.
|
|
24
|
+
* @param start The buffer index where scanning begins.
|
|
25
25
|
* @returns The index of the first non-whitespace byte, or the buffer length if the buffer ends.
|
|
26
26
|
*/
|
|
27
27
|
function skipWhitespace(buffer, start) {
|
|
@@ -38,8 +38,8 @@ function skipWhitespace(buffer, start) {
|
|
|
38
38
|
/**
|
|
39
39
|
* Scans past a JSON string starting at the opening quotation mark.
|
|
40
40
|
*
|
|
41
|
-
* @param buffer
|
|
42
|
-
* @param startQuotePos
|
|
41
|
+
* @param buffer The trace byte buffer to scan.
|
|
42
|
+
* @param startQuotePos The buffer index of the opening quotation mark.
|
|
43
43
|
* @returns The index immediately following the closing quotation mark.
|
|
44
44
|
* @throws {SyntaxError} If the string is unterminated before the end of the buffer.
|
|
45
45
|
*/
|
|
@@ -65,8 +65,8 @@ function skipString(buffer, startQuotePos) {
|
|
|
65
65
|
* Scans past a complete JSON value starting at the specified buffer position.
|
|
66
66
|
* Skips strings, compound objects, arrays, and primitive values without parsing them into memory.
|
|
67
67
|
*
|
|
68
|
-
* @param buffer
|
|
69
|
-
* @param startPos
|
|
68
|
+
* @param buffer The trace byte buffer to scan.
|
|
69
|
+
* @param startPos The buffer index where the value begins.
|
|
70
70
|
* @returns The index immediately following the skipped JSON value.
|
|
71
71
|
* @throws {SyntaxError} If the value contains unbalanced delimiters, unterminated strings, or empty primitive tokens.
|
|
72
72
|
*/
|
|
@@ -131,9 +131,9 @@ function skipValue(buffer, startPos) {
|
|
|
131
131
|
/**
|
|
132
132
|
* Scans trace events from a JSON array in bounded batches to limit memory consumption.
|
|
133
133
|
*
|
|
134
|
-
* @param buffer
|
|
135
|
-
* @param startPos
|
|
136
|
-
* @param config
|
|
134
|
+
* @param buffer The raw byte buffer containing the events array.
|
|
135
|
+
* @param startPos The index immediately after the opening array bracket.
|
|
136
|
+
* @param config Configuration settings controlling batch sizes and text decoding.
|
|
137
137
|
* @returns An object containing the parsed events and the ending buffer position.
|
|
138
138
|
* @throws {SyntaxError} If the event array contains malformed JSON, unbalanced delimiters, or unexpected tokens.
|
|
139
139
|
*/
|
|
@@ -244,8 +244,8 @@ function parseEventsArray(buffer, startPos, config) {
|
|
|
244
244
|
* Supports both root array format ([...]) and object container format ({"traceEvents": [...]}).
|
|
245
245
|
* Parses events in chunks to prevent V8 string length and memory exhaustion errors.
|
|
246
246
|
*
|
|
247
|
-
* @param buffer
|
|
248
|
-
* @param options
|
|
247
|
+
* @param buffer The raw trace buffer to parse.
|
|
248
|
+
* @param options Optional configuration settings for batch processing.
|
|
249
249
|
* @returns A {@link ParsedTraceBuffer} containing parsed trace events and optional file metadata, or an object with an empty events array if the buffer is empty or contains only whitespace.
|
|
250
250
|
* @throws {Error} If the buffer contains non-whitespace data that does not begin with a valid JSON array or object.
|
|
251
251
|
* @throws {SyntaxError} If the underlying JSON syntax within batches or metadata is invalid.
|