mcp-browser-dev-tools 0.0.6 → 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/README.md CHANGED
@@ -3,49 +3,21 @@
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
4
  [![npm downloads](https://img.shields.io/npm/dm/mcp-browser-dev-tools)](https://www.npmjs.com/package/mcp-browser-dev-tools)
5
5
 
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.
7
-
8
- It is designed for a local trust boundary:
9
-
10
- `AI client -> MCP over stdio -> local broker -> browser adapter -> page target`
11
-
12
- ## What You Get
13
-
14
- - A stdio MCP server for local desktop and terminal clients
15
- - Browser discovery and attach/detach for Chrome, Edge, other Chromium-family browsers, and Firefox
16
- - Tab lifecycle tools to create and close browser tabs through MCP
17
- - Inspection tools for DOM lookup, richer element details, cookies, storage, console messages, network requests, HAR-like exports, screenshots, tab listing, and buffered events
18
- - Page interaction tools for navigation, reload, click, hover, type, select, key presses, scroll, and viewport overrides
19
- - Wait conditions for selector visibility, URL changes, and document ready state
20
- - One-shot debug bundle capture for page state, storage summary, recent console, recent network, and screenshots
21
- - Optional JavaScript evaluation behind an explicit environment flag
22
- - Helper commands to check browser connectivity, launch a debug-enabled browser, and relay CDP traffic across a local machine boundary
23
-
24
- ## Requirements
25
-
26
- - Node.js `24+`
27
- - A local browser exposing either CDP or BiDi, or permission for the broker to launch one locally
28
- - Loopback endpoints by default; remote endpoints require an explicit opt-in flag
6
+ 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.
29
7
 
30
8
  ## Quick Start
31
9
 
32
- In normal use, the only thing a user should need to do is register this MCP server in their agent client. After that, let the agent drive the browser through MCP.
33
-
34
- If you want the simplest local path, start with the default `auto` setup. The broker can auto-discover loopback CDP and BiDi ports, launch a compatible browser through MCP, and in WSL bootstrap the Windows Chrome or Edge relay when your config asks it to.
35
-
36
- ### Codex
37
-
38
- ```bash
39
- codex mcp add browser-devtools -- npx -y mcp-browser-dev-tools serve
40
- ```
41
-
42
- ### Claude Code
10
+ You need Node.js 24 or later. Register the server with your MCP client:
43
11
 
44
12
  ```bash
13
+ # Claude Code
45
14
  claude mcp add browser-devtools --scope user -- npx -y mcp-browser-dev-tools serve
15
+
16
+ # Codex
17
+ codex mcp add browser-devtools -- npx -y mcp-browser-dev-tools serve
46
18
  ```
47
19
 
48
- ### Cursor
20
+ Cursor and other clients that use an `mcpServers` config:
49
21
 
50
22
  ```json
51
23
  {
@@ -58,305 +30,122 @@ claude mcp add browser-devtools --scope user -- npx -y mcp-browser-dev-tools ser
58
30
  }
59
31
  ```
60
32
 
61
- These commands intentionally do not include a profile flag. They only start the MCP broker. Browser launch options belong to the later `ensure_browser` or `launch_browser` call that the agent makes after the broker is running, and the broker can auto-create a temporary Chromium-family profile when that is needed.
62
-
63
- ## After Setup
64
-
65
- Once the server is registered, the normal workflow is to ask the agent for browser work directly:
66
-
67
- - open a browser to a URL and inspect the page
68
- - attach to the current tab and inspect DOM, console, or network state
69
- - take a screenshot or capture a debug report
33
+ 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.
70
34
 
71
- The agent should usually start with `ensure_browser`. That tool can confirm browser availability, launch one if needed, and optionally open the requested URL in one step.
35
+ ## What It Does
72
36
 
73
- Both `ensure_browser` and `launch_browser` try to keep one browser running instead of starting more:
37
+ ![An AI agent sends one run_steps call with five steps to the browser and gets one reply with every result](docs/images/overview.svg)
74
38
 
75
- - a browser that is already reachable is reused, whatever profile it runs on; `launch_browser` returns `reused: true` instead of launching when `port`, `address`, `userDataDir`, and `unsafeArgs` are all omitted, and opens `url` in a new tab of that browser
76
- - before reusing or launching, the browser status is checked three times, so one slow answer does not trigger a launch
77
- - after launching, the broker will not launch the same browser again for 30 seconds while it waits for the endpoint, and launches are handled one at a time, so parallel tool calls do not start one browser each
78
- - on macOS and Linux, the broker never launches a second browser on a profile that is already open (or, for Firefox without `userDataDir`, while any Firefox is running), because that only opens another window in the running browser; it waits for that browser's endpoint instead, and fails with an explanation if the endpoint stays down. On Windows and WSL the broker cannot read browser command lines, so it cannot detect which profile a running Chrome or Edge uses; the Firefox check and the automatic temporary Chrome/Edge profile still apply there
39
+ Your agent gets 38 browser tools over MCP: open or attach to tabs, click, type, and navigate, read the console and network, take screenshots, and save and restore sessions. At the center is `run_steps`: the agent sends a whole task, with branches and waits in it, and the server carries it out in the browser and replies once. `run_tabs` does the same in several tabs at the same time.
79
40
 
80
- To make every launch use the same profile, set `MCP_BROWSER_USER_DATA_DIR` in the MCP server environment instead of passing `userDataDir` on every call. It applies only when a browser actually has to be launched; a browser that is already reachable is reused as is.
41
+ ## Why This One
81
42
 
82
- If the agent launches Chrome or Edge without `userDataDir`, the broker checks whether the same browser family is already running. If it is, the broker automatically creates a temporary profile directory before launching so the new debug flags are not swallowed by the already-running profile.
43
+ - **Fewer round trips.** Every model turn costs thinking time and tokens, so the agent does more with each call. In our benchmark, batching halved the turns Sonnet 5.5 needed to sign up through a form.
44
+ - **Many pages at once.** Research over several pages happens side by side: `run_tabs` opens them together and `read_text` brings back what they say. In our benchmark, reading five slow pages took Sonnet 5.5 8.4 s and 4 turns instead of 28 s and 14.
45
+ - **Calm on real pages.** Waits end on whichever outcome shows up, actions wait out a covering banner or a button that isn't enabled yet, and if a step fails the reply lists the page's controls, so the next try is an informed one.
46
+ - **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.
47
+ - **A debugger at hand.** Console messages with stack traces, network requests and HAR export, cookies and storage, and a one-call debug report.
83
48
 
84
- Typical temporary profile locations:
49
+ ## One Call, Start To Finish
85
50
 
86
- - Windows broker: `%TEMP%\\mcp-browser-dev-tools-edge` or PowerShell `$env:TEMP\\mcp-browser-dev-tools-edge`
87
- - macOS broker: `$HOME/Library/Caches/mcp-browser-dev-tools-profile`
88
- - Linux or WSL broker: `$HOME/.cache/mcp-browser-dev-tools-profile`
89
-
90
- Use a path that matches the OS running the broker process. If you want a stable or reusable profile path, still pass `userDataDir` explicitly. If a browser is already open and already exposing a debug endpoint, the broker can still attach to it. If Chrome or Edge is already open without a debug endpoint, the automatic temporary profile is the default safety path for launches initiated through `ensure_browser`, `launch_browser`, or the manual `open` command.
91
-
92
- Example `ensure_browser` payload for Chrome or Edge:
51
+ A `run_steps` call that dismisses a cookie banner if one is showing, fills in and submits a form, waits for either the success or the error message, and reads it:
93
52
 
94
53
  ```json
95
54
  {
96
- "browserFamily": "edge",
97
- "url": "https://example.com"
55
+ "sessionId": "chromium:1f0c…",
56
+ "steps": [
57
+ {
58
+ "tool": "if",
59
+ "arguments": {
60
+ "condition": { "selector": "text=Accept cookies" },
61
+ "then": [
62
+ {
63
+ "tool": "click",
64
+ "arguments": { "selector": "text=Accept cookies" }
65
+ }
66
+ ]
67
+ }
68
+ },
69
+ {
70
+ "tool": "type",
71
+ "arguments": {
72
+ "selector": "role=textbox[name=\"Email\"]",
73
+ "text": "ada@example.com"
74
+ }
75
+ },
76
+ {
77
+ "tool": "click",
78
+ "arguments": { "selector": "role=button[name=\"Sign up\"]" }
79
+ },
80
+ {
81
+ "tool": "wait_for",
82
+ "arguments": {
83
+ "anyOf": [
84
+ { "selector": "#message", "textIncludes": "Welcome" },
85
+ { "selector": "#message", "textIncludes": "error" }
86
+ ]
87
+ }
88
+ },
89
+ { "tool": "inspect_element", "arguments": { "selector": "#message" } }
90
+ ]
98
91
  }
99
92
  ```
100
93
 
101
- Add `userDataDir` only if you want to force a specific profile path.
94
+ The result has each step's outcome: which branch the `if` took, which `anyOf` alternative matched, and the message element with its text. Locators can be CSS, `text=`, `role=` with an accessible name, or `name=`. The full semantics of `run_steps`, `if`, `repeat`, and conditions are in [Tools](docs/tools.md#batched-steps).
102
95
 
103
- When the broker launches a browser, the result reports the selected `userDataDir`, `profileStrategy`, and `existingBrowserProcess` state so the agent can see whether a temporary profile was chosen automatically.
96
+ ## Measured
104
97
 
105
- ## MCP Client Configuration
98
+ Model turns per task, median of 3 runs, from the benchmark in [PERFORMANCE.md](PERFORMANCE.md):
106
99
 
107
- The same launch-profile advice applies to every MCP client config below: if you later ask the agent to launch Chrome or Edge, you can pass `userDataDir` to force a specific profile path, but if you omit it the broker can auto-create a temporary profile when an already-running Chromium-family browser would otherwise swallow the new debug flags. The config commands themselves still only launch `serve`; they do not carry browser launch arguments.
100
+ | Task | Sonnet 5.5, one action per call | Sonnet 5.5 with `run_steps` | Opus 5.5 with `run_steps` |
101
+ | ----------------------------------- | ------------------------------- | --------------------------- | ------------------------- |
102
+ | Sign up through a form | 10 | 5 | 4 |
103
+ | Pay, retrying declined attempts | 12 | 11 | 4 |
104
+ | Sign in, then change settings | 16 | 9 | 7 |
105
+ | Read five pages from a results list | 14 | 4 | 4 |
108
106
 
109
- ### Codex
107
+ Opus retried the payment inside a single `repeat` step. The last row uses `run_tabs` in place of `run_steps`. Seven models (Claude Fable 5.1, Opus 5.5, Sonnet 5.5, and Haiku 4.5; GPT-6-Astra, GPT-6.1 Sol, and GPT-6-Luna) completed all 63 runs of the first three tasks; PERFORMANCE.md has the time, cost, and turns for each, and how the runs were set up.
110
108
 
111
- Minimal local setup:
109
+ ## Tools
112
110
 
113
- ```bash
114
- codex mcp add browser-devtools -- npx -y mcp-browser-dev-tools serve
115
- ```
111
+ 38 tools, described in [docs/tools.md](docs/tools.md):
116
112
 
117
- Equivalent `~/.codex/config.toml` entry:
113
+ - **Browser and tabs:** `browser_status`, `ensure_browser`, `launch_browser`, `list_tabs`, `new_tab`, `close_tab`, `attach_tab`, `detach_tab`, `list_sessions`
114
+ - **Act:** `navigate`, `reload`, `click`, `hover`, `type`, `select`, `press_key`, `scroll`, `set_viewport`
115
+ - **Wait and batch:** `wait_for`, `run_steps`, `run_tabs`
116
+ - **Inspect:** `get_page_state`, `get_document`, `inspect_element`, `read_text`, `take_screenshot`, `evaluate_js`
117
+ - **Console and network:** `get_console_messages`, `get_network_requests`, `get_events`, `get_har`
118
+ - **Session state:** `get_cookies`, `get_storage`, `capture_session_snapshot`, `restore_session_snapshot`, `compare_page_state`, `compare_selector`, `capture_debug_report`
118
119
 
119
- ```toml
120
- [mcp_servers.browser-devtools]
121
- command = "npx"
122
- args = ["-y", "mcp-browser-dev-tools", "serve"]
123
- ```
120
+ ## Configuration
124
121
 
125
- ### Claude Code
122
+ The defaults work for most setups: the server finds a Chromium or Firefox debugging endpoint on loopback ports 9222–9226, or launches a browser when asked. The settings people change most:
126
123
 
127
- Minimal local setup:
124
+ - `MCP_BROWSER_FAMILY`: `auto` (default), `chromium`, `edge`, or `firefox`
125
+ - `CDP_BASE_URL` and `FIREFOX_BIDI_WS_URL`: fixed browser endpoints
126
+ - `MCP_BROWSER_USER_DATA_DIR`: the profile to launch browsers with
127
+ - `MCP_BROWSER_ENABLE_EVAL=0`: turn off page JavaScript from the agent (`evaluate_js` and `expression` conditions)
128
128
 
129
- ```bash
130
- claude mcp add browser-devtools --scope user -- npx -y mcp-browser-dev-tools serve
131
- ```
129
+ Every setting, per-client examples, and how the server reuses or launches browsers are in [docs/configuration.md](docs/configuration.md). WSL with a Windows browser, and other platform walkthroughs, are in [docs/setup.md](docs/setup.md).
132
130
 
133
- On native Windows, wrap `npx` with `cmd /c`:
131
+ ## Safety
134
132
 
135
- ```powershell
136
- claude mcp add browser-devtools --scope user --env MCP_BROWSER_FAMILY=auto --env CDP_BASE_URL=http://127.0.0.1:9223 --env FIREFOX_BIDI_WS_URL=ws://127.0.0.1:9222 -- cmd /c npx -y mcp-browser-dev-tools serve
137
- ```
133
+ - The server only connects to loopback browser endpoints unless you set `MCP_BROWSER_ALLOW_REMOTE_ENDPOINTS=1`.
134
+ - 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.
135
+ - `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.
138
136
 
139
- Equivalent `.mcp.json` shape:
137
+ ## Compared With Playwright
140
138
 
141
- ```json
142
- {
143
- "mcpServers": {
144
- "browser-devtools": {
145
- "command": "npx",
146
- "args": ["-y", "mcp-browser-dev-tools", "serve"]
147
- }
148
- }
149
- }
150
- ```
151
-
152
- ### Cursor
139
+ Playwright is the better choice for deterministic automation and end-to-end tests, with its assertions, tracing, and CI tooling. This server is for a different job: letting an AI agent inspect and operate a live browser through MCP. The agent calls a fixed set of tools instead of writing and running scripts, can work in the tab and session you already have open, and uses the same tools on Chromium and Firefox.
153
140
 
154
- Minimal local setup:
141
+ ## Documentation
155
142
 
156
- ```json
157
- {
158
- "mcpServers": {
159
- "browser-devtools": {
160
- "command": "npx",
161
- "args": ["-y", "mcp-browser-dev-tools", "serve"]
162
- }
163
- }
164
- }
165
- ```
166
-
167
- ### Common Variants
168
-
169
- The default broker mode is `auto`. If you want to pin the broker to one browser family or one set of endpoints, change the environment in your MCP client config.
170
-
171
- Auto mode with both browsers attached to one MCP server:
172
-
173
- ```json
174
- {
175
- "MCP_BROWSER_FAMILY": "auto",
176
- "CDP_BASE_URL": "http://127.0.0.1:9223",
177
- "FIREFOX_BIDI_WS_URL": "ws://127.0.0.1:9222"
178
- }
179
- ```
180
-
181
- Firefox:
182
-
183
- ```json
184
- {
185
- "MCP_BROWSER_FAMILY": "firefox",
186
- "FIREFOX_BIDI_WS_URL": "ws://127.0.0.1:9222"
187
- }
188
- ```
189
-
190
- Microsoft Edge:
191
-
192
- ```json
193
- {
194
- "MCP_BROWSER_FAMILY": "edge",
195
- "CDP_BASE_URL": "http://127.0.0.1:9222"
196
- }
197
- ```
198
-
199
- Manual Windows browser relay into WSL:
200
-
201
- ```json
202
- {
203
- "MCP_BROWSER_FAMILY": "chromium",
204
- "MCP_BROWSER_ALLOW_REMOTE_ENDPOINTS": "1",
205
- "CDP_BASE_URL": "http://<windows-host-ip>:9223"
206
- }
207
- ```
208
-
209
- If you only want a single CDP browser, switch `MCP_BROWSER_FAMILY` back to `chromium` or `edge` and omit `FIREFOX_BIDI_WS_URL`.
210
-
211
- Enable `evaluate_js`:
212
-
213
- ```json
214
- {
215
- "MCP_BROWSER_ENABLE_EVAL": "1"
216
- }
217
- ```
218
-
219
- Enable unsafe browser launch args for `launch_browser` and `ensure_browser`:
220
-
221
- ```json
222
- {
223
- "MCP_BROWSER_ENABLE_UNSAFE_LAUNCH_ARGS": "1"
224
- }
225
- ```
226
-
227
- 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).
228
-
229
- ## Advanced Environment Options
230
-
231
- - `MCP_BROWSER_FAMILY` defaults to `auto`; set `chromium`, `edge`, or `firefox` to pin the broker to one browser family
232
- - `CDP_BASE_URL` defaults to `http://127.0.0.1:9222`; when left at that default the broker probes loopback ports `9222` through `9226` for a reachable CDP browser endpoint
233
- - `FIREFOX_BIDI_WS_URL` defaults to `ws://127.0.0.1:9222`; when left at that default the broker probes loopback ports `9222` through `9226`, and when pointed at the root Firefox remote debugging port it connects to the `/session` websocket and creates a BiDi session there
234
- - in `auto` mode, assign CDP and Firefox different ports so both browsers can run at once
235
- - `MCP_BROWSER_USER_DATA_DIR` sets the browser profile directory that `ensure_browser` and `launch_browser` use when `userDataDir` is not passed; a leading `~/` expands to the home directory
236
- - `MCP_BROWSER_EVENT_BUFFER_SIZE` sets the per-session buffered event limit
237
- - `MCP_BROWSER_LOG_LEVEL` controls diagnostic logging to `stderr`: `error`, `warn`, `info`, or `debug`
238
- - `MCP_BROWSER_DEBUG_STDIO=1` emits raw MCP stdio transport diagnostics to `stderr`
239
- - `MCP_BROWSER_ENABLE_EVAL=1` enables `evaluate_js`
240
- - `MCP_BROWSER_ENABLE_UNSAFE_LAUNCH_ARGS=1` exposes the `unsafeArgs` launch option on `launch_browser` and `ensure_browser`
241
- - `MCP_BROWSER_ALLOW_REMOTE_ENDPOINTS=1` allows non-loopback CDP or BiDi endpoints
242
- - `MCP_BROWSER_ALLOW_REMOTE_CDP=1` is still accepted as a legacy alias
243
- - `MCP_BROWSER_WINDOWS_NODE` optionally overrides the Windows `node` executable used by `serve --bootstrap-wsl-relay`
244
- - `MCP_PROTOCOL_VERSION` overrides the advertised MCP protocol version
245
-
246
- ## Exposed Tools
247
-
248
- - `browser_status` returns broker metadata too: `serverName` and `serverVersion`
249
- In `auto` mode it also includes per-browser adapter status under `browsers`
250
- Protocol adapters may also include `attemptedEndpoint` when discovery retries or fallback probing occur
251
- - `ensure_browser`
252
- Ensures a compatible browser is reachable, launches one if needed, and can open a tab for the requested URL in a single MCP call
253
- In `auto` mode, pass `browserFamily`
254
- 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
255
- 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.
256
- - `launch_browser`
257
- Launches a local debug-enabled browser that matches the current broker configuration and can return an inline doctor report
258
- In `auto` mode, pass `browserFamily`
259
- 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
260
- 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.
261
- - `list_tabs`
262
- In `auto` mode each `targetId` is namespaced as `chromium:<id>` or `firefox:<id>`
263
- - `new_tab`
264
- In `auto` mode, pass `browserFamily`
265
- - `close_tab`
266
- - `list_sessions`
267
- In `auto` mode each `sessionId` is namespaced the same way
268
- - `attach_tab`
269
- - `detach_tab`
270
- - `get_page_state`
271
- - `compare_page_state`
272
- - `compare_selector`
273
- - `get_cookies`
274
- - `get_storage`
275
- - `capture_debug_report`
276
- - `capture_session_snapshot`
277
- - `restore_session_snapshot`
278
- - `get_har`
279
- - `wait_for`
280
- - `navigate`
281
- - `reload`
282
- - `click`
283
- - `hover`
284
- - `type`
285
- - `select`
286
- - `press_key`
287
- - `scroll`
288
- - `set_viewport`
289
- - `get_console_messages`
290
- - `get_network_requests`
291
- - `get_document`
292
- - `inspect_element`
293
- - `take_screenshot`
294
- - `get_events`
295
-
296
- `evaluate_js` is intentionally disabled by default. Enable it only when you want the broker to allow page-side code execution.
297
-
298
- 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`.
299
-
300
- For tools that take `sessionId`, call `attach_tab` first and reuse the returned session.
301
-
302
- ### Locator Syntax
303
-
304
- Interaction and inspection tools accept these locator forms:
305
-
306
- - CSS selectors such as `#app button.primary` or `css=.modal button`
307
- - visible-text lookup such as `text=Open settings`
308
- - role plus accessible name such as `role=button[name="Open settings"]`
309
- - accessible-name lookup such as `name=Open settings`
310
-
311
- `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.
312
-
313
- ### Screenshot Output
314
-
315
- `take_screenshot` returns base64 image data plus metadata such as `mimeType`, `byteLength`, and `scope`. Pass `selector` to capture a single element instead of the full page.
316
-
317
- ### Session Snapshots
318
-
319
- - `get_cookies` returns bounded page-visible cookies from the attached page context
320
- - `get_storage` returns bounded `localStorage` and `sessionStorage` entries and can filter to one storage area
321
- - `capture_debug_report` bundles page state, cookie/storage summaries, recent console messages, recent network requests, and an optional screenshot
322
- - `capture_session_snapshot` exports bounded page-visible cookies plus local and session storage for later reuse
323
- - `restore_session_snapshot` restores a captured snapshot onto the current origin and can optionally clear storage first
324
- - `get_har` exports buffered network activity in a bounded HAR-like JSON structure
325
- - `compare_page_state` and `compare_selector` compare bounded state across two attached sessions, which is especially useful in `auto` mode
326
-
327
- ## Browser Notes
328
-
329
- - Chromium uses the standard DevTools endpoints at `/json/version` and `/json/list`
330
- - Firefox support expects a direct BiDi websocket endpoint
331
- - In WSL, Linux browser executables are preferred before Windows fallback paths
332
- - For Windows Chrome or Edge + WSL, prefer the broker-managed relay path over changing the browser's remote debugging bind
333
-
334
- ## Why Not Playwright?
335
-
336
- 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.
337
-
338
- `mcp-browser-dev-tools` solves a different problem:
339
-
340
- - it is MCP-native, so AI clients call a bounded tool surface instead of generating and executing Playwright scripts
341
- - it can inspect an already-open browser tab or create a fresh one, then inspect the current session state, cookies, login state, extensions, console, and network history
342
- - it is designed for local AI debugging workflows, including loopback-only defaults, opt-in evaluation, and the Windows-to-WSL relay path
343
- - it presents one MCP interface across Chromium CDP and Firefox BiDi instead of requiring the AI client to know browser protocol details
344
-
345
- 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.
346
-
347
- ## Debugging Notes
348
-
349
- - `attach_tab` now seeds network history from the Performance API so already-loaded pages still show useful requests
350
- - console buffers include source URL, line and column where the browser reports them, plus stack frames when available
351
- - `get_page_state` reports the current URL, title, viewport, and scroll position without enabling `evaluate_js`
352
- - broker diagnostics write to `stderr` so `stdout` stays reserved for MCP protocol traffic
353
-
354
- ## Safety Defaults
355
-
356
- - The broker only allows loopback browser endpoints unless you opt in
357
- - The default tool surface is read-focused
358
- - Arbitrary page evaluation is opt-in
359
- - Clients interact with a bounded MCP tool surface instead of raw browser protocol calls
143
+ - [Tools](docs/tools.md): every tool, locator syntax, and `run_steps` in full
144
+ - [Configuration](docs/configuration.md): MCP clients, browser launching and profiles, environment variables
145
+ - [Manual Verification And Troubleshooting](docs/setup.md): Windows, WSL, Linux, and macOS walkthroughs
146
+ - [Performance](PERFORMANCE.md): benchmark method and results across models
147
+ - [Architecture](docs/architecture.md)
148
+ - [Changelog](CHANGELOG.md)
360
149
 
361
150
  ## Development
362
151
 
@@ -367,11 +156,4 @@ pnpm run check
367
156
  pnpm run pack:check
368
157
  ```
369
158
 
370
- The repository uses `pnpm` for local development and CI. End-user installation and publish flows still target the npm registry.
371
-
372
- Additional docs:
373
-
374
- - [Architecture](docs/architecture.md)
375
- - [Manual Verification And Troubleshooting](docs/setup.md)
376
- - [Repository Settings](docs/repository-settings.md)
377
- - [Publishing](PUBLISHING.md)
159
+ The repository uses `pnpm` for development and CI; the package is published to npm. See [Publishing](PUBLISHING.md) and [Repository Settings](docs/repository-settings.md) for the release process.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mcp-browser-dev-tools",
3
- "version": "0.0.6",
4
- "description": "Local MCP server for Chromium DevTools Protocol and Firefox WebDriver BiDi",
3
+ "version": "0.2.0",
4
+ "description": "Browser MCP server for AI agents: batch actions, waits, and checks into one call on Chrome, Edge, or Firefox (CDP and WebDriver BiDi)",
5
5
  "author": "Hinaser <rindo.hinase@gmail.com>",
6
6
  "license": "MIT",
7
7
  "type": "module",
@@ -36,12 +36,26 @@
36
36
  "src/logger.mjs",
37
37
  "src/mcp-server.mjs",
38
38
  "src/page-context.mjs",
39
+ "src/page-script.mjs",
39
40
  "src/package-info.mjs",
40
41
  "src/serve-bootstrap.mjs",
41
42
  "src/session-events.mjs",
42
43
  "src/server.mjs",
43
44
  "src/tcp-relay.mjs",
45
+ "src/top-level-await.mjs",
44
46
  "src/wait-for.mjs",
47
+ "src/action-retry.mjs",
48
+ "src/browser-requests.mjs",
49
+ "src/json-schema.mjs",
50
+ "src/run-steps.mjs",
51
+ "src/run-tabs.mjs",
52
+ "src/screenshot-output.mjs",
53
+ "src/tool-results.mjs",
54
+ "src/tool-schemas.mjs",
55
+ "src/tools/action-tools.mjs",
56
+ "src/tools/browser-tools.mjs",
57
+ "src/tools/inspection-tools.mjs",
58
+ "src/tools/state-tools.mjs",
45
59
  "README.md"
46
60
  ],
47
61
  "bin": {
@@ -75,6 +89,8 @@
75
89
  "check": "node --run lint && node --run format:check && node --run test",
76
90
  "prepare": "husky",
77
91
  "pack:check": "node scripts/pack-check.mjs",
92
+ "bench": "node bench/run.mjs",
93
+ "bench:summary": "node bench/summarize.mjs",
78
94
  "prepublishOnly": "node --run check",
79
95
  "test": "node --test"
80
96
  },
@@ -0,0 +1,50 @@
1
+ import { ELEMENT_NOT_ACTIONABLE } from "./page-context.mjs";
2
+
3
+ function sleep(ms) {
4
+ return new Promise((resolve) => {
5
+ setTimeout(resolve, ms);
6
+ });
7
+ }
8
+
9
+ export const DEFAULT_ACTION_TIMEOUT_MS = 2000;
10
+
11
+ export const ACTION_RETRY_MS = 100;
12
+
13
+ // Retries an action while its element is missing or not yet usable, so a
14
+ // batch survives a late banner or a control that is enabled a moment later.
15
+ // Invalid selectors and other errors fail at once. Retried errors come from
16
+ // checks made before any input is sent, so a retry never repeats an action.
17
+ export async function retryUntilActionable(action, timeoutMs) {
18
+ const limit = timeoutMs ?? DEFAULT_ACTION_TIMEOUT_MS;
19
+ const startedAt = Date.now();
20
+ let retried = false;
21
+ while (true) {
22
+ let result;
23
+ let error = null;
24
+ try {
25
+ result = await action();
26
+ } catch (caught) {
27
+ if (caught?.code !== ELEMENT_NOT_ACTIONABLE) {
28
+ throw caught;
29
+ }
30
+ error = caught;
31
+ }
32
+
33
+ const missing = !error && result?.found === false && !result.error;
34
+ const waitedMs = Date.now() - startedAt;
35
+ const done = (!error && !missing) || waitedMs >= limit;
36
+ if (done) {
37
+ if (error) {
38
+ if (retried) {
39
+ error.message += ` (still failing after ${waitedMs}ms)`;
40
+ }
41
+ throw error;
42
+ }
43
+ return retried && result && typeof result === "object"
44
+ ? { ...result, waitedMs }
45
+ : result;
46
+ }
47
+ retried = true;
48
+ await sleep(Math.min(ACTION_RETRY_MS, limit - waitedMs));
49
+ }
50
+ }
@@ -284,8 +284,8 @@ export class MultiBrowserAdapter {
284
284
  return this.delegateSession(sessionId, "setViewport", [options]);
285
285
  }
286
286
 
287
- evaluate(sessionId, expression) {
288
- return this.delegateSession(sessionId, "evaluate", [expression]);
287
+ evaluate(sessionId, expression, options) {
288
+ return this.delegateSession(sessionId, "evaluate", [expression, options]);
289
289
  }
290
290
 
291
291
  getDocument(sessionId, depth) {
@@ -300,8 +300,19 @@ export class MultiBrowserAdapter {
300
300
  return this.delegateSession(sessionId, "getNetworkRequests", [limit]);
301
301
  }
302
302
 
303
- inspectElement(sessionId, selector) {
304
- return this.delegateSession(sessionId, "inspectElement", [selector]);
303
+ readText(sessionId, options) {
304
+ return this.delegateSession(sessionId, "readText", [options]);
305
+ }
306
+
307
+ snapshotControls(sessionId) {
308
+ return this.delegateSession(sessionId, "snapshotControls");
309
+ }
310
+
311
+ inspectElement(sessionId, selector, options) {
312
+ return this.delegateSession(sessionId, "inspectElement", [
313
+ selector,
314
+ options,
315
+ ]);
305
316
  }
306
317
 
307
318
  takeScreenshot(sessionId, format, options) {
@@ -0,0 +1,15 @@
1
+ export function requestedBrowserFamily(configuredFamily, requestedFamily) {
2
+ if (requestedFamily) {
3
+ return requestedFamily;
4
+ }
5
+
6
+ return configuredFamily === "auto" ? null : configuredFamily;
7
+ }
8
+
9
+ export function shouldCreateBrowserTab(args) {
10
+ if (args.createTab !== undefined) {
11
+ return args.createTab;
12
+ }
13
+
14
+ return typeof args.url === "string" && args.url.trim() !== "";
15
+ }