mcp-teams 0.3.32 → 0.3.34

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();
@@ -1059,6 +1062,7 @@ async function fetchMessages(id, opts) {
1059
1062
  }
1060
1063
 
1061
1064
  const MAX_PAGES = 20;
1065
+ const MESSAGES_ACCOUNT_CHANGED = ACCOUNT_CHANGED_WHILE("messages were read", "reads them as that account");
1062
1066
 
1063
1067
  /** The conversation id chatsvc pages: the conversation, or one channel post's thread. */
1064
1068
  const messagesTarget = (id, threadId) => (threadId ? `${id};messageid=${threadId}` : id);
@@ -1078,9 +1082,18 @@ async function fetchMessagePages(id, { limit, olderThan, includeSystem, threadId
1078
1082
  const linkOf = new Map();
1079
1083
  let counted = 0;
1080
1084
  let pages = 0;
1085
+ // Every page is read as one account: the user of the first page's session (its oid; a 401
1086
+ // can bring the same user a session on another base), with no switch landing meanwhile.
1087
+ const switches = accountSwitches;
1088
+ let readAs; // the oid the pages are read as, from the first session used
1089
+ const sameAccount = (cap) => {
1090
+ if (readAs === undefined) readAs = cap.oid ?? null;
1091
+ if ((cap.oid ?? null) !== readAs) throw new Error(MESSAGES_ACCOUNT_CHANGED);
1092
+ };
1081
1093
  while (path) {
1082
1094
  if (pages === MAX_PAGES) return { raw, linkOf, first, next: path, capped: true, pages };
1083
- const json = await api("chatsvc", path, { ctx });
1095
+ const json = await api("chatsvc", path, { ctx, onCapture: sameAccount });
1096
+ if (switches !== accountSwitches) throw new Error(MESSAGES_ACCOUNT_CHANGED);
1084
1097
  pages++;
1085
1098
  const msgs = json?.messages ?? [];
1086
1099
  for (const m of msgs) {
@@ -1360,6 +1373,7 @@ export const handlers = {
1360
1373
  async requestSend({ conversation, to, title, text, threadId, subject, autoSendTo }, ctx) {
1361
1374
  if (!String(text ?? "").trim()) throw new Error("The message is empty.");
1362
1375
  // Who the window (or an auto-send) is for: taken before anything is looked up for it.
1376
+ const switches = accountSwitches;
1363
1377
  const account = await signedInAccount();
1364
1378
  // The server's allowlist (config autoSendTo) only permits; whether this send goes without the
1365
1379
  // window is decided below from the target as resolved here (see sendsToMeAlone, isMeAlone).
@@ -1367,8 +1381,8 @@ export const handlers = {
1367
1381
  if (to?.length) {
1368
1382
  if (conversation) throw new Error("Give either a conversation or people (to), not both.");
1369
1383
  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.");
1384
+ if (!account) throw new Error(NOT_SHOWN);
1385
+ const me = `8:orgid:${account}`;
1372
1386
  if (allow.length && !title && (await sendsToMeAlone(to, me, allow, ctx))) {
1373
1387
  return sendWithoutConfirming({ conversation: NOTES_TO_SELF, text: String(text) }, ctx, account);
1374
1388
  }
@@ -1389,8 +1403,15 @@ export const handlers = {
1389
1403
  replyingTo = root ? teams.parseMessage(root) : { id: threadId };
1390
1404
  }
1391
1405
  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);
1406
+ // Without an account known from the start, the decision to send goes to the user (the window).
1407
+ if (account && allow.length && !threadId && !subject && (await isMeAlone(conv, allow, ctx))) return sendWithoutConfirming(request, ctx, account);
1408
+ if (account) return askUserToConfirm(request, ctx, account);
1409
+ // A cold start: the lookups may have shown who is signed in. The window rests on that account,
1410
+ // unless a switch landed since the send began, when they may have been another account's.
1411
+ const shown = await signedInAccount();
1412
+ if (switches !== accountSwitches) return { sent: false, reason: ACCOUNT_CHANGED_BEFORE };
1413
+ if (!shown) throw new Error(NOT_SHOWN);
1414
+ return askUserToConfirm(request, ctx, shown);
1394
1415
  },
1395
1416
  };
1396
1417
 
@@ -1398,7 +1419,7 @@ export const handlers = {
1398
1419
  * Creates a chat with these members and me (called only after the user clicked Send).
1399
1420
  * A 1:1 chat that already exists on Teams' side comes back as that chat.
1400
1421
  */
1401
- async function createChat({ members, title }, account = null) {
1422
+ async function createChat({ members, title }, account) {
1402
1423
  const me = await myMri();
1403
1424
  const oneOnOne = members.length === 1;
1404
1425
  const body = {
@@ -1425,16 +1446,16 @@ async function createChat({ members, title }, account = null) {
1425
1446
  }
1426
1447
 
1427
1448
  /**
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
1449
+ * An onCapture check for a post confirmed as `account` (an oid; requestSend goes no further
1450
+ * without one): fails before anything is sent when the session it would go out with is
1430
1451
  * another account's (Teams switched since the click).
1431
1452
  */
1432
1453
  const asConfirmed = (account) => async (cap) => {
1433
- if (account && (cap.oid ?? (await signedInAccount())) !== account) throw Object.assign(new Error(ACCOUNT_CHANGED), { accountChanged: true });
1454
+ if ((cap.oid ?? (await signedInAccount())) !== account) throw Object.assign(new Error(ACCOUNT_CHANGED), { accountChanged: true });
1434
1455
  };
1435
1456
 
1436
1457
  /** Posts a confirmed message; `account`: who confirmed it (see asConfirmed). */
1437
- async function sendMessage({ conversation, newChat, people, text, threadId, subject }, account = null) {
1458
+ async function sendMessage({ conversation, newChat, people, text, threadId, subject }, account) {
1438
1459
  if (newChat) {
1439
1460
  let id;
1440
1461
  try {
@@ -1548,11 +1569,11 @@ async function isMeAlone(conv, allow, ctx) {
1548
1569
  * Posts without the window (see above). Once started, the post runs to the end, as after a click.
1549
1570
  * `account`: who it was judged to reach alone; as after a click, it isn't posted as another (3.3).
1550
1571
  */
1551
- async function sendWithoutConfirming(request, ctx, account = null) {
1572
+ async function sendWithoutConfirming(request, ctx, account) {
1552
1573
  if (ctx?.cancelled) return WITHDRAWN;
1553
1574
  autoSending++;
1554
1575
  try {
1555
- if (account && (await signedInAccount()) !== account) return { sent: false, autoSent: true, reason: ACCOUNT_CHANGED };
1576
+ if ((await signedInAccount()) !== account) return { sent: false, autoSent: true, reason: ACCOUNT_CHANGED };
1556
1577
  return { ...(await sendMessage(request, account)), autoSent: true, note: AUTO_SENT_NOTE };
1557
1578
  } catch (err) {
1558
1579
  return { sent: false, autoSent: true, reason: sendFailure(err) };
@@ -1575,6 +1596,8 @@ export function pendingSendCount() {
1575
1596
  }
1576
1597
 
1577
1598
  const ACCOUNT_CHANGED = "The signed-in Teams account changed since this was confirmed; nothing was sent.";
1599
+ 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.";
1600
+ const NOT_SHOWN = "Teams hasn't shown who is signed in yet. Reload the Teams tab and try again.";
1578
1601
  const CHAT_CREATED_ACCOUNT_CHANGED =
1579
1602
  "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
1603
 
@@ -1598,7 +1621,7 @@ const WITHDRAWN = {
1598
1621
  * the AI was told the send failed. Once the user clicked Send, the post runs to the end
1599
1622
  * and its outcome is the answer.
1600
1623
  */
1601
- async function askUserToConfirm(request, ctx, account = null) {
1624
+ async function askUserToConfirm(request, ctx, account) {
1602
1625
  if (ctx?.cancelled) return WITHDRAWN;
1603
1626
  const id = crypto.randomUUID();
1604
1627
  const win = await chrome.windows.create({
@@ -1666,7 +1689,7 @@ function onConfirmMessage(msg, sender, sendResponse) {
1666
1689
  // From here on the post runs to the end: a withdrawal no longer closes the window.
1667
1690
  p.sending = true;
1668
1691
  // Confirmed as one account, clicked after Teams switched to another: its session would post it.
1669
- if (p.account && (await signedInAccount()) !== p.account) {
1692
+ if ((await signedInAccount()) !== p.account) {
1670
1693
  p.finish({ sent: false, reason: ACCOUNT_CHANGED }, true);
1671
1694
  return sendResponse({ ok: false, error: ACCOUNT_CHANGED });
1672
1695
  }
@@ -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.34",
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.34",
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": {