@1outres/dsh-bot-connector-browser 0.0.0-stage → 0.3.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/lib/index.js ADDED
@@ -0,0 +1,1762 @@
1
+ // src/index.ts
2
+ import { readFile } from "node:fs/promises";
3
+
4
+ // src/generated/playwright-mcp.json
5
+ var playwright_mcp_default = {
6
+ package: "@playwright/mcp",
7
+ version: "0.0.86",
8
+ server: {
9
+ name: "Playwright",
10
+ version: "1.66.0-alpha-2026-11-18"
11
+ },
12
+ arguments: ["--caps", "vision,pdf", "--no-webmcp"],
13
+ tools: [
14
+ {
15
+ name: "browser_close",
16
+ description: "Close the browser and all open tabs.",
17
+ inputSchema: {
18
+ $schema: "https://json-schema.org/draft/2020-12/schema",
19
+ type: "object",
20
+ properties: {},
21
+ additionalProperties: false
22
+ },
23
+ annotations: {
24
+ title: "Close browser",
25
+ readOnlyHint: false,
26
+ destructiveHint: true,
27
+ openWorldHint: true
28
+ }
29
+ },
30
+ {
31
+ name: "browser_resize",
32
+ description: "Resize the browser window",
33
+ inputSchema: {
34
+ $schema: "https://json-schema.org/draft/2020-12/schema",
35
+ type: "object",
36
+ properties: {
37
+ width: {
38
+ type: "number",
39
+ description: "Width of the browser window"
40
+ },
41
+ height: {
42
+ type: "number",
43
+ description: "Height of the browser window"
44
+ }
45
+ },
46
+ required: ["width", "height"],
47
+ additionalProperties: false
48
+ },
49
+ annotations: {
50
+ title: "Resize browser window",
51
+ readOnlyHint: false,
52
+ destructiveHint: true,
53
+ openWorldHint: true
54
+ }
55
+ },
56
+ {
57
+ name: "browser_console_messages",
58
+ description: "Returns all console messages",
59
+ inputSchema: {
60
+ $schema: "https://json-schema.org/draft/2020-12/schema",
61
+ type: "object",
62
+ properties: {
63
+ level: {
64
+ default: "info",
65
+ description: 'Level of the console messages to return. Each level includes the messages of more severe levels. Defaults to "info".',
66
+ type: "string",
67
+ enum: ["error", "warning", "info", "debug"]
68
+ },
69
+ all: {
70
+ description: "Return all console messages since the beginning of the session, not just since the last navigation. Defaults to false.",
71
+ type: "boolean"
72
+ },
73
+ filename: {
74
+ description: "File name to save the console messages to. Relative file names are resolved against the workspace root. If not provided, messages are returned as text.",
75
+ type: "string"
76
+ }
77
+ },
78
+ required: ["level"],
79
+ additionalProperties: false
80
+ },
81
+ annotations: {
82
+ title: "Get console messages",
83
+ readOnlyHint: true,
84
+ destructiveHint: false,
85
+ openWorldHint: true
86
+ }
87
+ },
88
+ {
89
+ name: "browser_handle_dialog",
90
+ description: "Handle a dialog",
91
+ inputSchema: {
92
+ $schema: "https://json-schema.org/draft/2020-12/schema",
93
+ type: "object",
94
+ properties: {
95
+ accept: {
96
+ type: "boolean",
97
+ description: "Whether to accept the dialog."
98
+ },
99
+ promptText: {
100
+ description: "The text of the prompt in case of a prompt dialog.",
101
+ type: "string"
102
+ }
103
+ },
104
+ required: ["accept"],
105
+ additionalProperties: false
106
+ },
107
+ annotations: {
108
+ title: "Handle a dialog",
109
+ readOnlyHint: false,
110
+ destructiveHint: true,
111
+ openWorldHint: true
112
+ }
113
+ },
114
+ {
115
+ name: "browser_emulate_media",
116
+ description: "Emulate CSS media features for the page, for example switch between the light and dark color scheme. Omitted parameters are left unchanged; null clears an override.",
117
+ inputSchema: {
118
+ $schema: "https://json-schema.org/draft/2020-12/schema",
119
+ type: "object",
120
+ properties: {
121
+ colorScheme: {
122
+ description: "Emulates the prefers-color-scheme media feature",
123
+ anyOf: [
124
+ {
125
+ type: "string",
126
+ enum: ["light", "dark"]
127
+ },
128
+ {
129
+ type: "null"
130
+ }
131
+ ]
132
+ },
133
+ reducedMotion: {
134
+ description: "Emulates the prefers-reduced-motion media feature",
135
+ anyOf: [
136
+ {
137
+ type: "string",
138
+ enum: ["reduce", "no-preference"]
139
+ },
140
+ {
141
+ type: "null"
142
+ }
143
+ ]
144
+ },
145
+ forcedColors: {
146
+ description: "Emulates the forced-colors media feature",
147
+ anyOf: [
148
+ {
149
+ type: "string",
150
+ enum: ["active", "none"]
151
+ },
152
+ {
153
+ type: "null"
154
+ }
155
+ ]
156
+ },
157
+ contrast: {
158
+ description: "Emulates the prefers-contrast media feature",
159
+ anyOf: [
160
+ {
161
+ type: "string",
162
+ enum: ["more", "no-preference"]
163
+ },
164
+ {
165
+ type: "null"
166
+ }
167
+ ]
168
+ },
169
+ media: {
170
+ description: "Changes the CSS media type of the page",
171
+ anyOf: [
172
+ {
173
+ type: "string",
174
+ enum: ["screen", "print"]
175
+ },
176
+ {
177
+ type: "null"
178
+ }
179
+ ]
180
+ }
181
+ },
182
+ additionalProperties: false
183
+ },
184
+ annotations: {
185
+ title: "Emulate media features",
186
+ readOnlyHint: false,
187
+ destructiveHint: true,
188
+ openWorldHint: true
189
+ }
190
+ },
191
+ {
192
+ name: "browser_evaluate",
193
+ description: "Evaluate JavaScript expression on page or element",
194
+ inputSchema: {
195
+ $schema: "https://json-schema.org/draft/2020-12/schema",
196
+ type: "object",
197
+ properties: {
198
+ element: {
199
+ description: "Human-readable element description used to obtain permission to interact with the element",
200
+ type: "string"
201
+ },
202
+ target: {
203
+ description: "Exact target element reference from the page snapshot, or a unique element selector",
204
+ type: "string"
205
+ },
206
+ function: {
207
+ type: "string",
208
+ description: "() => { /* code */ } or (element) => { /* code */ } when element is provided"
209
+ },
210
+ filename: {
211
+ description: "File name to save the result to. Relative file names are resolved against the workspace root. If not provided, result is returned as text.",
212
+ type: "string"
213
+ }
214
+ },
215
+ required: ["function"],
216
+ additionalProperties: false
217
+ },
218
+ annotations: {
219
+ title: "Evaluate JavaScript",
220
+ readOnlyHint: false,
221
+ destructiveHint: true,
222
+ openWorldHint: true
223
+ }
224
+ },
225
+ {
226
+ name: "browser_file_upload",
227
+ description: "Upload one or multiple files",
228
+ inputSchema: {
229
+ $schema: "https://json-schema.org/draft/2020-12/schema",
230
+ type: "object",
231
+ properties: {
232
+ paths: {
233
+ description: "The absolute paths to the files to upload. Can be single file or multiple files. If omitted, file chooser is cancelled.",
234
+ type: "array",
235
+ items: {
236
+ type: "string"
237
+ }
238
+ }
239
+ },
240
+ additionalProperties: false
241
+ },
242
+ annotations: {
243
+ title: "Upload files",
244
+ readOnlyHint: false,
245
+ destructiveHint: true,
246
+ openWorldHint: true
247
+ }
248
+ },
249
+ {
250
+ name: "browser_drop",
251
+ description: 'Drop files or MIME-typed data onto an element, as if dragged from outside the page. At least one of "paths" or "data" must be provided.',
252
+ inputSchema: {
253
+ $schema: "https://json-schema.org/draft/2020-12/schema",
254
+ type: "object",
255
+ properties: {
256
+ element: {
257
+ description: "Human-readable element description used to obtain permission to interact with the element",
258
+ type: "string"
259
+ },
260
+ target: {
261
+ type: "string",
262
+ description: "Exact target element reference from the page snapshot, or a unique element selector"
263
+ },
264
+ paths: {
265
+ description: "Absolute paths to files to drop onto the element.",
266
+ type: "array",
267
+ items: {
268
+ type: "string"
269
+ }
270
+ },
271
+ data: {
272
+ description: 'Data to drop, as a map of MIME type to string value (e.g. {"text/plain": "hello", "text/uri-list": "https://example.com"}).',
273
+ type: "object",
274
+ propertyNames: {
275
+ type: "string"
276
+ },
277
+ additionalProperties: {
278
+ type: "string"
279
+ }
280
+ }
281
+ },
282
+ required: ["target"],
283
+ additionalProperties: false
284
+ },
285
+ annotations: {
286
+ title: "Drop files or data onto an element",
287
+ readOnlyHint: false,
288
+ destructiveHint: true,
289
+ openWorldHint: true
290
+ }
291
+ },
292
+ {
293
+ name: "browser_find",
294
+ description: "Search the accessibility snapshot of the current page for text or a regular expression. Returns matching snapshot nodes with a few lines of surrounding context (like search snippets), each shown under its path from the root of the tree, which is cheaper than capturing the whole snapshot when you only need to locate an element and its ref.",
295
+ inputSchema: {
296
+ $schema: "https://json-schema.org/draft/2020-12/schema",
297
+ type: "object",
298
+ properties: {
299
+ text: {
300
+ description: "Plain text to search for in the page snapshot (case-insensitive substring match). Provide either text or regex, not both.",
301
+ type: "string"
302
+ },
303
+ regex: {
304
+ description: 'Regular expression to search for in the page snapshot. Matching is case-sensitive by default; wrap the pattern in slashes to add flags, e.g. "/error/i" for case-insensitive. Provide either text or regex, not both.',
305
+ type: "string"
306
+ },
307
+ maxResults: {
308
+ description: "Maximum number of matching items to return. Defaults to returning all matches.",
309
+ type: "number"
310
+ },
311
+ filename: {
312
+ description: "Save results to a file instead of returning them in the response. Relative file names are resolved against the workspace root.",
313
+ type: "string"
314
+ }
315
+ },
316
+ additionalProperties: false
317
+ },
318
+ annotations: {
319
+ title: "Find in page snapshot",
320
+ readOnlyHint: true,
321
+ destructiveHint: false,
322
+ openWorldHint: true
323
+ }
324
+ },
325
+ {
326
+ name: "browser_fill_form",
327
+ description: "Fill multiple form fields",
328
+ inputSchema: {
329
+ $schema: "https://json-schema.org/draft/2020-12/schema",
330
+ type: "object",
331
+ properties: {
332
+ fields: {
333
+ type: "array",
334
+ items: {
335
+ type: "object",
336
+ properties: {
337
+ element: {
338
+ description: "Human-readable element description used to obtain permission to interact with the element",
339
+ type: "string"
340
+ },
341
+ target: {
342
+ type: "string",
343
+ description: "Exact target element reference from the page snapshot, or a unique element selector"
344
+ },
345
+ name: {
346
+ type: "string",
347
+ description: "Human-readable field name"
348
+ },
349
+ type: {
350
+ type: "string",
351
+ enum: ["textbox", "checkbox", "radio", "combobox", "slider"],
352
+ description: "Type of the field"
353
+ },
354
+ value: {
355
+ type: "string",
356
+ description: "Value to fill in the field. If the field is a checkbox, the value should be `true` or `false`. If the field is a combobox, the value should be the text of the option."
357
+ }
358
+ },
359
+ required: ["target", "name", "type", "value"],
360
+ additionalProperties: false
361
+ },
362
+ description: "Fields to fill in"
363
+ }
364
+ },
365
+ required: ["fields"],
366
+ additionalProperties: false
367
+ },
368
+ annotations: {
369
+ title: "Fill form",
370
+ readOnlyHint: false,
371
+ destructiveHint: true,
372
+ openWorldHint: true
373
+ }
374
+ },
375
+ {
376
+ name: "browser_press_key",
377
+ description: "Press a key on the keyboard",
378
+ inputSchema: {
379
+ $schema: "https://json-schema.org/draft/2020-12/schema",
380
+ type: "object",
381
+ properties: {
382
+ key: {
383
+ type: "string",
384
+ description: "Name of the key to press or a character to generate, such as `ArrowLeft` or `a`"
385
+ }
386
+ },
387
+ required: ["key"],
388
+ additionalProperties: false
389
+ },
390
+ annotations: {
391
+ title: "Press a key",
392
+ readOnlyHint: false,
393
+ destructiveHint: true,
394
+ openWorldHint: true
395
+ }
396
+ },
397
+ {
398
+ name: "browser_type",
399
+ description: "Type text into editable element",
400
+ inputSchema: {
401
+ $schema: "https://json-schema.org/draft/2020-12/schema",
402
+ type: "object",
403
+ properties: {
404
+ element: {
405
+ description: "Human-readable element description used to obtain permission to interact with the element",
406
+ type: "string"
407
+ },
408
+ target: {
409
+ type: "string",
410
+ description: "Exact target element reference from the page snapshot, or a unique element selector"
411
+ },
412
+ text: {
413
+ type: "string",
414
+ description: "Text to type into the element"
415
+ },
416
+ submit: {
417
+ description: "Whether to submit entered text (press Enter after)",
418
+ type: "boolean"
419
+ },
420
+ slowly: {
421
+ description: "Whether to type one character at a time. Useful for triggering key handlers in the page. By default entire text is filled in at once.",
422
+ type: "boolean"
423
+ }
424
+ },
425
+ required: ["target", "text"],
426
+ additionalProperties: false
427
+ },
428
+ annotations: {
429
+ title: "Type text",
430
+ readOnlyHint: false,
431
+ destructiveHint: true,
432
+ openWorldHint: true
433
+ }
434
+ },
435
+ {
436
+ name: "browser_mouse_move_xy",
437
+ description: "Move mouse to a given position",
438
+ inputSchema: {
439
+ $schema: "https://json-schema.org/draft/2020-12/schema",
440
+ type: "object",
441
+ properties: {
442
+ x: {
443
+ type: "number",
444
+ description: "X coordinate"
445
+ },
446
+ y: {
447
+ type: "number",
448
+ description: "Y coordinate"
449
+ }
450
+ },
451
+ required: ["x", "y"],
452
+ additionalProperties: false
453
+ },
454
+ annotations: {
455
+ title: "Move mouse",
456
+ readOnlyHint: false,
457
+ destructiveHint: true,
458
+ openWorldHint: true
459
+ }
460
+ },
461
+ {
462
+ name: "browser_mouse_click_xy",
463
+ description: "Click mouse button at a given position",
464
+ inputSchema: {
465
+ $schema: "https://json-schema.org/draft/2020-12/schema",
466
+ type: "object",
467
+ properties: {
468
+ x: {
469
+ type: "number",
470
+ description: "X coordinate"
471
+ },
472
+ y: {
473
+ type: "number",
474
+ description: "Y coordinate"
475
+ },
476
+ button: {
477
+ description: "Button to click, defaults to left",
478
+ type: "string",
479
+ enum: ["left", "right", "middle"]
480
+ },
481
+ clickCount: {
482
+ description: "Number of clicks, defaults to 1",
483
+ type: "number"
484
+ },
485
+ delay: {
486
+ description: "Time to wait between mouse down and mouse up in milliseconds, defaults to 0",
487
+ type: "number"
488
+ }
489
+ },
490
+ required: ["x", "y"],
491
+ additionalProperties: false
492
+ },
493
+ annotations: {
494
+ title: "Click",
495
+ readOnlyHint: false,
496
+ destructiveHint: true,
497
+ openWorldHint: true
498
+ }
499
+ },
500
+ {
501
+ name: "browser_mouse_drag_xy",
502
+ description: "Drag left mouse button to a given position",
503
+ inputSchema: {
504
+ $schema: "https://json-schema.org/draft/2020-12/schema",
505
+ type: "object",
506
+ properties: {
507
+ startX: {
508
+ type: "number",
509
+ description: "Start X coordinate"
510
+ },
511
+ startY: {
512
+ type: "number",
513
+ description: "Start Y coordinate"
514
+ },
515
+ endX: {
516
+ type: "number",
517
+ description: "End X coordinate"
518
+ },
519
+ endY: {
520
+ type: "number",
521
+ description: "End Y coordinate"
522
+ }
523
+ },
524
+ required: ["startX", "startY", "endX", "endY"],
525
+ additionalProperties: false
526
+ },
527
+ annotations: {
528
+ title: "Drag mouse",
529
+ readOnlyHint: false,
530
+ destructiveHint: true,
531
+ openWorldHint: true
532
+ }
533
+ },
534
+ {
535
+ name: "browser_mouse_down",
536
+ description: "Press mouse down",
537
+ inputSchema: {
538
+ $schema: "https://json-schema.org/draft/2020-12/schema",
539
+ type: "object",
540
+ properties: {
541
+ button: {
542
+ description: "Button to press, defaults to left",
543
+ type: "string",
544
+ enum: ["left", "right", "middle"]
545
+ }
546
+ },
547
+ additionalProperties: false
548
+ },
549
+ annotations: {
550
+ title: "Press mouse down",
551
+ readOnlyHint: false,
552
+ destructiveHint: true,
553
+ openWorldHint: true
554
+ }
555
+ },
556
+ {
557
+ name: "browser_mouse_up",
558
+ description: "Press mouse up",
559
+ inputSchema: {
560
+ $schema: "https://json-schema.org/draft/2020-12/schema",
561
+ type: "object",
562
+ properties: {
563
+ button: {
564
+ description: "Button to press, defaults to left",
565
+ type: "string",
566
+ enum: ["left", "right", "middle"]
567
+ }
568
+ },
569
+ additionalProperties: false
570
+ },
571
+ annotations: {
572
+ title: "Press mouse up",
573
+ readOnlyHint: false,
574
+ destructiveHint: true,
575
+ openWorldHint: true
576
+ }
577
+ },
578
+ {
579
+ name: "browser_mouse_wheel",
580
+ description: "Scroll mouse wheel",
581
+ inputSchema: {
582
+ $schema: "https://json-schema.org/draft/2020-12/schema",
583
+ type: "object",
584
+ properties: {
585
+ deltaX: {
586
+ default: 0,
587
+ description: "X delta",
588
+ type: "number"
589
+ },
590
+ deltaY: {
591
+ default: 0,
592
+ description: "Y delta",
593
+ type: "number"
594
+ }
595
+ },
596
+ required: ["deltaX", "deltaY"],
597
+ additionalProperties: false
598
+ },
599
+ annotations: {
600
+ title: "Scroll mouse wheel",
601
+ readOnlyHint: false,
602
+ destructiveHint: true,
603
+ openWorldHint: true
604
+ }
605
+ },
606
+ {
607
+ name: "browser_navigate",
608
+ description: "Navigate to a URL",
609
+ inputSchema: {
610
+ $schema: "https://json-schema.org/draft/2020-12/schema",
611
+ type: "object",
612
+ properties: {
613
+ url: {
614
+ type: "string",
615
+ description: "The URL to navigate to"
616
+ }
617
+ },
618
+ required: ["url"],
619
+ additionalProperties: false
620
+ },
621
+ annotations: {
622
+ title: "Navigate to a URL",
623
+ readOnlyHint: false,
624
+ destructiveHint: true,
625
+ openWorldHint: true
626
+ }
627
+ },
628
+ {
629
+ name: "browser_navigate_back",
630
+ description: "Go back to the previous page in the history",
631
+ inputSchema: {
632
+ $schema: "https://json-schema.org/draft/2020-12/schema",
633
+ type: "object",
634
+ properties: {},
635
+ additionalProperties: false
636
+ },
637
+ annotations: {
638
+ title: "Go back",
639
+ readOnlyHint: false,
640
+ destructiveHint: true,
641
+ openWorldHint: true
642
+ }
643
+ },
644
+ {
645
+ name: "browser_network_requests",
646
+ description: "Returns a numbered list of network requests since loading the page. Use browser_network_request with the number to get full details.",
647
+ inputSchema: {
648
+ $schema: "https://json-schema.org/draft/2020-12/schema",
649
+ type: "object",
650
+ properties: {
651
+ static: {
652
+ default: false,
653
+ description: "Whether to include successful static resources like images, fonts, scripts, etc. Defaults to false.",
654
+ type: "boolean"
655
+ },
656
+ filter: {
657
+ description: 'Only return requests whose URL matches this regexp (e.g. "/api/.*user").',
658
+ type: "string"
659
+ },
660
+ all: {
661
+ description: "Return all network requests since the beginning of the session, not just since the last navigation. Defaults to false.",
662
+ type: "boolean"
663
+ },
664
+ filename: {
665
+ description: "File name to save the network requests to. Relative file names are resolved against the workspace root. If not provided, requests are returned as text.",
666
+ type: "string"
667
+ }
668
+ },
669
+ required: ["static"],
670
+ additionalProperties: false
671
+ },
672
+ annotations: {
673
+ title: "List network requests",
674
+ readOnlyHint: true,
675
+ destructiveHint: false,
676
+ openWorldHint: true
677
+ }
678
+ },
679
+ {
680
+ name: "browser_network_request",
681
+ description: "Returns full details (headers and body) of a single network request, or a single part if `part` is set. Use the number from browser_network_requests.",
682
+ inputSchema: {
683
+ $schema: "https://json-schema.org/draft/2020-12/schema",
684
+ type: "object",
685
+ properties: {
686
+ index: {
687
+ type: "integer",
688
+ minimum: 1,
689
+ maximum: 9007199254740991,
690
+ description: "1-based index of the request, as printed by browser_network_requests."
691
+ },
692
+ part: {
693
+ description: "Return only this part of the request. Omit to return full details.",
694
+ type: "string",
695
+ enum: ["request-headers", "request-body", "response-headers", "response-body"]
696
+ },
697
+ filename: {
698
+ description: "File name to save the result to. Relative file names are resolved against the workspace root. If not provided, output is returned as text.",
699
+ type: "string"
700
+ }
701
+ },
702
+ required: ["index"],
703
+ additionalProperties: false
704
+ },
705
+ annotations: {
706
+ title: "Show network request details",
707
+ readOnlyHint: true,
708
+ destructiveHint: false,
709
+ openWorldHint: true
710
+ }
711
+ },
712
+ {
713
+ name: "browser_pdf_save",
714
+ description: "Save page as PDF",
715
+ inputSchema: {
716
+ $schema: "https://json-schema.org/draft/2020-12/schema",
717
+ type: "object",
718
+ properties: {
719
+ filename: {
720
+ description: "File name to save the pdf to. Relative file names are resolved against the workspace root. If not specified, the pdf is saved into the output directory as `page-{timestamp}.pdf`.",
721
+ type: "string"
722
+ }
723
+ },
724
+ additionalProperties: false
725
+ },
726
+ annotations: {
727
+ title: "Save as PDF",
728
+ readOnlyHint: true,
729
+ destructiveHint: false,
730
+ openWorldHint: true
731
+ }
732
+ },
733
+ {
734
+ name: "browser_run_code_unsafe",
735
+ description: "Run a Playwright code snippet. Unsafe: executes arbitrary JavaScript in the Playwright server process and is RCE-equivalent.",
736
+ inputSchema: {
737
+ $schema: "https://json-schema.org/draft/2020-12/schema",
738
+ type: "object",
739
+ properties: {
740
+ code: {
741
+ description: "A JavaScript function containing Playwright code to execute. It will be invoked with a single argument, page, which you can use for any page interaction. For example: `async (page) => { await page.getByRole('button', { name: 'Submit' }).click(); return await page.title(); }`",
742
+ type: "string"
743
+ },
744
+ filename: {
745
+ description: "Load code from the specified file. Relative file names are resolved against the workspace root. If both code and filename are provided, code will be ignored.",
746
+ type: "string"
747
+ }
748
+ },
749
+ additionalProperties: false
750
+ },
751
+ annotations: {
752
+ title: "Run Playwright code (unsafe)",
753
+ readOnlyHint: false,
754
+ destructiveHint: true,
755
+ openWorldHint: true
756
+ }
757
+ },
758
+ {
759
+ name: "browser_take_screenshot",
760
+ description: "Take a screenshot of the current page. Use browser_snapshot for actions by default. With the vision capability enabled, use screenshot coordinates with the coordinate-based mouse tools for elements not exposed in the accessibility snapshot.",
761
+ inputSchema: {
762
+ $schema: "https://json-schema.org/draft/2020-12/schema",
763
+ type: "object",
764
+ properties: {
765
+ element: {
766
+ description: "Human-readable element description used to obtain permission to interact with the element",
767
+ type: "string"
768
+ },
769
+ target: {
770
+ description: "Exact target element reference from the page snapshot, or a unique element selector",
771
+ type: "string"
772
+ },
773
+ type: {
774
+ description: "Image format for the screenshot. If unset, inferred from the filename extension, otherwise png.",
775
+ type: "string",
776
+ enum: ["png", "jpeg", "webp"]
777
+ },
778
+ filename: {
779
+ description: "File name to save the screenshot to. Relative file names are resolved against the workspace root. If not specified, the screenshot is saved into the output directory as `page-{timestamp}.{png|jpeg|webp}`.",
780
+ type: "string"
781
+ },
782
+ fullPage: {
783
+ description: "When true, takes a screenshot of the full scrollable page, instead of the currently visible viewport. Cannot be used with element screenshots.",
784
+ type: "boolean"
785
+ },
786
+ scale: {
787
+ default: "css",
788
+ description: 'Image resolution scale. "css" produces a screenshot sized in CSS pixels (smaller, consistent across devices). "device" produces a high-resolution screenshot using device pixels (larger, accounts for the device pixel ratio). Default is css.',
789
+ type: "string",
790
+ enum: ["css", "device"]
791
+ }
792
+ },
793
+ required: ["scale"],
794
+ additionalProperties: false
795
+ },
796
+ annotations: {
797
+ title: "Take a screenshot",
798
+ readOnlyHint: true,
799
+ destructiveHint: false,
800
+ openWorldHint: true
801
+ }
802
+ },
803
+ {
804
+ name: "browser_snapshot",
805
+ description: "Capture accessibility snapshot of the current page, this is better than screenshot",
806
+ inputSchema: {
807
+ $schema: "https://json-schema.org/draft/2020-12/schema",
808
+ type: "object",
809
+ properties: {
810
+ target: {
811
+ description: "Exact target element reference from the page snapshot, or a unique element selector",
812
+ type: "string"
813
+ },
814
+ filename: {
815
+ description: "Save snapshot to a file instead of returning it in the response. Relative file names are resolved against the workspace root.",
816
+ type: "string"
817
+ },
818
+ depth: {
819
+ description: "Limit the depth of the snapshot tree",
820
+ type: "number"
821
+ },
822
+ boxes: {
823
+ description: "Include each element's bounding box as [box=x,y,width,height] in the snapshot. Coordinates are viewport-relative, in CSS pixels (Element.getBoundingClientRect)",
824
+ type: "boolean"
825
+ }
826
+ },
827
+ additionalProperties: false
828
+ },
829
+ annotations: {
830
+ title: "Page snapshot",
831
+ readOnlyHint: true,
832
+ destructiveHint: false,
833
+ openWorldHint: true
834
+ }
835
+ },
836
+ {
837
+ name: "browser_click",
838
+ description: "Perform click on a web page",
839
+ inputSchema: {
840
+ $schema: "https://json-schema.org/draft/2020-12/schema",
841
+ type: "object",
842
+ properties: {
843
+ element: {
844
+ description: "Human-readable element description used to obtain permission to interact with the element",
845
+ type: "string"
846
+ },
847
+ target: {
848
+ type: "string",
849
+ description: "Exact target element reference from the page snapshot, or a unique element selector"
850
+ },
851
+ doubleClick: {
852
+ description: "Whether to perform a double click instead of a single click",
853
+ type: "boolean"
854
+ },
855
+ button: {
856
+ description: "Button to click, defaults to left",
857
+ type: "string",
858
+ enum: ["left", "right", "middle"]
859
+ },
860
+ modifiers: {
861
+ description: "Modifier keys to press",
862
+ type: "array",
863
+ items: {
864
+ type: "string",
865
+ enum: ["Alt", "Control", "ControlOrMeta", "Meta", "Shift"]
866
+ }
867
+ }
868
+ },
869
+ required: ["target"],
870
+ additionalProperties: false
871
+ },
872
+ annotations: {
873
+ title: "Click",
874
+ readOnlyHint: false,
875
+ destructiveHint: true,
876
+ openWorldHint: true
877
+ }
878
+ },
879
+ {
880
+ name: "browser_drag",
881
+ description: "Perform drag and drop between two elements",
882
+ inputSchema: {
883
+ $schema: "https://json-schema.org/draft/2020-12/schema",
884
+ type: "object",
885
+ properties: {
886
+ startElement: {
887
+ description: "Human-readable source element description used to obtain the permission to interact with the element",
888
+ type: "string"
889
+ },
890
+ startTarget: {
891
+ type: "string",
892
+ description: "Exact target element reference from the page snapshot, or a unique element selector"
893
+ },
894
+ endElement: {
895
+ description: "Human-readable target element description used to obtain the permission to interact with the element",
896
+ type: "string"
897
+ },
898
+ endTarget: {
899
+ type: "string",
900
+ description: "Exact target element reference from the page snapshot, or a unique element selector"
901
+ }
902
+ },
903
+ required: ["startTarget", "endTarget"],
904
+ additionalProperties: false
905
+ },
906
+ annotations: {
907
+ title: "Drag mouse",
908
+ readOnlyHint: false,
909
+ destructiveHint: true,
910
+ openWorldHint: true
911
+ }
912
+ },
913
+ {
914
+ name: "browser_hover",
915
+ description: "Hover over element on page",
916
+ inputSchema: {
917
+ $schema: "https://json-schema.org/draft/2020-12/schema",
918
+ type: "object",
919
+ properties: {
920
+ element: {
921
+ description: "Human-readable element description used to obtain permission to interact with the element",
922
+ type: "string"
923
+ },
924
+ target: {
925
+ type: "string",
926
+ description: "Exact target element reference from the page snapshot, or a unique element selector"
927
+ }
928
+ },
929
+ required: ["target"],
930
+ additionalProperties: false
931
+ },
932
+ annotations: {
933
+ title: "Hover mouse",
934
+ readOnlyHint: false,
935
+ destructiveHint: true,
936
+ openWorldHint: true
937
+ }
938
+ },
939
+ {
940
+ name: "browser_select_option",
941
+ description: "Select an option in a dropdown",
942
+ inputSchema: {
943
+ $schema: "https://json-schema.org/draft/2020-12/schema",
944
+ type: "object",
945
+ properties: {
946
+ element: {
947
+ description: "Human-readable element description used to obtain permission to interact with the element",
948
+ type: "string"
949
+ },
950
+ target: {
951
+ type: "string",
952
+ description: "Exact target element reference from the page snapshot, or a unique element selector"
953
+ },
954
+ values: {
955
+ type: "array",
956
+ items: {
957
+ type: "string"
958
+ },
959
+ description: "Array of values to select in the dropdown. This can be a single value or multiple values."
960
+ }
961
+ },
962
+ required: ["target", "values"],
963
+ additionalProperties: false
964
+ },
965
+ annotations: {
966
+ title: "Select option",
967
+ readOnlyHint: false,
968
+ destructiveHint: true,
969
+ openWorldHint: true
970
+ }
971
+ },
972
+ {
973
+ name: "browser_tabs",
974
+ description: "List, create, close, or select a browser tab.",
975
+ inputSchema: {
976
+ $schema: "https://json-schema.org/draft/2020-12/schema",
977
+ type: "object",
978
+ properties: {
979
+ action: {
980
+ type: "string",
981
+ enum: ["list", "new", "close", "select"],
982
+ description: "Operation to perform"
983
+ },
984
+ index: {
985
+ description: "Tab index, used for close/select. If omitted for close, current tab is closed.",
986
+ type: "number"
987
+ },
988
+ url: {
989
+ description: "URL to navigate to in the new tab, used for new.",
990
+ type: "string"
991
+ },
992
+ isolatedContext: {
993
+ description: 'Name of an isolated browser context to create the new tab in, used for new. Tabs in the same isolated context share cookies and storage, tabs in different contexts are fully isolated. If omitted or "default", the tab is created in the default context.',
994
+ type: "string"
995
+ }
996
+ },
997
+ required: ["action"],
998
+ additionalProperties: false
999
+ },
1000
+ annotations: {
1001
+ title: "Manage tabs",
1002
+ readOnlyHint: false,
1003
+ destructiveHint: true,
1004
+ openWorldHint: true
1005
+ }
1006
+ },
1007
+ {
1008
+ name: "browser_wait_for",
1009
+ description: "Wait for text to appear or disappear or a specified time to pass. When both text and textGone are provided, waits for the first one to happen",
1010
+ inputSchema: {
1011
+ $schema: "https://json-schema.org/draft/2020-12/schema",
1012
+ type: "object",
1013
+ properties: {
1014
+ time: {
1015
+ description: "The time to wait in seconds, at most 30. When combined with text or textGone, serves as a timeout for them instead of the default action timeout",
1016
+ type: "number"
1017
+ },
1018
+ text: {
1019
+ description: "The text to wait for",
1020
+ type: "string"
1021
+ },
1022
+ textGone: {
1023
+ description: "The text to wait for to disappear",
1024
+ type: "string"
1025
+ }
1026
+ },
1027
+ additionalProperties: false
1028
+ },
1029
+ annotations: {
1030
+ title: "Wait for",
1031
+ readOnlyHint: true,
1032
+ destructiveHint: false,
1033
+ openWorldHint: true
1034
+ }
1035
+ }
1036
+ ]
1037
+ };
1038
+
1039
+ // src/host/mcp/protocol.ts
1040
+ var PROTOCOL_VERSION = "2025-06-18";
1041
+ var McpProtocolError = class extends Error {
1042
+ constructor(message) {
1043
+ super(`Playwright MCP answered something unexpected: ${message}`);
1044
+ this.name = "McpProtocolError";
1045
+ }
1046
+ };
1047
+ var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
1048
+ function parseTool(value, where) {
1049
+ if (!isRecord(value)) throw new McpProtocolError(`${where} is not an object`);
1050
+ const { name: name2, description, inputSchema, annotations } = value;
1051
+ if (typeof name2 !== "string" || name2 === "") throw new McpProtocolError(`${where} has no name`);
1052
+ if (typeof description !== "string") throw new McpProtocolError(`${name2} has no description`);
1053
+ if (!isRecord(inputSchema) || inputSchema.type !== "object") {
1054
+ throw new McpProtocolError(`${name2} has no object input schema`);
1055
+ }
1056
+ if (annotations !== void 0 && !isRecord(annotations)) {
1057
+ throw new McpProtocolError(`${name2} has annotations that are not an object`);
1058
+ }
1059
+ return {
1060
+ name: name2,
1061
+ description,
1062
+ inputSchema,
1063
+ ...annotations === void 0 ? {} : { annotations }
1064
+ };
1065
+ }
1066
+ function parseToolList(value) {
1067
+ if (!isRecord(value) || !Array.isArray(value.tools)) {
1068
+ throw new McpProtocolError("tools/list has no tools");
1069
+ }
1070
+ if (value.nextCursor !== void 0) {
1071
+ throw new McpProtocolError("tools/list answered in pages, which the connector does not read");
1072
+ }
1073
+ return value.tools.map((tool, index) => parseTool(tool, `tool ${index + 1}`));
1074
+ }
1075
+ function parseCallResult(value) {
1076
+ if (!isRecord(value) || !Array.isArray(value.content)) {
1077
+ throw new McpProtocolError("a tool's result has no content");
1078
+ }
1079
+ if (value.isError !== void 0 && typeof value.isError !== "boolean") {
1080
+ throw new McpProtocolError("a tool's isError is not true or false");
1081
+ }
1082
+ const content = value.content.map((block, index) => {
1083
+ if (!isRecord(block)) throw new McpProtocolError(`content ${index + 1} is not an object`);
1084
+ if (block.type === "text" && typeof block.text === "string") {
1085
+ return { type: "text", text: block.text };
1086
+ }
1087
+ if (block.type === "image" && typeof block.data === "string" && typeof block.mimeType === "string") {
1088
+ return { type: "image", data: block.data, mimeType: block.mimeType };
1089
+ }
1090
+ throw new McpProtocolError(`content ${index + 1} is neither text nor an image`);
1091
+ });
1092
+ return { content, isError: value.isError === true };
1093
+ }
1094
+ function parseInitialize(value) {
1095
+ if (!isRecord(value) || !isRecord(value.serverInfo)) {
1096
+ throw new McpProtocolError("initialize has no serverInfo");
1097
+ }
1098
+ const { name: name2, version } = value.serverInfo;
1099
+ if (typeof name2 !== "string" || typeof version !== "string") {
1100
+ throw new McpProtocolError("initialize has no server name and version");
1101
+ }
1102
+ if (typeof value.protocolVersion !== "string") {
1103
+ throw new McpProtocolError("initialize has no protocol version");
1104
+ }
1105
+ return { name: name2, version };
1106
+ }
1107
+
1108
+ // src/host/catalog.ts
1109
+ var NOT_OFFERED = ["browser_close", "browser_install"];
1110
+ var DISALLOWED = ["browser_run_code_unsafe"];
1111
+ var UPSTREAM_PREFIX = "browser_";
1112
+ function parseGeneratedServer(value) {
1113
+ const record = value;
1114
+ const server = record.server;
1115
+ if (typeof record.package !== "string" || typeof record.version !== "string" || typeof server?.name !== "string" || typeof server.version !== "string" || !Array.isArray(record.arguments) || !record.arguments.every((argument) => typeof argument === "string") || !Array.isArray(record.tools)) {
1116
+ throw new Error("src/generated/playwright-mcp.json is malformed; run the generator again");
1117
+ }
1118
+ return {
1119
+ package: record.package,
1120
+ version: record.version,
1121
+ server: { name: server.name, version: server.version },
1122
+ arguments: record.arguments,
1123
+ tools: record.tools.map((tool, index) => parseTool(tool, `generated tool ${index + 1}`))
1124
+ };
1125
+ }
1126
+ var GENERATED_SERVER = parseGeneratedServer(playwright_mcp_default);
1127
+ function offeredTools(tools) {
1128
+ return tools.filter((tool) => !NOT_OFFERED.includes(tool.name)).map((tool) => {
1129
+ if (!tool.name.startsWith(UPSTREAM_PREFIX)) {
1130
+ throw new Error(`Playwright MCP's tool ${tool.name} is not named ${UPSTREAM_PREFIX}\u2026`);
1131
+ }
1132
+ return {
1133
+ upstream: tool,
1134
+ name: tool.name.slice(UPSTREAM_PREFIX.length),
1135
+ permission: DISALLOWED.includes(tool.name) ? "disallow" : "allow",
1136
+ readOnly: tool.annotations?.readOnlyHint === true
1137
+ };
1138
+ });
1139
+ }
1140
+ var canonical = (value) => {
1141
+ if (Array.isArray(value)) return value.map(canonical);
1142
+ if (typeof value !== "object" || value === null) return value;
1143
+ return Object.fromEntries(
1144
+ Object.keys(value).sort().map((key) => [key, canonical(value[key])])
1145
+ );
1146
+ };
1147
+ function toolDifferences(expected, listed) {
1148
+ const byName = new Map(listed.map((tool) => [tool.name, tool]));
1149
+ const differences = [];
1150
+ for (const tool of expected) {
1151
+ const other = byName.get(tool.name);
1152
+ if (other === void 0) differences.push(`${tool.name} is missing`);
1153
+ else if (JSON.stringify(canonical(other)) !== JSON.stringify(canonical(tool))) {
1154
+ differences.push(`${tool.name} changed`);
1155
+ }
1156
+ byName.delete(tool.name);
1157
+ }
1158
+ for (const name2 of byName.keys()) differences.push(`${name2} is new`);
1159
+ return differences;
1160
+ }
1161
+
1162
+ // src/shared/connector.ts
1163
+ var BROWSER_CONNECTOR_ID = "browser";
1164
+ var DESKTOP_CONNECTOR_ID = "desktop";
1165
+
1166
+ // src/host/connections.ts
1167
+ var BrowserConnections = class {
1168
+ opened = /* @__PURE__ */ new Map();
1169
+ unseen = /* @__PURE__ */ new Set();
1170
+ /** A connection opened; every one after the first is a reconnection. */
1171
+ connected(botId) {
1172
+ const count = (this.opened.get(botId) ?? 0) + 1;
1173
+ this.opened.set(botId, count);
1174
+ if (count > 1) this.unseen.add(botId);
1175
+ }
1176
+ /** Whether the next result is the first since a reconnection (it then is not any more). */
1177
+ takeReconnected(botId) {
1178
+ return this.unseen.delete(botId);
1179
+ }
1180
+ };
1181
+
1182
+ // src/host/vm/layout.ts
1183
+ var MCP_DIR = "/opt/dsh-browser/mcp";
1184
+ var MCP_SHRINKWRAP = `${MCP_DIR}/npm-shrinkwrap.json`;
1185
+ var MCP_CLI = `${MCP_DIR}/node_modules/@playwright/mcp/cli.js`;
1186
+ var CDP_ENDPOINT = "http://127.0.0.1:9222";
1187
+ var OUTPUT_MAX_BYTES = 256 << 20;
1188
+ var outputDir = (user) => `${user.home}/.cache/dsh-browser/output`;
1189
+ var stagingDir = (user) => `${user.home}/.cache/dsh-browser/staging`;
1190
+
1191
+ // src/host/mcp/client.ts
1192
+ var McpCallError = class extends Error {
1193
+ constructor(code, message) {
1194
+ super(message);
1195
+ this.code = code;
1196
+ this.name = "McpCallError";
1197
+ }
1198
+ code;
1199
+ };
1200
+ var McpUnavailableError = class extends Error {
1201
+ constructor(reason) {
1202
+ super(`Playwright MCP is not reachable: ${reason}`);
1203
+ this.name = "McpUnavailableError";
1204
+ }
1205
+ };
1206
+ var NEWLINE = 10;
1207
+ var METHOD_NOT_FOUND = -32601;
1208
+ var isRecord2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
1209
+ function createMcpClient(process, deps, limits) {
1210
+ const pending = /* @__PURE__ */ new Map();
1211
+ const encoder = new TextEncoder();
1212
+ const decoder = new TextDecoder();
1213
+ let nextId = 1;
1214
+ let failure;
1215
+ const send = (message) => process.stdin.write(encoder.encode(`${JSON.stringify({ jsonrpc: "2.0", ...message })}
1216
+ `));
1217
+ const failAll = (error) => {
1218
+ failure ??= error;
1219
+ for (const entry of pending.values()) entry.reject(failure);
1220
+ pending.clear();
1221
+ };
1222
+ const answerRequest = (id, method) => {
1223
+ if (typeof id !== "number" && typeof id !== "string") return;
1224
+ void send(
1225
+ method === "ping" ? { id, result: {} } : { id, error: { code: METHOD_NOT_FOUND, message: `${method} is not supported` } }
1226
+ ).catch(() => {
1227
+ });
1228
+ };
1229
+ const receive = (line) => {
1230
+ let message;
1231
+ try {
1232
+ message = JSON.parse(decoder.decode(line));
1233
+ } catch {
1234
+ throw new McpProtocolError("a line that is not JSON");
1235
+ }
1236
+ if (!isRecord2(message) || message.jsonrpc !== "2.0") {
1237
+ throw new McpProtocolError("a line that is not JSON-RPC 2.0");
1238
+ }
1239
+ if (typeof message.method === "string") {
1240
+ if ("id" in message) answerRequest(message.id, message.method);
1241
+ return;
1242
+ }
1243
+ if (typeof message.id !== "number") throw new McpProtocolError("a reply without a request id");
1244
+ const entry = pending.get(message.id);
1245
+ if (entry === void 0) return;
1246
+ pending.delete(message.id);
1247
+ const { error } = message;
1248
+ if (error !== void 0) {
1249
+ const code = isRecord2(error) && typeof error.code === "number" ? error.code : 0;
1250
+ const text = isRecord2(error) && typeof error.message === "string" ? error.message : "an error";
1251
+ entry.reject(new McpCallError(code, text.slice(0, 4e3)));
1252
+ } else if ("result" in message) {
1253
+ entry.resolve(message.result);
1254
+ } else {
1255
+ entry.reject(new McpProtocolError("a reply without a result"));
1256
+ }
1257
+ };
1258
+ const read = async () => {
1259
+ let buffer = new Uint8Array(0);
1260
+ for await (const chunk of process.stdout) {
1261
+ const joined = new Uint8Array(buffer.byteLength + chunk.byteLength);
1262
+ joined.set(buffer);
1263
+ joined.set(chunk, buffer.byteLength);
1264
+ buffer = joined;
1265
+ let start = 0;
1266
+ for (let index = buffer.indexOf(NEWLINE); index >= 0; index = buffer.indexOf(NEWLINE, start)) {
1267
+ receive(buffer.subarray(start, index));
1268
+ start = index + 1;
1269
+ }
1270
+ buffer = buffer.slice(start);
1271
+ if (buffer.byteLength > limits.maxLineBytes) {
1272
+ throw new McpProtocolError(`a line longer than ${limits.maxLineBytes} bytes`);
1273
+ }
1274
+ }
1275
+ throw new McpUnavailableError("its process ended");
1276
+ };
1277
+ const closed = read().catch((error) => {
1278
+ failAll(error instanceof Error ? error : new McpUnavailableError(String(error)));
1279
+ });
1280
+ return {
1281
+ closed,
1282
+ async notify(method, params) {
1283
+ if (failure !== void 0) throw failure;
1284
+ await send(params === void 0 ? { method } : { method, params });
1285
+ },
1286
+ async request(method, params, options) {
1287
+ if (failure !== void 0) throw failure;
1288
+ const id = nextId++;
1289
+ const deadline = deps.deadline(options.timeoutMs);
1290
+ const signal = options.signal === void 0 ? deadline : AbortSignal.any([deadline, options.signal]);
1291
+ const answer = new Promise((resolve, reject) => {
1292
+ pending.set(id, { resolve, reject });
1293
+ signal.addEventListener(
1294
+ "abort",
1295
+ () => {
1296
+ if (!pending.delete(id)) return;
1297
+ const reason = deadline.aborted ? `${method} took longer than ${options.timeoutMs} ms` : "cancelled";
1298
+ void send({
1299
+ method: "notifications/cancelled",
1300
+ params: { requestId: id, reason }
1301
+ }).catch(() => {
1302
+ });
1303
+ reject(
1304
+ deadline.aborted ? new McpUnavailableError(reason) : signal.reason instanceof Error ? signal.reason : new Error(reason)
1305
+ );
1306
+ },
1307
+ { once: true }
1308
+ );
1309
+ });
1310
+ try {
1311
+ await send({ id, method, params });
1312
+ } catch (error) {
1313
+ pending.delete(id);
1314
+ throw new McpUnavailableError(error instanceof Error ? error.message : String(error));
1315
+ }
1316
+ return answer;
1317
+ }
1318
+ };
1319
+ }
1320
+
1321
+ // src/host/mcp/server.ts
1322
+ var MAX_SERVER_LINE_BYTES = 48 << 20;
1323
+ var START_TIMEOUT_MS = 6e4;
1324
+ var LIST_TIMEOUT_MS = 3e4;
1325
+ function serverArgv(user, toolArguments) {
1326
+ return [
1327
+ "node",
1328
+ MCP_CLI,
1329
+ ...toolArguments,
1330
+ "--cdp-endpoint",
1331
+ CDP_ENDPOINT,
1332
+ "--codegen",
1333
+ "none",
1334
+ "--file-paths",
1335
+ "absolute",
1336
+ "--output-dir",
1337
+ outputDir(user),
1338
+ "--output-max-size",
1339
+ String(OUTPUT_MAX_BYTES)
1340
+ ];
1341
+ }
1342
+ async function startServer(environment, user, toolArguments, signal, deps) {
1343
+ const process = await environment.spawn({ argv: serverArgv(user, toolArguments), signal });
1344
+ const client = createMcpClient(process, deps, { maxLineBytes: MAX_SERVER_LINE_BYTES });
1345
+ let server;
1346
+ try {
1347
+ server = parseInitialize(
1348
+ await client.request(
1349
+ "initialize",
1350
+ {
1351
+ protocolVersion: PROTOCOL_VERSION,
1352
+ capabilities: {},
1353
+ clientInfo: { name: "dsh-bot-connector-browser", version: "1" }
1354
+ },
1355
+ { timeoutMs: START_TIMEOUT_MS, signal }
1356
+ )
1357
+ );
1358
+ await client.notify("notifications/initialized");
1359
+ } catch (error) {
1360
+ process.terminate();
1361
+ const log = process.stderr().trim();
1362
+ const reason = error instanceof Error ? error.message : String(error);
1363
+ throw new Error(log === "" ? reason : `${reason} (${log.split("\n").slice(-3).join("; ")})`);
1364
+ }
1365
+ return {
1366
+ server,
1367
+ async listTools(listSignal) {
1368
+ return parseToolList(
1369
+ await client.request("tools/list", {}, { timeoutMs: LIST_TIMEOUT_MS, signal: listSignal })
1370
+ );
1371
+ },
1372
+ async callTool(name2, args, options) {
1373
+ return parseCallResult(await client.request("tools/call", { name: name2, arguments: args }, options));
1374
+ },
1375
+ ended: Promise.race([process.done, client.closed]),
1376
+ close: () => process.terminate()
1377
+ };
1378
+ }
1379
+
1380
+ // src/host/vm/commands.ts
1381
+ var CommandError = class extends Error {
1382
+ constructor(argv, result) {
1383
+ const status = result.timedOut ? "timed out" : result.signal !== null ? `signal ${result.signal}` : `exit ${result.exitCode}`;
1384
+ const detail = result.stderr.trim().split("\n").slice(-6).join("\n");
1385
+ super(`${argv.slice(0, 4).join(" ")} failed (${status})${detail === "" ? "" : `: ${detail}`}`);
1386
+ this.name = "CommandError";
1387
+ }
1388
+ };
1389
+ async function run(environment, argv, options) {
1390
+ const result = await environment.exec({
1391
+ argv,
1392
+ timeoutMs: options.timeoutMs ?? 6e4,
1393
+ maxOutputBytes: options.maxOutputBytes ?? 64 * 1024,
1394
+ signal: options.signal
1395
+ });
1396
+ options.signal.throwIfAborted();
1397
+ const accepted = options.accept ?? [0];
1398
+ if (result.timedOut || result.exitCode === null || !accepted.includes(result.exitCode)) {
1399
+ throw new CommandError(argv, result);
1400
+ }
1401
+ return { exitCode: result.exitCode, stdout: new TextDecoder().decode(result.stdout) };
1402
+ }
1403
+ var ACCOUNT = 'id -u; id -un; printf "%s\\n" "$HOME"';
1404
+ async function readVmUser(environment, signal) {
1405
+ const { stdout } = await run(environment, ["sh", "-c", ACCOUNT], { signal, timeoutMs: 3e4 });
1406
+ const [uid, name2, home] = stdout.split("\n");
1407
+ if (uid === void 0 || !/^[0-9]{1,9}$/.test(uid) || name2 === void 0 || !/^[a-z_][a-z0-9_-]{0,31}$/.test(name2) || home === void 0 || !/^\/[^\0\n]*$/.test(home)) {
1408
+ throw new Error("the bot's account in its environment could not be read");
1409
+ }
1410
+ return { uid: Number(uid), name: name2, home };
1411
+ }
1412
+
1413
+ // src/host/preparation.ts
1414
+ var INSTALL_TIMEOUT_MS = 15 * 6e4;
1415
+ function chromeVersion(answer) {
1416
+ let parsed;
1417
+ try {
1418
+ parsed = JSON.parse(answer);
1419
+ } catch {
1420
+ throw new Error(`${CDP_ENDPOINT} did not answer with JSON`);
1421
+ }
1422
+ const browser = parsed?.Browser;
1423
+ if (typeof browser !== "string" || !/^Chrome\/[0-9.]+$/.test(browser)) {
1424
+ throw new Error(`${CDP_ENDPOINT} is not Chrome's DevTools`);
1425
+ }
1426
+ return browser;
1427
+ }
1428
+ function createBrowserPreparation(deps) {
1429
+ const decoder = new TextDecoder();
1430
+ const install = async (context, user) => {
1431
+ const stage = stagingDir(user);
1432
+ const { signal, environment } = context;
1433
+ await run(environment, ["rm", "-rf", "--", stage], { signal });
1434
+ await run(environment, ["mkdir", "-p", "-m", "0700", "--", stage], { signal });
1435
+ const files = [
1436
+ ["package.json", deps.installation.packageJson],
1437
+ ["npm-shrinkwrap.json", deps.installation.shrinkwrap],
1438
+ ["install-mcp.sh", deps.installation.script]
1439
+ ];
1440
+ for (const [name2, data] of files) {
1441
+ await environment.writeFile(`${stage}/${name2}`, data, { mode: 420, signal });
1442
+ }
1443
+ await run(environment, ["sudo", "-n", "sh", `${stage}/install-mcp.sh`, stage, MCP_DIR], {
1444
+ signal,
1445
+ timeoutMs: INSTALL_TIMEOUT_MS
1446
+ });
1447
+ await run(environment, ["rm", "-rf", "--", stage], { signal });
1448
+ };
1449
+ const installed = async (context) => {
1450
+ const current = await run(context.environment, ["cat", "--", MCP_SHRINKWRAP], {
1451
+ signal: context.signal,
1452
+ accept: [0, 1],
1453
+ maxOutputBytes: 4 << 20
1454
+ });
1455
+ return current.exitCode === 0 && current.stdout === decoder.decode(deps.installation.shrinkwrap);
1456
+ };
1457
+ const checkTools = async (context, user) => {
1458
+ const server = await startServer(
1459
+ context.environment,
1460
+ user,
1461
+ deps.generated.arguments,
1462
+ context.signal,
1463
+ deps
1464
+ );
1465
+ try {
1466
+ const differences = toolDifferences(
1467
+ deps.generated.tools,
1468
+ await server.listTools(context.signal)
1469
+ );
1470
+ if (differences.length > 0) {
1471
+ throw new Error(
1472
+ `Playwright MCP in the bot's VM lists other tools than this connector was built with (${deps.generated.package} ${deps.generated.version}): ${differences.slice(0, 8).join(", ")}`
1473
+ );
1474
+ }
1475
+ } finally {
1476
+ server.close();
1477
+ }
1478
+ };
1479
+ return {
1480
+ async prepare(context, progress) {
1481
+ progress("reading the bot's account");
1482
+ const user = await readVmUser(context.environment, context.signal);
1483
+ progress("checking Playwright MCP");
1484
+ if (!await installed(context)) {
1485
+ progress(`installing Playwright MCP ${deps.generated.version}`);
1486
+ await install(context, user);
1487
+ }
1488
+ progress("checking the desktop's Chrome");
1489
+ const answer = await run(
1490
+ context.environment,
1491
+ ["curl", "-sf", "--max-time", "10", `${CDP_ENDPOINT}/json/version`],
1492
+ { signal: context.signal }
1493
+ );
1494
+ chromeVersion(answer.stdout);
1495
+ progress("checking Playwright MCP's tools");
1496
+ await checkTools(context, user);
1497
+ }
1498
+ };
1499
+ }
1500
+
1501
+ // src/host/session.ts
1502
+ function browserAttachment(deps) {
1503
+ return {
1504
+ async open(context) {
1505
+ const user = await readVmUser(context.environment, context.signal);
1506
+ const server = await startServer(
1507
+ context.environment,
1508
+ user,
1509
+ deps.generated.arguments,
1510
+ context.signal,
1511
+ deps
1512
+ );
1513
+ deps.connections.connected(context.bot.id);
1514
+ return {
1515
+ value: server,
1516
+ ended: server.ended,
1517
+ async dispose() {
1518
+ server.close();
1519
+ }
1520
+ };
1521
+ }
1522
+ };
1523
+ }
1524
+
1525
+ // src/host/result.ts
1526
+ var IMAGE_TYPES = ["image/png", "image/jpeg", "image/webp"];
1527
+ var MAX_IMAGE_BYTES = 16 << 20;
1528
+ var BASE64 = /^[A-Za-z0-9+/]*={0,2}$/;
1529
+ var isImageType = (value) => IMAGE_TYPES.includes(value);
1530
+ function imageOf(block) {
1531
+ if (!isImageType(block.mimeType)) {
1532
+ throw new Error(`Playwright MCP returned an image of type ${block.mimeType.slice(0, 60)}`);
1533
+ }
1534
+ if (block.data.length % 4 !== 0 || !BASE64.test(block.data)) {
1535
+ throw new Error("Playwright MCP returned an image that is not base64");
1536
+ }
1537
+ if (block.data.length / 4 * 3 > MAX_IMAGE_BYTES) {
1538
+ throw new Error(`Playwright MCP returned an image larger than ${MAX_IMAGE_BYTES} bytes`);
1539
+ }
1540
+ return { mediaType: block.mimeType, data: new Uint8Array(Buffer.from(block.data, "base64")) };
1541
+ }
1542
+ async function resultOf(result, run2) {
1543
+ const texts = [];
1544
+ const images = [];
1545
+ for (const block of result.content) {
1546
+ if (block.type === "text") {
1547
+ texts.push(block.text);
1548
+ continue;
1549
+ }
1550
+ const image = imageOf(block);
1551
+ if (result.isError) continue;
1552
+ if (run2.caller === void 0) {
1553
+ texts.push("[An image was left out: an approved action's result carries text only.]");
1554
+ continue;
1555
+ }
1556
+ const admitted = await run2.caller.images.admit(image);
1557
+ if (!admitted.ok) throw new Error(`cannot show the image: ${admitted.reason}`);
1558
+ images.push(admitted.image);
1559
+ }
1560
+ const text = texts.join("\n\n");
1561
+ if (result.isError) throw new Error(text === "" ? "Playwright MCP reported an error" : text);
1562
+ return { ...text === "" ? {} : { text }, ...images.length === 0 ? {} : { images } };
1563
+ }
1564
+
1565
+ // src/host/schema.ts
1566
+ var ANNOTATIONS = /* @__PURE__ */ new Set(["description", "title", "default", "examples"]);
1567
+ var KEPT = /* @__PURE__ */ new Set(["type", "properties", "required", "enum", "const", "items"]);
1568
+ var isNode = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
1569
+ var described = (node, notes) => {
1570
+ if (notes.length === 0) return node;
1571
+ const note = notes.join("; ");
1572
+ return {
1573
+ ...node,
1574
+ description: typeof node.description === "string" && node.description !== "" ? `${node.description} (${note})` : `(${note})`
1575
+ };
1576
+ };
1577
+ function convert(node, path) {
1578
+ if (!isNode(node)) throw new Error(`${path} is not a schema object`);
1579
+ const out = {};
1580
+ const notes = [];
1581
+ for (const [key, value] of Object.entries(node)) {
1582
+ if (ANNOTATIONS.has(key) || key === "type" || key === "required" || key === "enum" || key === "const") {
1583
+ out[key] = value;
1584
+ } else if (key === "$schema") {
1585
+ } else if (key === "properties") {
1586
+ if (!isNode(value)) throw new Error(`${path}.properties is not an object`);
1587
+ out.properties = Object.fromEntries(
1588
+ Object.entries(value).map(([name2, child]) => [
1589
+ name2,
1590
+ convert(child, `${path}.properties.${name2}`)
1591
+ ])
1592
+ );
1593
+ } else if (key === "items") {
1594
+ out.items = convert(value, `${path}.items`);
1595
+ } else if (key === "anyOf") {
1596
+ out.oneOf = exclusiveBranches(value, path);
1597
+ } else if (key === "additionalProperties") {
1598
+ if (typeof value === "boolean") out.additionalProperties = value;
1599
+ else notes.push(`every value: ${valueType(value, path)}`);
1600
+ } else if (key === "propertyNames") {
1601
+ if (!isNode(value) || value.type !== "string" || Object.keys(value).length !== 1) {
1602
+ throw new Error(`${path}.propertyNames is more than "any string"`);
1603
+ }
1604
+ } else if (key === "minimum") {
1605
+ notes.push(`at least ${String(value)}`);
1606
+ } else if (key === "maximum") {
1607
+ if (value !== Number.MAX_SAFE_INTEGER) notes.push(`at most ${String(value)}`);
1608
+ } else {
1609
+ throw new Error(`${path}.${key} is a keyword the conversion does not know`);
1610
+ }
1611
+ }
1612
+ for (const key of Object.keys(out)) {
1613
+ if (!KEPT.has(key) && !ANNOTATIONS.has(key) && key !== "oneOf" && key !== "additionalProperties") {
1614
+ throw new Error(`${path}.${key} was kept by mistake`);
1615
+ }
1616
+ }
1617
+ return described(out, notes);
1618
+ }
1619
+ function exclusiveBranches(value, path) {
1620
+ if (!Array.isArray(value) || value.length < 2) {
1621
+ throw new Error(`${path}.anyOf is not a list of at least two schemas`);
1622
+ }
1623
+ const branches = value.map((branch, index) => convert(branch, `${path}.anyOf[${index}]`));
1624
+ const types = branches.map((branch) => branch.type);
1625
+ if (types.some((type) => typeof type !== "string") || new Set(types).size !== types.length) {
1626
+ throw new Error(`${path}.anyOf has branches that may overlap`);
1627
+ }
1628
+ return branches;
1629
+ }
1630
+ function valueType(value, path) {
1631
+ if (!isNode(value) || typeof value.type !== "string" || Object.keys(value).length !== 1) {
1632
+ throw new Error(`${path}.additionalProperties is more than a type`);
1633
+ }
1634
+ return value.type;
1635
+ }
1636
+ function toolSchema(inputSchema, tool) {
1637
+ const converted = convert(inputSchema, tool);
1638
+ if (converted.type !== "object") throw new Error(`${tool}'s arguments are not an object`);
1639
+ return converted;
1640
+ }
1641
+
1642
+ // src/host/tools.ts
1643
+ var MAX_RESULT_CHARS = 128e3;
1644
+ var CALL_TIMEOUT_MS = 18e4;
1645
+ var EXCLUSIVE_PAGE = "page";
1646
+ var RECONNECTED = "Note: the connection to the browser was opened again since your last call (the tabs and the page stay as they were). Element refs of earlier snapshots no longer work: take a new browser_snapshot. The previous call was not repeated.";
1647
+ function previewOf(name2, args) {
1648
+ return {
1649
+ title: `Run browser_${name2} in the bot's browser?`,
1650
+ fields: Object.entries(args).map(([label, value]) => {
1651
+ const text = typeof value === "string" ? value : JSON.stringify(value);
1652
+ return { label, value: text.length > 300 ? `${text.slice(0, 300)}\u2026` : text };
1653
+ })
1654
+ };
1655
+ }
1656
+ function explain(error) {
1657
+ if (error instanceof McpUnavailableError || error instanceof McpProtocolError) {
1658
+ return new Error(
1659
+ `${error.message}. The next browser call starts it again; take a browser_snapshot before repeating anything.`
1660
+ );
1661
+ }
1662
+ if (error instanceof McpCallError) return new Error(`Playwright MCP: ${error.message}`);
1663
+ return error instanceof Error ? error : new Error(String(error));
1664
+ }
1665
+ function browserTools(offered, connections) {
1666
+ return offered.map((entry) => {
1667
+ const tool = {
1668
+ name: entry.name,
1669
+ description: entry.upstream.description,
1670
+ inputSchema: toolSchema(entry.upstream.inputSchema, entry.upstream.name),
1671
+ permission: entry.permission,
1672
+ readOnly: entry.readOnly,
1673
+ exclusive: EXCLUSIVE_PAGE,
1674
+ maxResultChars: MAX_RESULT_CHARS,
1675
+ preview: (args) => previewOf(entry.name, args),
1676
+ async execute(args, run2) {
1677
+ let result;
1678
+ try {
1679
+ result = await resultOf(
1680
+ await run2.attachment.callTool(entry.upstream.name, args, {
1681
+ signal: run2.signal,
1682
+ timeoutMs: CALL_TIMEOUT_MS
1683
+ }),
1684
+ run2
1685
+ );
1686
+ } catch (error) {
1687
+ throw explain(error);
1688
+ }
1689
+ if (!connections.takeReconnected(run2.bot.id)) return result;
1690
+ return {
1691
+ ...result,
1692
+ text: [RECONNECTED, ...result.text === void 0 ? [] : [result.text]].join("\n\n")
1693
+ };
1694
+ }
1695
+ };
1696
+ return tool;
1697
+ });
1698
+ }
1699
+
1700
+ // src/host/connector.ts
1701
+ var BROWSER_MIN_MEMORY_MIB = 3072;
1702
+ function createBrowserConnector(deps) {
1703
+ const connections = new BrowserConnections();
1704
+ return {
1705
+ id: BROWSER_CONNECTOR_ID,
1706
+ name: "Browser",
1707
+ description: {
1708
+ en: "The Google Chrome on the bot's desktop, which the bot drives with Playwright MCP in its VM (page snapshots, forms, screenshots). Needs the desktop.",
1709
+ ja: "\u30DC\u30C3\u30C8\u306E\u30C7\u30B9\u30AF\u30C8\u30C3\u30D7\u306E Google Chrome\u3002\u30DC\u30C3\u30C8\u306F VM \u306E\u4E2D\u306E Playwright MCP \u3067\u64CD\u4F5C\u3057\u307E\u3059\uFF08\u30DA\u30FC\u30B8\u306E\u30B9\u30CA\u30C3\u30D7\u30B7\u30E7\u30C3\u30C8\u3001\u30D5\u30A9\u30FC\u30E0\u3001\u30B9\u30AF\u30EA\u30FC\u30F3\u30B7\u30E7\u30C3\u30C8\uFF09\u3002\u30C7\u30B9\u30AF\u30C8\u30C3\u30D7\u304C\u5FC5\u8981\u3067\u3059\u3002"
1710
+ },
1711
+ sessions: "bot",
1712
+ minimumSpec: { memoryMiB: BROWSER_MIN_MEMORY_MIB },
1713
+ requires: [DESKTOP_CONNECTOR_ID],
1714
+ creationOption: "workstation",
1715
+ preparation: {
1716
+ ...createBrowserPreparation(deps),
1717
+ hint: {
1718
+ en: "The browser is prepared after the desktop; the first time can take a minute.",
1719
+ ja: "\u30D6\u30E9\u30A6\u30B6\u306F\u30C7\u30B9\u30AF\u30C8\u30C3\u30D7\u306E\u3042\u3068\u306B\u6E96\u5099\u3055\u308C\u307E\u3059\u3002\u521D\u56DE\u306F 1 \u5206\u307B\u3069\u304B\u304B\u308B\u3053\u3068\u304C\u3042\u308A\u307E\u3059\u3002"
1720
+ }
1721
+ },
1722
+ attachment: browserAttachment({ ...deps, connections }),
1723
+ tools: browserTools(offeredTools(deps.generated.tools), connections)
1724
+ };
1725
+ }
1726
+
1727
+ // src/index.ts
1728
+ var name = "bot-connector-browser";
1729
+ var BOT = "bot";
1730
+ var inject = ["bot"];
1731
+ function botOf(ctx) {
1732
+ const bot = ctx.get(BOT);
1733
+ if (bot === void 0) throw new Error(`the "${BOT}" service is not available; inject it`);
1734
+ return bot;
1735
+ }
1736
+ var VM = new URL("../vm/", import.meta.url);
1737
+ async function readMcpInstallation(directory = VM) {
1738
+ const read = async (path) => new Uint8Array(await readFile(new URL(path, directory)));
1739
+ return {
1740
+ packageJson: await read("mcp/package.json"),
1741
+ shrinkwrap: await read("mcp/npm-shrinkwrap.json"),
1742
+ script: await read("install-mcp.sh")
1743
+ };
1744
+ }
1745
+ async function apply(ctx) {
1746
+ const bot = botOf(ctx);
1747
+ const connector = createBrowserConnector({
1748
+ generated: GENERATED_SERVER,
1749
+ installation: await readMcpInstallation(),
1750
+ deadline: (ms) => AbortSignal.timeout(ms)
1751
+ });
1752
+ ctx.effect(() => bot.registerConnector(connector), "browser: connector");
1753
+ }
1754
+ export {
1755
+ BROWSER_CONNECTOR_ID,
1756
+ GENERATED_SERVER,
1757
+ apply,
1758
+ createBrowserConnector,
1759
+ inject,
1760
+ name,
1761
+ readMcpInstallation
1762
+ };