bidi-browser-mcp 0.1.9 → 0.2.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.
- package/LICENSE +21 -21
- package/README.md +398 -343
- package/dist/bin.js +3 -2
- package/dist/config.js +4 -0
- package/dist/connection/bidi-client.d.ts +13 -1
- package/dist/connection/bidi-client.js +59 -8
- package/dist/connection/browser-discovery.d.ts +20 -0
- package/dist/connection/browser-discovery.js +76 -12
- package/dist/connection/chromium-mapper.d.ts +9 -0
- package/dist/connection/chromium-mapper.js +24 -0
- package/dist/connection/event-pipeline.d.ts +15 -2
- package/dist/connection/event-pipeline.js +45 -3
- package/dist/connection/protocol-probe.d.ts +43 -0
- package/dist/connection/protocol-probe.js +112 -0
- package/dist/index.js +6 -0
- package/dist/session/session-manager.d.ts +26 -1
- package/dist/session/session-manager.js +262 -6
- package/dist/snapshot/cache.d.ts +4 -0
- package/dist/snapshot/cache.js +8 -0
- package/dist/snapshot/dom-snapshot.js +190 -181
- package/dist/snapshot/element-script.d.ts +23 -0
- package/dist/snapshot/element-script.js +70 -0
- package/dist/snapshot/token-optimizer.js +26 -8
- package/dist/snapshot/uid-verify.d.ts +43 -0
- package/dist/snapshot/uid-verify.js +154 -0
- package/dist/tools/browser.js +21 -6
- package/dist/tools/context.js +4 -6
- package/dist/tools/interact.d.ts +1 -0
- package/dist/tools/interact.js +593 -0
- package/dist/tools/network.d.ts +1 -0
- package/dist/tools/network.js +166 -0
- package/dist/tools/page.js +53 -2
- package/dist/tools/ping.js +5 -1
- package/dist/tools/script.d.ts +1 -0
- package/dist/tools/script.js +166 -0
- package/dist/types.d.ts +50 -1
- package/dist/utils/bidi-value.d.ts +10 -0
- package/dist/utils/bidi-value.js +56 -0
- package/dist/utils/errors.d.ts +3 -1
- package/dist/utils/errors.js +13 -7
- package/dist/utils/redact.d.ts +16 -0
- package/dist/utils/redact.js +47 -0
- package/package.json +86 -86
package/README.md
CHANGED
|
@@ -1,343 +1,398 @@
|
|
|
1
|
-
<p align="center">
|
|
2
|
-
<h1 align="center">BiDi Browser MCP Server</h1>
|
|
3
|
-
<p align="center">
|
|
4
|
-
<strong>Control your real Firefox over the W3C standard protocol.</strong><br>
|
|
5
|
-
Keep your cookies. Keep your sessions. Keep your containers.
|
|
6
|
-
</p>
|
|
7
|
-
</p>
|
|
8
|
-
|
|
9
|
-
<p align="center">
|
|
10
|
-
<img src="https://img.shields.io/badge/version-0.1.7-blue" alt="Version">
|
|
11
|
-
<img src="https://img.shields.io/badge/status-connect-orange" alt="Status">
|
|
12
|
-
<img src="https://img.shields.io/badge/node-%3E%3D20-brightgreen" alt="Node">
|
|
13
|
-
<img src="https://img.shields.io/badge/license-MIT-yellow" alt="License">
|
|
14
|
-
</p>
|
|
15
|
-
|
|
16
|
-
---
|
|
17
|
-
|
|
18
|
-
## Status
|
|
19
|
-
|
|
20
|
-
v0.1.9 — first public npm release. The stdio MCP server exposes `ping`,
|
|
21
|
-
`browser`, `tabs`, `page` (snapshot/content), `console`, `observe`, `context`
|
|
22
|
-
(containers), `spaces` (Zen), and `cleanup`. Socket drops clear session state
|
|
23
|
-
honestly and the next connect recovers. Chromium browsers are supported without
|
|
24
|
-
chromedriver: the `chromium-bidi` mapper runs inside this server and translates
|
|
25
|
-
BiDi to CDP, with Firefox-only tools gated by a clear `UNSUPPORTED` error.
|
|
26
|
-
|
|
27
|
-
v1 attaches to a Firefox you start; it does not launch, profile-manage, or close
|
|
28
|
-
the browser. Launch/private/incognito control is future work.
|
|
29
|
-
|
|
30
|
-
The full design and protocol research ship on the `dev` branch. `main` carries
|
|
31
|
-
product code and release artifacts only.
|
|
32
|
-
|
|
33
|
-
## Why BiDi
|
|
34
|
-
|
|
35
|
-
Firefox removed CDP in Firefox 141. WebDriver BiDi is the W3C standard that
|
|
36
|
-
replaced it, and it is native in Firefox 129+ — no driver binary, no
|
|
37
|
-
Puppeteer/Playwright, no browser download.
|
|
38
|
-
|
|
39
|
-
Firefox-family browsers such as Zen, LibreWolf, Waterfox, and Floorp should work
|
|
40
|
-
once their Remote Agent is enabled; profile discovery still needs testing per
|
|
41
|
-
browser.
|
|
42
|
-
|
|
43
|
-
This server connects to an **already-running Firefox** over its native BiDi
|
|
44
|
-
WebSocket. Your logins, cookies, extensions, and containers stay intact.
|
|
45
|
-
|
|
46
|
-
## Tool surface
|
|
47
|
-
|
|
48
|
-
Nine tools
|
|
49
|
-
`
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
- `
|
|
56
|
-
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
- `
|
|
62
|
-
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
-
|
|
74
|
-
-
|
|
75
|
-
|
|
76
|
-
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
`
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
```bash
|
|
240
|
-
|
|
241
|
-
pnpm
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
```json
|
|
250
|
-
{
|
|
251
|
-
"mcpServers": {
|
|
252
|
-
"bidi-browser": {
|
|
253
|
-
"command": "
|
|
254
|
-
"args": ["
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
```
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<h1 align="center">BiDi Browser MCP Server</h1>
|
|
3
|
+
<p align="center">
|
|
4
|
+
<strong>Control your real Firefox over the W3C standard protocol.</strong><br>
|
|
5
|
+
Keep your cookies. Keep your sessions. Keep your containers.
|
|
6
|
+
</p>
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<img src="https://img.shields.io/badge/version-0.1.7-blue" alt="Version">
|
|
11
|
+
<img src="https://img.shields.io/badge/status-connect-orange" alt="Status">
|
|
12
|
+
<img src="https://img.shields.io/badge/node-%3E%3D20-brightgreen" alt="Node">
|
|
13
|
+
<img src="https://img.shields.io/badge/license-MIT-yellow" alt="License">
|
|
14
|
+
</p>
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Status
|
|
19
|
+
|
|
20
|
+
v0.1.9 — first public npm release. The stdio MCP server exposes `ping`,
|
|
21
|
+
`browser`, `tabs`, `page` (snapshot/content), `console`, `observe`, `context`
|
|
22
|
+
(containers), `spaces` (Zen), and `cleanup`. Socket drops clear session state
|
|
23
|
+
honestly and the next connect recovers. Chromium browsers are supported without
|
|
24
|
+
chromedriver: the `chromium-bidi` mapper runs inside this server and translates
|
|
25
|
+
BiDi to CDP, with Firefox-only tools gated by a clear `UNSUPPORTED` error.
|
|
26
|
+
|
|
27
|
+
v1 attaches to a Firefox you start; it does not launch, profile-manage, or close
|
|
28
|
+
the browser. Launch/private/incognito control is future work.
|
|
29
|
+
|
|
30
|
+
The full design and protocol research ship on the `dev` branch. `main` carries
|
|
31
|
+
product code and release artifacts only.
|
|
32
|
+
|
|
33
|
+
## Why BiDi
|
|
34
|
+
|
|
35
|
+
Firefox removed CDP in Firefox 141. WebDriver BiDi is the W3C standard that
|
|
36
|
+
replaced it, and it is native in Firefox 129+ — no driver binary, no
|
|
37
|
+
Puppeteer/Playwright, no browser download.
|
|
38
|
+
|
|
39
|
+
Firefox-family browsers such as Zen, LibreWolf, Waterfox, and Floorp should work
|
|
40
|
+
once their Remote Agent is enabled; profile discovery still needs testing per
|
|
41
|
+
browser.
|
|
42
|
+
|
|
43
|
+
This server connects to an **already-running Firefox** over its native BiDi
|
|
44
|
+
WebSocket. Your logins, cookies, extensions, and containers stay intact.
|
|
45
|
+
|
|
46
|
+
## Tool surface
|
|
47
|
+
|
|
48
|
+
Nine tools in `core`, plus `network` (visible with `BIDI_TOOLSET=network` or
|
|
49
|
+
`devtools`): `ping` · `browser` · `tabs` · `page` · `interact` · `console` ·
|
|
50
|
+
`observe` · `context` · `spaces` · `cleanup` · `script` · `network`.
|
|
51
|
+
|
|
52
|
+
- `page` — snapshot (uid element map), readable text, and `navigate`
|
|
53
|
+
(`wait: none | domContentLoaded | load`; failures map to
|
|
54
|
+
`NAVIGATION_FAILED`).
|
|
55
|
+
- `interact` — act on snapshot uids: `click` `type` `clear` `press` `check`
|
|
56
|
+
`select` `scroll` `upload`. Every action re-verifies the uid against the
|
|
57
|
+
live page first (`ELEMENT_NOT_FOUND` / `STALE_UID` when the page moved on);
|
|
58
|
+
clicks hit-test and refuse covered targets with `NOT_INTERACTABLE` (iframe
|
|
59
|
+
and shadow crossings get boundary-specific fix text); input state is always
|
|
60
|
+
released, and the snapshot cache is dropped after every dispatched action.
|
|
61
|
+
Read-write: `readOnlyHint: false`, `destructiveHint: true`.
|
|
62
|
+
- `script` — `waitFor` (safe condition polling, 250 ms interval, 120 s cap)
|
|
63
|
+
and `evaluate` (credential-unsafe; **gated by `BIDI_ALLOW_SCRIPT_EVAL=1`** —
|
|
64
|
+
the tool stays visible and the refusal names the flag).
|
|
65
|
+
- `network` — read-only waits for request/response metadata
|
|
66
|
+
(`until: request|response`, `method`, `urlPattern` filter; no bodies, no
|
|
67
|
+
interception). Requires **`BIDI_ENABLE_NETWORK=1`**; the first subscription
|
|
68
|
+
starts at session connect, so trigger-then-wait flows still match.
|
|
69
|
+
`readOnlyHint: true`.
|
|
70
|
+
|
|
71
|
+
Later — state and environment:
|
|
72
|
+
|
|
73
|
+
- `storage` — cookies first, then web storage
|
|
74
|
+
- `emulate` — locale, timezone, geolocation (tested null-reset only)
|
|
75
|
+
- network intercepts with scoped, auto-removed handlers
|
|
76
|
+
- `extensions` — Firefox, install gated by `BIDI_ALLOW_EXTENSION_INSTALL`
|
|
77
|
+
- opt-in `devtools` — `moz:debugging` (Firefox 153+) and `moz:profiler`
|
|
78
|
+
(Firefox 154+), screencast (Firefox 154+), preload scripts and realms
|
|
79
|
+
- `BIDI_OUTPUT_MODE=file`, health monitor
|
|
80
|
+
|
|
81
|
+
Firefox-specific capabilities:
|
|
82
|
+
|
|
83
|
+
- **User contexts** - isolated containers / storage (not the same as a private
|
|
84
|
+
window)
|
|
85
|
+
- **Web extension install/list/uninstall** (install is opt-in and path-gated)
|
|
86
|
+
- **Preload scripts** and script realms
|
|
87
|
+
- **Debugger and profiler** - `moz:debugging` (Firefox 153+) and
|
|
88
|
+
`moz:profiler` (Firefox 154+), opt-in `devtools` toolset
|
|
89
|
+
- **Screencast** - Firefox 154+
|
|
90
|
+
|
|
91
|
+
Not available in BiDi (compared with CDP): full accessibility tree, CSS domain,
|
|
92
|
+
heap snapshots, network/CPU throttling, touch emulation. Debugger and profiler
|
|
93
|
+
are Firefox vendor modules, not part of the core W3C command set, and do not
|
|
94
|
+
exist in every browser.
|
|
95
|
+
|
|
96
|
+
## Cross-browser roadmap
|
|
97
|
+
|
|
98
|
+
Firefox-family browsers expose a native BiDi endpoint; this server attaches to
|
|
99
|
+
it directly. Chromium browsers (Chrome, Brave, Edge, Vivaldi, Chromium) expose
|
|
100
|
+
CDP only, so this server hosts the
|
|
101
|
+
[chromium-bidi mapper](https://github.com/GoogleChromeLabs/chromium-bidi)
|
|
102
|
+
in-process — no chromedriver and no driver binary. Safari is experimental and
|
|
103
|
+
partial, and is not supported yet.
|
|
104
|
+
|
|
105
|
+
## Requirements
|
|
106
|
+
|
|
107
|
+
- Node.js 20.19+
|
|
108
|
+
- Firefox 129+ for the core surface; 153 ESR recommended; 158+ for the full
|
|
109
|
+
surface (debugger, profiler, screencast, newer emulation)
|
|
110
|
+
- Two runtime dependencies: `ws`, `@modelcontextprotocol/sdk`
|
|
111
|
+
- Optional: `chromium-bidi` for Chromium support. Its own `engines` range is
|
|
112
|
+
Node 20.19+, 21.x, or 22.12+ (22.0–22.11 are excluded); Firefox works on the
|
|
113
|
+
wider Node range either way.
|
|
114
|
+
|
|
115
|
+
## Chromium browsers (Chrome, Brave, Edge, …)
|
|
116
|
+
|
|
117
|
+
Chromium does not speak WebDriver BiDi natively: `--remote-debugging-port`
|
|
118
|
+
exposes CDP, a different protocol. When this server discovers a Chromium
|
|
119
|
+
endpoint it starts the **chromium-bidi mapper inside its own process**, hands
|
|
120
|
+
it a CDP connection, and keeps speaking BiDi to the tool layer. No chromedriver,
|
|
121
|
+
no extension, no browser restart.
|
|
122
|
+
|
|
123
|
+
1. Launch Chromium with `--remote-debugging-port=<port>`.
|
|
124
|
+
2. Approve the debugging permission dialog in the browser window when the
|
|
125
|
+
server connects (Chromium asks once per connection).
|
|
126
|
+
3. The optional mapper is installed together with this package. If it is
|
|
127
|
+
missing — an install that omitted optional dependencies, or Node outside
|
|
128
|
+
the mapper's range — Chromium sessions fail with `MISSING_DEPENDENCY` and
|
|
129
|
+
the fix names the exact command. npm users can install it beside the
|
|
130
|
+
server:
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
npm install -g chromium-bidi@158.0.8123-0 # global npm server
|
|
134
|
+
npm install chromium-bidi@158.0.8123-0 # project npm server
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
pnpm isolates global packages, so a separately installed global
|
|
138
|
+
`chromium-bidi` is not visible to the server; reinstall the server itself
|
|
139
|
+
(`pnpm add -g bidi-browser-mcp`) or run it through `pnpm dlx` instead.
|
|
140
|
+
The version is pinned because the mapper's deep import is a build artifact.
|
|
141
|
+
It also pulls `devtools-protocol` (about 30 MB on disk).
|
|
142
|
+
|
|
143
|
+
Discovery finds a running Chromium browser two ways: it reads
|
|
144
|
+
`DevToolsActivePort` from the standard Chrome, Brave, Edge, Chromium, and
|
|
145
|
+
Vivaldi user-data directories, and it resolves the `--user-data-dir` of a
|
|
146
|
+
running Chromium process — so portable installs work with no configuration.
|
|
147
|
+
`BIDI_CHROMIUM_DATA_DIR` adds directories explicitly (`;`-separated), and
|
|
148
|
+
`BIDI_WS_URL` can name the browser's
|
|
149
|
+
`ws://127.0.0.1:<port>/devtools/browser/<id>` URL. Chromium ports are never
|
|
150
|
+
probed as BiDi `/session` endpoints (they always answer 403).
|
|
151
|
+
|
|
152
|
+
`ping`, `browser`, `tabs`, `page`, `console`, `observe`, and `cleanup` work
|
|
153
|
+
through the mapper. Firefox-family features (`context`, `spaces`) refuse with
|
|
154
|
+
a clear `UNSUPPORTED` error on non-Firefox sessions. Firefox endpoints are
|
|
155
|
+
preferred when both browser families are running; set `BIDI_WS_URL` to force a
|
|
156
|
+
specific browser.
|
|
157
|
+
|
|
158
|
+
## Discovery and connect
|
|
159
|
+
|
|
160
|
+
`browser.profiles` lists every browser the server can find — Firefox-family
|
|
161
|
+
endpoints from profile discovery files, process command lines, and port probes;
|
|
162
|
+
Chromium endpoints from `DevToolsActivePort` records and running processes. Each
|
|
163
|
+
candidate carries:
|
|
164
|
+
|
|
165
|
+
| Field | Meaning |
|
|
166
|
+
| --- | --- |
|
|
167
|
+
| `id` | Stable handle for `browser.connect` — `f-<port>` (Firefox/BiDi), `c-<port>` (Chromium/CDP), `x-<port>` (unidentified port) |
|
|
168
|
+
| `endpoint` | The WebSocket the server would attach to |
|
|
169
|
+
| `family` / `port` | `firefox` or `chromium`, plus the endpoint's port |
|
|
170
|
+
| `reachable` | TCP: something is listening on the port |
|
|
171
|
+
| `connectable` | Protocol verdict — a BiDi endpoint answered `session.status`; a Chromium DevTools endpoint is recorded and its port answers |
|
|
172
|
+
| `reason` | Why the endpoint is **not** connectable (no listener, not BiDi, stale record) |
|
|
173
|
+
| `live` | This candidate is the currently attached session |
|
|
174
|
+
|
|
175
|
+
Probing stays read-only and side-effect-free: the BiDi check is a real
|
|
176
|
+
`session.status` handshake, which never creates a session, so listing cannot
|
|
177
|
+
take Firefox's single-session slot. Chromium is **never** WebSocket-probed by
|
|
178
|
+
the listing — attaching may require approving the browser's debugging prompt,
|
|
179
|
+
and that handshake blocks until granted; the connect attempt is where that
|
|
180
|
+
error surfaces, with the approval step in its fix text.
|
|
181
|
+
|
|
182
|
+
`browser.connect` takes any of: a candidate `id` (`c-9222`), a port (`9222`),
|
|
183
|
+
an exact `ws://` endpoint, or a profile/user-data path (the redacted `~\…`
|
|
184
|
+
form shown in the listing works). Omit the target for ordered auto-connect,
|
|
185
|
+
which skips endpoints the listing already proved dead or non-BiDi.
|
|
186
|
+
|
|
187
|
+
```json
|
|
188
|
+
{
|
|
189
|
+
"candidates": [
|
|
190
|
+
{ "id": "f-9223", "endpoint": "ws://127.0.0.1:9223/session", "source": "profiles-ini",
|
|
191
|
+
"browserFamily": "firefox", "port": 9223, "reachable": true, "connectable": true },
|
|
192
|
+
{ "id": "c-9222", "endpoint": "ws://127.0.0.1:9222/devtools/browser/<id>", "source": "chromium-devtools-port",
|
|
193
|
+
"browserFamily": "chromium", "port": 9222, "reachable": true, "connectable": true }
|
|
194
|
+
]
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
## Start Firefox with BiDi
|
|
199
|
+
|
|
200
|
+
```powershell
|
|
201
|
+
# Windows
|
|
202
|
+
& "C:\Program Files\Mozilla Firefox\firefox.exe" --remote-debugging-port=9222
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
# macOS / Linux
|
|
207
|
+
firefox --remote-debugging-port=9222
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
BiDi endpoint: `ws://127.0.0.1:9222/session`
|
|
211
|
+
|
|
212
|
+
Firefox sets `navigator.webdriver === true` whenever the Remote Agent is
|
|
213
|
+
enabled. This is not a stealth or anti-detection tool; some sites may challenge
|
|
214
|
+
the session. There is no spoofing layer.
|
|
215
|
+
|
|
216
|
+
## Test it now
|
|
217
|
+
|
|
218
|
+
For a quick endpoint check, use [`TESTING.md`](./TESTING.md). Short version:
|
|
219
|
+
|
|
220
|
+
```powershell
|
|
221
|
+
& "C:\Program Files\Mozilla Firefox\firefox.exe" --remote-debugging-port=9223
|
|
222
|
+
pnpm build
|
|
223
|
+
pnpm smoke
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
The smoke script calls `session.status` only; it does not take over the session.
|
|
227
|
+
`about:debugging` is not used by this MCP server.
|
|
228
|
+
|
|
229
|
+
To see whether a running Firefox-family process has the Remote Agent on:
|
|
230
|
+
|
|
231
|
+
```powershell
|
|
232
|
+
pnpm detect
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## Install
|
|
236
|
+
|
|
237
|
+
v0.1.9 is the first public release. Install globally with npm or pnpm:
|
|
238
|
+
|
|
239
|
+
```bash
|
|
240
|
+
npm install -g bidi-browser-mcp
|
|
241
|
+
pnpm add -g bidi-browser-mcp
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
A global install is the simplest MCP setup. For Chromium, avoid
|
|
245
|
+
`--omit=optional` (see Chromium browsers above).
|
|
246
|
+
|
|
247
|
+
Or reference it from an MCP client without a global install:
|
|
248
|
+
|
|
249
|
+
```json
|
|
250
|
+
{
|
|
251
|
+
"mcpServers": {
|
|
252
|
+
"bidi-browser": {
|
|
253
|
+
"command": "npx",
|
|
254
|
+
"args": ["-y", "bidi-browser-mcp@latest"]
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
The pnpm equivalent:
|
|
261
|
+
|
|
262
|
+
```json
|
|
263
|
+
{
|
|
264
|
+
"mcpServers": {
|
|
265
|
+
"bidi-browser": {
|
|
266
|
+
"command": "pnpm",
|
|
267
|
+
"args": ["dlx", "bidi-browser-mcp@latest"]
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
The published package contains only compiled `dist/` plus `README`, `LICENSE`,
|
|
274
|
+
and `package.json`. Repository docs, tests, and build scripts are not installed.
|
|
275
|
+
|
|
276
|
+
## Setup
|
|
277
|
+
|
|
278
|
+
One-shot install/build/test/verify:
|
|
279
|
+
|
|
280
|
+
```bash
|
|
281
|
+
pnpm setup
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
If Firefox or Zen is running with `--remote-debugging-port`, this also probes the
|
|
285
|
+
BiDi endpoint automatically. No env vars are required for the common case.
|
|
286
|
+
|
|
287
|
+
Process-based discovery finds a running Firefox or Zen without env vars. There
|
|
288
|
+
is no supported in-browser toggle to start the Remote Agent.
|
|
289
|
+
|
|
290
|
+
## Build from source
|
|
291
|
+
|
|
292
|
+
```bash
|
|
293
|
+
pnpm install
|
|
294
|
+
pnpm build
|
|
295
|
+
pnpm typecheck
|
|
296
|
+
pnpm test
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
Point your MCP client at `dist/bin.js` while developing. Use an absolute path in
|
|
300
|
+
your local client config; do not commit it:
|
|
301
|
+
|
|
302
|
+
```json
|
|
303
|
+
{
|
|
304
|
+
"mcpServers": {
|
|
305
|
+
"bidi-browser": {
|
|
306
|
+
"command": "node",
|
|
307
|
+
"args": ["<absolute-path-to-repo>/dist/bin.js"]
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
After `pnpm build`, restart the MCP server so it loads the new `dist/`. Once the
|
|
314
|
+
package is published, replace the dev entry with
|
|
315
|
+
`pnpm dlx bidi-browser-mcp@latest` (or a global install).
|
|
316
|
+
|
|
317
|
+
## Troubleshooting
|
|
318
|
+
|
|
319
|
+
- **`MISSING_DEPENDENCY` on Chromium** — the optional `chromium-bidi` mapper is
|
|
320
|
+
not resolvable from the server. npm: install the exact pin beside the server
|
|
321
|
+
(`npm install -g chromium-bidi@158.0.8123-0`) or reinstall without
|
|
322
|
+
`--omit=optional`. pnpm: reinstall the server itself (`pnpm add -g
|
|
323
|
+
bidi-browser-mcp`) or use `pnpm dlx`; pnpm's global installs are isolated.
|
|
324
|
+
- **Chromium connect times out / hangs** — approve the in-browser debugging
|
|
325
|
+
permission dialog; Chromium stalls the connection until it is allowed.
|
|
326
|
+
- **`SESSION_BUSY` on Firefox/Zen** — Firefox allows one BiDi session. Close the
|
|
327
|
+
other client (another MCP server, a test script, DevTools) and retry; the
|
|
328
|
+
session is not released until the browser or the client ends it.
|
|
329
|
+
- **No Firefox endpoint found** — start the browser with
|
|
330
|
+
`--remote-debugging-port=9222` (Firefox/Zen) or set `BIDI_WS_URL`.
|
|
331
|
+
|
|
332
|
+
## Configuration
|
|
333
|
+
|
|
334
|
+
`BIDI_OUTPUT_MODE=file` is not implemented yet and is rejected at startup; the
|
|
335
|
+
allow flags are reserved for later waves.
|
|
336
|
+
|
|
337
|
+
| Variable | Default | Description |
|
|
338
|
+
|---|---|---|
|
|
339
|
+
| `BIDI_HOST` | `127.0.0.1` | BiDi WebSocket host |
|
|
340
|
+
| `BIDI_PORT` | `9222` | BiDi WebSocket port |
|
|
341
|
+
| `BIDI_WS_URL` | auto | Override full WebSocket URL |
|
|
342
|
+
| `BIDI_PROFILE_DIR` | auto | Firefox profile directory for discovery |
|
|
343
|
+
| `BIDI_APP_DATA_ROOT` | `%APPDATA%` | App-data root used for profile discovery |
|
|
344
|
+
| `BIDI_LOCAL_APP_DATA_ROOT` | `%LOCALAPPDATA%` | Local app-data root used to find Chromium user-data dirs |
|
|
345
|
+
| `BIDI_CHROMIUM_DATA_DIR` | auto | Extra Chromium user-data dirs (one or more, `;`-separated) for `DevToolsActivePort` discovery |
|
|
346
|
+
| `BIDI_TIMEOUT` | `30000` | Command timeout (ms) |
|
|
347
|
+
| `BIDI_TOOLSET` | `core` | `core`, `network`, or `devtools` |
|
|
348
|
+
| `BIDI_OUTPUT_MODE` | `full` | `full` (no inline cut; snapshots capped at 1 MiB) or `inline` (fit `BIDI_MAX_INLINE_LEN`); `file` is rejected |
|
|
349
|
+
| `BIDI_MAX_INLINE_LEN` | `60000` | Max inline response chars |
|
|
350
|
+
| `BIDI_TEMP_DIR` | `.temp` | Temp file directory — parsed and validated, but no temp files are written yet (reserved for later waves) |
|
|
351
|
+
| `BIDI_ALLOW_EXTENSION_INSTALL` | `false` | Gate extension install |
|
|
352
|
+
| `BIDI_ALLOW_BROWSER_CLOSE` | `false` | Gate `browser.close` |
|
|
353
|
+
| `BIDI_ENABLE_NETWORK` | `false` | Opt-in for `network.wait` (read-only request/response metadata) |
|
|
354
|
+
| `BIDI_ALLOW_SCRIPT_EVAL` | `false` | Opt-in for `script.evaluate` (reads credentials; `script.waitFor` needs no flag) |
|
|
355
|
+
|
|
356
|
+
## Safety limits
|
|
357
|
+
|
|
358
|
+
- Snapshots never read live field values. Passwords, tokens, and typed text
|
|
359
|
+
stay out of the snapshot, the agent context, and client logs.
|
|
360
|
+
- `tabs.new` opens `http:`, `https:`, and `about:blank` only. `file:`, `data:`,
|
|
361
|
+
`javascript:`, and `blob:` are rejected — they would turn the browser into a
|
|
362
|
+
local-file or script reader.
|
|
363
|
+
- `context.remove` needs `confirm: true`; it deletes the container with its
|
|
364
|
+
tabs, cookies, and storage.
|
|
365
|
+
- Non-loopback endpoints need `BIDI_ALLOW_REMOTE=1` — the gate covers every
|
|
366
|
+
discovered candidate, including profile files.
|
|
367
|
+
|
|
368
|
+
## Architecture
|
|
369
|
+
|
|
370
|
+
```
|
|
371
|
+
src/
|
|
372
|
+
├── bin.ts # CLI entry (shebang) → dist/bin.js
|
|
373
|
+
├── index.ts # public API: createServer(), VERSION
|
|
374
|
+
├── config.ts # env-based config (only env reader)
|
|
375
|
+
├── types.ts # shared contracts
|
|
376
|
+
├── connection/ # planned: BiDi client, discovery, health, event pipeline
|
|
377
|
+
├── session/ # planned: single-session manager, context manager
|
|
378
|
+
├── snapshot/ # planned: JS DOM snapshots, cache, refs, token optimizer
|
|
379
|
+
├── tools/ # defineTool, registry, ping, browser, tabs, page, console, observe, cleanup
|
|
380
|
+
├── utils/ # errors, result envelope, argument guards
|
|
381
|
+
└── __tests__/ # hermetic unit tests + MockBiDiServer
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
Firefox allows only one BiDi session at a time, so the server reuses a single
|
|
385
|
+
session instead of copying CDP's multi-session model. A second client gets
|
|
386
|
+
`BIDI_SESSION_BUSY`, not a retry loop. All tools in **one server process** share
|
|
387
|
+
the session; separate MCP server processes need the future broker. BiDi has no
|
|
388
|
+
full accessibility-tree API, so snapshots are built with `script.evaluate` plus
|
|
389
|
+
DOM traversal.
|
|
390
|
+
|
|
391
|
+
## Contributing
|
|
392
|
+
|
|
393
|
+
See [CONTRIBUTING.md](./CONTRIBUTING.md) and [AGENTS.md](./AGENTS.md). Work
|
|
394
|
+
happens on `dev`; PRs target `dev`, and releases are cut from `main`.
|
|
395
|
+
|
|
396
|
+
## License
|
|
397
|
+
|
|
398
|
+
MIT © 2026 Tushar Agarwal
|