chrome-devtools-mcp 1.11.0 → 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.
Files changed (72) hide show
  1. package/README.md +72 -20
  2. package/build/src/BrowserManager.js +27 -18
  3. package/build/src/McpContext.js +435 -87
  4. package/build/src/McpPage.js +189 -59
  5. package/build/src/McpResponse.js +61 -44
  6. package/build/src/TextSnapshot.js +37 -18
  7. package/build/src/ToolHandler.js +256 -135
  8. package/build/src/bin/chrome-devtools-mcp-main.js +6 -4
  9. package/build/src/bin/chrome-devtools.js +4 -4
  10. package/build/src/collectors/PageCollector.js +13 -9
  11. package/build/src/collectors/ServiceWorkerCollector.js +2 -2
  12. package/build/src/collectors/constants.js +7 -0
  13. package/build/src/config/ConfigParser.js +44 -149
  14. package/build/src/config/ConfigWatcher.js +3 -2
  15. package/build/src/config/ServerConfig.js +251 -0
  16. package/build/src/config/browser-options.js +13 -4
  17. package/build/src/config/cli-options.js +35 -19
  18. package/build/src/config/mcp-options.js +61 -35
  19. package/build/src/config/puppeteer-options.js +4 -2
  20. package/build/src/daemon/client.js +3 -3
  21. package/build/src/daemon/daemon.js +7 -3
  22. package/build/src/daemon/utils.js +2 -1
  23. package/build/src/devtools/DevToolsCommentBridge.js +28 -5
  24. package/build/src/devtools/DevtoolsUtils.js +49 -12
  25. package/build/src/formatters/ConsoleFormatter.js +28 -1
  26. package/build/src/formatters/HeapSnapshotFormatter.js +14 -18
  27. package/build/src/formatters/NetworkFormatter.js +54 -15
  28. package/build/src/formatters/RemoteObjectFormatter.js +231 -0
  29. package/build/src/formatters/SnapshotFormatter.js +13 -3
  30. package/build/src/index.js +256 -104
  31. package/build/src/processors/HeapSnapshotManager.js +390 -128
  32. package/build/src/third_party/THIRD_PARTY_NOTICES +542 -445
  33. package/build/src/third_party/bundled-packages.json +2 -2
  34. package/build/src/third_party/cli.js +9239 -0
  35. package/build/src/third_party/devtools-formatter-worker.js +3089 -2438
  36. package/build/src/third_party/devtools-heap-snapshot-worker.js +172 -1
  37. package/build/src/third_party/index.js +52247 -55764
  38. package/build/src/third_party/lighthouse-devtools-mcp-bundle.js +54576 -52174
  39. package/build/src/tools/ToolDefinition.js +90 -12
  40. package/build/src/tools/comments.js +42 -3
  41. package/build/src/tools/console.js +6 -4
  42. package/build/src/tools/css.js +1 -0
  43. package/build/src/tools/emulation.js +5 -4
  44. package/build/src/tools/extensions.js +5 -0
  45. package/build/src/tools/input.js +21 -6
  46. package/build/src/tools/lighthouse.js +24 -8
  47. package/build/src/tools/memory.js +59 -53
  48. package/build/src/tools/network.js +5 -4
  49. package/build/src/tools/pages.js +48 -6
  50. package/build/src/tools/performance.js +7 -4
  51. package/build/src/tools/pwa.js +7 -0
  52. package/build/src/tools/screencast.js +3 -1
  53. package/build/src/tools/screenshot.js +23 -7
  54. package/build/src/tools/script.js +38 -6
  55. package/build/src/tools/slim/tools.js +21 -5
  56. package/build/src/tools/snapshot.js +13 -3
  57. package/build/src/tools/thirdPartyDeveloper.js +3 -1
  58. package/build/src/tools/webmcp.js +2 -0
  59. package/build/src/utils/TaskRunner.js +136 -0
  60. package/build/src/utils/WaitForHelper.js +1 -1
  61. package/build/src/utils/bytes.js +2 -12
  62. package/build/src/utils/check-for-updates.js +1 -1
  63. package/build/src/utils/disclaimers.js +27 -0
  64. package/build/src/utils/keyboard.js +14 -2
  65. package/build/src/utils/logger.js +69 -0
  66. package/build/src/utils/resourceType.js +27 -0
  67. package/build/src/utils/text.js +29 -0
  68. package/build/src/utils/timeout.js +14 -0
  69. package/build/src/utils/url.js +41 -0
  70. package/build/src/version.js +1 -1
  71. package/package.json +5 -4
  72. package/skills/a11y-debugging/SKILL.md +3 -8
