mcp-browser-dev-tools 0.2.2 → 0.4.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.
@@ -14,15 +14,11 @@ export function sessionWithLimitSchema(description) {
14
14
  return {
15
15
  type: "object",
16
16
  properties: {
17
- sessionId: {
18
- type: "string",
19
- description: "Session id returned by attach_tab.",
20
- },
17
+ sessionId: { type: "string" },
21
18
  limit: {
22
19
  type: "integer",
23
20
  minimum: 1,
24
- description:
25
- "Return the most recent N entries from the session buffer (default 50).",
21
+ description: "Most recent N (default 50).",
26
22
  },
27
23
  },
28
24
  required: ["sessionId"],
@@ -32,7 +28,7 @@ export function sessionWithLimitSchema(description) {
32
28
  }
33
29
 
34
30
  export const LOCATOR_DESCRIPTION =
35
- 'Locator: CSS, text=Visible text, role=button[name="Save"], or name=Accessible name.';
31
+ 'Locator: ref=e3, CSS, text=\u2026, role=button[name="\u2026"], or name=\u2026';
36
32
 
37
33
  // A copy of schema without descriptions, for a schema repeated inside another
38
34
  // whose fields are already described once; validation is unchanged.
@@ -59,14 +55,50 @@ export function selectorProperty() {
59
55
  };
60
56
  }
61
57
 
58
+ // x and y place pointer input at viewport coordinates instead of an element.
59
+ export function pointProperties(prefix = "") {
60
+ const name = (axis) => (prefix ? prefix + axis.toUpperCase() : axis);
61
+ return {
62
+ [name("x")]: {
63
+ type: "number",
64
+ minimum: 0,
65
+ description: `Viewport CSS px, with ${name("y")}, instead of ${prefix ? `${prefix}Selector` : "selector"}.`,
66
+ },
67
+ [name("y")]: { type: "number", minimum: 0 },
68
+ };
69
+ }
70
+
71
+ // The selector, or the { x, y } point, that args name under prefix; throws
72
+ // unless exactly one of the two is given.
73
+ export function pointerTarget(args, prefix = "", required = true) {
74
+ const key = (name) =>
75
+ prefix ? prefix + name[0].toUpperCase() + name.slice(1) : name;
76
+ const selector = args[key("selector")];
77
+ const x = args[key("x")];
78
+ const y = args[key("y")];
79
+ const hasPoint = x !== undefined || y !== undefined;
80
+ if (hasPoint && (x === undefined || y === undefined)) {
81
+ throw new Error(`${key("x")} and ${key("y")} go together`);
82
+ }
83
+ if (selector !== undefined && hasPoint) {
84
+ throw new Error(
85
+ `Pass ${key("selector")} or ${key("x")}/${key("y")}, not both`,
86
+ );
87
+ }
88
+ if (selector === undefined && !hasPoint) {
89
+ if (!required) {
90
+ return null;
91
+ }
92
+ throw new Error(`Pass ${key("selector")} or ${key("x")} and ${key("y")}`);
93
+ }
94
+ return selector ?? { x, y };
95
+ }
96
+
62
97
  export function sessionSchema(properties, required, description) {
63
98
  return {
64
99
  type: "object",
65
100
  properties: {
66
- sessionId: {
67
- type: "string",
68
- description: "Session id returned by attach_tab.",
69
- },
101
+ sessionId: { type: "string" },
70
102
  ...properties,
71
103
  },
72
104
  required: ["sessionId", ...required],
@@ -80,7 +112,7 @@ export function waitUntilProperty() {
80
112
  type: "string",
81
113
  enum: ["none", "interactive", "complete"],
82
114
  description:
83
- "When to return: none returns once navigation starts, interactive after DOMContentLoaded, complete after the load event (default complete).",
115
+ "Return at none (navigation started), interactive (DOMContentLoaded), or complete (load; default).",
84
116
  };
85
117
  }
86
118
 
@@ -93,42 +125,41 @@ export function pageConditionProperties({ expression = false } = {}) {
93
125
  type: "string",
94
126
  enum: ["present", "visible", "hidden"],
95
127
  description:
96
- "Selector state (default visible). present: in the DOM. hidden: absent or not visible. Requires selector.",
128
+ "With selector (default visible); hidden means absent or not visible.",
97
129
  },
98
130
  url: {
99
131
  type: "string",
100
- description: "The page URL equals this string exactly.",
132
+ description: "Page URL equals this.",
101
133
  },
102
134
  urlIncludes: {
103
135
  type: "string",
104
- description: "The page URL contains this string.",
136
+ description: "Page URL contains this.",
105
137
  },
106
138
  readyState: {
107
139
  type: "string",
108
140
  enum: ["interactive", "complete"],
109
- description: "document.readyState has reached this state or later.",
141
+ description: "document.readyState is at least this.",
110
142
  },
111
143
  textEquals: {
112
144
  type: "string",
113
145
  description:
114
- "The selector's full visible text equals this, with whitespace collapsed. Requires selector; not with state hidden.",
146
+ "The selector's visible text equals this (whitespace collapsed).",
115
147
  },
116
148
  textIncludes: {
117
149
  type: "string",
118
- description:
119
- "The selector's full visible text contains this, with whitespace collapsed. Requires selector; not with state hidden.",
150
+ description: "The selector's visible text contains this.",
120
151
  },
121
152
  textExcludes: {
122
153
  type: "string",
123
154
  description:
124
- "The selector's visible text no longer contains this, for example Processing; never holds for a missing element. Requires selector; not with state hidden.",
155
+ "The selector's visible text no longer contains this; false for a missing element.",
125
156
  },
126
157
  ...(expression
127
158
  ? {
128
159
  expression: {
129
160
  type: "string",
130
161
  description:
131
- "JavaScript in the page's main world; holds when its result (awaited if a promise) is truthy, for example document.querySelectorAll('.row').length >= 5. Throwing fails the check; each evaluation must settle within the remaining wait (5000ms in if and repeat).",
162
+ "Page JavaScript; holds when its (awaited) result is truthy. Throwing fails.",
132
163
  },
133
164
  }
134
165
  : {}),
@@ -156,7 +187,7 @@ export function anyOfProperty(options) {
156
187
  additionalProperties: false,
157
188
  },
158
189
  description:
159
- "Alternative conditions with the fields above, instead of them; holds when any one holds, checked in order, for example a status of either Paid or Declined. The result reports matchedIndex.",
190
+ "Conditions with the fields above, instead of them; holds when any holds (result: matchedIndex).",
160
191
  };
161
192
  }
