mcp-browser-dev-tools 0.0.1-beta.3 → 0.0.1-beta.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 +137 -16
- package/package.json +2 -1
- package/src/browser-launcher.mjs +3 -0
- package/src/cli.mjs +75 -7
- package/src/page-context.mjs +18 -3
package/README.md
CHANGED
|
@@ -25,6 +25,8 @@ It is designed for a local trust boundary:
|
|
|
25
25
|
|
|
26
26
|
If you are trying the prerelease from npm, replace `mcp-browser-dev-tools` below with `mcp-browser-dev-tools@beta`.
|
|
27
27
|
|
|
28
|
+
The published package name stays `mcp-browser-dev-tools`. The preferred installed CLI command is `mbdt`.
|
|
29
|
+
|
|
28
30
|
One-off execution with `npx`:
|
|
29
31
|
|
|
30
32
|
```bash
|
|
@@ -35,14 +37,14 @@ Global install:
|
|
|
35
37
|
|
|
36
38
|
```bash
|
|
37
39
|
npm install -g mcp-browser-dev-tools
|
|
38
|
-
|
|
40
|
+
mbdt serve
|
|
39
41
|
```
|
|
40
42
|
|
|
41
43
|
Project-local install:
|
|
42
44
|
|
|
43
45
|
```bash
|
|
44
46
|
npm install mcp-browser-dev-tools
|
|
45
|
-
npx
|
|
47
|
+
npx mbdt serve
|
|
46
48
|
```
|
|
47
49
|
|
|
48
50
|
## Try It Locally
|
|
@@ -54,13 +56,20 @@ For Windows, WSL, macOS, and Linux-specific setup paths, see [docs/setup.md](doc
|
|
|
54
56
|
Quick Chromium flow:
|
|
55
57
|
|
|
56
58
|
```bash
|
|
57
|
-
# Launch a local browser with remote debugging enabled
|
|
58
|
-
|
|
59
|
+
# Launch a local browser with remote debugging enabled.
|
|
60
|
+
# open waits for the debug endpoint and prints the doctor summary automatically.
|
|
61
|
+
npx -y mcp-browser-dev-tools@beta open about:blank --family chromium
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
If you want to verify a specific app URL too:
|
|
59
65
|
|
|
60
|
-
|
|
61
|
-
npx -y mcp-browser-dev-tools@beta doctor --url
|
|
66
|
+
```bash
|
|
67
|
+
npx -y mcp-browser-dev-tools@beta doctor --url http://127.0.0.1:3000
|
|
68
|
+
```
|
|
62
69
|
|
|
63
|
-
|
|
70
|
+
Then start the MCP server in a dedicated terminal:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
64
73
|
npx -y mcp-browser-dev-tools@beta serve
|
|
65
74
|
```
|
|
66
75
|
|
|
@@ -76,7 +85,78 @@ If you need to bridge Windows Chrome into WSL without changing WSL networking mo
|
|
|
76
85
|
|
|
77
86
|
## MCP Client Configuration
|
|
78
87
|
|
|
79
|
-
|
|
88
|
+
Use the same server command across MCP clients:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
npx -y mcp-browser-dev-tools@beta serve
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
If you installed the package already, the shorter equivalent is:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
mbdt serve
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Codex
|
|
101
|
+
|
|
102
|
+
Add the server with the Codex CLI:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
codex mcp add browser-devtools \
|
|
106
|
+
--env MCP_BROWSER_FAMILY=chromium \
|
|
107
|
+
--env CDP_BASE_URL=http://127.0.0.1:9222 \
|
|
108
|
+
-- npx -y mcp-browser-dev-tools@beta serve
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Equivalent `~/.codex/config.toml` entry:
|
|
112
|
+
|
|
113
|
+
```toml
|
|
114
|
+
[mcp_servers.browser-devtools]
|
|
115
|
+
command = "npx"
|
|
116
|
+
args = ["-y", "mcp-browser-dev-tools@beta", "serve"]
|
|
117
|
+
|
|
118
|
+
[mcp_servers.browser-devtools.env]
|
|
119
|
+
MCP_BROWSER_FAMILY = "chromium"
|
|
120
|
+
CDP_BASE_URL = "http://127.0.0.1:9222"
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Claude Code
|
|
124
|
+
|
|
125
|
+
Add the server with Claude Code:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
claude mcp add browser-devtools --scope user \
|
|
129
|
+
--env MCP_BROWSER_FAMILY=chromium \
|
|
130
|
+
--env CDP_BASE_URL=http://127.0.0.1:9222 \
|
|
131
|
+
-- npx -y mcp-browser-dev-tools@beta serve
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
On native Windows, wrap `npx` with `cmd /c`:
|
|
135
|
+
|
|
136
|
+
```powershell
|
|
137
|
+
claude mcp add browser-devtools --scope user --env MCP_BROWSER_FAMILY=chromium --env CDP_BASE_URL=http://127.0.0.1:9222 -- cmd /c npx -y mcp-browser-dev-tools@beta serve
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Equivalent `.mcp.json` shape:
|
|
141
|
+
|
|
142
|
+
```json
|
|
143
|
+
{
|
|
144
|
+
"mcpServers": {
|
|
145
|
+
"browser-devtools": {
|
|
146
|
+
"command": "npx",
|
|
147
|
+
"args": ["-y", "mcp-browser-dev-tools@beta", "serve"],
|
|
148
|
+
"env": {
|
|
149
|
+
"MCP_BROWSER_FAMILY": "chromium",
|
|
150
|
+
"CDP_BASE_URL": "http://127.0.0.1:9222"
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Cursor
|
|
158
|
+
|
|
159
|
+
Cursor reads MCP servers from `mcp.json`:
|
|
80
160
|
|
|
81
161
|
```json
|
|
82
162
|
{
|
|
@@ -93,7 +173,34 @@ Generic stdio client configuration:
|
|
|
93
173
|
}
|
|
94
174
|
```
|
|
95
175
|
|
|
96
|
-
|
|
176
|
+
### Common Variants
|
|
177
|
+
|
|
178
|
+
Firefox:
|
|
179
|
+
|
|
180
|
+
```json
|
|
181
|
+
{
|
|
182
|
+
"MCP_BROWSER_FAMILY": "firefox",
|
|
183
|
+
"FIREFOX_BIDI_WS_URL": "ws://127.0.0.1:9222"
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
Windows browser bridged into WSL through the relay:
|
|
188
|
+
|
|
189
|
+
```json
|
|
190
|
+
{
|
|
191
|
+
"MCP_BROWSER_FAMILY": "chromium",
|
|
192
|
+
"MCP_BROWSER_ALLOW_REMOTE_ENDPOINTS": "1",
|
|
193
|
+
"CDP_BASE_URL": "http://<windows-host-ip>:9223"
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Enable `evaluate_js`:
|
|
198
|
+
|
|
199
|
+
```json
|
|
200
|
+
{
|
|
201
|
+
"MCP_BROWSER_ENABLE_EVAL": "1"
|
|
202
|
+
}
|
|
203
|
+
```
|
|
97
204
|
|
|
98
205
|
## Commands
|
|
99
206
|
|
|
@@ -107,10 +214,11 @@ For Firefox, switch `MCP_BROWSER_FAMILY` to `firefox` and set `FIREFOX_BIDI_WS_U
|
|
|
107
214
|
Examples:
|
|
108
215
|
|
|
109
216
|
```bash
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
217
|
+
mbdt doctor
|
|
218
|
+
mbdt doctor --url http://127.0.0.1:3000
|
|
219
|
+
mbdt open http://127.0.0.1:3000 --family chromium
|
|
220
|
+
mbdt open about:blank --family firefox --user-data-dir /tmp/mbdt-firefox
|
|
221
|
+
mbdt relay --wsl
|
|
114
222
|
```
|
|
115
223
|
|
|
116
224
|
## Configuration
|
|
@@ -161,9 +269,9 @@ For tools that take `sessionId`, call `attach_tab` first and reuse the returned
|
|
|
161
269
|
Interaction and inspection tools accept these locator forms:
|
|
162
270
|
|
|
163
271
|
- CSS selectors such as `#app button.primary` or `css=.modal button`
|
|
164
|
-
- visible-text lookup such as `text
|
|
165
|
-
- role plus accessible name such as `role=button[name="
|
|
166
|
-
- accessible-name lookup such as `name
|
|
272
|
+
- visible-text lookup such as `text=Open settings`
|
|
273
|
+
- role plus accessible name such as `role=button[name="Open settings"]`
|
|
274
|
+
- accessible-name lookup such as `name=Open settings`
|
|
167
275
|
|
|
168
276
|
`inspect_element` returns layout and accessibility-focused metadata including bounding box, visibility flags, interactivity flags, accessible name, inferred role, and a subset of computed styles. Invalid CSS selectors now return an explicit locator error instead of a generic DOM failure.
|
|
169
277
|
|
|
@@ -178,6 +286,19 @@ Interaction and inspection tools accept these locator forms:
|
|
|
178
286
|
- In WSL, Linux browser executables are preferred before Windows fallback paths
|
|
179
287
|
- For Windows Chrome + WSL, prefer the `relay` command over changing Chrome's remote debugging bind
|
|
180
288
|
|
|
289
|
+
## Why Not Playwright?
|
|
290
|
+
|
|
291
|
+
Playwright is still the stronger choice for deterministic browser automation and end-to-end tests. It has a more mature locator model, assertions, waiting semantics, tracing, and CI story.
|
|
292
|
+
|
|
293
|
+
`mcp-browser-dev-tools` solves a different problem:
|
|
294
|
+
|
|
295
|
+
- it is MCP-native, so AI clients call a bounded tool surface instead of generating and executing Playwright scripts
|
|
296
|
+
- it attaches to an already-open browser tab and inspects the current session state, cookies, login state, extensions, console, and network history
|
|
297
|
+
- it is designed for local AI debugging workflows, including loopback-only defaults, opt-in evaluation, and the Windows-to-WSL relay path
|
|
298
|
+
- it presents one MCP interface across Chromium CDP and Firefox BiDi instead of requiring the AI client to know browser protocol details
|
|
299
|
+
|
|
300
|
+
Use Playwright when you want reproducible automation. Use this project when you want an AI assistant to inspect and manipulate a live browser session through MCP.
|
|
301
|
+
|
|
181
302
|
## Debugging Notes
|
|
182
303
|
|
|
183
304
|
- `attach_tab` now seeds network history from the Performance API so already-loaded pages still show useful requests
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mcp-browser-dev-tools",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
3
|
+
"version": "0.0.1-beta.5",
|
|
4
4
|
"description": "Local MCP server for Chromium DevTools Protocol and Firefox WebDriver BiDi",
|
|
5
5
|
"author": "Hinaser <rindo.hinase@gmail.com>",
|
|
6
6
|
"type": "module",
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"README.md"
|
|
40
40
|
],
|
|
41
41
|
"bin": {
|
|
42
|
+
"mbdt": "cli.mjs",
|
|
42
43
|
"mcp-browser-dev-tools": "cli.mjs"
|
|
43
44
|
},
|
|
44
45
|
"keywords": [
|
package/src/browser-launcher.mjs
CHANGED
|
@@ -149,6 +149,9 @@ export function buildBrowserLaunchArgs({
|
|
|
149
149
|
|
|
150
150
|
const args = [];
|
|
151
151
|
if (family === "firefox") {
|
|
152
|
+
if (userDataDir) {
|
|
153
|
+
args.push("-new-instance", "-profile", userDataDir);
|
|
154
|
+
}
|
|
152
155
|
if (remoteDebuggingPort) {
|
|
153
156
|
args.push(`--remote-debugging-port=${remoteDebuggingPort}`);
|
|
154
157
|
}
|
package/src/cli.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { spawn } from "node:child_process";
|
|
3
|
+
import { mkdir } from "node:fs/promises";
|
|
3
4
|
import process from "node:process";
|
|
4
5
|
import { pathToFileURL } from "node:url";
|
|
5
6
|
|
|
@@ -68,7 +69,9 @@ function printUsage() {
|
|
|
68
69
|
" --family <name> chromium or firefox",
|
|
69
70
|
" --port <port> remote debugging port",
|
|
70
71
|
" --address <host> remote debugging address for Chromium",
|
|
71
|
-
" --user-data-dir <p> optional
|
|
72
|
+
" --user-data-dir <p> optional Chromium user data dir or Firefox profile dir",
|
|
73
|
+
" --wait-ms <ms> wait for the debug endpoint and print doctor output",
|
|
74
|
+
" --no-doctor skip the post-launch doctor check",
|
|
72
75
|
"",
|
|
73
76
|
"Relay options:",
|
|
74
77
|
" --listen-host <host> relay bind host (defaults to 127.0.0.1)",
|
|
@@ -85,6 +88,21 @@ function printVersion() {
|
|
|
85
88
|
process.stdout.write(`${PACKAGE_VERSION}\n`);
|
|
86
89
|
}
|
|
87
90
|
|
|
91
|
+
function sleep(ms) {
|
|
92
|
+
return new Promise((resolve) => {
|
|
93
|
+
setTimeout(resolve, ms);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function isHttpLikeUrl(value) {
|
|
98
|
+
try {
|
|
99
|
+
const url = new URL(value);
|
|
100
|
+
return url.protocol === "http:" || url.protocol === "https:";
|
|
101
|
+
} catch {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
88
106
|
async function runServe() {
|
|
89
107
|
const app = createBrowserDevToolsApp();
|
|
90
108
|
app.installSignalHandlers();
|
|
@@ -137,17 +155,23 @@ async function runOpen(positional, options) {
|
|
|
137
155
|
family === "firefox"
|
|
138
156
|
? new URL(config.firefoxBidiWsUrl).port || "9222"
|
|
139
157
|
: new URL(config.cdpBaseUrl).port || "9222";
|
|
158
|
+
const resolvedPort =
|
|
159
|
+
typeof options.port === "string" ? options.port : defaultPort;
|
|
160
|
+
const userDataDir =
|
|
161
|
+
typeof options["user-data-dir"] === "string"
|
|
162
|
+
? options["user-data-dir"]
|
|
163
|
+
: undefined;
|
|
164
|
+
|
|
165
|
+
if (family === "firefox" && userDataDir) {
|
|
166
|
+
await mkdir(userDataDir, { recursive: true });
|
|
167
|
+
}
|
|
140
168
|
|
|
141
169
|
const args = buildBrowserLaunchArgs({
|
|
142
170
|
family,
|
|
143
171
|
url,
|
|
144
|
-
remoteDebuggingPort:
|
|
145
|
-
typeof options.port === "string" ? options.port : defaultPort,
|
|
172
|
+
remoteDebuggingPort: resolvedPort,
|
|
146
173
|
remoteDebuggingAddress: requestedAddress || undefined,
|
|
147
|
-
userDataDir
|
|
148
|
-
family === "chromium" && typeof options["user-data-dir"] === "string"
|
|
149
|
-
? options["user-data-dir"]
|
|
150
|
-
: undefined,
|
|
174
|
+
userDataDir,
|
|
151
175
|
});
|
|
152
176
|
|
|
153
177
|
const child = spawn(executable, args, {
|
|
@@ -159,6 +183,50 @@ async function runOpen(positional, options) {
|
|
|
159
183
|
process.stdout.write(
|
|
160
184
|
`launched ${family} browser: ${executable} ${args.join(" ")}\n`,
|
|
161
185
|
);
|
|
186
|
+
|
|
187
|
+
if (options["no-doctor"] === true) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const waitMs =
|
|
192
|
+
typeof options["wait-ms"] === "string"
|
|
193
|
+
? Number.parseInt(options["wait-ms"], 10)
|
|
194
|
+
: 5000;
|
|
195
|
+
const timeoutMs = Number.isInteger(waitMs) && waitMs >= 0 ? waitMs : 5000;
|
|
196
|
+
const startedAt = Date.now();
|
|
197
|
+
const doctorEnv = {
|
|
198
|
+
...process.env,
|
|
199
|
+
MCP_BROWSER_FAMILY: family,
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
if (family === "firefox") {
|
|
203
|
+
doctorEnv.FIREFOX_BIDI_WS_URL = `ws://127.0.0.1:${resolvedPort}`;
|
|
204
|
+
} else {
|
|
205
|
+
const address = requestedAddress || "127.0.0.1";
|
|
206
|
+
doctorEnv.CDP_BASE_URL = `http://${address}:${resolvedPort}`;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
let report = await collectDoctorReport({
|
|
210
|
+
env: doctorEnv,
|
|
211
|
+
url: isHttpLikeUrl(url) ? url : null,
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
while (
|
|
215
|
+
!report.browserStatus.available &&
|
|
216
|
+
Date.now() - startedAt < timeoutMs
|
|
217
|
+
) {
|
|
218
|
+
await sleep(250);
|
|
219
|
+
report = await collectDoctorReport({
|
|
220
|
+
env: doctorEnv,
|
|
221
|
+
url: isHttpLikeUrl(url) ? url : null,
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
process.stdout.write(`${renderDoctorReport(report)}\n`);
|
|
226
|
+
|
|
227
|
+
if (!report.browserStatus.available) {
|
|
228
|
+
process.exitCode = 1;
|
|
229
|
+
}
|
|
162
230
|
}
|
|
163
231
|
|
|
164
232
|
async function runRelay(options) {
|
package/src/page-context.mjs
CHANGED
|
@@ -214,6 +214,21 @@ export function buildPageContextExpression(
|
|
|
214
214
|
);
|
|
215
215
|
}
|
|
216
216
|
|
|
217
|
+
function summarizeLocator(locator) {
|
|
218
|
+
if (!locator || typeof locator !== "object") {
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const summary = {};
|
|
223
|
+
for (const key of ["locator", "strategy", "query", "role", "name", "error"]) {
|
|
224
|
+
if (locator[key] !== undefined) {
|
|
225
|
+
summary[key] = locator[key];
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return summary;
|
|
230
|
+
}
|
|
231
|
+
|
|
217
232
|
function describeElement(element, locator) {
|
|
218
233
|
const rect = element.getBoundingClientRect();
|
|
219
234
|
const style = getComputedStyle(element);
|
|
@@ -221,7 +236,7 @@ export function buildPageContextExpression(
|
|
|
221
236
|
const accessibleName = getAccessibleName(element);
|
|
222
237
|
|
|
223
238
|
return {
|
|
224
|
-
locator,
|
|
239
|
+
locator: summarizeLocator(locator),
|
|
225
240
|
tagName: element.tagName,
|
|
226
241
|
id: element.getAttribute("id"),
|
|
227
242
|
className: element.getAttribute("class"),
|
|
@@ -413,7 +428,7 @@ export function buildPageContextExpression(
|
|
|
413
428
|
browserFamily: payload.browserFamily,
|
|
414
429
|
selector: rawLocator,
|
|
415
430
|
found: false,
|
|
416
|
-
locator: resolved,
|
|
431
|
+
locator: summarizeLocator(resolved),
|
|
417
432
|
error: resolved.error,
|
|
418
433
|
};
|
|
419
434
|
}
|
|
@@ -423,7 +438,7 @@ export function buildPageContextExpression(
|
|
|
423
438
|
browserFamily: payload.browserFamily,
|
|
424
439
|
selector: rawLocator,
|
|
425
440
|
found: false,
|
|
426
|
-
locator: resolved,
|
|
441
|
+
locator: summarizeLocator(resolved),
|
|
427
442
|
};
|
|
428
443
|
}
|
|
429
444
|
|