mcp-browser-dev-tools 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,6 @@
1
1
  # mcp-browser-dev-tools
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/mcp-browser-dev-tools?label=npm)](https://www.npmjs.com/package/mcp-browser-dev-tools)
4
- [![npm beta](https://img.shields.io/npm/v/mcp-browser-dev-tools/beta?label=beta)](https://www.npmjs.com/package/mcp-browser-dev-tools)
5
4
  [![npm downloads](https://img.shields.io/npm/dm/mcp-browser-dev-tools)](https://www.npmjs.com/package/mcp-browser-dev-tools)
6
5
 
7
6
  `mcp-browser-dev-tools` is a local MCP server that lets AI clients inspect browser state through Chromium DevTools Protocol or Firefox WebDriver BiDi.
@@ -208,6 +207,14 @@ Enable `evaluate_js`:
208
207
  }
209
208
  ```
210
209
 
210
+ Enable unsafe browser launch args for `launch_browser` and `ensure_browser`:
211
+
212
+ ```json
213
+ {
214
+ "MCP_BROWSER_ENABLE_UNSAFE_LAUNCH_ARGS": "1"
215
+ }
216
+ ```
217
+
211
218
  If you use WSL with a Windows Chrome or Edge browser, prefer `serve --bootstrap-wsl-relay` in the configured args instead of manually wiring `relay`. If you use Windows Firefox from WSL, or `auto` mode with both Windows Firefox and Windows Chrome or Edge, run the broker on Windows instead. Full examples are in [docs/setup.md](docs/setup.md).
212
219
 
213
220
  ## Advanced Environment Options
@@ -220,6 +227,7 @@ If you use WSL with a Windows Chrome or Edge browser, prefer `serve --bootstrap-
220
227
  - `MCP_BROWSER_LOG_LEVEL` controls diagnostic logging to `stderr`: `error`, `warn`, `info`, or `debug`
221
228
  - `MCP_BROWSER_DEBUG_STDIO=1` emits raw MCP stdio transport diagnostics to `stderr`
222
229
  - `MCP_BROWSER_ENABLE_EVAL=1` enables `evaluate_js`
230
+ - `MCP_BROWSER_ENABLE_UNSAFE_LAUNCH_ARGS=1` exposes the `unsafeArgs` launch option on `launch_browser` and `ensure_browser`
223
231
  - `MCP_BROWSER_ALLOW_REMOTE_ENDPOINTS=1` allows non-loopback CDP or BiDi endpoints
224
232
  - `MCP_BROWSER_ALLOW_REMOTE_CDP=1` is still accepted as a legacy alias
225
233
  - `MCP_BROWSER_WINDOWS_NODE` optionally overrides the Windows `node` executable used by `serve --bootstrap-wsl-relay`
@@ -234,10 +242,12 @@ If you use WSL with a Windows Chrome or Edge browser, prefer `serve --bootstrap-
234
242
  Ensures a compatible browser is reachable, launches one if needed, and can open a tab for the requested URL in a single MCP call
235
243
  In `auto` mode, pass `browserFamily`
236
244
  For Chrome or Edge launches, `userDataDir` is optional; if omitted, the broker auto-creates a temporary profile when an already-running browser process makes that necessary
245
+ When `MCP_BROWSER_ENABLE_UNSAFE_LAUNCH_ARGS=1`, this tool also accepts `unsafeArgs` as an array of browser flags. Broker-managed launch flags such as the debug port and profile path still cannot be overridden.
237
246
  - `launch_browser`
238
247
  Launches a local debug-enabled browser that matches the current broker configuration and can return an inline doctor report
239
248
  In `auto` mode, pass `browserFamily`
240
249
  For Chrome or Edge launches, `userDataDir` is optional; if omitted, the broker auto-creates a temporary profile when an already-running browser process makes that necessary
250
+ When `MCP_BROWSER_ENABLE_UNSAFE_LAUNCH_ARGS=1`, this tool also accepts `unsafeArgs` as an array of browser flags. Broker-managed launch flags such as the debug port and profile path still cannot be overridden.
241
251
  - `list_tabs`
242
252
  In `auto` mode each `targetId` is namespaced as `chromium:<id>` or `firefox:<id>`
243
253
  - `new_tab`
@@ -275,6 +285,8 @@ If you use WSL with a Windows Chrome or Edge browser, prefer `serve --bootstrap-
275
285
 
276
286
  `evaluate_js` is intentionally disabled by default. Enable it only when you want the broker to allow page-side code execution.
277
287
 
288
+ Unsafe browser launch flags are also disabled by default. If you enable `MCP_BROWSER_ENABLE_UNSAFE_LAUNCH_ARGS=1`, pass only full flag strings such as `--remote-allow-origins=http://localhost:9222`. This does not enable `evaluate_js`, and it still does not let callers replace broker-managed launch flags like `--remote-debugging-port` or `--user-data-dir`.
289
+
278
290
  For tools that take `sessionId`, call `attach_tab` first and reuse the returned session.
279
291
 
280
292
  ### Locator Syntax
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-browser-dev-tools",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "Local MCP server for Chromium DevTools Protocol and Firefox WebDriver BiDi",
5
5
  "author": "Hinaser <rindo.hinase@gmail.com>",
6
6
  "license": "MIT",
@@ -73,6 +73,16 @@ function normalizeStringValue(value) {
73
73
  return trimmed ? trimmed : null;
74
74
  }
75
75
 
76
+ const MANAGED_UNSAFE_LAUNCH_ARG_PREFIXES = [
77
+ "--remote-debugging-address",
78
+ "--remote-debugging-port",
79
+ "--remote-debugging-pipe",
80
+ "--user-data-dir",
81
+ "--profile",
82
+ "-profile",
83
+ "-new-instance",
84
+ ];
85
+
76
86
  function normalizeIntegerValue(value, optionName, { minimum = 1 } = {}) {
77
87
  if (value === undefined || value === null || value === "") {
78
88
  return null;
@@ -87,6 +97,46 @@ function normalizeIntegerValue(value, optionName, { minimum = 1 } = {}) {
87
97
  return String(parsed);
88
98
  }
89
99
 
100
+ function normalizeUnsafeLaunchArgs(unsafeArgs) {
101
+ if (unsafeArgs === undefined || unsafeArgs === null) {
102
+ return [];
103
+ }
104
+
105
+ if (!Array.isArray(unsafeArgs)) {
106
+ throw new Error("unsafeArgs must be an array of strings");
107
+ }
108
+
109
+ return unsafeArgs.map((value, index) => {
110
+ if (typeof value !== "string") {
111
+ throw new Error(`unsafeArgs[${index}] must be a string`);
112
+ }
113
+
114
+ const normalized = value.trim();
115
+ if (!normalized) {
116
+ throw new Error(`unsafeArgs[${index}] must not be empty`);
117
+ }
118
+
119
+ if (!normalized.startsWith("-")) {
120
+ throw new Error(
121
+ `unsafeArgs[${index}] must be a browser flag starting with "-"`,
122
+ );
123
+ }
124
+
125
+ const lowered = normalized.toLowerCase();
126
+ if (
127
+ MANAGED_UNSAFE_LAUNCH_ARG_PREFIXES.some(
128
+ (prefix) => lowered === prefix || lowered.startsWith(`${prefix}=`),
129
+ )
130
+ ) {
131
+ throw new Error(
132
+ `unsafeArgs[${index}] conflicts with broker-managed launch options`,
133
+ );
134
+ }
135
+
136
+ return normalized;
137
+ });
138
+ }
139
+
90
140
  function resolveDefaultPort(config, family) {
91
141
  if (family === "firefox") {
92
142
  return new URL(config.firefoxBidiWsUrl).port || "9222";
@@ -368,6 +418,7 @@ export async function launchBrowser(
368
418
  port,
369
419
  address,
370
420
  userDataDir,
421
+ unsafeArgs,
371
422
  waitMs = 5_000,
372
423
  skipDoctor = false,
373
424
  env = process.env,
@@ -389,9 +440,16 @@ export async function launchBrowser(
389
440
  const resolvedPort =
390
441
  normalizeIntegerValue(port, "port", { minimum: 1 }) ??
391
442
  resolveDefaultPort(config, family);
443
+ const normalizedUnsafeArgs = normalizeUnsafeLaunchArgs(unsafeArgs);
392
444
  const requestedAddress =
393
445
  family === "firefox" ? null : normalizeStringValue(address);
394
446
 
447
+ if (normalizedUnsafeArgs.length > 0 && !config.enableUnsafeLaunchArgs) {
448
+ throw new Error(
449
+ "unsafeArgs requires MCP_BROWSER_ENABLE_UNSAFE_LAUNCH_ARGS=1",
450
+ );
451
+ }
452
+
395
453
  if (
396
454
  requestedAddress &&
397
455
  !isLoopbackHost(requestedAddress) &&
@@ -433,6 +491,7 @@ export async function launchBrowser(
433
491
  remoteDebuggingPort: resolvedPort,
434
492
  remoteDebuggingAddress: launchAddress ?? undefined,
435
493
  userDataDir: normalizedUserDataDir,
494
+ unsafeArgs: normalizedUnsafeArgs,
436
495
  });
437
496
 
438
497
  const child = spawnProcess(executable, args, {
@@ -454,6 +513,7 @@ export async function launchBrowser(
454
513
  ? `ws://127.0.0.1:${resolvedPort}`
455
514
  : `http://${endpointAddress}:${resolvedPort}`,
456
515
  userDataDir: normalizedUserDataDir ?? null,
516
+ unsafeArgs: normalizedUnsafeArgs,
457
517
  profileStrategy,
458
518
  existingBrowserProcess,
459
519
  doctorReport: null,
@@ -174,6 +174,7 @@ export function buildBrowserLaunchArgs({
174
174
  remoteDebuggingPort,
175
175
  remoteDebuggingAddress,
176
176
  userDataDir,
177
+ unsafeArgs = [],
177
178
  }) {
178
179
  if (!url) {
179
180
  throw new Error("A target URL is required");
@@ -187,6 +188,7 @@ export function buildBrowserLaunchArgs({
187
188
  if (remoteDebuggingPort) {
188
189
  args.push(`--remote-debugging-port=${remoteDebuggingPort}`);
189
190
  }
191
+ args.push(...unsafeArgs);
190
192
  args.push(url);
191
193
  return args;
192
194
  }
@@ -200,6 +202,7 @@ export function buildBrowserLaunchArgs({
200
202
  if (userDataDir) {
201
203
  args.push(`--user-data-dir=${userDataDir}`);
202
204
  }
205
+ args.push(...unsafeArgs);
203
206
  args.push(url);
204
207
  return args;
205
208
  }
package/src/config.mjs CHANGED
@@ -114,6 +114,9 @@ export function loadConfig(env = process.env) {
114
114
  allowRemoteEndpoints,
115
115
  allowRemoteCdp: allowRemoteEndpoints,
116
116
  enableEvaluate: isTruthyFlag(env.MCP_BROWSER_ENABLE_EVAL),
117
+ enableUnsafeLaunchArgs: isTruthyFlag(
118
+ env.MCP_BROWSER_ENABLE_UNSAFE_LAUNCH_ARGS,
119
+ ),
117
120
  eventBufferSize: parsePositiveInteger(
118
121
  env.MCP_BROWSER_EVENT_BUFFER_SIZE,
119
122
  DEFAULT_EVENT_BUFFER_SIZE,
@@ -320,7 +320,16 @@ function newTabInputSchema(browserFamily) {
320
320
  };
321
321
  }
322
322
 
323
- function launchBrowserInputSchema(browserFamily) {
323
+ function unsafeArgsProperty() {
324
+ return {
325
+ type: "array",
326
+ items: {
327
+ type: "string",
328
+ },
329
+ };
330
+ }
331
+
332
+ function launchBrowserInputSchema(browserFamily, enableUnsafeLaunchArgs) {
324
333
  const properties = {
325
334
  url: {
326
335
  type: "string",
@@ -347,6 +356,9 @@ function launchBrowserInputSchema(browserFamily) {
347
356
  type: "boolean",
348
357
  },
349
358
  };
359
+ if (enableUnsafeLaunchArgs) {
360
+ properties.unsafeArgs = unsafeArgsProperty();
361
+ }
350
362
  const required = browserFamily === "auto" ? ["browserFamily"] : [];
351
363
 
352
364
  return {
@@ -357,41 +369,46 @@ function launchBrowserInputSchema(browserFamily) {
357
369
  };
358
370
  }
359
371
 
360
- function ensureBrowserInputSchema(browserFamily) {
372
+ function ensureBrowserInputSchema(browserFamily, enableUnsafeLaunchArgs) {
373
+ const properties = {
374
+ browserFamily: {
375
+ type: "string",
376
+ enum: supportedLaunchFamilies(browserFamily),
377
+ },
378
+ url: {
379
+ type: "string",
380
+ },
381
+ createTab: {
382
+ type: "boolean",
383
+ },
384
+ launchIfMissing: {
385
+ type: "boolean",
386
+ },
387
+ port: {
388
+ type: "integer",
389
+ minimum: 1,
390
+ },
391
+ address: {
392
+ type: "string",
393
+ },
394
+ userDataDir: {
395
+ type: "string",
396
+ },
397
+ waitMs: {
398
+ type: "integer",
399
+ minimum: 0,
400
+ },
401
+ skipDoctor: {
402
+ type: "boolean",
403
+ },
404
+ };
405
+ if (enableUnsafeLaunchArgs) {
406
+ properties.unsafeArgs = unsafeArgsProperty();
407
+ }
408
+
361
409
  return {
362
410
  type: "object",
363
- properties: {
364
- browserFamily: {
365
- type: "string",
366
- enum: supportedLaunchFamilies(browserFamily),
367
- },
368
- url: {
369
- type: "string",
370
- },
371
- createTab: {
372
- type: "boolean",
373
- },
374
- launchIfMissing: {
375
- type: "boolean",
376
- },
377
- port: {
378
- type: "integer",
379
- minimum: 1,
380
- },
381
- address: {
382
- type: "string",
383
- },
384
- userDataDir: {
385
- type: "string",
386
- },
387
- waitMs: {
388
- type: "integer",
389
- minimum: 0,
390
- },
391
- skipDoctor: {
392
- type: "boolean",
393
- },
394
- },
411
+ properties,
395
412
  required: browserFamily === "auto" ? ["browserFamily"] : [],
396
413
  additionalProperties: false,
397
414
  };
@@ -534,7 +551,10 @@ export class McpBrowserDevToolsServer {
534
551
  name: "launch_browser",
535
552
  description:
536
553
  "Launch a local debug-enabled browser process that matches the current broker configuration and return launch details plus an optional doctor report.",
537
- inputSchema: launchBrowserInputSchema(this.config.browserFamily),
554
+ inputSchema: launchBrowserInputSchema(
555
+ this.config.browserFamily,
556
+ this.config.enableUnsafeLaunchArgs,
557
+ ),
538
558
  },
539
559
  handler: async (args) =>
540
560
  this.launchBrowser({
@@ -544,6 +564,7 @@ export class McpBrowserDevToolsServer {
544
564
  port: args.port,
545
565
  address: args.address,
546
566
  userDataDir: args.userDataDir,
567
+ unsafeArgs: args.unsafeArgs,
547
568
  waitMs: args.waitMs,
548
569
  skipDoctor: args.skipDoctor,
549
570
  }),
@@ -556,7 +577,10 @@ export class McpBrowserDevToolsServer {
556
577
  name: "ensure_browser",
557
578
  description:
558
579
  "Ensure a compatible browser is reachable through the current broker. If needed, launch one locally and optionally open a tab for the requested URL.",
559
- inputSchema: ensureBrowserInputSchema(this.config.browserFamily),
580
+ inputSchema: ensureBrowserInputSchema(
581
+ this.config.browserFamily,
582
+ this.config.enableUnsafeLaunchArgs,
583
+ ),
560
584
  },
561
585
  handler: async (args) => {
562
586
  const browserFamily = requestedBrowserFamily(
@@ -590,6 +614,7 @@ export class McpBrowserDevToolsServer {
590
614
  port: args.port,
591
615
  address: args.address,
592
616
  userDataDir: args.userDataDir,
617
+ unsafeArgs: args.unsafeArgs,
593
618
  waitMs: args.waitMs,
594
619
  skipDoctor: args.skipDoctor,
595
620
  });