mcp-browser-dev-tools 0.1.0 → 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 +90 -355
- package/package.json +16 -2
- package/src/action-retry.mjs +50 -0
- package/src/browser-adapter.mjs +15 -4
- package/src/browser-requests.mjs +15 -0
- package/src/cdp-client.mjs +104 -10
- package/src/firefox-bidi-client.mjs +26 -3
- package/src/json-schema.mjs +99 -0
- package/src/mcp-server.mjs +34 -2013
- package/src/page-context.mjs +25 -1034
- package/src/page-script.mjs +1372 -0
- package/src/run-steps.mjs +510 -0
- package/src/run-tabs.mjs +291 -0
- package/src/screenshot-output.mjs +141 -0
- package/src/tool-results.mjs +34 -0
- package/src/tool-schemas.mjs +431 -0
- package/src/tools/action-tools.mjs +318 -0
- package/src/tools/browser-tools.mjs +221 -0
- package/src/tools/inspection-tools.mjs +287 -0
- package/src/tools/state-tools.mjs +327 -0
- package/src/top-level-await.mjs +260 -0
- package/src/wait-for.mjs +381 -71
package/README.md
CHANGED
|
@@ -3,141 +3,21 @@
|
|
|
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
|
-
|
|
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, element text, URL changes, and document ready state
|
|
20
|
-
- Batched steps that run several actions and checks in one call, with `if`/`else` branches on the page state
|
|
21
|
-
- One-shot debug bundle capture for page state, storage summary, recent console, recent network, and screenshots
|
|
22
|
-
- JavaScript evaluation in the page, on by default and removable with an environment flag
|
|
23
|
-
- Helper commands to check browser connectivity, launch a debug-enabled browser, and relay CDP traffic across a local machine boundary
|
|
24
|
-
|
|
25
|
-
## Requirements
|
|
26
|
-
|
|
27
|
-
- Node.js `24+`
|
|
28
|
-
- A local browser exposing either CDP or BiDi, or permission for the broker to launch one locally
|
|
29
|
-
- 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.
|
|
30
7
|
|
|
31
8
|
## Quick Start
|
|
32
9
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
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.
|
|
36
|
-
|
|
37
|
-
### Codex
|
|
38
|
-
|
|
39
|
-
```bash
|
|
40
|
-
codex mcp add browser-devtools -- npx -y mcp-browser-dev-tools serve
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
### Claude Code
|
|
10
|
+
You need Node.js 24 or later. Register the server with your MCP client:
|
|
44
11
|
|
|
45
12
|
```bash
|
|
13
|
+
# Claude Code
|
|
46
14
|
claude mcp add browser-devtools --scope user -- npx -y mcp-browser-dev-tools serve
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
### Cursor
|
|
50
|
-
|
|
51
|
-
```json
|
|
52
|
-
{
|
|
53
|
-
"mcpServers": {
|
|
54
|
-
"browser-devtools": {
|
|
55
|
-
"command": "npx",
|
|
56
|
-
"args": ["-y", "mcp-browser-dev-tools", "serve"]
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
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.
|
|
63
|
-
|
|
64
|
-
## After Setup
|
|
65
|
-
|
|
66
|
-
Once the server is registered, the normal workflow is to ask the agent for browser work directly:
|
|
67
|
-
|
|
68
|
-
- open a browser to a URL and inspect the page
|
|
69
|
-
- attach to the current tab and inspect DOM, console, or network state
|
|
70
|
-
- take a screenshot or capture a debug report
|
|
71
|
-
|
|
72
|
-
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.
|
|
73
|
-
|
|
74
|
-
Both `ensure_browser` and `launch_browser` try to keep one browser running instead of starting more:
|
|
75
15
|
|
|
76
|
-
|
|
77
|
-
- before reusing or launching, the browser status is checked three times, so one slow answer does not trigger a launch
|
|
78
|
-
- 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
|
|
79
|
-
- 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
|
|
80
|
-
|
|
81
|
-
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.
|
|
82
|
-
|
|
83
|
-
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.
|
|
84
|
-
|
|
85
|
-
Typical temporary profile locations:
|
|
86
|
-
|
|
87
|
-
- Windows broker: `%TEMP%\\mcp-browser-dev-tools-edge` or PowerShell `$env:TEMP\\mcp-browser-dev-tools-edge`
|
|
88
|
-
- macOS broker: `$HOME/Library/Caches/mcp-browser-dev-tools-profile`
|
|
89
|
-
- Linux or WSL broker: `$HOME/.cache/mcp-browser-dev-tools-profile`
|
|
90
|
-
|
|
91
|
-
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.
|
|
92
|
-
|
|
93
|
-
Example `ensure_browser` payload for Chrome or Edge:
|
|
94
|
-
|
|
95
|
-
```json
|
|
96
|
-
{
|
|
97
|
-
"browserFamily": "edge",
|
|
98
|
-
"url": "https://example.com"
|
|
99
|
-
}
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
Add `userDataDir` only if you want to force a specific profile path.
|
|
103
|
-
|
|
104
|
-
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.
|
|
105
|
-
|
|
106
|
-
## MCP Client Configuration
|
|
107
|
-
|
|
108
|
-
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.
|
|
109
|
-
|
|
110
|
-
### Codex
|
|
111
|
-
|
|
112
|
-
Minimal local setup:
|
|
113
|
-
|
|
114
|
-
```bash
|
|
16
|
+
# Codex
|
|
115
17
|
codex mcp add browser-devtools -- npx -y mcp-browser-dev-tools serve
|
|
116
18
|
```
|
|
117
19
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
```toml
|
|
121
|
-
[mcp_servers.browser-devtools]
|
|
122
|
-
command = "npx"
|
|
123
|
-
args = ["-y", "mcp-browser-dev-tools", "serve"]
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
### Claude Code
|
|
127
|
-
|
|
128
|
-
Minimal local setup:
|
|
129
|
-
|
|
130
|
-
```bash
|
|
131
|
-
claude mcp add browser-devtools --scope user -- npx -y mcp-browser-dev-tools 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=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
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
Equivalent `.mcp.json` shape:
|
|
20
|
+
Cursor and other clients that use an `mcpServers` config:
|
|
141
21
|
|
|
142
22
|
```json
|
|
143
23
|
{
|
|
@@ -150,260 +30,122 @@ Equivalent `.mcp.json` shape:
|
|
|
150
30
|
}
|
|
151
31
|
```
|
|
152
32
|
|
|
153
|
-
|
|
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.
|
|
154
34
|
|
|
155
|
-
|
|
35
|
+
## What It Does
|
|
156
36
|
|
|
157
|
-
|
|
158
|
-
{
|
|
159
|
-
"mcpServers": {
|
|
160
|
-
"browser-devtools": {
|
|
161
|
-
"command": "npx",
|
|
162
|
-
"args": ["-y", "mcp-browser-dev-tools", "serve"]
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
### Common Variants
|
|
169
|
-
|
|
170
|
-
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.
|
|
171
|
-
|
|
172
|
-
Auto mode with both browsers attached to one MCP server:
|
|
173
|
-
|
|
174
|
-
```json
|
|
175
|
-
{
|
|
176
|
-
"MCP_BROWSER_FAMILY": "auto",
|
|
177
|
-
"CDP_BASE_URL": "http://127.0.0.1:9223",
|
|
178
|
-
"FIREFOX_BIDI_WS_URL": "ws://127.0.0.1:9222"
|
|
179
|
-
}
|
|
180
|
-
```
|
|
37
|
+

|
|
181
38
|
|
|
182
|
-
|
|
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.
|
|
183
40
|
|
|
184
|
-
|
|
185
|
-
{
|
|
186
|
-
"MCP_BROWSER_FAMILY": "firefox",
|
|
187
|
-
"FIREFOX_BIDI_WS_URL": "ws://127.0.0.1:9222"
|
|
188
|
-
}
|
|
189
|
-
```
|
|
41
|
+
## Why This One
|
|
190
42
|
|
|
191
|
-
|
|
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.
|
|
192
48
|
|
|
193
|
-
|
|
194
|
-
{
|
|
195
|
-
"MCP_BROWSER_FAMILY": "edge",
|
|
196
|
-
"CDP_BASE_URL": "http://127.0.0.1:9222"
|
|
197
|
-
}
|
|
198
|
-
```
|
|
49
|
+
## One Call, Start To Finish
|
|
199
50
|
|
|
200
|
-
|
|
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:
|
|
201
52
|
|
|
202
53
|
```json
|
|
203
54
|
{
|
|
204
|
-
"
|
|
205
|
-
"MCP_BROWSER_ALLOW_REMOTE_ENDPOINTS": "1",
|
|
206
|
-
"CDP_BASE_URL": "http://<windows-host-ip>:9223"
|
|
207
|
-
}
|
|
208
|
-
```
|
|
209
|
-
|
|
210
|
-
If you only want a single CDP browser, switch `MCP_BROWSER_FAMILY` back to `chromium` or `edge` and omit `FIREFOX_BIDI_WS_URL`.
|
|
211
|
-
|
|
212
|
-
Disable `evaluate_js`:
|
|
213
|
-
|
|
214
|
-
```json
|
|
215
|
-
{
|
|
216
|
-
"MCP_BROWSER_ENABLE_EVAL": "0"
|
|
217
|
-
}
|
|
218
|
-
```
|
|
219
|
-
|
|
220
|
-
Enable unsafe browser launch args for `launch_browser` and `ensure_browser`:
|
|
221
|
-
|
|
222
|
-
```json
|
|
223
|
-
{
|
|
224
|
-
"MCP_BROWSER_ENABLE_UNSAFE_LAUNCH_ARGS": "1"
|
|
225
|
-
}
|
|
226
|
-
```
|
|
227
|
-
|
|
228
|
-
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).
|
|
229
|
-
|
|
230
|
-
## Advanced Environment Options
|
|
231
|
-
|
|
232
|
-
- `MCP_BROWSER_FAMILY` defaults to `auto`; set `chromium`, `edge`, or `firefox` to pin the broker to one browser family
|
|
233
|
-
- `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
|
|
234
|
-
- `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
|
|
235
|
-
- in `auto` mode, assign CDP and Firefox different ports so both browsers can run at once
|
|
236
|
-
- `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
|
|
237
|
-
- `MCP_BROWSER_EVENT_BUFFER_SIZE` sets the per-session buffered event limit
|
|
238
|
-
- `MCP_BROWSER_LOG_LEVEL` controls diagnostic logging to `stderr`: `error`, `warn`, `info`, or `debug`
|
|
239
|
-
- `MCP_BROWSER_DEBUG_STDIO=1` emits raw MCP stdio transport diagnostics to `stderr`
|
|
240
|
-
- `MCP_BROWSER_TIMING_LOG` names a file that gets one JSON line per tool call with the tool name, duration, success, and response size (text characters and image count); the benchmark in `PERFORMANCE.md` uses it
|
|
241
|
-
- `MCP_BROWSER_ENABLE_EVAL=0` (or `false`) disables `evaluate_js`, which is enabled by default
|
|
242
|
-
- `MCP_BROWSER_ENABLE_UNSAFE_LAUNCH_ARGS=1` exposes the `unsafeArgs` launch option on `launch_browser` and `ensure_browser`
|
|
243
|
-
- `MCP_BROWSER_ALLOW_REMOTE_ENDPOINTS=1` allows non-loopback CDP or BiDi endpoints
|
|
244
|
-
- `MCP_BROWSER_ALLOW_REMOTE_CDP=1` is still accepted as a legacy alias
|
|
245
|
-
- `MCP_BROWSER_WINDOWS_NODE` optionally overrides the Windows `node` executable used by `serve --bootstrap-wsl-relay`
|
|
246
|
-
- `MCP_PROTOCOL_VERSION` overrides the advertised MCP protocol version
|
|
247
|
-
|
|
248
|
-
## Exposed Tools
|
|
249
|
-
|
|
250
|
-
- `browser_status` returns broker metadata too: `serverName` and `serverVersion`
|
|
251
|
-
In `auto` mode it also includes per-browser adapter status under `browsers`
|
|
252
|
-
Protocol adapters may also include `attemptedEndpoint` when discovery retries or fallback probing occur
|
|
253
|
-
- `ensure_browser`
|
|
254
|
-
Ensures a compatible browser is reachable, launches one if needed, and can open a tab for the requested URL in a single MCP call
|
|
255
|
-
In `auto` mode, pass `browserFamily`
|
|
256
|
-
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
|
|
257
|
-
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.
|
|
258
|
-
- `launch_browser`
|
|
259
|
-
Launches a local debug-enabled browser that matches the current broker configuration and can return an inline doctor report
|
|
260
|
-
In `auto` mode, pass `browserFamily`
|
|
261
|
-
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
|
|
262
|
-
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.
|
|
263
|
-
- `list_tabs`
|
|
264
|
-
In `auto` mode each `targetId` is namespaced as `chromium:<id>` or `firefox:<id>`
|
|
265
|
-
- `new_tab`
|
|
266
|
-
In `auto` mode, pass `browserFamily`
|
|
267
|
-
- `close_tab`
|
|
268
|
-
- `list_sessions`
|
|
269
|
-
In `auto` mode each `sessionId` is namespaced the same way
|
|
270
|
-
- `attach_tab`
|
|
271
|
-
- `detach_tab`
|
|
272
|
-
- `get_page_state`
|
|
273
|
-
- `compare_page_state`
|
|
274
|
-
- `compare_selector`
|
|
275
|
-
- `get_cookies`
|
|
276
|
-
- `get_storage`
|
|
277
|
-
- `capture_debug_report`
|
|
278
|
-
- `capture_session_snapshot`
|
|
279
|
-
- `restore_session_snapshot`
|
|
280
|
-
- `get_har`
|
|
281
|
-
- `wait_for`
|
|
282
|
-
- `navigate`
|
|
283
|
-
- `reload`
|
|
284
|
-
- `click`
|
|
285
|
-
- `hover`
|
|
286
|
-
- `type`
|
|
287
|
-
- `select`
|
|
288
|
-
- `press_key`
|
|
289
|
-
- `scroll`
|
|
290
|
-
- `set_viewport`
|
|
291
|
-
- `get_console_messages`
|
|
292
|
-
- `get_network_requests`
|
|
293
|
-
- `get_document`
|
|
294
|
-
- `inspect_element`
|
|
295
|
-
- `take_screenshot`
|
|
296
|
-
- `get_events`
|
|
297
|
-
- `run_steps`
|
|
298
|
-
|
|
299
|
-
`evaluate_js` is enabled by default, as page evaluation is in most browser MCP servers. Set `MCP_BROWSER_ENABLE_EVAL=0` to remove it from the tool list. Treat that as a way to narrow the tool surface, not as a security boundary: the other tools already read page content, cookies, and storage and can navigate anywhere, and any local process that reaches the debugging port can evaluate code through the browser protocol directly. To control page-side code execution per call, use your MCP client's tool permissions.
|
|
300
|
-
|
|
301
|
-
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`. It still does not let callers replace broker-managed launch flags like `--remote-debugging-port` or `--user-data-dir`.
|
|
302
|
-
|
|
303
|
-
For tools that take `sessionId`, call `attach_tab` first and reuse the returned session.
|
|
304
|
-
|
|
305
|
-
### Locator Syntax
|
|
306
|
-
|
|
307
|
-
Interaction and inspection tools accept these locator forms:
|
|
308
|
-
|
|
309
|
-
- CSS selectors such as `#app button.primary` or `css=.modal button`
|
|
310
|
-
- visible-text lookup such as `text=Open settings`
|
|
311
|
-
- role plus accessible name such as `role=button[name="Open settings"]`
|
|
312
|
-
- accessible-name lookup such as `name=Open settings`
|
|
313
|
-
|
|
314
|
-
`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.
|
|
315
|
-
|
|
316
|
-
### Screenshot Output
|
|
317
|
-
|
|
318
|
-
`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.
|
|
319
|
-
|
|
320
|
-
`output` changes how the image comes back. `image` returns an MCP image content block, with only the metadata in the JSON. `file` writes the decoded image to a file and returns its `path` instead of base64 data; passing `path` implies `file`. `path` must be absolute and end in `.png`, `.jpg`, `.jpeg`, or `.webp` (not `.webp` on Firefox), which also sets the format; missing parent directories are created. An existing file is only replaced with `overwrite: true`, and a symlink at `path` is replaced rather than written through. Without `path`, the image goes to a new private directory under the system temp directory. Files are created readable only by the current user. Without `output` or `path`, `take_screenshot` returns base64 data as before.
|
|
321
|
-
|
|
322
|
-
### Batched Steps
|
|
323
|
-
|
|
324
|
-
`run_steps` runs several session tools in order in one call, so an action and the check of its result take one round trip instead of several:
|
|
325
|
-
|
|
326
|
-
```json
|
|
327
|
-
{
|
|
328
|
-
"sessionId": "chromium:session-1",
|
|
55
|
+
"sessionId": "chromium:1f0c…",
|
|
329
56
|
"steps": [
|
|
330
|
-
{
|
|
331
|
-
|
|
332
|
-
|
|
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" } }
|
|
333
90
|
]
|
|
334
91
|
}
|
|
335
92
|
```
|
|
336
93
|
|
|
337
|
-
|
|
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).
|
|
338
95
|
|
|
339
|
-
|
|
96
|
+
## Measured
|
|
340
97
|
|
|
341
|
-
|
|
342
|
-
{
|
|
343
|
-
"tool": "if",
|
|
344
|
-
"arguments": {
|
|
345
|
-
"condition": { "selector": "#status", "textIncludes": "failed" },
|
|
346
|
-
"then": [{ "tool": "click", "arguments": { "selector": "text=Retry" } }],
|
|
347
|
-
"elseIf": [
|
|
348
|
-
{
|
|
349
|
-
"condition": { "urlIncludes": "/login" },
|
|
350
|
-
"then": [
|
|
351
|
-
{ "tool": "take_screenshot", "arguments": { "output": "image" } }
|
|
352
|
-
]
|
|
353
|
-
}
|
|
354
|
-
],
|
|
355
|
-
"else": [{ "tool": "get_page_state" }]
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
```
|
|
98
|
+
Model turns per task, median of 3 runs, from the benchmark in [PERFORMANCE.md](PERFORMANCE.md):
|
|
359
99
|
|
|
360
|
-
|
|
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 |
|
|
361
106
|
|
|
362
|
-
|
|
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.
|
|
363
108
|
|
|
364
|
-
|
|
109
|
+
## Tools
|
|
365
110
|
|
|
366
|
-
|
|
367
|
-
- `get_storage` returns bounded `localStorage` and `sessionStorage` entries and can filter to one storage area
|
|
368
|
-
- `capture_debug_report` bundles page state, cookie/storage summaries, recent console messages, recent network requests, and an optional screenshot
|
|
369
|
-
- `capture_session_snapshot` exports bounded page-visible cookies plus local and session storage for later reuse
|
|
370
|
-
- `restore_session_snapshot` restores a captured snapshot onto the current origin and can optionally clear storage first
|
|
371
|
-
- `get_har` exports buffered network activity in a bounded HAR-like JSON structure
|
|
372
|
-
- `compare_page_state` and `compare_selector` compare bounded state across two attached sessions, which is especially useful in `auto` mode
|
|
111
|
+
38 tools, described in [docs/tools.md](docs/tools.md):
|
|
373
112
|
|
|
374
|
-
|
|
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`
|
|
375
119
|
|
|
376
|
-
|
|
377
|
-
- Firefox support expects a direct BiDi websocket endpoint
|
|
378
|
-
- In WSL, Linux browser executables are preferred before Windows fallback paths
|
|
379
|
-
- For Windows Chrome or Edge + WSL, prefer the broker-managed relay path over changing the browser's remote debugging bind
|
|
120
|
+
## Configuration
|
|
380
121
|
|
|
381
|
-
|
|
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:
|
|
382
123
|
|
|
383
|
-
|
|
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)
|
|
384
128
|
|
|
385
|
-
|
|
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).
|
|
386
130
|
|
|
387
|
-
|
|
388
|
-
- 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
|
|
389
|
-
- it is designed for local AI debugging workflows, including loopback-only defaults and the Windows-to-WSL relay path
|
|
390
|
-
- it presents one MCP interface across Chromium CDP and Firefox BiDi instead of requiring the AI client to know browser protocol details
|
|
131
|
+
## Safety
|
|
391
132
|
|
|
392
|
-
|
|
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.
|
|
393
136
|
|
|
394
|
-
##
|
|
137
|
+
## Compared With Playwright
|
|
395
138
|
|
|
396
|
-
-
|
|
397
|
-
- console buffers include source URL, line and column where the browser reports them, plus stack frames when available
|
|
398
|
-
- `get_page_state` reports the current URL, title, viewport, and scroll position without enabling `evaluate_js`
|
|
399
|
-
- broker diagnostics write to `stderr` so `stdout` stays reserved for MCP protocol traffic
|
|
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.
|
|
400
140
|
|
|
401
|
-
##
|
|
141
|
+
## Documentation
|
|
402
142
|
|
|
403
|
-
-
|
|
404
|
-
-
|
|
405
|
-
-
|
|
406
|
-
-
|
|
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)
|
|
407
149
|
|
|
408
150
|
## Development
|
|
409
151
|
|
|
@@ -414,11 +156,4 @@ pnpm run check
|
|
|
414
156
|
pnpm run pack:check
|
|
415
157
|
```
|
|
416
158
|
|
|
417
|
-
The repository uses `pnpm` for
|
|
418
|
-
|
|
419
|
-
Additional docs:
|
|
420
|
-
|
|
421
|
-
- [Architecture](docs/architecture.md)
|
|
422
|
-
- [Manual Verification And Troubleshooting](docs/setup.md)
|
|
423
|
-
- [Repository Settings](docs/repository-settings.md)
|
|
424
|
-
- [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.
|
|
4
|
-
"description": "
|
|
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": {
|
|
@@ -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
|
+
}
|
package/src/browser-adapter.mjs
CHANGED
|
@@ -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
|
-
|
|
304
|
-
return this.delegateSession(sessionId, "
|
|
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
|
+
}
|