mcp-browser-dev-tools 0.1.0 → 0.2.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 +116 -347
- package/package.json +16 -2
- package/src/action-retry.mjs +50 -0
- package/src/browser-adapter.mjs +15 -4
- package/src/browser-requests.mjs +15 -0
- package/src/cdp-client.mjs +104 -10
- package/src/firefox-bidi-client.mjs +26 -3
- package/src/json-schema.mjs +99 -0
- package/src/mcp-server.mjs +35 -2014
- package/src/page-context.mjs +25 -1034
- package/src/page-script.mjs +1372 -0
- package/src/run-steps.mjs +510 -0
- package/src/run-tabs.mjs +291 -0
- package/src/screenshot-output.mjs +141 -0
- package/src/tool-results.mjs +34 -0
- package/src/tool-schemas.mjs +449 -0
- package/src/tools/action-tools.mjs +318 -0
- package/src/tools/browser-tools.mjs +221 -0
- package/src/tools/inspection-tools.mjs +287 -0
- package/src/tools/state-tools.mjs +327 -0
- package/src/top-level-await.mjs +260 -0
- package/src/wait-for.mjs +381 -71
package/src/mcp-server.mjs
CHANGED
|
@@ -1,26 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { actionTools } from "./tools/action-tools.mjs";
|
|
2
|
+
import { browserTools } from "./tools/browser-tools.mjs";
|
|
3
|
+
import { inspectionTools } from "./tools/inspection-tools.mjs";
|
|
4
|
+
import { stateTools } from "./tools/state-tools.mjs";
|
|
5
|
+
import { appendFile } from "node:fs/promises";
|
|
6
|
+
import { launchBrowser as launchLocalBrowser } from "./browser-launch-service.mjs";
|
|
2
7
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
writeFile,
|
|
9
|
-
} from "node:fs/promises";
|
|
10
|
-
import { tmpdir } from "node:os";
|
|
11
|
-
import path from "node:path";
|
|
12
|
-
|
|
13
|
-
import { encodeMessage, MessageBuffer } from "./json-rpc-stdio.mjs";
|
|
14
|
-
import { parseKeyCombo } from "./keyboard.mjs";
|
|
8
|
+
requestedBrowserFamily,
|
|
9
|
+
shouldCreateBrowserTab,
|
|
10
|
+
} from "./browser-requests.mjs";
|
|
11
|
+
import { MessageBuffer, encodeMessage } from "./json-rpc-stdio.mjs";
|
|
12
|
+
import { validateValue } from "./json-schema.mjs";
|
|
15
13
|
import { createLogger } from "./logger.mjs";
|
|
16
|
-
import {
|
|
17
|
-
launchBrowser as launchLocalBrowser,
|
|
18
|
-
supportedLaunchFamilies,
|
|
19
|
-
} from "./browser-launch-service.mjs";
|
|
20
14
|
import { PACKAGE_NAME, PACKAGE_VERSION } from "./package-info.mjs";
|
|
21
|
-
import {
|
|
15
|
+
import { StepRunner, runStepsTool, stepSchema } from "./run-steps.mjs";
|
|
16
|
+
import { TabRunner, runTabsTool } from "./run-tabs.mjs";
|
|
17
|
+
import { asToolResult } from "./tool-results.mjs";
|
|
22
18
|
|
|
23
19
|
const SERVER_NAME = PACKAGE_NAME;
|
|
20
|
+
|
|
24
21
|
const SERVER_VERSION = PACKAGE_VERSION;
|
|
25
22
|
|
|
26
23
|
function formatChunkPreview(chunk, limit = 160) {
|
|
@@ -51,762 +48,6 @@ function failure(id, code, message) {
|
|
|
51
48
|
};
|
|
52
49
|
}
|
|
53
50
|
|
|
54
|
-
function asToolResult(value) {
|
|
55
|
-
return {
|
|
56
|
-
content: [
|
|
57
|
-
{
|
|
58
|
-
type: "text",
|
|
59
|
-
text: JSON.stringify(value, null, 2),
|
|
60
|
-
},
|
|
61
|
-
],
|
|
62
|
-
structuredContent: value,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function asImageToolResult({ value, images }) {
|
|
67
|
-
return {
|
|
68
|
-
content: [
|
|
69
|
-
{
|
|
70
|
-
type: "text",
|
|
71
|
-
text: JSON.stringify(value, null, 2),
|
|
72
|
-
},
|
|
73
|
-
...images,
|
|
74
|
-
],
|
|
75
|
-
structuredContent: value,
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function emptyObjectSchema() {
|
|
80
|
-
return {
|
|
81
|
-
type: "object",
|
|
82
|
-
properties: {},
|
|
83
|
-
additionalProperties: false,
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function validateValue(path, value, schema) {
|
|
88
|
-
if (schema.type === "object") {
|
|
89
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
90
|
-
throw new Error(`${path} must be an object`);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const properties = schema.properties ?? {};
|
|
94
|
-
const required = schema.required ?? [];
|
|
95
|
-
for (const key of required) {
|
|
96
|
-
if (value[key] === undefined) {
|
|
97
|
-
throw new Error(`${path}.${key} is required`);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (schema.additionalProperties === false) {
|
|
102
|
-
for (const key of Object.keys(value)) {
|
|
103
|
-
if (!(key in properties)) {
|
|
104
|
-
throw new Error(`${path}.${key} is not allowed`);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
for (const [key, propertySchema] of Object.entries(properties)) {
|
|
110
|
-
if (value[key] !== undefined) {
|
|
111
|
-
validateValue(`${path}.${key}`, value[key], propertySchema);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (schema.type === "array") {
|
|
119
|
-
if (!Array.isArray(value)) {
|
|
120
|
-
throw new Error(`${path} must be an array`);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
if (schema.minItems !== undefined && value.length < schema.minItems) {
|
|
124
|
-
throw new Error(`${path} must have at least ${schema.minItems} items`);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if (schema.maxItems !== undefined && value.length > schema.maxItems) {
|
|
128
|
-
throw new Error(`${path} must have at most ${schema.maxItems} items`);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if (schema.items) {
|
|
132
|
-
value.forEach((item, index) => {
|
|
133
|
-
validateValue(`${path}[${index}]`, item, schema.items);
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
if (schema.type === "string") {
|
|
141
|
-
if (typeof value !== "string") {
|
|
142
|
-
throw new Error(`${path} must be a string`);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
if (schema.enum && !schema.enum.includes(value)) {
|
|
146
|
-
throw new Error(`${path} must be one of: ${schema.enum.join(", ")}`);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
if (schema.type === "boolean") {
|
|
153
|
-
if (typeof value !== "boolean") {
|
|
154
|
-
throw new Error(`${path} must be a boolean`);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
if (schema.type === "integer") {
|
|
161
|
-
if (!Number.isInteger(value)) {
|
|
162
|
-
throw new Error(`${path} must be an integer`);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
if (schema.minimum !== undefined && value < schema.minimum) {
|
|
166
|
-
throw new Error(`${path} must be >= ${schema.minimum}`);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
if (schema.maximum !== undefined && value > schema.maximum) {
|
|
170
|
-
throw new Error(`${path} must be <= ${schema.maximum}`);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
if (schema.type === "number") {
|
|
177
|
-
if (typeof value !== "number" || Number.isNaN(value)) {
|
|
178
|
-
throw new Error(`${path} must be a number`);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
if (schema.minimum !== undefined && value < schema.minimum) {
|
|
182
|
-
throw new Error(`${path} must be >= ${schema.minimum}`);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
function screenshotFormatsFor(browserFamily) {
|
|
188
|
-
return browserFamily === "firefox"
|
|
189
|
-
? ["png", "jpeg"]
|
|
190
|
-
: ["png", "jpeg", "webp"];
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
const SCREENSHOT_FILE_FORMATS = {
|
|
194
|
-
".png": "png",
|
|
195
|
-
".jpg": "jpeg",
|
|
196
|
-
".jpeg": "jpeg",
|
|
197
|
-
".webp": "webp",
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
function screenshotFileExtensions(browserFamily) {
|
|
201
|
-
const allowed = screenshotFormatsFor(browserFamily);
|
|
202
|
-
return Object.entries(SCREENSHOT_FILE_FORMATS)
|
|
203
|
-
.filter(([, format]) => allowed.includes(format))
|
|
204
|
-
.map(([extension]) => extension);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
// Only image extensions are accepted, so a screenshot path can never replace
|
|
208
|
-
// a config file or script.
|
|
209
|
-
function screenshotTarget(args, browserFamily) {
|
|
210
|
-
const output = args.output ?? (args.path === undefined ? "data" : "file");
|
|
211
|
-
if (output !== "file") {
|
|
212
|
-
if (args.path !== undefined || args.overwrite !== undefined) {
|
|
213
|
-
throw new Error(
|
|
214
|
-
`take_screenshot path and overwrite require output file, not ${output}`,
|
|
215
|
-
);
|
|
216
|
-
}
|
|
217
|
-
return { output, format: args.format ?? "png", filePath: null };
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
if (args.path === undefined) {
|
|
221
|
-
return { output, format: args.format ?? "png", filePath: null };
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
if (!path.isAbsolute(args.path)) {
|
|
225
|
-
throw new Error("take_screenshot path must be absolute");
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
const format = SCREENSHOT_FILE_FORMATS[path.extname(args.path).toLowerCase()];
|
|
229
|
-
if (!format || !screenshotFormatsFor(browserFamily).includes(format)) {
|
|
230
|
-
throw new Error(
|
|
231
|
-
`take_screenshot path must end with ${screenshotFileExtensions(browserFamily).join(", ")}`,
|
|
232
|
-
);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
if (args.format !== undefined && args.format !== format) {
|
|
236
|
-
throw new Error(
|
|
237
|
-
`take_screenshot format ${args.format} does not match the ${format} path extension`,
|
|
238
|
-
);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
return { output, format, filePath: args.path };
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
// Screenshots can show signed-in pages, so files are private to the user.
|
|
245
|
-
const SCREENSHOT_FILE_MODE = 0o600;
|
|
246
|
-
|
|
247
|
-
async function writeTempScreenshot(image, format) {
|
|
248
|
-
// mkdtemp makes a fresh 0700 directory, which other users on a shared /tmp
|
|
249
|
-
// cannot pre-create or read.
|
|
250
|
-
const dir = await mkdtemp(path.join(tmpdir(), "mcp-browser-dev-tools-"));
|
|
251
|
-
const filePath = path.join(
|
|
252
|
-
dir,
|
|
253
|
-
`screenshot.${format === "jpeg" ? "jpg" : format}`,
|
|
254
|
-
);
|
|
255
|
-
await writeFile(filePath, image, { flag: "wx", mode: SCREENSHOT_FILE_MODE });
|
|
256
|
-
return filePath;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
async function writeScreenshotFile(filePath, image, overwrite) {
|
|
260
|
-
await mkdir(path.dirname(filePath), { recursive: true });
|
|
261
|
-
if (!overwrite) {
|
|
262
|
-
// O_EXCL also refuses an existing symlink instead of following it.
|
|
263
|
-
try {
|
|
264
|
-
await writeFile(filePath, image, {
|
|
265
|
-
flag: "wx",
|
|
266
|
-
mode: SCREENSHOT_FILE_MODE,
|
|
267
|
-
});
|
|
268
|
-
} catch (error) {
|
|
269
|
-
if (error.code === "EEXIST") {
|
|
270
|
-
throw new Error(
|
|
271
|
-
`${filePath} already exists; pass overwrite: true to replace it`,
|
|
272
|
-
{ cause: error },
|
|
273
|
-
);
|
|
274
|
-
}
|
|
275
|
-
throw error;
|
|
276
|
-
}
|
|
277
|
-
return filePath;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
// Renaming a new file into place replaces a symlink at filePath rather
|
|
281
|
-
// than writing through it to a file without an image extension.
|
|
282
|
-
const tempPath = `${filePath}.${randomUUID()}.tmp`;
|
|
283
|
-
try {
|
|
284
|
-
await writeFile(tempPath, image, {
|
|
285
|
-
flag: "wx",
|
|
286
|
-
mode: SCREENSHOT_FILE_MODE,
|
|
287
|
-
});
|
|
288
|
-
await rename(tempPath, filePath);
|
|
289
|
-
} catch (error) {
|
|
290
|
-
await rm(tempPath, { force: true });
|
|
291
|
-
throw error;
|
|
292
|
-
}
|
|
293
|
-
return filePath;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
function sessionWithLimitSchema(description) {
|
|
297
|
-
return {
|
|
298
|
-
type: "object",
|
|
299
|
-
properties: {
|
|
300
|
-
sessionId: {
|
|
301
|
-
type: "string",
|
|
302
|
-
description: "Session id returned by attach_tab.",
|
|
303
|
-
},
|
|
304
|
-
limit: {
|
|
305
|
-
type: "integer",
|
|
306
|
-
minimum: 1,
|
|
307
|
-
description:
|
|
308
|
-
"Return the most recent N entries from the session buffer (default 50).",
|
|
309
|
-
},
|
|
310
|
-
},
|
|
311
|
-
required: ["sessionId"],
|
|
312
|
-
additionalProperties: false,
|
|
313
|
-
description,
|
|
314
|
-
};
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
const LOCATOR_DESCRIPTION =
|
|
318
|
-
'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.';
|
|
319
|
-
|
|
320
|
-
function selectorProperty() {
|
|
321
|
-
return {
|
|
322
|
-
type: "string",
|
|
323
|
-
description: LOCATOR_DESCRIPTION,
|
|
324
|
-
};
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
function sessionSchema(properties, required, description) {
|
|
328
|
-
return {
|
|
329
|
-
type: "object",
|
|
330
|
-
properties: {
|
|
331
|
-
sessionId: {
|
|
332
|
-
type: "string",
|
|
333
|
-
description: "Session id returned by attach_tab.",
|
|
334
|
-
},
|
|
335
|
-
...properties,
|
|
336
|
-
},
|
|
337
|
-
required: ["sessionId", ...required],
|
|
338
|
-
additionalProperties: false,
|
|
339
|
-
description,
|
|
340
|
-
};
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
function waitUntilProperty() {
|
|
344
|
-
return {
|
|
345
|
-
type: "string",
|
|
346
|
-
enum: ["none", "interactive", "complete"],
|
|
347
|
-
description:
|
|
348
|
-
"When to return: none returns once navigation starts, interactive after DOMContentLoaded, complete after the load event (default complete).",
|
|
349
|
-
};
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
function pageConditionProperties() {
|
|
353
|
-
return {
|
|
354
|
-
selector: selectorProperty(),
|
|
355
|
-
state: {
|
|
356
|
-
type: "string",
|
|
357
|
-
enum: ["present", "visible", "hidden"],
|
|
358
|
-
description:
|
|
359
|
-
"Selector state (default visible). present: in the DOM. hidden: absent or not visible. Requires selector.",
|
|
360
|
-
},
|
|
361
|
-
url: {
|
|
362
|
-
type: "string",
|
|
363
|
-
description: "The page URL equals this string exactly.",
|
|
364
|
-
},
|
|
365
|
-
urlIncludes: {
|
|
366
|
-
type: "string",
|
|
367
|
-
description: "The page URL contains this string.",
|
|
368
|
-
},
|
|
369
|
-
readyState: {
|
|
370
|
-
type: "string",
|
|
371
|
-
enum: ["interactive", "complete"],
|
|
372
|
-
description: "document.readyState has reached this state or later.",
|
|
373
|
-
},
|
|
374
|
-
textEquals: {
|
|
375
|
-
type: "string",
|
|
376
|
-
description:
|
|
377
|
-
"The selector's visible text equals this string, comparing with whitespace collapsed; only the first 400 characters of the element's text are read, so textEquals never matches longer text. Requires selector; not with state hidden.",
|
|
378
|
-
},
|
|
379
|
-
textIncludes: {
|
|
380
|
-
type: "string",
|
|
381
|
-
description:
|
|
382
|
-
"The selector's visible text contains this string, comparing with whitespace collapsed; only the first 400 characters of the element's text are searched. Requires selector; not with state hidden.",
|
|
383
|
-
},
|
|
384
|
-
};
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
function waitForInputSchema() {
|
|
388
|
-
return {
|
|
389
|
-
type: "object",
|
|
390
|
-
properties: {
|
|
391
|
-
sessionId: {
|
|
392
|
-
type: "string",
|
|
393
|
-
description: "Session id returned by attach_tab.",
|
|
394
|
-
},
|
|
395
|
-
...pageConditionProperties(),
|
|
396
|
-
timeoutMs: {
|
|
397
|
-
type: "integer",
|
|
398
|
-
minimum: 1,
|
|
399
|
-
description: "How long to wait before failing (default 10000).",
|
|
400
|
-
},
|
|
401
|
-
pollIntervalMs: {
|
|
402
|
-
type: "integer",
|
|
403
|
-
minimum: 1,
|
|
404
|
-
description: "Delay between checks (default 100).",
|
|
405
|
-
},
|
|
406
|
-
},
|
|
407
|
-
required: ["sessionId"],
|
|
408
|
-
additionalProperties: false,
|
|
409
|
-
};
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
const MAX_RUN_STEPS = 50;
|
|
413
|
-
const MAX_STEP_DEPTH = 4;
|
|
414
|
-
const MAX_SLEEP_MS = 30_000;
|
|
415
|
-
|
|
416
|
-
function sleepStepSchema() {
|
|
417
|
-
return {
|
|
418
|
-
type: "object",
|
|
419
|
-
properties: {
|
|
420
|
-
ms: {
|
|
421
|
-
type: "integer",
|
|
422
|
-
minimum: 0,
|
|
423
|
-
maximum: MAX_SLEEP_MS,
|
|
424
|
-
description: `Milliseconds to wait (at most ${MAX_SLEEP_MS}).`,
|
|
425
|
-
},
|
|
426
|
-
},
|
|
427
|
-
required: ["ms"],
|
|
428
|
-
additionalProperties: false,
|
|
429
|
-
};
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
function ifStepSchema() {
|
|
433
|
-
const condition = {
|
|
434
|
-
type: "object",
|
|
435
|
-
properties: pageConditionProperties(),
|
|
436
|
-
additionalProperties: false,
|
|
437
|
-
};
|
|
438
|
-
const steps = {
|
|
439
|
-
type: "array",
|
|
440
|
-
items: { type: "object" },
|
|
441
|
-
};
|
|
442
|
-
return {
|
|
443
|
-
type: "object",
|
|
444
|
-
properties: {
|
|
445
|
-
condition,
|
|
446
|
-
then: steps,
|
|
447
|
-
elseIf: {
|
|
448
|
-
type: "array",
|
|
449
|
-
items: {
|
|
450
|
-
type: "object",
|
|
451
|
-
properties: { condition, then: steps },
|
|
452
|
-
required: ["condition"],
|
|
453
|
-
additionalProperties: false,
|
|
454
|
-
},
|
|
455
|
-
},
|
|
456
|
-
else: steps,
|
|
457
|
-
},
|
|
458
|
-
required: ["condition"],
|
|
459
|
-
additionalProperties: false,
|
|
460
|
-
};
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
function stepSchema(stepTools) {
|
|
464
|
-
return {
|
|
465
|
-
type: "object",
|
|
466
|
-
properties: {
|
|
467
|
-
tool: {
|
|
468
|
-
type: "string",
|
|
469
|
-
enum: ["sleep", "if", ...stepTools],
|
|
470
|
-
description:
|
|
471
|
-
"A tool that takes sessionId, sleep to pause, or if to branch.",
|
|
472
|
-
},
|
|
473
|
-
arguments: {
|
|
474
|
-
type: "object",
|
|
475
|
-
description:
|
|
476
|
-
"That tool's arguments without sessionId (default {}). sleep takes { ms }. if takes { condition, then, elseIf, else }: each condition has the wait_for condition fields, checked once without waiting, all of which must hold; then and else are step lists; elseIf is a list of { condition, then } checked in order after condition, and the first condition that holds runs its then.",
|
|
477
|
-
},
|
|
478
|
-
},
|
|
479
|
-
required: ["tool"],
|
|
480
|
-
additionalProperties: false,
|
|
481
|
-
};
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
function runStepsInputSchema(stepTools) {
|
|
485
|
-
return {
|
|
486
|
-
type: "object",
|
|
487
|
-
properties: {
|
|
488
|
-
sessionId: {
|
|
489
|
-
type: "string",
|
|
490
|
-
description:
|
|
491
|
-
"Session id returned by attach_tab. Every step runs on this session.",
|
|
492
|
-
},
|
|
493
|
-
steps: {
|
|
494
|
-
type: "array",
|
|
495
|
-
minItems: 1,
|
|
496
|
-
maxItems: MAX_RUN_STEPS,
|
|
497
|
-
description: `Steps to run in order (at most ${MAX_RUN_STEPS}, counting steps inside if branches; if nests at most ${MAX_STEP_DEPTH} deep).`,
|
|
498
|
-
items: stepSchema(stepTools),
|
|
499
|
-
},
|
|
500
|
-
continueOnError: {
|
|
501
|
-
type: "boolean",
|
|
502
|
-
description:
|
|
503
|
-
"Run the remaining steps after a step fails (default false: stop at the first failure).",
|
|
504
|
-
},
|
|
505
|
-
},
|
|
506
|
-
required: ["sessionId", "steps"],
|
|
507
|
-
additionalProperties: false,
|
|
508
|
-
};
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
function moveScreenshotImage(screenshot, images) {
|
|
512
|
-
if (typeof screenshot?.data !== "string") {
|
|
513
|
-
return screenshot;
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
const { data, ...metadata } = screenshot;
|
|
517
|
-
images.push({ type: "image", data, mimeType: screenshot.mimeType });
|
|
518
|
-
return { ...metadata, image: images.length };
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
// Moves screenshot data out of a step result so the client receives it as
|
|
522
|
-
// image content, leaving `image` (1-based position among the images) behind.
|
|
523
|
-
function extractStepImages(tool, result, images) {
|
|
524
|
-
if (tool === "take_screenshot") {
|
|
525
|
-
return moveScreenshotImage(result, images);
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
if (tool === "capture_debug_report" && result?.screenshot) {
|
|
529
|
-
return {
|
|
530
|
-
...result,
|
|
531
|
-
screenshot: moveScreenshotImage(result.screenshot, images),
|
|
532
|
-
};
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
return result;
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
function parseSessionSnapshot(text) {
|
|
539
|
-
let snapshot;
|
|
540
|
-
try {
|
|
541
|
-
snapshot = JSON.parse(text);
|
|
542
|
-
} catch {
|
|
543
|
-
throw new Error("restore_session_snapshot snapshot must be valid JSON");
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
if (!snapshot || typeof snapshot !== "object") {
|
|
547
|
-
throw new Error(
|
|
548
|
-
"restore_session_snapshot snapshot must decode to an object",
|
|
549
|
-
);
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
return snapshot;
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
function compareSessionsSchema(properties, required) {
|
|
556
|
-
return {
|
|
557
|
-
type: "object",
|
|
558
|
-
properties: {
|
|
559
|
-
sessionIdA: {
|
|
560
|
-
type: "string",
|
|
561
|
-
description: "Session id returned by attach_tab.",
|
|
562
|
-
},
|
|
563
|
-
sessionIdB: {
|
|
564
|
-
type: "string",
|
|
565
|
-
description: "Session id returned by attach_tab.",
|
|
566
|
-
},
|
|
567
|
-
...properties,
|
|
568
|
-
},
|
|
569
|
-
required: ["sessionIdA", "sessionIdB", ...required],
|
|
570
|
-
additionalProperties: false,
|
|
571
|
-
};
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
function storageInputSchema() {
|
|
575
|
-
return {
|
|
576
|
-
type: "object",
|
|
577
|
-
properties: {
|
|
578
|
-
sessionId: {
|
|
579
|
-
type: "string",
|
|
580
|
-
description: "Session id returned by attach_tab.",
|
|
581
|
-
},
|
|
582
|
-
area: {
|
|
583
|
-
type: "string",
|
|
584
|
-
enum: ["all", "localStorage", "sessionStorage"],
|
|
585
|
-
description: "Which storage to return (default all).",
|
|
586
|
-
},
|
|
587
|
-
},
|
|
588
|
-
required: ["sessionId"],
|
|
589
|
-
additionalProperties: false,
|
|
590
|
-
};
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
function captureDebugReportInputSchema(browserFamily) {
|
|
594
|
-
return {
|
|
595
|
-
type: "object",
|
|
596
|
-
properties: {
|
|
597
|
-
sessionId: {
|
|
598
|
-
type: "string",
|
|
599
|
-
description: "Session id returned by attach_tab.",
|
|
600
|
-
},
|
|
601
|
-
consoleLimit: {
|
|
602
|
-
type: "integer",
|
|
603
|
-
minimum: 1,
|
|
604
|
-
description: "Most recent console entries to include (default 20).",
|
|
605
|
-
},
|
|
606
|
-
networkLimit: {
|
|
607
|
-
type: "integer",
|
|
608
|
-
minimum: 1,
|
|
609
|
-
description: "Most recent network requests to include (default 20).",
|
|
610
|
-
},
|
|
611
|
-
includeScreenshot: {
|
|
612
|
-
type: "boolean",
|
|
613
|
-
description: "Include a viewport screenshot (default true).",
|
|
614
|
-
},
|
|
615
|
-
screenshotFormat: {
|
|
616
|
-
type: "string",
|
|
617
|
-
enum: screenshotFormatsFor(browserFamily),
|
|
618
|
-
description: "Screenshot image format (default png).",
|
|
619
|
-
},
|
|
620
|
-
},
|
|
621
|
-
required: ["sessionId"],
|
|
622
|
-
additionalProperties: false,
|
|
623
|
-
};
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
function restoreSessionSnapshotInputSchema() {
|
|
627
|
-
return {
|
|
628
|
-
type: "object",
|
|
629
|
-
properties: {
|
|
630
|
-
sessionId: {
|
|
631
|
-
type: "string",
|
|
632
|
-
description: "Session id returned by attach_tab.",
|
|
633
|
-
},
|
|
634
|
-
snapshot: {
|
|
635
|
-
type: "string",
|
|
636
|
-
description:
|
|
637
|
-
"The JSON output of capture_session_snapshot, as a string. Only entries for the current page origin are restored.",
|
|
638
|
-
},
|
|
639
|
-
clearStorage: {
|
|
640
|
-
type: "boolean",
|
|
641
|
-
description:
|
|
642
|
-
"Clear localStorage and sessionStorage before restoring (default false).",
|
|
643
|
-
},
|
|
644
|
-
},
|
|
645
|
-
required: ["sessionId", "snapshot"],
|
|
646
|
-
additionalProperties: false,
|
|
647
|
-
};
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
function newTabInputSchema(browserFamily) {
|
|
651
|
-
const properties = {
|
|
652
|
-
url: {
|
|
653
|
-
type: "string",
|
|
654
|
-
description: "URL to open (default about:blank).",
|
|
655
|
-
},
|
|
656
|
-
};
|
|
657
|
-
const required = [];
|
|
658
|
-
|
|
659
|
-
if (browserFamily === "auto") {
|
|
660
|
-
properties.browserFamily = {
|
|
661
|
-
type: "string",
|
|
662
|
-
enum: ["chromium", "firefox"],
|
|
663
|
-
description: "Browser to open the tab in.",
|
|
664
|
-
};
|
|
665
|
-
required.push("browserFamily");
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
return {
|
|
669
|
-
type: "object",
|
|
670
|
-
properties,
|
|
671
|
-
required,
|
|
672
|
-
additionalProperties: false,
|
|
673
|
-
};
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
function unsafeArgsProperty() {
|
|
677
|
-
return {
|
|
678
|
-
type: "array",
|
|
679
|
-
items: {
|
|
680
|
-
type: "string",
|
|
681
|
-
},
|
|
682
|
-
description:
|
|
683
|
-
"Extra browser command-line flags, each starting with -. Flags that conflict with broker-managed launch options (debugging port, address, profile) are rejected.",
|
|
684
|
-
};
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
function launchBrowserInputSchema(browserFamily, enableUnsafeLaunchArgs) {
|
|
688
|
-
const properties = {
|
|
689
|
-
url: {
|
|
690
|
-
type: "string",
|
|
691
|
-
description: "URL to open in the launched browser (default about:blank).",
|
|
692
|
-
},
|
|
693
|
-
browserFamily: {
|
|
694
|
-
type: "string",
|
|
695
|
-
enum: supportedLaunchFamilies(browserFamily),
|
|
696
|
-
description:
|
|
697
|
-
"Browser to launch. Required when the broker runs in auto mode.",
|
|
698
|
-
},
|
|
699
|
-
port: {
|
|
700
|
-
type: "integer",
|
|
701
|
-
minimum: 1,
|
|
702
|
-
description:
|
|
703
|
-
"Remote debugging port to launch on (default: the port of the configured browser endpoint, usually 9222).",
|
|
704
|
-
},
|
|
705
|
-
address: {
|
|
706
|
-
type: "string",
|
|
707
|
-
description:
|
|
708
|
-
"Remote debugging bind address for Chromium and Edge (ignored for Firefox). Must be loopback unless MCP_BROWSER_ALLOW_REMOTE_ENDPOINTS=1.",
|
|
709
|
-
},
|
|
710
|
-
userDataDir: {
|
|
711
|
-
type: "string",
|
|
712
|
-
description:
|
|
713
|
-
"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.",
|
|
714
|
-
},
|
|
715
|
-
waitMs: {
|
|
716
|
-
type: "integer",
|
|
717
|
-
minimum: 0,
|
|
718
|
-
description:
|
|
719
|
-
"How long to wait for the debugging endpoint to answer after launch (default 5000).",
|
|
720
|
-
},
|
|
721
|
-
skipDoctor: {
|
|
722
|
-
type: "boolean",
|
|
723
|
-
description:
|
|
724
|
-
"Return right after spawning the browser, without waiting for the endpoint or running the doctor report (default false).",
|
|
725
|
-
},
|
|
726
|
-
};
|
|
727
|
-
if (enableUnsafeLaunchArgs) {
|
|
728
|
-
properties.unsafeArgs = unsafeArgsProperty();
|
|
729
|
-
}
|
|
730
|
-
const required = browserFamily === "auto" ? ["browserFamily"] : [];
|
|
731
|
-
|
|
732
|
-
return {
|
|
733
|
-
type: "object",
|
|
734
|
-
properties,
|
|
735
|
-
required,
|
|
736
|
-
additionalProperties: false,
|
|
737
|
-
};
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
function ensureBrowserInputSchema(browserFamily, enableUnsafeLaunchArgs) {
|
|
741
|
-
const properties = {
|
|
742
|
-
browserFamily: {
|
|
743
|
-
type: "string",
|
|
744
|
-
enum: supportedLaunchFamilies(browserFamily),
|
|
745
|
-
description:
|
|
746
|
-
"Browser to check or launch. Required when the broker runs in auto mode.",
|
|
747
|
-
},
|
|
748
|
-
url: {
|
|
749
|
-
type: "string",
|
|
750
|
-
description: "URL to open in a new tab once the browser is reachable.",
|
|
751
|
-
},
|
|
752
|
-
createTab: {
|
|
753
|
-
type: "boolean",
|
|
754
|
-
description:
|
|
755
|
-
"Open a tab after the browser is reachable (default: true when url is given).",
|
|
756
|
-
},
|
|
757
|
-
launchIfMissing: {
|
|
758
|
-
type: "boolean",
|
|
759
|
-
description:
|
|
760
|
-
"Launch a browser when none is reachable (default true). When false and none is reachable, return the status without launching or opening a tab.",
|
|
761
|
-
},
|
|
762
|
-
port: {
|
|
763
|
-
type: "integer",
|
|
764
|
-
minimum: 1,
|
|
765
|
-
description:
|
|
766
|
-
"Remote debugging port to launch on (default: the port of the configured browser endpoint, usually 9222).",
|
|
767
|
-
},
|
|
768
|
-
address: {
|
|
769
|
-
type: "string",
|
|
770
|
-
description:
|
|
771
|
-
"Remote debugging bind address for Chromium and Edge (ignored for Firefox). Must be loopback unless MCP_BROWSER_ALLOW_REMOTE_ENDPOINTS=1.",
|
|
772
|
-
},
|
|
773
|
-
userDataDir: {
|
|
774
|
-
type: "string",
|
|
775
|
-
description:
|
|
776
|
-
"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.",
|
|
777
|
-
},
|
|
778
|
-
waitMs: {
|
|
779
|
-
type: "integer",
|
|
780
|
-
minimum: 0,
|
|
781
|
-
description:
|
|
782
|
-
"How long to wait for the debugging endpoint to answer after launch (default 5000).",
|
|
783
|
-
},
|
|
784
|
-
skipDoctor: {
|
|
785
|
-
type: "boolean",
|
|
786
|
-
description:
|
|
787
|
-
"Return right after spawning the browser, without waiting for the endpoint or running the doctor report (default false).",
|
|
788
|
-
},
|
|
789
|
-
};
|
|
790
|
-
if (enableUnsafeLaunchArgs) {
|
|
791
|
-
properties.unsafeArgs = unsafeArgsProperty();
|
|
792
|
-
}
|
|
793
|
-
|
|
794
|
-
return {
|
|
795
|
-
type: "object",
|
|
796
|
-
properties,
|
|
797
|
-
required: browserFamily === "auto" ? ["browserFamily"] : [],
|
|
798
|
-
additionalProperties: false,
|
|
799
|
-
};
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
function requestedBrowserFamily(configuredFamily, requestedFamily) {
|
|
803
|
-
if (requestedFamily) {
|
|
804
|
-
return requestedFamily;
|
|
805
|
-
}
|
|
806
|
-
|
|
807
|
-
return configuredFamily === "auto" ? null : configuredFamily;
|
|
808
|
-
}
|
|
809
|
-
|
|
810
51
|
function isRequestedBrowserAvailable(
|
|
811
52
|
status,
|
|
812
53
|
configuredFamily,
|
|
@@ -823,6 +64,7 @@ function isRequestedBrowserAvailable(
|
|
|
823
64
|
}
|
|
824
65
|
|
|
825
66
|
const STATUS_PROBE_ATTEMPTS = 3;
|
|
67
|
+
|
|
826
68
|
const LAUNCH_GRACE_MS = 30_000;
|
|
827
69
|
|
|
828
70
|
function sleep(ms) {
|
|
@@ -831,59 +73,6 @@ function sleep(ms) {
|
|
|
831
73
|
});
|
|
832
74
|
}
|
|
833
75
|
|
|
834
|
-
function shouldCreateBrowserTab(args) {
|
|
835
|
-
if (args.createTab !== undefined) {
|
|
836
|
-
return args.createTab;
|
|
837
|
-
}
|
|
838
|
-
|
|
839
|
-
return typeof args.url === "string" && args.url.trim() !== "";
|
|
840
|
-
}
|
|
841
|
-
|
|
842
|
-
function sameValue(left, right) {
|
|
843
|
-
return JSON.stringify(left) === JSON.stringify(right);
|
|
844
|
-
}
|
|
845
|
-
|
|
846
|
-
function compareField(left, right) {
|
|
847
|
-
return {
|
|
848
|
-
equal: sameValue(left, right),
|
|
849
|
-
a: left,
|
|
850
|
-
b: right,
|
|
851
|
-
};
|
|
852
|
-
}
|
|
853
|
-
|
|
854
|
-
function summarizeComparablePageState(page = {}) {
|
|
855
|
-
return {
|
|
856
|
-
browserFamily: page.browserFamily ?? null,
|
|
857
|
-
url: page.url ?? null,
|
|
858
|
-
title: page.title ?? null,
|
|
859
|
-
readyState: page.readyState ?? null,
|
|
860
|
-
visibilityState: page.visibilityState ?? null,
|
|
861
|
-
viewport: page.viewport ?? null,
|
|
862
|
-
scroll: page.scroll ?? null,
|
|
863
|
-
};
|
|
864
|
-
}
|
|
865
|
-
|
|
866
|
-
function summarizeComparableElement(result = {}) {
|
|
867
|
-
if (!result.found || !result.node) {
|
|
868
|
-
return {
|
|
869
|
-
found: false,
|
|
870
|
-
selector: result.selector ?? null,
|
|
871
|
-
error: result.error ?? null,
|
|
872
|
-
};
|
|
873
|
-
}
|
|
874
|
-
|
|
875
|
-
return {
|
|
876
|
-
found: true,
|
|
877
|
-
selector: result.selector ?? null,
|
|
878
|
-
tagName: result.node.tagName ?? null,
|
|
879
|
-
accessibleName: result.node.accessibleName ?? null,
|
|
880
|
-
role: result.node.role ?? null,
|
|
881
|
-
visible: result.node.visible ?? null,
|
|
882
|
-
disabled: result.node.disabled ?? null,
|
|
883
|
-
textContent: result.node.textContent ?? null,
|
|
884
|
-
};
|
|
885
|
-
}
|
|
886
|
-
|
|
887
76
|
export class McpBrowserDevToolsServer {
|
|
888
77
|
constructor({
|
|
889
78
|
config,
|
|
@@ -1029,1201 +218,33 @@ export class McpBrowserDevToolsServer {
|
|
|
1029
218
|
};
|
|
1030
219
|
}
|
|
1031
220
|
|
|
1032
|
-
async takeScreenshot(args) {
|
|
1033
|
-
const { output, format, filePath } = screenshotTarget(
|
|
1034
|
-
args,
|
|
1035
|
-
this.config.browserFamily,
|
|
1036
|
-
);
|
|
1037
|
-
const screenshot = await this.browserAdapter.takeScreenshot(
|
|
1038
|
-
args.sessionId,
|
|
1039
|
-
format,
|
|
1040
|
-
{
|
|
1041
|
-
selector: args.selector,
|
|
1042
|
-
},
|
|
1043
|
-
);
|
|
1044
|
-
if (output !== "file" || screenshot?.found === false) {
|
|
1045
|
-
return screenshot;
|
|
1046
|
-
}
|
|
1047
|
-
|
|
1048
|
-
if (typeof screenshot?.data !== "string") {
|
|
1049
|
-
throw new Error("The browser returned no screenshot data");
|
|
1050
|
-
}
|
|
1051
|
-
|
|
1052
|
-
const { data, ...metadata } = screenshot;
|
|
1053
|
-
const image = Buffer.from(data, "base64");
|
|
1054
|
-
const savedPath = filePath
|
|
1055
|
-
? await writeScreenshotFile(filePath, image, args.overwrite)
|
|
1056
|
-
: await writeTempScreenshot(image, format);
|
|
1057
|
-
return { ...metadata, path: savedPath };
|
|
1058
|
-
}
|
|
1059
|
-
|
|
1060
|
-
prepareSteps(steps, context, pathPrefix, depth) {
|
|
1061
|
-
return steps.map((step, index) => {
|
|
1062
|
-
const stepPath = `${pathPrefix}[${index}]`;
|
|
1063
|
-
validateValue(stepPath, step, this.stepSchema);
|
|
1064
|
-
context.count += 1;
|
|
1065
|
-
if (context.count > MAX_RUN_STEPS) {
|
|
1066
|
-
throw new Error(
|
|
1067
|
-
`run_steps allows at most ${MAX_RUN_STEPS} steps, counting steps inside if branches`,
|
|
1068
|
-
);
|
|
1069
|
-
}
|
|
1070
|
-
|
|
1071
|
-
const path = `${stepPath}.arguments`;
|
|
1072
|
-
const stepArgs = step.arguments ?? {};
|
|
1073
|
-
if (step.tool === "sleep") {
|
|
1074
|
-
validateValue(path, stepArgs, sleepStepSchema());
|
|
1075
|
-
return { tool: step.tool, args: stepArgs };
|
|
1076
|
-
}
|
|
1077
|
-
|
|
1078
|
-
if (step.tool === "if") {
|
|
1079
|
-
if (depth >= MAX_STEP_DEPTH) {
|
|
1080
|
-
throw new Error(
|
|
1081
|
-
`${path} nests if deeper than ${MAX_STEP_DEPTH} levels`,
|
|
1082
|
-
);
|
|
1083
|
-
}
|
|
1084
|
-
validateValue(path, stepArgs, ifStepSchema());
|
|
1085
|
-
const prepareBranch = (branch, branchPath) => ({
|
|
1086
|
-
condition: normalizeWaitForOptions(
|
|
1087
|
-
branch.condition,
|
|
1088
|
-
`${branchPath}.condition`,
|
|
1089
|
-
),
|
|
1090
|
-
steps: this.prepareSteps(
|
|
1091
|
-
branch.then ?? [],
|
|
1092
|
-
context,
|
|
1093
|
-
`${branchPath}.then`,
|
|
1094
|
-
depth + 1,
|
|
1095
|
-
),
|
|
1096
|
-
});
|
|
1097
|
-
return {
|
|
1098
|
-
tool: step.tool,
|
|
1099
|
-
branches: [
|
|
1100
|
-
{ name: "then", ...prepareBranch(stepArgs, path) },
|
|
1101
|
-
...(stepArgs.elseIf ?? []).map((branch, branchIndex) => ({
|
|
1102
|
-
name: `elseIf[${branchIndex}]`,
|
|
1103
|
-
...prepareBranch(branch, `${path}.elseIf[${branchIndex}]`),
|
|
1104
|
-
})),
|
|
1105
|
-
],
|
|
1106
|
-
else: this.prepareSteps(
|
|
1107
|
-
stepArgs.else ?? [],
|
|
1108
|
-
context,
|
|
1109
|
-
`${path}.else`,
|
|
1110
|
-
depth + 1,
|
|
1111
|
-
),
|
|
1112
|
-
};
|
|
1113
|
-
}
|
|
1114
|
-
|
|
1115
|
-
if (stepArgs.sessionId !== undefined) {
|
|
1116
|
-
throw new Error(
|
|
1117
|
-
`${path}.sessionId is not allowed; run_steps passes its own sessionId`,
|
|
1118
|
-
);
|
|
1119
|
-
}
|
|
1120
|
-
|
|
1121
|
-
const toolArgs = { ...stepArgs, sessionId: context.sessionId };
|
|
1122
|
-
const tool = this.tools.get(step.tool);
|
|
1123
|
-
validateValue(path, toolArgs, tool.definition.inputSchema);
|
|
1124
|
-
tool.validate?.(toolArgs);
|
|
1125
|
-
return { tool: step.tool, args: toolArgs };
|
|
1126
|
-
});
|
|
1127
|
-
}
|
|
1128
|
-
|
|
1129
|
-
async checkStepCondition(condition, context) {
|
|
1130
|
-
const check = await checkPageCondition({
|
|
1131
|
-
getPageState: () => this.browserAdapter.getPageState(context.sessionId),
|
|
1132
|
-
inspectElement: (selector) =>
|
|
1133
|
-
this.browserAdapter.inspectElement(context.sessionId, selector),
|
|
1134
|
-
normalized: condition,
|
|
1135
|
-
});
|
|
1136
|
-
const observed = {};
|
|
1137
|
-
if (check.page) {
|
|
1138
|
-
observed.url = check.page.url ?? null;
|
|
1139
|
-
observed.readyState = check.page.readyState ?? null;
|
|
1140
|
-
}
|
|
1141
|
-
if (condition.selector) {
|
|
1142
|
-
observed.found = Boolean(check.element?.found);
|
|
1143
|
-
observed.visible = check.element?.node?.visible === true;
|
|
1144
|
-
if (condition.textEquals !== null || condition.textIncludes !== null) {
|
|
1145
|
-
observed.text = check.text;
|
|
1146
|
-
}
|
|
1147
|
-
}
|
|
1148
|
-
return { matched: check.matched, observed };
|
|
1149
|
-
}
|
|
1150
|
-
|
|
1151
|
-
// Checks the then and elseIf conditions in order and runs the first branch
|
|
1152
|
-
// whose condition holds, or else when none does.
|
|
1153
|
-
async runIfStep(step, context) {
|
|
1154
|
-
const checked = [];
|
|
1155
|
-
let selected = null;
|
|
1156
|
-
for (const branch of step.branches) {
|
|
1157
|
-
const { matched, observed } = await this.checkStepCondition(
|
|
1158
|
-
branch.condition,
|
|
1159
|
-
context,
|
|
1160
|
-
);
|
|
1161
|
-
checked.push({ branch: branch.name, matched, observed });
|
|
1162
|
-
if (matched) {
|
|
1163
|
-
selected = branch;
|
|
1164
|
-
break;
|
|
1165
|
-
}
|
|
1166
|
-
}
|
|
1167
|
-
|
|
1168
|
-
const steps = await this.executeSteps(
|
|
1169
|
-
selected ? selected.steps : step.else,
|
|
1170
|
-
context,
|
|
1171
|
-
);
|
|
1172
|
-
return {
|
|
1173
|
-
ok: steps.every((result) => result.ok),
|
|
1174
|
-
result: {
|
|
1175
|
-
matched: selected !== null,
|
|
1176
|
-
branch: selected ? selected.name : "else",
|
|
1177
|
-
checked,
|
|
1178
|
-
steps,
|
|
1179
|
-
},
|
|
1180
|
-
};
|
|
1181
|
-
}
|
|
1182
|
-
|
|
1183
|
-
async runStep(step, context) {
|
|
1184
|
-
if (step.tool === "if") {
|
|
1185
|
-
return this.runIfStep(step, context);
|
|
1186
|
-
}
|
|
1187
|
-
|
|
1188
|
-
let result;
|
|
1189
|
-
if (step.tool === "sleep") {
|
|
1190
|
-
await sleep(step.args.ms);
|
|
1191
|
-
result = { sleptMs: step.args.ms };
|
|
1192
|
-
} else {
|
|
1193
|
-
result = await this.tools.get(step.tool).handler(step.args);
|
|
1194
|
-
}
|
|
1195
|
-
|
|
1196
|
-
const entry = {
|
|
1197
|
-
ok: true,
|
|
1198
|
-
result: extractStepImages(step.tool, result, context.images),
|
|
1199
|
-
};
|
|
1200
|
-
// Actions report a missing element as found: false instead of throwing;
|
|
1201
|
-
// later steps usually depend on it, so treat it as a failure.
|
|
1202
|
-
// inspect_element may be checking that something is gone.
|
|
1203
|
-
if (result?.found === false && step.tool !== "inspect_element") {
|
|
1204
|
-
entry.ok = false;
|
|
1205
|
-
entry.error =
|
|
1206
|
-
result.error ?? `No element matches selector ${step.args.selector}`;
|
|
1207
|
-
}
|
|
1208
|
-
return entry;
|
|
1209
|
-
}
|
|
1210
|
-
|
|
1211
|
-
async executeSteps(steps, context) {
|
|
1212
|
-
const results = [];
|
|
1213
|
-
for (const [index, step] of steps.entries()) {
|
|
1214
|
-
const startedAt = Date.now();
|
|
1215
|
-
let entry;
|
|
1216
|
-
try {
|
|
1217
|
-
entry = await this.runStep(step, context);
|
|
1218
|
-
} catch (error) {
|
|
1219
|
-
entry = { ok: false, error: error.message };
|
|
1220
|
-
}
|
|
1221
|
-
|
|
1222
|
-
results.push({
|
|
1223
|
-
index,
|
|
1224
|
-
tool: step.tool,
|
|
1225
|
-
durationMs: Date.now() - startedAt,
|
|
1226
|
-
...entry,
|
|
1227
|
-
});
|
|
1228
|
-
if (!entry.ok && !context.continueOnError) {
|
|
1229
|
-
break;
|
|
1230
|
-
}
|
|
1231
|
-
}
|
|
1232
|
-
return results;
|
|
1233
|
-
}
|
|
1234
|
-
|
|
1235
|
-
async runSteps(args) {
|
|
1236
|
-
const context = {
|
|
1237
|
-
sessionId: args.sessionId,
|
|
1238
|
-
continueOnError: args.continueOnError === true,
|
|
1239
|
-
images: [],
|
|
1240
|
-
count: 0,
|
|
1241
|
-
};
|
|
1242
|
-
// Validate every step, including both branches of each if, first, so a
|
|
1243
|
-
// typo in a late step does not leave the page half-changed.
|
|
1244
|
-
const steps = this.prepareSteps(args.steps, context, "arguments.steps", 0);
|
|
1245
|
-
const results = await this.executeSteps(steps, context);
|
|
1246
|
-
|
|
1247
|
-
return {
|
|
1248
|
-
value: {
|
|
1249
|
-
sessionId: args.sessionId,
|
|
1250
|
-
ok:
|
|
1251
|
-
results.length === steps.length &&
|
|
1252
|
-
results.every((result) => result.ok),
|
|
1253
|
-
ranSteps: results.length,
|
|
1254
|
-
skippedSteps: steps.length - results.length,
|
|
1255
|
-
steps: results,
|
|
1256
|
-
},
|
|
1257
|
-
images: context.images,
|
|
1258
|
-
};
|
|
1259
|
-
}
|
|
1260
|
-
|
|
1261
221
|
createTools() {
|
|
1262
222
|
const tools = [
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
name: "browser_status",
|
|
1268
|
-
description:
|
|
1269
|
-
"Report whether the configured browser endpoint is reachable and how many active sessions are attached.",
|
|
1270
|
-
inputSchema: emptyObjectSchema(),
|
|
1271
|
-
},
|
|
1272
|
-
handler: async () => ({
|
|
1273
|
-
serverName: SERVER_NAME,
|
|
1274
|
-
serverVersion: SERVER_VERSION,
|
|
1275
|
-
...(await this.browserAdapter.getBrowserStatus()),
|
|
1276
|
-
}),
|
|
1277
|
-
},
|
|
1278
|
-
],
|
|
1279
|
-
[
|
|
1280
|
-
"list_tabs",
|
|
1281
|
-
{
|
|
1282
|
-
definition: {
|
|
1283
|
-
name: "list_tabs",
|
|
1284
|
-
description:
|
|
1285
|
-
"List inspectable page targets exposed by the configured browser adapter.",
|
|
1286
|
-
inputSchema: emptyObjectSchema(),
|
|
1287
|
-
},
|
|
1288
|
-
handler: async () => ({
|
|
1289
|
-
tabs: await this.browserAdapter.listTargets(),
|
|
1290
|
-
}),
|
|
1291
|
-
},
|
|
1292
|
-
],
|
|
1293
|
-
[
|
|
1294
|
-
"launch_browser",
|
|
1295
|
-
{
|
|
1296
|
-
definition: {
|
|
1297
|
-
name: "launch_browser",
|
|
1298
|
-
description:
|
|
1299
|
-
"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.",
|
|
1300
|
-
inputSchema: launchBrowserInputSchema(
|
|
1301
|
-
this.config.browserFamily,
|
|
1302
|
-
this.config.enableUnsafeLaunchArgs,
|
|
1303
|
-
),
|
|
1304
|
-
},
|
|
1305
|
-
handler: async (args) =>
|
|
1306
|
-
this.runExclusiveLaunch(async () => {
|
|
1307
|
-
const browserFamily = requestedBrowserFamily(
|
|
1308
|
-
this.config.browserFamily,
|
|
1309
|
-
args.browserFamily,
|
|
1310
|
-
);
|
|
1311
|
-
// A requested port, address, profile, or flags ask for a
|
|
1312
|
-
// specific browser, so only a plain launch may reuse the
|
|
1313
|
-
// running one.
|
|
1314
|
-
if (
|
|
1315
|
-
args.port === undefined &&
|
|
1316
|
-
args.address === undefined &&
|
|
1317
|
-
args.userDataDir === undefined &&
|
|
1318
|
-
args.unsafeArgs === undefined
|
|
1319
|
-
) {
|
|
1320
|
-
const { status, available } =
|
|
1321
|
-
await this.probeBrowser(browserFamily);
|
|
1322
|
-
if (available) {
|
|
1323
|
-
const tab = shouldCreateBrowserTab(args)
|
|
1324
|
-
? await this.browserAdapter.createTab(args.url, {
|
|
1325
|
-
browserFamily,
|
|
1326
|
-
})
|
|
1327
|
-
: null;
|
|
1328
|
-
return {
|
|
1329
|
-
browserFamily,
|
|
1330
|
-
launched: false,
|
|
1331
|
-
reused: true,
|
|
1332
|
-
status,
|
|
1333
|
-
tab,
|
|
1334
|
-
};
|
|
1335
|
-
}
|
|
1336
|
-
}
|
|
1337
|
-
|
|
1338
|
-
return this.launchUnlessPending(browserFamily, {
|
|
1339
|
-
config: this.config,
|
|
1340
|
-
browserFamily: args.browserFamily,
|
|
1341
|
-
url: args.url,
|
|
1342
|
-
port: args.port,
|
|
1343
|
-
address: args.address,
|
|
1344
|
-
userDataDir: args.userDataDir,
|
|
1345
|
-
unsafeArgs: args.unsafeArgs,
|
|
1346
|
-
waitMs: args.waitMs,
|
|
1347
|
-
skipDoctor: args.skipDoctor,
|
|
1348
|
-
});
|
|
1349
|
-
}),
|
|
1350
|
-
},
|
|
1351
|
-
],
|
|
1352
|
-
[
|
|
1353
|
-
"ensure_browser",
|
|
1354
|
-
{
|
|
1355
|
-
definition: {
|
|
1356
|
-
name: "ensure_browser",
|
|
1357
|
-
description:
|
|
1358
|
-
"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.",
|
|
1359
|
-
inputSchema: ensureBrowserInputSchema(
|
|
1360
|
-
this.config.browserFamily,
|
|
1361
|
-
this.config.enableUnsafeLaunchArgs,
|
|
1362
|
-
),
|
|
1363
|
-
},
|
|
1364
|
-
handler: async (args) =>
|
|
1365
|
-
this.runExclusiveLaunch(() => this.ensureBrowser(args)),
|
|
1366
|
-
},
|
|
1367
|
-
],
|
|
1368
|
-
[
|
|
1369
|
-
"list_sessions",
|
|
1370
|
-
{
|
|
1371
|
-
definition: {
|
|
1372
|
-
name: "list_sessions",
|
|
1373
|
-
description:
|
|
1374
|
-
"List active attached debugging sessions held by this broker.",
|
|
1375
|
-
inputSchema: emptyObjectSchema(),
|
|
1376
|
-
},
|
|
1377
|
-
handler: async () => ({
|
|
1378
|
-
sessions: this.browserAdapter.listSessions(),
|
|
1379
|
-
}),
|
|
1380
|
-
},
|
|
1381
|
-
],
|
|
1382
|
-
[
|
|
1383
|
-
"new_tab",
|
|
1384
|
-
{
|
|
1385
|
-
definition: {
|
|
1386
|
-
name: "new_tab",
|
|
1387
|
-
description:
|
|
1388
|
-
"Create a new browser tab and return the resulting target metadata.",
|
|
1389
|
-
inputSchema: newTabInputSchema(this.config.browserFamily),
|
|
1390
|
-
},
|
|
1391
|
-
handler: async (args) =>
|
|
1392
|
-
this.browserAdapter.createTab(args.url, {
|
|
1393
|
-
browserFamily: args.browserFamily,
|
|
1394
|
-
}),
|
|
1395
|
-
},
|
|
1396
|
-
],
|
|
1397
|
-
[
|
|
1398
|
-
"close_tab",
|
|
1399
|
-
{
|
|
1400
|
-
definition: {
|
|
1401
|
-
name: "close_tab",
|
|
1402
|
-
description:
|
|
1403
|
-
"Close a browser tab by target id. Any attached session for that tab will disconnect.",
|
|
1404
|
-
inputSchema: {
|
|
1405
|
-
type: "object",
|
|
1406
|
-
properties: {
|
|
1407
|
-
targetId: {
|
|
1408
|
-
type: "string",
|
|
1409
|
-
description: "Target id returned by list_tabs or new_tab.",
|
|
1410
|
-
},
|
|
1411
|
-
},
|
|
1412
|
-
required: ["targetId"],
|
|
1413
|
-
additionalProperties: false,
|
|
1414
|
-
},
|
|
1415
|
-
},
|
|
1416
|
-
handler: async (args) =>
|
|
1417
|
-
this.browserAdapter.closeTarget(args.targetId),
|
|
1418
|
-
},
|
|
1419
|
-
],
|
|
1420
|
-
[
|
|
1421
|
-
"attach_tab",
|
|
1422
|
-
{
|
|
1423
|
-
definition: {
|
|
1424
|
-
name: "attach_tab",
|
|
1425
|
-
description:
|
|
1426
|
-
"Attach to a page target and start buffering console, log, and network events.",
|
|
1427
|
-
inputSchema: {
|
|
1428
|
-
type: "object",
|
|
1429
|
-
properties: {
|
|
1430
|
-
targetId: {
|
|
1431
|
-
type: "string",
|
|
1432
|
-
description: "The target id returned by list_tabs.",
|
|
1433
|
-
},
|
|
1434
|
-
},
|
|
1435
|
-
required: ["targetId"],
|
|
1436
|
-
additionalProperties: false,
|
|
1437
|
-
},
|
|
1438
|
-
},
|
|
1439
|
-
handler: async (args) =>
|
|
1440
|
-
this.browserAdapter.attachToTarget(args.targetId),
|
|
1441
|
-
},
|
|
1442
|
-
],
|
|
1443
|
-
[
|
|
1444
|
-
"detach_tab",
|
|
1445
|
-
{
|
|
1446
|
-
definition: {
|
|
1447
|
-
name: "detach_tab",
|
|
1448
|
-
description: "Close an attached debugging session.",
|
|
1449
|
-
inputSchema: {
|
|
1450
|
-
type: "object",
|
|
1451
|
-
properties: {
|
|
1452
|
-
sessionId: {
|
|
1453
|
-
type: "string",
|
|
1454
|
-
description: "The session id returned by attach_tab.",
|
|
1455
|
-
},
|
|
1456
|
-
},
|
|
1457
|
-
required: ["sessionId"],
|
|
1458
|
-
additionalProperties: false,
|
|
1459
|
-
},
|
|
1460
|
-
},
|
|
1461
|
-
handler: async (args) =>
|
|
1462
|
-
this.browserAdapter.detachSession(args.sessionId),
|
|
1463
|
-
},
|
|
1464
|
-
],
|
|
1465
|
-
[
|
|
1466
|
-
"get_page_state",
|
|
1467
|
-
{
|
|
1468
|
-
definition: {
|
|
1469
|
-
name: "get_page_state",
|
|
1470
|
-
description:
|
|
1471
|
-
"Return the current URL, title, ready state, viewport, and scroll positions for an attached page.",
|
|
1472
|
-
inputSchema: sessionSchema({}, []),
|
|
1473
|
-
},
|
|
1474
|
-
handler: async (args) =>
|
|
1475
|
-
this.browserAdapter.getPageState(args.sessionId),
|
|
1476
|
-
},
|
|
1477
|
-
],
|
|
1478
|
-
[
|
|
1479
|
-
"compare_page_state",
|
|
1480
|
-
{
|
|
1481
|
-
definition: {
|
|
1482
|
-
name: "compare_page_state",
|
|
1483
|
-
description:
|
|
1484
|
-
"Compare bounded page state across two attached sessions, useful for cross-browser checks in auto mode.",
|
|
1485
|
-
inputSchema: compareSessionsSchema({}, []),
|
|
1486
|
-
},
|
|
1487
|
-
handler: async (args) => {
|
|
1488
|
-
const [pageA, pageB] = await Promise.all([
|
|
1489
|
-
this.browserAdapter.getPageState(args.sessionIdA),
|
|
1490
|
-
this.browserAdapter.getPageState(args.sessionIdB),
|
|
1491
|
-
]);
|
|
1492
|
-
const left = summarizeComparablePageState(pageA);
|
|
1493
|
-
const right = summarizeComparablePageState(pageB);
|
|
1494
|
-
const fields = {
|
|
1495
|
-
browserFamily: compareField(
|
|
1496
|
-
left.browserFamily,
|
|
1497
|
-
right.browserFamily,
|
|
1498
|
-
),
|
|
1499
|
-
url: compareField(left.url, right.url),
|
|
1500
|
-
title: compareField(left.title, right.title),
|
|
1501
|
-
readyState: compareField(left.readyState, right.readyState),
|
|
1502
|
-
visibilityState: compareField(
|
|
1503
|
-
left.visibilityState,
|
|
1504
|
-
right.visibilityState,
|
|
1505
|
-
),
|
|
1506
|
-
viewport: compareField(left.viewport, right.viewport),
|
|
1507
|
-
scroll: compareField(left.scroll, right.scroll),
|
|
1508
|
-
};
|
|
1509
|
-
|
|
1510
|
-
return {
|
|
1511
|
-
matches: Object.values(fields).every((field) => field.equal),
|
|
1512
|
-
a: left,
|
|
1513
|
-
b: right,
|
|
1514
|
-
fields,
|
|
1515
|
-
};
|
|
1516
|
-
},
|
|
1517
|
-
},
|
|
1518
|
-
],
|
|
1519
|
-
[
|
|
1520
|
-
"compare_selector",
|
|
1521
|
-
{
|
|
1522
|
-
definition: {
|
|
1523
|
-
name: "compare_selector",
|
|
1524
|
-
description:
|
|
1525
|
-
"Compare a selector across two attached sessions using a bounded element summary.",
|
|
1526
|
-
inputSchema: compareSessionsSchema(
|
|
1527
|
-
{
|
|
1528
|
-
selector: selectorProperty(),
|
|
1529
|
-
},
|
|
1530
|
-
["selector"],
|
|
1531
|
-
),
|
|
1532
|
-
},
|
|
1533
|
-
handler: async (args) => {
|
|
1534
|
-
const [elementA, elementB] = await Promise.all([
|
|
1535
|
-
this.browserAdapter.inspectElement(
|
|
1536
|
-
args.sessionIdA,
|
|
1537
|
-
args.selector,
|
|
1538
|
-
),
|
|
1539
|
-
this.browserAdapter.inspectElement(
|
|
1540
|
-
args.sessionIdB,
|
|
1541
|
-
args.selector,
|
|
1542
|
-
),
|
|
1543
|
-
]);
|
|
1544
|
-
const left = summarizeComparableElement(elementA);
|
|
1545
|
-
const right = summarizeComparableElement(elementB);
|
|
1546
|
-
const fields = {
|
|
1547
|
-
found: compareField(left.found, right.found),
|
|
1548
|
-
tagName: compareField(
|
|
1549
|
-
left.tagName ?? null,
|
|
1550
|
-
right.tagName ?? null,
|
|
1551
|
-
),
|
|
1552
|
-
accessibleName: compareField(
|
|
1553
|
-
left.accessibleName ?? null,
|
|
1554
|
-
right.accessibleName ?? null,
|
|
1555
|
-
),
|
|
1556
|
-
role: compareField(left.role ?? null, right.role ?? null),
|
|
1557
|
-
visible: compareField(
|
|
1558
|
-
left.visible ?? null,
|
|
1559
|
-
right.visible ?? null,
|
|
1560
|
-
),
|
|
1561
|
-
disabled: compareField(
|
|
1562
|
-
left.disabled ?? null,
|
|
1563
|
-
right.disabled ?? null,
|
|
1564
|
-
),
|
|
1565
|
-
textContent: compareField(
|
|
1566
|
-
left.textContent ?? null,
|
|
1567
|
-
right.textContent ?? null,
|
|
1568
|
-
),
|
|
1569
|
-
};
|
|
1570
|
-
|
|
1571
|
-
return {
|
|
1572
|
-
selector: args.selector,
|
|
1573
|
-
matches: Object.values(fields).every((field) => field.equal),
|
|
1574
|
-
a: left,
|
|
1575
|
-
b: right,
|
|
1576
|
-
fields,
|
|
1577
|
-
};
|
|
1578
|
-
},
|
|
1579
|
-
},
|
|
1580
|
-
],
|
|
1581
|
-
[
|
|
1582
|
-
"wait_for",
|
|
1583
|
-
{
|
|
1584
|
-
definition: {
|
|
1585
|
-
name: "wait_for",
|
|
1586
|
-
description:
|
|
1587
|
-
"Wait until every given condition holds on an attached session: selector state, selector text (textEquals, textIncludes), exact url, urlIncludes substring, and readyState. Give at least one of selector, url, urlIncludes, or readyState. 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.",
|
|
1588
|
-
inputSchema: waitForInputSchema(),
|
|
1589
|
-
},
|
|
1590
|
-
validate: (args) => {
|
|
1591
|
-
normalizeWaitForOptions(args);
|
|
1592
|
-
},
|
|
1593
|
-
handler: async (args) =>
|
|
1594
|
-
this.browserAdapter.waitFor(args.sessionId, {
|
|
1595
|
-
selector: args.selector,
|
|
1596
|
-
state: args.state,
|
|
1597
|
-
url: args.url,
|
|
1598
|
-
urlIncludes: args.urlIncludes,
|
|
1599
|
-
readyState: args.readyState,
|
|
1600
|
-
textEquals: args.textEquals,
|
|
1601
|
-
textIncludes: args.textIncludes,
|
|
1602
|
-
timeoutMs: args.timeoutMs,
|
|
1603
|
-
pollIntervalMs: args.pollIntervalMs,
|
|
1604
|
-
}),
|
|
1605
|
-
},
|
|
1606
|
-
],
|
|
1607
|
-
[
|
|
1608
|
-
"get_cookies",
|
|
1609
|
-
{
|
|
1610
|
-
definition: {
|
|
1611
|
-
name: "get_cookies",
|
|
1612
|
-
description:
|
|
1613
|
-
"Read bounded page-visible cookies for the attached session.",
|
|
1614
|
-
inputSchema: sessionSchema({}, []),
|
|
1615
|
-
},
|
|
1616
|
-
handler: async (args) =>
|
|
1617
|
-
this.browserAdapter.getCookies(args.sessionId),
|
|
1618
|
-
},
|
|
1619
|
-
],
|
|
1620
|
-
[
|
|
1621
|
-
"get_storage",
|
|
1622
|
-
{
|
|
1623
|
-
definition: {
|
|
1624
|
-
name: "get_storage",
|
|
1625
|
-
description:
|
|
1626
|
-
"Read bounded localStorage and sessionStorage entries for the attached session.",
|
|
1627
|
-
inputSchema: storageInputSchema(),
|
|
1628
|
-
},
|
|
1629
|
-
handler: async (args) => {
|
|
1630
|
-
const result = await this.browserAdapter.getStorage(args.sessionId);
|
|
1631
|
-
if (!args.area || args.area === "all") {
|
|
1632
|
-
return result;
|
|
1633
|
-
}
|
|
1634
|
-
|
|
1635
|
-
return {
|
|
1636
|
-
browserFamily: result.browserFamily,
|
|
1637
|
-
storage: {
|
|
1638
|
-
[args.area]: result.storage?.[args.area] ?? null,
|
|
1639
|
-
},
|
|
1640
|
-
};
|
|
1641
|
-
},
|
|
1642
|
-
},
|
|
1643
|
-
],
|
|
1644
|
-
[
|
|
1645
|
-
"capture_debug_report",
|
|
1646
|
-
{
|
|
1647
|
-
definition: {
|
|
1648
|
-
name: "capture_debug_report",
|
|
1649
|
-
description:
|
|
1650
|
-
"Capture a bounded debug bundle with page state, cookies/storage summary, recent console, recent network, and an optional screenshot.",
|
|
1651
|
-
inputSchema: captureDebugReportInputSchema(
|
|
1652
|
-
this.config.browserFamily,
|
|
1653
|
-
),
|
|
1654
|
-
},
|
|
1655
|
-
handler: async (args) =>
|
|
1656
|
-
this.browserAdapter.captureDebugReport(args.sessionId, {
|
|
1657
|
-
consoleLimit: args.consoleLimit,
|
|
1658
|
-
networkLimit: args.networkLimit,
|
|
1659
|
-
includeScreenshot: args.includeScreenshot,
|
|
1660
|
-
screenshotFormat: args.screenshotFormat,
|
|
1661
|
-
}),
|
|
1662
|
-
},
|
|
1663
|
-
],
|
|
1664
|
-
[
|
|
1665
|
-
"capture_session_snapshot",
|
|
1666
|
-
{
|
|
1667
|
-
definition: {
|
|
1668
|
-
name: "capture_session_snapshot",
|
|
1669
|
-
description:
|
|
1670
|
-
"Capture a bounded session snapshot with page state, cookies, and web storage for later bounded restore on the same origin.",
|
|
1671
|
-
inputSchema: sessionSchema({}, []),
|
|
1672
|
-
},
|
|
1673
|
-
handler: async (args) =>
|
|
1674
|
-
this.browserAdapter.captureSessionSnapshot(args.sessionId),
|
|
1675
|
-
},
|
|
1676
|
-
],
|
|
1677
|
-
[
|
|
1678
|
-
"restore_session_snapshot",
|
|
1679
|
-
{
|
|
1680
|
-
definition: {
|
|
1681
|
-
name: "restore_session_snapshot",
|
|
1682
|
-
description:
|
|
1683
|
-
"Restore a bounded session snapshot into the currently attached page context. Restores only page-visible cookies plus localStorage/sessionStorage on the current origin.",
|
|
1684
|
-
inputSchema: restoreSessionSnapshotInputSchema(),
|
|
1685
|
-
},
|
|
1686
|
-
validate: (args) => {
|
|
1687
|
-
parseSessionSnapshot(args.snapshot);
|
|
1688
|
-
},
|
|
1689
|
-
handler: async (args) =>
|
|
1690
|
-
this.browserAdapter.restoreSessionSnapshot(
|
|
1691
|
-
args.sessionId,
|
|
1692
|
-
parseSessionSnapshot(args.snapshot),
|
|
1693
|
-
{
|
|
1694
|
-
clearStorage: args.clearStorage,
|
|
1695
|
-
},
|
|
1696
|
-
),
|
|
1697
|
-
},
|
|
1698
|
-
],
|
|
1699
|
-
[
|
|
1700
|
-
"get_har",
|
|
1701
|
-
{
|
|
1702
|
-
definition: {
|
|
1703
|
-
name: "get_har",
|
|
1704
|
-
description:
|
|
1705
|
-
"Export a bounded HAR-like summary from buffered network activity for an attached session.",
|
|
1706
|
-
inputSchema: sessionWithLimitSchema(),
|
|
1707
|
-
},
|
|
1708
|
-
handler: async (args) =>
|
|
1709
|
-
this.browserAdapter.getHar(args.sessionId, {
|
|
1710
|
-
limit: args.limit ?? 50,
|
|
1711
|
-
}),
|
|
1712
|
-
},
|
|
1713
|
-
],
|
|
1714
|
-
[
|
|
1715
|
-
"navigate",
|
|
1716
|
-
{
|
|
1717
|
-
definition: {
|
|
1718
|
-
name: "navigate",
|
|
1719
|
-
description:
|
|
1720
|
-
"Navigate an attached tab to a URL and optionally wait for interactive or complete load state.",
|
|
1721
|
-
inputSchema: sessionSchema(
|
|
1722
|
-
{
|
|
1723
|
-
url: {
|
|
1724
|
-
type: "string",
|
|
1725
|
-
description: "Absolute URL to load.",
|
|
1726
|
-
},
|
|
1727
|
-
waitUntil: waitUntilProperty(),
|
|
1728
|
-
},
|
|
1729
|
-
["url"],
|
|
1730
|
-
),
|
|
1731
|
-
},
|
|
1732
|
-
handler: async (args) =>
|
|
1733
|
-
this.browserAdapter.navigate(args.sessionId, args.url, {
|
|
1734
|
-
waitUntil: args.waitUntil,
|
|
1735
|
-
}),
|
|
1736
|
-
},
|
|
1737
|
-
],
|
|
1738
|
-
[
|
|
1739
|
-
"reload",
|
|
1740
|
-
{
|
|
1741
|
-
definition: {
|
|
1742
|
-
name: "reload",
|
|
1743
|
-
description:
|
|
1744
|
-
"Reload the attached tab and optionally ignore cache while waiting for interactive or complete load state.",
|
|
1745
|
-
inputSchema: sessionSchema(
|
|
1746
|
-
{
|
|
1747
|
-
ignoreCache: {
|
|
1748
|
-
type: "boolean",
|
|
1749
|
-
description:
|
|
1750
|
-
"Bypass the HTTP cache for this reload (default false).",
|
|
1751
|
-
},
|
|
1752
|
-
waitUntil: waitUntilProperty(),
|
|
1753
|
-
},
|
|
1754
|
-
[],
|
|
1755
|
-
),
|
|
1756
|
-
},
|
|
1757
|
-
handler: async (args) =>
|
|
1758
|
-
this.browserAdapter.reload(args.sessionId, {
|
|
1759
|
-
ignoreCache: args.ignoreCache,
|
|
1760
|
-
waitUntil: args.waitUntil,
|
|
1761
|
-
}),
|
|
1762
|
-
},
|
|
1763
|
-
],
|
|
1764
|
-
[
|
|
1765
|
-
"click",
|
|
1766
|
-
{
|
|
1767
|
-
definition: {
|
|
1768
|
-
name: "click",
|
|
1769
|
-
description:
|
|
1770
|
-
"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. To check the result in the same call, run it as a run_steps step followed by wait_for, inspect_element, or take_screenshot.",
|
|
1771
|
-
inputSchema: sessionSchema(
|
|
1772
|
-
{
|
|
1773
|
-
selector: selectorProperty(),
|
|
1774
|
-
},
|
|
1775
|
-
["selector"],
|
|
1776
|
-
),
|
|
1777
|
-
},
|
|
1778
|
-
handler: async (args) =>
|
|
1779
|
-
this.browserAdapter.click(args.sessionId, args.selector),
|
|
1780
|
-
},
|
|
1781
|
-
],
|
|
1782
|
-
[
|
|
1783
|
-
"hover",
|
|
1784
|
-
{
|
|
1785
|
-
definition: {
|
|
1786
|
-
name: "hover",
|
|
1787
|
-
description:
|
|
1788
|
-
"Hover a single element located by CSS, text=..., role=..., or name=... syntax. Moves the real mouse pointer to the element center.",
|
|
1789
|
-
inputSchema: sessionSchema(
|
|
1790
|
-
{
|
|
1791
|
-
selector: selectorProperty(),
|
|
1792
|
-
},
|
|
1793
|
-
["selector"],
|
|
1794
|
-
),
|
|
1795
|
-
},
|
|
1796
|
-
handler: async (args) =>
|
|
1797
|
-
this.browserAdapter.hover(args.sessionId, args.selector),
|
|
1798
|
-
},
|
|
1799
|
-
],
|
|
1800
|
-
[
|
|
1801
|
-
"type",
|
|
1802
|
-
{
|
|
1803
|
-
definition: {
|
|
1804
|
-
name: "type",
|
|
1805
|
-
description:
|
|
1806
|
-
"Type text into an input, textarea, or contenteditable element using real text input, replacing existing content unless clear is false. To check the result in the same call, run it as a run_steps step followed by wait_for, inspect_element, or take_screenshot.",
|
|
1807
|
-
inputSchema: sessionSchema(
|
|
1808
|
-
{
|
|
1809
|
-
selector: selectorProperty(),
|
|
1810
|
-
text: {
|
|
1811
|
-
type: "string",
|
|
1812
|
-
description:
|
|
1813
|
-
"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.",
|
|
1814
|
-
},
|
|
1815
|
-
clear: {
|
|
1816
|
-
type: "boolean",
|
|
1817
|
-
description:
|
|
1818
|
-
"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.",
|
|
1819
|
-
},
|
|
1820
|
-
},
|
|
1821
|
-
["selector", "text"],
|
|
1822
|
-
),
|
|
1823
|
-
},
|
|
1824
|
-
handler: async (args) =>
|
|
1825
|
-
this.browserAdapter.type(args.sessionId, args.selector, args.text, {
|
|
1826
|
-
clear: args.clear,
|
|
1827
|
-
}),
|
|
1828
|
-
},
|
|
1829
|
-
],
|
|
1830
|
-
[
|
|
1831
|
-
"select",
|
|
1832
|
-
{
|
|
1833
|
-
definition: {
|
|
1834
|
-
name: "select",
|
|
1835
|
-
description:
|
|
1836
|
-
"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. To check the result in the same call, run it as a run_steps step followed by wait_for, inspect_element, or take_screenshot.",
|
|
1837
|
-
inputSchema: sessionSchema(
|
|
1838
|
-
{
|
|
1839
|
-
selector: selectorProperty(),
|
|
1840
|
-
value: {
|
|
1841
|
-
type: "string",
|
|
1842
|
-
description:
|
|
1843
|
-
"Matches an option whose value attribute or full text equals this string.",
|
|
1844
|
-
},
|
|
1845
|
-
label: {
|
|
1846
|
-
type: "string",
|
|
1847
|
-
description:
|
|
1848
|
-
"Matches an option whose visible text contains this string (case-sensitive).",
|
|
1849
|
-
},
|
|
1850
|
-
},
|
|
1851
|
-
["selector"],
|
|
1852
|
-
),
|
|
1853
|
-
},
|
|
1854
|
-
validate: (args) => {
|
|
1855
|
-
if (!args.value && !args.label) {
|
|
1856
|
-
throw new Error("select requires either value or label");
|
|
1857
|
-
}
|
|
1858
|
-
},
|
|
1859
|
-
handler: async (args) =>
|
|
1860
|
-
this.browserAdapter.select(args.sessionId, args.selector, {
|
|
1861
|
-
value: args.value,
|
|
1862
|
-
label: args.label,
|
|
1863
|
-
}),
|
|
1864
|
-
},
|
|
1865
|
-
],
|
|
1866
|
-
[
|
|
1867
|
-
"press_key",
|
|
1868
|
-
{
|
|
1869
|
-
definition: {
|
|
1870
|
-
name: "press_key",
|
|
1871
|
-
description:
|
|
1872
|
-
"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. To check the result in the same call, run it as a run_steps step followed by wait_for, inspect_element, or take_screenshot.",
|
|
1873
|
-
inputSchema: sessionSchema(
|
|
1874
|
-
{
|
|
1875
|
-
key: {
|
|
1876
|
-
type: "string",
|
|
1877
|
-
description:
|
|
1878
|
-
"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.",
|
|
1879
|
-
},
|
|
1880
|
-
selector: selectorProperty(),
|
|
1881
|
-
},
|
|
1882
|
-
["key"],
|
|
1883
|
-
),
|
|
1884
|
-
},
|
|
1885
|
-
validate: (args) => {
|
|
1886
|
-
parseKeyCombo(args.key);
|
|
1887
|
-
},
|
|
1888
|
-
handler: async (args) =>
|
|
1889
|
-
this.browserAdapter.pressKey(
|
|
1890
|
-
args.sessionId,
|
|
1891
|
-
args.key,
|
|
1892
|
-
args.selector,
|
|
1893
|
-
),
|
|
1894
|
-
},
|
|
1895
|
-
],
|
|
1896
|
-
[
|
|
1897
|
-
"scroll",
|
|
1898
|
-
{
|
|
1899
|
-
definition: {
|
|
1900
|
-
name: "scroll",
|
|
1901
|
-
description:
|
|
1902
|
-
"Scroll the page by deltas or scroll a specific element into view.",
|
|
1903
|
-
inputSchema: sessionSchema(
|
|
1904
|
-
{
|
|
1905
|
-
selector: selectorProperty(),
|
|
1906
|
-
deltaX: {
|
|
1907
|
-
type: "integer",
|
|
1908
|
-
description:
|
|
1909
|
-
"Horizontal scroll distance in CSS pixels; negative scrolls left. Ignored when selector is given.",
|
|
1910
|
-
},
|
|
1911
|
-
deltaY: {
|
|
1912
|
-
type: "integer",
|
|
1913
|
-
description:
|
|
1914
|
-
"Vertical scroll distance in CSS pixels; negative scrolls up. Ignored when selector is given.",
|
|
1915
|
-
},
|
|
1916
|
-
block: {
|
|
1917
|
-
type: "string",
|
|
1918
|
-
enum: ["start", "center", "end", "nearest"],
|
|
1919
|
-
description:
|
|
1920
|
-
"Vertical alignment when scrolling selector into view (default center).",
|
|
1921
|
-
},
|
|
1922
|
-
},
|
|
1923
|
-
[],
|
|
1924
|
-
),
|
|
1925
|
-
},
|
|
1926
|
-
validate: (args) => {
|
|
1927
|
-
if (
|
|
1928
|
-
!args.selector &&
|
|
1929
|
-
args.deltaX === undefined &&
|
|
1930
|
-
args.deltaY === undefined
|
|
1931
|
-
) {
|
|
1932
|
-
throw new Error(
|
|
1933
|
-
"scroll requires either selector or deltaX/deltaY values",
|
|
1934
|
-
);
|
|
1935
|
-
}
|
|
1936
|
-
},
|
|
1937
|
-
handler: async (args) =>
|
|
1938
|
-
this.browserAdapter.scroll(args.sessionId, {
|
|
1939
|
-
selector: args.selector,
|
|
1940
|
-
deltaX: args.deltaX,
|
|
1941
|
-
deltaY: args.deltaY,
|
|
1942
|
-
block: args.block,
|
|
1943
|
-
}),
|
|
1944
|
-
},
|
|
1945
|
-
],
|
|
1946
|
-
[
|
|
1947
|
-
"set_viewport",
|
|
1948
|
-
{
|
|
1949
|
-
definition: {
|
|
1950
|
-
name: "set_viewport",
|
|
1951
|
-
description:
|
|
1952
|
-
"Override the page viewport to a specific width and height for responsive debugging.",
|
|
1953
|
-
inputSchema: sessionSchema(
|
|
1954
|
-
{
|
|
1955
|
-
width: {
|
|
1956
|
-
type: "integer",
|
|
1957
|
-
minimum: 1,
|
|
1958
|
-
description: "Viewport width in CSS pixels.",
|
|
1959
|
-
},
|
|
1960
|
-
height: {
|
|
1961
|
-
type: "integer",
|
|
1962
|
-
minimum: 1,
|
|
1963
|
-
description: "Viewport height in CSS pixels.",
|
|
1964
|
-
},
|
|
1965
|
-
deviceScaleFactor: {
|
|
1966
|
-
type: "number",
|
|
1967
|
-
minimum: 0.1,
|
|
1968
|
-
description:
|
|
1969
|
-
"Device pixel ratio to emulate. Chromium and Edge use 1 when omitted; Firefox keeps its current ratio.",
|
|
1970
|
-
},
|
|
1971
|
-
mobile: {
|
|
1972
|
-
type: "boolean",
|
|
1973
|
-
description:
|
|
1974
|
-
"Emulate a mobile device, including meta viewport handling (default false). Chromium and Edge only; ignored on Firefox.",
|
|
1975
|
-
},
|
|
1976
|
-
},
|
|
1977
|
-
["width", "height"],
|
|
1978
|
-
),
|
|
1979
|
-
},
|
|
1980
|
-
handler: async (args) =>
|
|
1981
|
-
this.browserAdapter.setViewport(args.sessionId, {
|
|
1982
|
-
width: args.width,
|
|
1983
|
-
height: args.height,
|
|
1984
|
-
deviceScaleFactor: args.deviceScaleFactor,
|
|
1985
|
-
mobile: args.mobile,
|
|
1986
|
-
}),
|
|
1987
|
-
},
|
|
1988
|
-
],
|
|
1989
|
-
[
|
|
1990
|
-
"get_console_messages",
|
|
1991
|
-
{
|
|
1992
|
-
definition: {
|
|
1993
|
-
name: "get_console_messages",
|
|
1994
|
-
description:
|
|
1995
|
-
"Read buffered console, log, and exception messages for an attached session.",
|
|
1996
|
-
inputSchema: sessionWithLimitSchema(),
|
|
1997
|
-
},
|
|
1998
|
-
handler: async (args) => ({
|
|
1999
|
-
messages: this.browserAdapter.getConsoleMessages(
|
|
2000
|
-
args.sessionId,
|
|
2001
|
-
args.limit ?? 50,
|
|
2002
|
-
),
|
|
2003
|
-
}),
|
|
2004
|
-
},
|
|
2005
|
-
],
|
|
2006
|
-
[
|
|
2007
|
-
"get_network_requests",
|
|
2008
|
-
{
|
|
2009
|
-
definition: {
|
|
2010
|
-
name: "get_network_requests",
|
|
2011
|
-
description:
|
|
2012
|
-
"Summarize buffered network requests for an attached session in a DevTools-network-tab style view.",
|
|
2013
|
-
inputSchema: sessionWithLimitSchema(),
|
|
2014
|
-
},
|
|
2015
|
-
handler: async (args) => ({
|
|
2016
|
-
requests: this.browserAdapter.getNetworkRequests(
|
|
2017
|
-
args.sessionId,
|
|
2018
|
-
args.limit ?? 50,
|
|
2019
|
-
),
|
|
2020
|
-
}),
|
|
2021
|
-
},
|
|
2022
|
-
],
|
|
2023
|
-
[
|
|
2024
|
-
"get_document",
|
|
2025
|
-
{
|
|
2026
|
-
definition: {
|
|
2027
|
-
name: "get_document",
|
|
2028
|
-
description: "Fetch the DOM document tree for an attached page.",
|
|
2029
|
-
inputSchema: {
|
|
2030
|
-
type: "object",
|
|
2031
|
-
properties: {
|
|
2032
|
-
sessionId: {
|
|
2033
|
-
type: "string",
|
|
2034
|
-
description: "Session id returned by attach_tab.",
|
|
2035
|
-
},
|
|
2036
|
-
depth: {
|
|
2037
|
-
type: "integer",
|
|
2038
|
-
minimum: 1,
|
|
2039
|
-
description:
|
|
2040
|
-
"How many levels of child nodes to include (default 2). Chromium and Edge only; Firefox returns the full document HTML regardless.",
|
|
2041
|
-
},
|
|
2042
|
-
},
|
|
2043
|
-
required: ["sessionId"],
|
|
2044
|
-
additionalProperties: false,
|
|
2045
|
-
},
|
|
2046
|
-
},
|
|
2047
|
-
handler: async (args) =>
|
|
2048
|
-
this.browserAdapter.getDocument(args.sessionId, args.depth ?? 2),
|
|
2049
|
-
},
|
|
2050
|
-
],
|
|
2051
|
-
[
|
|
2052
|
-
"inspect_element",
|
|
2053
|
-
{
|
|
2054
|
-
definition: {
|
|
2055
|
-
name: "inspect_element",
|
|
2056
|
-
description:
|
|
2057
|
-
"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.",
|
|
2058
|
-
inputSchema: {
|
|
2059
|
-
type: "object",
|
|
2060
|
-
properties: {
|
|
2061
|
-
sessionId: {
|
|
2062
|
-
type: "string",
|
|
2063
|
-
description: "Session id returned by attach_tab.",
|
|
2064
|
-
},
|
|
2065
|
-
selector: selectorProperty(),
|
|
2066
|
-
},
|
|
2067
|
-
required: ["sessionId", "selector"],
|
|
2068
|
-
additionalProperties: false,
|
|
2069
|
-
},
|
|
2070
|
-
},
|
|
2071
|
-
handler: async (args) =>
|
|
2072
|
-
this.browserAdapter.inspectElement(args.sessionId, args.selector),
|
|
2073
|
-
},
|
|
2074
|
-
],
|
|
2075
|
-
[
|
|
2076
|
-
"take_screenshot",
|
|
2077
|
-
{
|
|
2078
|
-
definition: {
|
|
2079
|
-
name: "take_screenshot",
|
|
2080
|
-
description:
|
|
2081
|
-
"Capture a screenshot from an attached page or a single element when selector is provided. By default the image comes back as base64 data in the JSON result; output image returns it as image content instead, and output file (or path) writes it to a file and returns the path.",
|
|
2082
|
-
inputSchema: {
|
|
2083
|
-
type: "object",
|
|
2084
|
-
properties: {
|
|
2085
|
-
sessionId: {
|
|
2086
|
-
type: "string",
|
|
2087
|
-
description: "Session id returned by attach_tab.",
|
|
2088
|
-
},
|
|
2089
|
-
format: {
|
|
2090
|
-
type: "string",
|
|
2091
|
-
enum: screenshotFormatsFor(this.config.browserFamily),
|
|
2092
|
-
description:
|
|
2093
|
-
"Image format (default png). With path, it must match the extension.",
|
|
2094
|
-
},
|
|
2095
|
-
selector: selectorProperty(),
|
|
2096
|
-
output: {
|
|
2097
|
-
type: "string",
|
|
2098
|
-
enum: ["data", "image", "file"],
|
|
2099
|
-
description:
|
|
2100
|
-
"How to return the image: data puts base64 data in the JSON result, image returns an image content block with only metadata in the JSON, file writes the decoded image to a file and returns its path (default data, or file when path is given).",
|
|
2101
|
-
},
|
|
2102
|
-
path: {
|
|
2103
|
-
type: "string",
|
|
2104
|
-
description: `Absolute file path for output file, ending in ${screenshotFileExtensions(this.config.browserFamily).join(", ")}; the extension sets the format. Missing parent directories are created. Default: a new file in a private directory under the system temp directory.`,
|
|
2105
|
-
},
|
|
2106
|
-
overwrite: {
|
|
2107
|
-
type: "boolean",
|
|
2108
|
-
description:
|
|
2109
|
-
"For output file: replace path if it already exists (default false: fail instead).",
|
|
2110
|
-
},
|
|
2111
|
-
},
|
|
2112
|
-
required: ["sessionId"],
|
|
2113
|
-
additionalProperties: false,
|
|
2114
|
-
},
|
|
2115
|
-
},
|
|
2116
|
-
validate: (args) => {
|
|
2117
|
-
screenshotTarget(args, this.config.browserFamily);
|
|
2118
|
-
},
|
|
2119
|
-
handler: async (args) => this.takeScreenshot(args),
|
|
2120
|
-
formatResult: (result, args) => {
|
|
2121
|
-
if (args.output !== "image") {
|
|
2122
|
-
return asToolResult(result);
|
|
2123
|
-
}
|
|
2124
|
-
const images = [];
|
|
2125
|
-
const value = moveScreenshotImage(result, images);
|
|
2126
|
-
return asImageToolResult({ value, images });
|
|
2127
|
-
},
|
|
2128
|
-
},
|
|
2129
|
-
],
|
|
2130
|
-
[
|
|
2131
|
-
"get_events",
|
|
2132
|
-
{
|
|
2133
|
-
definition: {
|
|
2134
|
-
name: "get_events",
|
|
2135
|
-
description:
|
|
2136
|
-
"Read buffered console, log, exception, and network events for an attached session.",
|
|
2137
|
-
inputSchema: {
|
|
2138
|
-
type: "object",
|
|
2139
|
-
properties: {
|
|
2140
|
-
sessionId: {
|
|
2141
|
-
type: "string",
|
|
2142
|
-
description: "Session id returned by attach_tab.",
|
|
2143
|
-
},
|
|
2144
|
-
limit: {
|
|
2145
|
-
type: "integer",
|
|
2146
|
-
minimum: 1,
|
|
2147
|
-
description:
|
|
2148
|
-
"Return the most recent N events from the session buffer (default 50).",
|
|
2149
|
-
},
|
|
2150
|
-
},
|
|
2151
|
-
required: ["sessionId"],
|
|
2152
|
-
additionalProperties: false,
|
|
2153
|
-
},
|
|
2154
|
-
},
|
|
2155
|
-
handler: async (args) => ({
|
|
2156
|
-
events: this.browserAdapter.getEvents(
|
|
2157
|
-
args.sessionId,
|
|
2158
|
-
args.limit ?? 50,
|
|
2159
|
-
),
|
|
2160
|
-
}),
|
|
2161
|
-
},
|
|
2162
|
-
],
|
|
223
|
+
...browserTools(this),
|
|
224
|
+
...stateTools(this),
|
|
225
|
+
...actionTools(this),
|
|
226
|
+
...inspectionTools(this),
|
|
2163
227
|
];
|
|
2164
228
|
|
|
2165
|
-
if (this.config.enableEvaluate) {
|
|
2166
|
-
tools.push([
|
|
2167
|
-
"evaluate_js",
|
|
2168
|
-
{
|
|
2169
|
-
definition: {
|
|
2170
|
-
name: "evaluate_js",
|
|
2171
|
-
description: "Evaluate JavaScript in the attached page context.",
|
|
2172
|
-
inputSchema: {
|
|
2173
|
-
type: "object",
|
|
2174
|
-
properties: {
|
|
2175
|
-
sessionId: {
|
|
2176
|
-
type: "string",
|
|
2177
|
-
description: "Session id returned by attach_tab.",
|
|
2178
|
-
},
|
|
2179
|
-
expression: {
|
|
2180
|
-
type: "string",
|
|
2181
|
-
description:
|
|
2182
|
-
"JavaScript expression to evaluate in the page's main world.",
|
|
2183
|
-
},
|
|
2184
|
-
awaitPromise: {
|
|
2185
|
-
type: "boolean",
|
|
2186
|
-
description:
|
|
2187
|
-
"Wait for a returned promise to settle and return its result (default true).",
|
|
2188
|
-
},
|
|
2189
|
-
returnByValue: {
|
|
2190
|
-
type: "boolean",
|
|
2191
|
-
description:
|
|
2192
|
-
"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.",
|
|
2193
|
-
},
|
|
2194
|
-
},
|
|
2195
|
-
required: ["sessionId", "expression"],
|
|
2196
|
-
additionalProperties: false,
|
|
2197
|
-
},
|
|
2198
|
-
},
|
|
2199
|
-
handler: async (args) =>
|
|
2200
|
-
this.browserAdapter.evaluate(args.sessionId, args.expression, {
|
|
2201
|
-
awaitPromise: args.awaitPromise,
|
|
2202
|
-
returnByValue: args.returnByValue,
|
|
2203
|
-
}),
|
|
2204
|
-
},
|
|
2205
|
-
]);
|
|
2206
|
-
}
|
|
2207
|
-
|
|
2208
229
|
const stepTools = tools
|
|
2209
230
|
.filter(([, tool]) =>
|
|
2210
231
|
tool.definition.inputSchema.required?.includes("sessionId"),
|
|
2211
232
|
)
|
|
2212
233
|
.map(([name]) => name);
|
|
2213
|
-
this.
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
234
|
+
this.stepRunner = new StepRunner({
|
|
235
|
+
getTools: () => this.tools,
|
|
236
|
+
browserAdapter: this.browserAdapter,
|
|
237
|
+
stepSchema: stepSchema(stepTools),
|
|
238
|
+
conditionOptions: { expression: this.config.enableEvaluate },
|
|
239
|
+
});
|
|
240
|
+
tools.push(runStepsTool(this.stepRunner, stepTools));
|
|
241
|
+
this.tabRunner = new TabRunner({
|
|
242
|
+
stepRunner: this.stepRunner,
|
|
243
|
+
browserAdapter: this.browserAdapter,
|
|
244
|
+
});
|
|
245
|
+
tools.push(
|
|
246
|
+
runTabsTool(this.tabRunner, stepTools, this.config.browserFamily),
|
|
247
|
+
);
|
|
2227
248
|
|
|
2228
249
|
return new Map(tools);
|
|
2229
250
|
}
|
|
@@ -2311,7 +332,7 @@ export class McpBrowserDevToolsServer {
|
|
|
2311
332
|
version: SERVER_VERSION,
|
|
2312
333
|
},
|
|
2313
334
|
instructions:
|
|
2314
|
-
'Use the browser tools to inspect tabs, console output, network activity, DOM structure, element state, screenshots, and page interactions across Chromium CDP or Firefox BiDi. To act on a page and check the result, prefer run_steps: send the actions you already know (such as every field of a form), a wait_for, and the check (take_screenshot with output image, or inspect_element) in one call instead of several round trips, for example {"sessionId":"<id>","steps":[{"tool":"type","arguments":{"selector":"#search","text":"headphones"}},{"tool":"press_key","arguments":{"key":"Enter"}},{"tool":"wait_for","arguments":{"selector":"#results"}},{"tool":"take_screenshot","arguments":{"output":"image"}}]}. Add an if step when the page can be in more than one state.',
|
|
335
|
+
'Use the browser tools to inspect tabs, console output, network activity, DOM structure, element state, screenshots, and page interactions across Chromium CDP or Firefox BiDi. To act on a page and check the result, prefer run_steps: send the actions you already know (such as every field of a form), a wait_for, and the check (take_screenshot with output image, or inspect_element) in one call instead of several round trips, for example {"sessionId":"<id>","steps":[{"tool":"type","arguments":{"selector":"#search","text":"headphones"}},{"tool":"press_key","arguments":{"key":"Enter"}},{"tool":"wait_for","arguments":{"selector":"#results"}},{"tool":"take_screenshot","arguments":{"output":"image"}}]}. Add an if step when the page can be in more than one state. To read several pages, open them together with run_tabs and read each with read_text. Locators: plain CSS (or css=) takes the first match; text=Foo takes the first visible element whose text equals Foo, else contains it, in document order, so it can match a wrapper; role=button[name="Save"] matches ARIA role and accessible name (equal or containing) without a visibility check; name=Foo takes the first visible element whose accessible name equals or contains Foo, and a matched <label> resolves to its control when that control is visible. Comparisons are case-sensitive; iframes and shadow roots are not searched.',
|
|
2315
336
|
});
|
|
2316
337
|
case "notifications/initialized":
|
|
2317
338
|
return null;
|