162
193
 
@@ -164,21 +195,18 @@ export function waitForInputSchema(options) {
164
195
  return {
165
196
  type: "object",
166
197
  properties: {
167
- sessionId: {
168
- type: "string",
169
- description: "Session id returned by attach_tab.",
170
- },
198
+ sessionId: { type: "string" },
171
199
  ...pageConditionProperties(options),
172
200
  anyOf: anyOfProperty(options),
173
201
  timeoutMs: {
174
202
  type: "integer",
175
203
  minimum: 1,
176
- description: "How long to wait before failing (default 10000).",
204
+ description: "ms before failing (default 10000).",
177
205
  },
178
206
  pollIntervalMs: {
179
207
  type: "integer",
180
208
  minimum: 1,
181
- description: "Delay between checks (default 100).",
209
+ description: "ms between checks (default 100).",
182
210
  },
183
211
  },
184
212
  required: ["sessionId"],
@@ -191,7 +219,7 @@ export function actionTimeoutProperty(what) {
191
219
  type: "integer",
192
220
  minimum: 0,
193
221
  maximum: 30_000,
194
- description: `How long to keep retrying while the element is missing${what}, before failing (default ${DEFAULT_ACTION_TIMEOUT_MS}; 0 fails at once).`,
222
+ description: `ms to retry while the element is missing${what} (default ${DEFAULT_ACTION_TIMEOUT_MS}).`,
195
223
  };
196
224
  }
197
225
 
@@ -199,14 +227,8 @@ export function compareSessionsSchema(properties, required) {
199
227
  return {
200
228
  type: "object",
201
229
  properties: {
202
- sessionIdA: {
203
- type: "string",
204
- description: "Session id returned by attach_tab.",
205
- },
206
- sessionIdB: {
207
- type: "string",
208
- description: "Session id returned by attach_tab.",
209
- },
230
+ sessionIdA: { type: "string" },
231
+ sessionIdB: { type: "string" },
210
232
  ...properties,
211
233
  },
212
234
  required: ["sessionIdA", "sessionIdB", ...required],
@@ -218,14 +240,11 @@ export function storageInputSchema() {
218
240
  return {
219
241
  type: "object",
220
242
  properties: {
221
- sessionId: {
222
- type: "string",
223
- description: "Session id returned by attach_tab.",
224
- },
243
+ sessionId: { type: "string" },
225
244
  area: {
226
245
  type: "string",
227
246
  enum: ["all", "localStorage", "sessionStorage"],
228
- description: "Which storage to return (default all).",
247
+ description: "Default all.",
229
248
  },
230
249
  },
231
250
  required: ["sessionId"],
@@ -237,28 +256,25 @@ export function captureDebugReportInputSchema(browserFamily) {
237
256
  return {
238
257
  type: "object",
239
258
  properties: {
240
- sessionId: {
241
- type: "string",
242
- description: "Session id returned by attach_tab.",
243
- },
259
+ sessionId: { type: "string" },
244
260
  consoleLimit: {
245
261
  type: "integer",
246
262
  minimum: 1,
247
- description: "Most recent console entries to include (default 20).",
263
+ description: "Default 20.",
248
264
  },
249
265
  networkLimit: {
250
266
  type: "integer",
251
267
  minimum: 1,
252
- description: "Most recent network requests to include (default 20).",
268
+ description: "Default 20.",
253
269
  },
254
270
  includeScreenshot: {
255
271
  type: "boolean",
256
- description: "Include a viewport screenshot (default true).",
272
+ description: "Default true.",
257
273
  },
258
274
  screenshotFormat: {
259
275
  type: "string",
260
276
  enum: screenshotFormatsFor(browserFamily),
261
- description: "Screenshot image format (default png).",
277
+ description: "Default png.",
262
278
  },
263
279
  },
264
280
  required: ["sessionId"],
@@ -270,19 +286,14 @@ export function restoreSessionSnapshotInputSchema() {
270
286
  return {
271
287
  type: "object",
272
288
  properties: {
273
- sessionId: {
274
- type: "string",
275
- description: "Session id returned by attach_tab.",
276
- },
289
+ sessionId: { type: "string" },
277
290
  snapshot: {
278
291
  type: "string",
279
- description:
280
- "The JSON output of capture_session_snapshot, as a string. Only entries for the current page origin are restored.",
292
+ description: "capture_session_snapshot's JSON output, as a string.",
281
293
  },
282
294
  clearStorage: {
283
295
  type: "boolean",
284
- description:
285
- "Clear localStorage and sessionStorage before restoring (default false).",
296
+ description: "Clear web storage first (default false).",
286
297
  },
287
298
  },
288
299
  required: ["sessionId", "snapshot"],
@@ -294,7 +305,7 @@ export function newTabInputSchema(browserFamily) {
294
305
  const properties = {
295
306
  url: {
296
307
  type: "string",
297
- description: "URL to open (default about:blank).",
308
+ description: "Default about:blank.",
298
309
  },
299
310
  };
300
311
  const required = [];
@@ -303,7 +314,7 @@ export function newTabInputSchema(browserFamily) {
303
314
  properties.browserFamily = {
304
315
  type: "string",
305
316
  enum: ["chromium", "firefox"],
306
- description: "Browser to open the tab in.",
317
+ description: "Required in auto mode.",
307
318
  };
308
319
  required.push("browserFamily");
309
320
  }
@@ -323,7 +334,7 @@ export function unsafeArgsProperty() {
323
334
  type: "string",
324
335
  },
325
336
  description:
326
- "Extra browser command-line flags, each starting with -. Flags that conflict with broker-managed launch options (debugging port, address, profile) are rejected.",
337
+ "Extra browser flags; ones that set the port, address, or profile are rejected.",
327
338
  };
328
339
  }
329
340
 
@@ -334,40 +345,38 @@ export function launchBrowserInputSchema(
334
345
  const properties = {
335
346
  url: {
336
347
  type: "string",
337
- description: "URL to open in the launched browser (default about:blank).",
348
+ description: "Default about:blank.",
338
349
  },
339
350
  browserFamily: {
340
351
  type: "string",
341
352
  enum: supportedLaunchFamilies(browserFamily),
342
- description:
343
- "Browser to launch. Required when the broker runs in auto mode.",
353
+ description: "Required in auto mode.",
344
354
  },
345
355
  port: {
346
356
  type: "integer",
347
357
  minimum: 1,
348
358
  description:
349
- "Remote debugging port to launch on (default: the port of the configured browser endpoint, usually 9222).",
359
+ "Debugging port (default: the configured endpoint's, usually 9222).",
350
360
  },
351
361
  address: {
352
362
  type: "string",
353
363
  description:
354
- "Remote debugging bind address for Chromium and Edge (ignored for Firefox). Must be loopback unless MCP_BROWSER_ALLOW_REMOTE_ENDPOINTS=1.",
364
+ "Chromium/Edge bind address; loopback unless MCP_BROWSER_ALLOW_REMOTE_ENDPOINTS=1.",
355
365
  },
356
366
  userDataDir: {
357
367
  type: "string",
358
368
  description:
359
- "Profile directory for a new launch (default: MCP_BROWSER_USER_DATA_DIR). Without either, Chromium and Edge use a temporary profile if already running, else the default one.",
369
+ "Profile for a new launch (default MCP_BROWSER_USER_DATA_DIR).",
360
370
  },
361
371
  waitMs: {
362
372
  type: "integer",
363
373
  minimum: 0,
364
- description:
365
- "How long to wait for the debugging endpoint to answer after launch (default 5000).",
374
+ description: "ms to wait for the endpoint after launch (default 5000).",
366
375
  },
367
376
  skipDoctor: {
368
377
  type: "boolean",
369
378
  description:
370
- "Return right after spawning the browser, without waiting for the endpoint or running the doctor report (default false).",
379
+ "Return right after spawning, without waiting or a doctor report.",
371
380
  },
372
381
  };
373
382
  if (enableUnsafeLaunchArgs) {
@@ -391,49 +400,45 @@ export function ensureBrowserInputSchema(
391
400
  browserFamily: {
392
401
  type: "string",
393
402
  enum: supportedLaunchFamilies(browserFamily),
394
- description:
395
- "Browser to check or launch. Required when the broker runs in auto mode.",
403
+ description: "Required in auto mode.",
396
404
  },
397
405
  url: {
398
406
  type: "string",
399
- description: "URL to open in a new tab once the browser is reachable.",
407
+ description: "Open this in a new tab.",
400
408
  },
401
409
  createTab: {
402
410
  type: "boolean",
403
- description:
404
- "Open a tab after the browser is reachable (default: true when url is given).",
411
+ description: "Default: true when url is given.",
405
412
  },
406
413
  launchIfMissing: {
407
414
  type: "boolean",
408
- description:
409
- "Launch a browser when none is reachable (default true). When false and none is reachable, return the status without launching or opening a tab.",
415
+ description: "Launch when none is reachable (default true).",
410
416
  },
411
417
  port: {
412
418
  type: "integer",
413
419
  minimum: 1,
414
420
  description:
415
- "Remote debugging port to launch on (default: the port of the configured browser endpoint, usually 9222).",
421
+ "Debugging port (default: the configured endpoint's, usually 9222).",
416
422
  },
417
423
  address: {
418
424
  type: "string",
419
425
  description:
420
- "Remote debugging bind address for Chromium and Edge (ignored for Firefox). Must be loopback unless MCP_BROWSER_ALLOW_REMOTE_ENDPOINTS=1.",
426
+ "Chromium/Edge bind address; loopback unless MCP_BROWSER_ALLOW_REMOTE_ENDPOINTS=1.",
421
427
  },
422
428
  userDataDir: {
423
429
  type: "string",
424
430
  description:
425
- "Profile directory for a new launch (default: MCP_BROWSER_USER_DATA_DIR). Without either, Chromium and Edge use a temporary profile if already running, else the default one.",
431
+ "Profile for a new launch (default MCP_BROWSER_USER_DATA_DIR).",
426
432
  },
427
433
  waitMs: {
428
434
  type: "integer",
429
435
  minimum: 0,
430
- description:
431
- "How long to wait for the debugging endpoint to answer after launch (default 5000).",
436
+ description: "ms to wait for the endpoint after launch (default 5000).",
432
437
  },
433
438
  skipDoctor: {
434
439
  type: "boolean",
435
440
  description:
436
- "Return right after spawning the browser, without waiting for the endpoint or running the doctor report (default false).",
441
+ "Return right after spawning, without waiting or a doctor report.",
437
442
  },
438
443
  };
439
444
  if (enableUnsafeLaunchArgs) {
@@ -0,0 +1,73 @@
1
+ // Every model turn pays for the definitions of every tool the server
2
+ // offers, so by default it offers the core set, the tools page work needs.
3
+ // MCP_BROWSER_TOOLS adds groups or single tools (comma-separated), or all.
4
+ export const TOOL_GROUPS = {
5
+ core: [
6
+ "ensure_browser",
7
+ "list_tabs",
8
+ "new_tab",
9
+ "close_tab",
10
+ "attach_tab",
11
+ "navigate",
12
+ "reload",
13
+ "click",
14
+ "hover",
15
+ "type",
16
+ "select",
17
+ "press_key",
18
+ "scroll",
19
+ "upload_file",
20
+ "wait_for",
21
+ "run_steps",
22
+ "run_tabs",
23
+ "get_snapshot",
24
+ "read_text",
25
+ "inspect_element",
26
+ "take_screenshot",
27
+ "evaluate_js",
28
+ "get_console_messages",
29
+ "get_network_requests",
30
+ ],
31
+ input: ["drag", "set_viewport"],
32
+ network: ["set_network", "get_har", "get_events"],
33
+ state: [
34
+ "get_cookies",
35
+ "get_storage",
36
+ "capture_session_snapshot",
37
+ "restore_session_snapshot",
38
+ "capture_debug_report",
39
+ "get_page_state",
40
+ "get_document",
41
+ ],
42
+ compare: ["compare_page_state", "compare_selector"],
43
+ browser: ["browser_status", "launch_browser", "list_sessions", "detach_tab"],
44
+ performance: ["get_performance", "record_trace", "record_video"],
45
+ };
46
+
47
+ // The tool names MCP_BROWSER_TOOLS enables, or null for all. The core set
48
+ // is always included, so naming a group adds to it. A name that is neither
49
+ // a group nor a tool fails at startup rather than leaving a tool missing.
50
+ export function parseToolSet(value) {
51
+ const entries = (value ?? "")
52
+ .split(",")
53
+ .map((entry) => entry.trim())
54
+ .filter(Boolean);
55
+ const known = new Set(Object.values(TOOL_GROUPS).flat());
56
+ const names = new Set(TOOL_GROUPS.core);
57
+ for (const entry of entries) {
58
+ if (entry === "all") {
59
+ Object.values(TOOL_GROUPS)
60
+ .flat()
61
+ .forEach((name) => names.add(name));
62
+ } else if (TOOL_GROUPS[entry]) {
63
+ TOOL_GROUPS[entry].forEach((name) => names.add(name));
64
+ } else if (known.has(entry)) {
65
+ names.add(entry);
66
+ } else {
67
+ throw new Error(
68
+ `MCP_BROWSER_TOOLS has an unknown group or tool: ${entry}. Groups: all, ${Object.keys(TOOL_GROUPS).join(", ")}`,
69
+ );
70
+ }
71
+ }
72
+ return entries.includes("all") ? null : names;
73
+ }