mcp-browser-dev-tools 0.0.1-beta.1 → 0.0.1-beta.2

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
@@ -12,7 +12,7 @@ It is designed for a local trust boundary:
12
12
  - Browser discovery and attach/detach for Chromium-family browsers and Firefox
13
13
  - Read-oriented tools for DOM inspection, element lookup, console messages, network requests, screenshots, tab listing, and buffered events
14
14
  - Optional JavaScript evaluation behind an explicit environment flag
15
- - Helper commands to check browser connectivity and launch a debug-enabled browser
15
+ - Helper commands to check browser connectivity, launch a debug-enabled browser, and relay CDP traffic across a local machine boundary
16
16
 
17
17
  ## Requirements
18
18
 
@@ -22,6 +22,8 @@ It is designed for a local trust boundary:
22
22
 
23
23
  ## Install
24
24
 
25
+ If you are trying the prerelease from npm, replace `mcp-browser-dev-tools` below with `mcp-browser-dev-tools@beta`.
26
+
25
27
  One-off execution with `npx`:
26
28
 
27
29
  ```bash
@@ -42,6 +44,35 @@ npm install mcp-browser-dev-tools
42
44
  npx mcp-browser-dev-tools serve
43
45
  ```
44
46
 
47
+ ## Try It Locally
48
+
49
+ You can smoke-test the broker before wiring it into an MCP client.
50
+
51
+ For Windows, WSL, macOS, and Linux-specific setup paths, see [docs/setup.md](docs/setup.md).
52
+
53
+ Quick Chromium flow:
54
+
55
+ ```bash
56
+ # Launch a local browser with remote debugging enabled
57
+ npx -y mcp-browser-dev-tools@beta open https://example.com --family chromium
58
+
59
+ # Verify that the browser endpoint and page are reachable
60
+ npx -y mcp-browser-dev-tools@beta doctor --url https://example.com
61
+
62
+ # Start the MCP server in a dedicated terminal
63
+ npx -y mcp-browser-dev-tools@beta serve
64
+ ```
65
+
66
+ `serve` stays attached to stdio because MCP clients talk to it over standard input and output. Run it in its own terminal or let your MCP client spawn it directly.
67
+
68
+ If you already have a browser listening on `http://127.0.0.1:9222`, `doctor` is enough to confirm that the broker can reach it:
69
+
70
+ ```bash
71
+ CDP_BASE_URL=http://127.0.0.1:9222 npx -y mcp-browser-dev-tools@beta doctor
72
+ ```
73
+
74
+ If you need to bridge Windows Chrome into WSL without changing WSL networking mode, run the relay on Windows and point WSL at the relay port instead. The full procedure is in [docs/setup.md](docs/setup.md).
75
+
45
76
  ## MCP Client Configuration
46
77
 
47
78
  Generic stdio client configuration:
@@ -68,6 +99,7 @@ For Firefox, switch `MCP_BROWSER_FAMILY` to `firefox` and set `FIREFOX_BIDI_WS_U
68
99
  - `serve` runs the MCP broker over stdio
69
100
  - `doctor [--url URL]` checks browser reachability, local display state, and optional page access
70
101
  - `open <url>` launches a local browser with remote debugging enabled
102
+ - `relay` forwards TCP traffic, useful for Windows-to-WSL DevTools bridging
71
103
  - `--help` and `help` print usage
72
104
  - `--version` and `version` print the package version
73
105
 
@@ -77,6 +109,7 @@ Examples:
77
109
  mcp-browser-dev-tools doctor
78
110
  mcp-browser-dev-tools doctor --url http://127.0.0.1:3000
79
111
  mcp-browser-dev-tools open http://127.0.0.1:3000 --family chromium
112
+ mcp-browser-dev-tools relay --wsl
80
113
  ```
81
114
 
82
115
  ## Configuration
@@ -92,6 +125,8 @@ mcp-browser-dev-tools open http://127.0.0.1:3000 --family chromium
92
125
 
93
126
  The `open` command also requires `MCP_BROWSER_ALLOW_REMOTE_ENDPOINTS=1` before it will bind Chromium remote debugging to a non-loopback address.
94
127
 
