mcp-teams 0.3.32 → 0.3.33

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/README.md CHANGED
@@ -108,7 +108,7 @@ Every AI session starts its own mcp-teams server, and they share the one extensi
108
108
  | `port` | `TEAMS_MCP_PORT` | `47393` (also set it in the extension popup) |
109
109
  | `autoSendTo` | — | `[]`: every send shows the confirmation window |
110
110
 
111
- `autoSendTo` is a list of your own email addresses (or UPNs), compared without regard to case or surrounding spaces, e.g. `"autoSendTo": ["you@example.com"]`. With it, `send_message` posts without the confirmation window when the message goes to you alone: your notes-to-self chat, a chat whose only member is you, or `to` with just your own address. The extension decides this itself after resolving the target: it looks up your profile and posts without asking only if one of your own addresses is on the list. Anything else (other people, group chats you are in, meetings, channels, a chat or profile it can't look up) shows the window as usual. The result then says `autoSent: true`. A value that isn't a list of email addresses stops the server with an error. Restart the AI session after changing it.
111
+ `autoSendTo` is a list of your own email addresses (or UPNs), compared without regard to case or surrounding spaces, e.g. `"autoSendTo": ["you@example.com"]`. With it, `send_message` posts without the confirmation window when the message goes to you alone: your notes-to-self chat, a chat whose only member is you, or `to` with just your own address. The extension decides this itself after resolving the target: it looks up your profile and posts without asking only if one of your own addresses is on the list. Anything else (other people, group chats you are in, meetings, channels, a chat or profile it can't look up) shows the window as usual. The result then says `autoSent: true`. A send that began before Teams had shown who is signed in never goes without the window. It shows the window only when the lookups for the send reveal the account. Otherwise it is refused ("Teams hasn't shown who is signed in yet"): reload the Teams tab and send again. This includes every `to` send in that case, as it looks nothing up first. A value that isn't a list of email addresses stops the server with an error. Restart the AI session after changing it.
112
112
 
113
113
  ## Security notes
114
114
 
@@ -729,11 +729,14 @@ async function myMri() {
729
729
  */
730
730
  const accountKey = (cap) => (cap ? `${cap.base}\n${cap.oid ?? ""}` : null);
731
731
 
732
+ let accountSwitches = 0; // bumped by forgetAccount: a send sees that a switch landed while it looked things up
733
+
732
734
  /**
733
735
  * The user switched Teams to another account or tenant: forget what the previous one saw.
734
736
  * (Throttle gates stay: they are Teams' limits per service and base, not anyone's data.)
735
737
  */
736
738
  function forgetAccount() {
739
+ accountSwitches++;
737
740
  dropList();
738
741
  names.clear();
739
742
  transcripts.clear();
@@ -1360,6 +1363,7 @@ export const handlers = {
1360
1363
  async requestSend({ conversation, to, title, text, threadId, subject, autoSendTo }, ctx) {
1361
1364
  if (!String(text ?? "").trim()) throw new Error("The message is empty.");
1362
1365
  // Who the window (or an auto-send) is for: taken before anything is looked up for it.
1366
+ const switches = accountSwitches;
1363
1367
  const account = await signedInAccount();
1364
1368
  // The server's allowlist (config autoSendTo) only permits; whether this send goes without the
1365
1369
  // window is decided below from the target as resolved here (see sendsToMeAlone, isMeAlone).
@@ -1367,8 +1371,8 @@ export const handlers = {
1367
1371
  if (to?.length) {
1368
1372
  if (conversation) throw new Error("Give either a conversation or people (to), not both.");
1369
1373
  if (threadId || subject) throw new Error("reply_to and subject are for channels; a new chat takes people and an optional title.");
1370
- const me = await myMri();
1371
- if (!me) throw new Error("Teams hasn't shown who is signed in yet. Reload the Teams tab and try again.");
1374
+ if (!account) throw new Error(NOT_SHOWN);
1375
+ const me = `8:orgid:${account}`;
1372
1376
  if (allow.length && !title && (await sendsToMeAlone(to, me, allow, ctx))) {
1373
1377
  return sendWithoutConfirming({ conversation: NOTES_TO_SELF, text: String(text) }, ctx, account);
1374
1378
  }
@@ -1389,8 +1393,15 @@ export const handlers = {
1389
1393
  replyingTo = root ? teams.parseMessage(root) : { id: threadId };
1390
1394
  }
1391
1395
  const request = { conversation: conv, text: String(text), threadId: threadId ?? null, subject: subject ?? null, replyingTo };
1392
- if (allow.length && !threadId && !subject && (await isMeAlone(conv, allow, ctx))) return sendWithoutConfirming(request, ctx, account);
1393
- return askUserToConfirm(request, ctx, account);
1396
+ // Without an account known from the start, the decision to send goes to the user (the window).
1397
+ if (account && allow.length && !threadId && !subject && (await isMeAlone(conv, allow, ctx))) return sendWithoutConfirming(request, ctx, account);
1398
+ if (account) return askUserToConfirm(request, ctx, account);
1399
+ // A cold start: the lookups may have shown who is signed in. The window rests on that account,
1400
+ // unless a switch landed since the send began, when they may have been another account's.
1401
+ const shown = await signedInAccount();
1402
+ if (switches !== accountSwitches) return { sent: false, reason: ACCOUNT_CHANGED_BEFORE };
1403
+ if (!shown) throw new Error(NOT_SHOWN);
1404
+ return askUserToConfirm(request, ctx, shown);
1394
1405
  },
1395
1406
  };
1396
1407
 
@@ -1398,7 +1409,7 @@ export const handlers = {
1398
1409
  * Creates a chat with these members and me (called only after the user clicked Send).
1399
1410
  * A 1:1 chat that already exists on Teams' side comes back as that chat.
1400
1411
  */
1401
- async function createChat({ members, title }, account = null) {
1412
+ async function createChat({ members, title }, account) {
1402
1413
  const me = await myMri();
1403
1414
  const oneOnOne = members.length === 1;
1404
1415
  const body = {
@@ -1425,16 +1436,16 @@ async function createChat({ members, title }, account = null) {
1425
1436
  }
1426
1437
 
1427
1438
  /**
1428
- * An onCapture check for a post confirmed as `account` (an oid, or null when Teams hadn't shown
1429
- * who was signed in): fails before anything is sent when the session it would go out with is
1439
+ * An onCapture check for a post confirmed as `account` (an oid; requestSend goes no further
1440
+ * without one): fails before anything is sent when the session it would go out with is
1430
1441
  * another account's (Teams switched since the click).
1431
1442
  */
1432
1443
  const asConfirmed = (account) => async (cap) => {
1433
- if (account && (cap.oid ?? (await signedInAccount())) !== account) throw Object.assign(new Error(ACCOUNT_CHANGED), { accountChanged: true });
1444
+ if ((cap.oid ?? (await signedInAccount())) !== account) throw Object.assign(new Error(ACCOUNT_CHANGED), { accountChanged: true });
1434
1445
  };
1435
1446
 
1436
1447
  /** Posts a confirmed message; `account`: who confirmed it (see asConfirmed). */
1437
- async function sendMessage({ conversation, newChat, people, text, threadId, subject }, account = null) {
1448
+ async function sendMessage({ conversation, newChat, people, text, threadId, subject }, account) {
1438
1449
  if (newChat) {
1439
1450
  let id;
1440
1451
  try {
@@ -1548,11 +1559,11 @@ async function isMeAlone(conv, allow, ctx) {
1548
1559
  * Posts without the window (see above). Once started, the post runs to the end, as after a click.
1549
1560
  * `account`: who it was judged to reach alone; as after a click, it isn't posted as another (3.3).
1550
1561
  */
1551
- async function sendWithoutConfirming(request, ctx, account = null) {
1562
+ async function sendWithoutConfirming(request, ctx, account) {
1552
1563
  if (ctx?.cancelled) return WITHDRAWN;
1553
1564
  autoSending++;
1554
1565
  try {
1555
- if (account && (await signedInAccount()) !== account) return { sent: false, autoSent: true, reason: ACCOUNT_CHANGED };
1566
+ if ((await signedInAccount()) !== account) return { sent: false, autoSent: true, reason: ACCOUNT_CHANGED };
1556
1567
  return { ...(await sendMessage(request, account)), autoSent: true, note: AUTO_SENT_NOTE };
1557
1568
  } catch (err) {
1558
1569
  return { sent: false, autoSent: true, reason: sendFailure(err) };
@@ -1575,6 +1586,8 @@ export function pendingSendCount() {
1575
1586
  }
1576
1587
 
1577
1588
  const ACCOUNT_CHANGED = "The signed-in Teams account changed since this was confirmed; nothing was sent.";
1589
+ const ACCOUNT_CHANGED_BEFORE = "The signed-in Teams account changed while this send was being prepared; nothing was sent. Check who is signed in, then try again.";
1590
+ const NOT_SHOWN = "Teams hasn't shown who is signed in yet. Reload the Teams tab and try again.";
1578
1591
  const CHAT_CREATED_ACCOUNT_CHANGED =
1579
1592
  "The chat was created, but no message was sent: the signed-in Teams account changed while it was being sent. Check with list_chats (as the account that confirmed it) before trying again.";
1580
1593
 
@@ -1598,7 +1611,7 @@ const WITHDRAWN = {
1598
1611
  * the AI was told the send failed. Once the user clicked Send, the post runs to the end
1599
1612
  * and its outcome is the answer.
1600
1613
  */
1601
- async function askUserToConfirm(request, ctx, account = null) {
1614
+ async function askUserToConfirm(request, ctx, account) {
1602
1615
  if (ctx?.cancelled) return WITHDRAWN;
1603
1616
  const id = crypto.randomUUID();
1604
1617
  const win = await chrome.windows.create({
@@ -1666,7 +1679,7 @@ function onConfirmMessage(msg, sender, sendResponse) {
1666
1679
  // From here on the post runs to the end: a withdrawal no longer closes the window.
1667
1680
  p.sending = true;
1668
1681
  // Confirmed as one account, clicked after Teams switched to another: its session would post it.
1669
- if (p.account && (await signedInAccount()) !== p.account) {
1682
+ if ((await signedInAccount()) !== p.account) {
1670
1683
  p.finish({ sent: false, reason: ACCOUNT_CHANGED }, true);
1671
1684
  return sendResponse({ ok: false, error: ACCOUNT_CHANGED });
1672
1685
  }
@@ -2,7 +2,7 @@
2
2
  "manifest_version": 3,
3
3
  "key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvoz9Wexl4ZqY9YtEyBZsu/Qi5Ft5EjNUNB8b30wgt3AR8TjXI5UumcPQFBIm7ZfvBsjgrh6tBJlygsgFbZ5cB1EiI+WSz/2Wcqwz4eowKMXXPvGuDGrO+2O2zbSpTG19/MwTljI+g0TLfn8Vkoqd8z9MskKk+vCZjjV0Jk8QjVEdHypgM7H8zTuUM06SO12IIZMdeE3IURzf35zbjlfPPkJiDWoo3wB9nxAvLd57xrQhPUB/lGtCJk9mS3SY+/VwOlG5kJ9WS/RCHXcs5Qs7huIlKIatmFz7YiducvTR3DKBbjqbMTyqHzXkmkUmJRqzsYtgtKcz0C0cjFOt6uNdhwIDAQAB",
4
4
  "name": "mcp-teams bridge",
5
- "version": "0.3.32",
5
+ "version": "0.3.33",
6
6
  "description": "Lets AI assistants (via the mcp-teams MCP server) read and search Microsoft Teams chats, channels and meeting transcripts and, with your explicit confirmation, post messages.",
7
7
  "minimum_chrome_version": "116",
8
8
  "icons": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-teams",
3
- "version": "0.3.32",
3
+ "version": "0.3.33",
4
4
  "description": "MCP server that lets AI assistants work with Microsoft Teams (web) through a Chrome/Edge extension bridge",
5
5
  "keywords": ["mcp", "model-context-protocol", "teams", "microsoft-teams", "microsoft-365", "chat", "claude", "chrome-extension"],
6
6
  "repository": {