@chrischall/microsoft-teams-mcp 0.3.0 → 0.5.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.
Files changed (50) hide show
  1. package/.claude-plugin/marketplace.json +4 -4
  2. package/.claude-plugin/plugin.json +2 -2
  3. package/README.md +577 -93
  4. package/dist/auth-fetchproxy.js +138 -0
  5. package/dist/bundle.js +44324 -37483
  6. package/dist/capture-window.js +41 -0
  7. package/dist/chatsvc.js +580 -0
  8. package/dist/compose.js +241 -0
  9. package/dist/deps.js +1 -0
  10. package/dist/index.js +35 -6
  11. package/dist/model.js +603 -0
  12. package/dist/sharepoint-auth.js +162 -0
  13. package/dist/sharepoint-token-cache.js +105 -0
  14. package/dist/sharepoint.js +289 -0
  15. package/dist/substrate-auth.js +104 -0
  16. package/dist/substrate-token-cache.js +64 -0
  17. package/dist/substrate.js +319 -0
  18. package/dist/token-cache.js +67 -0
  19. package/dist/tools/activity.js +155 -19
  20. package/dist/tools/attachment.js +174 -0
  21. package/dist/tools/changes.js +241 -0
  22. package/dist/tools/channels.js +62 -44
  23. package/dist/tools/chat-search.js +65 -0
  24. package/dist/tools/chat.js +121 -41
  25. package/dist/tools/confirm.js +188 -0
  26. package/dist/tools/conversation.js +394 -30
  27. package/dist/tools/cursor.js +43 -0
  28. package/dist/tools/errors.js +18 -17
  29. package/dist/tools/format.js +135 -0
  30. package/dist/tools/healthcheck.js +91 -27
  31. package/dist/tools/limit.js +43 -12
  32. package/dist/tools/listing.js +180 -0
  33. package/dist/tools/markread.js +246 -0
  34. package/dist/tools/react.js +217 -0
  35. package/dist/tools/roots.js +73 -0
  36. package/dist/tools/search.js +426 -0
  37. package/dist/tools/send.js +309 -0
  38. package/dist/tools/timezone.js +38 -0
  39. package/dist/tools/titles.js +180 -0
  40. package/dist/tools/unread.js +263 -0
  41. package/dist/tools/untrusted.js +16 -1
  42. package/dist/version.js +1 -1
  43. package/mint.yaml +75 -20
  44. package/package.json +1 -2
  45. package/server.json +87 -3
  46. package/skills/teams-fpx/SKILL.md +111 -92
  47. package/skills/teams-fpx/references/chatsvc-recipes.md +151 -0
  48. package/skills/teams-fpx/references/teams-env.sh +146 -0
  49. package/dist/client.js +0 -290
  50. package/skills/teams-fpx/references/dom-list-recipes.md +0 -81
