@chrischall/microsoft-teams-mcp 0.3.0 → 0.4.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.
- package/.claude-plugin/marketplace.json +4 -4
- package/.claude-plugin/plugin.json +2 -2
- package/README.md +279 -93
- package/dist/auth-fetchproxy.js +138 -0
- package/dist/bundle.js +42380 -37144
- package/dist/capture-window.js +41 -0
- package/dist/chatsvc.js +552 -0
- package/dist/compose.js +241 -0
- package/dist/deps.js +1 -0
- package/dist/index.js +26 -6
- package/dist/model.js +499 -0
- package/dist/sharepoint-auth.js +162 -0
- package/dist/sharepoint-token-cache.js +105 -0
- package/dist/sharepoint.js +289 -0
- package/dist/token-cache.js +67 -0
- package/dist/tools/activity.js +155 -19
- package/dist/tools/attachment.js +174 -0
- package/dist/tools/channels.js +60 -44
- package/dist/tools/chat.js +47 -42
- package/dist/tools/confirm.js +145 -0
- package/dist/tools/conversation.js +172 -32
- package/dist/tools/errors.js +18 -17
- package/dist/tools/healthcheck.js +86 -27
- package/dist/tools/limit.js +43 -12
- package/dist/tools/listing.js +116 -0
- package/dist/tools/react.js +217 -0
- package/dist/tools/send.js +309 -0
- package/dist/tools/titles.js +180 -0
- package/dist/tools/unread.js +162 -0
- package/dist/tools/untrusted.js +16 -1
- package/dist/version.js +1 -1
- package/mint.yaml +63 -20
- package/package.json +1 -2
- package/server.json +80 -3
- package/skills/teams-fpx/SKILL.md +108 -92
- package/skills/teams-fpx/references/chatsvc-recipes.md +151 -0
- package/skills/teams-fpx/references/teams-env.sh +146 -0
- package/dist/client.js +0 -290
- package/skills/teams-fpx/references/dom-list-recipes.md +0 -81
|
@@ -6,16 +6,16 @@
|
|
|
6
6
|
"email": "chris.c.hall@gmail.com"
|
|
7
7
|
},
|
|
8
8
|
"metadata": {
|
|
9
|
-
"description": "MCP server for Microsoft Teams — read
|
|
10
|
-
"version": "0.
|
|
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.4.0"
|
|
11
11
|
},
|
|
12
12
|
"plugins": [
|
|
13
13
|
{
|
|
14
14
|
"name": "microsoft-teams-mcp",
|
|
15
15
|
"displayName": "Microsoft Teams",
|
|
16
16
|
"source": "./",
|
|
17
|
-
"description": "MCP server for Microsoft Teams — read
|
|
18
|
-
"version": "0.
|
|
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.4.0",
|
|
19
19
|
"author": {
|
|
20
20
|
"name": "Chris Hall"
|
|
21
21
|
},
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "microsoft-teams-mcp",
|
|
3
3
|
"displayName": "Microsoft Teams",
|
|
4
|
-
"version": "0.
|
|
5
|
-
"description": "Microsoft Teams for Claude — read
|
|
4
|
+
"version": "0.4.0",
|
|
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",
|
|
8
8
|
"email": "chris.c.hall@gmail.com"
|
package/README.md
CHANGED
|
@@ -1,34 +1,67 @@
|
|
|
1
1
|
# microsoft-teams-mcp
|
|
2
2
|
|
|
3
|
-
MCP server for **Microsoft Teams** — list
|
|
4
|
-
read
|
|
5
|
-
|
|
3
|
+
MCP server for **Microsoft Teams** — list every chat and channel you are in,
|
|
4
|
+
read any of them by id or name, pull everything you have not read yet,
|
|
5
|
+
read your Activity feed, fetch inline images, and — each one confirmed by you first — post messages
|
|
6
|
+
and reactions, using your signed-in browser session.
|
|
6
7
|
|
|
7
8
|
> This project was developed and is maintained by AI (Claude Code). Use at your
|
|
8
9
|
> own discretion.
|
|
9
10
|
|
|
10
|
-
## How it works
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
11
|
+
## How it works
|
|
12
|
+
|
|
13
|
+
Chats and channels are read through Teams' own **chat-service REST API**
|
|
14
|
+
(`https://teams.cloud.microsoft/api/chatsvc/<region>/v1`). The server needs a
|
|
15
|
+
bearer token for it, and the only place one exists is your signed-in
|
|
16
|
+
`teams.cloud.microsoft` tab: through the
|
|
17
|
+
[fetchproxy](https://github.com/chrischall/fetchproxy) browser bridge it
|
|
18
|
+
captures the `Authorization` header off a request the Teams web app makes to
|
|
19
|
+
its chat service — **once**. From then on every call is a plain server-side
|
|
20
|
+
request; the token is cached in `~/.microsoft-teams-mcp/token.json` for its
|
|
21
|
+
~23h lifetime (so a restart needs no browser), and a 401 re-captures once and
|
|
22
|
+
replays. `teams.microsoft.com` (the old host) is not supported.
|
|
23
|
+
|
|
24
|
+
So **chats and channels no longer need to be open in the browser** — any of
|
|
25
|
+
them can be read by id or name, and listing covers every chat, not just the
|
|
26
|
+
ones the sidebar shows. To capture a token, an idle tab is not enough: click
|
|
27
|
+
into any chat so Teams calls its chat service.
|
|
28
|
+
|
|
29
|
+
**The Activity feed comes from the same API.** It is a chat-service
|
|
30
|
+
conversation of its own (`48:notifications`), so `teams_get_activity` reads
|
|
31
|
+
it like any chat — no Activity view (or any view) needs to be open, and
|
|
32
|
+
nothing reads the page. The bridge is used for one thing only: capturing the
|
|
33
|
+
token.
|
|
34
|
+
|
|
35
|
+
Nothing here marks anything read. Reading a chat through this server leaves
|
|
36
|
+
your Teams unread badges exactly as they were. The two writes —
|
|
37
|
+
`teams_send_message` and `teams_react` — go through the same chat-service
|
|
38
|
+
API and post nothing until you confirm (see [Writes](#writes)).
|
|
39
|
+
|
|
40
|
+
## SharePoint file download
|
|
41
|
+
|
|
42
|
+
A **shared file** in a chat or channel is not in Teams' own object store
|
|
43
|
+
(where inline images live) — it is in **SharePoint**, which does not accept the
|
|
44
|
+
chat-service token. So `teams_get_attachment` captures a **separate SharePoint
|
|
45
|
+
token** and fetches the file through SharePoint's `v2.1` shares API, then
|
|
46
|
+
downloads the pre-signed link it returns (with no token attached).
|
|
47
|
+
|
|
48
|
+
Two things follow from that, both one-time and additive — they do **not** change
|
|
49
|
+
how the chat-service token is captured:
|
|
50
|
+
|
|
51
|
+
- **A one-time re-pair.** The SharePoint path declares a second trust scope,
|
|
52
|
+
`sharepoint.com`, so the ContextMint Bridge grant has to cover it. If you
|
|
53
|
+
paired `microsoft-teams-mcp` before this feature, revoke and re-pair it in the
|
|
54
|
+
bridge popup once to add the SharePoint scope (a `not in declared set` error
|
|
55
|
+
on a file download is this, nothing more). The chat-service capture is
|
|
56
|
+
untouched — it still trusts only `teams.cloud.microsoft`.
|
|
57
|
+
- **Open the file once per SharePoint host.** The SharePoint token is captured
|
|
58
|
+
from the browser's own request to the file's SharePoint host, is short-lived
|
|
59
|
+
(~53 minutes), and is scoped to one host family. So the first file from a
|
|
60
|
+
given host in a session may need you to open it once in a signed-in Teams tab
|
|
61
|
+
(that browser request is what the token is read from); after that the token is
|
|
62
|
+
cached and refreshed until it expires. A file your account cannot open, or on
|
|
63
|
+
a SharePoint host your token does not cover, comes back as metadata and its
|
|
64
|
+
open link rather than failing.
|
|
32
65
|
|
|
33
66
|
## Install
|
|
34
67
|
|
|
@@ -78,89 +111,247 @@ opencode reads MCP servers from `opencode.json` (project) or
|
|
|
78
111
|
|
|
79
112
|
### Configuration
|
|
80
113
|
|
|
81
|
-
Everything is optional —
|
|
114
|
+
Everything is optional — by default the token is captured from your browser.
|
|
82
115
|
|
|
83
116
|
| variable | purpose |
|
|
84
117
|
| --- | --- |
|
|
118
|
+
| `TEAMS_ACCESS_TOKEN` | A chat-service bearer token (the JWT itself) to use instead of capturing one. Never re-captured from the browser: when Teams rejects it, replace it. |
|
|
119
|
+
| `TEAMS_DISABLE_FETCHPROXY` | `true` to never capture from the browser (then `TEAMS_ACCESS_TOKEN` is required). |
|
|
120
|
+
| `TEAMS_CHATSVC_REGION` | Chat-service region in the API path. Defaults to `amer`. |
|
|
121
|
+
| `TEAMS_CHATSVC_BASE` | Full override for the API base (default `https://teams.cloud.microsoft/api/chatsvc/<region>/v1`). |
|
|
122
|
+
| `TEAMS_CAPTURE_TIMEOUT` | Seconds to wait for the Teams tab to issue a chat-service request. Defaults to `30`. The bridge deadline is derived from it (window + 15s). |
|
|
123
|
+
| `TEAMS_TOKEN_CACHE` | `false` to keep the captured token in memory only. Defaults to on. |
|
|
124
|
+
| `TEAMS_TOKEN_FILE` | Where the captured token is cached. Defaults to `~/.microsoft-teams-mcp/token.json`. |
|
|
85
125
|
| `TEAMS_WS_PORT` | fetchproxy concentrator port. Defaults to `37149`, the fleet-wide shared port. |
|
|
86
126
|
| `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. |
|
|
87
127
|
| `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. |
|
|
88
128
|
|
|
89
129
|
## Tools
|
|
90
130
|
|
|
91
|
-
- `teams_list_chats` —
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
`
|
|
121
|
-
|
|
122
|
-
|
|
131
|
+
- `teams_list_chats` — every chat you are in (1:1, group and meeting chats,
|
|
132
|
+
not just the visible sidebar, plus your `48:notes` self-chat as kind
|
|
133
|
+
`self` when Teams lists it), favorites and pinned chats first, then most
|
|
134
|
+
recent activity first: id, kind,
|
|
135
|
+
title, unread hint, ISO-8601 last-activity time, last-message preview and
|
|
136
|
+
sender. `unread_only` (exact — see below), `since_days` (with
|
|
137
|
+
`unread_only`; default 14), `query` (title, or a participant's name) and
|
|
138
|
+
`limit` (default 50, max 500). A group chat with no topic is titled after
|
|
139
|
+
who is in it — `Group chat: <up to three recent senders other than you,
|
|
140
|
+
most recent first>` plus `+N` for more, with every recent sender in
|
|
141
|
+
`participants` — rather than after whoever posted last, so chats that
|
|
142
|
+
share a last sender stay distinguishable. The chat service has no member
|
|
143
|
+
list, so this reads up to 30 recent messages (one small page) of each such
|
|
144
|
+
chat returned (four at a time, cached until a new message arrives); if that
|
|
145
|
+
read fails, the chat keeps its last-sender title. A 1:1 is titled by the
|
|
146
|
+
other person (its id names them) and carries them as its one
|
|
147
|
+
`participants` entry — read from their recent messages when you sent the
|
|
148
|
+
last one, `(1:1 chat)` if they wrote nothing recently. `query` matches such
|
|
149
|
+
chats by their participants, never by the made-up `Group chat:` or
|
|
150
|
+
`(1:1 chat)` titles, so `group` or `chat` does not hit every untitled chat.
|
|
151
|
+
Conversations the chat service marks favorite or pinned carry
|
|
152
|
+
`favorite: true` / `pinned: true` and lead the plain listing (favorites,
|
|
153
|
+
then pinned); `unread_only` keeps most-recent-first order but carries the
|
|
154
|
+
flags. Note the new Teams **Favorites section for chats** is kept by a
|
|
155
|
+
different Teams service this MCP does not read, so a chat you put there is
|
|
156
|
+
not flagged (verified live 2026-10-10) — the flags mostly reflect favorited
|
|
157
|
+
channels and pinned conversations.
|
|
158
|
+
- `teams_list_teams_and_channels` — every channel you are in, by team then
|
|
159
|
+
title, with the same fields — favorite and pinned channels first, flagged
|
|
160
|
+
as in `teams_list_chats`. Channels you have hidden in Teams are listed
|
|
161
|
+
after the rest with `hidden: true`, and left out of `unread_only` unless
|
|
162
|
+
`include_hidden` is set. `unread_only`, `include_hidden`, `since_days`
|
|
163
|
+
(with `unread_only`; default 14), `query` (channel or team name) and
|
|
164
|
+
`limit` (default 50, max 500).
|
|
165
|
+
- `teams_read_conversation` — read any chat or channel by id or name,
|
|
166
|
+
oldest first: sender, ISO-8601 time, text, subject, edited/deleted flags
|
|
167
|
+
and attachments. A channel comes back as threads (root post + replies).
|
|
168
|
+
`unread_only`, `since` (ISO 8601) and `limit` (default 50, max 500, newest
|
|
169
|
+
kept). An ambiguous name lists the candidates and asks for the id; an
|
|
170
|
+
untitled group chat can be named by one of its participants, and a 1:1 by
|
|
171
|
+
the other person (this, and the same naming in `teams_send_message` /
|
|
172
|
+
`teams_react`, titles every untitled chat first).
|
|
173
|
+
`48:notes` — or the name `notes` / `self` — is your notes self-chat.
|
|
174
|
+
- `teams_get_unread` — every unread message across your chats and channels,
|
|
175
|
+
grouped by conversation, most recent first. Filter by `kinds` (`chat`,
|
|
176
|
+
`channel`, `meeting`, `oneOnOne`) or `query` (title, channel or team
|
|
177
|
+
name, or an untitled chat's participant name); `per_conversation_limit`
|
|
178
|
+
(default 50) and `max_conversations` (default 20 returned with their
|
|
179
|
+
messages — the rest are named, with their `unread_count`, in
|
|
180
|
+
`more_unread_conversations`). Hidden channels are left out unless
|
|
181
|
+
`include_hidden`. Only conversations with unread messages from the last
|
|
182
|
+
`since_days` (default 14, max 3650) are returned; older ones are counted
|
|
183
|
+
in `older_unread_skipped`. An untitled group chat or 1:1 is titled after
|
|
184
|
+
its participants, as in `teams_list_chats` — in `conversations`, in
|
|
185
|
+
`more_unread_conversations` and in `errors`.
|
|
186
|
+
- `teams_get_attachment` — one attachment of a message: an inline image is
|
|
187
|
+
returned as the image itself; a shared file is downloaded from SharePoint and
|
|
188
|
+
returned as its contents — an image as the image, anything else as an embedded
|
|
189
|
+
resource carrying the bytes. Shared-file download uses a separate, short-lived
|
|
190
|
+
SharePoint token captured per SharePoint host, so the first file from a given
|
|
191
|
+
host may need [opening once in Teams](#sharepoint-file-download) to mint it; a
|
|
192
|
+
file your account cannot open, or one that could not be fetched, comes back as
|
|
193
|
+
metadata and its open link instead of failing.
|
|
194
|
+
- `teams_get_activity` — the Activity feed (the bell icon), newest first:
|
|
195
|
+
mentions (including @team / @everyone), reactions, replies, meeting
|
|
196
|
+
notices and missed calls across every chat and channel. Each row has its
|
|
197
|
+
time (ISO 8601), `kind` (`mention`, `reaction`, `reply`, `meeting`, `call`
|
|
198
|
+
or `other`) with Teams' raw type/subtype, whether you have seen it, who
|
|
199
|
+
did it, where (`conversation_id`, title, type), the `message_id` and a
|
|
200
|
+
plain-text preview — pass `where.conversation_id` to
|
|
201
|
+
`teams_read_conversation` to read it in context. Filter with
|
|
202
|
+
`unread_only`, `kinds` and `since_days` (default 14, max 3650); `limit`
|
|
203
|
+
(default 50, max 200). Read from the chat service, so the Activity view
|
|
204
|
+
does not need to be open; it never marks anything read.
|
|
205
|
+
- `teams_healthcheck` — resolves the token the way every tool does
|
|
206
|
+
(capturing one on a cold start) and probes the chat service with one
|
|
207
|
+
conversations listing. Reports where the token came from and when it
|
|
208
|
+
expires (both `null` when no token is held, e.g. after a failed capture)
|
|
209
|
+
and how many conversations the listing returned — never the token.
|
|
210
|
+
|
|
211
|
+
**Write** (both ask you to confirm first — see [Writes](#writes)):
|
|
212
|
+
|
|
213
|
+
- `teams_send_message` — post as you to any chat or channel, by id or name.
|
|
214
|
+
`text` is plain text: it is escaped, newlines are kept, and `:key:`
|
|
215
|
+
shortcodes (`:smile:`, `:1f389_partypopper:`) become Teams emoji.
|
|
216
|
+
`reply_to` posts into a channel post's thread — it must be a root post in
|
|
217
|
+
that channel, not a reply (in a chat it quote-replies that message); `quote` quote-replies a message anywhere; `mentions`
|
|
218
|
+
@-mentions people by MRI or by a display name matched among the
|
|
219
|
+
conversation's recent senders (an ambiguous name is refused with the
|
|
220
|
+
candidates). The result says whether the post was found again by reading
|
|
221
|
+
the conversation back (`verified`).
|
|
222
|
+
- `teams_react` — add or (with `remove: true`) withdraw your reaction on a
|
|
223
|
+
message: an emoji or name (`thumbsup`/👍, `heart`/❤️, `laugh`/😆,
|
|
224
|
+
`surprised`/😮, `sad`/😢, `angry`/😡, `checkmark`/✅) or any raw Teams
|
|
225
|
+
reaction key (`fire`, `1f389_partypopper`). The message is read back to
|
|
226
|
+
verify the change (`verified: null` when it is not found again). It writes only that message's reaction — never your
|
|
227
|
+
recent-reactions list or any other preference.
|
|
228
|
+
|
|
229
|
+
Every other tool is read-only, and none of them marks anything read.
|
|
230
|
+
|
|
231
|
+
## Writes
|
|
232
|
+
|
|
233
|
+
Both writes are visible to everyone in the conversation, so each asks you
|
|
234
|
+
first. A client that can show a confirmation prompt (Claude Code) shows one.
|
|
235
|
+
On a client that cannot, the first call posts nothing and returns a
|
|
236
|
+
`confirmation-required` preview — the conversation, the exact text, any
|
|
237
|
+
mentions, the quoted message or the reaction, with everything other people
|
|
238
|
+
wrote (titles, names, quoted text) fenced as untrusted — plus a `confirmToken`; only a
|
|
239
|
+
repeat call with that token posts. The token is single-use, expires, and is
|
|
240
|
+
bound to the exact arguments: change anything between the two calls and it
|
|
241
|
+
is refused with a fresh preview.
|
|
242
|
+
|
|
243
|
+
| variable | default | |
|
|
244
|
+
| --- | --- | --- |
|
|
245
|
+
| `MCP_CONFIRM_MODE` | `ask-user` | What a write does on a client that cannot show a confirmation prompt (claude.ai, Claude Desktop). `ask-user`: two steps, and the model must get your approval in chat before calling again with the token. `auto`: the same two steps, but the model may use the token after reviewing the preview itself. `refuse`: writes are refused on such clients. An unrecognised value is treated as `refuse`. |
|
|
246
|
+
| `MCP_CONFIRM_ELICITATION` | `on` | `off` never shows a confirmation prompt, so every client gets the `MCP_CONFIRM_MODE` behaviour. Set it for a client that says it can show prompts but never does. |
|
|
247
|
+
| `MCP_CONFIRM_TTL_SECONDS` | `600` | How long a token stays valid. |
|
|
248
|
+
| `MCP_CONFIRM_SECRET` | random per process | Signing key; set it only if tokens must survive a server restart. |
|
|
249
|
+
|
|
250
|
+
On a client without prompts the token is something the model passes back
|
|
251
|
+
itself, so keep `MCP_CONFIRM_MODE=ask-user` and approve each preview in chat
|
|
252
|
+
as the real guard on what gets posted.
|
|
253
|
+
|
|
254
|
+
**Try it in your own notes first.** The conversation `48:notes` (also by the
|
|
255
|
+
name `notes` or `self`) is your Teams self-chat ("notes to self"): both writes
|
|
256
|
+
accept it, `teams_read_conversation` reads it, nobody else sees it, and
|
|
257
|
+
it is the safe place to see what a message or reaction will look like. Every
|
|
258
|
+
other `48:` system conversation (calendar and the like) is refused.
|
|
259
|
+
|
|
260
|
+
**A send that times out is not retried.** If Teams does not confirm a post (a
|
|
261
|
+
timeout, a dropped connection or a 5xx after the request went out), the
|
|
262
|
+
result is `status: "unknown"` — the message may already be there, so read the
|
|
263
|
+
conversation before sending again. A 4xx is a refusal and stays an error. A
|
|
264
|
+
reaction Teams does not confirm is settled by reading the message back, and
|
|
265
|
+
is `status: "unknown"` only when that does not show the change. Threaded channel replies, @mentions,
|
|
266
|
+
removing a reaction and the ✅ reaction's key follow Teams' documented or
|
|
267
|
+
inferred shapes but have not been verified against a live tenant yet.
|
|
268
|
+
|
|
269
|
+
**No Calendar tool here.** Teams Web's Calendar is Outlook's data, rendered
|
|
270
|
+
inside an embedded `outlook.office.com` iframe — not the chat service's. Use
|
|
123
271
|
[`office-outlook-mcp`](https://github.com/chrischall/office-outlook-mcp)'s
|
|
124
272
|
`outlook_list_events` / `outlook_get_event` / `outlook_list_calendars`
|
|
125
|
-
instead
|
|
126
|
-
"must have it open" limitation at all.
|
|
273
|
+
instead.
|
|
127
274
|
|
|
128
275
|
## Things worth knowing
|
|
129
276
|
|
|
130
|
-
- **One Teams tab at a time.** If more than one `teams.cloud.microsoft` tab
|
|
131
|
-
is open, the bridge reads whichever answers first — which may not be the
|
|
132
|
-
one you're looking at. The "open" tools report the conversation they read
|
|
133
|
-
(`conversation.title`, or `null` if it couldn't be identified) and their
|
|
134
|
-
descriptions tell the model to check it before summarizing.
|
|
135
277
|
- **Results are framed as untrusted.** Every data tool returns
|
|
136
278
|
`{ untrusted_content: true, note, ... }` and says in its description that
|
|
137
279
|
the text is written by other Teams users. Message bodies, previews and
|
|
138
280
|
subjects are data to report, never instructions to follow — this matters
|
|
139
281
|
because the server usually runs beside write-capable MCPs (mail, messaging)
|
|
140
282
|
that an injected instruction could otherwise reach.
|
|
141
|
-
- **
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
283
|
+
- **Unread means what Teams means, and is confirmed by reading.** A message
|
|
284
|
+
is unread when it arrived after the conversation's read marker
|
|
285
|
+
(`consumptionhorizon`), was not sent by you, is a real message (`Text` or
|
|
286
|
+
`RichText/Html`) and is not deleted. System messages — call recordings and
|
|
287
|
+
transcripts (`RichText/Media_*`), `Event/*`, `ThreadActivity/*`,
|
|
288
|
+
`Control/*` — never make anything unread. The conversation listing cannot
|
|
289
|
+
tell on its own: `lastimreceivedtime` moves for a call recording too,
|
|
290
|
+
`lastMessage` can be stale, and a chat you never opened has no marker at
|
|
291
|
+
all. So the listing only nominates candidates (anything past the marker,
|
|
292
|
+
or no marker), and `unread_only` and `teams_get_unread` read each
|
|
293
|
+
candidate's messages past its marker (four at a time) and keep only those
|
|
294
|
+
holding a real unread message, with its `unread_count`. Without
|
|
295
|
+
`unread_only` the list tools' `unread` is just that cheap hint, marked
|
|
296
|
+
`unread_confirmed: false`. A candidate that answers 404 or 403 (a channel
|
|
297
|
+
that is gone or no longer readable) is not unread: it is skipped and
|
|
298
|
+
counted in `skipped_unreachable`. Channels you have hidden in Teams
|
|
299
|
+
(`hidden: true`) are not counted as unread unless you pass
|
|
300
|
+
`include_hidden`. Unread answers are also limited to recent activity:
|
|
301
|
+
a conversation counts only when its newest unread message arrived in the
|
|
302
|
+
last `since_days` days (default 14, max 3650) — in practice most
|
|
303
|
+
"unread" channels are dormant ones, untouched for months or years in teams
|
|
304
|
+
you never open. A candidate with no activity at all inside the window is
|
|
305
|
+
not even read. Whatever the window leaves out is counted in
|
|
306
|
+
`older_unread_skipped` (with a hint to widen `since_days`), never dropped
|
|
307
|
+
silently. `teams_read_conversation` is not windowed: it takes an explicit
|
|
308
|
+
`since` and `limit`. This server only reads the marker; it never moves it.
|
|
309
|
+
- **The token only goes to Teams.** The chat-service token is sent to the
|
|
310
|
+
chat-service base and, for inline images, only to https hosts under
|
|
311
|
+
`.asm.skype.com` (Teams' own image store) — an image link pointing anywhere
|
|
312
|
+
else is refused. Shared-file download uses a **separate** SharePoint token
|
|
313
|
+
(below), sent only to the file's own `*.sharepoint.com` host; the pre-signed
|
|
314
|
+
download link it returns is fetched with **no** token at all.
|
|
315
|
+
- **Shared files download from SharePoint.** They live in SharePoint, which
|
|
316
|
+
does not accept the chat-service token, so `teams_get_attachment` captures a
|
|
317
|
+
separate SharePoint token and fetches the file through SharePoint's v2.1
|
|
318
|
+
shares API — see below.
|
|
319
|
+
- **Scope grows quietly.** If you see a `not in declared set` error, the
|
|
320
|
+
extension's approved scope is behind the server's declared one — revoke
|
|
321
|
+
and re-pair `microsoft-teams-mcp` in the ContextMint Bridge popup.
|
|
322
|
+
|
|
323
|
+
## Upgrading from 0.3
|
|
324
|
+
|
|
325
|
+
0.4 moves every tool onto the Teams chat-service API, and several outputs
|
|
326
|
+
changed shape. If you script against them:
|
|
327
|
+
|
|
328
|
+
- **Removed tools:** `teams_get_open_chat_messages` and
|
|
329
|
+
`teams_get_open_channel_posts` — use `teams_read_conversation`, which reads
|
|
330
|
+
any chat or channel by id or name without it being open.
|
|
331
|
+
- **`teams_get_activity`:** rows now come from the Activity feed itself.
|
|
332
|
+
`title` and `location` are replaced by `type`/`subtype`/`kind`, `from`,
|
|
333
|
+
`where: { conversation_id, title, type }`, `message_id`, `reply_chain_id`
|
|
334
|
+
and `preview`; `time` is ISO 8601 (it was prose like "1:19 PM"); `read` is
|
|
335
|
+
new; `empty_hint` is gone (the feed no longer depends on the Activity view).
|
|
336
|
+
- **`teams_get_attachment`:** a shared file now returns its **contents** (an
|
|
337
|
+
image as image content, anything else as an MCP embedded resource carrying the
|
|
338
|
+
bytes), not just metadata and a link — see
|
|
339
|
+
[SharePoint file download](#sharepoint-file-download). A file that cannot be
|
|
340
|
+
fetched still returns the old metadata-and-link shape, so a script that only
|
|
341
|
+
reads the metadata keeps working.
|
|
342
|
+
- **`teams_healthcheck`:** the top-level `bridge` section is gone — the bridge
|
|
343
|
+
is only used to capture the token now. Token health is under `credential`
|
|
344
|
+
and `chat_service`; a new `sharepoint` note describes the on-demand,
|
|
345
|
+
short-lived SharePoint token (the healthcheck does not require one).
|
|
346
|
+
- **Chat titles:** untitled chats are titled `(1:1 chat)` (or the other
|
|
347
|
+
person's name), `Group chat: A; B; C +N` (with a `participants` array), or
|
|
348
|
+
`(untitled group chat)` — no longer the last sender's name or
|
|
349
|
+
`(untitled chat)`. Plain `teams_list_chats` / `teams_list_teams_and_channels`
|
|
350
|
+
listings put `favorite` and then `pinned` conversations first.
|
|
351
|
+
- **Unread:** confirmed by reading messages after your read point (call
|
|
352
|
+
recordings and other system events never count), hidden channels are left
|
|
353
|
+
out unless `include_hidden`, and `since_days` defaults to 14 with
|
|
354
|
+
`older_unread_skipped` reporting the rest.
|
|
164
355
|
|
|
165
356
|
## Development
|
|
166
357
|
|
|
@@ -171,11 +362,6 @@ npm test # typecheck + suite
|
|
|
171
362
|
npm run test:coverage # CI's gate
|
|
172
363
|
```
|
|
173
364
|
|
|
174
|
-
This server depends on `read_dom_list`, a fetchproxy capability added
|
|
175
|
-
alongside this repo — it needs `@fetchproxy/protocol`/`@fetchproxy/server`
|
|
176
|
-
`>= 3.1.0`, the first published versions that include it
|
|
177
|
-
([chrischall/fetchproxy#381](https://github.com/chrischall/fetchproxy/pull/381)).
|
|
178
|
-
|
|
179
365
|
## License
|
|
180
366
|
|
|
181
367
|
MIT
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bootstrap-only fetchproxy auth for the Teams chat-service API.
|
|
3
|
+
*
|
|
4
|
+
* The Teams web worker sends `Authorization: Bearer …` on every request to
|
|
5
|
+
* `https://teams.cloud.microsoft/api/chatsvc/*`. We snapshot that header off a
|
|
6
|
+
* request the page already makes, and from then on this MCP talks to the
|
|
7
|
+
* chat service with a plain Node `fetch`.
|
|
8
|
+
*
|
|
9
|
+
* The bridge is therefore touched ONCE per token (~23h), never in the hot
|
|
10
|
+
* path — and nothing ever reads the page itself: the Activity feed is a
|
|
11
|
+
* chat-service conversation too (`tools/activity.ts`).
|
|
12
|
+
*
|
|
13
|
+
* Verified live 2026-10-10 against a real Teams tenant:
|
|
14
|
+
* - the token has `aud: https://ic3.teams.office.com`,
|
|
15
|
+
* `scp: Teams.AccessAsUser.All` and a ~23.5h lifetime;
|
|
16
|
+
* - that token plus `behavioroverride: redirectAs404` authenticates plain
|
|
17
|
+
* server-side requests to the chat service with no bridge involved;
|
|
18
|
+
* - no `authentication`/`x-skypetoken` header is needed.
|
|
19
|
+
*
|
|
20
|
+
* We do NOT try to mint a token by calling an endpoint ourselves — it comes
|
|
21
|
+
* from MSAL's hidden-iframe flow, which a bridge fetch cannot drive. Capture is
|
|
22
|
+
* the only path, which is why a failed capture is a hard error with actionable
|
|
23
|
+
* guidance rather than a fallback.
|
|
24
|
+
*
|
|
25
|
+
* Import this module LAZILY (`await import('./auth-fetchproxy.js')`) from the
|
|
26
|
+
* code that needs a token, as Outlook's client does, so a server run with
|
|
27
|
+
* `TEAMS_ACCESS_TOKEN` never has to load the bridge to boot.
|
|
28
|
+
*/
|
|
29
|
+
import { createBootstrapOpts, createFetchproxyTransport } from '@chrischall/mcp-utils/fetchproxy';
|
|
30
|
+
import { readPortEnv } from '@chrischall/mcp-utils';
|
|
31
|
+
import { bridgeDeadlineMs, captureWindowMs } from './capture-window.js';
|
|
32
|
+
import { PACKAGE_NAME, VERSION } from './version.js';
|
|
33
|
+
/**
|
|
34
|
+
* fetchproxy concentrator port — one for the whole fleet. `TEAMS_WS_PORT`
|
|
35
|
+
* overrides it for local development and for a hosted bridged registration
|
|
36
|
+
* (where mcp-host names this variable in `bridgePortEnv`).
|
|
37
|
+
*/
|
|
38
|
+
const DEFAULT_WS_PORT = 37_149;
|
|
39
|
+
export function getWsPort() {
|
|
40
|
+
return readPortEnv('TEAMS_WS_PORT', DEFAULT_WS_PORT);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The one request we capture from: any chat-service call on the New Teams
|
|
44
|
+
* host. An idle tab may make none — opening a chat is what makes the worker
|
|
45
|
+
* issue one, hence the guidance in the capture error below.
|
|
46
|
+
*/
|
|
47
|
+
export const CAPTURE_DECL = {
|
|
48
|
+
host: 'teams.cloud.microsoft',
|
|
49
|
+
path: '/api/chatsvc/*',
|
|
50
|
+
headerName: 'authorization',
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* The extension's trust boundary for the chat-service path: exactly the host we
|
|
54
|
+
* capture from. Every API call afterwards is a plain server-side `fetch` the
|
|
55
|
+
* bridge never sees, so nothing wider is needed here.
|
|
56
|
+
*
|
|
57
|
+
* Shared-file download adds a SECOND, independent trust scope —
|
|
58
|
+
* `SHAREPOINT_TRUST_DOMAINS = ['sharepoint.com']` in `sharepoint-auth.ts` — used
|
|
59
|
+
* only when a file is opened. It is additive: the SharePoint capture declares
|
|
60
|
+
* `sharepoint.com` on its own transport and does NOT widen this chat-service
|
|
61
|
+
* capture decl, which stays `teams.cloud.microsoft` alone. Granting the broader
|
|
62
|
+
* SharePoint scope takes a one-time re-pair of `microsoft-teams-mcp` in the
|
|
63
|
+
* ContextMint Bridge popup; until then shared files degrade to metadata + link.
|
|
64
|
+
*/
|
|
65
|
+
export const TRUST_DOMAINS = [CAPTURE_DECL.host];
|
|
66
|
+
/**
|
|
67
|
+
* Shortest plausible token. Real ones are several KB of JWT; this only guards
|
|
68
|
+
* against an empty or echoed header, not against a wrong-audience token.
|
|
69
|
+
*/
|
|
70
|
+
const MIN_TOKEN_LENGTH = 100;
|
|
71
|
+
/** Normalise a captured header to a bare token, dropping any `Bearer ` prefix. */
|
|
72
|
+
export function stripBearer(raw) {
|
|
73
|
+
const m = /^\s*Bearer\s+(.+)$/i.exec(raw);
|
|
74
|
+
return (m ? m[1] : raw).trim();
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Capture a chat-service access token from the user's signed-in Teams tab.
|
|
78
|
+
* Returns the bare token (no `Bearer ` prefix).
|
|
79
|
+
*/
|
|
80
|
+
export async function captureTokenViaFetchproxy(env = process.env) {
|
|
81
|
+
// Read per capture, not at import: see `capture-window.ts`.
|
|
82
|
+
const windowMs = captureWindowMs(env);
|
|
83
|
+
const transport = createFetchproxyTransport({
|
|
84
|
+
// `createBootstrapOpts` derives the capability set from the declarations:
|
|
85
|
+
// `capture_request_header`, the only verb this MCP uses, beside the `fetch`
|
|
86
|
+
// base verb mcp-utils always keeps (the field replaces the server default).
|
|
87
|
+
// This is the same set as before the Activity feed left the page, so an
|
|
88
|
+
// existing pairing needs no re-approval.
|
|
89
|
+
...createBootstrapOpts({
|
|
90
|
+
domains: [...TRUST_DOMAINS],
|
|
91
|
+
bootstrap: { captureHeaders: [{ ...CAPTURE_DECL }] },
|
|
92
|
+
}),
|
|
93
|
+
port: getWsPort(),
|
|
94
|
+
// Both: the explicit deadline for every bridge version, and the declared
|
|
95
|
+
// window so mcp-utils' own derivation agrees with it.
|
|
96
|
+
fetchTimeoutMs: bridgeDeadlineMs(windowMs),
|
|
97
|
+
captureWindowMs: windowMs,
|
|
98
|
+
serverName: PACKAGE_NAME,
|
|
99
|
+
version: VERSION,
|
|
100
|
+
});
|
|
101
|
+
try {
|
|
102
|
+
// `start()` loads the identity keypair. It does not bind the port or dial —
|
|
103
|
+
// that stays lazy until the first verb — but skipping it makes the first
|
|
104
|
+
// verb throw "ensureConnected called before listen()", which reads exactly
|
|
105
|
+
// like a pairing problem and is not one.
|
|
106
|
+
await transport.start();
|
|
107
|
+
try {
|
|
108
|
+
const raw = await transport.server.captureRequestHeader({
|
|
109
|
+
...CAPTURE_DECL,
|
|
110
|
+
timeoutMs: windowMs,
|
|
111
|
+
});
|
|
112
|
+
if (typeof raw !== 'string') {
|
|
113
|
+
throw new Error(`${CAPTURE_DECL.host}: capture returned no header`);
|
|
114
|
+
}
|
|
115
|
+
const token = stripBearer(raw);
|
|
116
|
+
if (token.length < MIN_TOKEN_LENGTH) {
|
|
117
|
+
throw new Error(`${CAPTURE_DECL.host}: authorization header was present but too short to be a ` +
|
|
118
|
+
`token (${token.length} chars)`);
|
|
119
|
+
}
|
|
120
|
+
return token;
|
|
121
|
+
}
|
|
122
|
+
catch (e) {
|
|
123
|
+
const detail = e.message;
|
|
124
|
+
throw new Error(`could not capture a Teams token from the browser (${detail}). ` +
|
|
125
|
+
'Open a signed-in teams.cloud.microsoft tab and click into any chat — ' +
|
|
126
|
+
'that is what makes the page call the chat service; an idle tab never ' +
|
|
127
|
+
'does — then retry.');
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
finally {
|
|
131
|
+
try {
|
|
132
|
+
await transport.close();
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
/* the token, or the original failure, is what matters */
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|