mcp-browser-dev-tools 0.2.2 → 0.3.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 +17 -15
- package/package.json +8 -2
- package/src/action-changes.mjs +340 -0
- package/src/browser-adapter.mjs +40 -4
- package/src/cdp-client.mjs +923 -43
- package/src/config.mjs +9 -0
- package/src/firefox-bidi-client.mjs +757 -47
- package/src/json-schema.mjs +14 -1
- package/src/mcp-server.mjs +59 -8
- package/src/network-control.mjs +156 -0
- package/src/page-context.mjs +306 -2
- package/src/page-script.mjs +1175 -13
- package/src/run-steps.mjs +75 -23
- package/src/run-tabs.mjs +11 -16
- package/src/screenshot-output.mjs +92 -1
- package/src/session-events.mjs +57 -0
- package/src/tool-schemas.mjs +88 -83
- package/src/tool-sets.mjs +73 -0
- package/src/tools/action-tools.mjs +217 -77
- package/src/tools/browser-tools.mjs +12 -19
- package/src/tools/inspection-tools.mjs +88 -54
- package/src/tools/more-tools.mjs +108 -0
- package/src/tools/performance-tools.mjs +116 -0
- package/src/tools/state-tools.mjs +62 -16
- package/src/upload-files.mjs +57 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { realpath, stat } from "node:fs/promises";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
// upload_file hands local files to a web page, so it reads only from the
|
|
6
|
+
// directories the user would expect: the server's working directory
|
|
7
|
+
// (usually the project), the system temp directory, and those listed in
|
|
8
|
+
// MCP_BROWSER_UPLOAD_DIRS. Paths are compared after resolving symlinks, so
|
|
9
|
+
// a link inside an allowed directory cannot reach outside it. The boundary
|
|
10
|
+
// is against an agent a page has talked into uploading private files; it
|
|
11
|
+
// does not stop a process that can write to the allowed directories (it
|
|
12
|
+
// could swap a file for a link after the check), since such a process can
|
|
13
|
+
// read those files itself.
|
|
14
|
+
export async function allowedUploadDirs(config) {
|
|
15
|
+
const dirs = [process.cwd(), tmpdir(), ...(config.uploadDirs ?? [])];
|
|
16
|
+
const resolved = await Promise.all(
|
|
17
|
+
dirs.map((dir) => realpath(dir).catch(() => null)),
|
|
18
|
+
);
|
|
19
|
+
return Array.from(new Set(resolved.filter(Boolean)));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function inside(dir, file) {
|
|
23
|
+
const relative = path.relative(dir, file);
|
|
24
|
+
return (
|
|
25
|
+
relative !== "" &&
|
|
26
|
+
relative !== ".." &&
|
|
27
|
+
!relative.startsWith(`..${path.sep}`) &&
|
|
28
|
+
!path.isAbsolute(relative)
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// The real paths of the files to upload; throws for a path that is not
|
|
33
|
+
// absolute, not a regular file, or outside the allowed directories.
|
|
34
|
+
export async function resolveUploadPaths(paths, allowedDirs) {
|
|
35
|
+
const resolved = [];
|
|
36
|
+
for (const file of paths) {
|
|
37
|
+
if (!path.isAbsolute(file)) {
|
|
38
|
+
throw new Error(`Upload path must be absolute: ${file}`);
|
|
39
|
+
}
|
|
40
|
+
let real;
|
|
41
|
+
try {
|
|
42
|
+
real = await realpath(file);
|
|
43
|
+
} catch {
|
|
44
|
+
throw new Error(`No file at ${file}`);
|
|
45
|
+
}
|
|
46
|
+
if (!(await stat(real)).isFile()) {
|
|
47
|
+
throw new Error(`Not a regular file: ${file}`);
|
|
48
|
+
}
|
|
49
|
+
if (!allowedDirs.some((dir) => inside(dir, real))) {
|
|
50
|
+
throw new Error(
|
|
51
|
+
`${file} is outside the directories upload_file may read (the server's working directory, the temp directory, and MCP_BROWSER_UPLOAD_DIRS): ${allowedDirs.join(", ")}`,
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
resolved.push(real);
|
|
55
|
+
}
|
|
56
|
+
return resolved;
|
|
57
|
+
}
|