@ricsam/browser-mcp 0.0.0 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +14 -0
- package/README.md +51 -43
- package/THIRD_PARTY_NOTICES.md +17 -0
- package/dist/chunk-1sjcwr28.js +4 -0
- package/dist/chunk-2hzkme2s.js +41 -0
- package/dist/chunk-847prxk6.js +98 -0
- package/dist/chunk-cy1a8r79.js +255 -0
- package/dist/chunk-j6psfksr.js +52 -0
- package/dist/chunk-s1kjxpf5.js +5005 -0
- package/dist/chunk-swy0qtx0.js +60 -0
- package/dist/chunk-xgk37h9a.js +77 -0
- package/dist/main.js +36 -0
- package/package.json +10 -7
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import {
|
|
2
|
+
connectForward
|
|
3
|
+
} from "./chunk-cy1a8r79.js";
|
|
4
|
+
import"./chunk-1sjcwr28.js";
|
|
5
|
+
|
|
6
|
+
// cli/src/agent/forward.ts
|
|
7
|
+
import { constants } from "node:fs";
|
|
8
|
+
import { open } from "node:fs/promises";
|
|
9
|
+
async function runForward(args) {
|
|
10
|
+
if (args.includes("--help")) {
|
|
11
|
+
console.log(`browser-mcp forward --capability-file <private-json-file> | --stdin
|
|
12
|
+
One lease, no reconnect. Capability bytes are sensitive; never pass a token in argv.`);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
let text;
|
|
16
|
+
if (args.length === 1 && args[0] === "--stdin") {
|
|
17
|
+
const parts = [];
|
|
18
|
+
let size = 0;
|
|
19
|
+
for await (const chunk of process.stdin) {
|
|
20
|
+
const b = Buffer.from(chunk);
|
|
21
|
+
size += b.length;
|
|
22
|
+
if (size > 16384)
|
|
23
|
+
throw new Error("capability too large");
|
|
24
|
+
parts.push(b);
|
|
25
|
+
}
|
|
26
|
+
text = Buffer.concat(parts).toString("utf8");
|
|
27
|
+
} else if (args.length === 2 && args[0] === "--capability-file") {
|
|
28
|
+
const handle = await open(args[1], constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
29
|
+
try {
|
|
30
|
+
const stat = await handle.stat();
|
|
31
|
+
if (!stat.isFile() || stat.size > 16384 || process.platform !== "win32" && ((stat.mode & 63) !== 0 || stat.uid !== process.getuid?.()))
|
|
32
|
+
throw new Error("capability file must be private, owned, regular, <=16 KiB");
|
|
33
|
+
text = await handle.readFile("utf8");
|
|
34
|
+
} finally {
|
|
35
|
+
await handle.close();
|
|
36
|
+
}
|
|
37
|
+
} else
|
|
38
|
+
throw new Error("use forward --capability-file <path> or --stdin; tokens in arguments are not accepted");
|
|
39
|
+
let cap;
|
|
40
|
+
try {
|
|
41
|
+
cap = JSON.parse(text);
|
|
42
|
+
} catch {
|
|
43
|
+
throw new Error("invalid capability JSON");
|
|
44
|
+
}
|
|
45
|
+
if (cap.role !== "agent")
|
|
46
|
+
throw new Error("agent capability required");
|
|
47
|
+
const connection = await connectForward(cap);
|
|
48
|
+
const stop = () => connection.close();
|
|
49
|
+
process.once("SIGINT", stop);
|
|
50
|
+
process.once("SIGTERM", stop);
|
|
51
|
+
try {
|
|
52
|
+
await connection.closed;
|
|
53
|
+
} finally {
|
|
54
|
+
process.removeListener("SIGINT", stop);
|
|
55
|
+
process.removeListener("SIGTERM", stop);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export {
|
|
59
|
+
runForward
|
|
60
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import {
|
|
2
|
+
capabilityFetch,
|
|
3
|
+
exclusiveOutput,
|
|
4
|
+
readCapability
|
|
5
|
+
} from "./chunk-2hzkme2s.js";
|
|
6
|
+
import"./chunk-1sjcwr28.js";
|
|
7
|
+
|
|
8
|
+
// cli/src/agent/files.ts
|
|
9
|
+
import { open, constants, unlink } from "node:fs/promises";
|
|
10
|
+
import { Readable, Transform } from "node:stream";
|
|
11
|
+
import { pipeline } from "node:stream/promises";
|
|
12
|
+
async function uploadFile(capabilityPath, inputPath) {
|
|
13
|
+
const cap = await readCapability(capabilityPath);
|
|
14
|
+
if (cap.method !== "PUT")
|
|
15
|
+
throw new Error("Upload capability required");
|
|
16
|
+
const file = await open(inputPath, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
17
|
+
try {
|
|
18
|
+
const stat = await file.stat();
|
|
19
|
+
if (!stat.isFile() || stat.size !== cap.limits.maxBytes)
|
|
20
|
+
throw new Error("Input size mismatch");
|
|
21
|
+
await capabilityFetch(cap, file.createReadStream({ autoClose: false }));
|
|
22
|
+
return { uploaded: true, bytes: stat.size };
|
|
23
|
+
} finally {
|
|
24
|
+
await file.close();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async function downloadFile(capabilityPath, outputPath) {
|
|
28
|
+
const cap = await readCapability(capabilityPath);
|
|
29
|
+
if (cap.method !== "GET")
|
|
30
|
+
throw new Error("Download capability required");
|
|
31
|
+
const file = await exclusiveOutput(outputPath);
|
|
32
|
+
let success = false;
|
|
33
|
+
try {
|
|
34
|
+
const response = await capabilityFetch(cap);
|
|
35
|
+
if (!response.body)
|
|
36
|
+
throw new Error("Missing transfer body");
|
|
37
|
+
let bytes = 0;
|
|
38
|
+
const limiter = new Transform({ transform(chunk, _encoding, callback) {
|
|
39
|
+
bytes += chunk.length;
|
|
40
|
+
if (bytes > cap.limits.maxBytes)
|
|
41
|
+
return callback(new Error("Size exceeded"));
|
|
42
|
+
callback(null, chunk);
|
|
43
|
+
} });
|
|
44
|
+
await pipeline(Readable.fromWeb(response.body), limiter, file.createWriteStream({ autoClose: false }));
|
|
45
|
+
await file.sync();
|
|
46
|
+
success = true;
|
|
47
|
+
return { downloaded: true, bytes };
|
|
48
|
+
} finally {
|
|
49
|
+
await file.close();
|
|
50
|
+
if (!success)
|
|
51
|
+
await unlink(outputPath).catch(() => {});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async function runFilesCommand(args) {
|
|
55
|
+
if (!args.length || args.includes("--help") || args[0] === "help") {
|
|
56
|
+
console.log(`Usage: files upload --capability private.json|- --input PATH
|
|
57
|
+
files download --capability private.json|- --output PATH`);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const [operation, ...rest] = args;
|
|
61
|
+
const value = (flag) => {
|
|
62
|
+
const i = rest.indexOf(flag);
|
|
63
|
+
if (i < 0 || !rest[i + 1])
|
|
64
|
+
throw new Error(`Required ${flag}`);
|
|
65
|
+
return rest[i + 1];
|
|
66
|
+
};
|
|
67
|
+
if (operation === "upload")
|
|
68
|
+
return uploadFile(value("--capability"), value("--input"));
|
|
69
|
+
if (operation === "download")
|
|
70
|
+
return downloadFile(value("--capability"), value("--output"));
|
|
71
|
+
throw new Error("Usage: files upload|download --capability private.json|- --input|--output PATH");
|
|
72
|
+
}
|
|
73
|
+
export {
|
|
74
|
+
downloadFile,
|
|
75
|
+
runFilesCommand,
|
|
76
|
+
uploadFile
|
|
77
|
+
};
|
package/dist/main.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
__require
|
|
4
|
+
} from "./chunk-1sjcwr28.js";
|
|
5
|
+
|
|
6
|
+
// cli/src/main.ts
|
|
7
|
+
var args = process.argv.slice(2);
|
|
8
|
+
var command = args.shift();
|
|
9
|
+
async function main() {
|
|
10
|
+
if (!command || command === "--help" || command === "help") {
|
|
11
|
+
console.log(`@ricsam/browser-mcp 0.3.4
|
|
12
|
+
Usage: browser-mcp browser start|status|pause|resume|stop [options]
|
|
13
|
+
browser-mcp files upload|download [options]
|
|
14
|
+
browser-mcp secrets export|exec [options]
|
|
15
|
+
browser-mcp forward --capability-file PATH
|
|
16
|
+
Browser dependencies load only for browser commands. No automatic Chrome downloads.`);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (command === "--version") {
|
|
20
|
+
console.log("0.3.4");
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (command === "browser")
|
|
24
|
+
return (await import("./chunk-s1kjxpf5.js")).runBrowser(args);
|
|
25
|
+
if (command === "files")
|
|
26
|
+
return (await import("./chunk-xgk37h9a.js")).runFilesCommand(args);
|
|
27
|
+
if (command === "secrets")
|
|
28
|
+
return (await import("./chunk-847prxk6.js")).runSecretsCommand(args);
|
|
29
|
+
if (command === "forward")
|
|
30
|
+
return (await import("./chunk-swy0qtx0.js")).runForward(args);
|
|
31
|
+
throw new Error("Unknown command. Use --help.");
|
|
32
|
+
}
|
|
33
|
+
main().catch((error) => {
|
|
34
|
+
console.error(error instanceof Error ? error.message : "Command failed");
|
|
35
|
+
process.exitCode = 1;
|
|
36
|
+
});
|
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ricsam/browser-mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
"version": "0.3.4",
|
|
4
|
+
"description": "Dedicated native Chrome companion for Browser MCP",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": { "browser-mcp": "dist/main.js" },
|
|
7
|
+
"engines": { "node": ">=22.14.0" },
|
|
8
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
9
|
+
"repository": { "type": "git", "url": "https://github.com/ricsam/browser-mcp" },
|
|
10
|
+
"files": ["dist/", "README.md", "LICENSE", "THIRD_PARTY_NOTICES.md"],
|
|
11
|
+
"dependencies": { "playwright-core": "1.63.0", "ws": "8.22.0" },
|
|
12
|
+
"devDependencies": { "@types/ws": "8.18.1", "@types/node": "22.15.30", "typescript": "5.9.3" }
|
|
10
13
|
}
|