@chrischall/microsoft-teams-mcp 0.7.0 → 0.8.0

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.
@@ -7,7 +7,7 @@
7
7
  },
8
8
  "metadata": {
9
9
  "description": "MCP server for Microsoft Teams — read any chat or channel, your unread messages, and their attachments, and send messages and reactions (each confirmed first)",
10
- "version": "0.7.0"
10
+ "version": "0.8.0"
11
11
  },
12
12
  "plugins": [
13
13
  {
@@ -15,7 +15,7 @@
15
15
  "displayName": "Microsoft Teams",
16
16
  "source": "./",
17
17
  "description": "MCP server for Microsoft Teams — read any chat or channel, your unread messages, and their attachments, and send messages and reactions (each confirmed first), via your signed-in browser session",
18
- "version": "0.7.0",
18
+ "version": "0.8.0",
19
19
  "author": {
20
20
  "name": "Chris Hall"
21
21
  },
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "microsoft-teams-mcp",
3
3
  "displayName": "Microsoft Teams",
4
- "version": "0.7.0",
4
+ "version": "0.8.0",
5
5
  "description": "Microsoft Teams for Claude — read any chat or channel, your unread messages, and their attachments, and send messages and reactions (each confirmed first), using your signed-in browser session",
6
6
  "author": {
7
7
  "name": "Chris Hall",
package/README.md CHANGED
@@ -40,6 +40,29 @@ for it: `teams_mark_read`, or `mark_read: true` on `teams_list_messages`
40
40
  chat-service API and change nothing until you confirm (see
41
41
  [Writes](#writes)).
42
42
 
43
+ ## Pairing
44
+
45
+ The bridge remembers a pairing only for the exact set of domains it approved,
46
+ and approving a grant replaces the stored list of header captures. So all of
47
+ this server's captures (chat service, SharePoint, Substrate search) declare the
48
+ **same** scope: the three domains `teams.cloud.microsoft`, `sharepoint.com` and
49
+ `substrate.office.com`, plus the chat-service and search captures and one
50
+ capture per SharePoint host the server has already captured from. Each capture
51
+ still reads only the one header it needs. The SharePoint hosts are remembered
52
+ in `~/.microsoft-teams-mcp/bridge-scope.json` (beside the SharePoint token
53
+ cache; not written with `TEAMS_TOKEN_CACHE=false`) once a capture from them
54
+ succeeds.
55
+
56
+ Up to 0.7, each capture declared only its own domain, so the bridge asked to
57
+ pair again (or to update its grants) whenever the server moved between chats,
58
+ search and files. Upgrading from 0.7 asks to pair **once** more, for the
59
+ combined scope; after that it stays paired.
60
+
61
+ If you run the bridge in more than one browser or browser profile, each one is a
62
+ different extension identity, and the server trusts only the one it paired
63
+ with. Keep the bridge enabled in the browser you pair with (or re-pair
64
+ deliberately with `FETCHPROXY_TRUST_NEW_EXTENSION=1` after switching browsers).
65
+
43
66
  ## SharePoint file download
44
67
 
45
68
  A **shared file** in a chat or channel is not in Teams' own object store
@@ -48,15 +71,15 @@ chat-service token. So `teams_get_attachment` captures a **separate SharePoint
48
71
  token** and fetches the file through SharePoint's `v2.1` shares API, then
49
72
  downloads the pre-signed link it returns (with no token attached).
50
73
 
51
- Two things follow from that, both one-time and additive — they do **not** change
52
- how the chat-service token is captured:
74
+ Two things follow from that:
53
75
 
54
- - **A one-time re-pair.** The SharePoint path declares a second trust scope,
55
- `sharepoint.com`, so the ContextMint Bridge grant has to cover it. If you
56
- paired `microsoft-teams-mcp` before this feature, revoke and re-pair it in the
57
- bridge popup once to add the SharePoint scope (a `not in declared set` error
58
- on a file download is this, nothing more). The chat-service capture is
59
- untouched — it still trusts only `teams.cloud.microsoft`.
76
+ - **One pairing covers it.** Every capture this server makes — chat service,
77
+ SharePoint and search — declares the same ContextMint Bridge scope: the domains
78
+ `teams.cloud.microsoft`, `sharepoint.com` and `substrate.office.com`, and the
79
+ same list of header captures. So approving `microsoft-teams-mcp` once covers
80
+ all three, and moving between chats, files and search never asks again (see
81
+ [Pairing](#pairing)). The first file from a new SharePoint host asks once to
82
+ grant that host's capture.
60
83
  - **Open the file once per SharePoint host.** The SharePoint token is captured
61
84
  from the browser's own request to the file's SharePoint host, is short-lived
62
85
  (~53 minutes), and is scoped to one host family. So the first file from a
@@ -76,10 +99,8 @@ Substrate does not accept the chat-service token either, so search captures a
76
99
  in `~/.microsoft-teams-mcp/substrate-token.json`. As with the other two, it is
77
100
  read only from the request header, never from page storage.
78
101
 
79
- - **A one-time re-pair.** The search path declares its own trust scope,
80
- `substrate.office.com`, which the ContextMint Bridge grant has to cover. If you
81
- paired `microsoft-teams-mcp` before this feature, revoke and re-pair it in the
82
- bridge popup once. The chat-service and SharePoint captures are untouched.
102
+ - **No separate pairing.** Search is part of the one bridge scope every capture
103
+ declares (see [Pairing](#pairing)), so the pairing that reads chats covers it.
83
104
  - **Run a search in Teams once.** The token is read off the Teams tab's own
84
105
  search request, so the first search may need you to type anything into the
85
106
  Teams search box and press Enter while the capture waits
@@ -170,7 +191,7 @@ Everything is optional — by default the token is captured from your browser.
170
191
  | `TEAMS_SUBSTRATE_TOKEN_FILE` | Where the captured Substrate search token is cached. Defaults to `~/.microsoft-teams-mcp/substrate-token.json`. `TEAMS_TOKEN_CACHE=false` keeps it in memory too. |
171
192
  | `TEAMS_SHAREPOINT_TOKEN_FILE` | Where the captured SharePoint tokens (one per host, used to download shared files) are cached. Defaults to `~/.microsoft-teams-mcp/sharepoint-tokens.json`. `TEAMS_TOKEN_CACHE=false` keeps them in memory too. |
172
193
  | `TEAMS_TIME_ZONE` | Default IANA time zone (e.g. `America/New_York`) for the `tz` argument of `teams_list_messages` and `teams_list_unread_messages`: each message then carries `time_local` (ISO 8601 with offset) next to its UTC `time`. Unset means no `time_local` unless `tz` is passed; a name `Intl` does not know is reported as an error. |
173
- | `TEAMS_OUTPUT_DIR` | Folder `teams_export_messages` writes exports into (each export gets its own timestamped subfolder). Defaults to `~/Downloads/microsoft-teams-mcp`. When set, a per-call `dest` must lie inside it; when unset, `dest` must be under `~/Downloads`, `~/Documents` or `~/Desktop`. |
194
+ | `TEAMS_OUTPUT_DIR` | Folder `teams_export_messages` (and `teams_get_transcript` with `save`) writes into (each export gets its own timestamped subfolder). Defaults to `~/Downloads/microsoft-teams-mcp`. When set, a per-call `dest` must lie inside it; when unset, `dest` must be under `~/Downloads`, `~/Documents` or `~/Desktop`. |
174
195
  | `TEAMS_WS_PORT` | fetchproxy concentrator port. Defaults to `37149`, the fleet-wide shared port. |
175
196
  | `FETCHPROXY_WS_HOST` | Bind interface for the bridge (default `127.0.0.1`; a literal IP only, anything else is ignored). Keep on loopback — it exists for ONE topology: a hosted child in its own network namespace. |
176
197
  | `FETCHPROXY_IDENTITY_DIR` | Where to store the long-term fetchproxy identity keypair (default `~/.fetchproxy/identity/`; an absolute path only, anything else is ignored). Exists for a host that runs a separate child per caller, so they can share one identity. |
@@ -370,7 +391,11 @@ Everything is optional — by default the token is captured from your browser.
370
391
  changed with `teams_list_messages`, handing on the row's
371
392
  `after_message_id` — **not** `next_cursor`, which is a time token that only
372
393
  `teams_list_changed_conversations` accepts (`teams_list_messages` rejects it, and
373
- `teams_list_changed_conversations` rejects a message id):
394
+ `teams_list_changed_conversations` rejects a message id). `view: "brief"`
395
+ answers plain text instead, one line per changed conversation —
396
+ `title — <newest ISO time | no date> — <n> new, <m> from others` (or
397
+ `could not read`), at most 120 characters — the shape mcp-host's context
398
+ groups read (this is the work group's canonical *what's new*):
374
399
 
375
400
  ```jsonc
376
401
  // first call: the last 24 hours
@@ -452,6 +477,25 @@ Everything is optional — by default the token is captured from your browser.
452
477
  (default 50, max 200). Read from the chat service, so the Activity view
453
478
  does not need to be open; it never marks anything read (`teams_mark_read`
454
479
  marks chats and channels read, not the Activity feed).
480
+ - `teams_get_transcript` — the transcript of a recorded Teams meeting, read from
481
+ its meeting chat (`conversation`: the chat's id or a substring of its title).
482
+ It reads **Teams' own copy** of the transcript — the one the meeting's Recap
483
+ tab shows — from Teams' object store with the chat-service token, so it works
484
+ **even when the organizer turned transcript download off** (only the
485
+ OneDrive copy is locked then). No SharePoint token or extra pairing is
486
+ involved. Returns the newest transcribed recording unless `recording_id`
487
+ names another, with `recording` (`recording_id`, time, `duration`,
488
+ `play_url`), `speakers`, `cue_count`, `other_recordings` (newest first, up to
489
+ 20) and `transcript`: `format: "text"` (default — one line per speaker turn,
490
+ `[hh:mm:ss] Name: words`) or `"vtt"` (the WebVTT as Teams serves it). A
491
+ transcript over 200,000 characters is cut short (`truncated: true`).
492
+ `save: true` writes `<meeting>-<time>.vtt` and `.txt` instead, like
493
+ `teams_export_messages` (a fresh folder under `dest` → `TEAMS_OUTPUT_DIR` →
494
+ `~/Downloads/microsoft-teams-mcp` locally; a zip behind a signed link on a
495
+ hosted install), and returns where. The newest 2,000 messages of the chat are
496
+ searched for recordings. Teams' copy expires after some weeks (verified: about
497
+ four): an expired transcript is an error naming that, never a silent switch
498
+ to another recording.
455
499
  - `teams_export_messages` — bulk-export chats and channels to files, so thousands of
456
500
  messages can be archived or searched with shell tools without any of them
457
501
  entering the conversation: the result is only a manifest (where the files
@@ -702,8 +746,8 @@ instead.
702
746
  separate SharePoint token and fetches the file through SharePoint's v2.1
703
747
  shares API — see below.
704
748
  - **Scope grows quietly.** If you see a `not in declared set` error, the
705
- extension's approved scope is behind the server's declared one — revoke
706
- and re-pair `microsoft-teams-mcp` in the ContextMint Bridge popup.
749
+ extension's approved scope is behind the server's declared one — approve
750
+ `microsoft-teams-mcp` in the ContextMint Bridge popup.
707
751
 
708
752
  ## Upgrading from 0.4
709
753
 
@@ -29,6 +29,7 @@
29
29
  import { captureBearerHeader, createFetchproxyTransport } from '@chrischall/mcp-utils/fetchproxy';
30
30
  import { readPortEnv } from '@chrischall/mcp-utils';
31
31
  import { captureWindowMs } from './capture-window.js';
32
+ import { BRIDGE_TRUST_DOMAINS, CAPTURE_DECL, withBridgeScope } from './bridge-scope.js';
32
33
  import { PACKAGE_NAME, VERSION } from './version.js';
33
34
  export { stripBearer } from '@chrischall/mcp-utils/fetchproxy';
34
35
  /**
@@ -43,48 +44,43 @@ export function getWsPort() {
43
44
  /**
44
45
  * The one request we capture from: any chat-service call on the New Teams
45
46
  * host. An idle tab may make none — opening a chat is what makes the worker
46
- * issue one, hence the guidance in the capture error below.
47
+ * issue one, hence the guidance in the capture error below. Defined in
48
+ * `bridge-scope.ts`, beside the other captures it is declared with.
47
49
  */
48
- export const CAPTURE_DECL = {
49
- host: 'teams.cloud.microsoft',
50
- path: '/api/chatsvc/*',
51
- headerName: 'authorization',
52
- };
50
+ export { CAPTURE_DECL } from './bridge-scope.js';
53
51
  /**
54
- * The extension's trust boundary for the chat-service path: exactly the host we
55
- * capture from. Every API call afterwards is a plain server-side `fetch` the
56
- * bridge never sees, so nothing wider is needed here.
57
- *
58
- * Shared-file download adds a SECOND, independent trust scope —
59
- * `SHAREPOINT_TRUST_DOMAINS = ['sharepoint.com']` in `sharepoint-auth.ts` — used
60
- * only when a file is opened. It is additive: the SharePoint capture declares
61
- * `sharepoint.com` on its own transport and does NOT widen this chat-service
62
- * capture decl, which stays `teams.cloud.microsoft` alone. Granting the broader
63
- * SharePoint scope takes a one-time re-pair of `microsoft-teams-mcp` in the
64
- * ContextMint Bridge popup; until then shared files degrade to metadata + link.
52
+ * The domains every capture of this server trusts — see `bridge-scope.ts` for
53
+ * why the chat-service capture declares the SharePoint and Substrate domains
54
+ * too, and every capture header beside its own.
65
55
  */
66
- export const TRUST_DOMAINS = [CAPTURE_DECL.host];
56
+ export const TRUST_DOMAINS = [...BRIDGE_TRUST_DOMAINS];
67
57
  /**
68
58
  * Build the capture transport through this module's import binding, so a
69
59
  * test's `vi.mock('@chrischall/mcp-utils/fetchproxy')` stub is the one used.
70
60
  * Shared by the SharePoint and Substrate captures.
71
61
  */
72
62
  export const createCaptureTransport = (opts) => createFetchproxyTransport(opts);
63
+ /**
64
+ * A capture transport factory that declares the one bridge scope
65
+ * (`withBridgeScope`), whichever single header the capture reads.
66
+ * `sharePointHost` is the host a SharePoint capture is about to try.
67
+ */
68
+ export const bridgeScopedTransport = (env, sharePointHost) => (opts) => createCaptureTransport(withBridgeScope(opts, env, sharePointHost));
73
69
  /**
74
70
  * Capture a chat-service access token from the user's signed-in Teams tab.
75
71
  * Returns the bare token (no `Bearer ` prefix).
76
72
  *
77
73
  * `captureBearerHeader` declares only `capture_request_header` (beside the
78
- * `fetch` base verb mcp-utils always keeps) — the same set as before the
79
- * Activity feed left the page, so an existing pairing needs no re-approval —
80
- * sets the bridge deadline to the capture window + 15 s, starts the transport
74
+ * `fetch` base verb mcp-utils always keeps), widened to the one bridge scope
75
+ * (`bridge-scope.ts`) so this capture never re-pairs a grant the search or
76
+ * SharePoint capture made — sets the bridge deadline to the capture window + 15 s, starts the transport
81
77
  * (skipping `start()` makes the first verb throw "ensureConnected called before
82
78
  * listen()", which reads exactly like a pairing problem), guards against a
83
79
  * header too short to be a token, and closes the transport whatever happened.
84
80
  */
85
81
  export async function captureTokenViaFetchproxy(env = process.env) {
86
82
  return captureBearerHeader({
87
- captures: [CAPTURE_DECL],
83
+ captures: [{ ...CAPTURE_DECL }],
88
84
  domains: TRUST_DOMAINS,
89
85
  // Read per capture, not at import: see `capture-window.ts`.
90
86
  windowMs: captureWindowMs(env),
@@ -95,6 +91,6 @@ export async function captureTokenViaFetchproxy(env = process.env) {
95
91
  guidance: 'Open a signed-in teams.cloud.microsoft tab and click into any chat — ' +
96
92
  'that is what makes the page call the chat service; an idle tab never ' +
97
93
  'does — then retry.',
98
- createTransport: createCaptureTransport,
94
+ createTransport: bridgeScopedTransport(env),
99
95
  });
100
96
  }
@@ -0,0 +1,133 @@
1
+ /**
2
+ * The ONE scope every browser-bridge capture of this server declares.
3
+ *
4
+ * The server captures three tokens through the ContextMint Bridge — the chat
5
+ * service's (`auth-fetchproxy.ts`), Substrate search's (`substrate-auth.ts`) and
6
+ * a SharePoint host's (`sharepoint-auth.ts`) — all under one identity. The
7
+ * bridge keys its trust record on that identity and:
8
+ *
9
+ * - forces a fresh pair whenever a hello's DOMAIN SET differs from the
10
+ * approved one (`sameDomainSet` in contextmint-bridge's `background/hello.ts`);
11
+ * - offers a "grant" whenever the declared CAPTURE HEADERS exceed the approved
12
+ * ones, and approving it REPLACES the stored list with the declared one.
13
+ *
14
+ * So captures that each declared only their own host thrashed the record: a
15
+ * chat-service capture after a search re-paired, and so on — a pair prompt or a
16
+ * grant prompt on nearly every use. Every capture therefore declares the same
17
+ * domains and the same capture-header list, and captures only the one header it
18
+ * needs.
19
+ *
20
+ * The SharePoint capture host is concrete and per-tenant (the capture layer
21
+ * rejects a wildcard host), so it cannot be known up front. Each one is
22
+ * remembered in `bridge-scope.json` beside the SharePoint token cache once a
23
+ * capture of it SUCCEEDS — i.e. once the user has granted it — and every later
24
+ * hello declares it. A host is never remembered before that: a capture the
25
+ * user has not approved would otherwise grow every later hello and keep
26
+ * offering the same grant.
27
+ */
28
+ import { dirname, join } from 'node:path';
29
+ import { parseBoolEnv } from '@chrischall/mcp-utils';
30
+ import { createFileStatePersistence } from '@chrischall/mcp-utils/session';
31
+ import { sharePointTokenCachePath } from './sharepoint-token-cache.js';
32
+ import { reportCacheWriteFailure } from './token-cache.js';
33
+ /**
34
+ * The chat-service capture: any chat-service call on the New Teams host. An
35
+ * idle tab may make none — opening a chat is what makes the worker issue one.
36
+ */
37
+ export const CAPTURE_DECL = {
38
+ host: 'teams.cloud.microsoft',
39
+ path: '/api/chatsvc/*',
40
+ headerName: 'authorization',
41
+ };
42
+ /** The search capture: a search-service call the Teams tab makes. */
43
+ export const SUBSTRATE_CAPTURE_DECL = {
44
+ host: 'substrate.office.com',
45
+ path: '/searchservice/*',
46
+ headerName: 'authorization',
47
+ };
48
+ /**
49
+ * Every domain the server captures from. `sharepoint.com` is the family domain:
50
+ * the bridge accepts any `*.sharepoint.com` host under it.
51
+ */
52
+ export const BRIDGE_TRUST_DOMAINS = [CAPTURE_DECL.host, 'sharepoint.com', SUBSTRATE_CAPTURE_DECL.host];
53
+ /**
54
+ * True for a concrete SharePoint tenant host (`{label}.sharepoint.com`), such
55
+ * as `contoso-my.sharepoint.com` or `contoso.sharepoint.com`. Rejects a bare
56
+ * `sharepoint.com`, a suffix spoof (`sharepoint.com.evil.com`), and any
57
+ * non-SharePoint host. Host is lowercased before matching.
58
+ */
59
+ export function isSharePointHost(host) {
60
+ return /^[a-z0-9][a-z0-9-]*\.sharepoint\.com$/.test(host.toLowerCase());
61
+ }
62
+ /** The capture of a SharePoint token off any browser request to `host`. */
63
+ export function sharePointCaptureDecl(host) {
64
+ return { host: host.toLowerCase(), path: '/*', headerName: 'authorization' };
65
+ }
66
+ /**
67
+ * The capture headers every hello declares: the chat-service and search
68
+ * captures, then one per SharePoint host (deduplicated, sorted, and only
69
+ * concrete SharePoint hosts), so the list is the same whichever capture runs.
70
+ */
71
+ export function bridgeCaptureDecls(sharePointHosts) {
72
+ const hosts = [...new Set([...sharePointHosts].map((h) => h.toLowerCase()).filter(isSharePointHost))].sort();
73
+ return [{ ...CAPTURE_DECL }, { ...SUBSTRATE_CAPTURE_DECL }, ...hosts.map(sharePointCaptureDecl)];
74
+ }
75
+ /** Where the remembered SharePoint hosts are kept: beside the SharePoint token cache. */
76
+ export function bridgeScopePath(env = process.env) {
77
+ return join(dirname(sharePointTokenCachePath(env)), 'bridge-scope.json');
78
+ }
79
+ function validateScope(raw) {
80
+ if (raw === null || typeof raw !== 'object' || Array.isArray(raw))
81
+ return null;
82
+ const hosts = raw.sharePointHosts;
83
+ if (!Array.isArray(hosts))
84
+ return null;
85
+ return { sharePointHosts: hosts.filter((h) => typeof h === 'string' && isSharePointHost(h)) };
86
+ }
87
+ function scopeFile(env) {
88
+ return createFileStatePersistence({ filePath: bridgeScopePath(env), validate: validateScope });
89
+ }
90
+ /** The SharePoint hosts a capture has succeeded for; empty when none, or the file is unusable. */
91
+ export function knownSharePointHosts(env = process.env) {
92
+ try {
93
+ return scopeFile(env).load()?.sharePointHosts.map((h) => h.toLowerCase()) ?? [];
94
+ }
95
+ catch {
96
+ return [];
97
+ }
98
+ }
99
+ /**
100
+ * Remember `host` once a capture of it has succeeded. Off with
101
+ * `TEAMS_TOKEN_CACHE=false` (nothing of this server's is written to disk then);
102
+ * a failed write is reported, never thrown — it costs at most one more grant
103
+ * prompt.
104
+ */
105
+ export function rememberSharePointHost(host, env = process.env) {
106
+ if (!isSharePointHost(host))
107
+ return;
108
+ if (!parseBoolEnv('TEAMS_TOKEN_CACHE', { env, default: true }))
109
+ return;
110
+ const known = knownSharePointHosts(env);
111
+ const h = host.toLowerCase();
112
+ if (known.includes(h))
113
+ return;
114
+ try {
115
+ scopeFile(env).save({ sharePointHosts: [...known, h].sort() });
116
+ }
117
+ catch (err) {
118
+ reportCacheWriteFailure(err);
119
+ }
120
+ }
121
+ /**
122
+ * The hello options of a capture transport, widened to the one scope: the
123
+ * domains and capture headers mcp-utils derived from the single capture are
124
+ * replaced with {@link BRIDGE_TRUST_DOMAINS} and {@link bridgeCaptureDecls}
125
+ * (plus `extraSharePointHost`, the host a SharePoint capture is about to try).
126
+ * The verb set is unchanged — every capture is `capture_request_header`.
127
+ */
128
+ export function withBridgeScope(opts, env, extraSharePointHost) {
129
+ const hosts = knownSharePointHosts(env);
130
+ if (extraSharePointHost !== undefined)
131
+ hosts.push(extraSharePointHost);
132
+ return { ...opts, domains: [...BRIDGE_TRUST_DOMAINS], captureHeaders: bridgeCaptureDecls(hosts) };
133
+ }