mcp-browser-dev-tools 0.0.1-beta.1
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 +141 -0
- package/cli.mjs +9 -0
- package/package.json +87 -0
- package/src/app.mjs +56 -0
- package/src/browser-adapter.mjs +10 -0
- package/src/browser-launcher.mjs +170 -0
- package/src/cdp-client.mjs +599 -0
- package/src/cli.mjs +199 -0
- package/src/config.mjs +86 -0
- package/src/doctor.mjs +88 -0
- package/src/firefox-bidi-client.mjs +645 -0
- package/src/index.mjs +31 -0
- package/src/json-rpc-stdio.mjs +56 -0
- package/src/mcp-server.mjs +506 -0
- package/src/package-info.mjs +5 -0
- package/src/server.mjs +5 -0
- package/src/session-events.mjs +76 -0
package/README.md
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# mcp-browser-dev-tools
|
|
2
|
+
|
|
3
|
+
`mcp-browser-dev-tools` is a local MCP server that lets AI clients inspect browser state through Chromium DevTools Protocol or Firefox WebDriver BiDi.
|
|
4
|
+
|
|
5
|
+
It is designed for a local trust boundary:
|
|
6
|
+
|
|
7
|
+
`AI client -> MCP over stdio -> local broker -> browser adapter -> page target`
|
|
8
|
+
|
|
9
|
+
## What You Get
|
|
10
|
+
|
|
11
|
+
- A stdio MCP server for local desktop and terminal clients
|
|
12
|
+
- Browser discovery and attach/detach for Chromium-family browsers and Firefox
|
|
13
|
+
- Read-oriented tools for DOM inspection, element lookup, console messages, network requests, screenshots, tab listing, and buffered events
|
|
14
|
+
- Optional JavaScript evaluation behind an explicit environment flag
|
|
15
|
+
- Helper commands to check browser connectivity and launch a debug-enabled browser
|
|
16
|
+
|
|
17
|
+
## Requirements
|
|
18
|
+
|
|
19
|
+
- Node.js `24+`
|
|
20
|
+
- A local browser exposing either CDP or BiDi
|
|
21
|
+
- Loopback endpoints by default; remote endpoints require an explicit opt-in flag
|
|
22
|
+
|
|
23
|
+
## Install
|
|
24
|
+
|
|
25
|
+
One-off execution with `npx`:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npx -y mcp-browser-dev-tools serve
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Global install:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npm install -g mcp-browser-dev-tools
|
|
35
|
+
mcp-browser-dev-tools serve
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Project-local install:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npm install mcp-browser-dev-tools
|
|
42
|
+
npx mcp-browser-dev-tools serve
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## MCP Client Configuration
|
|
46
|
+
|
|
47
|
+
Generic stdio client configuration:
|
|
48
|
+
|
|
49
|
+
```json
|
|
50
|
+
{
|
|
51
|
+
"mcpServers": {
|
|
52
|
+
"browser-devtools": {
|
|
53
|
+
"command": "npx",
|
|
54
|
+
"args": ["-y", "mcp-browser-dev-tools", "serve"],
|
|
55
|
+
"env": {
|
|
56
|
+
"MCP_BROWSER_FAMILY": "chromium",
|
|
57
|
+
"CDP_BASE_URL": "http://127.0.0.1:9222"
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
For Firefox, switch `MCP_BROWSER_FAMILY` to `firefox` and set `FIREFOX_BIDI_WS_URL`.
|
|
65
|
+
|
|
66
|
+
## Commands
|
|
67
|
+
|
|
68
|
+
- `serve` runs the MCP broker over stdio
|
|
69
|
+
- `doctor [--url URL]` checks browser reachability, local display state, and optional page access
|
|
70
|
+
- `open <url>` launches a local browser with remote debugging enabled
|
|
71
|
+
- `--help` and `help` print usage
|
|
72
|
+
- `--version` and `version` print the package version
|
|
73
|
+
|
|
74
|
+
Examples:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
mcp-browser-dev-tools doctor
|
|
78
|
+
mcp-browser-dev-tools doctor --url http://127.0.0.1:3000
|
|
79
|
+
mcp-browser-dev-tools open http://127.0.0.1:3000 --family chromium
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Configuration
|
|
83
|
+
|
|
84
|
+
- `MCP_BROWSER_FAMILY` defaults to `chromium`; set `firefox` for Firefox BiDi
|
|
85
|
+
- `CDP_BASE_URL` defaults to `http://127.0.0.1:9222`
|
|
86
|
+
- `FIREFOX_BIDI_WS_URL` defaults to `ws://127.0.0.1:9222`
|
|
87
|
+
- `MCP_BROWSER_EVENT_BUFFER_SIZE` sets the per-session buffered event limit
|
|
88
|
+
- `MCP_BROWSER_ENABLE_EVAL=1` enables `evaluate_js`
|
|
89
|
+
- `MCP_BROWSER_ALLOW_REMOTE_ENDPOINTS=1` allows non-loopback CDP or BiDi endpoints
|
|
90
|
+
- `MCP_BROWSER_ALLOW_REMOTE_CDP=1` is still accepted as a legacy alias
|
|
91
|
+
- `MCP_PROTOCOL_VERSION` overrides the advertised MCP protocol version
|
|
92
|
+
|
|
93
|
+
The `open` command also requires `MCP_BROWSER_ALLOW_REMOTE_ENDPOINTS=1` before it will bind Chromium remote debugging to a non-loopback address.
|
|
94
|
+
|
|
95
|
+
## Exposed Tools
|
|
96
|
+
|
|
97
|
+
- `browser_status`
|
|
98
|
+
- `list_tabs`
|
|
99
|
+
- `list_sessions`
|
|
100
|
+
- `attach_tab`
|
|
101
|
+
- `detach_tab`
|
|
102
|
+
- `get_console_messages`
|
|
103
|
+
- `get_network_requests`
|
|
104
|
+
- `get_document`
|
|
105
|
+
- `inspect_element`
|
|
106
|
+
- `take_screenshot`
|
|
107
|
+
- `get_events`
|
|
108
|
+
|
|
109
|
+
`evaluate_js` is intentionally disabled by default. Enable it only when you want the broker to allow page-side code execution.
|
|
110
|
+
|
|
111
|
+
For tools that take `sessionId`, call `attach_tab` first and reuse the returned session.
|
|
112
|
+
|
|
113
|
+
## Browser Notes
|
|
114
|
+
|
|
115
|
+
- Chromium uses the standard DevTools endpoints at `/json/version` and `/json/list`
|
|
116
|
+
- Firefox support expects a direct BiDi websocket endpoint
|
|
117
|
+
- In WSL, Linux browser executables are preferred before Windows fallback paths
|
|
118
|
+
|
|
119
|
+
## Safety Defaults
|
|
120
|
+
|
|
121
|
+
- The broker only allows loopback browser endpoints unless you opt in
|
|
122
|
+
- The default tool surface is read-focused
|
|
123
|
+
- Arbitrary page evaluation is opt-in
|
|
124
|
+
- Clients interact with a bounded MCP tool surface instead of raw browser protocol calls
|
|
125
|
+
|
|
126
|
+
## Development
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
corepack enable
|
|
130
|
+
pnpm install
|
|
131
|
+
pnpm run check
|
|
132
|
+
pnpm run pack:check
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
The repository uses `pnpm` for local development and CI. End-user installation and publish flows still target the npm registry.
|
|
136
|
+
|
|
137
|
+
Additional docs:
|
|
138
|
+
|
|
139
|
+
- [Architecture](docs/architecture.md)
|
|
140
|
+
- [Repository Settings](docs/repository-settings.md)
|
|
141
|
+
- [Publishing](PUBLISHING.md)
|
package/cli.mjs
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mcp-browser-dev-tools",
|
|
3
|
+
"version": "0.0.1-beta.1",
|
|
4
|
+
"description": "Local MCP server for Chromium DevTools Protocol and Firefox WebDriver BiDi",
|
|
5
|
+
"author": "Hinaser <rindo.hinase@gmail.com>",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"packageManager": "pnpm@10.29.3",
|
|
8
|
+
"homepage": "https://github.com/Hinaser/mcp-browser-dev-tools#readme",
|
|
9
|
+
"main": "./src/index.mjs",
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/Hinaser/mcp-browser-dev-tools/issues"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/Hinaser/mcp-browser-dev-tools.git"
|
|
16
|
+
},
|
|
17
|
+
"exports": {
|
|
18
|
+
".": "./src/index.mjs",
|
|
19
|
+
"./package.json": "./package.json"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"cli.mjs",
|
|
23
|
+
"src/app.mjs",
|
|
24
|
+
"src/browser-adapter.mjs",
|
|
25
|
+
"src/browser-launcher.mjs",
|
|
26
|
+
"src/cdp-client.mjs",
|
|
27
|
+
"src/cli.mjs",
|
|
28
|
+
"src/config.mjs",
|
|
29
|
+
"src/doctor.mjs",
|
|
30
|
+
"src/firefox-bidi-client.mjs",
|
|
31
|
+
"src/index.mjs",
|
|
32
|
+
"src/json-rpc-stdio.mjs",
|
|
33
|
+
"src/mcp-server.mjs",
|
|
34
|
+
"src/package-info.mjs",
|
|
35
|
+
"src/session-events.mjs",
|
|
36
|
+
"src/server.mjs",
|
|
37
|
+
"README.md"
|
|
38
|
+
],
|
|
39
|
+
"bin": {
|
|
40
|
+
"mcp-browser-dev-tools": "cli.mjs"
|
|
41
|
+
},
|
|
42
|
+
"keywords": [
|
|
43
|
+
"mcp",
|
|
44
|
+
"mcp-server",
|
|
45
|
+
"model-context-protocol",
|
|
46
|
+
"browser",
|
|
47
|
+
"devtools",
|
|
48
|
+
"cdp",
|
|
49
|
+
"webdriver-bidi",
|
|
50
|
+
"chromium",
|
|
51
|
+
"firefox",
|
|
52
|
+
"cli"
|
|
53
|
+
],
|
|
54
|
+
"engines": {
|
|
55
|
+
"node": ">=24",
|
|
56
|
+
"pnpm": ">=10"
|
|
57
|
+
},
|
|
58
|
+
"scripts": {
|
|
59
|
+
"start": "node src/cli.mjs serve",
|
|
60
|
+
"dev": "node --watch src/cli.mjs serve",
|
|
61
|
+
"doctor": "node src/cli.mjs doctor",
|
|
62
|
+
"lint": "eslint .",
|
|
63
|
+
"lint:fix": "eslint . --fix",
|
|
64
|
+
"format": "prettier --write .",
|
|
65
|
+
"format:check": "prettier --check .",
|
|
66
|
+
"check": "node --run lint && node --run format:check && node --run test",
|
|
67
|
+
"prepare": "husky",
|
|
68
|
+
"pack:check": "node scripts/pack-check.mjs",
|
|
69
|
+
"prepublishOnly": "node --run check",
|
|
70
|
+
"test": "node --test"
|
|
71
|
+
},
|
|
72
|
+
"lint-staged": {
|
|
73
|
+
"*.mjs": [
|
|
74
|
+
"eslint --fix",
|
|
75
|
+
"prettier --write"
|
|
76
|
+
],
|
|
77
|
+
"*.{json,md,yml,yaml}": "prettier --write"
|
|
78
|
+
},
|
|
79
|
+
"devDependencies": {
|
|
80
|
+
"@eslint/js": "^10.0.1",
|
|
81
|
+
"eslint": "^10.0.3",
|
|
82
|
+
"globals": "^17.4.0",
|
|
83
|
+
"husky": "^9.1.7",
|
|
84
|
+
"lint-staged": "^16.3.2",
|
|
85
|
+
"prettier": "^3.8.1"
|
|
86
|
+
}
|
|
87
|
+
}
|
package/src/app.mjs
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { createBrowserAdapter } from "./browser-adapter.mjs";
|
|
2
|
+
import { loadConfig } from "./config.mjs";
|
|
3
|
+
import { McpBrowserDevToolsServer } from "./mcp-server.mjs";
|
|
4
|
+
import { PACKAGE_NAME } from "./package-info.mjs";
|
|
5
|
+
|
|
6
|
+
export function createBrowserDevToolsApp({
|
|
7
|
+
env = process.env,
|
|
8
|
+
input = process.stdin,
|
|
9
|
+
output = process.stdout,
|
|
10
|
+
errorOutput = process.stderr,
|
|
11
|
+
} = {}) {
|
|
12
|
+
const config = loadConfig(env);
|
|
13
|
+
const browserAdapter = createBrowserAdapter(config);
|
|
14
|
+
const server = new McpBrowserDevToolsServer({
|
|
15
|
+
config,
|
|
16
|
+
browserAdapter,
|
|
17
|
+
input,
|
|
18
|
+
output,
|
|
19
|
+
errorOutput,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
let closing = false;
|
|
23
|
+
|
|
24
|
+
async function close(signal = "shutdown") {
|
|
25
|
+
if (closing) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
closing = true;
|
|
30
|
+
errorOutput.write(`[${PACKAGE_NAME}] shutting down after ${signal}\n`);
|
|
31
|
+
await browserAdapter.closeAll();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function start() {
|
|
35
|
+
server.start();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function installSignalHandlers() {
|
|
39
|
+
process.on("SIGINT", () => {
|
|
40
|
+
void close("SIGINT").finally(() => process.exit(0));
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
process.on("SIGTERM", () => {
|
|
44
|
+
void close("SIGTERM").finally(() => process.exit(0));
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
config,
|
|
50
|
+
browserAdapter,
|
|
51
|
+
server,
|
|
52
|
+
start,
|
|
53
|
+
close,
|
|
54
|
+
installSignalHandlers,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CdpSessionManager } from "./cdp-client.mjs";
|
|
2
|
+
import { FirefoxBidiSessionManager } from "./firefox-bidi-client.mjs";
|
|
3
|
+
|
|
4
|
+
export function createBrowserAdapter(config) {
|
|
5
|
+
if (config.browserFamily === "firefox") {
|
|
6
|
+
return new FirefoxBidiSessionManager(config);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
return new CdpSessionManager(config);
|
|
10
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { access } from "node:fs/promises";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { constants } from "node:fs";
|
|
5
|
+
|
|
6
|
+
function splitPathEntries(value) {
|
|
7
|
+
return value ? value.split(path.delimiter).filter(Boolean) : [];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async function isExecutable(filePath) {
|
|
11
|
+
try {
|
|
12
|
+
await access(filePath, constants.X_OK);
|
|
13
|
+
return true;
|
|
14
|
+
} catch {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function detectPlatform(env = process.env) {
|
|
20
|
+
const release = os.release().toLowerCase();
|
|
21
|
+
if (
|
|
22
|
+
process.platform === "linux" &&
|
|
23
|
+
(release.includes("microsoft") || env.WSL_INTEROP)
|
|
24
|
+
) {
|
|
25
|
+
return "wsl";
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return process.platform;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function isAbsoluteExecutableCandidate(candidate) {
|
|
32
|
+
return path.isAbsolute(candidate) || path.win32.isAbsolute(candidate);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function getBrowserCandidates(
|
|
36
|
+
family,
|
|
37
|
+
env = process.env,
|
|
38
|
+
platform = detectPlatform(env),
|
|
39
|
+
) {
|
|
40
|
+
if (family === "firefox") {
|
|
41
|
+
if (platform === "darwin") {
|
|
42
|
+
return ["/Applications/Firefox.app/Contents/MacOS/firefox", "firefox"];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (platform === "wsl") {
|
|
46
|
+
return [
|
|
47
|
+
"firefox",
|
|
48
|
+
"/mnt/c/Program Files/Mozilla Firefox/firefox.exe",
|
|
49
|
+
"firefox.exe",
|
|
50
|
+
];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (platform === "win32") {
|
|
54
|
+
return [
|
|
55
|
+
"C:\\Program Files\\Mozilla Firefox\\firefox.exe",
|
|
56
|
+
"firefox.exe",
|
|
57
|
+
"firefox",
|
|
58
|
+
];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return ["firefox"];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (platform === "darwin") {
|
|
65
|
+
return [
|
|
66
|
+
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
|
|
67
|
+
"google-chrome",
|
|
68
|
+
"chromium",
|
|
69
|
+
"chromium-browser",
|
|
70
|
+
];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (platform === "wsl") {
|
|
74
|
+
return [
|
|
75
|
+
"chromium-browser",
|
|
76
|
+
"chromium",
|
|
77
|
+
"google-chrome",
|
|
78
|
+
"google-chrome-stable",
|
|
79
|
+
"/mnt/c/Program Files/Google/Chrome/Application/chrome.exe",
|
|
80
|
+
"/mnt/c/Program Files/Chromium/Application/chrome.exe",
|
|
81
|
+
"google-chrome.exe",
|
|
82
|
+
"chromium.exe",
|
|
83
|
+
];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (platform === "win32") {
|
|
87
|
+
return [
|
|
88
|
+
"C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe",
|
|
89
|
+
"C:\\Program Files\\Chromium\\Application\\chrome.exe",
|
|
90
|
+
"chrome.exe",
|
|
91
|
+
"chromium.exe",
|
|
92
|
+
"chromium-browser",
|
|
93
|
+
"chromium",
|
|
94
|
+
"google-chrome",
|
|
95
|
+
];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return [
|
|
99
|
+
"google-chrome",
|
|
100
|
+
"google-chrome-stable",
|
|
101
|
+
"chromium",
|
|
102
|
+
"chromium-browser",
|
|
103
|
+
];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export async function findBrowserExecutable(family, env = process.env) {
|
|
107
|
+
const candidates = getBrowserCandidates(family, env);
|
|
108
|
+
const pathEntries = splitPathEntries(env.PATH);
|
|
109
|
+
|
|
110
|
+
for (const candidate of candidates) {
|
|
111
|
+
if (isAbsoluteExecutableCandidate(candidate)) {
|
|
112
|
+
if (await isExecutable(candidate)) {
|
|
113
|
+
return candidate;
|
|
114
|
+
}
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
for (const pathEntry of pathEntries) {
|
|
119
|
+
const resolved = path.join(pathEntry, candidate);
|
|
120
|
+
if (await isExecutable(resolved)) {
|
|
121
|
+
return resolved;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export async function detectInstalledBrowsers(env = process.env) {
|
|
130
|
+
const chromium = await findBrowserExecutable("chromium", env);
|
|
131
|
+
const firefox = await findBrowserExecutable("firefox", env);
|
|
132
|
+
|
|
133
|
+
return {
|
|
134
|
+
chromium,
|
|
135
|
+
firefox,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function buildBrowserLaunchArgs({
|
|
140
|
+
family,
|
|
141
|
+
url,
|
|
142
|
+
remoteDebuggingPort,
|
|
143
|
+
remoteDebuggingAddress,
|
|
144
|
+
userDataDir,
|
|
145
|
+
}) {
|
|
146
|
+
if (!url) {
|
|
147
|
+
throw new Error("A target URL is required");
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const args = [];
|
|
151
|
+
if (family === "firefox") {
|
|
152
|
+
if (remoteDebuggingPort) {
|
|
153
|
+
args.push(`--remote-debugging-port=${remoteDebuggingPort}`);
|
|
154
|
+
}
|
|
155
|
+
args.push(url);
|
|
156
|
+
return args;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (remoteDebuggingAddress) {
|
|
160
|
+
args.push(`--remote-debugging-address=${remoteDebuggingAddress}`);
|
|
161
|
+
}
|
|
162
|
+
if (remoteDebuggingPort) {
|
|
163
|
+
args.push(`--remote-debugging-port=${remoteDebuggingPort}`);
|
|
164
|
+
}
|
|
165
|
+
if (userDataDir) {
|
|
166
|
+
args.push(`--user-data-dir=${userDataDir}`);
|
|
167
|
+
}
|
|
168
|
+
args.push(url);
|
|
169
|
+
return args;
|
|
170
|
+
}
|