@zegazone_mcp/mcp 2.0.0 → 2.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zegazone_mcp/mcp",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "type": "module",
5
5
  "description": "MCP server wrapper for Zegazone thirdparty-v1 API",
6
6
  "publishConfig": {
@@ -13,7 +13,8 @@
13
13
  */
14
14
 
15
15
  import crypto from "node:crypto";
16
- import fs from "node:fs/promises";
16
+ import fs from "node:fs";
17
+ import fsPromises from "node:fs/promises";
17
18
  import http from "node:http";
18
19
  import path from "node:path";
19
20
  import os from "node:os";
@@ -52,6 +53,14 @@ function randomState() {
52
53
  return base64url(crypto.randomBytes(16));
53
54
  }
54
55
 
56
+ function isWsl() {
57
+ try {
58
+ return fs.readFileSync("/proc/version", "utf8").toLowerCase().includes("microsoft");
59
+ } catch {
60
+ return false;
61
+ }
62
+ }
63
+
55
64
  function openBrowser(url) {
56
65
  const plat = process.platform;
57
66
  const detached = { detached: true, stdio: "ignore" };
@@ -62,7 +71,9 @@ function openBrowser(url) {
62
71
  } else if (plat === "darwin") {
63
72
  spawn("open", [url], detached).unref();
64
73
  } else {
65
- spawn("xdg-open", [url], detached).unref();
74
+ const child = spawn("xdg-open", [url], detached);
75
+ child.on("error", () => {}); // xdg-open absent on WSL — URL already printed above
76
+ child.unref();
66
77
  }
67
78
  }
68
79
 
@@ -101,10 +112,10 @@ async function writeCredentials(filePath, tokens) {
101
112
  access_token: tokens.access_token,
102
113
  access_expires_at_ms,
103
114
  };
104
- await fs.mkdir(path.dirname(filePath), { recursive: true });
115
+ await fsPromises.mkdir(path.dirname(filePath), { recursive: true });
105
116
  const tmp = `${filePath}.${process.pid}.tmp`;
106
- await fs.writeFile(tmp, `${JSON.stringify(doc, null, 2)}\n`, { encoding: "utf8", mode: 0o600 });
107
- await fs.rename(tmp, filePath);
117
+ await fsPromises.writeFile(tmp, `${JSON.stringify(doc, null, 2)}\n`, { encoding: "utf8", mode: 0o600 });
118
+ await fsPromises.rename(tmp, filePath);
108
119
  }
109
120
 
110
121
  function buildAuthorizeUrl(redirectUri, codeChallenge, state) {
@@ -114,9 +125,9 @@ function buildAuthorizeUrl(redirectUri, codeChallenge, state) {
114
125
  u.searchParams.set("redirect_uri", redirectUri);
115
126
  u.searchParams.set("code_challenge", codeChallenge);
116
127
  u.searchParams.set("code_challenge_method", "S256");
117
- u.searchParams.set("scope", SCOPE);
118
128
  u.searchParams.set("state", state);
119
- return u.toString();
129
+ const encodedScope = SCOPE.split(" ").map((s) => encodeURIComponent(s)).join("%20");
130
+ return `${u.toString()}&scope=${encodedScope}`;
120
131
  }
121
132
 
122
133
  async function main() {
@@ -208,9 +219,20 @@ async function main() {
208
219
  });
209
220
  });
210
221
 
211
- console.error("Opening browser for Zegazone login…");
212
- console.error(`If it does not open, visit:\n${authorizeUrl}\n`);
213
- openBrowser(authorizeUrl);
222
+ if (isWsl()) {
223
+ console.error("Running in WSL2 cannot open a browser automatically.");
224
+ console.error("Open this URL in your Windows browser to authorise:\n");
225
+ console.error(` ${authorizeUrl}\n`);
226
+ console.error("Waiting for the browser callback (up to 10 minutes)…");
227
+ } else {
228
+ console.error("Opening browser for Zegazone login…");
229
+ console.error(`If the browser does not open, visit:\n ${authorizeUrl}\n`);
230
+ openBrowser(authorizeUrl);
231
+ }
232
+
233
+ const heartbeat = setInterval(() => {
234
+ process.stderr.write(".");
235
+ }, 10_000);
214
236
 
215
237
  try {
216
238
  await done;
@@ -220,6 +242,9 @@ async function main() {
220
242
  const msg = e instanceof Error ? e.message : String(e);
221
243
  console.error(msg);
222
244
  process.exit(1);
245
+ } finally {
246
+ clearInterval(heartbeat);
247
+ process.stderr.write("\n");
223
248
  }
224
249
  }
225
250