@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
package/dist/compose.js
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Building an outgoing Teams message — pure functions, no I/O.
|
|
3
|
+
*
|
|
4
|
+
* Every shape here is the one captured from Teams' own requests (see "Verified
|
|
5
|
+
* write shapes" in `docs/plans/2026-10-10-chatsvc-api.md`), except the mention
|
|
6
|
+
* markup, which follows the documented Skype format and is NOT yet captured
|
|
7
|
+
* live. The caller's text is always escaped: the only markup a message can
|
|
8
|
+
* carry is what these builders emit (paragraph, line breaks, mention spans,
|
|
9
|
+
* emoji spans, the quote block), so a caller cannot smuggle HTML into a post.
|
|
10
|
+
*/
|
|
11
|
+
import { randomInt } from 'node:crypto';
|
|
12
|
+
import { McpToolError } from '@chrischall/mcp-utils';
|
|
13
|
+
const HTML_ESCAPES = {
|
|
14
|
+
'&': '&',
|
|
15
|
+
'<': '<',
|
|
16
|
+
'>': '>',
|
|
17
|
+
'"': '"',
|
|
18
|
+
"'": ''',
|
|
19
|
+
};
|
|
20
|
+
export function escapeHtml(s) {
|
|
21
|
+
return s.replace(/[&<>"']/g, (c) => HTML_ESCAPES[c]);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Teams' short legacy emoji keys this module can render, with the title Teams
|
|
25
|
+
* shows and the character used as the `alt` fallback. The keys are the
|
|
26
|
+
* observed ones; the titles and characters are best-effort (they only affect
|
|
27
|
+
* hover text and copy-paste, never which emoji renders).
|
|
28
|
+
*/
|
|
29
|
+
const NAMED_EMOJI = {
|
|
30
|
+
like: { title: 'Like', char: '👍' },
|
|
31
|
+
heart: { title: 'Heart', char: '❤️' },
|
|
32
|
+
laugh: { title: 'Laugh', char: '😆' },
|
|
33
|
+
surprised: { title: 'Surprised', char: '😮' },
|
|
34
|
+
sad: { title: 'Sad', char: '😢' },
|
|
35
|
+
angry: { title: 'Angry', char: '😡' },
|
|
36
|
+
smile: { title: 'Smile', char: '🙂' },
|
|
37
|
+
wink: { title: 'Wink', char: '😉' },
|
|
38
|
+
cool: { title: 'Cool', char: '😎' },
|
|
39
|
+
hearteyes: { title: 'Heart eyes', char: '😍' },
|
|
40
|
+
fire: { title: 'Fire', char: '🔥' },
|
|
41
|
+
party: { title: 'Party', char: '🎉' },
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* A unicode-style key: lowercase hex code point(s), `_`, the character's name
|
|
45
|
+
* squashed to `[a-z0-9]` (`1f389_partypopper`). Multi-code-point keys are
|
|
46
|
+
* assumed `-`-joined — unverified, so such a key at worst renders as Teams'
|
|
47
|
+
* missing-emoji image.
|
|
48
|
+
*/
|
|
49
|
+
const UNICODE_KEY = /^([0-9a-f]{4,6}(?:-[0-9a-f]{4,6})*)_([a-z0-9]+)$/;
|
|
50
|
+
/**
|
|
51
|
+
* The captured inline-emoji span for `key`, or `undefined` when the key is
|
|
52
|
+
* neither a known short name nor unicode-style — the caller then leaves the
|
|
53
|
+
* `:key:` as plain text (so "10:30:45" is never mangled).
|
|
54
|
+
*/
|
|
55
|
+
export function emojiSpan(key) {
|
|
56
|
+
let title;
|
|
57
|
+
let char;
|
|
58
|
+
const named = NAMED_EMOJI[key];
|
|
59
|
+
if (named !== undefined) {
|
|
60
|
+
({ title, char } = named);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
const m = UNICODE_KEY.exec(key);
|
|
64
|
+
if (m === null)
|
|
65
|
+
return undefined;
|
|
66
|
+
const points = m[1].split('-').map((h) => parseInt(h, 16));
|
|
67
|
+
if (points.some((p) => p > 0x10ffff))
|
|
68
|
+
return undefined;
|
|
69
|
+
char = String.fromCodePoint(...points);
|
|
70
|
+
title = m[2];
|
|
71
|
+
}
|
|
72
|
+
// `key` is [a-z0-9_-] by construction here, so it is safe in a URL and attribute.
|
|
73
|
+
const t = escapeHtml(title);
|
|
74
|
+
return (`<span contenteditable="false" title="${t}" type="(${key})" class="animated-emoticon-20-${key}" itemscope>` +
|
|
75
|
+
`<img itemscope itemtype="http://schema.skype.com/Emoji" itemid="${key}" ` +
|
|
76
|
+
`src="https://statics.teams.cdn.office.net/evergreen-assets/personal-expressions/v2/assets/emoticons/${key}/default/20_f.png" ` +
|
|
77
|
+
`title="${t}" alt="${escapeHtml(char)}" style="width:20px;height:20px;"></span>`);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Plain text → escaped HTML, newlines as `<br>`, known `:key:` shortcodes as
|
|
81
|
+
* emoji spans. A `:key:` that cannot be rendered gives its closing colon back,
|
|
82
|
+
* so in "a:b:smile:" the ":b:" miss still leaves ":smile:" to render.
|
|
83
|
+
*/
|
|
84
|
+
function renderPlain(text) {
|
|
85
|
+
let out = '';
|
|
86
|
+
let at = 0;
|
|
87
|
+
const shortcode = /:([a-z0-9_-]+):/g;
|
|
88
|
+
for (let m = shortcode.exec(text); m !== null; m = shortcode.exec(text)) {
|
|
89
|
+
const span = emojiSpan(m[1]);
|
|
90
|
+
if (span === undefined) {
|
|
91
|
+
shortcode.lastIndex = m.index + m[0].length - 1;
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
out += escapeLines(text.slice(at, m.index)) + span;
|
|
95
|
+
at = shortcode.lastIndex;
|
|
96
|
+
}
|
|
97
|
+
return out + escapeLines(text.slice(at));
|
|
98
|
+
}
|
|
99
|
+
const escapeLines = (s) => escapeHtml(s).replace(/\r?\n/g, '<br>');
|
|
100
|
+
const isWordChar = (c) => c !== undefined && /[\p{L}\p{N}_]/u.test(c);
|
|
101
|
+
/**
|
|
102
|
+
* Where `name` first occurs in `text` outside `taken`: `@name` (exactly, then
|
|
103
|
+
* ignoring case) wins, else the bare name as a whole word, ignoring case.
|
|
104
|
+
* Either way the name must END at a word boundary, so "@Sam" is never found
|
|
105
|
+
* inside "@Samantha".
|
|
106
|
+
*/
|
|
107
|
+
function locate(text, name, taken) {
|
|
108
|
+
const free = (s, e) => taken.every(([ts, te]) => e <= ts || s >= te);
|
|
109
|
+
const find = (needle, ci, wordStart) => {
|
|
110
|
+
const hay = ci ? text.toLowerCase() : text;
|
|
111
|
+
const n = ci ? needle.toLowerCase() : needle;
|
|
112
|
+
for (let i = hay.indexOf(n); i >= 0; i = hay.indexOf(n, i + 1)) {
|
|
113
|
+
const end = i + n.length;
|
|
114
|
+
if (isWordChar(text[end]) || (wordStart && isWordChar(text[i - 1])))
|
|
115
|
+
continue;
|
|
116
|
+
if (free(i, end))
|
|
117
|
+
return [i, end];
|
|
118
|
+
}
|
|
119
|
+
return undefined;
|
|
120
|
+
};
|
|
121
|
+
return find(`@${name}`, false, false) ?? find(`@${name}`, true, false) ?? find(name, true, true);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* The message body as Teams HTML: one paragraph of escaped text, with each
|
|
125
|
+
* mention's first free occurrence (`@name`, else `name`) replaced by a mention
|
|
126
|
+
* span. Mentions are numbered 0, 1, … in order of appearance in the text.
|
|
127
|
+
*/
|
|
128
|
+
export function renderMessageHtml(text, mentions) {
|
|
129
|
+
const placed = [];
|
|
130
|
+
for (const m of mentions) {
|
|
131
|
+
const range = locate(text, m.text, placed.map((p) => [p.start, p.end]));
|
|
132
|
+
if (range === undefined) {
|
|
133
|
+
throw new McpToolError(`The mention "${m.text}" does not appear in the text.`, {
|
|
134
|
+
hint: 'name_in_text must be written in text (as @name or name) once per mention.',
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
placed.push({ start: range[0], end: range[1], mri: m.mri });
|
|
138
|
+
}
|
|
139
|
+
placed.sort((a, b) => a.start - b.start);
|
|
140
|
+
let html = '';
|
|
141
|
+
let at = 0;
|
|
142
|
+
const out = [];
|
|
143
|
+
placed.forEach((p, n) => {
|
|
144
|
+
const shown = text.slice(p.start, p.end).replace(/^@/, '');
|
|
145
|
+
html += renderPlain(text.slice(at, p.start));
|
|
146
|
+
html += `<span itemscope itemtype="http://schema.skype.com/Mention" itemid="${n}">${escapeHtml(shown)}</span>`;
|
|
147
|
+
out.push({ itemid: String(n), mri: p.mri, displayName: shown });
|
|
148
|
+
at = p.end;
|
|
149
|
+
});
|
|
150
|
+
html += renderPlain(text.slice(at));
|
|
151
|
+
return { html: `<p>${html}</p>`, mentions: out };
|
|
152
|
+
}
|
|
153
|
+
/** `properties.mentions` — a JSON STRING, like every `properties` value. */
|
|
154
|
+
export function mentionsProperty(mentions) {
|
|
155
|
+
return JSON.stringify(mentions.map((m) => ({
|
|
156
|
+
'@type': 'http://schema.skype.com/Mention',
|
|
157
|
+
itemid: m.itemid,
|
|
158
|
+
mri: m.mri,
|
|
159
|
+
mentionType: 'person',
|
|
160
|
+
displayName: m.displayName,
|
|
161
|
+
})));
|
|
162
|
+
}
|
|
163
|
+
/** Longest quoted-message preview Teams' own quote block carries. */
|
|
164
|
+
const QUOTE_PREVIEW_CHARS = 200;
|
|
165
|
+
/**
|
|
166
|
+
* `s` cut to at most `max` UTF-16 units, ending in `ellipsis` when cut. Never
|
|
167
|
+
* splits a surrogate pair, so an emoji at the cut is dropped whole rather than
|
|
168
|
+
* leaving a lone half (invalid UTF-16 that renders as �).
|
|
169
|
+
*/
|
|
170
|
+
export function clipText(s, max, ellipsis = '') {
|
|
171
|
+
if (s.length <= max)
|
|
172
|
+
return s;
|
|
173
|
+
let end = Math.max(0, max - ellipsis.length);
|
|
174
|
+
const last = s.charCodeAt(end - 1);
|
|
175
|
+
if (last >= 0xd800 && last <= 0xdbff)
|
|
176
|
+
end -= 1;
|
|
177
|
+
return s.slice(0, end) + ellipsis;
|
|
178
|
+
}
|
|
179
|
+
/** The captured quote-reply block, placed before the reply's own paragraph. */
|
|
180
|
+
export function quoteHtml(q) {
|
|
181
|
+
const preview = clipText(q.text, QUOTE_PREVIEW_CHARS, '…');
|
|
182
|
+
const id = escapeHtml(q.id);
|
|
183
|
+
return (`<blockquote itemscope itemtype="http://schema.skype.com/Reply" itemid="${id}">` +
|
|
184
|
+
`<strong itemprop="mri" itemid="${escapeHtml(q.senderMri)}">${escapeHtml(q.senderName)}</strong>` +
|
|
185
|
+
`<span itemprop="time" itemid="${id}"></span>` +
|
|
186
|
+
`<p itemprop="preview">${escapeHtml(preview)}</p></blockquote>`);
|
|
187
|
+
}
|
|
188
|
+
/** `properties.qtdMsgs` — the quoted message, as a JSON string. */
|
|
189
|
+
export function qtdMsgsProperty(q) {
|
|
190
|
+
return JSON.stringify([{ messageId: q.id, sender: q.senderMri, time: Number(q.id) }]);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* A fresh `clientmessageid`: a random 19-digit number, as Teams generates.
|
|
194
|
+
* It is how the read-back finds the message this send created.
|
|
195
|
+
*/
|
|
196
|
+
export function newClientMessageId() {
|
|
197
|
+
let id = String(randomInt(1, 10));
|
|
198
|
+
for (let i = 0; i < 18; i++)
|
|
199
|
+
id += String(randomInt(0, 10));
|
|
200
|
+
return id;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* The captured `POST …/messages` body. `properties` values are JSON STRINGS,
|
|
204
|
+
* and `conversationLink` really is the literal `blah/<id>` Teams sends.
|
|
205
|
+
*/
|
|
206
|
+
export function buildSendBody(i) {
|
|
207
|
+
const time = i.now.toISOString();
|
|
208
|
+
return {
|
|
209
|
+
id: '-1',
|
|
210
|
+
type: 'Message',
|
|
211
|
+
conversationid: i.conversationId,
|
|
212
|
+
conversationLink: `blah/${i.conversationId}`,
|
|
213
|
+
from: i.meMri,
|
|
214
|
+
fromUserId: i.meMri,
|
|
215
|
+
composetime: time,
|
|
216
|
+
originalarrivaltime: time,
|
|
217
|
+
content: i.content,
|
|
218
|
+
messagetype: 'RichText/Html',
|
|
219
|
+
contenttype: 'Text',
|
|
220
|
+
imdisplayname: i.meName,
|
|
221
|
+
clientmessageid: i.clientmessageid,
|
|
222
|
+
callId: '',
|
|
223
|
+
state: 0,
|
|
224
|
+
version: '0',
|
|
225
|
+
amsreferences: [],
|
|
226
|
+
properties: {
|
|
227
|
+
importance: '',
|
|
228
|
+
subject: '',
|
|
229
|
+
title: '',
|
|
230
|
+
cards: '[]',
|
|
231
|
+
links: '[]',
|
|
232
|
+
mentions: i.mentions ?? '[]',
|
|
233
|
+
onbehalfof: null,
|
|
234
|
+
files: '[]',
|
|
235
|
+
policyViolation: null,
|
|
236
|
+
formatVariant: 'TEAMS',
|
|
237
|
+
...(i.qtdMsgs !== undefined ? { qtdMsgs: i.qtdMsgs } : {}),
|
|
238
|
+
},
|
|
239
|
+
crossPostChannels: [],
|
|
240
|
+
};
|
|
241
|
+
}
|
package/dist/deps.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.js
CHANGED
|
@@ -1,24 +1,53 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { runMcp, loadDotenvSafely } from '@chrischall/mcp-utils';
|
|
3
3
|
import { VERSION } from './version.js';
|
|
4
|
-
import {
|
|
4
|
+
import { ChatServiceClient } from './chatsvc.js';
|
|
5
|
+
import { SharePointClient } from './sharepoint.js';
|
|
6
|
+
import { SubstrateClient } from './substrate.js';
|
|
5
7
|
import { registerChatTools } from './tools/chat.js';
|
|
6
8
|
import { registerChannelTools } from './tools/channels.js';
|
|
9
|
+
import { registerConversationTools } from './tools/conversation.js';
|
|
10
|
+
import { registerUnreadTools } from './tools/unread.js';
|
|
11
|
+
import { registerChangesTools } from './tools/changes.js';
|
|
12
|
+
import { registerAttachmentTools } from './tools/attachment.js';
|
|
13
|
+
import { registerSendTools } from './tools/send.js';
|
|
14
|
+
import { registerReactTools } from './tools/react.js';
|
|
15
|
+
import { registerMarkReadTools } from './tools/markread.js';
|
|
7
16
|
import { registerActivityTools } from './tools/activity.js';
|
|
17
|
+
import { registerSearchTools } from './tools/search.js';
|
|
8
18
|
import { registerHealthcheckTool } from './tools/healthcheck.js';
|
|
9
19
|
loadDotenvSafely();
|
|
10
20
|
/**
|
|
11
21
|
* Built HERE, in the caller, not inside a registrar — see office-outlook-mcp
|
|
12
22
|
* for the full rationale (`runMcp` builds a server instance per served
|
|
13
23
|
* connection, so anything built inside a registrar would be rebuilt). For
|
|
14
|
-
* this MCP
|
|
15
|
-
*
|
|
24
|
+
* this MCP a second `ChatServiceClient` would mean a second token capture.
|
|
25
|
+
* `SharePointClient` holds its own per-host token managers, so the same reason
|
|
26
|
+
* applies — build it once, here, beside the chat-service client — and so does
|
|
27
|
+
* `SubstrateClient`, which holds the search token.
|
|
16
28
|
*/
|
|
17
|
-
const
|
|
29
|
+
const deps = {
|
|
30
|
+
chatsvc: new ChatServiceClient(),
|
|
31
|
+
sharepoint: new SharePointClient(),
|
|
32
|
+
substrate: new SubstrateClient(),
|
|
33
|
+
};
|
|
18
34
|
await runMcp({
|
|
19
35
|
name: 'microsoft-teams-mcp',
|
|
20
36
|
version: VERSION,
|
|
21
37
|
banner: '[microsoft-teams-mcp] This project was developed and is maintained by AI. Use at your own discretion.',
|
|
22
|
-
deps
|
|
23
|
-
tools: [
|
|
38
|
+
deps,
|
|
39
|
+
tools: [
|
|
40
|
+
registerChatTools,
|
|
41
|
+
registerChannelTools,
|
|
42
|
+
registerConversationTools,
|
|
43
|
+
registerUnreadTools,
|
|
44
|
+
registerChangesTools,
|
|
45
|
+
registerAttachmentTools,
|
|
46
|
+
registerSendTools,
|
|
47
|
+
registerReactTools,
|
|
48
|
+
registerMarkReadTools,
|
|
49
|
+
registerActivityTools,
|
|
50
|
+
registerSearchTools,
|
|
51
|
+
registerHealthcheckTool,
|
|
52
|
+
],
|
|
24
53
|
});
|