@chrischall/microsoft-teams-mcp 0.9.0 → 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 +24 -6
- package/dist/bundle.js +159 -5
- package/dist/chatsvc.js +49 -0
- package/dist/substrate.js +2 -1
- package/dist/tools/group-chat.js +144 -12
- package/dist/tools/people.js +8 -4
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/server.json +3 -3
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
},
|
|
8
8
|
"metadata": {
|
|
9
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.
|
|
10
|
+
"version": "0.10.0"
|
|
11
11
|
},
|
|
12
12
|
"plugins": [
|
|
13
13
|
{
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"displayName": "Microsoft Teams",
|
|
16
16
|
"source": "./",
|
|
17
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.
|
|
18
|
+
"version": "0.10.0",
|
|
19
19
|
"author": {
|
|
20
20
|
"name": "Chris Hall"
|
|
21
21
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "microsoft-teams-mcp",
|
|
3
3
|
"displayName": "Microsoft Teams",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.10.0",
|
|
5
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",
|
package/README.md
CHANGED
|
@@ -36,9 +36,10 @@ By default nothing here marks anything read. Reading a chat through this
|
|
|
36
36
|
server leaves your Teams unread badges exactly as they were — unless you ask
|
|
37
37
|
for it: `teams_mark_read`, or `mark_read: true` on `teams_list_messages`
|
|
38
38
|
/ `teams_list_unread_messages`, moves your read marker forward. The writes —
|
|
39
|
-
`teams_send_message`, `teams_react`, marking read,
|
|
39
|
+
`teams_send_message`, `teams_react`, marking read, renaming a group chat
|
|
40
40
|
or adding and removing its members (`teams_rename_chat`,
|
|
41
|
-
`teams_add_chat_members`, `teams_remove_chat_members`)
|
|
41
|
+
`teams_add_chat_members`, `teams_remove_chat_members`), and starting a new
|
|
42
|
+
one (`teams_create_group_chat`) — go through the same
|
|
42
43
|
chat-service API and change nothing until you confirm (see
|
|
43
44
|
[Writes](#writes)).
|
|
44
45
|
|
|
@@ -126,8 +127,8 @@ read only from the request header, never from page storage.
|
|
|
126
127
|
another capture for 10 minutes. `mode: "substrate"` fails instead;
|
|
127
128
|
`mode: "scan"` never touches Substrate.
|
|
128
129
|
|
|
129
|
-
- **It also finds people.** `teams_add_chat_members
|
|
130
|
-
`teams_remove_chat_members` use the same token to look a person up in your
|
|
130
|
+
- **It also finds people.** `teams_add_chat_members`,
|
|
131
|
+
`teams_remove_chat_members` and `teams_create_group_chat` use the same token to look a person up in your
|
|
131
132
|
organisation's directory (Substrate's people suggestions) when a name is not
|
|
132
133
|
in your chats, or when you pass an email address. A lookup is an explicit
|
|
133
134
|
request, so it always tries a fresh capture rather than honouring the
|
|
@@ -646,6 +647,23 @@ Everything is optional — by default the token is captured from your browser.
|
|
|
646
647
|
`not_member` and not written. Teams posts a notice in the chat for each
|
|
647
648
|
person removed, and they lose access to it. Each person is reported
|
|
648
649
|
`removed`, `not_member`, `unknown` or `failed`.
|
|
650
|
+
- `teams_create_group_chat` — start a new group chat with `people` (2–20,
|
|
651
|
+
named as for `teams_add_chat_members`, except that with no chat yet a name
|
|
652
|
+
is matched among the other person of each of your 1:1 chats only, then the
|
|
653
|
+
directory) and an optional `topic` (trimmed; empty or missing is an
|
|
654
|
+
untitled chat). You are always included — listing yourself is ignored, as
|
|
655
|
+
are duplicates — and fewer than two other people is refused: one other
|
|
656
|
+
person is a 1:1, which this tool does not create. Sent as one
|
|
657
|
+
`POST /threads` with everyone as a member (Teams makes every group-chat
|
|
658
|
+
member an Admin). Everyone added sees the new chat at once, and **it
|
|
659
|
+
cannot be deleted afterwards** — only left. No message is sent; post the
|
|
660
|
+
first one with `teams_send_message`. The preview shows the topic and
|
|
661
|
+
everyone with their `source` and, from the directory, `email`. The chat is
|
|
662
|
+
read back and the result is `created` with the new `conversation` (id,
|
|
663
|
+
title, kind `group`), the `members` and `verified` (everyone and the topic
|
|
664
|
+
shown). It is not idempotent: `status: "unknown"` means Teams did not
|
|
665
|
+
confirm the create — check `teams_list_conversations` before retrying,
|
|
666
|
+
since a blind retry makes a second chat.
|
|
649
667
|
|
|
650
668
|
`teams_list_messages` and `teams_list_unread_messages` also write when — and only
|
|
651
669
|
when — you pass `mark_read: true` (see above). Every other tool is
|
|
@@ -653,8 +671,8 @@ read-only, and nothing marks anything read unless you ask it to.
|
|
|
653
671
|
|
|
654
672
|
## Writes
|
|
655
673
|
|
|
656
|
-
A post, a reaction, a rename
|
|
657
|
-
in the conversation, and marking read clears your unread badges, so each
|
|
674
|
+
A post, a reaction, a rename, a membership change and a new group chat are
|
|
675
|
+
visible to everyone in the conversation, and marking read clears your unread badges, so each
|
|
658
676
|
write asks you first. A
|
|
659
677
|
client that can show a confirmation prompt (Claude Code) shows one. On a
|
|
660
678
|
client that cannot, the first call changes nothing and returns a
|
package/dist/bundle.js
CHANGED
|
@@ -38523,7 +38523,7 @@ var init_version = __esm({
|
|
|
38523
38523
|
"src/version.ts"() {
|
|
38524
38524
|
"use strict";
|
|
38525
38525
|
PACKAGE_NAME = "microsoft-teams-mcp";
|
|
38526
|
-
VERSION = "0.
|
|
38526
|
+
VERSION = "0.10.0";
|
|
38527
38527
|
}
|
|
38528
38528
|
});
|
|
38529
38529
|
|
|
@@ -50762,6 +50762,7 @@ function outcomeUnknown(method, e, hint) {
|
|
|
50762
50762
|
var SEND_OUTCOME_HINT = "The message may already have been posted \u2014 check the conversation (teams_list_messages) before retrying; do not resend blindly.";
|
|
50763
50763
|
var REACTION_OUTCOME_HINT = "The reaction change may already have been applied \u2014 check the message (teams_list_messages) before retrying.";
|
|
50764
50764
|
var THREAD_OUTCOME_HINT = "The change to the chat may already have been applied \u2014 check the chat (its name and members) before retrying.";
|
|
50765
|
+
var CREATE_OUTCOME_HINT = "A chat may already have been created \u2014 check teams_list_conversations before retrying; a blind retry would create a second chat (and a chat cannot be deleted).";
|
|
50765
50766
|
var HORIZON_OUTCOME_HINT = "The read marker may already have moved \u2014 check the conversation (teams_list_messages) before retrying; moving it again to the same message is harmless.";
|
|
50766
50767
|
var ChatServiceClient = class {
|
|
50767
50768
|
#baseUrl;
|
|
@@ -51019,6 +51020,55 @@ var ChatServiceClient = class {
|
|
|
51019
51020
|
async removeMember(id, mri) {
|
|
51020
51021
|
await this.#writeThread("DELETE", `${this.#threadUrl(id)}/members/${encodeURIComponent(mri)}`);
|
|
51021
51022
|
}
|
|
51023
|
+
/**
|
|
51024
|
+
* Start a group chat: `POST /threads` with every member as `Admin` (Teams
|
|
51025
|
+
* makes every group-chat member Admin) and `{ threadType: "chat" }` plus the
|
|
51026
|
+
* topic when there is one (verified live 2026-11-09: 201, `{}`, and the new
|
|
51027
|
+
* id in `Location`). The signed-in user is always the first member.
|
|
51028
|
+
*
|
|
51029
|
+
* Not idempotent: an answer lost after sending (a timeout, a dropped
|
|
51030
|
+
* connection, a 5xx) is a `WriteOutcomeUnknownError` — the chat may exist,
|
|
51031
|
+
* and a retry would make a second one. A success without a readable
|
|
51032
|
+
* `Location` is an error too: the chat was probably made, its id unknown.
|
|
51033
|
+
*/
|
|
51034
|
+
async createGroupChat(memberMris, topic) {
|
|
51035
|
+
this.#requireConfigured();
|
|
51036
|
+
const me = await this.meMri();
|
|
51037
|
+
const others = memberMris.filter((m) => m.toLowerCase() !== me.toLowerCase());
|
|
51038
|
+
const body = {
|
|
51039
|
+
members: [me, ...others].map((id2) => ({ id: id2, role: "Admin" })),
|
|
51040
|
+
properties: {
|
|
51041
|
+
threadType: "chat",
|
|
51042
|
+
...topic ? { topic } : {},
|
|
51043
|
+
fixedRoster: false,
|
|
51044
|
+
uniquerosterthread: false
|
|
51045
|
+
}
|
|
51046
|
+
};
|
|
51047
|
+
const { status, headers } = await this.#send(`${this.#baseUrl}/threads`, "text", void 0, {
|
|
51048
|
+
method: "POST",
|
|
51049
|
+
body,
|
|
51050
|
+
hint: CREATE_OUTCOME_HINT
|
|
51051
|
+
});
|
|
51052
|
+
this.#checkWriteStatus("POST", status, CREATE_OUTCOME_HINT);
|
|
51053
|
+
const raw = /\/threads\/([^/?#]+)\/?(?:[?#].*)?$/.exec(headers.get("location") ?? "")?.[1];
|
|
51054
|
+
let id;
|
|
51055
|
+
try {
|
|
51056
|
+
id = raw !== void 0 ? decodeURIComponent(raw) : void 0;
|
|
51057
|
+
} catch {
|
|
51058
|
+
id = void 0;
|
|
51059
|
+
}
|
|
51060
|
+
if (!id) {
|
|
51061
|
+
throw new McpToolError(
|
|
51062
|
+
`Teams answered HTTP ${status} to creating the group chat, so it was probably created, but its id was not returned.`,
|
|
51063
|
+
{
|
|
51064
|
+
status,
|
|
51065
|
+
kind: "http",
|
|
51066
|
+
hint: "Find the new chat in teams_list_conversations (it has no messages yet) before trying again \u2014 do not retry blindly."
|
|
51067
|
+
}
|
|
51068
|
+
);
|
|
51069
|
+
}
|
|
51070
|
+
return { id };
|
|
51071
|
+
}
|
|
51022
51072
|
#threadUrl(id) {
|
|
51023
51073
|
return `${this.#baseUrl}/threads/${encodeURIComponent(id)}`;
|
|
51024
51074
|
}
|
|
@@ -55443,6 +55493,7 @@ async function knownPeople(chatsvc, me, conversationId) {
|
|
|
55443
55493
|
}
|
|
55444
55494
|
} catch {
|
|
55445
55495
|
}
|
|
55496
|
+
if (conversationId === void 0) return [...byMri.values()];
|
|
55446
55497
|
try {
|
|
55447
55498
|
for (const [mri, name] of await recentSenders(chatsvc, conversationId)) add(mri, name);
|
|
55448
55499
|
} catch {
|
|
@@ -55524,7 +55575,7 @@ function pickByName(person, found) {
|
|
|
55524
55575
|
);
|
|
55525
55576
|
}
|
|
55526
55577
|
throw new McpToolError(`No one in your chats or your organisation's directory is called "${person}".`, {
|
|
55527
|
-
hint: `${PASS_ID} A name is matched among the other person of each of your 1:1 chats and
|
|
55578
|
+
hint: `${PASS_ID} A name is matched among the other person of each of your 1:1 chats and (for an existing chat) its recent senders, then searched in your organisation's directory.`
|
|
55528
55579
|
});
|
|
55529
55580
|
}
|
|
55530
55581
|
async function resolvePeople(inputs, known, directory) {
|
|
@@ -55918,6 +55969,7 @@ init_dist2();
|
|
|
55918
55969
|
var RENAME = "teams_rename_chat";
|
|
55919
55970
|
var ADD = "teams_add_chat_members";
|
|
55920
55971
|
var REMOVE = "teams_remove_chat_members";
|
|
55972
|
+
var CREATE = "teams_create_group_chat";
|
|
55921
55973
|
var MAX_PEOPLE = 20;
|
|
55922
55974
|
var KIND_LABELS = {
|
|
55923
55975
|
oneOnOne: "a 1:1 chat",
|
|
@@ -55928,10 +55980,16 @@ var KIND_LABELS = {
|
|
|
55928
55980
|
var conversationParam = external_exports.string().min(1).describe(
|
|
55929
55981
|
"The group chat: its id (from teams_list_conversations), or a case-insensitive substring of its title or an untitled chat's participant names."
|
|
55930
55982
|
);
|
|
55931
|
-
|
|
55932
|
-
`
|
|
55983
|
+
function peopleParamText(local) {
|
|
55984
|
+
return `each an MRI (8:orgid:\u2026), a bare Entra object id, an email address (looked up in your organisation's directory), or a display name ("Greg King" and "King, Greg" are the same) matched among ${local}, then \u2014 only if no one there matches \u2014 in the directory.`;
|
|
55985
|
+
}
|
|
55986
|
+
var peopleParam = external_exports.array(external_exports.string().trim().min(1)).min(1).max(MAX_PEOPLE).describe(`Who: ${peopleParamText("the other people of your 1:1 chats and recent senders in this chat")}`);
|
|
55987
|
+
function peopleSentence(local) {
|
|
55988
|
+
return `people are MRIs (8:orgid:\u2026), bare object ids, email addresses, or display names. A name is matched (ignoring case, in either "First Last" or "Last, First" order) among ${local} first; only when no one there matches is the organisation's directory searched, where the one person with exactly that name is taken (or the only suggestion, when the name is whole words of it). An email address is looked up in the directory and must be exactly one person's email or UPN. An ambiguous or unknown person refuses the whole call, listing candidates. The directory is searched with the same token as teams_search_messages: the first lookup may need the user to run any search in the Teams search box so it can be captured. `;
|
|
55989
|
+
}
|
|
55990
|
+
var PEOPLE_SENTENCE = peopleSentence(
|
|
55991
|
+
"the other person of each of the user's 1:1 chats and the chat's recent senders"
|
|
55933
55992
|
);
|
|
55934
|
-
var PEOPLE_SENTENCE = `people are MRIs (8:orgid:\u2026), bare object ids, email addresses, or display names. A name is matched (ignoring case, in either "First Last" or "Last, First" order) among the other person of each of the user's 1:1 chats and the chat's recent senders first; only when no one there matches is the organisation's directory searched, where the one person with exactly that name is taken (or the only suggestion, when the name is whole words of it). An email address is looked up in the directory and must be exactly one person's email or UPN. An ambiguous or unknown person refuses the whole call, listing candidates. The directory is searched with the same token as teams_search_messages: the first lookup may need the user to run any search in the Teams search box so it can be captured. `;
|
|
55935
55993
|
async function groupChat(chatsvc, conversation, me, doing) {
|
|
55936
55994
|
const target = await resolveTarget(chatsvc, conversation, me, `change`);
|
|
55937
55995
|
if (target.kind === "group") return target;
|
|
@@ -56228,6 +56286,102 @@ function registerGroupChatTools(server, { chatsvc, substrate }) {
|
|
|
56228
56286
|
}
|
|
56229
56287
|
}
|
|
56230
56288
|
);
|
|
56289
|
+
server.registerTool(
|
|
56290
|
+
CREATE,
|
|
56291
|
+
{
|
|
56292
|
+
title: "Create a Teams group chat",
|
|
56293
|
+
description: "Start a new group chat as the signed-in user with 2\u201320 other people, optionally named (topic). The user is always included (listing them is ignored), as are duplicates; fewer than two other people is refused \u2014 one other person is a 1:1, which this tool does not create. " + peopleSentence("the other person of each of the user's 1:1 chats") + 'Everyone added sees the chat at once in their chat list, and it cannot be deleted afterwards \u2014 only left. No message is sent: post the first one with teams_send_message, passing the new conversation id. Not idempotent: every confirmed call makes a NEW chat. The result has the new conversation (id, title, kind "group"), the members and whether reading the chat back showed them all and the topic (verified); status "unknown" means Teams did not confirm the create \u2014 a chat may exist anyway, so check teams_list_conversations and do NOT retry blindly (that would make a second chat). ' + CONFIRM_FLOW_SENTENCE + " The preview shows the topic and exactly who would be in the chat \u2014 each with their source (id, chat or directory) and, from the directory, their email \u2014 so the user can check it is the right people. " + CONFIRM_INJECTION_RULE + UNTRUSTED_DESCRIPTION_SUFFIX2,
|
|
56294
|
+
annotations: toolAnnotations({ readOnly: false, destructive: false, idempotent: false, openWorld: true }),
|
|
56295
|
+
_meta: workMeta("send", {
|
|
56296
|
+
aliases: ["create chat", "new group chat", "start a chat", "new chat", "group chat", "start group chat"]
|
|
56297
|
+
}),
|
|
56298
|
+
inputSchema: {
|
|
56299
|
+
people: external_exports.array(external_exports.string().trim().min(1)).min(2).max(MAX_PEOPLE).describe(
|
|
56300
|
+
`Who to start the chat with (2\u201320 others; you are added automatically): ` + peopleParamText("the other people of your 1:1 chats")
|
|
56301
|
+
),
|
|
56302
|
+
topic: external_exports.string().optional().describe("A name for the chat (surrounding spaces are trimmed). Omit or leave empty for an untitled chat."),
|
|
56303
|
+
confirmToken: confirmTokenParam
|
|
56304
|
+
}
|
|
56305
|
+
},
|
|
56306
|
+
async ({ people, topic: rawTopic, confirmToken }, ctx) => {
|
|
56307
|
+
try {
|
|
56308
|
+
const me = await chatsvc.meMri();
|
|
56309
|
+
const topic = rawTopic?.trim() || void 0;
|
|
56310
|
+
const others = (await resolveFor(chatsvc, substrate, me, void 0, people)).filter(
|
|
56311
|
+
(p) => p.mri.toLowerCase() !== me.toLowerCase()
|
|
56312
|
+
);
|
|
56313
|
+
if (others.length < 2) {
|
|
56314
|
+
throw new McpToolError(
|
|
56315
|
+
`A group chat needs at least two other people besides you; ${others.length === 1 ? `only ${JSON.stringify(others[0].person)} is` : "no one else is"} left once you and duplicates are dropped. One other person is a 1:1 chat, which this tool does not create.`,
|
|
56316
|
+
{
|
|
56317
|
+
hint: "Add at least one more person, or to talk to one person use your 1:1 chat with them (teams_send_message, conversation set to their name)."
|
|
56318
|
+
}
|
|
56319
|
+
);
|
|
56320
|
+
}
|
|
56321
|
+
const members2 = others.map(shown);
|
|
56322
|
+
const allMris = [me, ...others.map((p) => p.mri)];
|
|
56323
|
+
const count = `you and ${others.length} other people`;
|
|
56324
|
+
const gate = await confirmWrite(ctx, {
|
|
56325
|
+
tool: CREATE,
|
|
56326
|
+
action: "chat.create",
|
|
56327
|
+
message: "Review and confirm this new group chat before it is created \u2014 it cannot be deleted afterwards:",
|
|
56328
|
+
// The topic is the caller's own text: JSON-quoted all the same, so it reads as one value.
|
|
56329
|
+
summary: `Create ${topic !== void 0 ? `group chat ${JSON.stringify(topic)}` : "an untitled group chat"} with ${count}`,
|
|
56330
|
+
account: me,
|
|
56331
|
+
target: "new group chat",
|
|
56332
|
+
request: { method: "POST", path: "/threads", body: { members: allMris, ...topic !== void 0 ? { topic } : {} } },
|
|
56333
|
+
// The resolved names are set by other people, so they are fenced.
|
|
56334
|
+
preview: {
|
|
56335
|
+
topic: topic ?? "(untitled)",
|
|
56336
|
+
members: untrustedField(members2),
|
|
56337
|
+
note: "Creates a NEW group chat with everyone as a member (Teams makes each one an Admin). Everyone added sees it at once; it cannot be deleted afterwards, only left. No message is sent."
|
|
56338
|
+
},
|
|
56339
|
+
confirmToken
|
|
56340
|
+
});
|
|
56341
|
+
if (gate) return gate;
|
|
56342
|
+
let id;
|
|
56343
|
+
try {
|
|
56344
|
+
({ id } = await chatsvc.createGroupChat(others.map((p) => p.mri), topic));
|
|
56345
|
+
} catch (e) {
|
|
56346
|
+
if (!(e instanceof WriteOutcomeUnknownError)) throw e;
|
|
56347
|
+
return untrustedResult2({
|
|
56348
|
+
status: "unknown",
|
|
56349
|
+
...topic !== void 0 ? { topic } : {},
|
|
56350
|
+
members: members2,
|
|
56351
|
+
warning: `Teams did not confirm creating the chat (${unconfirmedWhy2(e)}), so it may or may not exist. Check teams_list_conversations for a new group chat with these people (no messages yet) before doing anything else \u2014 do NOT retry blindly: if it was created, retrying makes a second chat, and chats cannot be deleted.`
|
|
56352
|
+
});
|
|
56353
|
+
}
|
|
56354
|
+
let warning;
|
|
56355
|
+
let verified;
|
|
56356
|
+
try {
|
|
56357
|
+
const thread = await chatsvc.getThread(id);
|
|
56358
|
+
const present = memberSet(thread);
|
|
56359
|
+
const missing = allMris.filter((m) => !present.has(m.toLowerCase()));
|
|
56360
|
+
const shownTopic = thread.properties?.topic || void 0;
|
|
56361
|
+
const notes = [];
|
|
56362
|
+
if (missing.length > 0) notes.push(`did not show ${missing.join(", ")} as a member`);
|
|
56363
|
+
if (shownTopic !== topic) notes.push(`showed the topic as ${JSON.stringify(shownTopic ?? "")}`);
|
|
56364
|
+
verified = notes.length === 0;
|
|
56365
|
+
if (!verified) {
|
|
56366
|
+
warning = `Teams created the chat, but reading it back ${notes.join(" and ")} \u2014 check it in Teams (do not create it again).`;
|
|
56367
|
+
}
|
|
56368
|
+
} catch {
|
|
56369
|
+
verified = null;
|
|
56370
|
+
warning = "Teams created the chat, but reading the chat back failed \u2014 check it in teams_list_conversations (do not create it again).";
|
|
56371
|
+
}
|
|
56372
|
+
return untrustedResult2({
|
|
56373
|
+
status: "created",
|
|
56374
|
+
conversation: { id, title: topic ?? UNTITLED_GROUP_TITLE, kind: "group" },
|
|
56375
|
+
...topic !== void 0 ? { topic } : {},
|
|
56376
|
+
members: members2,
|
|
56377
|
+
verified,
|
|
56378
|
+
...warning !== void 0 ? { warning } : {}
|
|
56379
|
+
});
|
|
56380
|
+
} catch (err) {
|
|
56381
|
+
throw wrapApiError(err, "create the group chat");
|
|
56382
|
+
}
|
|
56383
|
+
}
|
|
56384
|
+
);
|
|
56231
56385
|
}
|
|
56232
56386
|
function orderAs(people, results) {
|
|
56233
56387
|
return people.map((p) => results.find((r) => r.mri === p.mri));
|
package/dist/chatsvc.js
CHANGED
|
@@ -109,6 +109,8 @@ function outcomeUnknown(method, e, hint) {
|
|
|
109
109
|
const SEND_OUTCOME_HINT = 'The message may already have been posted — check the conversation (teams_list_messages) before retrying; do not resend blindly.';
|
|
110
110
|
const REACTION_OUTCOME_HINT = 'The reaction change may already have been applied — check the message (teams_list_messages) before retrying.';
|
|
111
111
|
const THREAD_OUTCOME_HINT = 'The change to the chat may already have been applied — check the chat (its name and members) before retrying.';
|
|
112
|
+
const CREATE_OUTCOME_HINT = 'A chat may already have been created — check teams_list_conversations before retrying; a blind retry ' +
|
|
113
|
+
'would create a second chat (and a chat cannot be deleted).';
|
|
112
114
|
const HORIZON_OUTCOME_HINT = 'The read marker may already have moved — check the conversation (teams_list_messages) before retrying; ' +
|
|
113
115
|
'moving it again to the same message is harmless.';
|
|
114
116
|
export class ChatServiceClient {
|
|
@@ -393,6 +395,53 @@ export class ChatServiceClient {
|
|
|
393
395
|
async removeMember(id, mri) {
|
|
394
396
|
await this.#writeThread('DELETE', `${this.#threadUrl(id)}/members/${encodeURIComponent(mri)}`);
|
|
395
397
|
}
|
|
398
|
+
/**
|
|
399
|
+
* Start a group chat: `POST /threads` with every member as `Admin` (Teams
|
|
400
|
+
* makes every group-chat member Admin) and `{ threadType: "chat" }` plus the
|
|
401
|
+
* topic when there is one (verified live 2026-11-09: 201, `{}`, and the new
|
|
402
|
+
* id in `Location`). The signed-in user is always the first member.
|
|
403
|
+
*
|
|
404
|
+
* Not idempotent: an answer lost after sending (a timeout, a dropped
|
|
405
|
+
* connection, a 5xx) is a `WriteOutcomeUnknownError` — the chat may exist,
|
|
406
|
+
* and a retry would make a second one. A success without a readable
|
|
407
|
+
* `Location` is an error too: the chat was probably made, its id unknown.
|
|
408
|
+
*/
|
|
409
|
+
async createGroupChat(memberMris, topic) {
|
|
410
|
+
this.#requireConfigured();
|
|
411
|
+
const me = await this.meMri();
|
|
412
|
+
const others = memberMris.filter((m) => m.toLowerCase() !== me.toLowerCase());
|
|
413
|
+
const body = {
|
|
414
|
+
members: [me, ...others].map((id) => ({ id, role: 'Admin' })),
|
|
415
|
+
properties: {
|
|
416
|
+
threadType: 'chat',
|
|
417
|
+
...(topic ? { topic } : {}),
|
|
418
|
+
fixedRoster: false,
|
|
419
|
+
uniquerosterthread: false,
|
|
420
|
+
},
|
|
421
|
+
};
|
|
422
|
+
const { status, headers } = await this.#send(`${this.#baseUrl}/threads`, 'text', undefined, {
|
|
423
|
+
method: 'POST',
|
|
424
|
+
body,
|
|
425
|
+
hint: CREATE_OUTCOME_HINT,
|
|
426
|
+
});
|
|
427
|
+
this.#checkWriteStatus('POST', status, CREATE_OUTCOME_HINT);
|
|
428
|
+
const raw = /\/threads\/([^/?#]+)\/?(?:[?#].*)?$/.exec(headers.get('location') ?? '')?.[1];
|
|
429
|
+
let id;
|
|
430
|
+
try {
|
|
431
|
+
id = raw !== undefined ? decodeURIComponent(raw) : undefined;
|
|
432
|
+
}
|
|
433
|
+
catch {
|
|
434
|
+
id = undefined;
|
|
435
|
+
}
|
|
436
|
+
if (!id) {
|
|
437
|
+
throw new McpToolError(`Teams answered HTTP ${status} to creating the group chat, so it was probably created, but its id was not returned.`, {
|
|
438
|
+
status,
|
|
439
|
+
kind: 'http',
|
|
440
|
+
hint: 'Find the new chat in teams_list_conversations (it has no messages yet) before trying again — do not retry blindly.',
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
return { id };
|
|
444
|
+
}
|
|
396
445
|
#threadUrl(id) {
|
|
397
446
|
return `${this.#baseUrl}/threads/${encodeURIComponent(id)}`;
|
|
398
447
|
}
|
package/dist/substrate.js
CHANGED
|
@@ -48,7 +48,8 @@
|
|
|
48
48
|
* - A bad token is a 401.
|
|
49
49
|
*
|
|
50
50
|
* People lookup (`suggestPeople`, the directory fallback of
|
|
51
|
-
* `teams_add_chat_members` / `teams_remove_chat_members`
|
|
51
|
+
* `teams_add_chat_members` / `teams_remove_chat_members` /
|
|
52
|
+
* `teams_create_group_chat`), verified live
|
|
52
53
|
* 2026-11-09 with the SAME captured token — no new token or bridge scope:
|
|
53
54
|
*
|
|
54
55
|
* POST https://substrate.office.com/search/api/v1/suggestions?scenario=powerbar
|
package/dist/tools/group-chat.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { CONFIRM_FLOW_SENTENCE, CONFIRM_INJECTION_RULE, confirmTokenParam, confirmWrite, McpToolError, toolAnnotations, WriteOutcomeUnknownError, writeOutcomeStatus, } from '@chrischall/mcp-utils';
|
|
3
|
+
import { UNTITLED_GROUP_TITLE } from '../model.js';
|
|
3
4
|
import { wrapApiError } from './errors.js';
|
|
4
5
|
import { workMeta } from './hints.js';
|
|
5
6
|
import { knownPeople, resolvePeople } from './people.js';
|
|
@@ -8,6 +9,7 @@ import { untrustedField, untrustedResult, UNTRUSTED_DESCRIPTION_SUFFIX } from '.
|
|
|
8
9
|
const RENAME = 'teams_rename_chat';
|
|
9
10
|
const ADD = 'teams_add_chat_members';
|
|
10
11
|
const REMOVE = 'teams_remove_chat_members';
|
|
12
|
+
const CREATE = 'teams_create_group_chat';
|
|
11
13
|
/** Most people one call adds or removes. */
|
|
12
14
|
const MAX_PEOPLE = 20;
|
|
13
15
|
const KIND_LABELS = {
|
|
@@ -21,21 +23,28 @@ const conversationParam = z
|
|
|
21
23
|
.min(1)
|
|
22
24
|
.describe('The group chat: its id (from teams_list_conversations), or a case-insensitive substring of its title or ' +
|
|
23
25
|
"an untitled chat's participant names.");
|
|
26
|
+
/** How a person may be named, for a `people` parameter; `local` says where a name is matched before the directory. */
|
|
27
|
+
function peopleParamText(local) {
|
|
28
|
+
return ('each an MRI (8:orgid:…), a bare Entra object id, an email address (looked up in your organisation\'s ' +
|
|
29
|
+
'directory), or a display name ("Greg King" and "King, Greg" are the same) matched among ' +
|
|
30
|
+
`${local}, then — only if no one there matches — in the directory.`);
|
|
31
|
+
}
|
|
24
32
|
const peopleParam = z
|
|
25
33
|
.array(z.string().trim().min(1))
|
|
26
34
|
.min(1)
|
|
27
35
|
.max(MAX_PEOPLE)
|
|
28
|
-
.describe(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
.describe(`Who: ${peopleParamText('the other people of your 1:1 chats and recent senders in this chat')}`);
|
|
37
|
+
/** The description's sentence on naming people; `local` says where a name is matched before the directory. */
|
|
38
|
+
function peopleSentence(local) {
|
|
39
|
+
return ('people are MRIs (8:orgid:…), bare object ids, email addresses, or display names. A name is matched ' +
|
|
40
|
+
`(ignoring case, in either "First Last" or "Last, First" order) among ${local} first; only when no one ` +
|
|
41
|
+
"there matches is the organisation's directory searched, where the one person with exactly that name is " +
|
|
42
|
+
'taken (or the only suggestion, when the name is whole words of it). An email address is looked up in the ' +
|
|
43
|
+
"directory and must be exactly one person's email or UPN. An ambiguous or unknown person refuses the whole " +
|
|
44
|
+
'call, listing candidates. The directory is searched with the same token as teams_search_messages: the ' +
|
|
45
|
+
'first lookup may need the user to run any search in the Teams search box so it can be captured. ');
|
|
46
|
+
}
|
|
47
|
+
const PEOPLE_SENTENCE = peopleSentence("the other person of each of the user's 1:1 chats and the chat's recent senders");
|
|
39
48
|
/** The conversation, refused unless it is a group chat. `doing` words the refusal ("renamed"). */
|
|
40
49
|
async function groupChat(chatsvc, conversation, me, doing) {
|
|
41
50
|
const target = await resolveTarget(chatsvc, conversation, me, `change`);
|
|
@@ -67,7 +76,11 @@ function shown(p) {
|
|
|
67
76
|
...(p.email !== undefined ? { email: p.email } : {}),
|
|
68
77
|
};
|
|
69
78
|
}
|
|
70
|
-
/**
|
|
79
|
+
/**
|
|
80
|
+
* People resolved and de-duplicated by MRI (the first naming of each kept).
|
|
81
|
+
* Names are matched among the user's 1:1s and, given `conversationId`, that
|
|
82
|
+
* chat's recent senders; with none (a chat not yet made), the 1:1s only.
|
|
83
|
+
*/
|
|
71
84
|
async function resolveFor(chatsvc, directory, me, conversationId, people) {
|
|
72
85
|
const known = await knownPeople(chatsvc, me, conversationId);
|
|
73
86
|
const seen = new Set();
|
|
@@ -378,6 +391,125 @@ export function registerGroupChatTools(server, { chatsvc, substrate }) {
|
|
|
378
391
|
throw wrapApiError(err, 'remove people from the chat');
|
|
379
392
|
}
|
|
380
393
|
});
|
|
394
|
+
server.registerTool(CREATE, {
|
|
395
|
+
title: 'Create a Teams group chat',
|
|
396
|
+
description: 'Start a new group chat as the signed-in user with 2–20 other people, optionally named (topic). The user ' +
|
|
397
|
+
'is always included (listing them is ignored), as are duplicates; fewer than two other people is refused — ' +
|
|
398
|
+
'one other person is a 1:1, which this tool does not create. ' +
|
|
399
|
+
peopleSentence("the other person of each of the user's 1:1 chats") +
|
|
400
|
+
'Everyone added sees the chat at once in their chat list, and it cannot be deleted afterwards — only ' +
|
|
401
|
+
'left. No message is sent: post the first one with teams_send_message, passing the new conversation id. ' +
|
|
402
|
+
'Not idempotent: every confirmed call makes a NEW chat. The result has the new conversation (id, title, ' +
|
|
403
|
+
'kind "group"), the members and whether reading the chat back showed them all and the topic (verified); ' +
|
|
404
|
+
'status "unknown" means Teams did not confirm the create — a chat may exist anyway, so check ' +
|
|
405
|
+
'teams_list_conversations and do NOT retry blindly (that would make a second chat). ' +
|
|
406
|
+
CONFIRM_FLOW_SENTENCE +
|
|
407
|
+
' The preview shows the topic and exactly who would be in the chat — each with their source (id, chat or ' +
|
|
408
|
+
'directory) and, from the directory, their email — so the user can check it is the right people. ' +
|
|
409
|
+
CONFIRM_INJECTION_RULE +
|
|
410
|
+
UNTRUSTED_DESCRIPTION_SUFFIX,
|
|
411
|
+
annotations: toolAnnotations({ readOnly: false, destructive: false, idempotent: false, openWorld: true }),
|
|
412
|
+
_meta: workMeta('send', {
|
|
413
|
+
aliases: ['create chat', 'new group chat', 'start a chat', 'new chat', 'group chat', 'start group chat'],
|
|
414
|
+
}),
|
|
415
|
+
inputSchema: {
|
|
416
|
+
people: z
|
|
417
|
+
.array(z.string().trim().min(1))
|
|
418
|
+
.min(2)
|
|
419
|
+
.max(MAX_PEOPLE)
|
|
420
|
+
.describe(`Who to start the chat with (2–20 others; you are added automatically): ` +
|
|
421
|
+
peopleParamText('the other people of your 1:1 chats')),
|
|
422
|
+
topic: z
|
|
423
|
+
.string()
|
|
424
|
+
.optional()
|
|
425
|
+
.describe('A name for the chat (surrounding spaces are trimmed). Omit or leave empty for an untitled chat.'),
|
|
426
|
+
confirmToken: confirmTokenParam,
|
|
427
|
+
},
|
|
428
|
+
}, async ({ people, topic: rawTopic, confirmToken }, ctx) => {
|
|
429
|
+
try {
|
|
430
|
+
const me = await chatsvc.meMri();
|
|
431
|
+
const topic = rawTopic?.trim() || undefined;
|
|
432
|
+
const others = (await resolveFor(chatsvc, substrate, me, undefined, people)).filter((p) => p.mri.toLowerCase() !== me.toLowerCase());
|
|
433
|
+
if (others.length < 2) {
|
|
434
|
+
throw new McpToolError(`A group chat needs at least two other people besides you; ${others.length === 1 ? `only ${JSON.stringify(others[0].person)} is` : 'no one else is'} left once you and duplicates are dropped. One other person is a 1:1 chat, which this tool does not create.`, {
|
|
435
|
+
hint: 'Add at least one more person, or to talk to one person use your 1:1 chat with them (teams_send_message, ' +
|
|
436
|
+
'conversation set to their name).',
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
const members = others.map(shown);
|
|
440
|
+
const allMris = [me, ...others.map((p) => p.mri)];
|
|
441
|
+
const count = `you and ${others.length} other people`;
|
|
442
|
+
const gate = await confirmWrite(ctx, {
|
|
443
|
+
tool: CREATE,
|
|
444
|
+
action: 'chat.create',
|
|
445
|
+
message: 'Review and confirm this new group chat before it is created — it cannot be deleted afterwards:',
|
|
446
|
+
// The topic is the caller's own text: JSON-quoted all the same, so it reads as one value.
|
|
447
|
+
summary: `Create ${topic !== undefined ? `group chat ${JSON.stringify(topic)}` : 'an untitled group chat'} with ${count}`,
|
|
448
|
+
account: me,
|
|
449
|
+
target: 'new group chat',
|
|
450
|
+
request: { method: 'POST', path: '/threads', body: { members: allMris, ...(topic !== undefined ? { topic } : {}) } },
|
|
451
|
+
// The resolved names are set by other people, so they are fenced.
|
|
452
|
+
preview: {
|
|
453
|
+
topic: topic ?? '(untitled)',
|
|
454
|
+
members: untrustedField(members),
|
|
455
|
+
note: 'Creates a NEW group chat with everyone as a member (Teams makes each one an Admin). Everyone added ' +
|
|
456
|
+
'sees it at once; it cannot be deleted afterwards, only left. No message is sent.',
|
|
457
|
+
},
|
|
458
|
+
confirmToken,
|
|
459
|
+
});
|
|
460
|
+
if (gate)
|
|
461
|
+
return gate;
|
|
462
|
+
let id;
|
|
463
|
+
try {
|
|
464
|
+
({ id } = await chatsvc.createGroupChat(others.map((p) => p.mri), topic));
|
|
465
|
+
}
|
|
466
|
+
catch (e) {
|
|
467
|
+
if (!(e instanceof WriteOutcomeUnknownError))
|
|
468
|
+
throw e;
|
|
469
|
+
return untrustedResult({
|
|
470
|
+
status: 'unknown',
|
|
471
|
+
...(topic !== undefined ? { topic } : {}),
|
|
472
|
+
members,
|
|
473
|
+
warning: `Teams did not confirm creating the chat (${unconfirmedWhy(e)}), so it may or may not exist. Check ` +
|
|
474
|
+
'teams_list_conversations for a new group chat with these people (no messages yet) before doing ' +
|
|
475
|
+
'anything else — do NOT retry blindly: if it was created, retrying makes a second chat, and chats ' +
|
|
476
|
+
'cannot be deleted.',
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
let warning;
|
|
480
|
+
let verified;
|
|
481
|
+
try {
|
|
482
|
+
const thread = await chatsvc.getThread(id);
|
|
483
|
+
const present = memberSet(thread);
|
|
484
|
+
const missing = allMris.filter((m) => !present.has(m.toLowerCase()));
|
|
485
|
+
const shownTopic = thread.properties?.topic || undefined;
|
|
486
|
+
const notes = [];
|
|
487
|
+
if (missing.length > 0)
|
|
488
|
+
notes.push(`did not show ${missing.join(', ')} as a member`);
|
|
489
|
+
if (shownTopic !== topic)
|
|
490
|
+
notes.push(`showed the topic as ${JSON.stringify(shownTopic ?? '')}`);
|
|
491
|
+
verified = notes.length === 0;
|
|
492
|
+
if (!verified) {
|
|
493
|
+
warning = `Teams created the chat, but reading it back ${notes.join(' and ')} — check it in Teams (do not create it again).`;
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
catch {
|
|
497
|
+
verified = null;
|
|
498
|
+
warning = 'Teams created the chat, but reading the chat back failed — check it in teams_list_conversations (do not create it again).';
|
|
499
|
+
}
|
|
500
|
+
return untrustedResult({
|
|
501
|
+
status: 'created',
|
|
502
|
+
conversation: { id, title: topic ?? UNTITLED_GROUP_TITLE, kind: 'group' },
|
|
503
|
+
...(topic !== undefined ? { topic } : {}),
|
|
504
|
+
members,
|
|
505
|
+
verified,
|
|
506
|
+
...(warning !== undefined ? { warning } : {}),
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
catch (err) {
|
|
510
|
+
throw wrapApiError(err, 'create the group chat');
|
|
511
|
+
}
|
|
512
|
+
});
|
|
381
513
|
}
|
|
382
514
|
/** `results` in the order the people were asked for. */
|
|
383
515
|
function orderAs(people, results) {
|
package/dist/tools/people.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
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
|
|
3
|
+
* (`teams_add_chat_members`, `teams_remove_chat_members`,
|
|
4
|
+
* `teams_create_group_chat`) and a message's
|
|
4
5
|
* @mentions (`teams_send_message`).
|
|
5
6
|
*
|
|
6
7
|
* A person is, in this order:
|
|
@@ -68,7 +69,8 @@ export async function recentSenders(chatsvc, conversationId) {
|
|
|
68
69
|
/**
|
|
69
70
|
* Everyone this MCP can put a name to for `conversationId`: the other person
|
|
70
71
|
* of every 1:1 the user has (as that 1:1 is titled), then the chat's recent
|
|
71
|
-
* senders.
|
|
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
|
|
72
74
|
* throws — a failed read just knows fewer people.
|
|
73
75
|
*/
|
|
74
76
|
export async function knownPeople(chatsvc, me, conversationId) {
|
|
@@ -91,6 +93,8 @@ export async function knownPeople(chatsvc, me, conversationId) {
|
|
|
91
93
|
catch {
|
|
92
94
|
// No 1:1 names; the chat's own senders may still do.
|
|
93
95
|
}
|
|
96
|
+
if (conversationId === undefined)
|
|
97
|
+
return [...byMri.values()];
|
|
94
98
|
try {
|
|
95
99
|
for (const [mri, name] of await recentSenders(chatsvc, conversationId))
|
|
96
100
|
add(mri, name);
|
|
@@ -187,8 +191,8 @@ function pickByName(person, found) {
|
|
|
187
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:…).' });
|
|
188
192
|
}
|
|
189
193
|
throw new McpToolError(`No one in your chats or your organisation's directory is called "${person}".`, {
|
|
190
|
-
hint: `${PASS_ID} A name is matched among the other person of each of your 1:1 chats and
|
|
191
|
-
"senders, then searched in your organisation's directory.",
|
|
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.",
|
|
192
196
|
});
|
|
193
197
|
}
|
|
194
198
|
/**
|
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, teams_rename_chat, teams_add_chat_members, teams_remove_chat_members 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
|