mcp-scraper 0.2.23 → 0.2.24

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.
Files changed (35) hide show
  1. package/README.md +19 -4
  2. package/dist/bin/api-server.cjs +1 -1
  3. package/dist/bin/api-server.cjs.map +1 -1
  4. package/dist/bin/api-server.js +1 -1
  5. package/dist/bin/browser-agent-stdio-server.cjs +1 -1
  6. package/dist/bin/browser-agent-stdio-server.cjs.map +1 -1
  7. package/dist/bin/browser-agent-stdio-server.js +2 -2
  8. package/dist/bin/mcp-scraper-cli.cjs +110 -10
  9. package/dist/bin/mcp-scraper-cli.cjs.map +1 -1
  10. package/dist/bin/mcp-scraper-cli.js +110 -10
  11. package/dist/bin/mcp-scraper-cli.js.map +1 -1
  12. package/dist/bin/mcp-scraper-combined-stdio-server.cjs +8 -8
  13. package/dist/bin/mcp-scraper-combined-stdio-server.cjs.map +1 -1
  14. package/dist/bin/mcp-scraper-combined-stdio-server.js +4 -4
  15. package/dist/bin/mcp-scraper-install.cjs +8 -8
  16. package/dist/bin/mcp-scraper-install.cjs.map +1 -1
  17. package/dist/bin/mcp-scraper-install.js +2 -2
  18. package/dist/bin/mcp-stdio-server.cjs +1 -1
  19. package/dist/bin/mcp-stdio-server.cjs.map +1 -1
  20. package/dist/bin/mcp-stdio-server.js +2 -2
  21. package/dist/{chunk-IXUMOR3H.js → chunk-4TNQUYP7.js} +2 -2
  22. package/dist/chunk-ISIITOAL.js +7 -0
  23. package/dist/chunk-ISIITOAL.js.map +1 -0
  24. package/dist/{chunk-4IFAEXVH.js → chunk-Q4STSM63.js} +8 -8
  25. package/dist/chunk-Q4STSM63.js.map +1 -0
  26. package/dist/{chunk-HHUOVPAO.js → chunk-TTSW2MHR.js} +2 -2
  27. package/dist/{server-G2WYJEUQ.js → server-TZ5EMANS.js} +3 -3
  28. package/docs/mcp-tool-craft-lint.generated.md +6 -2
  29. package/package.json +1 -1
  30. package/dist/chunk-4IFAEXVH.js.map +0 -1
  31. package/dist/chunk-TEBDAK63.js +0 -7
  32. package/dist/chunk-TEBDAK63.js.map +0 -1
  33. /package/dist/{chunk-IXUMOR3H.js.map → chunk-4TNQUYP7.js.map} +0 -0
  34. /package/dist/{chunk-HHUOVPAO.js.map → chunk-TTSW2MHR.js.map} +0 -0
  35. /package/dist/{server-G2WYJEUQ.js.map → server-TZ5EMANS.js.map} +0 -0
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  buildBrowserAgentMcpServer
4
- } from "../chunk-IXUMOR3H.js";
4
+ } from "../chunk-4TNQUYP7.js";
5
5
  import "../chunk-WN7PBKMV.js";
6
6
  import "../chunk-DUEW4EOO.js";
7
- import "../chunk-TEBDAK63.js";
7
+ import "../chunk-ISIITOAL.js";
8
8
 
9
9
  // bin/browser-agent-stdio-server.ts
10
10
  import { readFileSync } from "fs";
@@ -8,7 +8,7 @@ var import_promises6 = require("fs/promises");
8
8
  var import_node_path5 = require("path");
9
9
 
10
10
  // src/version.ts
11
- var PACKAGE_VERSION = "0.2.23";
11
+ var PACKAGE_VERSION = "0.2.24";
12
12
 
13
13
  // src/lib/chrome-profiles.ts
14
14
  var import_promises = require("fs/promises");
@@ -256,6 +256,22 @@ function renderClaudeCommand(options = {}) {
256
256
  ` -- npx ${combinedNpxArgs(options).join(" ")}`
257
257
  ].join(" \\\n");
258
258
  }