128
+ The `relay` command defaults to `127.0.0.1:9223 -> 127.0.0.1:9222`. Non-loopback relay binds require either `--wsl` on Windows or `MCP_BROWSER_ALLOW_REMOTE_ENDPOINTS=1`.
129
+
95
130
  ## Exposed Tools
96
131
 
97
132
  - `browser_status`
@@ -115,6 +150,7 @@ For tools that take `sessionId`, call `attach_tab` first and reuse the returned
115
150
  - Chromium uses the standard DevTools endpoints at `/json/version` and `/json/list`
116
151
  - Firefox support expects a direct BiDi websocket endpoint
117
152
  - In WSL, Linux browser executables are preferred before Windows fallback paths
153
+ - For Windows Chrome + WSL, prefer the `relay` command over changing Chrome's remote debugging bind
118
154
 
119
155
  ## Safety Defaults
120
156
 
@@ -137,5 +173,6 @@ The repository uses `pnpm` for local development and CI. End-user installation a
137
173
  Additional docs:
138
174
 
139
175
  - [Architecture](docs/architecture.md)
176
+ - [Setup Guide](docs/setup.md)
140
177
  - [Repository Settings](docs/repository-settings.md)
141
178
  - [Publishing](PUBLISHING.md)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-browser-dev-tools",
3
- "version": "0.0.1-beta.1",
3
+ "version": "0.0.1-beta.2",
4
4
  "description": "Local MCP server for Chromium DevTools Protocol and Firefox WebDriver BiDi",
5
5
  "author": "Hinaser <rindo.hinase@gmail.com>",
6
6
  "type": "module",
@@ -34,6 +34,7 @@
34
34
  "src/package-info.mjs",
35
35
  "src/session-events.mjs",
36
36
  "src/server.mjs",
37
+ "src/tcp-relay.mjs",
37
38
  "README.md"
38
39
  ],
