mcp-browser-dev-tools 0.5.3 → 0.5.5
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 +15 -5
- package/package.json +6 -2
- package/src/browser-launch-service.mjs +2 -0
- package/src/browser-launcher.mjs +25 -0
- package/src/cdp-client.mjs +23 -1
- package/src/tcp-relay.mjs +11 -4
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/mcp-browser-dev-tools)
|
|
4
4
|
[](https://www.npmjs.com/package/mcp-browser-dev-tools)
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
An MCP server for browser use: let an AI agent work in a real browser with fewer back-and-forths. It sends a whole sequence of clicks, typing, waits, and checks in one tool call and gets every result back together, in your Chrome, Edge, or Firefox. Against Playwright MCP and Chrome DevTools MCP, on six browser tasks with six models, it took the fewest turns and the least time with every model ([comparison](https://hinaser.github.io/mcp-browser-dev-tools/comparison.html)).
|
|
7
7
|
|
|
8
8
|
## Quick Start
|
|
9
9
|
|
|
@@ -11,10 +11,10 @@ You need Node.js 24 or later. Register the server with your MCP client:
|
|
|
11
11
|
|
|
12
12
|
```bash
|
|
13
13
|
# Claude Code
|
|
14
|
-
claude mcp add browser-devtools --scope user -- npx -y mcp-browser-dev-tools serve
|
|
14
|
+
claude mcp add browser-devtools --scope user -- npx -y mcp-browser-dev-tools@latest serve
|
|
15
15
|
|
|
16
16
|
# Codex
|
|
17
|
-
codex mcp add browser-devtools -- npx -y mcp-browser-dev-tools serve
|
|
17
|
+
codex mcp add browser-devtools -- npx -y mcp-browser-dev-tools@latest serve
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
Cursor and other clients that use an `mcpServers` config:
|
|
@@ -24,12 +24,14 @@ Cursor and other clients that use an `mcpServers` config:
|
|
|
24
24
|
"mcpServers": {
|
|
25
25
|
"browser-devtools": {
|
|
26
26
|
"command": "npx",
|
|
27
|
-
"args": ["-y", "mcp-browser-dev-tools", "serve"]
|
|
27
|
+
"args": ["-y", "mcp-browser-dev-tools@latest", "serve"]
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
+
`@latest` makes npx check for the current release when the client starts the server, reusing its cached copy when nothing changed; the check takes a moment and needs the npm registry or a cached answer. Without a version, npx uses an already installed copy, such as one from `npm install -g`, however old.
|
|
34
|
+
|
|
33
35
|
Then ask the agent for browser work, for example "open example.com and check the console for errors" or "attach to my open tab and find out why the form won't submit". The agent starts with `ensure_browser`, which reuses a browser that is already running with a debugging port, or launches one. To make launches use a particular profile, set `MCP_BROWSER_USER_DATA_DIR`; see [Configuration](docs/configuration.md) for this, native Windows, WSL, and Firefox.
|
|
34
36
|
|
|
35
37
|
## What It Does
|
|
@@ -47,7 +49,7 @@ Your agent gets 46 browser tools over MCP: open or attach to tabs, click, type,
|
|
|
47
49
|
- **Right where you work.** It attaches to the browser you already use, with its logins, tabs, and extensions, and speaks to Chrome, Edge, and Firefox with the same tools.
|
|
48
50
|
- **A debugger at hand.** Console messages with stack traces, network requests and HAR export, cookies and storage, and a one-call debug report.
|
|
49
51
|
|
|
50
|
-
Against Playwright MCP and Chrome DevTools MCP, on the same tasks with six models, it took the fewest turns and the least time with every model and cost the least on average
|
|
52
|
+
Against Playwright MCP and Chrome DevTools MCP, on the same tasks with six models, it took the fewest turns and the least time with every model and cost the least on average and with four of the six: see the [comparison](https://hinaser.github.io/mcp-browser-dev-tools/comparison.html).
|
|
51
53
|
|
|
52
54
|
## One Call, Start To Finish
|
|
53
55
|
|
|
@@ -184,6 +186,14 @@ Every setting, per-client examples, and how the server reuses or launches browse
|
|
|
184
186
|
- The server only connects to loopback browser endpoints unless you set `MCP_BROWSER_ALLOW_REMOTE_ENDPOINTS=1`.
|
|
185
187
|
- Tools both read and act on the page: they click, type, navigate, and run page JavaScript through `evaluate_js`, as whoever the browser profile is signed in as. Point the server at a profile you are willing to let an agent use.
|
|
186
188
|
- `MCP_BROWSER_ENABLE_EVAL=0` removes `evaluate_js` and the `expression` field of `wait_for` and `run_steps` conditions. This narrows the tool surface rather than drawing a security boundary: the other tools already read cookies and storage and can navigate anywhere. To approve page scripts one at a time, use your MCP client's tool permissions, and note that `wait_for` and `run_steps` calls can carry scripts too.
|
|
189
|
+
- `upload_file` gives a page files from the server's working directory, the temp directory, and `MCP_BROWSER_UPLOAD_DIRS`. Your MCP client chooses the working directory: if it starts the server in your home folder, every file there qualifies.
|
|
190
|
+
- `navigate` opens any URL the browser can, `file://` included. Screenshots, traces, and videos are saved to any absolute path the agent names, and replace an existing file of the same type only when the call passes `overwrite`.
|
|
191
|
+
- `MCP_BROWSER_TOOLS` changes which tools are listed, not which can run: the others stay callable through `more_tools`.
|
|
192
|
+
- The install commands use `@latest`, so a new release runs on the next start. To run only a version you have checked, pin it, such as `mcp-browser-dev-tools@0.5.5`.
|
|
193
|
+
|
|
194
|
+
The server has no runtime dependencies and no install scripts, and npm releases are built by GitHub Actions from signed tags, with [provenance](https://docs.npmjs.com/generating-provenance-statements). To check it yourself before installing, give your coding agent this prompt:
|
|
195
|
+
|
|
196
|
+
> Check https://github.com/Hinaser/mcp-browser-dev-tools for malicious or risky code before I install it. Look for network requests that leave this machine, data sent or saved outside the browser, downloaded code that gets run, and whether the npm package mcp-browser-dev-tools matches the source.
|
|
187
197
|
|
|
188
198
|
## Compared With Playwright
|
|
189
199
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mcp-browser-dev-tools",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
3
|
+
"mcpName": "io.github.Hinaser/mcp-browser-dev-tools",
|
|
4
|
+
"version": "0.5.5",
|
|
5
|
+
"description": "MCP server for browser use by AI agents: batch actions, waits, and checks into one call on Chrome, Edge, or Firefox (CDP and WebDriver BiDi)",
|
|
5
6
|
"author": "Hinaser <rindo.hinase@gmail.com>",
|
|
6
7
|
"license": "MIT",
|
|
7
8
|
"type": "module",
|
|
@@ -77,6 +78,9 @@
|
|
|
77
78
|
"mcp-server",
|
|
78
79
|
"model-context-protocol",
|
|
79
80
|
"browser",
|
|
81
|
+
"ai-agents",
|
|
82
|
+
"browser-automation",
|
|
83
|
+
"browser-use",
|
|
80
84
|
"devtools",
|
|
81
85
|
"cdp",
|
|
82
86
|
"webdriver-bidi",
|
|
@@ -13,6 +13,7 @@ import path from "node:path";
|
|
|
13
13
|
import { promisify } from "node:util";
|
|
14
14
|
|
|
15
15
|
import {
|
|
16
|
+
assertLaunchUrl,
|
|
16
17
|
buildBrowserLaunchArgs,
|
|
17
18
|
findBrowserExecutable,
|
|
18
19
|
} from "./browser-launcher.mjs";
|
|
@@ -591,6 +592,7 @@ export async function launchBrowser(
|
|
|
591
592
|
) {
|
|
592
593
|
const family = resolveLaunchFamily(config.browserFamily, browserFamily);
|
|
593
594
|
const targetUrl = normalizeStringValue(url) ?? "about:blank";
|
|
595
|
+
assertLaunchUrl(targetUrl);
|
|
594
596
|
const resolvedPort =
|
|
595
597
|
normalizeIntegerValue(port, "port", { minimum: 1 }) ??
|
|
596
598
|
resolveDefaultPort(config, family);
|
package/src/browser-launcher.mjs
CHANGED
|
@@ -168,6 +168,30 @@ export async function detectInstalledBrowsers(env = process.env) {
|
|
|
168
168
|
};
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
+
// The launch URL goes on the browser's command line, where a value such as
|
|
172
|
+
// --flag, -flag, or (on Windows) /flag is read as a switch. Only an absolute
|
|
173
|
+
// URL that starts with its scheme gets there, so its first character is a
|
|
174
|
+
// letter and it can never carry a switch past the unsafeArgs gate or the
|
|
175
|
+
// loopback check on the debugging address.
|
|
176
|
+
export function assertLaunchUrl(url) {
|
|
177
|
+
let protocol;
|
|
178
|
+
try {
|
|
179
|
+
protocol = new URL(url).protocol;
|
|
180
|
+
} catch {
|
|
181
|
+
protocol = null;
|
|
182
|
+
}
|
|
183
|
+
if (
|
|
184
|
+
typeof url !== "string" ||
|
|
185
|
+
!/^[a-z][a-z0-9+.-]*:/i.test(url) ||
|
|
186
|
+
!protocol ||
|
|
187
|
+
protocol === "javascript:"
|
|
188
|
+
) {
|
|
189
|
+
throw new Error(
|
|
190
|
+
"url must be an absolute URL that starts with its scheme, such as https://example.com or about:blank",
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
171
195
|
export function buildBrowserLaunchArgs({
|
|
172
196
|
family,
|
|
173
197
|
url,
|
|
@@ -179,6 +203,7 @@ export function buildBrowserLaunchArgs({
|
|
|
179
203
|
if (!url) {
|
|
180
204
|
throw new Error("A target URL is required");
|
|
181
205
|
}
|
|
206
|
+
assertLaunchUrl(url);
|
|
182
207
|
|
|
183
208
|
const args = [];
|
|
184
209
|
if (family === "firefox") {
|
package/src/cdp-client.mjs
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
InFlightRequests,
|
|
10
10
|
summarizeNetworkRequests,
|
|
11
11
|
} from "./session-events.mjs";
|
|
12
|
-
import { DEFAULT_CDP_BASE_URL } from "./config.mjs";
|
|
12
|
+
import { DEFAULT_CDP_BASE_URL, isLoopbackHost } from "./config.mjs";
|
|
13
13
|
import {
|
|
14
14
|
answerDialog,
|
|
15
15
|
createDialogAnswers,
|
|
@@ -479,6 +479,25 @@ function videoGapWarnings(state) {
|
|
|
479
479
|
];
|
|
480
480
|
}
|
|
481
481
|
|
|
482
|
+
// The endpoint check in config.mjs covers the address we discover on; the
|
|
483
|
+
// browser answers with the websocket to use, so that address is checked too.
|
|
484
|
+
export function assertDebuggerSocketUrl(websocketUrl, config) {
|
|
485
|
+
if (config?.allowRemoteEndpoints) {
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
let hostname;
|
|
489
|
+
try {
|
|
490
|
+
hostname = new URL(websocketUrl).hostname;
|
|
491
|
+
} catch {
|
|
492
|
+
hostname = null;
|
|
493
|
+
}
|
|
494
|
+
if (!isLoopbackHost(hostname)) {
|
|
495
|
+
throw new Error(
|
|
496
|
+
"The browser's debugger websocket is not on this machine; set MCP_BROWSER_ALLOW_REMOTE_ENDPOINTS=1 to allow it",
|
|
497
|
+
);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
482
501
|
export class CdpSession {
|
|
483
502
|
constructor(target, options = {}) {
|
|
484
503
|
this.id = newSessionId();
|
|
@@ -527,6 +546,7 @@ export class CdpSession {
|
|
|
527
546
|
);
|
|
528
547
|
}
|
|
529
548
|
|
|
549
|
+
assertDebuggerSocketUrl(this.target.webSocketDebuggerUrl, this.config);
|
|
530
550
|
this.websocket = new WebSocket(this.target.webSocketDebuggerUrl);
|
|
531
551
|
|
|
532
552
|
await new Promise((resolve, reject) => {
|
|
@@ -2462,6 +2482,7 @@ export class CdpSessionManager {
|
|
|
2462
2482
|
this.lastAttemptedBaseUrl = baseUrl;
|
|
2463
2483
|
const url = new URL(pathname, `${baseUrl}/`);
|
|
2464
2484
|
const response = await fetch(url, {
|
|
2485
|
+
redirect: "error",
|
|
2465
2486
|
signal: AbortSignal.timeout(this.fetchTimeoutMs),
|
|
2466
2487
|
});
|
|
2467
2488
|
return parseJson(response);
|
|
@@ -2535,6 +2556,7 @@ export class CdpSessionManager {
|
|
|
2535
2556
|
throw new Error("Browser endpoint does not expose a debugger websocket");
|
|
2536
2557
|
}
|
|
2537
2558
|
|
|
2559
|
+
assertDebuggerSocketUrl(info.webSocketDebuggerUrl, this.config);
|
|
2538
2560
|
const websocket = new WebSocket(info.webSocketDebuggerUrl);
|
|
2539
2561
|
|
|
2540
2562
|
return new Promise((resolve, reject) => {
|
package/src/tcp-relay.mjs
CHANGED
|
@@ -105,6 +105,16 @@ export function resolveRelayOptions(
|
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
+
const targetHost = normalizeHost(
|
|
109
|
+
options["target-host"],
|
|
110
|
+
DEFAULT_RELAY_TARGET_HOST,
|
|
111
|
+
);
|
|
112
|
+
if (!isLoopbackHost(targetHost) && !allowsRemoteEndpoints(env)) {
|
|
113
|
+
throw new Error(
|
|
114
|
+
"--target-host must be loopback unless MCP_BROWSER_ALLOW_REMOTE_ENDPOINTS=1",
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
108
118
|
return {
|
|
109
119
|
listenHost,
|
|
110
120
|
listenPort: parseRelayPort(
|
|
@@ -112,10 +122,7 @@ export function resolveRelayOptions(
|
|
|
112
122
|
DEFAULT_RELAY_LISTEN_PORT,
|
|
113
123
|
"--listen-port",
|
|
114
124
|
),
|
|
115
|
-
targetHost
|
|
116
|
-
options["target-host"],
|
|
117
|
-
DEFAULT_RELAY_TARGET_HOST,
|
|
118
|
-
),
|
|
125
|
+
targetHost,
|
|
119
126
|
targetPort: parseRelayPort(
|
|
120
127
|
options["target-port"],
|
|
121
128
|
DEFAULT_RELAY_TARGET_PORT,
|