@@ -3,55 +3,122 @@
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';
11
67
  import { HeapSnapshotManager } from './processors/HeapSnapshotManager.js';
12
68
  import { ClearcutLogger } from './telemetry/ClearcutLogger.js';
13
69
  import { FilePersistence } from './telemetry/persistence.js';
14
- import { McpServer as SdkMcpServer, Mutex, puppeteer, } from './third_party/index.js';
70
+ import { McpServer as SdkMcpServer, ProtocolError, ProtocolErrorCode, puppeteer, } from './third_party/index.js';
15
71
  import { ToolHandler } from './ToolHandler.js';
16
- import { isAvailableInMode, } from './tools/ToolDefinition.js';
17
72
  import { createTools } from './tools/tools.js';
73
+ import { logCruxDisclaimer } from './utils/disclaimers.js';
74
+ import { getErrorMessage } from './utils/errorHandling.js';
18
75
  import { logger } from './utils/logger.js';
76
+ import { TaskRunner } from './utils/TaskRunner.js';
19
77
  import { VERSION } from './version.js';
20
78
  puppeteer.setFollowSymlinks(false);
21
79
  /**
22
80
  * Timeout for a `roots/list` that a tool call is waiting on, matching the 5s
23
- * default used for page operations. `getContext()` awaits it while
24
- * `ToolHandler` holds the tool mutex, so leaving it unbounded lets a client
25
- * that negotiates `roots` but does not answer block every tool for the SDK's
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
26
84
  * default of 60s. Background refreshes are not bounded by this, so roots a
27
85
  * slow client sends late still land.
28
86
  */
29
87
  const ROOTS_REQUEST_TIMEOUT = 5_000;