package/dist/client.js DELETED
@@ -1,290 +0,0 @@
1
- /**
2
- * Full-bridge Teams client.
3
- *
4
- * Unlike Outlook's bootstrap-capture archetype, this one touches the bridge
5
- * on every call. Teams Web's message data lives only in a client-side sync
6
- * cache fed by a WebSocket/registrar channel — there is no REST or GraphQL
7
- * endpoint that returns it, so the only way to read it is to read the DOM the
8
- * page has already rendered. That rules out a captured-token-then-plain-fetch
9
- * design: every read here goes through `read_dom_list` against the user's
10
- * live, signed-in `teams.cloud.microsoft` tab.
11
- *
12
- * Consequence: this MCP can only read whichever chat or channel is
13
- * CURRENTLY DISPLAYED in that tab. `@fetchproxy/server` has no capability to
14
- * navigate a tab to a different conversation — every declared capability is
15
- * a fetch or a read, never a page interaction — so there is no way to ask
16
- * for "chat X's messages" or "channel Y's posts" on demand.
17
- * `listChats()`/`listTeamsAndChannels()` read their sidebars (always
18
- * visible once that nav section is open); `getOpenChatMessages()`/
19
- * `getOpenChannelPosts()` read whatever conversation the user has open.
20
- * Verified live 2026-09-21 against a real Teams tenant.
21
- */
22
- import { createFetchproxyTransport, } from '@chrischall/mcp-utils/fetchproxy';
23
- import { readPortEnv } from '@chrischall/mcp-utils';
24
- import { PACKAGE_NAME, VERSION } from './version.js';
25
- /**
26
- * The New Teams host this MCP reads from. `teams.microsoft.com` (the old
27
- * host) is deliberately not supported — only `teams.cloud.microsoft` tabs
28
- * are read.
29
- */
30
- export const DOMAINS = ['teams.cloud.microsoft'];
31
- /**
32
- * fetchproxy concentrator port — one for the whole fleet. `TEAMS_WS_PORT`
33
- * overrides it for local development and for a hosted bridged registration
34
- * (where mcp-host names this variable in `bridgePortEnv`).
35
- */
36
- const DEFAULT_WS_PORT = 37_149;
37
- export function getWsPort() {
38
- return readPortEnv('TEAMS_WS_PORT', DEFAULT_WS_PORT);
39
- }
40
- /**
41
- * The currently-open chat's message thread. `.fui-ChatMessage` (others'
42
- * messages) and `.fui-ChatMyMessage` (the signed-in user's own) are Teams
43
- * v2's two message-row classes; both carry the same `message-author-name` /
44
- * `time` / `chat-pane-message` structure. `sender` reads back even for a
45
- * grouped/consecutive message Teams visually hides the name on — it stays
46
- * in the DOM, just visually collapsed. A quoted-reply message's `text`
47
- * includes the quoted preview concatenated in (a known limitation of bulk
48
- * `.textContent` extraction, not fixable without a second, narrower field).
49
- */
50
- export const CHAT_MESSAGES_SELECTOR = {
51
- name: 'chatMessages',
52
- itemSelector: '.fui-ChatMessage, .fui-ChatMyMessage',
53
- fields: [
54
- { name: 'sender', selector: '[data-tid="message-author-name"]' },
55
- { name: 'time', selector: 'time', attribute: 'datetime' },
56
- { name: 'messageId', selector: 'time', attribute: 'id' },
57
- { name: 'text', selector: '[data-tid="chat-pane-message"]' },
58
- ],
59
- maxItems: 200,
60
- };
61
- /**
62
- * The chat-list sidebar (always rendered, regardless of which chat is
63
- * open). `conversationKey` is Teams' own compound tree-item value — it
64
- * embeds the real thread id (e.g. `19:<id>@thread.v2`) but is NOT usable to
65
- * open that chat from here; there is no navigate capability. It is exposed
66
- * so a caller can at least correlate a list entry with the currently-open
67
- * chat's messages.
68
- */
69
- export const CHAT_LIST_SELECTOR = {
70
- name: 'chatList',
71
- itemSelector: '[data-testid="list-item"]',
72
- fields: [
73
- { name: 'title', selector: '[id^="title-chat-list-item_"]' },
74
- { name: 'preview', selector: '[data-testid="comfy-message"]' },
75
- { name: 'time', selector: '[id^="time-chat-list-item_"]' },
76
- { name: 'conversationKey', attribute: 'data-fui-tree-item-value' },
77
- { name: 'itemType', attribute: 'data-item-type' },
78
- ],
79
- maxItems: 200,
80
- };
81
- /**
82
- * The Teams-and-Channels sidebar (the left rail under the "Teams" nav icon,
83
- * a DIFFERENT view from Chat — always rendered once that view is open,
84
- * regardless of which channel is open). Team and channel rows share one
85
- * item selector; `title-*`/`time-*` use a compound attribute selector
86
- * (`[id^="title-"][id*="-list-item-"]`) rather than a comma-joined pair of
87
- * prefixes, because a channel and a team item use different id prefixes
88
- * (`title-channel-list-item-*` / `title-team-list-item-*`) and this reads
89
- * either without needing two alternatives. `teamName` is the parent team's
90
- * display name shown under a channel row (absent on a team row itself).
91
- */
92
- export const TEAMS_AND_CHANNELS_SELECTOR = {
93
- name: 'teamsAndChannels',
94
- itemSelector: '[data-item-type="team"], [data-item-type="channel"]',
95
- fields: [
96
- { name: 'title', selector: '[id^="title-"][id*="-list-item-"]' },
97
- { name: 'teamName', selector: '[id^="preview-channel-list-item-"]' },
98
- { name: 'time', selector: '[id^="time-"][id*="-list-item-"]' },
99
- { name: 'conversationKey', attribute: 'data-fui-tree-item-value' },
100
- { name: 'itemType', attribute: 'data-item-type' },
101
- ],
102
- maxItems: 300,
103
- };
104
- /**
105
- * Top-level posts in whichever CHANNEL is currently open (same "reads only
106
- * what's displayed" constraint as chat messages — see module doc). Channel
107
- * posts use a different renderer than chat messages (`channel-pane-message`,
108
- * not `.fui-ChatMessage`), and their `<time>` element carries no ISO
109
- * `datetime` attribute — only a human-readable `aria-label` — so `time` here
110
- * is prose ("Tuesday, August 4, 2026 7:50 AM"), not ISO 8601 like
111
- * `ChatMessageRow.time`. `subject` is present only on a post that has a
112
- * title; a reply-shaped post has none. Threaded REPLIES under a post are not
113
- * captured — only the top-level posts a channel's "Posts" tab lists.
114
- */
115
- export const CHANNEL_POSTS_SELECTOR = {
116
- name: 'channelPosts',
117
- itemSelector: '[data-tid="channel-pane-message"]',
118
- fields: [
119
- { name: 'sender', selector: '[id^="author-"]' },
120
- { name: 'subject', selector: '[id^="subject-line-"]' },
121
- { name: 'time', selector: 'time[data-tid="timestamp"]', attribute: 'aria-label' },
122
- { name: 'messageId', selector: 'time[data-tid="timestamp"]', attribute: 'id' },
123
- { name: 'text', selector: '[id^="content-"]' },
124
- ],
125
- maxItems: 200,
126
- };
127
- /**
128
- * Top-level rows in the Activity feed (the bell icon in the left nav) —
129
- * mentions, replies, reactions, and the like across every chat and channel.
130
- * Always rendered once that nav section is open, regardless of which item
131
- * is selected — same "sidebar, not detail pane" shape as `CHAT_LIST_SELECTOR`
132
- * and `TEAMS_AND_CHANNELS_SELECTOR`. `location` is the team/channel or chat
133
- * the activity happened in, prose-joined by Teams itself (e.g. "NS_MS
134
- * Product CE > MS DevOps"). `time` is prose (e.g. "1:19 PM"), not ISO 8601 —
135
- * Teams renders it that way here, unlike `chatMessages.time`.
136
- */
137
- export const ACTIVITY_FEED_SELECTOR = {
138
- name: 'activityFeed',
139
- itemSelector: '[data-tid="activity-feed-list-item"]',
140
- fields: [
141
- { name: 'title', selector: '[id^="activity-feed-item-title-"]' },
142
- { name: 'preview', selector: '[id^="activity-feed-item-message-preview-"]' },
143
- { name: 'time', selector: '[id^="activity-feed-item-timestamp-"]' },
144
- { name: 'location', selector: '[id^="activity-feed-item-location-"]' },
145
- ],
146
- maxItems: 200,
147
- };
148
- /**
149
- * WHICH conversation is open — the sidebar row Teams marks as selected. Read
150
- * alongside `chatMessages`/`channelPosts` so the "open" tools can say which
151
- * chat or channel their rows came from; without it the model gets bare rows
152
- * and can misattribute another conversation's messages to the one the user
153
- * asked about. The chat-list and channel-list rows are Fluent UI tree items
154
- * (`data-fui-tree-item-value`, the same attribute `CHAT_LIST_SELECTOR` /
155
- * `TEAMS_AND_CHANNELS_SELECTOR` read `conversationKey` from), and a Fluent
156
- * tree item carries `aria-selected="true"` (or `aria-current`) when it is the
157
- * open one. `title` matches both the chat (`title-chat-list-item_*`) and
158
- * channel (`title-channel-list-item-*`) title ids. `conversationKey` embeds
159
- * the real thread id. Not yet re-verified against a live tenant — the tools
160
- * treat an empty read as "could not identify" rather than failing.
161
- */
162
- export const OPEN_CONVERSATION_SELECTOR = {
163
- name: 'openConversation',
164
- itemSelector: '[data-fui-tree-item-value][aria-selected="true"], ' +
165
- '[data-fui-tree-item-value][aria-current="true"], ' +
166
- '[data-fui-tree-item-value][aria-current="page"]',
167
- fields: [
168
- { name: 'title', selector: '[id^="title-"][id*="list-item"]' },
169
- { name: 'conversationKey', attribute: 'data-fui-tree-item-value' },
170
- { name: 'itemType', attribute: 'data-item-type' },
171
- ],
172
- maxItems: 5,
173
- };
174
- /** Every selector the client declares to the bridge (the pair-popup scope). */
175
- export const DOM_LIST_SELECTORS = [
176
- CHAT_MESSAGES_SELECTOR,
177
- CHAT_LIST_SELECTOR,
178
- TEAMS_AND_CHANNELS_SELECTOR,
179
- CHANNEL_POSTS_SELECTOR,
180
- ACTIVITY_FEED_SELECTOR,
181
- OPEN_CONVERSATION_SELECTOR,
182
- ];
183
- export class TeamsClient {
184
- #transport;
185
- /**
186
- * The in-flight (or settled) start, memoized so parallel first calls share
187
- * ONE `transport.start()` — two concurrent starts would each create and
188
- * persist a fresh fetchproxy identity keypair, leaving the paired key and
189
- * the on-disk key out of step. Cleared on failure so the next call retries.
190
- */
191
- #starting;
192
- constructor(opts = {}) {
193
- this.#transport =
194
- opts.transport ??
195
- createFetchproxyTransport({
196
- serverName: PACKAGE_NAME,
197
- version: VERSION,
198
- domains: [...DOMAINS],
199
- capabilities: ['read_dom_list'],
200
- domListSelectors: [...DOM_LIST_SELECTORS],
201
- port: getWsPort(),
202
- // stderr only — stdout is the JSON-RPC channel. Without this the
203
- // first-ever pairing (or a scope widening) leaves a tool call
204
- // hanging with no way for the user to know a ContextMint Bridge approval
205
- // is what it's waiting on.
206
- onPairCode: (code) => {
207
- console.error(`[microsoft-teams-mcp] fetchproxy pair code: ${code} — approve in the ContextMint Bridge extension popup`);
208
- },
209
- });
210
- }
211
- /**
212
- * `start()` only loads the identity keypair — it does not bind the port or
213
- * dial the extension, which stays lazy until the first verb. Called once,
214
- * lazily, so a server that never gets a tool call never touches the
215
- * bridge at all.
216
- */
217
- #ensureStarted() {
218
- this.#starting ??= this.#transport.start().catch((e) => {
219
- this.#starting = undefined;
220
- throw e;
221
- });
222
- return this.#starting;
223
- }
224
- /** Reads a declared selector off the single supported domain's live tab. */
225
- async #readDomList(name) {
226
- await this.#ensureStarted();
227
- try {
228
- return await this.#transport.server.readDomList({ name, domain: DOMAINS[0] });
229
- }
230
- catch (e) {
231
- const err = e;
232
- if (/no tab matching/i.test(err.message)) {
233
- throw new Error(`could not reach a signed-in Teams tab on ${DOMAINS[0]} (${err.message}). ` +
234
- `Open ${DOMAINS[0]} in a signed-in browser tab and retry.`);
235
- }
236
- throw e;
237
- }
238
- }
239
- /** The chat-list sidebar, regardless of which chat is currently open. */
240
- async listChats() {
241
- return (await this.#readDomList('chatList'));
242
- }
243
- /**
244
- * Messages from whichever chat is CURRENTLY DISPLAYED in the signed-in
245
- * tab. There is no way to select a different chat from here — see the
246
- * module doc.
247
- */
248
- async getOpenChatMessages() {
249
- return (await this.#readDomList('chatMessages'));
250
- }
251
- /** The Teams-and-Channels sidebar, regardless of which channel is open. */
252
- async listTeamsAndChannels() {
253
- return (await this.#readDomList('teamsAndChannels'));
254
- }
255
- /**
256
- * Top-level posts from whichever channel is CURRENTLY DISPLAYED in the
257
- * signed-in tab (the Teams-and-Channels view must be open, not Chat).
258
- * There is no way to select a different channel from here — see the
259
- * module doc.
260
- */
261
- async getOpenChannelPosts() {
262
- return (await this.#readDomList('channelPosts'));
263
- }
264
- /**
265
- * Every sidebar row Teams marks as selected (up to 5). Usually one, but the
266
- * selector spans BOTH the Chat and the Teams-and-Channels sidebars, so a
267
- * channel row can stay selected while a chat is open (and vice versa) —
268
- * callers must pick by `itemType` (see `tools/conversation.ts`), never
269
- * just take the first row.
270
- */
271
- async getSelectedConversations() {
272
- return (await this.#readDomList('openConversation'));
273
- }
274
- /** The Activity feed (the bell icon in the left nav), regardless of which item is selected. */
275
- async getActivity() {
276
- return (await this.#readDomList('activityFeed'));
277
- }
278
- async close() {
279
- await this.#transport.close();
280
- this.#starting = undefined;
281
- }
282
- /** Non-secret bridge status for the healthcheck tool. */
283
- status() {
284
- return this.#transport.status();
285
- }
286
- /** The underlying bridge transport, for `registerBridgeHealthcheckTool`. */
287
- get transport() {
288
- return this.#transport;
289
- }
290
- }
@@ -1,81 +0,0 @@
1
- # fpx dom-list recipes for Teams
2
-
3
- Every command needs `-p teams --storage-domain teams.cloud.microsoft`.
4
-
5
- ## Chat list (sidebar, Chat nav section)
6
-
7
- ```sh
8
- fpx dom-list chatList -p teams --storage-domain teams.cloud.microsoft \
9
- | jq -r '.[] | "\(.time)\t\(.title)\t\(.preview)"'
10
- ```
11
-
12
- Fields: `title`, `preview` (last-message text), `time` (relative, e.g. `9:02
13
- AM` or `9/18` — Teams renders it that way, not as an ISO timestamp),
14
- `conversationKey` (Teams' internal compound thread id — not usable to open
15
- the chat; there is no navigate capability), `itemType` (`chat` for every row
16
- in the Chat rail).
17
-
18
- ## Currently open chat's messages
19
-
20
- ```sh
21
- fpx dom-list chatMessages -p teams --storage-domain teams.cloud.microsoft \
22
- | jq -r '.[] | "\(.time)\t\(.sender // "(same as above)")\t\(.text)"'
23
- ```
24
-
25
- Fields: `sender`, `time` (ISO 8601, from the `<time datetime>` attribute),
26
- `messageId` (`timestamp-<epoch>`, stable per message), `text`.
27
-
28
- Reads whatever chat is CURRENTLY OPEN in the tab — open the one you want in
29
- the browser first, then run this.
30
-
31
- ## Teams and channels (sidebar, Teams nav section — a DIFFERENT view from Chat)
32
-
33
- ```sh
34
- fpx dom-list teamsAndChannels -p teams --storage-domain teams.cloud.microsoft \
35
- | jq -r '.[] | select(.itemType == "channel") | "\(.teamName)\t\(.title)"'
36
- ```
37
-
38
- Fields: `title` (team or channel name), `teamName` (the parent team's
39
- display name — present on a channel row, absent on a team row), `time`
40
- (relative, like `chatList.time`), `conversationKey` (internal compound id,
41
- not usable to open the item), `itemType` (`team` or `channel`).
42
-
43
- Needs the **Teams-and-Channels** nav section open in the browser (click
44
- "Teams" in the left rail), not Chat — if this returns `[]`, that's the
45
- usual reason.
46
-
47
- ## Currently open channel's posts
48
-
49
- ```sh
50
- fpx dom-list channelPosts -p teams --storage-domain teams.cloud.microsoft \
51
- | jq -r '.[] | "\(.time)\t\(.sender)\t\(.subject // "")\t\(.text)"'
52
- ```
53
-
54
- Fields: `sender`, `subject` (present only on a post with a title), `time`
55
- (prose, e.g. `Tuesday, August 4, 2026 7:50 AM` — NOT ISO 8601, unlike
56
- `chatMessages.time`), `messageId` (`timestamp-<epoch>`), `text`. Threaded
57
- replies under a post are not captured, only the top-level posts.
58
-
59
- Reads whatever channel is CURRENTLY OPEN — open it in the browser first.
60
-
61
- ## Activity feed (sidebar, Activity nav section — the bell icon)
62
-
63
- ```sh
64
- fpx dom-list activityFeed -p teams --storage-domain teams.cloud.microsoft \
65
- | jq -r '.[] | "\(.time)\t\(.title)\t\(.location)"'
66
- ```
67
-
68
- Fields: `title` (e.g. "Sanderson, Xi mentioned MS DevOps"), `preview`
69
- (message text), `time` (prose, e.g. `1:19 PM` — NOT ISO 8601), `location`
70
- (the team/channel or chat the activity happened in, e.g. "NS_MS Product CE
71
- > MS DevOps").
72
-
73
- Unlike the other three "currently open" reads, this is a sidebar list — it's
74
- always populated once the Activity view is open, regardless of which item
75
- is selected (same shape as `chatList`/`teamsAndChannels`).
76
-
77
- ## Multiple tabs
78
-
79
- If more than one `teams.cloud.microsoft` tab is open, the bridge picks
80
- whichever answers first — results can come from a tab you didn't mean.
81
- Close extras before relying on output.