chrome-devtools-mcp 1.9.0 → 1.10.1
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/build/src/BrowserManager.js +401 -0
- package/build/src/McpContext.js +5 -5
- package/build/src/McpPage.js +107 -3
- package/build/src/McpResponse.js +68 -3
- package/build/src/ToolHandler.js +172 -118
- package/build/src/bin/chrome-devtools-mcp-main.js +11 -6
- package/build/src/bin/chrome-devtools.js +6 -12
- package/build/src/collectors/PageCollector.js +66 -3
- package/build/src/config/browser-options.js +2 -0
- package/build/src/config/category-options.js +13 -4
- package/build/src/config/cli-commands.js +26 -0
- package/build/src/config/cli-options.js +32 -0
- package/build/src/config/mcp-options.js +40 -1
- package/build/src/devtools/DevToolsCommentBridge.js +91 -0
- package/build/src/formatters/CommentFormatter.js +82 -0
- package/build/src/formatters/CssFormatter.js +812 -0
- package/build/src/index.js +53 -72
- package/build/src/processors/ChunkedTraceParser.js +361 -0
- package/build/src/processors/PerformanceTrace.js +60 -13
- package/build/src/telemetry/ClearcutLogger.js +91 -34
- package/build/src/telemetry/metricsRegistry.js +3 -0
- package/build/src/telemetry/persistence.js +17 -7
- package/build/src/telemetry/transformation.js +53 -4
- package/build/src/telemetry/types.js +1 -0
- package/build/src/third_party/THIRD_PARTY_NOTICES +715 -131
- package/build/src/third_party/bundled-packages.json +6 -3
- package/build/src/third_party/devtools-formatter-worker.js +136 -5
- package/build/src/third_party/devtools-heap-snapshot-worker.js +567 -6
- package/build/src/third_party/index.js +54948 -35497
- package/build/src/third_party/issue-descriptions/webInstallManifestMissingId.md +3 -0
- package/build/src/third_party/issue-descriptions/webInstallManifestMissingNameOrShortName.md +3 -0
- package/build/src/third_party/issue-descriptions/webInstallManifestParsingOrNetworkError.md +3 -0
- package/build/src/third_party/issue-descriptions/webInstallNoManifest.md +3 -0
- package/build/src/third_party/issue-descriptions/webInstallStartUrlInvalid.md +3 -0
- package/build/src/tools/ToolDefinition.js +13 -21
- package/build/src/tools/comments.js +169 -0
- package/build/src/tools/console.js +3 -3
- package/build/src/tools/css.js +45 -0
- package/build/src/tools/emulation.js +5 -5
- package/build/src/tools/extensions.js +10 -10
- package/build/src/tools/input.js +159 -87
- package/build/src/tools/lighthouse.js +18 -7
- package/build/src/tools/memory.js +26 -26
- package/build/src/tools/network.js +4 -4
- package/build/src/tools/pages.js +14 -14
- package/build/src/tools/performance.js +6 -6
- package/build/src/tools/pwa.js +8 -8
- package/build/src/tools/screencast.js +4 -4
- package/build/src/tools/screenshot.js +2 -2
- package/build/src/tools/script.js +7 -7
- package/build/src/tools/slim/tools.js +5 -5
- package/build/src/tools/snapshot.js +4 -4
- package/build/src/tools/thirdPartyDeveloper.js +4 -4
- package/build/src/tools/tools.js +6 -9
- package/build/src/tools/webmcp.js +4 -4
- package/build/src/types.js +4 -1
- package/build/src/utils/WaitForHelper.js +14 -8
- package/build/src/utils/logger.js +7 -6
- package/build/src/version.js +1 -1
- package/package.json +8 -5
- package/skills/chrome-devtools/SKILL.md +2 -1
- package/skills/chrome-devtools-cli/SKILL.md +2 -0
- package/build/src/browser.js +0 -233
- package/build/src/third_party/issue-descriptions/cookieExcludeBlockedWithinRelatedWebsiteSet.md +0 -4
package/build/src/McpResponse.js
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
+
import { CommentFormatter, } from './formatters/CommentFormatter.js';
|
|
6
7
|
import { ConsoleFormatter } from './formatters/ConsoleFormatter.js';
|
|
8
|
+
import { CssFormatter, resolveContainerQueries, } from './formatters/CssFormatter.js';
|
|
7
9
|
import { HeapSnapshotFormatter, isEdgeLike, isNodeLike, } from './formatters/HeapSnapshotFormatter.js';
|
|
8
10
|
import { IssueFormatter } from './formatters/IssueFormatter.js';
|
|
9
11
|
import { NetworkFormatter } from './formatters/NetworkFormatter.js';
|
|
@@ -32,6 +34,7 @@ export class McpResponse {
|
|
|
32
34
|
#heapSnapshotOptions;
|
|
33
35
|
#networkRequestsOptions;
|
|
34
36
|
#consoleDataOptions;
|
|
37
|
+
#cssStylesData;
|
|
35
38
|
#listExtensions;
|
|
36
39
|
#listThirdPartyDeveloperTools;
|
|
37
40
|
#listWebMcpTools;
|
|
@@ -43,6 +46,7 @@ export class McpResponse {
|
|
|
43
46
|
#error;
|
|
44
47
|
#attachedWaitForResult;
|
|
45
48
|
#reconnectNotice = false;
|
|
49
|
+
#devToolsComments;
|
|
46
50
|
get #deviceScope() {
|
|
47
51
|
return this.#page?.viewport?.isMobile ? 'PHONE' : 'DESKTOP';
|
|
48
52
|
}
|
|
@@ -126,6 +130,12 @@ export class McpResponse {
|
|
|
126
130
|
serviceWorkerId: options?.serviceWorkerId,
|
|
127
131
|
};
|
|
128
132
|
}
|
|
133
|
+
setIncludeCssStyles(matchedStyles, options) {
|
|
134
|
+
this.#cssStylesData = {
|
|
135
|
+
matchedStyles,
|
|
136
|
+
options,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
129
139
|
setError(error) {
|
|
130
140
|
this.#error = error;
|
|
131
141
|
}
|
|
@@ -188,6 +198,12 @@ export class McpResponse {
|
|
|
188
198
|
attachWaitForResult(result) {
|
|
189
199
|
this.#attachedWaitForResult = result;
|
|
190
200
|
}
|
|
201
|
+
setDevToolsComments(threads) {
|
|
202
|
+
this.#devToolsComments = threads;
|
|
203
|
+
}
|
|
204
|
+
get devToolsComments() {
|
|
205
|
+
return this.#devToolsComments;
|
|
206
|
+
}
|
|
191
207
|
setHeapSnapshotAggregates(aggregateData, options) {
|
|
192
208
|
this.#heapSnapshotOptions = {
|
|
193
209
|
...this.#heapSnapshotOptions,
|
|
@@ -437,8 +453,23 @@ export class McpResponse {
|
|
|
437
453
|
redactNetworkHeaders: this.#redactNetworkHeaders,
|
|
438
454
|
})));
|
|
439
455
|
}
|
|
456
|
+
async #handleComments() {
|
|
457
|
+
const comments = this.#devToolsComments;
|
|
458
|
+
if (!comments) {
|
|
459
|
+
return undefined;
|
|
460
|
+
}
|
|
461
|
+
const page = this.#page;
|
|
462
|
+
return await CommentFormatter.from(comments, {
|
|
463
|
+
resolveBackendNodeId: page
|
|
464
|
+
? (id) => page.resolveBackendNodeId(id)
|
|
465
|
+
: undefined,
|
|
466
|
+
resolveCdpRequestId: page
|
|
467
|
+
? (id) => page.resolveCdpRequestId(id)
|
|
468
|
+
: undefined,
|
|
469
|
+
});
|
|
470
|
+
}
|
|
440
471
|
async handle(context, dataFormat = 'default') {
|
|
441
|
-
const [snapshot, detailedNetworkRequest, detailedConsoleMessage, thirdPartyDeveloperTools, webmcpTools, consoleMessages, networkRequests,] = await Promise.all([
|
|
472
|
+
const [snapshot, detailedNetworkRequest, detailedConsoleMessage, thirdPartyDeveloperTools, webmcpTools, consoleMessages, networkRequests, comments,] = await Promise.all([
|
|
442
473
|
this.#handleSnapshot(context),
|
|
443
474
|
this.#handleAttachedNetworkRequest(context),
|
|
444
475
|
this.#handleAttachedConsoleMessage(),
|
|
@@ -446,6 +477,7 @@ export class McpResponse {
|
|
|
446
477
|
this.#handleWebMCP(),
|
|
447
478
|
this.#handleConsoleList(context),
|
|
448
479
|
this.#handleNetworkRequestList(context),
|
|
480
|
+
this.#handleComments(),
|
|
449
481
|
]);
|
|
450
482
|
if (this.#includeExtensionServiceWorkers) {
|
|
451
483
|
await context.createExtensionServiceWorkersSnapshot();
|
|
@@ -466,6 +498,7 @@ export class McpResponse {
|
|
|
466
498
|
lighthouseResult: this.#attachedLighthouseResult,
|
|
467
499
|
thirdPartyDeveloperTools,
|
|
468
500
|
webmcpTools,
|
|
501
|
+
comments,
|
|
469
502
|
errorMessage: this.#error?.message,
|
|
470
503
|
}, dataFormat);
|
|
471
504
|
}
|
|
@@ -504,7 +537,7 @@ export class McpResponse {
|
|
|
504
537
|
const response = [];
|
|
505
538
|
if (this.#reconnectNotice) {
|
|
506
539
|
structuredContent.reconnected = true;
|
|
507
|
-
response.push(`Note: the browser was restarted or reconnected since the last call. Page ids have changed. Call ${listPages().name} to see open pages.`);
|
|
540
|
+
response.push(`Note: the browser was restarted or reconnected since the last call. Page ids have changed. Call ${listPages(this.#args).name} to see open pages.`);
|
|
508
541
|
}
|
|
509
542
|
if (this.#textResponseLines.length) {
|
|
510
543
|
structuredContent.message = this.#textResponseLines.join('\n');
|
|
@@ -557,7 +590,7 @@ export class McpResponse {
|
|
|
557
590
|
: '';
|
|
558
591
|
response.push(`# Open dialog
|
|
559
592
|
${dialog.type()}: ${dialog.message()}${defaultValueIfNeeded}.
|
|
560
|
-
Call ${handleDialog.name} to handle it before continuing.`);
|
|
593
|
+
Call ${handleDialog(this.#args).name} to handle it before continuing.`);
|
|
561
594
|
structuredContent.dialog = {
|
|
562
595
|
type: dialog.type(),
|
|
563
596
|
message: dialog.message(),
|
|
@@ -939,6 +972,38 @@ Call ${handleDialog.name} to handle it before continuing.`);
|
|
|
939
972
|
response.push('<no console messages found>');
|
|
940
973
|
}
|
|
941
974
|
}
|
|
975
|
+
if (data.comments) {
|
|
976
|
+
const commentsJson = data.comments.toJSON();
|
|
977
|
+
structuredContent.comments = commentsJson;
|
|
978
|
+
response.push(compactEncode ? compactEncode(commentsJson) : data.comments.toString());
|
|
979
|
+
}
|
|
980
|
+
if (this.#cssStylesData) {
|
|
981
|
+
const resolveUid = (backendNodeId) => this.#page?.textSnapshot?.resolveCdpElementId(backendNodeId);
|
|
982
|
+
const containerDetails = await resolveContainerQueries(this.#cssStylesData.matchedStyles, resolveUid);
|
|
983
|
+
const options = {
|
|
984
|
+
...this.#cssStylesData.options,
|
|
985
|
+
resolveUid,
|
|
986
|
+
containerDetails,
|
|
987
|
+
};
|
|
988
|
+
const allRules = CssFormatter.collectRules(this.#cssStylesData.matchedStyles, options);
|
|
989
|
+
let rules = allRules;
|
|
990
|
+
const hasPagination = this.#cssStylesData.options.pageSize !== undefined ||
|
|
991
|
+
this.#cssStylesData.options.pageIdx !== undefined;
|
|
992
|
+
if (hasPagination) {
|
|
993
|
+
const paginationData = this.#dataWithPagination(allRules, this.#cssStylesData.options);
|
|
994
|
+
structuredContent.pagination = paginationData.pagination;
|
|
995
|
+
response.push(...paginationData.info);
|
|
996
|
+
rules = paginationData.items;
|
|
997
|
+
}
|
|
998
|
+
const formatter = new CssFormatter(this.#cssStylesData.matchedStyles, options, rules);
|
|
999
|
+
structuredContent.matchedStyles = formatter.toJSON();
|
|
1000
|
+
if (compactEncode) {
|
|
1001
|
+
response.push(compactEncode(structuredContent.matchedStyles));
|
|
1002
|
+
}
|
|
1003
|
+
else {
|
|
1004
|
+
response.push(formatter.toString());
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
942
1007
|
if (data.errorMessage) {
|
|
943
1008
|
response.push(`Error: ${data.errorMessage}`);
|
|
944
1009
|
structuredContent.errorMessage = data.errorMessage;
|
package/build/src/ToolHandler.js
CHANGED
|
@@ -3,13 +3,64 @@
|
|
|
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 { McpResponse } from './McpResponse.js';
|
|
7
59
|
import { SlimMcpResponse } from './SlimMcpResponse.js';
|
|
8
60
|
import { ClearcutLogger } from './telemetry/ClearcutLogger.js';
|
|
9
61
|
import { zod } from './third_party/index.js';
|
|
10
62
|
import { labels } from './tools/categories.js';
|
|
11
63
|
import { categoryToFlagName } from './config/category-options.js';
|
|
12
|
-
import { pageIdSchema } from './tools/ToolDefinition.js';
|
|
13
64
|
import { logger } from './utils/logger.js';
|
|
14
65
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
15
66
|
import { isLocalhost } from './utils/url.js';
|
|
@@ -121,7 +172,7 @@ export class ToolHandler {
|
|
|
121
172
|
toolMutex;
|
|
122
173
|
inputSchema;
|
|
123
174
|
registeredInputSchema;
|
|
124
|
-
|
|
175
|
+
disabled;
|
|
125
176
|
disabledReason;
|
|
126
177
|
constructor(tool, serverArgs, getContext, toolMutex) {
|
|
127
178
|
this.tool = tool;
|
|
@@ -130,139 +181,142 @@ export class ToolHandler {
|
|
|
130
181
|
this.toolMutex = toolMutex;
|
|
131
182
|
const { disabled, reason } = getToolStatusInfo(tool, serverArgs);
|
|
132
183
|
this.disabledReason = reason;
|
|
133
|
-
this.
|
|
134
|
-
this.inputSchema =
|
|
135
|
-
|
|
136
|
-
tool.pageScoped &&
|
|
137
|
-
serverArgs.pageIdRouting &&
|
|
138
|
-
!serverArgs.slim
|
|
139
|
-
? { ...pageIdSchema, ...tool.schema }
|
|
140
|
-
: tool.schema;
|
|
141
|
-
this.registeredInputSchema = zod.object(this.inputSchema).passthrough();
|
|
184
|
+
this.disabled = disabled && !serverArgs.viaCli;
|
|
185
|
+
this.inputSchema = tool.schema;
|
|
186
|
+
this.registeredInputSchema = zod.object(this.inputSchema).loose();
|
|
142
187
|
}
|
|
143
188
|
unknownArgumentNames(params) {
|
|
144
189
|
return Object.keys(params).filter(key => !Object.hasOwn(this.inputSchema, key));
|
|
145
190
|
}
|
|
146
|
-
async
|
|
147
|
-
|
|
148
|
-
return {
|
|
149
|
-
content: [
|
|
150
|
-
{
|
|
151
|
-
type: 'text',
|
|
152
|
-
text: this.disabledReason,
|
|
153
|
-
},
|
|
154
|
-
],
|
|
155
|
-
isError: true,
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
const unknownArgumentNames = this.unknownArgumentNames(params);
|
|
159
|
-
if (unknownArgumentNames.length) {
|
|
160
|
-
return {
|
|
161
|
-
content: [
|
|
162
|
-
{
|
|
163
|
-
type: 'text',
|
|
164
|
-
text: buildUnknownArgumentsMessage(this.tool.name, unknownArgumentNames, Object.keys(this.inputSchema)),
|
|
165
|
-
},
|
|
166
|
-
],
|
|
167
|
-
isError: true,
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
const guard = await this.toolMutex.acquire();
|
|
171
|
-
const startTime = Date.now();
|
|
172
|
-
let success = false;
|
|
173
|
-
let devToolsData;
|
|
174
|
-
let pageUrl;
|
|
191
|
+
handle = async (params) => {
|
|
192
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
175
193
|
try {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
194
|
+
const _guard = __addDisposableResource(env_1, await this.toolMutex.acquire(), false);
|
|
195
|
+
if (this.disabledReason) {
|
|
196
|
+
return {
|
|
197
|
+
content: [
|
|
198
|
+
{
|
|
199
|
+
type: 'text',
|
|
200
|
+
text: this.disabledReason,
|
|
201
|
+
},
|
|
202
|
+
],
|
|
203
|
+
isError: true,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
const unknownArgumentNames = this.unknownArgumentNames(params);
|
|
207
|
+
if (unknownArgumentNames.length) {
|
|
208
|
+
return {
|
|
209
|
+
content: [
|
|
210
|
+
{
|
|
211
|
+
type: 'text',
|
|
212
|
+
text: buildUnknownArgumentsMessage(this.tool.name, unknownArgumentNames, Object.keys(this.inputSchema)),
|
|
213
|
+
},
|
|
214
|
+
],
|
|
215
|
+
isError: true,
|
|
216
|
+
};
|
|
185
217
|
}
|
|
186
|
-
|
|
218
|
+
const startTime = Date.now();
|
|
219
|
+
let success = false;
|
|
220
|
+
let devToolsData;
|
|
221
|
+
let pageUrl;
|
|
187
222
|
try {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
223
|
+
logger?.(`${this.tool.name} request: ${JSON.stringify(params, null, ' ')}`);
|
|
224
|
+
const context = await this.getContext();
|
|
225
|
+
logger?.(`${this.tool.name} context: resolved`);
|
|
226
|
+
const response = this.serverArgs.slim
|
|
227
|
+
? new SlimMcpResponse(this.serverArgs)
|
|
228
|
+
: new McpResponse(this.serverArgs);
|
|
229
|
+
response.setRedactNetworkHeaders(this.serverArgs.redactNetworkHeaders);
|
|
230
|
+
if (context.consumeReconnectNotice()) {
|
|
231
|
+
response.setReconnectNotice();
|
|
232
|
+
}
|
|
233
|
+
let page;
|
|
234
|
+
try {
|
|
235
|
+
await validateToolFiles(this.tool, params, context);
|
|
236
|
+
if (isPageScopedTool(this.tool)) {
|
|
237
|
+
const pageId = typeof params.pageId === 'number' ? params.pageId : undefined;
|
|
238
|
+
page =
|
|
239
|
+
this.serverArgs.pageIdRouting &&
|
|
240
|
+
pageId !== undefined &&
|
|
241
|
+
!this.serverArgs.slim
|
|
242
|
+
? context.getPageById(pageId)
|
|
243
|
+
: context.getSelectedMcpPage();
|
|
244
|
+
response.setPage(page);
|
|
245
|
+
if (this.tool.blockedByDialog) {
|
|
246
|
+
page.throwIfDialogOpen();
|
|
247
|
+
}
|
|
248
|
+
await this.tool.handler({
|
|
249
|
+
params,
|
|
250
|
+
page,
|
|
251
|
+
}, response, context);
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
await this.tool.handler({
|
|
255
|
+
params,
|
|
256
|
+
}, response, context);
|
|
200
257
|
}
|
|
201
|
-
await this.tool.handler({
|
|
202
|
-
params,
|
|
203
|
-
page,
|
|
204
|
-
}, response, context);
|
|
205
258
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
259
|
+
catch (err) {
|
|
260
|
+
response.setError(err);
|
|
261
|
+
}
|
|
262
|
+
devToolsData = await context.getDevToolsData(page);
|
|
263
|
+
pageUrl = context.getSelectedMcpPageUrl(page);
|
|
264
|
+
// Resolve data format: --experimentalDataFormat takes precedence, fall back to legacy --experimentalToonFormat
|
|
265
|
+
let dataFormat = 'default';
|
|
266
|
+
if (this.serverArgs.experimentalDataFormat) {
|
|
267
|
+
dataFormat = this.serverArgs.experimentalDataFormat;
|
|
210
268
|
}
|
|
269
|
+
else if (this.serverArgs.experimentalToonFormat) {
|
|
270
|
+
dataFormat = 'toon';
|
|
271
|
+
}
|
|
272
|
+
const { content, structuredContent } = await response.handle(context, dataFormat);
|
|
273
|
+
const result = {
|
|
274
|
+
content,
|
|
275
|
+
};
|
|
276
|
+
if (response.error) {
|
|
277
|
+
result.isError = true;
|
|
278
|
+
}
|
|
279
|
+
success = true;
|
|
280
|
+
if (this.serverArgs.experimentalStructuredContent) {
|
|
281
|
+
result.structuredContent = structuredContent;
|
|
282
|
+
}
|
|
283
|
+
return result;
|
|
211
284
|
}
|
|
212
285
|
catch (err) {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
content,
|
|
228
|
-
};
|
|
229
|
-
if (response.error) {
|
|
230
|
-
result.isError = true;
|
|
286
|
+
logger?.(`${this.tool.name} error:`, err, err?.stack);
|
|
287
|
+
let errorText = err && 'message' in err ? err.message : String(err);
|
|
288
|
+
if ('cause' in err && err.cause) {
|
|
289
|
+
errorText += `\nCause: ${err.cause.message}`;
|
|
290
|
+
}
|
|
291
|
+
return {
|
|
292
|
+
content: [
|
|
293
|
+
{
|
|
294
|
+
type: 'text',
|
|
295
|
+
text: errorText,
|
|
296
|
+
},
|
|
297
|
+
],
|
|
298
|
+
isError: true,
|
|
299
|
+
};
|
|
231
300
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
301
|
+
finally {
|
|
302
|
+
void ClearcutLogger.get()?.logToolInvocation({
|
|
303
|
+
toolName: this.tool.name,
|
|
304
|
+
params,
|
|
305
|
+
schema: this.inputSchema,
|
|
306
|
+
success,
|
|
307
|
+
latencyMs: Date.now() - startTime,
|
|
308
|
+
devToolsData,
|
|
309
|
+
pageUrl,
|
|
310
|
+
});
|
|
235
311
|
}
|
|
236
|
-
return result;
|
|
237
312
|
}
|
|
238
|
-
catch (
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
if ('cause' in err && err.cause) {
|
|
242
|
-
errorText += `\nCause: ${err.cause.message}`;
|
|
243
|
-
}
|
|
244
|
-
return {
|
|
245
|
-
content: [
|
|
246
|
-
{
|
|
247
|
-
type: 'text',
|
|
248
|
-
text: errorText,
|
|
249
|
-
},
|
|
250
|
-
],
|
|
251
|
-
isError: true,
|
|
252
|
-
};
|
|
313
|
+
catch (e_1) {
|
|
314
|
+
env_1.error = e_1;
|
|
315
|
+
env_1.hasError = true;
|
|
253
316
|
}
|
|
254
317
|
finally {
|
|
255
|
-
|
|
256
|
-
toolName: this.tool.name,
|
|
257
|
-
params,
|
|
258
|
-
schema: this.inputSchema,
|
|
259
|
-
success,
|
|
260
|
-
latencyMs: Date.now() - startTime,
|
|
261
|
-
devToolsData,
|
|
262
|
-
pageUrl,
|
|
263
|
-
});
|
|
264
|
-
guard[Symbol.dispose]();
|
|
318
|
+
__disposeResources(env_1);
|
|
265
319
|
}
|
|
266
|
-
}
|
|
320
|
+
};
|
|
267
321
|
}
|
|
268
322
|
//# sourceMappingURL=ToolHandler.js.map
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import '../utils/polyfill.js';
|
|
7
7
|
import process from 'node:process';
|
|
8
|
-
import {
|
|
8
|
+
import { BrowserManager } from '../BrowserManager.js';
|
|
9
9
|
import { McpServer, logDisclaimers } from '../index.js';
|
|
10
10
|
import { ClearcutLogger } from '../telemetry/ClearcutLogger.js';
|
|
11
11
|
import { computeFlagUsage } from '../telemetry/flagUtils.js';
|
|
@@ -22,6 +22,13 @@ if (process.env['CHROME_DEVTOOLS_MCP_CRASH_ON_UNCAUGHT'] !== 'true') {
|
|
|
22
22
|
logger?.('Unhandled promise rejection', promise, reason);
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
|
+
logger?.(`Starting Chrome DevTools MCP Server v${VERSION}`);
|
|
26
|
+
const browserManager = new BrowserManager(args, {
|
|
27
|
+
logFile,
|
|
28
|
+
});
|
|
29
|
+
const serverPromise = McpServer.from(args, {
|
|
30
|
+
browserManager,
|
|
31
|
+
});
|
|
25
32
|
// Shutdown on stdin EOF (stdio MCP convention — the client closes the
|
|
26
33
|
// transport to signal exit) and on standard termination signals. Without
|
|
27
34
|
// this, an active Chrome subprocess keeps the Node event loop ref'd after
|
|
@@ -41,7 +48,8 @@ async function shutdown(reason) {
|
|
|
41
48
|
logger?.('Shutdown timeout exceeded, forcing exit');
|
|
42
49
|
process.exit(0);
|
|
43
50
|
}, 5000).unref();
|
|
44
|
-
await
|
|
51
|
+
const server = await serverPromise;
|
|
52
|
+
await server.close();
|
|
45
53
|
process.exit(0);
|
|
46
54
|
}
|
|
47
55
|
process.stdin.on('end', () => {
|
|
@@ -59,10 +67,7 @@ process.on('SIGINT', () => {
|
|
|
59
67
|
process.on('SIGHUP', () => {
|
|
60
68
|
void shutdown('SIGHUP');
|
|
61
69
|
});
|
|
62
|
-
|
|
63
|
-
const server = await McpServer.from(args, {
|
|
64
|
-
logFile,
|
|
65
|
-
});
|
|
70
|
+
const server = await serverPromise;
|
|
66
71
|
const transport = new StdioServerTransport();
|
|
67
72
|
await server.connect(transport);
|
|
68
73
|
logger?.('Chrome DevTools MCP Server connected');
|
|
@@ -12,6 +12,7 @@ import { logDisclaimers } from '../index.js';
|
|
|
12
12
|
import { hideBin, yargs } from '../third_party/index.js';
|
|
13
13
|
import { checkForUpdates } from '../utils/check-for-updates.js';
|
|
14
14
|
import { VERSION } from '../version.js';
|
|
15
|
+
import { buildCommand } from '../config/cli-commands.js';
|
|
15
16
|
import { commands } from '../config/cli-options.js';
|
|
16
17
|
import { mcpOptions, parseArguments, getMcpOptionsForViaCli, } from '../config/mcp-options.js';
|
|
17
18
|
await checkForUpdates('Run `npm install -g chrome-devtools-mcp@latest` and `chrome-devtools start` to update and restart the daemon.');
|
|
@@ -41,7 +42,7 @@ const y = yargs(hideBin(process.argv))
|
|
|
41
42
|
.option('sessionId', {
|
|
42
43
|
type: 'string',
|
|
43
44
|
description: 'Session ID for daemon scoping',
|
|
44
|
-
default: '',
|
|
45
|
+
default: process.env.CD4A_INTERNAL_DAEMON_SESSION_ID || '',
|
|
45
46
|
hidden: true,
|
|
46
47
|
coerce: (sessionId) => {
|
|
47
48
|
assertValidSessionId(sessionId);
|
|
@@ -97,7 +98,7 @@ y.command('start', 'Start or restart chrome-devtools-mcp', y => y
|
|
|
97
98
|
!argv.wsEndpoint) {
|
|
98
99
|
argv.headless = true;
|
|
99
100
|
}
|
|
100
|
-
const args = serializeArgs(
|
|
101
|
+
const args = serializeArgs(getCliOptions(), argv);
|
|
101
102
|
await start(args, argv.sessionId);
|
|
102
103
|
process.exit(0);
|
|
103
104
|
}).strict(); // Re-enable strict validation for other commands; this is applied to the yargs instance itself
|
|
@@ -135,16 +136,9 @@ y.command('stop', 'Stop chrome-devtools-mcp if any', y => y, async (argv) => {
|
|
|
135
136
|
});
|
|
136
137
|
for (const [commandName, commandDef] of Object.entries(commands)) {
|
|
137
138
|
const args = commandDef.args;
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
for (const arg of requiredArgNames) {
|
|
142
|
-
commandStr += ` <${arg}>`;
|
|
143
|
-
}
|
|
144
|
-
for (const arg of optionalArgNames) {
|
|
145
|
-
commandStr += ` [--${arg}]`;
|
|
146
|
-
}
|
|
147
|
-
y.command(commandStr, commandDef.description, y => {
|
|
139
|
+
const { command, usage } = buildCommand(commandName, args);
|
|
140
|
+
y.command(command, commandDef.description, y => {
|
|
141
|
+
y.usage(usage);
|
|
148
142
|
y.option('output-format', {
|
|
149
143
|
choices: ['md', 'json'],
|
|
150
144
|
default: 'md',
|