259
+ function claudeMcpRemoveArgs() {
260
+ return ["mcp", "remove", "mcp-scraper", "-s", "user"];
261
+ }
262
+ function claudeMcpAddArgs(options = {}) {
263
+ const args = ["mcp", "add", "mcp-scraper", "--scope", "user"];
264
+ for (const [key, value] of Object.entries(envConfig(options))) {
265
+ args.push("--env", `${key}=${value}`);
266
+ }
267
+ args.push("--", "npx", ...combinedNpxArgs(options));
268
+ return args;
269
+ }
270
+ function normalizeAgentHost(host) {
271
+ if (host === "claude-code") return "claude";
272
+ if (host === "claude" || host === "codex" || host === "claude-desktop") return host;
273
+ throw new Error('Unknown host "' + host + '". Use: codex, claude, claude-code, or claude-desktop');
274
+ }
259
275
  function renderClaudeDesktopConfig(options = {}) {
260
276
  return JSON.stringify({
261
277
  mcpServers: {
@@ -268,8 +284,10 @@ function renderClaudeDesktopConfig(options = {}) {
268
284
  }, null, 2);
269
285
  }
270
286
  function renderAgentInstall(host, options = {}) {
287
+ const normalizedHost = normalizeAgentHost(host);
271
288
  const restart = "Restart the MCP client so it starts a fresh npx process.";
272
- if (host === "codex") {
289
+ const applyCommand = `MCP_SCRAPER_API_KEY=${apiKeyValue(options)} npx -y -p mcp-scraper@latest mcp-scraper-cli agent install claude --apply`;
290
+ if (normalizedHost === "codex") {
273
291
  return [
274
292
  "# Codex MCP config",
275
293
  renderCodexConfig(options),
@@ -277,11 +295,14 @@ function renderAgentInstall(host, options = {}) {
277
295
  restart
278
296
  ].join("\n");
279
297
  }
280
- if (host === "claude") {
298
+ if (normalizedHost === "claude") {
281
299
  return [
282
300
  "# Claude Code command",
283
301
  renderClaudeCommand(options),
284
302
  "",
303
+ "# One-command Claude Code setup",
304
+ applyCommand,
305
+ "",
285
306
  restart
286
307
  ].join("\n");
287
308
  }
@@ -2239,6 +2260,34 @@ function writeOutput(data, json) {
2239
2260
  `);
2240
2261
  }
2241
2262
  }
2263
+ function maskSecrets(value) {
2264
+ return value.replace(/sk_[A-Za-z0-9_-]+/g, "sk_***");
2265
+ }
2266
+ function runLocalCommand(command, args) {
2267
+ return new Promise((resolve) => {
2268
+ const child = (0, import_node_child_process2.spawn)(command, args, { stdio: ["ignore", "pipe", "pipe"] });
2269
+ const stdout = [];
2270
+ const stderr = [];
2271
+ let settled = false;
2272
+ const done = (result) => {
2273
+ if (settled) return;
2274
+ settled = true;
2275
+ resolve(result);
2276
+ };
2277
+ child.stdout.on("data", (chunk) => stdout.push(Buffer.from(chunk)));
2278
+ child.stderr.on("data", (chunk) => stderr.push(Buffer.from(chunk)));
2279
+ child.on("error", (err) => {
2280
+ done({ code: 127, stdout: "", stderr: err.message });
2281
+ });
2282
+ child.on("close", (code) => {
2283
+ done({
2284
+ code: typeof code === "number" ? code : 1,
2285
+ stdout: Buffer.concat(stdout).toString("utf8"),
2286
+ stderr: Buffer.concat(stderr).toString("utf8")
2287
+ });
2288
+ });
2289
+ });
2290
+ }
2242
2291
  function cadenceOpt(opts) {
2243
2292
  if (opts.daily) return "daily";
2244
2293
  if (opts.monthly) return "monthly";
@@ -2340,8 +2389,8 @@ function buildHumanCli() {
2340
2389
  "",
2341
2390
  "To clone a real local Chrome profile for MCP local browser mode:",
2342
2391
  " mcp-scraper-cli browser import-chrome --email you@example.com --name <suggested profile name>",
2343
- "Then generate config with:",
2344
- " mcp-scraper-cli agent install claude-desktop --browser-mode local --browser-profile <suggested profile name>"
2392
+ "Then apply Claude Code config with:",
2393
+ " MCP_SCRAPER_API_KEY=sk_live_your_key mcp-scraper-cli agent install claude --apply --browser-mode local --browser-profile <suggested profile name>"
2345
2394
  ];
2346
2395
  writeOutput(lines.join("\n"), false);
2347
2396
  });
@@ -2365,9 +2414,9 @@ function buildHumanCli() {
2365
2414
  `Managed user data dir: ${result.profile.userDataDir}`,
2366
2415
  "",
2367
2416
  "Install/config command:",
2368
- ` mcp-scraper-cli agent install codex --browser-mode local --browser-profile ${result.profile.name}`,
2417
+ ` MCP_SCRAPER_API_KEY=sk_live_your_key mcp-scraper-cli agent install claude --apply --browser-mode local --browser-profile ${result.profile.name}`,
2369
2418
  "",
2370
- "Restart the MCP client after updating config. Re-run sync-profile after signing into new sites in normal Chrome."
2419
+ "Fully exit Claude Code and start a new Claude terminal after applying config. Re-run sync-profile after signing into new sites in normal Chrome."
2371
2420
  ].join("\n"), false);
2372
2421
  });
2373
2422
  browser.command("sync-profile <name>").description("Refresh a managed local browser profile from its recorded source Chrome profile.").option("--output-dir <path>", "Managed profile base directory").option("--browser-executable <path>", "Chrome executable path for local launches").option("--json", "Print machine-readable JSON").action(async (name, opts) => {
@@ -2387,11 +2436,62 @@ function buildHumanCli() {
2387
2436
  ].join("\n"), false);
2388
2437
  });
2389
2438
  const agent = program.command("agent").description("Generate AI-agent install configs and workflow prompts.");
2390
- agent.command("install <host>").description("Print install/config instructions for codex, claude, or claude-desktop.").option("--api-key <key>", "API key to place in generated config").option("--package <spec>", "npm package spec", "mcp-scraper@latest").option("--browser-mode <mode>", "Browser mode: hosted or local", "hosted").option("--browser-profile <name>", "Default browser profile for browser_open sessions. In local mode this is a managed MCP Scraper profile name; in hosted mode it is a Kernel profile name.").option("--browser-executable <path>", "Chrome executable path for local browser mode").option("--save-browser-profile-changes", "Persist cookies/local storage back to the named browser profile when sessions close").option("--json", "Print machine-readable JSON").action((host, opts) => {
2391
- const valid = ["codex", "claude", "claude-desktop"];
2392
- if (!valid.includes(host)) throw new Error(`Unknown host "${host}". Use: ${valid.join(", ")}`);
2439
+ agent.command("install <host>").description("Print or apply install/config instructions for codex, claude/claude-code, or claude-desktop.").option("--api-key <key>", "API key to place in generated config").option("--package <spec>", "npm package spec", "mcp-scraper@latest").option("--browser-mode <mode>", "Browser mode: hosted or local", "hosted").option("--browser-profile <name>", "Default browser profile for browser_open sessions. In local mode this is a managed MCP Scraper profile name; in hosted mode it is a Kernel profile name.").option("--browser-executable <path>", "Chrome executable path for local browser mode").option("--save-browser-profile-changes", "Persist cookies/local storage back to the named browser profile when sessions close").option("--apply", "Apply the config to the local client when supported. For Claude Code, this upserts the user-scope mcp-scraper server.").option("--json", "Print machine-readable JSON").action(async (hostInput, opts) => {
2440
+ const host = normalizeAgentHost(hostInput);
2393
2441
  const browserMode = String(opts.browserMode ?? "hosted");
2394
2442
  if (!["hosted", "local"].includes(browserMode)) throw new Error("Unknown browser mode. Use: hosted or local");
2443
+ const apiKey = opts.apiKey ?? process.env.MCP_SCRAPER_API_KEY;
2444
+ if (opts.apply) {
2445
+ if (host !== "claude") throw new Error('--apply is currently supported for Claude Code only. Use host "claude" or "claude-code".');
2446
+ if (!apiKey?.trim()) {
2447
+ throw new Error("MCP_SCRAPER_API_KEY is required for --apply. Set it in the environment or pass --api-key.");
2448
+ }
2449
+ const configOptions = {
2450
+ apiKey,
2451
+ packageSpec: opts.package,
2452
+ browserMode,
2453
+ browserProfileName: opts.browserProfile,
2454
+ browserProfileSaveChanges: opts.saveBrowserProfileChanges,
2455
+ browserExecutablePath: opts.browserExecutable
2456
+ };
2457
+ const remove = await runLocalCommand("claude", claudeMcpRemoveArgs());
2458
+ const add = await runLocalCommand("claude", claudeMcpAddArgs(configOptions));
2459
+ if (add.code !== 0) {
2460
+ const reason = maskSecrets([add.stderr, add.stdout].filter(Boolean).join("\n").trim());
2461
+ throw new Error([
2462
+ "Claude Code MCP registration failed.",
2463
+ reason || "No error output returned.",
2464
+ "Make sure Claude Code is installed and the `claude` command is on PATH."
2465
+ ].join("\n"));
2466
+ }
2467
+ const list = await runLocalCommand("claude", ["mcp", "list"]);
2468
+ const result = {
2469
+ host: "claude",
2470
+ applied: true,
2471
+ replacedExisting: remove.code === 0,
2472
+ command: "npx",
2473
+ args: ["-y", "-p", opts.package, "mcp-scraper-combined"],
2474
+ nextStep: "Fully exit Claude Code, start a new Claude terminal, then run: claude mcp list",
2475
+ list: maskSecrets([list.stdout, list.stderr].filter(Boolean).join("\n").trim())
2476
+ };
2477
+ if (opts.json) {
2478
+ writeOutput(result, true);
2479
+ return;
2480
+ }
2481
+ writeOutput([
2482
+ "Applied Claude Code MCP config: mcp-scraper",
2483
+ remove.code === 0 ? "Replaced existing mcp-scraper entry." : "No existing mcp-scraper entry found; added a new one.",
2484
+ "Command: npx -y -p " + opts.package + " mcp-scraper-combined",
2485
+ browserMode === "local" && opts.browserProfile ? `Local browser profile: ${opts.browserProfile}` : "",
2486
+ "",
2487
+ "Next step: fully exit Claude Code, start a new Claude terminal, then run:",
2488
+ " claude mcp list",
2489
+ "",
2490
+ result.list ? `Current Claude MCP list:
2491
+ ${result.list}` : ""
2492
+ ].filter(Boolean).join("\n"), false);
2493
+ return;
2494
+ }
2395
2495
  const text = renderAgentInstall(host, {
2396
2496
  apiKey: opts.apiKey,
2397
2497
  packageSpec: opts.package,