mcp-newoutlook 0.32.7 → 0.32.8

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.
@@ -329,6 +329,8 @@ async function gatewayCall(body, ctx) {
329
329
  const res = await sendWithRetry(
330
330
  async () => {
331
331
  await holdWhileReloading(tab.id, ctx);
332
+ // Sending it again comes after a wait: the request may be gone by now (see owaCall).
333
+ if (sentWith) ctx?.askedBy?.check();
332
334
  sentWith = newestCapture(key, cap);
333
335
  return injectInTab(tab, pageGatewayFetch, [sentWith.url, sentWith.headers, body, OWA_TIMEOUT_MS], ctx, key, sentWith);
334
336
  },
@@ -528,8 +530,8 @@ async function waitForTabLoaded(tabId, timeoutMs = 30_000) {
528
530
  }
529
531
 
530
532
  /** Waits until a session newer than `since` is captured for origin; null on timeout. */
531
- function waitForCapture(origin, since, timeoutMs) {
532
- const fresh = (cap) => (cap && cap.at > since ? cap : null);
533
+ function waitForCapture(origin, since, timeoutMs, notSession = null) {
534
+ const fresh = (cap) => (cap && cap.at > since && !(notSession && sessionId(cap) === notSession) ? cap : null);
533
535
  return whenCaptured(async () => fresh(await getCapture(origin)), (changes) => fresh(changes[`capture:${origin}`]?.newValue), timeoutMs);
534
536
  }
535
537
 
@@ -672,39 +674,55 @@ async function holdWhileReloading(tabId, ctx) {
672
674
  }
673
675
  }
674
676
 
675
- /** How long a request waits on a visible tab for a request of Outlook's own to bring a session. */
676
- const VISIBLE_SESSION_WAIT_MS = 15_000;
677
+ /** How long a request waits, on a tab it can't reload, for a request of Outlook's own to bring a session. */
678
+ const OWN_REQUEST_WAIT_MS = 15_000;
677
679
  const refreshing = new Map(); // origin -> { why, done: Promise<{ cap, refused }> }, so parallel calls reload the tab once
678
680
 
679
681
  /**
680
682
  * The captured session is lost when the extension reloads (chrome.storage.session is
681
683
  * cleared) and expires after a while. Outlook's next own request brings it back; if
682
684
  * none comes soon, reload the Outlook tab, which makes Outlook send requests. A tab that can't
683
- * be reloaded because it is visible is awake and sending requests, so only those are waited for.
685
+ * be reloaded because it is visible, or was just reloaded, is left to send requests of its own, so
686
+ * those are waited for, for a while (a quiet tab may send none for minutes). notSession: a token
687
+ * just refused, left out of the wait on a tab just reloaded. A request joining a refresh under way
688
+ * shares its wait, but not its notSession: if that brings the token it was refused, it goes on.
684
689
  * why: what asks for it ("session": a request needs one; "wake": the tab is asleep; "stuck": a
685
690
  * script never answered). Gives { cap } (null if a reload brought none), and { refused } if the tab wasn't reloaded (see reloadTab).
686
691
  */
687
- function refreshSession(tab, { quickWaitMs = 3_000, why = "session" } = {}) {
692
+ function refreshSession(tab, { quickWaitMs = 3_000, why = "session", notSession = null } = {}) {
688
693
  const origin = new URL(tab.url).origin;
689
694
  const running = refreshing.get(origin);
690
- // A stuck check's refusal answers only that check: a tab that still answers may need a session or a wake.
691
- if (running?.why === "stuck" && why !== "stuck") return running.done.then((r) => (r.refused ? refreshSession(tab, { quickWaitMs, why }) : r));
692
- if (!running) {
693
- const since = Date.now();
694
- const done = (async () => {
695
- const quick = quickWaitMs ? await waitForCapture(origin, since, quickWaitMs) : null;
696
- if (quick) return { cap: quick };
697
- const { cap, refused } = await reloadTab(tab, why, (at) => waitForCapture(origin, at, 30_000));
698
- if (!refused) return { cap };
699
- if (why !== "session") return { cap: null, refused };
700
- // A session may have come meanwhile: from the reload another path just did, or, on a tab
701
- // that is visible, from Outlook's own next request.
702
- const own = refused === "visible" ? await waitForCapture(origin, since, VISIBLE_SESSION_WAIT_MS) : await getCapture(origin);
703
- return own ? { cap: own } : { cap: null, refused };
704
- })().finally(() => refreshing.delete(origin));
705
- refreshing.set(origin, { why, done });
695
+ const again = () => refreshSession(tab, { quickWaitMs, why, notSession });
696
+ if (running) {
697
+ return running.done.then((r) => {
698
+ // A stuck check's refusal answers only that check: a tab that still answers may need a session or a wake.
699
+ if (r.refused && running.why === "stuck" && why !== "stuck") return again();
700
+ return notSession && sessionId(r.cap) === notSession ? again() : r;
701
+ });
706
702
  }
707
- return refreshing.get(origin).done;
703
+ const since = Date.now();
704
+ const done = (async () => {
705
+ const quick = quickWaitMs ? await waitForCapture(origin, since, quickWaitMs) : null;
706
+ if (quick) return { cap: quick };
707
+ const { cap, refused } = await reloadTab(tab, why, (at) => waitForCapture(origin, at, 30_000));
708
+ if (!refused) return { cap };
709
+ if (why !== "session") return { cap: null, refused };
710
+ // A session may have come meanwhile: from the reload another path just did, or from Outlook's
711
+ // own next request, which is all that can bring one to a tab that is visible or was just
712
+ // reloaded (right after a reload, its first token may be refused).
713
+ if (refused === "visible") {
714
+ const own = await waitForCapture(origin, since, OWN_REQUEST_WAIT_MS);
715
+ return own ? { cap: own } : { cap: null, refused };
716
+ }
717
+ // Waiting holds nothing else up here, so the token just refused can be left out: a page sending
718
+ // it again isn't news. Elsewhere it counts: a 401 may have passed, and the same token work again.
719
+ const stored = await getCapture(origin);
720
+ const current = notSession && sessionId(stored) === notSession ? null : stored;
721
+ const own = current ?? (refused === "recent" ? await waitForCapture(origin, since, OWN_REQUEST_WAIT_MS, notSession) : null);
722
+ return own ? { cap: own } : { cap: null, refused };
723
+ })().finally(() => refreshing.delete(origin));
724
+ refreshing.set(origin, { why, done });
725
+ return done;
708
726
  }
709
727
 
710
728
  const SESSION_HELP =
@@ -737,9 +755,13 @@ async function owaCall(action, body, at) {
737
755
  const origin = new URL(tab.url).origin;
738
756
  const key = `capture:${origin}`;
739
757
  let sentWith; // this call's, not `at`'s: other calls share `at`, and may have moved on
758
+ let sent = false;
740
759
  const send = async () => {
741
760
  // Held first: the reload that holds it brings a newer session than the one it looked up.
742
761
  await holdWhileReloading(tab.id, ctx);
762
+ // Sending again comes after a wait, and Outlook hasn't run it yet: the request may be gone by now.
763
+ if (sent) ctx?.askedBy?.check();
764
+ sent = true;
743
765
  at.cap = newestCapture(key, at.cap);
744
766
  sentWith = at.cap;
745
767
  return runInTab(tab, sentWith, action, body, ctx);
@@ -752,7 +774,7 @@ async function owaCall(action, body, at) {
752
774
  // `at` keeps a session until then: calls sharing it still need one to send.
753
775
  at.cap =
754
776
  (await forgetRefused(key, sentWith, () => chrome.storage.session.set({ [lostSessionKey(origin)]: true }))) ??
755
- (await sessionFor(tab, { quickWaitMs: 0 }));
777
+ (await sessionFor(tab, { quickWaitMs: 0, notSession: sessionId(sentWith) }));
756
778
  res = await sendWithRetry(send, { idempotent, ctx });
757
779
  if (res.status === 401 || res.status === 440) throw new NoSessionError(SESSION_HELP);
758
780
  }
@@ -2063,7 +2085,7 @@ export const handlers = {
2063
2085
  // Fail before asking the user when a Teams link can't be made (no gateway session yet).
2064
2086
  if (teams && !(await getGatewayCapture(new URL((await requestAt(ctx)).t.url).origin))) throw new Error(GATEWAY_HELP);
2065
2087
  // One context for creating it: it looks the tab up once, so every step goes to the same site,
2066
- // and it has no deadline, as nothing stops the creation half-way.
2088
+ // and it has no deadline, so a first send isn't stopped half-way through a creation.
2067
2089
  const creating = () => requestContext(0, ctx?.session ?? "");
2068
2090
  const create = async (pinned) => {
2069
2091
  // The Teams meeting is made only now, so a declined invitation leaves none behind.
@@ -2080,7 +2102,7 @@ export const handlers = {
2080
2102
  const sessionAtRead = sessionId(await getCapture(confirmedSite));
2081
2103
  const confirmedAddress = await changeMailbox(ctx);
2082
2104
  const key = ["createEvent", confirmedSite, subject, start, end, location, bodyFormat, await sha256(body), required, optional, teams];
2083
- // Once started, creating it isn't stopped half-way (a Teams meeting without its event).
2105
+ // Once started, a first send isn't stopped (a Teams meeting without its event); see askedBy below.
2084
2106
  // It goes on the tab the key's site and mailbox were read from, whichever is in front by now.
2085
2107
  // That holds the site, not the account: with no window to recheck at, a new token may mean it
2086
2108
  // went out as someone else. Its result is kept under this mailbox only if that's still the one
@@ -2093,6 +2115,9 @@ export const handlers = {
2093
2115
  async () => {
2094
2116
  ctx?.check();
2095
2117
  const pinned = creating();
2118
+ // Its own context has no deadline, but with no window nobody approved it: anything
2119
+ // sending it again answers to the request that asked for it (see owaCall).
2120
+ pinned.askedBy = ctx;
2096
2121
  const chosen = await requestAt(ctx);
2097
2122
  pinned.at = Promise.resolve({ ...chosen, ctx: pinned });
2098
2123
  const result = await create(pinned);
@@ -2,7 +2,7 @@
2
2
  "manifest_version": 3,
3
3
  "key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyYxkVrq+THOJVscuwRU4IvQ4K0VWiXVOjhDWjcwpILY3r7e/Fb+VhI813kRV149laUXLfehqI6WrQKbVs/KODArPIfiNEpm/zsb2nmgbQtoYuzMO3b5Hvsp1JNZ+IEMQGRFwHlOQt+w+qLAbSgdgLK2mtvjhGu9kWLmiK2wxKPaI0/zVAdvvthzMeGZCcC7V9tH2WX8I3RVD/PZcgmmFY38APGwgatg5AV5zz0AZEPSH7ldcAI2dHkmxuFh85k1cJJjWYEHikXc+ibTv9n1OfGbt/BzV/+QpMjbpJGmnJJrzCEqjw0WOyoabtpRKympl/jshjA5Kp+avlUvEYse12QIDAQAB",
4
4
  "name": "mcp-newoutlook bridge",
5
- "version": "0.32.7",
5
+ "version": "0.32.8",
6
6
  "description": "Lets AI assistants (via the mcp-newoutlook MCP server) read, search, draft and — with your explicit confirmation — send mail in New Outlook.",
7
7
  "minimum_chrome_version": "116",
8
8
  "icons": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-newoutlook",
3
- "version": "0.32.7",
3
+ "version": "0.32.8",
4
4
  "description": "MCP server that lets AI assistants work with New Outlook (web) through a Chrome/Edge extension bridge",
5
5
  "keywords": ["mcp", "model-context-protocol", "outlook", "office365", "email", "calendar", "claude", "chrome-extension"],
6
6
  "repository": {