39
40
  "bin": {
package/src/cli.mjs CHANGED
@@ -11,6 +11,7 @@ import {
11
11
  import { isLoopbackHost, loadConfig } from "./config.mjs";
12
12
  import { collectDoctorReport, renderDoctorReport } from "./doctor.mjs";
13
13
  import { PACKAGE_NAME, PACKAGE_VERSION } from "./package-info.mjs";
14
+ import { resolveRelayOptions, startTcpRelay } from "./tcp-relay.mjs";
14
15
 
15
16
  export function parseCliArgs(argv) {
16
17
  const args = [...argv];
@@ -55,6 +56,7 @@ function printUsage() {
55
56
  " serve Run the MCP broker over stdio",
56
57
  " doctor [--url URL] Check browser endpoint and optional page reachability",
57
58
  " open <url> Launch a local browser with remote debugging enabled",
59
+ " relay Forward TCP traffic across a local machine boundary",
58
60
  " version Print the package version",
59
61
  " help Print usage information",
60
62
  "",
@@ -68,6 +70,13 @@ function printUsage() {
68
70
  " --address <host> remote debugging address for Chromium",
69
71
  " --user-data-dir <p> optional browser profile directory",
70
72
  "",
73
+ "Relay options:",
74
+ " --listen-host <host> relay bind host (defaults to 127.0.0.1)",
75
+ " --listen-port <port> relay bind port (defaults to 9223)",
76
+ " --target-host <host> relay target host (defaults to 127.0.0.1)",
77
+ " --target-port <port> relay target port (defaults to 9222)",
78
+ " --wsl on Windows, bind to the WSL virtual interface",
79
+ "",
71
80
  ].join("\n"),
72
81
  );
73
82
  }
@@ -152,6 +161,34 @@ async function runOpen(positional, options) {
152
161
  );
153
162
  }
154
163
 
164
+ async function runRelay(options) {
165
+ const relayOptions = resolveRelayOptions(options);
166
+ const relay = await startTcpRelay(relayOptions);
167
+
168
+ const close = async (signal) => {
169
+ process.stderr.write(`[relay] shutting down after ${signal}\n`);
170
+ await relay.close();
171
+ };
172
+
173
+ process.on("SIGINT", () => {
174
+ void close("SIGINT").finally(() => process.exit(0));
175
+ });
176
+
177
+ process.on("SIGTERM", () => {
178
+ void close("SIGTERM").finally(() => process.exit(0));
179
+ });
180
+
181
+ process.stdout.write(
182
+ `relay listening on ${relayOptions.listenHost}:${relayOptions.listenPort} -> ${relayOptions.targetHost}:${relayOptions.targetPort}\n`,
183
+ );
184
+
185
+ if (relayOptions.useWslBridge) {
186
+ process.stdout.write(
187
+ `for WSL use: CDP_BASE_URL=http://${relayOptions.listenHost}:${relayOptions.listenPort}\n`,
188
+ );
189
+ }
190
+ }
191
+
155
192
  export async function runCli(argv = process.argv.slice(2)) {
156
193
  const { command, positional, options } = parseCliArgs(argv);
157
194
 
@@ -175,6 +212,9 @@ export async function runCli(argv = process.argv.slice(2)) {
175
212
  case "open":
176
213
  await runOpen(positional, options);
177
214
  return;
215
+ case "relay":
216
+ await runRelay(options);
217
+ return;
178
218
  case "version":
179
219
  case "-v":
180
220
  printVersion();
package/src/index.mjs CHANGED
@@ -29,3 +29,12 @@ export {
29
29
  PACKAGE_NAME,
30
30
  PACKAGE_VERSION,
31
31
  } from "./package-info.mjs";
32
+ export {
33
+ DEFAULT_RELAY_LISTEN_HOST,
34
+ DEFAULT_RELAY_LISTEN_PORT,
35
+ DEFAULT_RELAY_TARGET_HOST,
36
+ DEFAULT_RELAY_TARGET_PORT,
37
+ getWindowsWslHostCandidates,
38
+ resolveRelayOptions,
39
+ startTcpRelay,
40
+ } from "./tcp-relay.mjs";
@@ -0,0 +1,194 @@
1
+ import net from "node:net";
2
+ import os from "node:os";
3
+ import process from "node:process";
4
+
5
+ import { isLoopbackHost, isTruthyFlag } from "./config.mjs";
6
+
7
+ export const DEFAULT_RELAY_LISTEN_HOST = "127.0.0.1";
8
+ export const DEFAULT_RELAY_LISTEN_PORT = 9223;
9
+ export const DEFAULT_RELAY_TARGET_HOST = "127.0.0.1";
10
+ export const DEFAULT_RELAY_TARGET_PORT = 9222;
11
+
12
+ function allowsRemoteEndpoints(env = process.env) {
13
+ return (
14
+ isTruthyFlag(env.MCP_BROWSER_ALLOW_REMOTE_ENDPOINTS) ||
15
+ isTruthyFlag(env.MCP_BROWSER_ALLOW_REMOTE_CDP)
16
+ );
17
+ }
18
+
19
+ function normalizeHost(value, fallback) {
20
+ return typeof value === "string" && value.trim() ? value.trim() : fallback;
21
+ }
22
+
23
+ export function parseRelayPort(value, fallback, optionName) {
24
+ const normalized =
25
+ typeof value === "number"
26
+ ? String(value)
27
+ : typeof value === "string"
28
+ ? value.trim()
29
+ : "";
30
+
31
+ if (!normalized) {
32
+ return fallback;
33
+ }
34
+
35
+ if (!/^\d+$/.test(normalized)) {
36
+ throw new Error(`${optionName} must be an integer between 1 and 65535`);
37
+ }
38
+
39
+ const parsed = Number.parseInt(normalized, 10);
40
+ if (parsed < 1 || parsed > 65535) {
41
+ throw new Error(`${optionName} must be an integer between 1 and 65535`);
42
+ }
43
+
44
+ return parsed;
45
+ }
46
+
47
+ export function getWindowsWslHostCandidates(
48
+ networkInterfaces = os.networkInterfaces(),
49
+ ) {
50
+ const candidates = [];
51
+
52
+ for (const [name, addresses] of Object.entries(networkInterfaces)) {
53
+ if (!/wsl/i.test(name)) {
54
+ continue;
55
+ }
56
+
57
+ for (const addressInfo of addresses ?? []) {
58
+ if (addressInfo.internal || addressInfo.family !== "IPv4") {
59
+ continue;
60
+ }
61
+
62
+ candidates.push(addressInfo.address);
63
+ }
64
+ }
65
+
66
+ return [...new Set(candidates)];
67
+ }
68
+
69
+ export function resolveRelayOptions(
70
+ options = {},
71
+ {
72
+ env = process.env,
73
+ platform = process.platform,
74
+ networkInterfaces = null,
75
+ } = {},
76
+ ) {
77
+ const useWslBridge = options.wsl === true;
78
+ let listenHost;
79
+
80
+ if (useWslBridge) {
81
+ if (platform !== "win32") {
82
+ throw new Error("--wsl is only supported on Windows");
83
+ }
84
+
85
+ const candidates = getWindowsWslHostCandidates(
86
+ networkInterfaces ?? os.networkInterfaces(),
87
+ );
88
+ if (candidates.length === 0) {
89
+ throw new Error("Could not detect a Windows WSL host address");
90
+ }
91
+
92
+ [listenHost] = candidates;
93
+ } else {
94
+ listenHost = normalizeHost(
95
+ options["listen-host"],
96
+ DEFAULT_RELAY_LISTEN_HOST,
97
+ );
98
+
99
+ if (!isLoopbackHost(listenHost) && !allowsRemoteEndpoints(env)) {
100
+ throw new Error(
101
+ "--listen-host must be loopback unless MCP_BROWSER_ALLOW_REMOTE_ENDPOINTS=1",
102
+ );
103
+ }
104
+ }
105
+
106
+ return {
107
+ listenHost,
108
+ listenPort: parseRelayPort(
109
+ options["listen-port"],
110
+ DEFAULT_RELAY_LISTEN_PORT,
111
+ "--listen-port",
112
+ ),
113
+ targetHost: normalizeHost(
114
+ options["target-host"],
115
+ DEFAULT_RELAY_TARGET_HOST,
116
+ ),
117
+ targetPort: parseRelayPort(
118
+ options["target-port"],
119
+ DEFAULT_RELAY_TARGET_PORT,
120
+ "--target-port",
121
+ ),
122
+ useWslBridge,
123
+ };
124
+ }
125
+
126
+ export async function startTcpRelay({
127
+ listenHost,
128
+ listenPort,
129
+ targetHost,
130
+ targetPort,
131
+ errorOutput = process.stderr,
132
+ } = {}) {
133
+ const openSockets = new Set();
134
+
135
+ const server = net.createServer((clientSocket) => {
136
+ const upstreamSocket = net.connect({
137
+ host: targetHost,
138
+ port: targetPort,
139
+ });
140
+
141
+ openSockets.add(clientSocket);
142
+ openSockets.add(upstreamSocket);
143
+
144
+ const cleanup = () => {
145
+ openSockets.delete(clientSocket);
146
+ openSockets.delete(upstreamSocket);
147
+ };
148
+
149
+ clientSocket.on("close", cleanup);
150
+ upstreamSocket.on("close", cleanup);
151
+
152
+ clientSocket.on("error", () => {
153
+ upstreamSocket.destroy();
154
+ });
155
+
156
+ upstreamSocket.on("error", (error) => {
157
+ errorOutput.write(`[relay] target connection failed: ${error.message}\n`);
158
+ clientSocket.destroy();
159
+ });
160
+
161
+ clientSocket.pipe(upstreamSocket);
162
+ upstreamSocket.pipe(clientSocket);
163
+ });
164
+
165
+ await new Promise((resolve, reject) => {
166
+ server.once("error", reject);
167
+ server.listen(listenPort, listenHost, () => {
168
+ server.off("error", reject);
169
+ resolve();
170
+ });
171
+ });
172
+
173
+ async function close() {
174
+ for (const socket of openSockets) {
175
+ socket.destroy();
176
+ }
177
+
178
+ await new Promise((resolve, reject) => {
179
+ server.close((error) => {
180
+ if (error) {
181
+ reject(error);
182
+ return;
183
+ }
184
+
185
+ resolve();
186
+ });
187
+ });
188
+ }
189
+
190
+ return {
191
+ server,
192
+ close,
193
+ };
194
+ }