@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.
- package/.claude-plugin/marketplace.json +4 -4
- package/.claude-plugin/plugin.json +2 -2
- package/README.md +577 -93
- package/dist/auth-fetchproxy.js +138 -0
- package/dist/bundle.js +44324 -37483
- package/dist/capture-window.js +41 -0
- package/dist/chatsvc.js +580 -0
- package/dist/compose.js +241 -0
- package/dist/deps.js +1 -0
- package/dist/index.js +35 -6
- package/dist/model.js +603 -0
- package/dist/sharepoint-auth.js +162 -0
- package/dist/sharepoint-token-cache.js +105 -0
- package/dist/sharepoint.js +289 -0
- package/dist/substrate-auth.js +104 -0
- package/dist/substrate-token-cache.js +64 -0
- package/dist/substrate.js +319 -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/changes.js +241 -0
- package/dist/tools/channels.js +62 -44
- package/dist/tools/chat-search.js +65 -0
- package/dist/tools/chat.js +121 -41
- package/dist/tools/confirm.js +188 -0
- package/dist/tools/conversation.js +394 -30
- package/dist/tools/cursor.js +43 -0
- package/dist/tools/errors.js +18 -17
- package/dist/tools/format.js +135 -0
- package/dist/tools/healthcheck.js +91 -27
- package/dist/tools/limit.js +43 -12
- package/dist/tools/listing.js +180 -0
- package/dist/tools/markread.js +246 -0
- package/dist/tools/react.js +217 -0
- package/dist/tools/roots.js +73 -0
- package/dist/tools/search.js +426 -0
- package/dist/tools/send.js +309 -0
- package/dist/tools/timezone.js +38 -0
- package/dist/tools/titles.js +180 -0
- package/dist/tools/unread.js +263 -0
- package/dist/tools/untrusted.js +16 -1
- package/dist/version.js +1 -1
- package/mint.yaml +75 -20
- package/package.json +1 -2
- package/server.json +87 -3
- package/skills/teams-fpx/SKILL.md +111 -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
|
@@ -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
|
+
}
|