wick-mcp 0.11.1 → 0.13.1

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/bin/wick CHANGED
@@ -1,5 +1,100 @@
1
- #!/bin/sh
2
- # Stub that gets replaced by the real binary during postinstall.
3
- # If you see this, run: npm run postinstall
4
- echo "Error: wick binary not installed. Run: npm run postinstall" >&2
5
- exit 1
1
+ #!/usr/bin/env node
2
+ // Launcher for the Wick binary. Installs it on first run (see lib/install.js)
3
+ // so the package works even when npm skips install scripts (npm 12+), then
4
+ // runs it with this process's arguments, stdio, exit code and signals.
5
+ "use strict";
6
+
7
+ const { spawn } = require("child_process");
8
+ const fs = require("fs");
9
+ const os = require("os");
10
+ const path = require("path");
11
+ const { ensureBinary, cleanupTemp } = require("../lib/install.js");
12
+
13
+ // The node to register for MCP clients: prefer an absolute link that
14
+ // resolves to this node (a PATH entry, or a well-known location such as
15
+ // /opt/homebrew/bin/node) over process.execPath, which is often a versioned
16
+ // location (a Homebrew Cellar path) that upgrades remove.
17
+ function stableNode() {
18
+ let real;
19
+ try { real = fs.realpathSync(process.execPath); } catch { return process.execPath; }
20
+ const dirs = (process.env.PATH || "").split(path.delimiter)
21
+ .concat(["/opt/homebrew/bin", "/usr/local/bin", "/usr/bin"]);
22
+ for (const dir of dirs) {
23
+ if (!path.isAbsolute(dir)) continue;
24
+ const candidate = path.join(dir, "node");
25
+ try {
26
+ if (fs.realpathSync(candidate) === real) return candidate;
27
+ } catch { /* not here */ }
28
+ }
29
+ return process.execPath;
30
+ }
31
+
32
+ // The launcher path to register: the file inside node_modules/wick-mcp, which
33
+ // npm keeps across upgrades and which can't be confused with a different
34
+ // `wick` later installed on PATH (Homebrew's binary). Under pnpm the real
35
+ // path is a versioned store directory, so use the stable link it was run by.
36
+ function stableLauncher() {
37
+ const invoked = path.resolve(process.argv[1]);
38
+ let real = invoked;
39
+ try { real = fs.realpathSync(invoked); } catch { /* use invoked */ }
40
+ return real.includes(`${path.sep}.pnpm${path.sep}`) ? invoked : real;
41
+ }
42
+
43
+ // Signal handling is installed before anything else and never removed
44
+ // until we exit: Node drops signals that are still queued when a signal's
45
+ // last listener is removed, so handlers that came and went around the
46
+ // install could lose an interrupt and start the server anyway. Before the
47
+ // server runs, a signal cleans up any partial install and we die by it;
48
+ // afterwards it is forwarded to the server.
49
+ const SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
50
+ let child = null;
51
+ let pending = null;
52
+
53
+ function dieBy(sig) {
54
+ for (const s of SIGNALS) process.removeAllListeners(s);
55
+ // Re-raise so our parent sees the signal. Node ignores SIGPIPE and
56
+ // treats SIGUSR1 as "start the inspector", so for those (and as a
57
+ // fallback) exit with the shell convention of 128 + signal number.
58
+ const code = 128 + (os.constants.signals[sig] || 0);
59
+ if (sig !== "SIGPIPE" && sig !== "SIGUSR1") process.kill(process.pid, sig);
60
+ setImmediate(() => process.exit(code));
61
+ }
62
+
63
+ for (const sig of SIGNALS) {
64
+ process.on(sig, () => {
65
+ // Forward to a running server. If it never started (spawn failed, no
66
+ // pid) or has already exited (kill returns false), the signal is ours.
67
+ if (child && child.pid !== undefined && child.kill(sig)) return;
68
+ pending = sig;
69
+ cleanupTemp();
70
+ dieBy(sig);
71
+ });
72
+ }
73
+
74
+ ensureBinary().then(({ bin, env }) => {
75
+ if (pending) return;
76
+ // `wick setup` registers node plus this launcher (see stableLauncher),
77
+ // rather than the versioned binary.
78
+ child = spawn(bin, process.argv.slice(2), {
79
+ stdio: "inherit",
80
+ env: { ...env, WICK_LAUNCHER: stableLauncher(), WICK_LAUNCHER_NODE: stableNode() },
81
+ });
82
+ child.on("error", err => {
83
+ process.stderr.write(`wick: failed to start ${bin}: ${err.message}\n`);
84
+ process.exit(1);
85
+ });
86
+ child.on("exit", (code, signal) => {
87
+ if (signal) dieBy(signal);
88
+ else process.exit(code ?? 1);
89
+ });
90
+ }, err => {
91
+ // An interrupt that killed an install step (Ctrl-C reaches tar too) may
92
+ // still be queued for us: give it a moment, so it is reported as the
93
+ // interrupt it was rather than as an install error. A step that died on
94
+ // its own (OOM, crash) is reported as the error it is.
95
+ setTimeout(() => {
96
+ if (pending) return;
97
+ process.stderr.write(`wick: ${err.message}\n`);
98
+ process.exit(1);
99
+ }, 500);
100
+ });
package/checksums.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": "0.13.1",
3
+ "sha256": {
4
+ "wick-darwin-arm64.tar.gz": "3d67dec8792930aabda4bb733a14edbcd4b4adddaa2a9bd8e59351d7e12c45fd",
5
+ "wick-linux-amd64.tar.gz": "7294ddd93517798d43c98e242ff3f80cf53915ade7df843e3c73ba61f0ced977"
6
+ }
7
+ }
package/lib/install.js ADDED
@@ -0,0 +1,210 @@
1
+ // Locates the Wick binary for this platform, downloading and verifying it
2
+ // on first use, for the `wick` launcher (bin/wick). There is deliberately no
3
+ // install script: npm 12 blocks them by default (and warns), so the
4
+ // launcher installs on first run instead. Everything it prints goes to
5
+ // stderr, because `wick serve --mcp` speaks JSON-RPC on stdout.
6
+ "use strict";
7
+
8
+ const crypto = require("crypto");
9
+ const fs = require("fs");
10
+ const https = require("https");
11
+ const os = require("os");
12
+ const path = require("path");
13
+ const { execFileSync } = require("child_process");
14
+
15
+ const PKG_ROOT = path.join(__dirname, "..");
16
+ const VERSION = require(path.join(PKG_ROOT, "package.json")).version;
17
+ const PLATFORM = `${process.platform}-${process.arch}`;
18
+
19
+ const ASSETS = {
20
+ "darwin-arm64": { file: "wick-darwin-arm64.tar.gz", lib: false },
21
+ "linux-x64": { file: "wick-linux-amd64.tar.gz", lib: true },
22
+ };
23
+
24
+ // Release assets live on GitHub. WICK_NPM_DOWNLOAD_BASE overrides the base
25
+ // URL for tests; the checksum check below still applies to whatever it serves.
26
+ function assetUrl(file) {
27
+ const base = process.env.WICK_NPM_DOWNLOAD_BASE ||
28
+ `https://github.com/wickproject/wick/releases/download/v${VERSION}`;
29
+ return `${base}/${file}`;
30
+ }
31
+
32
+ // SHA-256 of each release asset, written by the release workflow into
33
+ // checksums.json before `npm publish`. A published package always has it;
34
+ // a checkout of the repo does not, and then downloads are refused unless
35
+ // WICK_NPM_ALLOW_UNVERIFIED=1 (development only).
36
+ function expectedSha256(file) {
37
+ try {
38
+ const sums = JSON.parse(fs.readFileSync(path.join(PKG_ROOT, "checksums.json"), "utf8"));
39
+ if (sums.version === VERSION && typeof sums.sha256?.[file] === "string") return sums.sha256[file];
40
+ } catch { /* missing or unreadable */ }
41
+ return null;
42
+ }
43
+
44
+ function log(msg) {
45
+ process.stderr.write(`wick: ${msg}\n`);
46
+ }
47
+
48
+ function writable(dir) {
49
+ try {
50
+ fs.mkdirSync(dir, { recursive: true });
51
+ fs.accessSync(dir, fs.constants.W_OK);
52
+ return true;
53
+ } catch {
54
+ return false;
55
+ }
56
+ }
57
+
58
+ // Installed binaries go under the package itself when it is writable (the
59
+ // usual global and npx installs), else under ~/.wick/npm-bin. Both are keyed
60
+ // by version so an upgrade never runs a stale binary.
61
+ function installDir() {
62
+ const inPkg = path.join(PKG_ROOT, "dist", VERSION, PLATFORM);
63
+ if (writable(path.dirname(inPkg))) return inPkg;
64
+ return path.join(os.homedir(), ".wick", "npm-bin", VERSION, PLATFORM);
65
+ }
66
+
67
+ // No progress for this long on the socket aborts the download, and no
68
+ // download (redirects included) may run past DEADLINE_MS: a link that
69
+ // trickles a few bytes every few seconds would otherwise never finish or
70
+ // fail. Generous, so slow but working links still complete.
71
+ const STALL_MS = 30000;
72
+ const DEADLINE_MS = 30 * 60000;
73
+
74
+ function download(url, dest) {
75
+ return new Promise((resolve, reject) => {
76
+ let req;
77
+ let out;
78
+ const timer = setTimeout(() => fail(new Error(`download took longer than ${DEADLINE_MS / 60000} minutes`)), DEADLINE_MS);
79
+ function fail(err) {
80
+ clearTimeout(timer);
81
+ if (req) req.destroy();
82
+ if (out) out.destroy();
83
+ reject(err);
84
+ }
85
+ function get(u, redirects) {
86
+ try {
87
+ req = https.get(u, { headers: { "User-Agent": `wick-mcp/${VERSION}` } }, res => {
88
+ if ([301, 302, 303, 307, 308].includes(res.statusCode) && res.headers.location) {
89
+ res.resume();
90
+ if (redirects >= 5) return fail(new Error("too many redirects"));
91
+ let next;
92
+ try {
93
+ next = new URL(res.headers.location, u).toString();
94
+ } catch (e) {
95
+ return fail(new Error(`bad redirect from ${u}: ${e.message}`));
96
+ }
97
+ return get(next, redirects + 1);
98
+ }
99
+ if (res.statusCode !== 200) {
100
+ res.resume();
101
+ return fail(new Error(`HTTP ${res.statusCode} for ${u}`));
102
+ }
103
+ out = fs.createWriteStream(dest);
104
+ res.pipe(out);
105
+ out.on("finish", () => out.close(() => { clearTimeout(timer); resolve(); }));
106
+ out.on("error", fail);
107
+ res.on("error", fail);
108
+ });
109
+ } catch (e) {
110
+ return fail(e);
111
+ }
112
+ req.on("error", fail);
113
+ req.setTimeout(STALL_MS, () => fail(new Error(`download stalled for ${STALL_MS / 1000}s: ${u}`)));
114
+ }
115
+ get(url, 0);
116
+ });
117
+ }
118
+
119
+ // Remove temp dirs left by first runs that died mid-install without
120
+ // cleaning up (SIGKILL, a crash). Only ones untouched for a day: no live
121
+ // download can be that old, since DEADLINE_MS ends every download long
122
+ // before. Runs killed by an ordinary signal clean up after themselves
123
+ // (bin/wick calls cleanupTemp).
124
+ const STALE_TEMP_MS = 86400000;
125
+ function sweepStaleTemps(parent) {
126
+ let names = [];
127
+ try { names = fs.readdirSync(parent); } catch { return; }
128
+ for (const name of names) {
129
+ if (!name.startsWith(".tmp-")) continue;
130
+ const p = path.join(parent, name);
131
+ try {
132
+ if (Date.now() - fs.lstatSync(p).mtimeMs > STALE_TEMP_MS) fs.rmSync(p, { recursive: true, force: true });
133
+ } catch { /* gone already */ }
134
+ }
135
+ }
136
+
137
+ function sha256(file) {
138
+ return crypto.createHash("sha256").update(fs.readFileSync(file)).digest("hex");
139
+ }
140
+
141
+ /**
142
+ * Returns { bin, env } for running Wick on this machine, downloading and
143
+ * verifying the release asset first if needed. Concurrent first runs are
144
+ * safe: each extracts into its own temp dir and the first rename wins.
145
+ */
146
+ async function ensureBinary() {
147
+ const asset = ASSETS[PLATFORM];
148
+ if (!asset) {
149
+ throw new Error(
150
+ `no prebuilt Wick binary for ${PLATFORM} (supported: ${Object.keys(ASSETS).join(", ")}). ` +
151
+ "See https://github.com/wickproject/wick for other install options.");
152
+ }
153
+ const dir = installDir();
154
+ sweepStaleTemps(path.dirname(dir));
155
+ const result = () => ({
156
+ bin: path.join(dir, "wick"),
157
+ env: asset.lib ? { ...process.env, LD_LIBRARY_PATH: [dir, process.env.LD_LIBRARY_PATH].filter(Boolean).join(":") } : process.env,
158
+ });
159
+ if (fs.existsSync(path.join(dir, "wick"))) return result();
160
+
161
+ const want = expectedSha256(asset.file);
162
+ if (!want && process.env.WICK_NPM_ALLOW_UNVERIFIED !== "1") {
163
+ throw new Error(`no checksum for ${asset.file} in this package; refusing to install an unverified binary`);
164
+ }
165
+
166
+ fs.mkdirSync(path.dirname(dir), { recursive: true });
167
+ const tmp = fs.mkdtempSync(path.join(path.dirname(dir), ".tmp-"));
168
+ // The launcher owns signal handling (bin/wick); if it is interrupted
169
+ // mid-install it calls cleanupTemp() before dying.
170
+ currentTemp = tmp;
171
+ try {
172
+ const tarball = path.join(tmp, asset.file);
173
+ log(`downloading Wick ${VERSION} for ${PLATFORM} (first run only)...`);
174
+ await download(assetUrl(asset.file), tarball);
175
+ if (want) {
176
+ const got = sha256(tarball);
177
+ if (got !== want) throw new Error(`checksum mismatch for ${asset.file}: expected ${want}, got ${got}`);
178
+ }
179
+ const stage = path.join(tmp, "x");
180
+ fs.mkdirSync(stage);
181
+ execFileSync("tar", ["xzf", tarball, "-C", stage], { stdio: ["ignore", "ignore", "inherit"] });
182
+ const bin = path.join(stage, "wick");
183
+ if (!fs.existsSync(bin)) throw new Error(`${asset.file} has no wick binary`);
184
+ fs.chmodSync(bin, 0o755);
185
+ try {
186
+ fs.renameSync(stage, dir);
187
+ } catch (e) {
188
+ // Another process installed it first; theirs is just as good.
189
+ if (!fs.existsSync(path.join(dir, "wick"))) throw e;
190
+ }
191
+ log("installed.");
192
+ } finally {
193
+ cleanupTemp();
194
+ }
195
+ return result();
196
+ }
197
+
198
+ let currentTemp = null;
199
+
200
+ /** Remove the in-progress install's temp dir, if any. Never throws. */
201
+ function cleanupTemp() {
202
+ const t = currentTemp;
203
+ currentTemp = null;
204
+ if (!t) return;
205
+ try {
206
+ fs.rmSync(t, { recursive: true, force: true });
207
+ } catch { /* the day-old sweep gets it */ }
208
+ }
209
+
210
+ module.exports = { ensureBinary, cleanupTemp, VERSION, PLATFORM, ASSETS };
package/package.json CHANGED
@@ -1,26 +1,43 @@
1
1
  {
2
2
  "name": "wick-mcp",
3
- "version": "0.11.1",
3
+ "version": "0.13.1",
4
4
  "mcpName": "io.github.wickproject/wick",
5
5
  "description": "Browser-grade web access for AI agents. Gives MCP-compatible agents (Claude Code, Cursor, etc.) the same web access their human operators have.",
6
- "keywords": ["mcp", "ai-agent", "web-fetch", "browser", "claude", "cursor"],
6
+ "keywords": [
7
+ "mcp",
8
+ "ai-agent",
9
+ "web-fetch",
10
+ "browser",
11
+ "claude",
12
+ "cursor"
13
+ ],
7
14
  "homepage": "https://getwick.dev",
8
15
  "repository": {
9
16
  "type": "git",
10
- "url": "https://github.com/wickproject/wick.git"
17
+ "url": "git+https://github.com/wickproject/wick.git"
11
18
  },
12
19
  "license": "MIT",
13
20
  "bin": {
14
21
  "wick": "bin/wick"
15
22
  },
16
- "scripts": {
17
- "postinstall": "node scripts/install.js"
18
- },
19
- "os": ["darwin", "linux"],
20
- "cpu": ["arm64", "x64"],
23
+ "os": [
24
+ "darwin",
25
+ "linux"
26
+ ],
27
+ "cpu": [
28
+ "arm64",
29
+ "x64"
30
+ ],
21
31
  "files": [
22
32
  "bin/",
23
- "scripts/",
33
+ "lib/",
34
+ "checksums.json",
24
35
  "README.md"
25
- ]
36
+ ],
37
+ "engines": {
38
+ "node": ">=18"
39
+ },
40
+ "scripts": {
41
+ "prepublishOnly": "node scripts/check-publish.js"
42
+ }
26
43
  }
