@chrischall/microsoft-teams-mcp 0.8.7 → 0.10.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 +119 -26
- package/dist/auth-fetchproxy.js +2 -2
- package/dist/bridge-scope.js +4 -6
- package/dist/bundle.js +954 -135
- package/dist/chatsvc.js +101 -7
- package/dist/index.js +3 -1
- package/dist/sharepoint-auth.js +94 -40
- package/dist/sharepoint-token-cache.js +19 -17
- package/dist/sharepoint.js +46 -33
- package/dist/substrate.js +127 -11
- package/dist/tools/attachment.js +77 -31
- package/dist/tools/group-chat.js +517 -0
- package/dist/tools/healthcheck.js +4 -4
- package/dist/tools/people.js +240 -0
- package/dist/tools/send.js +3 -16
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/server.json +3 -3
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* People by name, for the tools that act on someone: a group chat's members
|
|
3
|
+
* (`teams_add_chat_members`, `teams_remove_chat_members`,
|
|
4
|
+
* `teams_create_group_chat`) and a message's
|
|
5
|
+
* @mentions (`teams_send_message`).
|
|
6
|
+
*
|
|
7
|
+
* A person is, in this order:
|
|
8
|
+
* - an MRI (`8:orgid:<oid>`) or a bare oid — taken as is (source `id`);
|
|
9
|
+
* - an email address (has an `@`) — looked up in the directory (Substrate's
|
|
10
|
+
* people suggestions, `substrate.ts`), and taken only when exactly one
|
|
11
|
+
* person there has that email or UPN, ignoring case;
|
|
12
|
+
* - a display name — matched first among the people this MCP can already
|
|
13
|
+
* see (source `chat`): the other person of each 1:1 chat (named as
|
|
14
|
+
* `tools/titles.ts` names that 1:1) and the recent senders of the chat
|
|
15
|
+
* being changed; exact (as {@link normaliseName} compares), else
|
|
16
|
+
* substring; several is refused. ONLY when that finds no one is the
|
|
17
|
+
* directory asked (source `directory`), and a suggestion is taken only
|
|
18
|
+
* when it is (a) the one suggestion whose normalised name equals the
|
|
19
|
+
* query's, or (b) the ONLY suggestion and the normalised query is a run of
|
|
20
|
+
* whole words of its normalised name ("solomon" or "gary" for "Solomon,
|
|
21
|
+
* Gary", never "sol"). Anything else is refused, listing the suggestions.
|
|
22
|
+
*
|
|
23
|
+
* A name is never guessed: ambiguous or unknown is an error. The chat
|
|
24
|
+
* service's own user-search endpoints answer 401 with the chat-service token
|
|
25
|
+
* (live, 2026-11-09), so the directory is reached through Substrate with the
|
|
26
|
+
* token search already captures.
|
|
27
|
+
*/
|
|
28
|
+
import { McpToolError } from '@chrischall/mcp-utils';
|
|
29
|
+
import { isUserMessage, oneOnOnePeerMri, senderMri, summariseAll } from '../model.js';
|
|
30
|
+
import { enrichTitles } from './titles.js';
|
|
31
|
+
import { THIRD_PARTY_NAMES_NOTE } from './untrusted.js';
|
|
32
|
+
/** An MRI such as `8:orgid:<oid>` (a person) or `28:<id>` (a bot). */
|
|
33
|
+
export const MRI = /^\d+:\S+$/;
|
|
34
|
+
/** A bare Entra object id. */
|
|
35
|
+
const GUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
36
|
+
/** Recent messages scanned for senders. */
|
|
37
|
+
const RECENT_MESSAGES = 200;
|
|
38
|
+
/** Candidates an error lists. */
|
|
39
|
+
const MAX_CANDIDATES = 10;
|
|
40
|
+
/** The MRI an input names directly — an MRI as is, a bare GUID as `8:orgid:<guid>` — else `undefined` (a name). */
|
|
41
|
+
export function personMri(input) {
|
|
42
|
+
const s = input.trim();
|
|
43
|
+
if (MRI.test(s))
|
|
44
|
+
return s;
|
|
45
|
+
if (GUID.test(s))
|
|
46
|
+
return `8:orgid:${s.toLowerCase()}`;
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* A name for comparing: lower-cased, spacing collapsed, and a "Last, First"
|
|
51
|
+
* display name (common in Teams) turned round to "first last".
|
|
52
|
+
*/
|
|
53
|
+
export function normaliseName(name) {
|
|
54
|
+
const s = name.trim().toLowerCase().replace(/\s+/g, ' ');
|
|
55
|
+
const m = /^([^,]+),\s*([^,]+)$/.exec(s);
|
|
56
|
+
return m ? `${m[2].trim()} ${m[1].trim()}` : s;
|
|
57
|
+
}
|
|
58
|
+
/** Who has written in the conversation lately, by MRI → display name. */
|
|
59
|
+
export async function recentSenders(chatsvc, conversationId) {
|
|
60
|
+
const out = new Map();
|
|
61
|
+
for (const m of await chatsvc.getMessages(conversationId, { max: RECENT_MESSAGES })) {
|
|
62
|
+
const mri = senderMri(m.from);
|
|
63
|
+
const name = m.imdisplayname?.trim();
|
|
64
|
+
if (isUserMessage(m) && mri !== undefined && name && !out.has(mri))
|
|
65
|
+
out.set(mri, name);
|
|
66
|
+
}
|
|
67
|
+
return out;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Everyone this MCP can put a name to for `conversationId`: the other person
|
|
71
|
+
* of every 1:1 the user has (as that 1:1 is titled), then the chat's recent
|
|
72
|
+
* senders. With no `conversationId` (a chat not yet made), the 1:1 people
|
|
73
|
+
* only. One entry per MRI (ignoring case), the 1:1 name winning. Never
|
|
74
|
+
* throws — a failed read just knows fewer people.
|
|
75
|
+
*/
|
|
76
|
+
export async function knownPeople(chatsvc, me, conversationId) {
|
|
77
|
+
const byMri = new Map();
|
|
78
|
+
const add = (mri, name) => {
|
|
79
|
+
const key = mri.toLowerCase();
|
|
80
|
+
if (name.trim() && !byMri.has(key))
|
|
81
|
+
byMri.set(key, { mri, name: name.trim() });
|
|
82
|
+
};
|
|
83
|
+
try {
|
|
84
|
+
const raw = await chatsvc.listConversations();
|
|
85
|
+
const oneOnOnes = summariseAll(raw, me).filter((s) => s.kind === 'oneOnOne');
|
|
86
|
+
for (const s of await enrichTitles(chatsvc, raw, me, oneOnOnes)) {
|
|
87
|
+
const peer = oneOnOnePeerMri(s.id, me);
|
|
88
|
+
const name = s.participants?.[0];
|
|
89
|
+
if (peer !== undefined && name !== undefined)
|
|
90
|
+
add(peer, name);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
// No 1:1 names; the chat's own senders may still do.
|
|
95
|
+
}
|
|
96
|
+
if (conversationId === undefined)
|
|
97
|
+
return [...byMri.values()];
|
|
98
|
+
try {
|
|
99
|
+
for (const [mri, name] of await recentSenders(chatsvc, conversationId))
|
|
100
|
+
add(mri, name);
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
// Fewer names, not a failure.
|
|
104
|
+
}
|
|
105
|
+
return [...byMri.values()];
|
|
106
|
+
}
|
|
107
|
+
/** The known name of `mri`, if any. */
|
|
108
|
+
export function knownName(mri, known) {
|
|
109
|
+
const key = mri.toLowerCase();
|
|
110
|
+
return known.find((k) => k.mri.toLowerCase() === key)?.name;
|
|
111
|
+
}
|
|
112
|
+
/** An email address, as opposed to a name. */
|
|
113
|
+
function isEmail(input) {
|
|
114
|
+
return /^[^@\s]+@[^@\s]+$/.test(input.trim());
|
|
115
|
+
}
|
|
116
|
+
/** Candidates, JSON-quoted (they are other people's display names), with email when known and MRI. */
|
|
117
|
+
function candidateList(people) {
|
|
118
|
+
return people
|
|
119
|
+
.slice(0, MAX_CANDIDATES)
|
|
120
|
+
.map((k) => {
|
|
121
|
+
const email = k.email ?? k.upn;
|
|
122
|
+
return `${JSON.stringify(k.name)}${email !== undefined ? ` <${email}>` : ''} (${k.mri})`;
|
|
123
|
+
})
|
|
124
|
+
.join('; ');
|
|
125
|
+
}
|
|
126
|
+
/** The local match for a name: one person, none (`undefined`), or a refusal when several match. */
|
|
127
|
+
function matchKnown(person, known) {
|
|
128
|
+
const q = normaliseName(person);
|
|
129
|
+
const raw = person.trim().toLowerCase();
|
|
130
|
+
const exact = known.filter((k) => normaliseName(k.name) === q);
|
|
131
|
+
const found = exact.length > 0
|
|
132
|
+
? exact
|
|
133
|
+
: known.filter((k) => normaliseName(k.name).includes(q) || k.name.toLowerCase().includes(raw));
|
|
134
|
+
if (found.length === 1)
|
|
135
|
+
return found[0];
|
|
136
|
+
if (found.length > 1) {
|
|
137
|
+
throw new McpToolError(`"${person}" matches ${found.length} people: ${candidateList(found)}. ${THIRD_PARTY_NAMES_NOTE}`, { hint: 'Pass the MRI (8:orgid:…) of the one you mean.' });
|
|
138
|
+
}
|
|
139
|
+
return undefined;
|
|
140
|
+
}
|
|
141
|
+
const PASS_ID = "Pass the person's email address or MRI (8:orgid:…) instead.";
|
|
142
|
+
/** A directory failure as the refusal for `person`, keeping the failure's message, kind and remedy. */
|
|
143
|
+
function directoryFailed(person, err, email) {
|
|
144
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
145
|
+
const own = err instanceof McpToolError ? err.hint : undefined;
|
|
146
|
+
const remedy = own ??
|
|
147
|
+
'Run any search in the Teams search box of a signed-in Teams tab while retrying (that is what lets this ' +
|
|
148
|
+
'server capture the token it searches the directory with).';
|
|
149
|
+
const lead = email ? `Could not look up "${person}" because` : `No one in your chats is called "${person}", and`;
|
|
150
|
+
return new McpToolError(`${lead} the directory could not be searched: ${message}`, {
|
|
151
|
+
hint: `${remedy} Or pass the person's MRI (8:orgid:…) instead.`,
|
|
152
|
+
...(err instanceof McpToolError && err.kind !== undefined ? { kind: err.kind } : {}),
|
|
153
|
+
cause: err,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
function fromDirectory(person, p) {
|
|
157
|
+
const email = p.email ?? p.upn;
|
|
158
|
+
return { person, mri: p.mri, name: p.name, source: 'directory', ...(email !== undefined ? { email } : {}) };
|
|
159
|
+
}
|
|
160
|
+
/** The one directory person an email names: their email or UPN equal to it, ignoring case. */
|
|
161
|
+
function pickByEmail(person, found) {
|
|
162
|
+
const want = person.trim().toLowerCase();
|
|
163
|
+
const hits = found.filter((p) => p.email?.toLowerCase() === want || p.upn?.toLowerCase() === want);
|
|
164
|
+
if (hits.length === 1)
|
|
165
|
+
return fromDirectory(person, hits[0]);
|
|
166
|
+
if (hits.length > 1) {
|
|
167
|
+
throw new McpToolError(`"${person}" is the address of ${hits.length} people in the directory: ${candidateList(hits)}. ${THIRD_PARTY_NAMES_NOTE}`, { hint: 'Pass the MRI (8:orgid:…) of the one you mean.' });
|
|
168
|
+
}
|
|
169
|
+
throw new McpToolError(`No one in your organisation's directory has the address "${person}".`, {
|
|
170
|
+
hint: "Check the address, or pass the person's name or MRI (8:orgid:…) instead. Only people in your " +
|
|
171
|
+
'organisation (not distribution lists or personal contacts) are found there.',
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* The one directory person a name means — see the module comment for the
|
|
176
|
+
* rule: a unique exact normalised match, or the only suggestion when the
|
|
177
|
+
* query is a run of whole words of its name. Otherwise refused.
|
|
178
|
+
*/
|
|
179
|
+
function pickByName(person, found) {
|
|
180
|
+
const q = normaliseName(person);
|
|
181
|
+
const exact = found.filter((p) => normaliseName(p.name) === q);
|
|
182
|
+
if (exact.length === 1)
|
|
183
|
+
return fromDirectory(person, exact[0]);
|
|
184
|
+
if (exact.length > 1) {
|
|
185
|
+
throw new McpToolError(`"${person}" matches ${exact.length} people in the directory: ${candidateList(exact)}. ${THIRD_PARTY_NAMES_NOTE}`, { hint: 'Pass the email address or MRI (8:orgid:…) of the one you mean.' });
|
|
186
|
+
}
|
|
187
|
+
if (found.length === 1 && ` ${normaliseName(found[0].name)} `.includes(` ${q} `))
|
|
188
|
+
return fromDirectory(person, found[0]);
|
|
189
|
+
if (found.length > 0) {
|
|
190
|
+
throw new McpToolError(`No one in your chats is called "${person}", and no one in the directory is called exactly that; it ` +
|
|
191
|
+
`suggested: ${candidateList(found)}. ${THIRD_PARTY_NAMES_NOTE}`, { hint: 'If one of them is who you mean, pass their email address or MRI (8:orgid:…).' });
|
|
192
|
+
}
|
|
193
|
+
throw new McpToolError(`No one in your chats or your organisation's directory is called "${person}".`, {
|
|
194
|
+
hint: `${PASS_ID} A name is matched among the other person of each of your 1:1 chats and (for an existing chat) ` +
|
|
195
|
+
"its recent senders, then searched in your organisation's directory.",
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Each requested person's MRI (and name, source and — from the directory —
|
|
200
|
+
* email), by the rules in the module comment. Every person resolves or the
|
|
201
|
+
* call throws, naming the candidates or the failure. Local matching runs for
|
|
202
|
+
* every input first, so a local ambiguity refuses before the directory is
|
|
203
|
+
* asked; then the directory is asked once per distinct input that needs it
|
|
204
|
+
* (`force`, so a retry after running a Teams search really re-captures).
|
|
205
|
+
*/
|
|
206
|
+
export async function resolvePeople(inputs, known, directory) {
|
|
207
|
+
const local = inputs.map((person) => {
|
|
208
|
+
const direct = personMri(person);
|
|
209
|
+
if (direct !== undefined) {
|
|
210
|
+
const name = knownName(direct, known);
|
|
211
|
+
return { person, mri: direct, ...(name !== undefined ? { name } : {}), source: 'id' };
|
|
212
|
+
}
|
|
213
|
+
if (isEmail(person))
|
|
214
|
+
return { person, email: true };
|
|
215
|
+
const k = matchKnown(person, known);
|
|
216
|
+
return k !== undefined ? { person, mri: k.mri, name: k.name, source: 'chat' } : { person, email: false };
|
|
217
|
+
});
|
|
218
|
+
const asked = new Map();
|
|
219
|
+
const out = [];
|
|
220
|
+
for (const r of local) {
|
|
221
|
+
if ('mri' in r) {
|
|
222
|
+
out.push(r);
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
const text = r.person.trim();
|
|
226
|
+
const key = r.email ? `@${text.toLowerCase()}` : normaliseName(text);
|
|
227
|
+
let found = asked.get(key);
|
|
228
|
+
if (found === undefined) {
|
|
229
|
+
try {
|
|
230
|
+
found = await directory.suggestPeople(text, { force: true });
|
|
231
|
+
}
|
|
232
|
+
catch (err) {
|
|
233
|
+
throw directoryFailed(r.person, err, r.email);
|
|
234
|
+
}
|
|
235
|
+
asked.set(key, found);
|
|
236
|
+
}
|
|
237
|
+
out.push(r.email ? pickByEmail(r.person, found) : pickByName(r.person, found));
|
|
238
|
+
}
|
|
239
|
+
return out;
|
|
240
|
+
}
|
package/dist/tools/send.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
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, mentionsProperty, newClientMessageId, qtdMsgsProperty, quoteHtml, renderMessageHtml, } from '../compose.js';
|
|
4
|
-
import { htmlToText,
|
|
4
|
+
import { htmlToText, normaliseMessage, SELF_CHAT, senderMri } from '../model.js';
|
|
5
5
|
import { resolveListed } from './conversation.js';
|
|
6
6
|
import { wrapApiError } from './errors.js';
|
|
7
|
+
import { MRI, recentSenders } from './people.js';
|
|
7
8
|
import { THIRD_PARTY_NAMES_NOTE, untrustedField, untrustedResult, UNTRUSTED_DESCRIPTION_SUFFIX, } from './untrusted.js';
|
|
8
9
|
import { workMeta } from './hints.js';
|
|
9
10
|
const TOOL = 'teams_send_message';
|
|
@@ -13,15 +14,12 @@ const TOOL = 'teams_send_message';
|
|
|
13
14
|
* (calendar, notifications, …) is refused.
|
|
14
15
|
*/
|
|
15
16
|
export { SELF_CHAT };
|
|
16
|
-
/** Recent messages scanned for
|
|
17
|
-
const RECENT_MESSAGES = 200;
|
|
17
|
+
/** Recent messages scanned for the read-back. */
|
|
18
18
|
const READBACK_MESSAGES = 50;
|
|
19
19
|
/** Candidates a mention error lists. */
|
|
20
20
|
const MAX_CANDIDATES = 10;
|
|
21
21
|
/** Previewed text of a quoted message. */
|
|
22
22
|
const PREVIEW_CHARS = 200;
|
|
23
|
-
/** An MRI such as `8:orgid:<oid>` (a person) or `28:<id>` (a bot). */
|
|
24
|
-
const MRI = /^\d+:\S+$/;
|
|
25
23
|
const mentionArg = z.object({
|
|
26
24
|
name_in_text: z
|
|
27
25
|
.string()
|
|
@@ -49,17 +47,6 @@ export async function resolveTarget(chatsvc, conversation, me, verb = 'post to')
|
|
|
49
47
|
const s = await resolveListed(chatsvc, raw, me, conversation, verb);
|
|
50
48
|
return { id: s.id, title: s.title, kind: s.kind, ...(s.participants !== undefined ? { participants: s.participants } : {}) };
|
|
51
49
|
}
|
|
52
|
-
/** Who has written in the conversation lately, by MRI → display name. */
|
|
53
|
-
async function recentSenders(chatsvc, conversationId) {
|
|
54
|
-
const out = new Map();
|
|
55
|
-
for (const m of await chatsvc.getMessages(conversationId, { max: RECENT_MESSAGES })) {
|
|
56
|
-
const mri = senderMri(m.from);
|
|
57
|
-
const name = m.imdisplayname?.trim();
|
|
58
|
-
if (isUserMessage(m) && mri !== undefined && name && !out.has(mri))
|
|
59
|
-
out.set(mri, name);
|
|
60
|
-
}
|
|
61
|
-
return out;
|
|
62
|
-
}
|
|
63
50
|
/**
|
|
64
51
|
* Each mention's MRI: an MRI is taken as-is; a name must match exactly one
|
|
65
52
|
* recent sender (exactly, else as a substring, ignoring case). Ambiguous or
|
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chrischall/microsoft-teams-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.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>",
|
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.10.0",
|
|
10
10
|
"packages": [
|
|
11
11
|
{
|
|
12
12
|
"registryType": "npm",
|
|
13
13
|
"identifier": "@chrischall/microsoft-teams-mcp",
|
|
14
|
-
"version": "0.
|
|
14
|
+
"version": "0.10.0",
|
|
15
15
|
"transport": {
|
|
16
16
|
"type": "stdio"
|
|
17
17
|
},
|
|
@@ -116,7 +116,7 @@
|
|
|
116
116
|
},
|
|
117
117
|
{
|
|
118
118
|
"name": "MCP_CONFIRM_MODE",
|
|
119
|
-
"description": "What the writes (teams_send_message, teams_react, teams_mark_read and the read tools' mark_read) do on a client that cannot show a confirmation prompt (claude.ai, Claude Desktop): \"ask-user\" (default: the first call returns a preview and a confirmToken, and the model must get your approval in chat before using it), \"auto\" (the model may use the token after reviewing the preview itself) or \"refuse\". An unrecognised value is treated as refuse.",
|
|
119
|
+
"description": "What the writes (teams_send_message, teams_react, teams_mark_read, teams_rename_chat, teams_add_chat_members, teams_remove_chat_members, teams_create_group_chat and the read tools' mark_read) do on a client that cannot show a confirmation prompt (claude.ai, Claude Desktop): \"ask-user\" (default: the first call returns a preview and a confirmToken, and the model must get your approval in chat before using it), \"auto\" (the model may use the token after reviewing the preview itself) or \"refuse\". An unrecognised value is treated as refuse.",
|
|
120
120
|
"isRequired": false,
|
|
121
121
|
"format": "string",
|
|
122
122
|
"isSecret": false
|