@chrischall/microsoft-teams-mcp 0.13.1 → 0.15.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 +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +241 -33
- package/dist/attachments.js +238 -0
- package/dist/auth-fetchproxy.js +42 -7
- package/dist/bridge-scope.js +45 -8
- package/dist/browser-open.js +138 -0
- package/dist/bundle.js +28684 -30653
- package/dist/capture-feedback.js +283 -0
- package/dist/chatsvc.js +132 -7
- package/dist/compose.js +9 -1
- package/dist/file-upload.js +335 -0
- package/dist/index.js +11 -1
- package/dist/model.js +1 -0
- package/dist/presence.js +120 -0
- package/dist/profile.js +182 -0
- package/dist/recap-auth.js +6 -4
- package/dist/recap.js +3 -1
- package/dist/sender-email.js +147 -0
- package/dist/sharepoint-auth.js +196 -29
- package/dist/sharepoint.js +329 -8
- package/dist/substrate-auth.js +8 -7
- package/dist/substrate.js +98 -4
- package/dist/tools/attach.js +167 -0
- package/dist/tools/attachment.js +3 -1
- package/dist/tools/conversation.js +14 -5
- package/dist/tools/edit.js +42 -14
- package/dist/tools/errors.js +10 -11
- package/dist/tools/export.js +30 -3
- package/dist/tools/format.js +29 -6
- package/dist/tools/group-chat.js +349 -33
- package/dist/tools/healthcheck.js +23 -9
- package/dist/tools/mention-check.js +225 -0
- package/dist/tools/people.js +149 -39
- package/dist/tools/profile.js +67 -0
- package/dist/tools/send.js +134 -37
- package/dist/tools/sender-email-arg.js +37 -0
- package/dist/tools/token-status.js +97 -0
- package/dist/tools/unread.js +3 -2
- package/dist/tools/upload-slots.js +51 -0
- package/dist/version.js +1 -1
- package/mint.yaml +19 -0
- package/package.json +4 -1
- package/server.json +30 -2
- package/skills/teams-fpx/references/teams-env.sh +1 -1
package/dist/tools/send.js
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { CONFIRM_FLOW_SENTENCE, CONFIRM_INJECTION_RULE, confirmTokenParam, confirmWrite, McpToolError, toolAnnotations, unknownOutcomeReason, writeOrUnknown, } from '@chrischall/mcp-utils';
|
|
3
3
|
import { buildSendBody, clipText, MESSAGE_FORMATS, mentionsProperty, newClientMessageId, qtdMsgsProperty, quoteHtml, renderMessageHtml, } from '../compose.js';
|
|
4
|
-
import { htmlToText, localIsoTime, normaliseMessage, SELF_CHAT, senderMri } from '../model.js';
|
|
5
|
-
import { resolveListed } from './conversation.js';
|
|
4
|
+
import { htmlToText, localIsoTime, matchConversations, normaliseMessage, SELF_CHAT, SELF_CHAT_ALIASES, senderMri, summariseAll, } from '../model.js';
|
|
5
|
+
import { resolveConversation, resolveListed } from './conversation.js';
|
|
6
|
+
import { enrichTitles } from './titles.js';
|
|
6
7
|
import { wrapApiError } from './errors.js';
|
|
7
|
-
import {
|
|
8
|
+
import { normaliseName, personMri, recentSenders } from './people.js';
|
|
9
|
+
import { CHANNEL_ID, checkMentions, mentionScope, scopeById, scopeByName } from './mention-check.js';
|
|
8
10
|
import { THIRD_PARTY_NAMES_NOTE, untrustedField, untrustedResult, UNTRUSTED_DESCRIPTION_SUFFIX, } from './untrusted.js';
|
|
9
11
|
import { workMeta } from './hints.js';
|
|
12
|
+
import { attachmentsParam } from '../attachments.js';
|
|
13
|
+
import { attachmentResult, deliverAttachments, planAttachments } from './attach.js';
|
|
14
|
+
import { filesProperty } from '../file-upload.js';
|
|
10
15
|
import { resolveTimeZone } from './timezone.js';
|
|
11
16
|
const TOOL = 'teams_send_message';
|
|
12
17
|
/**
|
|
@@ -37,14 +42,16 @@ export const mentionArg = z.object({
|
|
|
37
42
|
person: z
|
|
38
43
|
.string()
|
|
39
44
|
.min(1)
|
|
40
|
-
.describe('Who to mention: an MRI (8:orgid:…)
|
|
45
|
+
.describe('Who to mention: an MRI (8:orgid:…) or bare Entra object id, a display name matched among recent senders in this ' +
|
|
46
|
+
'conversation, or — to mention a channel — the id (19:…@thread.tacv2) or exact name of the channel being ' +
|
|
47
|
+
'posted to or of its team.'),
|
|
41
48
|
});
|
|
42
49
|
/**
|
|
43
50
|
* The conversation a write goes to: `48:notes` (also by the names `notes` /
|
|
44
51
|
* `self`), else an id or name as `teams_list_messages` resolves it. `verb` words the refusals ("post to",
|
|
45
52
|
* "react in").
|
|
46
53
|
*/
|
|
47
|
-
export async function resolveTarget(chatsvc, conversation, me, verb = 'post to') {
|
|
54
|
+
export async function resolveTarget(chatsvc, conversation, me, verb = 'post to', opts = {}) {
|
|
48
55
|
if (conversation === SELF_CHAT)
|
|
49
56
|
return { id: SELF_CHAT, title: 'Notes (self-chat)', kind: 'self' };
|
|
50
57
|
if (conversation.startsWith('48:')) {
|
|
@@ -53,30 +60,68 @@ export async function resolveTarget(chatsvc, conversation, me, verb = 'post to')
|
|
|
53
60
|
});
|
|
54
61
|
}
|
|
55
62
|
const raw = await chatsvc.listConversations();
|
|
63
|
+
const isName = !SELF_CHAT_ALIASES.has(conversation.trim().toLowerCase()) && !raw.some((c) => c.id === conversation);
|
|
64
|
+
if (opts.preferOneOnOne && isName) {
|
|
65
|
+
// A person's name: their 1:1 wins over group chats and channels that also
|
|
66
|
+
// match it — but only when the name is EXACTLY that one 1:1's person
|
|
67
|
+
// (ignoring case and "Last, First" order). The rest are listed, not hidden.
|
|
68
|
+
const titled = await enrichTitles(chatsvc, raw, me, summariseAll(raw, me));
|
|
69
|
+
const q = normaliseName(conversation);
|
|
70
|
+
const exact = titled.filter((t) => t.kind === 'oneOnOne' && (normaliseName(t.title) === q || (t.participants ?? []).some((p) => normaliseName(p) === q)));
|
|
71
|
+
if (exact.length === 1) {
|
|
72
|
+
const one = exact[0];
|
|
73
|
+
const others = matchConversations(titled, conversation)
|
|
74
|
+
.filter((m) => m.id !== one.id)
|
|
75
|
+
.map((m) => ({ id: m.id, title: m.title, kind: m.kind }));
|
|
76
|
+
return {
|
|
77
|
+
id: one.id,
|
|
78
|
+
title: one.title,
|
|
79
|
+
kind: one.kind,
|
|
80
|
+
...(one.participants !== undefined ? { participants: one.participants } : {}),
|
|
81
|
+
...(others.length > 0 ? { other_matches: others } : {}),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
const s = resolveConversation(titled, conversation, verb);
|
|
85
|
+
return { id: s.id, title: s.title, kind: s.kind, ...(s.participants !== undefined ? { participants: s.participants } : {}) };
|
|
86
|
+
}
|
|
56
87
|
const s = await resolveListed(chatsvc, raw, me, conversation, verb);
|
|
57
88
|
return { id: s.id, title: s.title, kind: s.kind, ...(s.participants !== undefined ? { participants: s.participants } : {}) };
|
|
58
89
|
}
|
|
59
90
|
/**
|
|
60
|
-
* Each mention's MRI: an MRI is taken as-is
|
|
61
|
-
*
|
|
62
|
-
*
|
|
91
|
+
* Each mention's MRI: an MRI is taken as-is (a bare Entra object id as
|
|
92
|
+
* `8:orgid:<id>`; a channel/team id is a channel mention); the exact name of
|
|
93
|
+
* the channel being posted to or its team (`scope`) is that channel/team;
|
|
94
|
+
* any other name must match exactly one recent sender (exactly, else as a
|
|
95
|
+
* substring, ignoring case). Ambiguous or unknown is an error naming the
|
|
96
|
+
* candidates — never a guess. `senders` loads the recent senders (shared with
|
|
97
|
+
* the preview's mention check, so they are read once).
|
|
63
98
|
*/
|
|
64
|
-
export async function resolveMentions(chatsvc, conversationId, mentions) {
|
|
99
|
+
export async function resolveMentions(chatsvc, conversationId, mentions, opts = {}) {
|
|
65
100
|
if (mentions.length === 0)
|
|
66
101
|
return [];
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
102
|
+
const { scope } = opts;
|
|
103
|
+
const byName = (p) => personMri(p) === undefined && scopeByName(scope, p) === undefined;
|
|
104
|
+
const senders = mentions.some((m) => byName(m.person.trim()))
|
|
105
|
+
? await (opts.senders ?? (() => recentSenders(chatsvc, conversationId)))()
|
|
106
|
+
: new Map();
|
|
70
107
|
const known = [...senders].map(([mri, name]) => ({ mri, name }));
|
|
71
108
|
return mentions.map(({ name_in_text, person }) => {
|
|
72
109
|
const p = person.trim();
|
|
73
|
-
|
|
74
|
-
|
|
110
|
+
const mri = personMri(p);
|
|
111
|
+
if (mri !== undefined) {
|
|
112
|
+
if (CHANNEL_ID.test(mri))
|
|
113
|
+
return { target: { text: name_in_text, mri }, person: p, ...scopeById(scope, mri) };
|
|
114
|
+
return { target: { text: name_in_text, mri }, person: p, type: 'person' };
|
|
115
|
+
}
|
|
116
|
+
const place = scopeByName(scope, p);
|
|
117
|
+
if (place !== undefined)
|
|
118
|
+
return { target: { text: name_in_text, mri: place.id }, person: place.name, type: place.type, name: place.name };
|
|
75
119
|
const q = p.toLowerCase();
|
|
76
120
|
const exact = known.filter((k) => k.name.toLowerCase() === q);
|
|
77
121
|
const found = exact.length > 0 ? exact : known.filter((k) => k.name.toLowerCase().includes(q));
|
|
78
|
-
if (found.length === 1)
|
|
79
|
-
return { target: { text: name_in_text, mri: found[0].mri }, person: found[0].name };
|
|
122
|
+
if (found.length === 1) {
|
|
123
|
+
return { target: { text: name_in_text, mri: found[0].mri }, person: found[0].name, type: 'person', name: found[0].name };
|
|
124
|
+
}
|
|
80
125
|
// Candidate names are other people's display names: JSON-quoted and
|
|
81
126
|
// flagged as data, as a read tool's envelope would.
|
|
82
127
|
if (found.length > 1) {
|
|
@@ -92,10 +137,15 @@ export async function resolveMentions(chatsvc, conversationId, mentions) {
|
|
|
92
137
|
.join(', ');
|
|
93
138
|
throw new McpToolError(`No recent sender in this conversation is called "${person}".`, {
|
|
94
139
|
hint: (some ? `Recent senders: ${some}. ${THIRD_PARTY_NAMES_NOTE} ` : '') +
|
|
95
|
-
|
|
140
|
+
"Pass an exact display name, the person's MRI (8:orgid:…), or — to mention the channel — its id or exact name.",
|
|
96
141
|
});
|
|
97
142
|
});
|
|
98
143
|
}
|
|
144
|
+
/** Load `load` once, however many times the result is asked for. */
|
|
145
|
+
export function once(load) {
|
|
146
|
+
let p;
|
|
147
|
+
return () => (p ??= load());
|
|
148
|
+
}
|
|
99
149
|
/** The message a quote points at, read for its sender and text. */
|
|
100
150
|
async function quoted(chatsvc, conversationId, id) {
|
|
101
151
|
const m = await chatsvc.getMessage(conversationId, id);
|
|
@@ -164,6 +214,12 @@ async function threadRoot(chatsvc, channelId, id, me) {
|
|
|
164
214
|
});
|
|
165
215
|
}
|
|
166
216
|
}
|
|
217
|
+
/** The action line's word on "@name"s that are not mentions, so it shows in the one-line summary too. */
|
|
218
|
+
export function unmatchedNote(count) {
|
|
219
|
+
if (count === 0)
|
|
220
|
+
return '';
|
|
221
|
+
return `, with ${count} @name${count === 1 ? ' that is' : 's that are'} not a mention (sent as plain text)`;
|
|
222
|
+
}
|
|
167
223
|
/**
|
|
168
224
|
* A send that may or may not have landed becomes a `status: "unknown"`
|
|
169
225
|
* result, never an error: an error invites a fresh preview and a second post.
|
|
@@ -178,7 +234,7 @@ function unconfirmedPost(conversation) {
|
|
|
178
234
|
'(teams_list_messages); do not resend blindly.',
|
|
179
235
|
});
|
|
180
236
|
}
|
|
181
|
-
export function registerSendTools(server, { chatsvc }) {
|
|
237
|
+
export function registerSendTools(server, { chatsvc, ...attach }) {
|
|
182
238
|
server.registerTool(TOOL, {
|
|
183
239
|
title: 'Send a Teams message',
|
|
184
240
|
description: 'Post a message as the signed-in user to any chat or channel, by id (from teams_list_conversations / ' +
|
|
@@ -194,16 +250,31 @@ export function registerSendTools(server, { chatsvc }) {
|
|
|
194
250
|
'post opens with a quote of it. quote quote-replies a message in any conversation. Pass reply_to ' +
|
|
195
251
|
'or quote only when the user asked for a reply or a quote; when the request is ambiguous (they ' +
|
|
196
252
|
'mention a message\'s timestamp, or say "reply" in a chat), ask them whether they want it quoted ' +
|
|
197
|
-
'rather than guessing.
|
|
253
|
+
'rather than guessing. A conversation given as a person\'s exact name (either "First Last" or "Last, First") goes to ' +
|
|
254
|
+
'your 1:1 with them even when group chats also match; the preview and result list those other matches ' +
|
|
255
|
+
'(other_matches). mentions @-mention people: name_in_text must appear ' +
|
|
198
256
|
'in text, and person is an MRI or a display name matched among recent senders (ambiguous names ' +
|
|
199
257
|
`are refused with the candidates). conversation "${SELF_CHAT}" (or "notes" / "self") is the user's own notes self-chat — ` +
|
|
200
258
|
'use it to try this tool without anyone else seeing; other 48: system conversations are refused. ' +
|
|
201
259
|
'Everyone in the conversation sees the post. The result says whether the post was found again by ' +
|
|
202
260
|
'reading the conversation back (verified); status "unknown" means Teams did not confirm it — check ' +
|
|
203
|
-
'the conversation before retrying. ' +
|
|
261
|
+
'the conversation before retrying. attachments sends files with the message (any type, up to 10, each at most ' +
|
|
262
|
+
'100 MiB): in a chat they are uploaded to your OneDrive "Microsoft Teams Chat Files" folder and shared (view) with ' +
|
|
263
|
+
'the chat\'s members; in a channel, to the channel\'s folder of the team\'s SharePoint "Shared Documents". They show ' +
|
|
264
|
+
'as file cards, as when Teams sends a file; text may then be left out. A file that cannot be uploaded or shared ' +
|
|
265
|
+
'stops the send — the message is never posted without its files. ' +
|
|
266
|
+
'A mention\'s person may also be a bare Entra object id, or the id (19:…@thread.tacv2) or exact name of the ' +
|
|
267
|
+
'channel being posted to or of its team, to mention that channel or team. An "@name" in text that no mention ' +
|
|
268
|
+
'covers is sent as plain text and notifies nobody: the preview lists it as unmatched_mentions (with ' +
|
|
269
|
+
'mention_warning) above the text — a warning, not a refusal. ' +
|
|
204
270
|
CONFIRM_FLOW_SENTENCE +
|
|
205
271
|
' The preview shows the conversation and exactly what would be posted, says in plain words what ' +
|
|
206
|
-
'is quoted (quoting: the sender, time and text, or "none"),
|
|
272
|
+
'is quoted (quoting: the sender, time and text, or "none"), warns when reply_to is set, shows each mention ' +
|
|
273
|
+
'(mentions_summary, and per mention its mention_type person|channel|team, resolved name, MRI and, for a person, ' +
|
|
274
|
+
'in_conversation true|false|"unknown"; mention_notes when someone is not a member or a channel is not the one ' +
|
|
275
|
+
'posted to), and lists each attached ' +
|
|
276
|
+
'file (name, size, type, SHA-256, destination) and who gets access; nothing is uploaded until it is confirmed, and ' +
|
|
277
|
+
'a file that changed in between is refused. ' +
|
|
207
278
|
CONFIRM_INJECTION_RULE +
|
|
208
279
|
UNTRUSTED_DESCRIPTION_SUFFIX,
|
|
209
280
|
annotations: toolAnnotations({ readOnly: false, destructive: true, idempotent: false, openWorld: true }),
|
|
@@ -217,8 +288,11 @@ export function registerSendTools(server, { chatsvc }) {
|
|
|
217
288
|
text: z
|
|
218
289
|
.string()
|
|
219
290
|
.min(1)
|
|
220
|
-
.
|
|
291
|
+
.optional()
|
|
292
|
+
.describe('The message: plain text (newlines kept, :key: shortcodes become emoji), or Markdown with format "markdown". ' +
|
|
293
|
+
'May be left out only when attachments are given.'),
|
|
221
294
|
format: formatParam,
|
|
295
|
+
attachments: attachmentsParam,
|
|
222
296
|
reply_to: z
|
|
223
297
|
.string()
|
|
224
298
|
.min(1)
|
|
@@ -229,10 +303,17 @@ export function registerSendTools(server, { chatsvc }) {
|
|
|
229
303
|
mentions: z.array(mentionArg).max(20).optional().describe('People to @-mention in text.'),
|
|
230
304
|
confirmToken: confirmTokenParam,
|
|
231
305
|
},
|
|
232
|
-
}, async ({ conversation, text, format = 'text', reply_to, quote, mentions, confirmToken }, ctx) => {
|
|
306
|
+
}, async ({ conversation, text: givenText, format = 'text', attachments, reply_to, quote, mentions, confirmToken }, ctx) => {
|
|
233
307
|
try {
|
|
308
|
+
if ((givenText === undefined || givenText === '') && (attachments === undefined || attachments.length === 0)) {
|
|
309
|
+
throw new McpToolError('Pass text or attachments (or both): there is nothing to send.', { kind: 'unknown' });
|
|
310
|
+
}
|
|
311
|
+
const text = givenText ?? '';
|
|
234
312
|
const [me, meName] = await Promise.all([chatsvc.meMri(), chatsvc.meDisplayName()]);
|
|
235
|
-
|
|
313
|
+
// A person's name prefers their 1:1 (the other matches are listed in the preview).
|
|
314
|
+
const target = await resolveTarget(chatsvc, conversation, me, 'post to', { preferOneOnOne: true });
|
|
315
|
+
// Every file is read, vetted and hashed on BOTH calls; nothing is uploaded here.
|
|
316
|
+
const plan = attachments !== undefined ? await planAttachments(chatsvc, attach, target, attachments, me) : undefined;
|
|
236
317
|
const inChannel = target.kind === 'channel';
|
|
237
318
|
// In a chat there is no thread to reply under, so reply_to means "quote this".
|
|
238
319
|
let quoteId = quote;
|
|
@@ -249,8 +330,20 @@ export function registerSendTools(server, { chatsvc }) {
|
|
|
249
330
|
if (inChannel && reply_to !== undefined)
|
|
250
331
|
await threadRoot(chatsvc, target.id, reply_to, me);
|
|
251
332
|
const q = quoteId !== undefined ? await quoted(chatsvc, target.id, quoteId) : undefined;
|
|
252
|
-
const
|
|
253
|
-
const
|
|
333
|
+
const senders = once(() => recentSenders(chatsvc, target.id));
|
|
334
|
+
const scope = await mentionScope(chatsvc, me, target, mentions ?? []);
|
|
335
|
+
const people = await resolveMentions(chatsvc, target.id, mentions ?? [], { scope, senders });
|
|
336
|
+
const checked = await checkMentions(chatsvc, {
|
|
337
|
+
target,
|
|
338
|
+
me,
|
|
339
|
+
text,
|
|
340
|
+
mentions: people.map((p, i) => ({ ...p, name_in_text: mentions[i].name_in_text })),
|
|
341
|
+
scope,
|
|
342
|
+
senders,
|
|
343
|
+
});
|
|
344
|
+
const rendered = text === '' && people.length === 0
|
|
345
|
+
? { html: '', mentions: [] }
|
|
346
|
+
: renderMessageHtml(text, people.map((p) => p.target), format);
|
|
254
347
|
const content = (q ? quoteHtml(q) : '') + rendered.html;
|
|
255
348
|
const quoting = quotingLine(q);
|
|
256
349
|
// reply_to is easy to pass by reflex; it changes what is posted, so the preview says so.
|
|
@@ -278,7 +371,9 @@ export function registerSendTools(server, { chatsvc }) {
|
|
|
278
371
|
// The title is someone else's text: JSON-quoted so it cannot break out of its quotes.
|
|
279
372
|
summary: `Post a message to ${target.kind} ${JSON.stringify(target.title)}` +
|
|
280
373
|
(q ? `, quoting ${JSON.stringify(q.senderName)}` : ', no quote') +
|
|
281
|
-
(inChannel && reply_to !== undefined ? `, in the thread under ${reply_to}` : '')
|
|
374
|
+
(inChannel && reply_to !== undefined ? `, in the thread under ${reply_to}` : '') +
|
|
375
|
+
(plan ? `, with ${plan.files.length} attached file${plan.files.length === 1 ? '' : 's'}` : '') +
|
|
376
|
+
unmatchedNote(checked.unmatched),
|
|
282
377
|
// The signed-in user, so an approval minted under one account never posts as another.
|
|
283
378
|
account: me,
|
|
284
379
|
target: postTo,
|
|
@@ -290,27 +385,26 @@ export function registerSendTools(server, { chatsvc }) {
|
|
|
290
385
|
conversation: untrustedField(target),
|
|
291
386
|
quoting,
|
|
292
387
|
...(replyWarning ? { warning: replyWarning } : {}),
|
|
388
|
+
// Mention warnings sit ABOVE the text, where they are read first.
|
|
389
|
+
...checked.above,
|
|
293
390
|
text,
|
|
294
391
|
format,
|
|
295
392
|
...(inChannel && reply_to !== undefined ? { thread_root: reply_to } : {}),
|
|
296
|
-
...(people.length > 0
|
|
297
|
-
? {
|
|
298
|
-
mentions: untrustedField(people.map((p, i) => ({
|
|
299
|
-
name_in_text: mentions[i].name_in_text,
|
|
300
|
-
person: p.person,
|
|
301
|
-
mri: p.target.mri,
|
|
302
|
-
}))),
|
|
303
|
-
}
|
|
304
|
-
: {}),
|
|
393
|
+
...(people.length > 0 ? { mentions: untrustedField(checked.mentions) } : {}),
|
|
305
394
|
...(q
|
|
306
395
|
? { quoted_message: untrustedField({ id: q.id, sender: q.senderName, preview: clipText(q.text, PREVIEW_CHARS) }) }
|
|
307
396
|
: {}),
|
|
308
|
-
|
|
397
|
+
...(plan ? plan.preview : {}),
|
|
398
|
+
note: 'clientmessageid and the timestamps are filled in when the message is posted' +
|
|
399
|
+
(plan ? '; properties.files is filled with the file cards once the files are uploaded.' : '.'),
|
|
309
400
|
},
|
|
310
401
|
confirmToken,
|
|
311
402
|
});
|
|
312
403
|
if (gate)
|
|
313
404
|
return gate;
|
|
405
|
+
// Confirmed: upload and share every file first. Any failure throws, so
|
|
406
|
+
// the message is never posted without its files.
|
|
407
|
+
const uploaded = plan ? await deliverAttachments(attach, plan) : [];
|
|
314
408
|
const clientmessageid = newClientMessageId();
|
|
315
409
|
const body = buildSendBody({
|
|
316
410
|
conversationId: postTo,
|
|
@@ -320,6 +414,7 @@ export function registerSendTools(server, { chatsvc }) {
|
|
|
320
414
|
clientmessageid,
|
|
321
415
|
now: new Date(),
|
|
322
416
|
...properties,
|
|
417
|
+
...(uploaded.length > 0 ? { files: filesProperty(uploaded) } : {}),
|
|
323
418
|
});
|
|
324
419
|
const sent = await writeOrUnknown(() => chatsvc.sendMessage(postTo, body), unconfirmedPost(target));
|
|
325
420
|
if (!sent.ok)
|
|
@@ -336,10 +431,12 @@ export function registerSendTools(server, { chatsvc }) {
|
|
|
336
431
|
}
|
|
337
432
|
const verified = found !== undefined;
|
|
338
433
|
const message_id = sent.value.id ?? found;
|
|
434
|
+
const files = plan ? await attachmentResult(plan, uploaded) : {};
|
|
339
435
|
return untrustedResult({
|
|
340
436
|
status: 'sent',
|
|
341
437
|
conversation: target,
|
|
342
438
|
...(message_id !== undefined ? { message_id } : {}),
|
|
439
|
+
...files,
|
|
343
440
|
verified,
|
|
344
441
|
...(verified
|
|
345
442
|
? {}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The opt-in `sender_email` argument `teams_list_messages` and
|
|
3
|
+
* `teams_export_messages` share: each message's sender email, looked up in
|
|
4
|
+
* the directory once per sender and cached (`sender-email.ts`).
|
|
5
|
+
*/
|
|
6
|
+
import { McpToolError } from '@chrischall/mcp-utils';
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
export const senderEmailArg = z
|
|
9
|
+
.boolean()
|
|
10
|
+
.optional()
|
|
11
|
+
.describe("Also give each message the sender's email (senderEmail), looked up in your organisation's directory once per " +
|
|
12
|
+
'sender (cached), by the sender\'s exact MRI — never a namesake. Default false. Uses the directory token ' +
|
|
13
|
+
"teams_get_profile uses; a sender the directory does not list has none.");
|
|
14
|
+
export const SENDER_EMAIL_DESCRIPTION = ' sender_email: true adds senderEmail to each message whose sender the directory lists (one lookup per sender, ' +
|
|
15
|
+
'cached); if the directory cannot be asked, sender_email_error says why and the messages still come back.';
|
|
16
|
+
/** `sender_email` needs the full format (the only one carrying senderMri) and a directory. */
|
|
17
|
+
export function assertSenderEmail(senderEmail, format, directory) {
|
|
18
|
+
if (!senderEmail)
|
|
19
|
+
return;
|
|
20
|
+
if (format !== undefined && format !== 'full') {
|
|
21
|
+
throw new McpToolError(`sender_email needs format "full" (format "${format}" carries no sender MRI).`, {
|
|
22
|
+
hint: 'Drop format, or drop sender_email.',
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
if (directory === undefined) {
|
|
26
|
+
throw new McpToolError('sender_email is unavailable: this server has no directory client.', {
|
|
27
|
+
hint: 'Drop sender_email.',
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** What a sender-email pass could not do, as result fields. */
|
|
32
|
+
export function senderEmailReport(r) {
|
|
33
|
+
return {
|
|
34
|
+
...(r.error !== undefined ? { sender_email_error: r.error } : {}),
|
|
35
|
+
...(r.unresolved !== undefined ? { sender_email_unresolved: r.unresolved } : {}),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { McpToolError, toolAnnotations } from '@chrischall/mcp-utils';
|
|
3
|
+
import { captureFailure, tokenAction, TokenCaptureError } from '../capture-feedback.js';
|
|
4
|
+
import { workMeta } from './hints.js';
|
|
5
|
+
const TOOL = 'teams_token_status';
|
|
6
|
+
const TITLE = 'Check (or prime) the Teams tokens this server holds';
|
|
7
|
+
/** How long a prime waits by default, and at most. */
|
|
8
|
+
export const PRIME_WAIT_SECONDS = 120;
|
|
9
|
+
const NOT_MANAGED = { held: false, note: 'This server cannot report this token.' };
|
|
10
|
+
export function registerTokenStatusTool(server, { chatsvc, substrate }) {
|
|
11
|
+
server.registerTool(TOOL, {
|
|
12
|
+
title: TITLE,
|
|
13
|
+
description: 'Report whether this server holds the tokens it reads Teams with, and until when — without touching the ' +
|
|
14
|
+
'browser: chat_service (every chat read and write) and substrate (search, and the directory lookup ' +
|
|
15
|
+
'teams_create_group_chat / teams_add_chat_members use for a name not in your chats). Use it before a ' +
|
|
16
|
+
'write to see whether the write will need a token capture. Each token reports held, from (memory, disk ' +
|
|
17
|
+
'cache or TEAMS_ACCESS_TOKEN), expires_at, minutes_remaining, and the last capture (its stable error code ' +
|
|
18
|
+
'when it failed, e.g. token_no_request_seen). A capture only sees requests the Teams page makes WHILE it ' +
|
|
19
|
+
'waits, so a click made before a call never counts. wait: true primes one token (token, default ' +
|
|
20
|
+
`chat_service) when it is not held: it waits up to wait_seconds (default ${PRIME_WAIT_SECONDS}) for the page ` +
|
|
21
|
+
'to make the request, reporting progress meanwhile — tell the user to start it, then click into any chat in ' +
|
|
22
|
+
'their Teams tab (for substrate: run any search in its search box). If the client gives up sooner, the ' +
|
|
23
|
+
'capture still finishes and the token is kept. A failed prime is reported in the result (error, next_step), ' +
|
|
24
|
+
'not as a tool error. Never returns a token.',
|
|
25
|
+
annotations: toolAnnotations({ title: TITLE, readOnly: true, idempotent: true, openWorld: true }),
|
|
26
|
+
_meta: workMeta('other', { aliases: ['token status', 'teams token', 'sign in', 'prime token', 'auth status'] }),
|
|
27
|
+
inputSchema: {
|
|
28
|
+
wait: z
|
|
29
|
+
.boolean()
|
|
30
|
+
.optional()
|
|
31
|
+
.describe('Prime the token when it is not held: wait for the Teams page to make the request (default false).'),
|
|
32
|
+
token: z
|
|
33
|
+
.enum(['chat_service', 'substrate'])
|
|
34
|
+
.optional()
|
|
35
|
+
.describe('Which token wait primes (default chat_service; substrate is the search/directory token).'),
|
|
36
|
+
wait_seconds: z
|
|
37
|
+
.number()
|
|
38
|
+
.int()
|
|
39
|
+
.min(5)
|
|
40
|
+
.max(PRIME_WAIT_SECONDS)
|
|
41
|
+
.optional()
|
|
42
|
+
.describe(`How long wait holds, in seconds (5–${PRIME_WAIT_SECONDS}, default ${PRIME_WAIT_SECONDS}).`),
|
|
43
|
+
},
|
|
44
|
+
}, async ({ wait = false, token = 'chat_service', wait_seconds = PRIME_WAIT_SECONDS }) => {
|
|
45
|
+
const status = () => ({
|
|
46
|
+
chat_service: chatsvc.tokenStatus(),
|
|
47
|
+
substrate: substrate.tokenStatus?.() ?? NOT_MANAGED,
|
|
48
|
+
});
|
|
49
|
+
let primed;
|
|
50
|
+
let error;
|
|
51
|
+
let nextStep;
|
|
52
|
+
const before = status()[token];
|
|
53
|
+
if (wait && !before.held) {
|
|
54
|
+
try {
|
|
55
|
+
if (token === 'chat_service')
|
|
56
|
+
await chatsvc.ensureToken({ windowMs: wait_seconds * 1000 });
|
|
57
|
+
else if (substrate.ensureToken !== undefined)
|
|
58
|
+
await substrate.ensureToken({ windowMs: wait_seconds * 1000 });
|
|
59
|
+
else
|
|
60
|
+
throw new McpToolError('This server cannot prime the Substrate token.');
|
|
61
|
+
primed = token;
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
const described = err instanceof TokenCaptureError || /could not capture/i.test(err instanceof Error ? err.message : '')
|
|
65
|
+
? captureFailure(err, token === 'chat_service' ? 'read Teams' : 'search Teams', token)
|
|
66
|
+
: err instanceof McpToolError
|
|
67
|
+
? err
|
|
68
|
+
: new McpToolError(err instanceof Error ? err.message : String(err));
|
|
69
|
+
error = described.message;
|
|
70
|
+
nextStep = described.hint;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const now = status();
|
|
74
|
+
if (nextStep === undefined) {
|
|
75
|
+
const missing = ['chat_service', 'substrate'].filter((k) => !now[k].held);
|
|
76
|
+
nextStep =
|
|
77
|
+
missing.length === 0
|
|
78
|
+
? 'Both tokens are held; no capture is needed for now.'
|
|
79
|
+
: `Not held: ${missing.join(', ')}. To prime one, call ${TOOL} with wait: true` +
|
|
80
|
+
`${missing[0] === 'substrate' ? ' and token: "substrate"' : ''}, and once it starts ` +
|
|
81
|
+
`${tokenAction(missing[0])} — a click made before the call starts does not count.`;
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
content: [
|
|
85
|
+
{
|
|
86
|
+
type: 'text',
|
|
87
|
+
text: JSON.stringify({
|
|
88
|
+
...now,
|
|
89
|
+
...(primed !== undefined ? { primed } : {}),
|
|
90
|
+
...(error !== undefined ? { error } : {}),
|
|
91
|
+
next_step: nextStep,
|
|
92
|
+
}, null, 2),
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
}
|
package/dist/tools/unread.js
CHANGED
|
@@ -144,9 +144,10 @@ export function registerUnreadTools(server, { chatsvc }) {
|
|
|
144
144
|
description: 'Get every unread message across all the chats and channels the signed-in user is in ' +
|
|
145
145
|
'(or those matching kinds / query), grouped by conversation, most recent activity ' +
|
|
146
146
|
'first. Each conversation comes with its summary (id, kind, title, team) and only the ' +
|
|
147
|
-
'messages the user has not read, oldest first; a channel\'s are
|
|
147
|
+
'messages the user has not read, oldest first, and message_count; a channel\'s are listed flat (each with ' +
|
|
148
|
+
'thread_root_id) and also grouped as threads ' +
|
|
148
149
|
'under their root post. A root the user already read is fetched and marked outside_window: true ' +
|
|
149
|
-
`(it is context, not unread or counted); up to ${MAX_ROOT_FETCHES} roots are fetched per call, and ` +
|
|
150
|
+
`(it is context, in threads only: not unread, listed or counted); up to ${MAX_ROOT_FETCHES} roots are fetched per call, and ` +
|
|
150
151
|
'any beyond that or that cannot be fetched is { id, missing: true }. Exact, as in ' +
|
|
151
152
|
'Teams: every conversation with activity past its read marker (or never opened) is read ' +
|
|
152
153
|
'past the marker and kept only if it holds a real message from someone else, so a call ' +
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { McpToolError, toolAnnotations } from '@chrischall/mcp-utils';
|
|
3
|
+
import { blobStoreFromEnv, MAX_UPLOAD_FILES, mintUploadSlot, uploadSlotRequestSchema } from '@chrischall/mcp-utils/export';
|
|
4
|
+
import { MAX_ATTACHMENT_BYTES, SLOT_TOOL } from '../attachments.js';
|
|
5
|
+
import { workMeta } from './hints.js';
|
|
6
|
+
export function registerUploadSlotTools(server, { env = process.env } = {}) {
|
|
7
|
+
server.registerTool(SLOT_TOOL, {
|
|
8
|
+
title: 'Get upload URLs for Teams attachments',
|
|
9
|
+
description: 'Hosted connector (claude.ai): get signed upload URLs so teams_send_message / teams_edit_message can attach a file ' +
|
|
10
|
+
'this server cannot read from your disk. For each file returns {blobKey, uploadUrl, curl, expiresAt}: PUT the file ' +
|
|
11
|
+
'to uploadUrl with exactly the Content-Type shown (the curl does it), then pass {blobKey} as an item of the ' +
|
|
12
|
+
`message tool's attachments. Any file type, each at most ${MAX_ATTACHMENT_BYTES / (1024 * 1024)} MiB; up to ` +
|
|
13
|
+
`${MAX_UPLOAD_FILES} files per call. Writes nothing to Teams; each URL is a credential to write that one upload ` +
|
|
14
|
+
'and expires in 30 minutes. Refused when this server has no blob store (a local install: pass path instead).',
|
|
15
|
+
annotations: toolAnnotations({ readOnly: true, openWorld: true }),
|
|
16
|
+
_meta: workMeta('other', { aliases: ['upload url', 'attach file', 'file upload'] }),
|
|
17
|
+
inputSchema: {
|
|
18
|
+
files: z
|
|
19
|
+
.array(uploadSlotRequestSchema)
|
|
20
|
+
.min(1)
|
|
21
|
+
.max(MAX_UPLOAD_FILES)
|
|
22
|
+
.describe('One entry per file: {filename, mimeType?}. The filename (a bare name, no path) is what Teams will show.'),
|
|
23
|
+
},
|
|
24
|
+
}, async ({ files }) => {
|
|
25
|
+
const store = blobStoreFromEnv(env);
|
|
26
|
+
if (!store) {
|
|
27
|
+
throw new McpToolError(`${SLOT_TOOL} needs the blob store a hosted deployment provides, and this server has no blob store. ` +
|
|
28
|
+
'Pass the attachment as path (a local file) or inline (base64) to teams_send_message / teams_edit_message instead.', { kind: 'unknown' });
|
|
29
|
+
}
|
|
30
|
+
let slots;
|
|
31
|
+
try {
|
|
32
|
+
slots = files.map((req) => mintUploadSlot(store, req));
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
throw new McpToolError(`Cannot make an upload slot: ${err.message}`, { kind: 'unknown' });
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
content: [
|
|
39
|
+
{
|
|
40
|
+
type: 'text',
|
|
41
|
+
text: JSON.stringify({
|
|
42
|
+
slots,
|
|
43
|
+
next: 'PUT each file to its uploadUrl with exactly its Content-Type (run the curl, replacing the <path to …> ' +
|
|
44
|
+
'placeholder), then call teams_send_message (or teams_edit_message) with attachments: [{ blobKey }] — one ' +
|
|
45
|
+
"item per slot's blobKey.",
|
|
46
|
+
}),
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
}
|
package/dist/version.js
CHANGED
package/mint.yaml
CHANGED
|
@@ -62,6 +62,25 @@ env:
|
|
|
62
62
|
help: >-
|
|
63
63
|
Set to 'false' to stop caching the captured token between runs. Defaults
|
|
64
64
|
to true.
|
|
65
|
+
- name: TEAMS_OPEN_SIGNIN_TAB
|
|
66
|
+
required: false
|
|
67
|
+
help: >-
|
|
68
|
+
Set to 'false' to never open a shared file's link in a browser tab when
|
|
69
|
+
the browser has no session on its SharePoint host. Defaults to true.
|
|
70
|
+
- name: TEAMS_OPEN_TEAMS_TAB
|
|
71
|
+
required: false
|
|
72
|
+
help: >-
|
|
73
|
+
Set to 'false' to never open the Teams web app in a browser tab when a
|
|
74
|
+
token capture starts. Defaults to true on a local install; never used on
|
|
75
|
+
a hosted one (the browser is not on the server's machine).
|
|
76
|
+
- name: TEAMS_UPLOAD_DIRS
|
|
77
|
+
required: false
|
|
78
|
+
help: >-
|
|
79
|
+
Folders (separated by ':' on macOS/Linux, ';' on Windows) that teams_send_message / teams_edit_message may attach local files from. Defaults to your home folder; hidden files and folders are refused either way.
|
|
80
|
+
- name: TEAMS_ONEDRIVE_HOST
|
|
81
|
+
required: false
|
|
82
|
+
help: >-
|
|
83
|
+
Your OneDrive host (e.g. contoso-my.sharepoint.com), where attachments sent in chats are uploaded. Defaults to the OneDrive host of a SharePoint host the server already knows (one a shared file was fetched from).
|
|
65
84
|
- name: TEAMS_TOKEN_FILE
|
|
66
85
|
required: false
|
|
67
86
|
help: >-
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chrischall/microsoft-teams-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"mcpName": "io.github.chrischall/microsoft-teams-mcp",
|
|
5
5
|
"description": "Microsoft Teams MCP server for Claude — developed and maintained by AI (Claude Code)",
|
|
6
6
|
"author": "Claude Code (AI) <https://www.anthropic.com/claude>",
|
|
@@ -67,5 +67,8 @@
|
|
|
67
67
|
"allowScripts": {
|
|
68
68
|
"esbuild": false,
|
|
69
69
|
"fsevents": false
|
|
70
|
+
},
|
|
71
|
+
"overrides": {
|
|
72
|
+
"uuid": "^11.1.1"
|
|
70
73
|
}
|
|
71
74
|
}
|
package/server.json
CHANGED
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
"url": "https://github.com/chrischall/microsoft-teams-mcp",
|
|
7
7
|
"source": "github"
|
|
8
8
|
},
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.15.0",
|
|
10
10
|
"packages": [
|
|
11
11
|
{
|
|
12
12
|
"registryType": "npm",
|
|
13
13
|
"identifier": "@chrischall/microsoft-teams-mcp",
|
|
14
|
-
"version": "0.
|
|
14
|
+
"version": "0.15.0",
|
|
15
15
|
"transport": {
|
|
16
16
|
"type": "stdio"
|
|
17
17
|
},
|
|
@@ -72,6 +72,34 @@
|
|
|
72
72
|
"format": "string",
|
|
73
73
|
"isSecret": false
|
|
74
74
|
},
|
|
75
|
+
{
|
|
76
|
+
"name": "TEAMS_OPEN_SIGNIN_TAB",
|
|
77
|
+
"description": "Set to false to never open a shared file's link in a browser tab. Defaults to on: when a shared SharePoint file is on a host the browser has no session for, the file's link opens in Chrome once so the browser signs in there, then the download is retried. The tab is left open.",
|
|
78
|
+
"isRequired": false,
|
|
79
|
+
"format": "string",
|
|
80
|
+
"isSecret": false
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
"name": "TEAMS_OPEN_TEAMS_TAB",
|
|
84
|
+
"description": "Set to false to never open the Teams web app in a browser tab when a token capture starts. Defaults to on for a local install (never on a hosted one): a capture only sees a request the Teams page makes while it waits, and a freshly loading Teams tab makes one at once, so the server opens https://teams.cloud.microsoft/ in Chrome (at most once per 10 minutes) as a chat-service token capture begins.",
|
|
85
|
+
"isRequired": false,
|
|
86
|
+
"format": "string",
|
|
87
|
+
"isSecret": false
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"name": "TEAMS_UPLOAD_DIRS",
|
|
91
|
+
"description": "Folders (separated by ':' on macOS/Linux, ';' on Windows) that teams_send_message / teams_edit_message may attach local files from. Defaults to your home folder; hidden files and folders are refused either way.",
|
|
92
|
+
"isRequired": false,
|
|
93
|
+
"format": "string",
|
|
94
|
+
"isSecret": false
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"name": "TEAMS_ONEDRIVE_HOST",
|
|
98
|
+
"description": "Your OneDrive host (e.g. contoso-my.sharepoint.com), where attachments sent in chats are uploaded. Defaults to the OneDrive host of a SharePoint host the server already knows (one a shared file was fetched from).",
|
|
99
|
+
"isRequired": false,
|
|
100
|
+
"format": "string",
|
|
101
|
+
"isSecret": false
|
|
102
|
+
},
|
|
75
103
|
{
|
|
76
104
|
"name": "TEAMS_TOKEN_CACHE",
|
|
77
105
|
"description": "Set to false to keep the captured token in memory only. Defaults to on: it is cached so a restart within its ~23h lifetime needs no browser.",
|
|
@@ -53,7 +53,7 @@ sys.stdout.write(vals[0].strip() if vals else "")
|
|
|
53
53
|
|
|
54
54
|
case "$token" in
|
|
55
55
|
Bearer\ *) : ;;
|
|
56
|
-
"") echo "no authorization header captured — click into
|
|
56
|
+
"") echo "no authorization header captured — retry, and click into any chat in your Teams tab while it waits (a click before it starts does not count)" >&2; return 1 ;;
|
|
57
57
|
*) token="Bearer $token" ;;
|
|
58
58
|
esac
|
|
59
59
|
|