30
88
  export class McpServer {
31
89
  server;
32
- #serverArgs;
90
+ #config;
33
91
  #browserManager;
34
92
  #context;
35
- #heapSnapshotManager = new HeapSnapshotManager();
93
+ /** Runs every tool call and config reload. */
94
+ #taskRunner = new TaskRunner();
95
+ #heapSnapshotManager = new HeapSnapshotManager(this.#taskRunner);
36
96
  /**
37
97
  * Client roots stay valid across browser reconnects and only the client can
38
98
  * invalidate them through a `roots/list_changed` notification. CLI-configured
39
- * roots are read from `#serverArgs` when combining roots.
99
+ * roots are read from `#config` when combining roots.
40
100
  */
41
101
  #lastClientRoots;
42
- #toolMutex = new Mutex();
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;
43
109
  #tools = new Map();
44
- constructor(serverArgs, options) {
45
- this.#serverArgs = serverArgs;
110
+ constructor(config, options) {
111
+ this.#config = config;
46
112
  this.#browserManager = options.browserManager;
47
- if (this.#serverArgs.usageStatistics) {
113
+ const serverArgs = this.#config.resolved;
114
+ if (serverArgs.usageStatistics) {
48
115
  ClearcutLogger.initialize({
49
116
  persistence: new FilePersistence(),
50
- logFile: this.#serverArgs.logFile,
117
+ logFile: serverArgs.logFile,
51
118
  appVersion: VERSION,
52
- clearcutEndpoint: this.#serverArgs.clearcutEndpoint,
53
- clearcutForceFlushIntervalMs: this.#serverArgs.clearcutForceFlushIntervalMs,
54
- clearcutIncludePidHeader: this.#serverArgs.clearcutIncludePidHeader,
119
+ clearcutEndpoint: serverArgs.clearcutEndpoint,
120
+ clearcutForceFlushIntervalMs: serverArgs.clearcutForceFlushIntervalMs,
121
+ clearcutIncludePidHeader: serverArgs.clearcutIncludePidHeader,
55
122
  });
56
123
  }
57
124
  this.server = new SdkMcpServer({
@@ -63,6 +130,13 @@ export class McpServer {
63
130
  // Enabling or updating many tools at once sends a single notification.
64
131
  debouncedNotificationMethods: ['notifications/tools/list_changed'],
65
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());
66
140
  this.server.server.setRequestHandler('logging/setLevel', () => {
67
141
  return {};
68
142
  });
@@ -77,8 +151,9 @@ export class McpServer {
77
151
  void this.#updateRoots();
78
152
  });
79
153
  }
80
- else if (!this.#serverArgs.allowUnrestrictedPaths &&
81
- (this.#serverArgs.filesystemRoot ?? []).length === 0) {
154
+ else if (!this.#config.resolved.allowUnrestrictedPaths &&
155
+ ((this.#config.resolved.filesystemRoot ?? []).length === 0 ||
156
+ this.#config.resolved.filesystemRoot === DEFAULT_FILESYSTEM_ROOT)) {
82
157
  console.warn('[chrome-devtools-mcp] The connecting client did not negotiate the MCP roots ' +
83
158
  'capability. Tools that read or write local files will be restricted to the OS temp directory. ' +
84
159
  'To restore the previous unrestricted behavior, start the server with ' +
@@ -87,6 +162,9 @@ export class McpServer {
87
162
  };
88
163
  }
89
164
  async connect(transport) {
165
+ if (this.#config.resolved.watchConfig) {
166
+ this.watchConfig();
167
+ }
90
168
  return await this.server.connect(transport);
91
169
  }
92
170
  async callTool(name, args = {}) {
@@ -102,35 +180,131 @@ export class McpServer {
102
180
  isError: true,
103
181
  };
104
182
  }
105
- const parseResult = await toolHandler.registeredInputSchema.safeParseAsync(args);
106
- if (!parseResult.success) {
107
- return {
108
- content: [
109
- {
110
- type: 'text',
111
- text: `Input validation error: Invalid arguments for tool ${name}: ${parseResult.error.issues
112
- .map(issue => `${issue.path.length > 0 ? `${issue.path.join('.')}: ` : ''}${issue.message}`)
113
- .join(', ')}`,
114
- },
115
- ],
116
- isError: true,
117
- };
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);
118
294
  }
119
- return await toolHandler.handle(parseResult.data);
120
295
  }
121
296
  /**
122
297
  * Closes the MCP connection and disposes internal context/listeners.
123
298
  */
124
299
  async close() {
300
+ this.#configWatcher?.dispose();
301
+ this.#configWatcher = undefined;
125
302
  try {
126
- this.#context?.dispose();
303
+ this.#context.dispose();
127
304
  }
128
305
  catch (err) {
129
306
  logger?.('Failed to dispose context', err);
130
307
  }
131
- finally {
132
- this.#context = undefined;
133
- }
134
308
  this.#heapSnapshotManager.dispose();
135
309
  await Promise.allSettled([
136
310
  this.#browserManager.close(),
@@ -145,24 +319,22 @@ export class McpServer {
145
319
  async [Symbol.asyncDispose]() {
146
320
  await this.close();
147
321
  }
148
- static async from(serverArgs, options) {
149
- const server = new McpServer(serverArgs, options);
322
+ static async from(config, options) {
323
+ const server = new McpServer(config, options);
150
324
  await server.#init();
151
325
  return server;
152
326
  }
153
327
  async #init() {
154
- for (const tool of createTools(this.#serverArgs)) {
155
- // Slim and regular tools may share names, only register the current mode.
156
- if (isAvailableInMode(tool, this.#serverArgs)) {
157
- this.#registerTool(tool);
158
- }
328
+ // Tool definitions take a ParsedArguments snapshot; reload recreates them.
329
+ for (const tool of createTools(this.#config.resolved)) {
330
+ this.#registerTool(tool);
159
331
  }
332
+ this.#setToolCallRequestHandler();
160
333
  await loadIssueDescriptions();
161
334
  }
162
335
  #combinedRoots() {
163
- const configuredRoots = (this.#serverArgs.allowUnrestrictedPaths
164
- ? []
165
- : (this.#serverArgs.filesystemRoot ?? [])).map(root => {
336
+ const serverArgs = this.#config.resolved;
337
+ const configuredRoots = (serverArgs.allowUnrestrictedPaths ? [] : (serverArgs.filesystemRoot ?? [])).map(root => {
166
338
  const rootPath = path.resolve(root);
167
339
  return {
168
340
  uri: pathToFileURL(rootPath).href,
@@ -176,8 +348,9 @@ export class McpServer {
176
348
  }
177
349
  /**
178
350
  * `timeout` is only passed where a tool call is waiting on the result – the
179
- * background refreshes below block nobody, so bounding them would just discard
180
- * roots a slow client was about to send
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
181
354
  */
182
355
  async #updateRoots(timeout) {
183
356
  if (!this.server.server.getClientCapabilities()?.roots) {
@@ -186,55 +359,39 @@ export class McpServer {
186
359
  try {
187
360
  const result = await this.server.server.request({ method: 'roots/list' }, timeout === undefined ? undefined : { timeout });
188
361
  this.#lastClientRoots = result.roots;
189
- this.#context?.setRoots(this.#combinedRoots());
362
+ this.#context.setRoots(this.#combinedRoots());
190
363
  }
191
364
  catch (e) {
192
365
  logger?.('Failed to list roots', e);
193
366
  }
194
367
  }
195
368
  async #getContext() {
196
- const browser = await this.#browserManager.ensureBrowser();
197
- if (this.#context?.browser !== browser) {
198
- this.#context?.dispose();
199
- this.#context = await McpContext.from(browser, logger, {
200
- experimentalDevToolsDebugging: this.#serverArgs.experimentalDevtools ?? false,
201
- experimentalIncludeAllPages: this.#serverArgs.experimentalIncludeAllPages,
202
- performanceCrux: this.#serverArgs.performanceCrux,
203
- sourceMaps: this.#serverArgs.sourceMaps,
204
- allowlist: this.#serverArgs.allowedUrlPattern,
205
- blocklist: this.#serverArgs.blockedUrlPattern,
206
- allowUnrestrictedPaths: this.#serverArgs.allowUnrestrictedPaths,
207
- // Surfaces a one-time note in the next response after a reconnect.
208
- reconnected: this.#context !== undefined,
209
- categoryExtensions: this.#serverArgs.categoryExtensions,
210
- heapSnapshotManager: this.#heapSnapshotManager,
211
- onNotification: (message) => {
212
- void this.server
213
- .sendLoggingMessage({
214
- level: 'info',
215
- data: message,
216
- })
217
- .catch(e => {
218
- logger?.('Failed to send MCP notification', e);
219
- });
220
- },
221
- });
222
- this.#context.setRoots(this.#combinedRoots());
223
- if (this.#lastClientRoots === undefined) {
224
- // Nothing listed yet, so this call has to wait – bounded, since it is
225
- // holding the tool mutex, and a later background refresh still lands
226
- await this.#updateRoots(ROOTS_REQUEST_TIMEOUT);
227
- }
228
- else {
229
- // Carry the known roots over and refresh out of band, so a reconnect
230
- // never pays for a client round-trip
231
- void this.#updateRoots();
232
- }
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;
233
374
  }
234
375
  return this.#context;
235
376
  }
236
377
  #createToolHandler(tool) {
237
- return new ToolHandler(tool, this.#serverArgs, () => this.#getContext(), this.#toolMutex, () => this.#browserManager.abandonPendingAttempt());
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
+ });
238
395
  }
239
396
  #registerTool(tool) {
240
397
  const handler = this.#createToolHandler(tool);
@@ -242,7 +399,7 @@ export class McpServer {
242
399
  description: tool.description,
243
400
  inputSchema: handler.registeredInputSchema,
244
401
  annotations: tool.annotations,
245
- }, handler.handle);
402
+ }, args => handler.handle(args));
246
403
  if (handler.disabled) {
247
404
  registeredTool.disable();
248
405
  }
@@ -254,29 +411,24 @@ export class McpServer {
254
411
  *
255
412
  * Maintained as a public API for backwards compatibility because external
256
413
  * consumers and integrations rely on `createMcpServer()`. For new code,
257
- * prefer using `McpServer.from(serverArgs, options)`.
414
+ * prefer using `McpServer.from(config, options)`.
258
415
  */
259
416
  export async function createMcpServer(serverArgs, options) {
260
- const browserManager = new BrowserManager(serverArgs, {
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, {
261
426
  logFile: options.logFile,
262
427
  });
263
- const server = await McpServer.from(serverArgs, {
428
+ const server = await McpServer.from(serverConfig, {
264
429
  browserManager,
265
430
  ...options,
266
431
  });
267
432
  return { server: server.server };
268
433
  }
269
- export const logDisclaimers = (args) => {
270
- console.error(`chrome-devtools-mcp exposes content of the browser instance to the MCP clients allowing them to inspect,
271
- debug, and modify any data in the browser or DevTools.
272
- Avoid sharing sensitive or personal information that you do not want to share with MCP clients.`);
273
- if (!args.slim && args.performanceCrux) {
274
- 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.`);
275
- }
276
- if (!args.slim && args.usageStatistics) {
277
- console.error(`
278
- Google collects usage statistics to improve Chrome DevTools MCP. To opt-out, run with --no-usage-statistics.
279
- For more details, visit: https://github.com/ChromeDevTools/chrome-devtools-mcp#usage-statistics`);
280
- }
281
- };
282
434
  //# sourceMappingURL=index.js.map