@memoraone/mcp 0.1.59 → 0.1.61

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/cli.cjs CHANGED
@@ -231,7 +231,7 @@ var require_package = __commonJS({
231
231
  "package.json"(exports2, module2) {
232
232
  module2.exports = {
233
233
  name: "@memoraone/mcp",
234
- version: "0.1.59",
234
+ version: "0.1.61",
235
235
  type: "module",
236
236
  main: "dist/index.cjs",
237
237
  exports: {
package/dist/gateway.cjs CHANGED
@@ -14130,6 +14130,19 @@ async function removeSession(sessionId) {
14130
14130
  } catch {
14131
14131
  }
14132
14132
  }
14133
+ function pauseHeartbeatWhenGetSseCloses(req, res, sessionId) {
14134
+ let paused = false;
14135
+ const pause = () => {
14136
+ if (paused) return;
14137
+ if (!res.headersSent || res.statusCode !== 200) return;
14138
+ paused = true;
14139
+ const session = sessionsById.get(sessionId);
14140
+ if (!session || session.closed) return;
14141
+ session.heartbeat?.stop();
14142
+ };
14143
+ res.once("close", pause);
14144
+ req.socket?.once("close", pause);
14145
+ }
14133
14146
  async function closeGatewayMcpSessionsForWorkspace(workspaceRoot) {
14134
14147
  const root = path50.resolve(workspaceRoot);
14135
14148
  const ids = [...sessionsById.values()].filter((s) => s.workspaceRoot === root).map((s) => s.sessionId);
@@ -14258,6 +14271,18 @@ async function handleAuthenticatedGatewayMcpRequest(req, res, auth, options = {}
14258
14271
  await existing.transport.handleRequest(req, res, parsed3.body);
14259
14272
  return;
14260
14273
  }
14274
+ if (method === "GET") {
14275
+ const heartbeat = existing.heartbeat;
14276
+ if (heartbeat && !heartbeat.isRunning()) {
14277
+ await heartbeat.start();
14278
+ }
14279
+ pauseHeartbeatWhenGetSseCloses(req, res, existing.sessionId);
14280
+ try {
14281
+ await existing.transport.handleRequest(req, res);
14282
+ } catch {
14283
+ }
14284
+ return;
14285
+ }
14261
14286
  await existing.transport.handleRequest(req, res);
14262
14287
  return;
14263
14288
  }
@@ -14314,6 +14339,15 @@ function sendUnauthorized(res, env2, workspaceRoot) {
14314
14339
  });
14315
14340
  res.end(body);
14316
14341
  }
14342
+ function sendForbidden(res) {
14343
+ const body = "Forbidden";
14344
+ res.writeHead(403, {
14345
+ "content-type": "text/plain; charset=utf-8",
14346
+ "cache-control": "no-store",
14347
+ "content-length": Buffer.byteLength(body)
14348
+ });
14349
+ res.end(body);
14350
+ }
14317
14351
  function sendPairingGate(res, body) {
14318
14352
  res.writeHead(403, {
14319
14353
  "content-type": "text/plain; charset=utf-8",
@@ -14411,6 +14445,19 @@ async function handleGatewayMcpAuthRequest(req, res, url, options = {}) {
14411
14445
  sendPairingGate(res, "Setup required");
14412
14446
  return true;
14413
14447
  }
14448
+ } else {
14449
+ const existingCreds = await readInstallationCredentials(
14450
+ binding.repositoryBindingId
14451
+ );
14452
+ const existingOwnerId = existingCreds?.supabaseUserId;
14453
+ if (typeof existingOwnerId !== "string" || existingOwnerId.length === 0) {
14454
+ const repairedIdentity = await fetchAuthIdentity(apiUrl, token, {
14455
+ fetchImpl: options.fetchImpl
14456
+ });
14457
+ await updateInstallationCredentials(binding.repositoryBindingId, {
14458
+ supabaseUserId: repairedIdentity.supabase_user_id
14459
+ });
14460
+ }
14414
14461
  }
14415
14462
  const creds = await readInstallationCredentials(binding.repositoryBindingId);
14416
14463
  const localOwnerId = creds?.supabaseUserId;
@@ -14435,12 +14482,19 @@ async function handleGatewayMcpAuthRequest(req, res, url, options = {}) {
14435
14482
  transportOptions
14436
14483
  );
14437
14484
  return true;
14438
- } catch {
14485
+ } catch (err) {
14439
14486
  if (!canWriteGatewayResponse(res)) {
14440
14487
  return true;
14441
14488
  }
14442
- sendUnauthorized(res, env2, parsed2.workspaceRoot);
14443
- return true;
14489
+ if (err instanceof MemoraOneHttpError && err.status === 401) {
14490
+ sendUnauthorized(res, env2, parsed2.workspaceRoot);
14491
+ return true;
14492
+ }
14493
+ if (err instanceof MemoraOneHttpError && err.status === 403) {
14494
+ sendForbidden(res);
14495
+ return true;
14496
+ }
14497
+ throw err;
14444
14498
  }
14445
14499
  }
14446
14500
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@memoraone/mcp",
3
- "version": "0.1.59",
3
+ "version": "0.1.61",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "exports": {