mcp-camoufox 0.5.1 → 0.5.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/dist/index.js +32 -51
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -113,6 +113,37 @@ const server = new McpServer({
|
|
|
113
113
|
version: "0.2.0",
|
|
114
114
|
});
|
|
115
115
|
// ── Tools: Browser Lifecycle ───────────────────────────────────────────────
|
|
116
|
+
async function ensureCamoufoxBinary() {
|
|
117
|
+
const { execSync } = await import("child_process");
|
|
118
|
+
const { existsSync } = await import("fs");
|
|
119
|
+
const { join: pathJoin } = await import("path");
|
|
120
|
+
const os = await import("os");
|
|
121
|
+
const homeDir = os.homedir();
|
|
122
|
+
const platform = os.platform();
|
|
123
|
+
let cacheDir;
|
|
124
|
+
if (platform === "darwin") {
|
|
125
|
+
cacheDir = pathJoin(homeDir, "Library", "Caches", "camoufox");
|
|
126
|
+
}
|
|
127
|
+
else if (platform === "win32") {
|
|
128
|
+
cacheDir = pathJoin(process.env.LOCALAPPDATA || pathJoin(homeDir, "AppData", "Local"), "camoufox");
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
cacheDir = pathJoin(process.env.XDG_CACHE_HOME || pathJoin(homeDir, ".cache"), "camoufox");
|
|
132
|
+
}
|
|
133
|
+
const versionFile = pathJoin(cacheDir, "version.json");
|
|
134
|
+
if (existsSync(versionFile))
|
|
135
|
+
return;
|
|
136
|
+
console.error("\n" + "=".repeat(60));
|
|
137
|
+
console.error("[mcp-camoufox] First-time setup: downloading Camoufox (~500MB)");
|
|
138
|
+
console.error("[mcp-camoufox] Please wait 2-5 minutes...");
|
|
139
|
+
console.error("=".repeat(60) + "\n");
|
|
140
|
+
const cmd = platform === "win32" ? "npx.cmd" : "npx";
|
|
141
|
+
execSync(`${cmd} camoufox-js fetch`, {
|
|
142
|
+
stdio: "inherit", timeout: 900000,
|
|
143
|
+
env: { ...process.env, npm_config_yes: "true" },
|
|
144
|
+
});
|
|
145
|
+
console.error("\n[mcp-camoufox] Download complete.\n");
|
|
146
|
+
}
|
|
116
147
|
server.tool("browser_launch", "Launch Camoufox stealth browser and navigate to URL. Browser persists between calls. Call this first.", {
|
|
117
148
|
url: z.string().default("about:blank").describe("URL to navigate to"),
|
|
118
149
|
headless: z.boolean().default(true).describe("Run without visible window"),
|
|
@@ -133,57 +164,7 @@ server.tool("browser_launch", "Launch Camoufox stealth browser and navigate to U
|
|
|
133
164
|
ensureDirs();
|
|
134
165
|
const w = width > 0 ? width : 1280;
|
|
135
166
|
const h = height > 0 ? height : 800;
|
|
136
|
-
|
|
137
|
-
// camoufox-js does NOT auto-download — we handle it here
|
|
138
|
-
await (async () => {
|
|
139
|
-
const { execSync } = await import("child_process");
|
|
140
|
-
const { existsSync, readdirSync } = await import("fs");
|
|
141
|
-
const { join: pathJoin } = await import("path");
|
|
142
|
-
const os = await import("os");
|
|
143
|
-
// Detect cache dir per platform (same logic as camoufox-js pkgman.ts)
|
|
144
|
-
const homeDir = os.homedir();
|
|
145
|
-
const platform = os.platform();
|
|
146
|
-
let cacheDir;
|
|
147
|
-
if (platform === "darwin") {
|
|
148
|
-
cacheDir = pathJoin(homeDir, "Library", "Caches", "camoufox");
|
|
149
|
-
}
|
|
150
|
-
else if (platform === "win32") {
|
|
151
|
-
cacheDir = pathJoin(process.env.LOCALAPPDATA || pathJoin(homeDir, "AppData", "Local"), "camoufox");
|
|
152
|
-
}
|
|
153
|
-
else {
|
|
154
|
-
cacheDir = pathJoin(process.env.XDG_CACHE_HOME || pathJoin(homeDir, ".cache"), "camoufox");
|
|
155
|
-
}
|
|
156
|
-
// Check if binary exists (look for version.json inside cache dir)
|
|
157
|
-
const versionFile = pathJoin(cacheDir, "version.json");
|
|
158
|
-
const isInstalled = existsSync(versionFile);
|
|
159
|
-
if (!isInstalled) {
|
|
160
|
-
console.error("");
|
|
161
|
-
console.error("=".repeat(60));
|
|
162
|
-
console.error("[mcp-camoufox] First-time setup: downloading Camoufox browser");
|
|
163
|
-
console.error("[mcp-camoufox] This is ~500MB and only happens once.");
|
|
164
|
-
console.error("[mcp-camoufox] Please wait 2-5 minutes...");
|
|
165
|
-
console.error("=".repeat(60));
|
|
166
|
-
console.error("");
|
|
167
|
-
try {
|
|
168
|
-
// Use npx to run camoufox-js CLI fetch command
|
|
169
|
-
const cmd = platform === "win32" ? "npx.cmd" : "npx";
|
|
170
|
-
execSync(`${cmd} camoufox-js fetch`, {
|
|
171
|
-
stdio: "inherit",
|
|
172
|
-
timeout: 900000, // 15 min max
|
|
173
|
-
env: { ...process.env, npm_config_yes: "true" },
|
|
174
|
-
});
|
|
175
|
-
console.error("");
|
|
176
|
-
console.error("[mcp-camoufox] Download complete! Browser ready.");
|
|
177
|
-
console.error("");
|
|
178
|
-
}
|
|
179
|
-
catch (fetchErr) {
|
|
180
|
-
console.error(`[mcp-camoufox] Auto-download failed: ${fetchErr.message?.slice(0, 200)}`);
|
|
181
|
-
console.error("[mcp-camoufox] Try manually: npx camoufox-js fetch");
|
|
182
|
-
throw new Error("Camoufox browser binary not found. Auto-download failed. " +
|
|
183
|
-
"Please run manually: npx camoufox-js fetch");
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
})();
|
|
167
|
+
await ensureCamoufoxBinary();
|
|
187
168
|
const ctx = await Camoufox({
|
|
188
169
|
headless,
|
|
189
170
|
humanize,
|
package/package.json
CHANGED