@@ -1,89 +0,0 @@
1
- const https = require("https");
2
- const fs = require("fs");
3
- const path = require("path");
4
- const { execFileSync } = require("child_process");
5
-
6
- const VERSION = "0.11.1";
7
- const PLATFORM = `${process.platform}-${process.arch}`;
8
-
9
- const ASSETS = {
10
- "darwin-arm64": {
11
- url: `https://github.com/wickproject/wick/releases/download/v${VERSION}/wick-darwin-arm64.tar.gz`,
12
- sha256: "927e8543497337de09c962ed157105ec262da1d08453dfa9cc552be6ac6753ce",
13
- },
14
- "linux-x64": {
15
- url: `https://github.com/wickproject/wick/releases/download/v${VERSION}/wick-linux-amd64.tar.gz`,
16
- sha256: "0560f34791076b38e738df03104a3c687e98eda78eee5d197c682e832c35c417",
17
- hasLib: true,
18
- },
19
- };
20
-
21
- const asset = ASSETS[PLATFORM];
22
- if (!asset) {
23
- console.error(
24
- `Wick does not yet have a prebuilt binary for ${PLATFORM}.\n` +
25
- `Supported: ${Object.keys(ASSETS).join(", ")}\n` +
26
- `See https://github.com/wickproject/wick for build-from-source instructions.`
27
- );
28
- process.exit(1);
29
- }
30
-
31
- const binDir = path.join(__dirname, "..", "bin");
32
- const binPath = path.join(binDir, "wick");
33
- const tarPath = path.join(binDir, "wick.tar.gz");
34
-
35
- // Check if real binary exists (not the stub — stub is <500 bytes)
36
- if (fs.existsSync(binPath) && fs.statSync(binPath).size > 1000) {
37
- process.exit(0);
38
- }
39
-
40
- fs.mkdirSync(binDir, { recursive: true });
41
-
42
- function download(url, dest) {
43
- return new Promise((resolve, reject) => {
44
- const file = fs.createWriteStream(dest);
45
- https
46
- .get(url, (res) => {
47
- if (res.statusCode === 302 || res.statusCode === 301) {
48
- download(res.headers.location, dest).then(resolve).catch(reject);
49
- return;
50
- }
51
- if (res.statusCode !== 200) {
52
- reject(new Error(`Download failed: HTTP ${res.statusCode}`));
53
- return;
54
- }
55
- res.pipe(file);
56
- file.on("finish", () => file.close(resolve));
57
- })
58
- .on("error", reject);
59
- });
60
- }
61
-
62
- async function main() {
63
- console.log(`Downloading wick ${VERSION} for ${PLATFORM}...`);
64
- await download(asset.url, tarPath);
65
-
66
- execFileSync("tar", ["xzf", tarPath, "-C", binDir]);
67
- fs.unlinkSync(tarPath);
68
- fs.chmodSync(binPath, 0o755);
69
-
70
- // On Linux, the tarball includes libcronet.so — create a wrapper script
71
- // so LD_LIBRARY_PATH is set automatically
72
- const libPath = path.join(binDir, "libcronet.so");
73
- if (asset.hasLib && fs.existsSync(libPath)) {
74
- const realBin = path.join(binDir, "wick-bin");
75
- fs.renameSync(binPath, realBin);
76
- fs.writeFileSync(
77
- binPath,
78
- `#!/bin/sh\nLD_LIBRARY_PATH="${binDir}:$LD_LIBRARY_PATH" exec "${realBin}" "$@"\n`
79
- );
80
- fs.chmodSync(binPath, 0o755);
81
- }
82
-
83
- console.log("Wick installed successfully.");
84
- }
85
-
86
- main().catch((err) => {
87
- console.error(`Failed to install wick: ${err.message}`);
88
- process.exit(1);
89
- });