mcp-browser-dev-tools 0.0.5 → 0.0.6-beta.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/README.md +10 -0
- package/package.json +2 -1
- package/src/browser-adapter.mjs +5 -2
- package/src/browser-launch-service.mjs +146 -9
- package/src/cdp-client.mjs +120 -20
- package/src/cli.mjs +3 -1
- package/src/config.mjs +1 -0
- package/src/firefox-bidi-client.mjs +127 -22
- package/src/keyboard.mjs +278 -0
- package/src/mcp-server.mjs +312 -109
- package/src/page-context.mjs +210 -88
package/src/mcp-server.mjs
CHANGED
|
@@ -143,10 +143,13 @@ function sessionWithLimitSchema(description) {
|
|
|
143
143
|
properties: {
|
|
144
144
|
sessionId: {
|
|
145
145
|
type: "string",
|
|
146
|
+
description: "Session id returned by attach_tab.",
|
|
146
147
|
},
|
|
147
148
|
limit: {
|
|
148
149
|
type: "integer",
|
|
149
150
|
minimum: 1,
|
|
151
|
+
description:
|
|
152
|
+
"Return the most recent N entries from the session buffer (default 50).",
|
|
150
153
|
},
|
|
151
154
|
},
|
|
152
155
|
required: ["sessionId"],
|
|
@@ -155,12 +158,23 @@ function sessionWithLimitSchema(description) {
|
|
|
155
158
|
};
|
|
156
159
|
}
|
|
157
160
|
|
|
161
|
+
const LOCATOR_DESCRIPTION =
|
|
162
|
+
'Element locator. Plain CSS (or css=...) resolves to the first document.querySelector match. text=Foo resolves to the first visible element whose whitespace-normalized text equals Foo, falling back to the first whose text contains Foo; elements are scanned in document order, so this can resolve to a wrapper around the element you want. role=button or role=button[name="Save"] matches by explicit or implicit ARIA role and, optionally, accessible name (equal or containing), without a visibility check. name=Foo resolves to the first visible element whose accessible name (aria-label, aria-labelledby, associated label, alt, and so on) equals or contains Foo. Text comparisons are case-sensitive. Only the top-level document is searched: elements inside iframes or shadow roots are not found.';
|
|
163
|
+
|
|
164
|
+
function selectorProperty() {
|
|
165
|
+
return {
|
|
166
|
+
type: "string",
|
|
167
|
+
description: LOCATOR_DESCRIPTION,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
158
171
|
function sessionSchema(properties, required, description) {
|
|
159
172
|
return {
|
|
160
173
|
type: "object",
|
|
161
174
|
properties: {
|
|
162
175
|
sessionId: {
|
|
163
176
|
type: "string",
|
|
177
|
+
description: "Session id returned by attach_tab.",
|
|
164
178
|
},
|
|
165
179
|
...properties,
|
|
166
180
|
},
|
|
@@ -174,6 +188,8 @@ function waitUntilProperty() {
|
|
|
174
188
|
return {
|
|
175
189
|
type: "string",
|
|
176
190
|
enum: ["none", "interactive", "complete"],
|
|
191
|
+
description:
|
|
192
|
+
"When to return: none returns once navigation starts, interactive after DOMContentLoaded, complete after the load event (default complete).",
|
|
177
193
|
};
|
|
178
194
|
}
|
|
179
195
|
|
|
@@ -183,31 +199,38 @@ function waitForInputSchema() {
|
|
|
183
199
|
properties: {
|
|
184
200
|
sessionId: {
|
|
185
201
|
type: "string",
|
|
202
|
+
description: "Session id returned by attach_tab.",
|
|
186
203
|
},
|
|
187
|
-
selector:
|
|
188
|
-
type: "string",
|
|
189
|
-
},
|
|
204
|
+
selector: selectorProperty(),
|
|
190
205
|
state: {
|
|
191
206
|
type: "string",
|
|
192
207
|
enum: ["present", "visible", "hidden"],
|
|
208
|
+
description:
|
|
209
|
+
"Selector state to wait for (default visible). present: in the DOM. hidden: absent or not visible. Requires selector.",
|
|
193
210
|
},
|
|
194
211
|
url: {
|
|
195
212
|
type: "string",
|
|
213
|
+
description: "Wait until the page URL equals this string exactly.",
|
|
196
214
|
},
|
|
197
215
|
urlIncludes: {
|
|
198
216
|
type: "string",
|
|
217
|
+
description: "Wait until the page URL contains this string.",
|
|
199
218
|
},
|
|
200
219
|
readyState: {
|
|
201
220
|
type: "string",
|
|
202
221
|
enum: ["interactive", "complete"],
|
|
222
|
+
description:
|
|
223
|
+
"Wait until document.readyState reaches this state or later.",
|
|
203
224
|
},
|
|
204
225
|
timeoutMs: {
|
|
205
226
|
type: "integer",
|
|
206
227
|
minimum: 1,
|
|
228
|
+
description: "How long to wait before failing (default 10000).",
|
|
207
229
|
},
|
|
208
230
|
pollIntervalMs: {
|
|
209
231
|
type: "integer",
|
|
210
232
|
minimum: 1,
|
|
233
|
+
description: "Delay between checks (default 100).",
|
|
211
234
|
},
|
|
212
235
|
},
|
|
213
236
|
required: ["sessionId"],
|
|
@@ -221,9 +244,11 @@ function compareSessionsSchema(properties, required) {
|
|
|
221
244
|
properties: {
|
|
222
245
|
sessionIdA: {
|
|
223
246
|
type: "string",
|
|
247
|
+
description: "Session id returned by attach_tab.",
|
|
224
248
|
},
|
|
225
249
|
sessionIdB: {
|
|
226
250
|
type: "string",
|
|
251
|
+
description: "Session id returned by attach_tab.",
|
|
227
252
|
},
|
|
228
253
|
...properties,
|
|
229
254
|
},
|
|
@@ -238,10 +263,12 @@ function storageInputSchema() {
|
|
|
238
263
|
properties: {
|
|
239
264
|
sessionId: {
|
|
240
265
|
type: "string",
|
|
266
|
+
description: "Session id returned by attach_tab.",
|
|
241
267
|
},
|
|
242
268
|
area: {
|
|
243
269
|
type: "string",
|
|
244
270
|
enum: ["all", "localStorage", "sessionStorage"],
|
|
271
|
+
description: "Which storage to return (default all).",
|
|
245
272
|
},
|
|
246
273
|
},
|
|
247
274
|
required: ["sessionId"],
|
|
@@ -255,21 +282,26 @@ function captureDebugReportInputSchema(browserFamily) {
|
|
|
255
282
|
properties: {
|
|
256
283
|
sessionId: {
|
|
257
284
|
type: "string",
|
|
285
|
+
description: "Session id returned by attach_tab.",
|
|
258
286
|
},
|
|
259
287
|
consoleLimit: {
|
|
260
288
|
type: "integer",
|
|
261
289
|
minimum: 1,
|
|
290
|
+
description: "Most recent console entries to include (default 20).",
|
|
262
291
|
},
|
|
263
292
|
networkLimit: {
|
|
264
293
|
type: "integer",
|
|
265
294
|
minimum: 1,
|
|
295
|
+
description: "Most recent network requests to include (default 20).",
|
|
266
296
|
},
|
|
267
297
|
includeScreenshot: {
|
|
268
298
|
type: "boolean",
|
|
299
|
+
description: "Include a viewport screenshot (default true).",
|
|
269
300
|
},
|
|
270
301
|
screenshotFormat: {
|
|
271
302
|
type: "string",
|
|
272
303
|
enum: screenshotFormatsFor(browserFamily),
|
|
304
|
+
description: "Screenshot image format (default png).",
|
|
273
305
|
},
|
|
274
306
|
},
|
|
275
307
|
required: ["sessionId"],
|
|
@@ -283,12 +315,17 @@ function restoreSessionSnapshotInputSchema() {
|
|
|
283
315
|
properties: {
|
|
284
316
|
sessionId: {
|
|
285
317
|
type: "string",
|
|
318
|
+
description: "Session id returned by attach_tab.",
|
|
286
319
|
},
|
|
287
320
|
snapshot: {
|
|
288
321
|
type: "string",
|
|
322
|
+
description:
|
|
323
|
+
"The JSON output of capture_session_snapshot, as a string. Only entries for the current page origin are restored.",
|
|
289
324
|
},
|
|
290
325
|
clearStorage: {
|
|
291
326
|
type: "boolean",
|
|
327
|
+
description:
|
|
328
|
+
"Clear localStorage and sessionStorage before restoring (default false).",
|
|
292
329
|
},
|
|
293
330
|
},
|
|
294
331
|
required: ["sessionId", "snapshot"],
|
|
@@ -300,6 +337,7 @@ function newTabInputSchema(browserFamily) {
|
|
|
300
337
|
const properties = {
|
|
301
338
|
url: {
|
|
302
339
|
type: "string",
|
|
340
|
+
description: "URL to open (default about:blank).",
|
|
303
341
|
},
|
|
304
342
|
};
|
|
305
343
|
const required = [];
|
|
@@ -308,6 +346,7 @@ function newTabInputSchema(browserFamily) {
|
|
|
308
346
|
properties.browserFamily = {
|
|
309
347
|
type: "string",
|
|
310
348
|
enum: ["chromium", "firefox"],
|
|
349
|
+
description: "Browser to open the tab in.",
|
|
311
350
|
};
|
|
312
351
|
required.push("browserFamily");
|
|
313
352
|
}
|
|
@@ -326,6 +365,8 @@ function unsafeArgsProperty() {
|
|
|
326
365
|
items: {
|
|
327
366
|
type: "string",
|
|
328
367
|
},
|
|
368
|
+
description:
|
|
369
|
+
"Extra browser command-line flags, each starting with -. Flags that conflict with broker-managed launch options (debugging port, address, profile) are rejected.",
|
|
329
370
|
};
|
|
330
371
|
}
|
|
331
372
|
|
|
@@ -333,27 +374,40 @@ function launchBrowserInputSchema(browserFamily, enableUnsafeLaunchArgs) {
|
|
|
333
374
|
const properties = {
|
|
334
375
|
url: {
|
|
335
376
|
type: "string",
|
|
377
|
+
description: "URL to open in the launched browser (default about:blank).",
|
|
336
378
|
},
|
|
337
379
|
browserFamily: {
|
|
338
380
|
type: "string",
|
|
339
381
|
enum: supportedLaunchFamilies(browserFamily),
|
|
382
|
+
description:
|
|
383
|
+
"Browser to launch. Required when the broker runs in auto mode.",
|
|
340
384
|
},
|
|
341
385
|
port: {
|
|
342
386
|
type: "integer",
|
|
343
387
|
minimum: 1,
|
|
388
|
+
description:
|
|
389
|
+
"Remote debugging port to launch on (default: the port of the configured browser endpoint, usually 9222).",
|
|
344
390
|
},
|
|
345
391
|
address: {
|
|
346
392
|
type: "string",
|
|
393
|
+
description:
|
|
394
|
+
"Remote debugging bind address for Chromium and Edge (ignored for Firefox). Must be loopback unless MCP_BROWSER_ALLOW_REMOTE_ENDPOINTS=1.",
|
|
347
395
|
},
|
|
348
396
|
userDataDir: {
|
|
349
397
|
type: "string",
|
|
398
|
+
description:
|
|
399
|
+
"Browser profile directory for a new launch (default: MCP_BROWSER_USER_DATA_DIR when set). Without either, Chromium and Edge get a fresh temporary profile if that browser is already running, and the default profile otherwise.",
|
|
350
400
|
},
|
|
351
401
|
waitMs: {
|
|
352
402
|
type: "integer",
|
|
353
403
|
minimum: 0,
|
|
404
|
+
description:
|
|
405
|
+
"How long to wait for the debugging endpoint to answer after launch (default 5000).",
|
|
354
406
|
},
|
|
355
407
|
skipDoctor: {
|
|
356
408
|
type: "boolean",
|
|
409
|
+
description:
|
|
410
|
+
"Return right after spawning the browser, without waiting for the endpoint or running the doctor report (default false).",
|
|
357
411
|
},
|
|
358
412
|
};
|
|
359
413
|
if (enableUnsafeLaunchArgs) {
|
|
@@ -374,32 +428,49 @@ function ensureBrowserInputSchema(browserFamily, enableUnsafeLaunchArgs) {
|
|
|
374
428
|
browserFamily: {
|
|
375
429
|
type: "string",
|
|
376
430
|
enum: supportedLaunchFamilies(browserFamily),
|
|
431
|
+
description:
|
|
432
|
+
"Browser to check or launch. Required when the broker runs in auto mode.",
|
|
377
433
|
},
|
|
378
434
|
url: {
|
|
379
435
|
type: "string",
|
|
436
|
+
description: "URL to open in a new tab once the browser is reachable.",
|
|
380
437
|
},
|
|
381
438
|
createTab: {
|
|
382
439
|
type: "boolean",
|
|
440
|
+
description:
|
|
441
|
+
"Open a tab after the browser is reachable (default: true when url is given).",
|
|
383
442
|
},
|
|
384
443
|
launchIfMissing: {
|
|
385
444
|
type: "boolean",
|
|
445
|
+
description:
|
|
446
|
+
"Launch a browser when none is reachable (default true). When false and none is reachable, return the status without launching or opening a tab.",
|
|
386
447
|
},
|
|
387
448
|
port: {
|
|
388
449
|
type: "integer",
|
|
389
450
|
minimum: 1,
|
|
451
|
+
description:
|
|
452
|
+
"Remote debugging port to launch on (default: the port of the configured browser endpoint, usually 9222).",
|
|
390
453
|
},
|
|
391
454
|
address: {
|
|
392
455
|
type: "string",
|
|
456
|
+
description:
|
|
457
|
+
"Remote debugging bind address for Chromium and Edge (ignored for Firefox). Must be loopback unless MCP_BROWSER_ALLOW_REMOTE_ENDPOINTS=1.",
|
|
393
458
|
},
|
|
394
459
|
userDataDir: {
|
|
395
460
|
type: "string",
|
|
461
|
+
description:
|
|
462
|
+
"Browser profile directory for a new launch (default: MCP_BROWSER_USER_DATA_DIR when set). Without either, Chromium and Edge get a fresh temporary profile if that browser is already running, and the default profile otherwise.",
|
|
396
463
|
},
|
|
397
464
|
waitMs: {
|
|
398
465
|
type: "integer",
|
|
399
466
|
minimum: 0,
|
|
467
|
+
description:
|
|
468
|
+
"How long to wait for the debugging endpoint to answer after launch (default 5000).",
|
|
400
469
|
},
|
|
401
470
|
skipDoctor: {
|
|
402
471
|
type: "boolean",
|
|
472
|
+
description:
|
|
473
|
+
"Return right after spawning the browser, without waiting for the endpoint or running the doctor report (default false).",
|
|
403
474
|
},
|
|
404
475
|
};
|
|
405
476
|
if (enableUnsafeLaunchArgs) {
|
|
@@ -431,7 +502,19 @@ function isRequestedBrowserAvailable(
|
|
|
431
502
|
return Boolean(status?.available);
|
|
432
503
|
}
|
|
433
504
|
|
|
434
|
-
|
|
505
|
+
// Edge shares the Chromium adapter in auto mode.
|
|
506
|
+
const adapterFamily =
|
|
507
|
+
requestedFamily === "edge" ? "chromium" : requestedFamily;
|
|
508
|
+
return Boolean(status?.browsers?.[adapterFamily]?.available);
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
const STATUS_PROBE_ATTEMPTS = 3;
|
|
512
|
+
const LAUNCH_GRACE_MS = 30_000;
|
|
513
|
+
|
|
514
|
+
function sleep(ms) {
|
|
515
|
+
return new Promise((resolve) => {
|
|
516
|
+
setTimeout(resolve, ms);
|
|
517
|
+
});
|
|
435
518
|
}
|
|
436
519
|
|
|
437
520
|
function shouldCreateBrowserTab(args) {
|
|
@@ -492,6 +575,7 @@ export class McpBrowserDevToolsServer {
|
|
|
492
575
|
config,
|
|
493
576
|
browserAdapter,
|
|
494
577
|
launchBrowser = launchLocalBrowser,
|
|
578
|
+
statusProbeRetryMs = 500,
|
|
495
579
|
input = process.stdin,
|
|
496
580
|
output = process.stdout,
|
|
497
581
|
errorOutput = process.stderr,
|
|
@@ -504,6 +588,9 @@ export class McpBrowserDevToolsServer {
|
|
|
504
588
|
this.config = config;
|
|
505
589
|
this.browserAdapter = browserAdapter;
|
|
506
590
|
this.launchBrowser = launchBrowser;
|
|
591
|
+
this.statusProbeRetryMs = statusProbeRetryMs;
|
|
592
|
+
this.launchQueue = Promise.resolve();
|
|
593
|
+
this.unconfirmedLaunches = new Map();
|
|
507
594
|
this.input = input;
|
|
508
595
|
this.output = output;
|
|
509
596
|
this.errorOutput = errorOutput;
|
|
@@ -512,6 +599,122 @@ export class McpBrowserDevToolsServer {
|
|
|
512
599
|
this.tools = this.createTools();
|
|
513
600
|
}
|
|
514
601
|
|
|
602
|
+
// Runs launch decisions one at a time, so parallel tool calls see the browser
|
|
603
|
+
// the first call started instead of each launching their own.
|
|
604
|
+
runExclusiveLaunch(task) {
|
|
605
|
+
const run = this.launchQueue.then(task, task);
|
|
606
|
+
this.launchQueue = run.catch(() => {});
|
|
607
|
+
return run;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
// A busy browser can miss a single status check, and treating that as "not
|
|
611
|
+
// running" would launch a second browser, so retry before giving up.
|
|
612
|
+
async probeBrowser(browserFamily) {
|
|
613
|
+
let status = null;
|
|
614
|
+
for (let attempt = 0; attempt < STATUS_PROBE_ATTEMPTS; attempt += 1) {
|
|
615
|
+
if (attempt > 0) {
|
|
616
|
+
await sleep(this.statusProbeRetryMs);
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
status = await this.browserAdapter.getBrowserStatus();
|
|
620
|
+
if (
|
|
621
|
+
isRequestedBrowserAvailable(
|
|
622
|
+
status,
|
|
623
|
+
this.config.browserFamily,
|
|
624
|
+
browserFamily,
|
|
625
|
+
)
|
|
626
|
+
) {
|
|
627
|
+
this.unconfirmedLaunches.delete(
|
|
628
|
+
browserFamily ?? this.config.browserFamily,
|
|
629
|
+
);
|
|
630
|
+
return { status, available: true };
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
return { status, available: false };
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
// A browser can take a while to expose its endpoint after launch. Launching
|
|
638
|
+
// again in that window would start a second browser, so refuse until the
|
|
639
|
+
// first one answers or the grace period passes.
|
|
640
|
+
async launchUnlessPending(browserFamily, options) {
|
|
641
|
+
const key = browserFamily ?? this.config.browserFamily;
|
|
642
|
+
const launchedAt = this.unconfirmedLaunches.get(key);
|
|
643
|
+
if (launchedAt !== undefined && Date.now() - launchedAt < LAUNCH_GRACE_MS) {
|
|
644
|
+
const seconds = Math.round((Date.now() - launchedAt) / 1000);
|
|
645
|
+
throw new Error(
|
|
646
|
+
`A ${key} browser launched ${seconds}s ago has not exposed its debugging endpoint yet, so another one was not launched. Wait a few seconds and call ensure_browser again.`,
|
|
647
|
+
);
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
const launch = await this.launchBrowser(options);
|
|
651
|
+
const confirmed =
|
|
652
|
+
launch?.launched === false ||
|
|
653
|
+
launch?.doctorReport?.browserStatus?.available === true;
|
|
654
|
+
if (confirmed) {
|
|
655
|
+
this.unconfirmedLaunches.delete(key);
|
|
656
|
+
} else {
|
|
657
|
+
this.unconfirmedLaunches.set(key, Date.now());
|
|
658
|
+
}
|
|
659
|
+
return launch;
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
async ensureBrowser(args) {
|
|
663
|
+
const browserFamily = requestedBrowserFamily(
|
|
664
|
+
this.config.browserFamily,
|
|
665
|
+
args.browserFamily,
|
|
666
|
+
);
|
|
667
|
+
const { status: currentStatus, available } =
|
|
668
|
+
await this.probeBrowser(browserFamily);
|
|
669
|
+
let launch = null;
|
|
670
|
+
let status = currentStatus;
|
|
671
|
+
|
|
672
|
+
if (!available) {
|
|
673
|
+
if (args.launchIfMissing === false) {
|
|
674
|
+
return {
|
|
675
|
+
browserFamily,
|
|
676
|
+
available: false,
|
|
677
|
+
launched: false,
|
|
678
|
+
status,
|
|
679
|
+
tab: null,
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
launch = await this.launchUnlessPending(browserFamily, {
|
|
684
|
+
config: this.config,
|
|
685
|
+
browserFamily,
|
|
686
|
+
url: args.url,
|
|
687
|
+
port: args.port,
|
|
688
|
+
address: args.address,
|
|
689
|
+
userDataDir: args.userDataDir,
|
|
690
|
+
unsafeArgs: args.unsafeArgs,
|
|
691
|
+
waitMs: args.waitMs,
|
|
692
|
+
skipDoctor: args.skipDoctor,
|
|
693
|
+
});
|
|
694
|
+
({ status } = await this.probeBrowser(browserFamily));
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
let tab = null;
|
|
698
|
+
if (shouldCreateBrowserTab(args)) {
|
|
699
|
+
tab = await this.browserAdapter.createTab(args.url, {
|
|
700
|
+
browserFamily,
|
|
701
|
+
});
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
return {
|
|
705
|
+
browserFamily,
|
|
706
|
+
available: isRequestedBrowserAvailable(
|
|
707
|
+
status,
|
|
708
|
+
this.config.browserFamily,
|
|
709
|
+
browserFamily,
|
|
710
|
+
),
|
|
711
|
+
launched: Boolean(launch) && launch.launched !== false,
|
|
712
|
+
launch,
|
|
713
|
+
status,
|
|
714
|
+
tab,
|
|
715
|
+
};
|
|
716
|
+
}
|
|
717
|
+
|
|
515
718
|
createTools() {
|
|
516
719
|
const tools = [
|
|
517
720
|
[
|
|
@@ -550,23 +753,56 @@ export class McpBrowserDevToolsServer {
|
|
|
550
753
|
definition: {
|
|
551
754
|
name: "launch_browser",
|
|
552
755
|
description:
|
|
553
|
-
"Launch a local debug-enabled browser process that matches the current broker configuration and return launch details plus an optional doctor report.",
|
|
756
|
+
"Launch a local debug-enabled browser process that matches the current broker configuration and return launch details plus an optional doctor report. When port, address, userDataDir, and unsafeArgs are all omitted and a browser of this family is already reachable, returns it with reused: true instead of launching, opening url in a new tab if given. On macOS and Linux it never starts a second browser on a profile that is already open. Prefer ensure_browser.",
|
|
554
757
|
inputSchema: launchBrowserInputSchema(
|
|
555
758
|
this.config.browserFamily,
|
|
556
759
|
this.config.enableUnsafeLaunchArgs,
|
|
557
760
|
),
|
|
558
761
|
},
|
|
559
762
|
handler: async (args) =>
|
|
560
|
-
this.
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
763
|
+
this.runExclusiveLaunch(async () => {
|
|
764
|
+
const browserFamily = requestedBrowserFamily(
|
|
765
|
+
this.config.browserFamily,
|
|
766
|
+
args.browserFamily,
|
|
767
|
+
);
|
|
768
|
+
// A requested port, address, profile, or flags ask for a
|
|
769
|
+
// specific browser, so only a plain launch may reuse the
|
|
770
|
+
// running one.
|
|
771
|
+
if (
|
|
772
|
+
args.port === undefined &&
|
|
773
|
+
args.address === undefined &&
|
|
774
|
+
args.userDataDir === undefined &&
|
|
775
|
+
args.unsafeArgs === undefined
|
|
776
|
+
) {
|
|
777
|
+
const { status, available } =
|
|
778
|
+
await this.probeBrowser(browserFamily);
|
|
779
|
+
if (available) {
|
|
780
|
+
const tab = shouldCreateBrowserTab(args)
|
|
781
|
+
? await this.browserAdapter.createTab(args.url, {
|
|
782
|
+
browserFamily,
|
|
783
|
+
})
|
|
784
|
+
: null;
|
|
785
|
+
return {
|
|
786
|
+
browserFamily,
|
|
787
|
+
launched: false,
|
|
788
|
+
reused: true,
|
|
789
|
+
status,
|
|
790
|
+
tab,
|
|
791
|
+
};
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
return this.launchUnlessPending(browserFamily, {
|
|
796
|
+
config: this.config,
|
|
797
|
+
browserFamily: args.browserFamily,
|
|
798
|
+
url: args.url,
|
|
799
|
+
port: args.port,
|
|
800
|
+
address: args.address,
|
|
801
|
+
userDataDir: args.userDataDir,
|
|
802
|
+
unsafeArgs: args.unsafeArgs,
|
|
803
|
+
waitMs: args.waitMs,
|
|
804
|
+
skipDoctor: args.skipDoctor,
|
|
805
|
+
});
|
|
570
806
|
}),
|
|
571
807
|
},
|
|
572
808
|
],
|
|
@@ -576,71 +812,14 @@ export class McpBrowserDevToolsServer {
|
|
|
576
812
|
definition: {
|
|
577
813
|
name: "ensure_browser",
|
|
578
814
|
description:
|
|
579
|
-
"Ensure a compatible browser is reachable through the current broker. If
|
|
815
|
+
"Ensure a compatible browser is reachable through the current broker, reusing a running one when possible. If none answers after three status checks, launch one locally, using the MCP_BROWSER_USER_DATA_DIR profile when set, and optionally open a tab for the requested URL. Will not launch again for 30 seconds while a browser it launched is still starting, and on macOS and Linux never starts a second browser on a profile that is already open.",
|
|
580
816
|
inputSchema: ensureBrowserInputSchema(
|
|
581
817
|
this.config.browserFamily,
|
|
582
818
|
this.config.enableUnsafeLaunchArgs,
|
|
583
819
|
),
|
|
584
820
|
},
|
|
585
|
-
handler: async (args) =>
|
|
586
|
-
|
|
587
|
-
this.config.browserFamily,
|
|
588
|
-
args.browserFamily,
|
|
589
|
-
);
|
|
590
|
-
const currentStatus = await this.browserAdapter.getBrowserStatus();
|
|
591
|
-
const available = isRequestedBrowserAvailable(
|
|
592
|
-
currentStatus,
|
|
593
|
-
this.config.browserFamily,
|
|
594
|
-
browserFamily,
|
|
595
|
-
);
|
|
596
|
-
let launch = null;
|
|
597
|
-
let status = currentStatus;
|
|
598
|
-
|
|
599
|
-
if (!available) {
|
|
600
|
-
if (args.launchIfMissing === false) {
|
|
601
|
-
return {
|
|
602
|
-
browserFamily,
|
|
603
|
-
available: false,
|
|
604
|
-
launched: false,
|
|
605
|
-
status,
|
|
606
|
-
tab: null,
|
|
607
|
-
};
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
launch = await this.launchBrowser({
|
|
611
|
-
config: this.config,
|
|
612
|
-
browserFamily,
|
|
613
|
-
url: args.url,
|
|
614
|
-
port: args.port,
|
|
615
|
-
address: args.address,
|
|
616
|
-
userDataDir: args.userDataDir,
|
|
617
|
-
unsafeArgs: args.unsafeArgs,
|
|
618
|
-
waitMs: args.waitMs,
|
|
619
|
-
skipDoctor: args.skipDoctor,
|
|
620
|
-
});
|
|
621
|
-
status = await this.browserAdapter.getBrowserStatus();
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
let tab = null;
|
|
625
|
-
if (shouldCreateBrowserTab(args)) {
|
|
626
|
-
tab = await this.browserAdapter.createTab(args.url, {
|
|
627
|
-
browserFamily,
|
|
628
|
-
});
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
return {
|
|
632
|
-
browserFamily,
|
|
633
|
-
available: isRequestedBrowserAvailable(
|
|
634
|
-
status,
|
|
635
|
-
this.config.browserFamily,
|
|
636
|
-
browserFamily,
|
|
637
|
-
),
|
|
638
|
-
launched: Boolean(launch),
|
|
639
|
-
launch,
|
|
640
|
-
status,
|
|
641
|
-
tab,
|
|
642
|
-
};
|
|
643
|
-
},
|
|
821
|
+
handler: async (args) =>
|
|
822
|
+
this.runExclusiveLaunch(() => this.ensureBrowser(args)),
|
|
644
823
|
},
|
|
645
824
|
],
|
|
646
825
|
[
|
|
@@ -684,6 +863,7 @@ export class McpBrowserDevToolsServer {
|
|
|
684
863
|
properties: {
|
|
685
864
|
targetId: {
|
|
686
865
|
type: "string",
|
|
866
|
+
description: "Target id returned by list_tabs or new_tab.",
|
|
687
867
|
},
|
|
688
868
|
},
|
|
689
869
|
required: ["targetId"],
|
|
@@ -802,9 +982,7 @@ export class McpBrowserDevToolsServer {
|
|
|
802
982
|
"Compare a selector across two attached sessions using a bounded element summary.",
|
|
803
983
|
inputSchema: compareSessionsSchema(
|
|
804
984
|
{
|
|
805
|
-
selector:
|
|
806
|
-
type: "string",
|
|
807
|
-
},
|
|
985
|
+
selector: selectorProperty(),
|
|
808
986
|
},
|
|
809
987
|
["selector"],
|
|
810
988
|
),
|
|
@@ -863,7 +1041,7 @@ export class McpBrowserDevToolsServer {
|
|
|
863
1041
|
definition: {
|
|
864
1042
|
name: "wait_for",
|
|
865
1043
|
description:
|
|
866
|
-
"Wait
|
|
1044
|
+
"Wait until every given condition holds on an attached session: selector state, exact url, urlIncludes substring, and readyState. Give at least one condition. Polls until the conditions match or timeoutMs passes, then fails with the last observed state. A selector check scrolls the matched element into view on each poll.",
|
|
867
1045
|
inputSchema: waitForInputSchema(),
|
|
868
1046
|
},
|
|
869
1047
|
handler: async (args) => {
|
|
@@ -1025,6 +1203,7 @@ export class McpBrowserDevToolsServer {
|
|
|
1025
1203
|
{
|
|
1026
1204
|
url: {
|
|
1027
1205
|
type: "string",
|
|
1206
|
+
description: "Absolute URL to load.",
|
|
1028
1207
|
},
|
|
1029
1208
|
waitUntil: waitUntilProperty(),
|
|
1030
1209
|
},
|
|
@@ -1048,6 +1227,8 @@ export class McpBrowserDevToolsServer {
|
|
|
1048
1227
|
{
|
|
1049
1228
|
ignoreCache: {
|
|
1050
1229
|
type: "boolean",
|
|
1230
|
+
description:
|
|
1231
|
+
"Bypass the HTTP cache for this reload (default false).",
|
|
1051
1232
|
},
|
|
1052
1233
|
waitUntil: waitUntilProperty(),
|
|
1053
1234
|
},
|
|
@@ -1067,12 +1248,10 @@ export class McpBrowserDevToolsServer {
|
|
|
1067
1248
|
definition: {
|
|
1068
1249
|
name: "click",
|
|
1069
1250
|
description:
|
|
1070
|
-
"Click a single element located by CSS, text=..., role=..., or name=... syntax.",
|
|
1251
|
+
"Click a single element located by CSS, text=..., role=..., or name=... syntax. Sends real mouse input at the element center and fails if another element covers that point. A JavaScript alert or confirm dialog that this opens is accepted automatically and a prompt is dismissed; get_events reports it as a dialog event.",
|
|
1071
1252
|
inputSchema: sessionSchema(
|
|
1072
1253
|
{
|
|
1073
|
-
selector:
|
|
1074
|
-
type: "string",
|
|
1075
|
-
},
|
|
1254
|
+
selector: selectorProperty(),
|
|
1076
1255
|
},
|
|
1077
1256
|
["selector"],
|
|
1078
1257
|
),
|
|
@@ -1087,12 +1266,10 @@ export class McpBrowserDevToolsServer {
|
|
|
1087
1266
|
definition: {
|
|
1088
1267
|
name: "hover",
|
|
1089
1268
|
description:
|
|
1090
|
-
"Hover a single element located by CSS, text=..., role=..., or name=... syntax.",
|
|
1269
|
+
"Hover a single element located by CSS, text=..., role=..., or name=... syntax. Moves the real mouse pointer to the element center.",
|
|
1091
1270
|
inputSchema: sessionSchema(
|
|
1092
1271
|
{
|
|
1093
|
-
selector:
|
|
1094
|
-
type: "string",
|
|
1095
|
-
},
|
|
1272
|
+
selector: selectorProperty(),
|
|
1096
1273
|
},
|
|
1097
1274
|
["selector"],
|
|
1098
1275
|
),
|
|
@@ -1107,17 +1284,19 @@ export class McpBrowserDevToolsServer {
|
|
|
1107
1284
|
definition: {
|
|
1108
1285
|
name: "type",
|
|
1109
1286
|
description:
|
|
1110
|
-
"Type text into an input, textarea, or contenteditable element.",
|
|
1287
|
+
"Type text into an input, textarea, or contenteditable element using real text input, replacing existing content unless clear is false.",
|
|
1111
1288
|
inputSchema: sessionSchema(
|
|
1112
1289
|
{
|
|
1113
|
-
selector:
|
|
1114
|
-
type: "string",
|
|
1115
|
-
},
|
|
1290
|
+
selector: selectorProperty(),
|
|
1116
1291
|
text: {
|
|
1117
1292
|
type: "string",
|
|
1293
|
+
description:
|
|
1294
|
+
"Text to enter. Each newline is sent as an Enter key press: a line break in a textarea, implicit form submission in a single-line input. Date, time, datetime-local, month, week, color, and range inputs get the value set directly, so pass it in that input's value format (for example 2026-09-27). An empty string with clear empties the field.",
|
|
1118
1295
|
},
|
|
1119
1296
|
clear: {
|
|
1120
1297
|
type: "boolean",
|
|
1298
|
+
description:
|
|
1299
|
+
"Replace the existing content (default true). When false, the text is inserted at the end of the current content. Ignored for date, time, datetime-local, month, week, color, and range inputs, whose value is always replaced.",
|
|
1121
1300
|
},
|
|
1122
1301
|
},
|
|
1123
1302
|
["selector", "text"],
|
|
@@ -1135,17 +1314,19 @@ export class McpBrowserDevToolsServer {
|
|
|
1135
1314
|
definition: {
|
|
1136
1315
|
name: "select",
|
|
1137
1316
|
description:
|
|
1138
|
-
"Select an option
|
|
1317
|
+
"Select an option in a native <select> element and fire input and change events. Provide value, label, or both; the first option matching either is selected, and the call fails if none matches. Custom dropdowns built from other elements need click instead.",
|
|
1139
1318
|
inputSchema: sessionSchema(
|
|
1140
1319
|
{
|
|
1141
|
-
selector:
|
|
1142
|
-
type: "string",
|
|
1143
|
-
},
|
|
1320
|
+
selector: selectorProperty(),
|
|
1144
1321
|
value: {
|
|
1145
1322
|
type: "string",
|
|
1323
|
+
description:
|
|
1324
|
+
"Matches an option whose value attribute or full text equals this string.",
|
|
1146
1325
|
},
|
|
1147
1326
|
label: {
|
|
1148
1327
|
type: "string",
|
|
1328
|
+
description:
|
|
1329
|
+
"Matches an option whose visible text contains this string (case-sensitive).",
|
|
1149
1330
|
},
|
|
1150
1331
|
},
|
|
1151
1332
|
["selector"],
|
|
@@ -1169,15 +1350,15 @@ export class McpBrowserDevToolsServer {
|
|
|
1169
1350
|
definition: {
|
|
1170
1351
|
name: "press_key",
|
|
1171
1352
|
description:
|
|
1172
|
-
"
|
|
1353
|
+
"Press a key or key combination (for example Enter, Tab, Escape, ArrowDown, Shift+Tab, Meta+a) with real keyboard input on the focused element, or on selector after focusing it. Fails if selector cannot take focus. A JavaScript alert or confirm dialog that this opens is accepted automatically and a prompt is dismissed; get_events reports it as a dialog event.",
|
|
1173
1354
|
inputSchema: sessionSchema(
|
|
1174
1355
|
{
|
|
1175
1356
|
key: {
|
|
1176
1357
|
type: "string",
|
|
1358
|
+
description:
|
|
1359
|
+
"A single character, or a named key: Enter, Tab, Escape, Backspace, Delete, Insert, ArrowUp/Down/Left/Right, Home, End, PageUp, PageDown, Space, F1-F12, Shift, Control, Alt, or Meta. Join modifiers with + (Shift+Tab, Control+Enter, Meta+a). Names are case-insensitive; unknown names are rejected.",
|
|
1177
1360
|
},
|
|
1178
|
-
selector:
|
|
1179
|
-
type: "string",
|
|
1180
|
-
},
|
|
1361
|
+
selector: selectorProperty(),
|
|
1181
1362
|
},
|
|
1182
1363
|
["key"],
|
|
1183
1364
|
),
|
|
@@ -1199,18 +1380,22 @@ export class McpBrowserDevToolsServer {
|
|
|
1199
1380
|
"Scroll the page by deltas or scroll a specific element into view.",
|
|
1200
1381
|
inputSchema: sessionSchema(
|
|
1201
1382
|
{
|
|
1202
|
-
selector:
|
|
1203
|
-
type: "string",
|
|
1204
|
-
},
|
|
1383
|
+
selector: selectorProperty(),
|
|
1205
1384
|
deltaX: {
|
|
1206
1385
|
type: "integer",
|
|
1386
|
+
description:
|
|
1387
|
+
"Horizontal scroll distance in CSS pixels; negative scrolls left. Ignored when selector is given.",
|
|
1207
1388
|
},
|
|
1208
1389
|
deltaY: {
|
|
1209
1390
|
type: "integer",
|
|
1391
|
+
description:
|
|
1392
|
+
"Vertical scroll distance in CSS pixels; negative scrolls up. Ignored when selector is given.",
|
|
1210
1393
|
},
|
|
1211
1394
|
block: {
|
|
1212
1395
|
type: "string",
|
|
1213
1396
|
enum: ["start", "center", "end", "nearest"],
|
|
1397
|
+
description:
|
|
1398
|
+
"Vertical alignment when scrolling selector into view (default center).",
|
|
1214
1399
|
},
|
|
1215
1400
|
},
|
|
1216
1401
|
[],
|
|
@@ -1248,17 +1433,23 @@ export class McpBrowserDevToolsServer {
|
|
|
1248
1433
|
width: {
|
|
1249
1434
|
type: "integer",
|
|
1250
1435
|
minimum: 1,
|
|
1436
|
+
description: "Viewport width in CSS pixels.",
|
|
1251
1437
|
},
|
|
1252
1438
|
height: {
|
|
1253
1439
|
type: "integer",
|
|
1254
1440
|
minimum: 1,
|
|
1441
|
+
description: "Viewport height in CSS pixels.",
|
|
1255
1442
|
},
|
|
1256
1443
|
deviceScaleFactor: {
|
|
1257
1444
|
type: "number",
|
|
1258
1445
|
minimum: 0.1,
|
|
1446
|
+
description:
|
|
1447
|
+
"Device pixel ratio to emulate. Chromium and Edge use 1 when omitted; Firefox keeps its current ratio.",
|
|
1259
1448
|
},
|
|
1260
1449
|
mobile: {
|
|
1261
1450
|
type: "boolean",
|
|
1451
|
+
description:
|
|
1452
|
+
"Emulate a mobile device, including meta viewport handling (default false). Chromium and Edge only; ignored on Firefox.",
|
|
1262
1453
|
},
|
|
1263
1454
|
},
|
|
1264
1455
|
["width", "height"],
|
|
@@ -1318,10 +1509,13 @@ export class McpBrowserDevToolsServer {
|
|
|
1318
1509
|
properties: {
|
|
1319
1510
|
sessionId: {
|
|
1320
1511
|
type: "string",
|
|
1512
|
+
description: "Session id returned by attach_tab.",
|
|
1321
1513
|
},
|
|
1322
1514
|
depth: {
|
|
1323
1515
|
type: "integer",
|
|
1324
1516
|
minimum: 1,
|
|
1517
|
+
description:
|
|
1518
|
+
"How many levels of child nodes to include (default 2). Chromium and Edge only; Firefox returns the full document HTML regardless.",
|
|
1325
1519
|
},
|
|
1326
1520
|
},
|
|
1327
1521
|
required: ["sessionId"],
|
|
@@ -1338,16 +1532,15 @@ export class McpBrowserDevToolsServer {
|
|
|
1338
1532
|
definition: {
|
|
1339
1533
|
name: "inspect_element",
|
|
1340
1534
|
description:
|
|
1341
|
-
"Inspect a single DOM element located by CSS, text=..., role=..., or name=... syntax and return normalized element details.",
|
|
1535
|
+
"Inspect a single DOM element located by CSS, text=..., role=..., or name=... syntax and return normalized element details. Scrolls the element into view first, so the returned box reflects the scrolled position.",
|
|
1342
1536
|
inputSchema: {
|
|
1343
1537
|
type: "object",
|
|
1344
1538
|
properties: {
|
|
1345
1539
|
sessionId: {
|
|
1346
1540
|
type: "string",
|
|
1541
|
+
description: "Session id returned by attach_tab.",
|
|
1347
1542
|
},
|
|
1348
|
-
selector:
|
|
1349
|
-
type: "string",
|
|
1350
|
-
},
|
|
1543
|
+
selector: selectorProperty(),
|
|
1351
1544
|
},
|
|
1352
1545
|
required: ["sessionId", "selector"],
|
|
1353
1546
|
additionalProperties: false,
|
|
@@ -1369,14 +1562,14 @@ export class McpBrowserDevToolsServer {
|
|
|
1369
1562
|
properties: {
|
|
1370
1563
|
sessionId: {
|
|
1371
1564
|
type: "string",
|
|
1565
|
+
description: "Session id returned by attach_tab.",
|
|
1372
1566
|
},
|
|
1373
1567
|
format: {
|
|
1374
1568
|
type: "string",
|
|
1375
1569
|
enum: screenshotFormatsFor(this.config.browserFamily),
|
|
1570
|
+
description: "Image format (default png).",
|
|
1376
1571
|
},
|
|
1377
|
-
selector:
|
|
1378
|
-
type: "string",
|
|
1379
|
-
},
|
|
1572
|
+
selector: selectorProperty(),
|
|
1380
1573
|
},
|
|
1381
1574
|
required: ["sessionId"],
|
|
1382
1575
|
additionalProperties: false,
|
|
@@ -1404,10 +1597,13 @@ export class McpBrowserDevToolsServer {
|
|
|
1404
1597
|
properties: {
|
|
1405
1598
|
sessionId: {
|
|
1406
1599
|
type: "string",
|
|
1600
|
+
description: "Session id returned by attach_tab.",
|
|
1407
1601
|
},
|
|
1408
1602
|
limit: {
|
|
1409
1603
|
type: "integer",
|
|
1410
1604
|
minimum: 1,
|
|
1605
|
+
description:
|
|
1606
|
+
"Return the most recent N events from the session buffer (default 50).",
|
|
1411
1607
|
},
|
|
1412
1608
|
},
|
|
1413
1609
|
required: ["sessionId"],
|
|
@@ -1436,15 +1632,22 @@ export class McpBrowserDevToolsServer {
|
|
|
1436
1632
|
properties: {
|
|
1437
1633
|
sessionId: {
|
|
1438
1634
|
type: "string",
|
|
1635
|
+
description: "Session id returned by attach_tab.",
|
|
1439
1636
|
},
|
|
1440
1637
|
expression: {
|
|
1441
1638
|
type: "string",
|
|
1639
|
+
description:
|
|
1640
|
+
"JavaScript expression to evaluate in the page's main world.",
|
|
1442
1641
|
},
|
|
1443
1642
|
awaitPromise: {
|
|
1444
1643
|
type: "boolean",
|
|
1644
|
+
description:
|
|
1645
|
+
"Wait for a returned promise to settle and return its result (default true).",
|
|
1445
1646
|
},
|
|
1446
1647
|
returnByValue: {
|
|
1447
1648
|
type: "boolean",
|
|
1649
|
+
description:
|
|
1650
|
+
"Return the result as a JSON value (default true). When false, only a short description of the resulting object is returned. Chromium and Edge only; Firefox always returns a serialized value.",
|
|
1448
1651
|
},
|
|
1449
1652
|
},
|
|
1450
1653
|
required: ["sessionId", "expression"],
|