@chrischall/microsoft-teams-mcp 0.6.2 → 0.7.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 +126 -66
- package/dist/bundle.js +1828 -282
- package/dist/chatsvc.js +5 -3
- package/dist/index.js +2 -0
- package/dist/tools/activity.js +34 -4
- package/dist/tools/attachment.js +24 -11
- package/dist/tools/changes.js +10 -9
- package/dist/tools/channels.js +2 -2
- package/dist/tools/chat-search.js +1 -1
- package/dist/tools/chat.js +3 -3
- package/dist/tools/conversation.js +17 -12
- package/dist/tools/cursor.js +6 -6
- package/dist/tools/export-attachments.js +114 -0
- package/dist/tools/export-format.js +101 -0
- package/dist/tools/export.js +550 -0
- package/dist/tools/format.js +3 -3
- package/dist/tools/from.js +1 -1
- package/dist/tools/limit.js +1 -1
- package/dist/tools/listing.js +9 -8
- package/dist/tools/markread.js +12 -6
- package/dist/tools/react.js +8 -8
- package/dist/tools/search.js +5 -4
- package/dist/tools/send.js +7 -7
- package/dist/tools/titles.js +103 -20
- package/dist/tools/unread.js +7 -6
- package/dist/version.js +1 -1
- package/mint.yaml +18 -0
- package/package.json +6 -2
- package/server.json +9 -2
package/dist/tools/limit.js
CHANGED
|
@@ -55,7 +55,7 @@ export function filterSince(rows, since) {
|
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
57
|
/**
|
|
58
|
-
* The `stopAt` behind `
|
|
58
|
+
* The `stopAt` behind `teams_list_messages` and `teams_list_unread_messages`. It
|
|
59
59
|
* sees each message once, newest first, so it can count: the first wanted
|
|
60
60
|
* message past `limit` is the boundary, and its existence is what says the
|
|
61
61
|
* result was truncated. `horizon` (when given) ends the read at the first
|
package/dist/tools/listing.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The conversation listing shared by `
|
|
3
|
-
* `
|
|
2
|
+
* The conversation listing shared by `teams_list_conversations` and
|
|
3
|
+
* `teams_list_channels`: one `listConversations` call, normalised
|
|
4
4
|
* against the signed-in user, then filtered by kind, unread state and query.
|
|
5
5
|
* With `unread_only`, the listing's unread flag only nominates candidates; each
|
|
6
6
|
* is confirmed by reading past its horizon (`confirm.ts`).
|
|
@@ -9,7 +9,7 @@ import { z } from 'zod';
|
|
|
9
9
|
import { confirmedSummary, confirmUnreadCandidates, olderUnreadArg, olderUnreadConversations, olderUnreadReport, sinceCutoff, sinceDaysArg, } from './confirm.js';
|
|
10
10
|
import { wrapApiError } from './errors.js';
|
|
11
11
|
import { searchRecentMessages } from './chat-search.js';
|
|
12
|
-
import { enrichTitles } from './titles.js';
|
|
12
|
+
import { enrichTitles, participantsOf } from './titles.js';
|
|
13
13
|
import { conversationSummary, matchConversations, SELF_CHAT, SELF_CHAT_ALIASES, } from '../model.js';
|
|
14
14
|
/**
|
|
15
15
|
* Whether a conversation's last activity falls in `[since, until]` (either
|
|
@@ -38,7 +38,7 @@ export const unreadOnlyArg = z
|
|
|
38
38
|
export const UNREAD_HINT_DESCRIPTION = 'Without unread_only, unread is only a hint from the listing (unread_confirmed: false): it can ' +
|
|
39
39
|
'flag a conversation whose only news is a call recording or other system event. For an exact ' +
|
|
40
40
|
'answer use unread_only (confirmed rows carry unread_confirmed: true and unread_count) or ' +
|
|
41
|
-
'
|
|
41
|
+
'teams_list_unread_messages.';
|
|
42
42
|
/** Real unread messages counted per candidate before unread_count is reported as a lower bound. */
|
|
43
43
|
const CONFIRM_LIMIT = 50;
|
|
44
44
|
/** Raw messages read per candidate — one page; the horizon is usually much nearer. */
|
|
@@ -68,9 +68,10 @@ export const MATCH_REASON_DESCRIPTION = 'With a query, each row carries match_re
|
|
|
68
68
|
'"participant" (an untitled chat\'s participant) or "message" (what was said, not what the ' +
|
|
69
69
|
'conversation is called) that applies.';
|
|
70
70
|
/** Description text on how an untitled group chat or 1:1 is titled. */
|
|
71
|
-
export const GROUP_TITLE_DESCRIPTION = 'A group chat with no topic is titled "Group chat: " and
|
|
72
|
-
'than the user,
|
|
73
|
-
'
|
|
71
|
+
export const GROUP_TITLE_DESCRIPTION = 'A group chat with no topic is titled "Group chat: " and the first three of its recent senders other ' +
|
|
72
|
+
'than the user, sorted by name ("; " between names, "+N" for more) — so it does not change when a ' +
|
|
73
|
+
'different person posts last — and carries every such recent sender, in that order, as participants; ' +
|
|
74
|
+
'it is "(untitled group chat)" when no one else wrote recently. ' +
|
|
74
75
|
'A 1:1 is titled by the other person, who is its one participant; it is "(1:1 chat)" when they ' +
|
|
75
76
|
'wrote nothing recently.';
|
|
76
77
|
/**
|
|
@@ -123,7 +124,7 @@ export async function listSummaries(chatsvc, filter) {
|
|
|
123
124
|
});
|
|
124
125
|
const errors = (titled) => outcome.failed.length > 0
|
|
125
126
|
? outcome.failed.map((f, i) => ({
|
|
126
|
-
conversation: { id: f.summary.id, title: titled[i].title },
|
|
127
|
+
conversation: { id: f.summary.id, title: titled[i].title, ...participantsOf(titled[i]) },
|
|
127
128
|
error: wrapApiError(f.error, 'confirm this conversation is unread').message,
|
|
128
129
|
}))
|
|
129
130
|
: undefined;
|
package/dist/tools/markread.js
CHANGED
|
@@ -90,6 +90,7 @@ export async function confirmMarks(ctx, opts) {
|
|
|
90
90
|
id: p.summary.id,
|
|
91
91
|
title: p.summary.title,
|
|
92
92
|
kind: p.summary.kind,
|
|
93
|
+
...(p.summary.participants !== undefined ? { participants: p.summary.participants } : {}),
|
|
93
94
|
previous_horizon_message_id: p.previous,
|
|
94
95
|
up_to_message_id: p.target,
|
|
95
96
|
}))),
|
|
@@ -130,13 +131,13 @@ export function registerMarkReadTools(server, { chatsvc }) {
|
|
|
130
131
|
server.registerTool(TOOL, {
|
|
131
132
|
title: 'Mark a Teams conversation read',
|
|
132
133
|
description: 'Mark a chat or channel read in Teams, clearing its unread badge: moves the signed-in user\'s read ' +
|
|
133
|
-
'marker up to up_to_message_id (from
|
|
134
|
-
'in the conversation. conversation is an id or name as for
|
|
134
|
+
'marker up to up_to_message_id (from teams_list_messages), or by default up to the newest message ' +
|
|
135
|
+
'in the conversation. conversation is an id or name as for teams_list_messages; ' +
|
|
135
136
|
`"${SELF_CHAT}" (or "notes" / "self") is the user's own notes self-chat — use it to try this tool. ` +
|
|
136
137
|
'The marker never moves backwards: when it is already at or past the target, nothing is written and ' +
|
|
137
138
|
'status is "already_read". Returns the conversation, previous_horizon_message_id (null if it was never ' +
|
|
138
139
|
'opened) and new_horizon_message_id; status "unknown" means Teams did not confirm the move — retrying is ' +
|
|
139
|
-
'harmless.
|
|
140
|
+
'harmless. teams_list_messages and teams_list_unread_messages can do the same after a read with mark_read. ' +
|
|
140
141
|
CONFIRM_FLOW_SENTENCE +
|
|
141
142
|
' The preview shows the conversation, the message the marker moves to and where it was. ' +
|
|
142
143
|
CONFIRM_INJECTION_RULE +
|
|
@@ -152,7 +153,7 @@ export function registerMarkReadTools(server, { chatsvc }) {
|
|
|
152
153
|
.string()
|
|
153
154
|
.min(1)
|
|
154
155
|
.optional()
|
|
155
|
-
.describe('Mark read up to and including this message, as
|
|
156
|
+
.describe('Mark read up to and including this message, as teams_list_messages lists it (default: the ' +
|
|
156
157
|
'newest message in the conversation). Messages after it stay unread.'),
|
|
157
158
|
confirmToken: confirmTokenParam,
|
|
158
159
|
},
|
|
@@ -169,7 +170,7 @@ export function registerMarkReadTools(server, { chatsvc }) {
|
|
|
169
170
|
target = await chatsvc.getMessage(summary.id, up_to_message_id);
|
|
170
171
|
if (target === undefined) {
|
|
171
172
|
throw new McpToolError(`There is no message ${up_to_message_id} in this conversation to mark read up to.`, {
|
|
172
|
-
hint: 'Take message ids from
|
|
173
|
+
hint: 'Take message ids from teams_list_messages, or leave up_to_message_id out to mark it all read.',
|
|
173
174
|
});
|
|
174
175
|
}
|
|
175
176
|
}
|
|
@@ -201,7 +202,12 @@ export function registerMarkReadTools(server, { chatsvc }) {
|
|
|
201
202
|
// The client time in the body is minted when the marker moves, so it is not bound.
|
|
202
203
|
request: { method: 'PUT', path: horizonPath(summary.id) },
|
|
203
204
|
preview: {
|
|
204
|
-
conversation: untrustedField({
|
|
205
|
+
conversation: untrustedField({
|
|
206
|
+
id: summary.id,
|
|
207
|
+
title: summary.title,
|
|
208
|
+
kind: summary.kind,
|
|
209
|
+
...(summary.participants !== undefined ? { participants: summary.participants } : {}),
|
|
210
|
+
}),
|
|
205
211
|
up_to_message: untrustedField({
|
|
206
212
|
id: to,
|
|
207
213
|
sender: target.imdisplayname?.trim() || senderMri(target.from) || 'unknown',
|
package/dist/tools/react.js
CHANGED
|
@@ -77,8 +77,8 @@ export function registerReactTools(server, { chatsvc }) {
|
|
|
77
77
|
server.registerTool(TOOL, {
|
|
78
78
|
title: 'React to a Teams message',
|
|
79
79
|
description: 'Add (or, with remove: true, withdraw) the signed-in user\'s reaction on a message in any chat or ' +
|
|
80
|
-
'channel. conversation is an id or name as for
|
|
81
|
-
'
|
|
80
|
+
'channel. conversation is an id or name as for teams_list_messages; message_id comes from ' +
|
|
81
|
+
'teams_list_messages. reaction is an emoji or name — thumbsup/👍/like, heart/❤️, laugh/😆, ' +
|
|
82
82
|
`surprised/😮, sad/😢, angry/😡, checkmark/✅ — or any raw Teams reaction key (e.g. fire, ` +
|
|
83
83
|
'1f389_partypopper); an emoji without a known key is refused with the rule for spelling its key. ' +
|
|
84
84
|
`conversation "${SELF_CHAT}" (or "notes" / "self") is the user's own notes self-chat — use it to try this tool. Everyone ` +
|
|
@@ -96,7 +96,7 @@ export function registerReactTools(server, { chatsvc }) {
|
|
|
96
96
|
.min(1)
|
|
97
97
|
.describe(`The conversation id (or "${SELF_CHAT}" — also by the name "notes" or "self" — for the self-chat), ` +
|
|
98
98
|
"or a case-insensitive substring of the chat title, channel name, team name or an untitled chat's participant names."),
|
|
99
|
-
message_id: z.string().min(1).describe('The message to react to, as
|
|
99
|
+
message_id: z.string().min(1).describe('The message to react to, as teams_list_messages lists it.'),
|
|
100
100
|
reaction: z.string().min(1).describe('An emoji (👍), a name (thumbsup) or a Teams reaction key (like, 1f389_partypopper).'),
|
|
101
101
|
remove: z.boolean().optional().describe('Withdraw this reaction instead of adding it (default false).'),
|
|
102
102
|
confirmToken: confirmTokenParam,
|
|
@@ -109,7 +109,7 @@ export function registerReactTools(server, { chatsvc }) {
|
|
|
109
109
|
const m = await chatsvc.getMessage(target.id, message_id);
|
|
110
110
|
if (m === undefined) {
|
|
111
111
|
throw new McpToolError(`There is no message ${message_id} in this conversation to react to.`, {
|
|
112
|
-
hint: 'Take message ids from
|
|
112
|
+
hint: 'Take message ids from teams_list_messages.',
|
|
113
113
|
});
|
|
114
114
|
}
|
|
115
115
|
const already = normaliseMessage(m, me).reactions?.some((r) => r.key === key && r.byMe) ?? false;
|
|
@@ -182,7 +182,7 @@ export function registerReactTools(server, { chatsvc }) {
|
|
|
182
182
|
verified,
|
|
183
183
|
warning: `Teams did not confirm this change (${why}), and reading the message back ` +
|
|
184
184
|
`${readBackFailed ? 'failed' : verified === null ? 'did not find it' : `did not show the reaction ${shown}`} — ` +
|
|
185
|
-
'check the message (
|
|
185
|
+
'check the message (teams_list_messages) before retrying.',
|
|
186
186
|
});
|
|
187
187
|
}
|
|
188
188
|
let warning;
|
|
@@ -190,15 +190,15 @@ export function registerReactTools(server, { chatsvc }) {
|
|
|
190
190
|
warning = `Teams did not confirm this change, but reading the message back shows the reaction ${shown}.`;
|
|
191
191
|
}
|
|
192
192
|
else if (readBackFailed) {
|
|
193
|
-
warning = 'Teams accepted the change, but reading the message back failed — check the message (
|
|
193
|
+
warning = 'Teams accepted the change, but reading the message back failed — check the message (teams_list_messages).';
|
|
194
194
|
}
|
|
195
195
|
else if (verified === null) {
|
|
196
196
|
warning =
|
|
197
197
|
'Teams accepted the change, but the message was not found on reading it back (it may have been deleted) — ' +
|
|
198
|
-
'check the conversation (
|
|
198
|
+
'check the conversation (teams_list_messages).';
|
|
199
199
|
}
|
|
200
200
|
else if (!verified) {
|
|
201
|
-
warning = `Teams accepted the change, but reading the message back did not show the reaction ${shown} — check the message (
|
|
201
|
+
warning = `Teams accepted the change, but reading the message back did not show the reaction ${shown} — check the message (teams_list_messages); the key may not be one Teams knows.`;
|
|
202
202
|
}
|
|
203
203
|
return untrustedResult({
|
|
204
204
|
status: remove ? 'removed' : 'reacted',
|
package/dist/tools/search.js
CHANGED
|
@@ -3,7 +3,7 @@ import { mapWithConcurrency, McpToolError, toolAnnotations } from '@chrischall/m
|
|
|
3
3
|
import { conversationKind, conversationSummary, isUserMessage, newestActivityMs, normaliseMessage, } from '../model.js';
|
|
4
4
|
import { arrivalMs, resolveListed } from './conversation.js';
|
|
5
5
|
import { CONFIRM_CONCURRENCY, isUnreachable } from './confirm.js';
|
|
6
|
-
import { enrichTitles } from './titles.js';
|
|
6
|
+
import { conversationName, enrichTitles, participantsOf } from './titles.js';
|
|
7
7
|
import { wrapApiError } from './errors.js';
|
|
8
8
|
import { untrustedResult, UNTRUSTED_DESCRIPTION_SUFFIX } from './untrusted.js';
|
|
9
9
|
const DEFAULT_LIMIT = 25;
|
|
@@ -58,8 +58,9 @@ function hitMessage(m) {
|
|
|
58
58
|
const { attachments: _a, reactions: _r, deleted: _d, ...rest } = m;
|
|
59
59
|
return rest;
|
|
60
60
|
}
|
|
61
|
+
/** A hit's conversation: its id and its name — title, kind, team, and an untitled chat's participants. */
|
|
61
62
|
function hitConversation(s) {
|
|
62
|
-
return
|
|
63
|
+
return conversationName(s);
|
|
63
64
|
}
|
|
64
65
|
export function registerSearchTools(server, { chatsvc, substrate }) {
|
|
65
66
|
server.registerTool('teams_search_messages', {
|
|
@@ -67,7 +68,7 @@ export function registerSearchTools(server, { chatsvc, substrate }) {
|
|
|
67
68
|
description: 'Find messages by text across the chats and channels the signed-in user is in. Hits come ' +
|
|
68
69
|
'newest first, each with its conversation (id, title, kind, team) and the message (id, time ' +
|
|
69
70
|
'ISO 8601, sender, fromMe (scan only), text, subject, replyTo for a channel reply); read a hit in context ' +
|
|
70
|
-
'with
|
|
71
|
+
'with teams_list_messages. conversation narrows to one chat or channel (id or name); from ' +
|
|
71
72
|
'keeps messages whose sender display name contains it; since (ISO 8601) sets how far back to ' +
|
|
72
73
|
`look (default the last ${DEFAULT_SINCE_DAYS} days); limit caps the hits (default ` +
|
|
73
74
|
`${DEFAULT_LIMIT}, max ${MAX_LIMIT}; total_hits and truncated say when there were more). ` +
|
|
@@ -401,7 +402,7 @@ async function scanSearch(chatsvc, raw, me, { query, target, fromLc, cutoff, cap
|
|
|
401
402
|
conversations_not_scanned: notScanned,
|
|
402
403
|
messages_scanned: messagesScanned,
|
|
403
404
|
skipped_unreachable: unreachable,
|
|
404
|
-
...(partial.length > 0 ? { partially_scanned: partial.map((s) => ({ id: s.id, title: final(s).title })) } : {}),
|
|
405
|
+
...(partial.length > 0 ? { partially_scanned: partial.map((s) => ({ id: s.id, title: final(s).title, ...participantsOf(final(s)) })) } : {}),
|
|
405
406
|
...(leftOut
|
|
406
407
|
? {
|
|
407
408
|
hint: (notScanned > 0
|
package/dist/tools/send.js
CHANGED
|
@@ -33,7 +33,7 @@ const mentionArg = z.object({
|
|
|
33
33
|
});
|
|
34
34
|
/**
|
|
35
35
|
* The conversation a write goes to: `48:notes` (also by the names `notes` /
|
|
36
|
-
* `self`), else an id or name as `
|
|
36
|
+
* `self`), else an id or name as `teams_list_messages` resolves it. `verb` words the refusals ("post to",
|
|
37
37
|
* "react in").
|
|
38
38
|
*/
|
|
39
39
|
export async function resolveTarget(chatsvc, conversation, me, verb = 'post to') {
|
|
@@ -46,7 +46,7 @@ export async function resolveTarget(chatsvc, conversation, me, verb = 'post to')
|
|
|
46
46
|
}
|
|
47
47
|
const raw = await chatsvc.listConversations();
|
|
48
48
|
const s = await resolveListed(chatsvc, raw, me, conversation, verb);
|
|
49
|
-
return { id: s.id, title: s.title, kind: s.kind };
|
|
49
|
+
return { id: s.id, title: s.title, kind: s.kind, ...(s.participants !== undefined ? { participants: s.participants } : {}) };
|
|
50
50
|
}
|
|
51
51
|
/** Who has written in the conversation lately, by MRI → display name. */
|
|
52
52
|
async function recentSenders(chatsvc, conversationId) {
|
|
@@ -104,7 +104,7 @@ async function quoted(chatsvc, conversationId, id) {
|
|
|
104
104
|
const m = await chatsvc.getMessage(conversationId, id);
|
|
105
105
|
if (m === undefined) {
|
|
106
106
|
throw new McpToolError(`There is no message ${id} in this conversation to quote.`, {
|
|
107
|
-
hint: 'Take message ids from
|
|
107
|
+
hint: 'Take message ids from teams_list_messages.',
|
|
108
108
|
});
|
|
109
109
|
}
|
|
110
110
|
const mri = senderMri(m.from) ?? '';
|
|
@@ -119,7 +119,7 @@ async function threadRoot(chatsvc, channelId, id, me) {
|
|
|
119
119
|
const m = await chatsvc.getMessage(channelId, id);
|
|
120
120
|
if (m === undefined) {
|
|
121
121
|
throw new McpToolError(`There is no post ${id} in this channel to reply under.`, {
|
|
122
|
-
hint: 'Take the root post\'s id from
|
|
122
|
+
hint: 'Take the root post\'s id from teams_list_messages.',
|
|
123
123
|
});
|
|
124
124
|
}
|
|
125
125
|
const replyTo = normaliseMessage(m, me).replyTo;
|
|
@@ -140,14 +140,14 @@ function unconfirmedPost(conversation) {
|
|
|
140
140
|
conversation,
|
|
141
141
|
warning: `Teams did not confirm this post (${unknownOutcomeReason(e, { sent: 'the post' })}), ` +
|
|
142
142
|
'so it may already be in the conversation. Check the conversation before retrying ' +
|
|
143
|
-
'(
|
|
143
|
+
'(teams_list_messages); do not resend blindly.',
|
|
144
144
|
});
|
|
145
145
|
}
|
|
146
146
|
export function registerSendTools(server, { chatsvc }) {
|
|
147
147
|
server.registerTool(TOOL, {
|
|
148
148
|
title: 'Send a Teams message',
|
|
149
|
-
description: 'Post a message as the signed-in user to any chat or channel, by id (from
|
|
150
|
-
'
|
|
149
|
+
description: 'Post a message as the signed-in user to any chat or channel, by id (from teams_list_conversations / ' +
|
|
150
|
+
'teams_list_channels) or by name. text is plain text: it is escaped, newlines are kept, ' +
|
|
151
151
|
'and :key: shortcodes (e.g. :smile:, :1f389_partypopper:) become Teams emoji. reply_to in a ' +
|
|
152
152
|
'channel posts into that root post\'s thread; in a chat it quote-replies that message. quote ' +
|
|
153
153
|
'quote-replies a message in any conversation. mentions @-mention people: name_in_text must appear ' +
|
package/dist/tools/titles.js
CHANGED
|
@@ -1,13 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Names for conversations: untitled group chats and 1:1s titled from who is in
|
|
3
|
+
* them, and {@link nameConversations} for any tool whose result carries a
|
|
4
|
+
* conversation id.
|
|
3
5
|
*
|
|
4
6
|
* A group chat with no topic has nothing in the listing to call it by: the
|
|
5
7
|
* listing's stand-in is the last message's sender (`conversationSummary`).
|
|
6
8
|
* Live (2026-10-10, a real tenant) that made 15 different group chats all
|
|
7
9
|
* "King, Greg" — one person who posts everywhere — so a list could not tell
|
|
8
|
-
* them apart and name resolution was always ambiguous.
|
|
9
|
-
*
|
|
10
|
-
*
|
|
10
|
+
* them apart and name resolution was always ambiguous.
|
|
11
|
+
*
|
|
12
|
+
* This server has no member-list call: nothing in the recorded API notes
|
|
13
|
+
* (`docs/plans/2026-10-10-chatsvc-api.md`) or the fixtures shows one (a
|
|
14
|
+
* `threads/{id}` read, say) working with the captured chat-service token, so
|
|
15
|
+
* none is guessed at. Every message does carry its sender's name and MRI, so
|
|
16
|
+
* reading a chat's recent messages names the people in it — the members who
|
|
17
|
+
* WROTE in that sample, not every member.
|
|
18
|
+
*
|
|
19
|
+
* The title is a pure function of that sampled set of people: they are sorted
|
|
20
|
+
* by display name (lower-cased, compared by code unit — no locale rules — and
|
|
21
|
+
* by MRI on a tie), the first three named and the rest counted as "+N". Who
|
|
22
|
+
* posted most recently does not move it, so a chat keeps its name from one
|
|
23
|
+
* message to the next; it changes only when the sample's people do (someone
|
|
24
|
+
* new writes, or someone's last message ages out of the page read).
|
|
11
25
|
*
|
|
12
26
|
* An untitled 1:1 is named after the other person, whose MRI its id carries
|
|
13
27
|
* (`oneOnOnePeerMri`). The listing has their name only when they sent the last
|
|
@@ -24,7 +38,7 @@
|
|
|
24
38
|
* a failed read keeps the listing's title — it never fails the call.
|
|
25
39
|
*/
|
|
26
40
|
import { mapWithConcurrency } from '@chrischall/mcp-utils';
|
|
27
|
-
import { conversationKind, GROUP_TITLE_PREFIX, isFromMri, isUserMessage, oneOnOnePeerMri, senderMri, UNTITLED_GROUP_TITLE, UNTITLED_ONE_ON_ONE_TITLE, } from '../model.js';
|
|
41
|
+
import { conversationKind, GROUP_TITLE_PREFIX, isFromMri, isUserMessage, oneOnOnePeerMri, senderMri, UNTITLED_GROUP_TITLE, UNTITLED_ONE_ON_ONE_TITLE, summariseAll, } from '../model.js';
|
|
28
42
|
/** Recent messages read per untitled chat. */
|
|
29
43
|
export const TITLE_FETCH_MESSAGES = 30;
|
|
30
44
|
/** Their page size, so the read is one small request rather than a 200-message page. */
|
|
@@ -42,32 +56,45 @@ const NAME_SEPARATOR = '; ';
|
|
|
42
56
|
export function isUntitledGroup(c) {
|
|
43
57
|
return conversationKind(c) === 'group' && !c.threadProperties?.topic?.trim();
|
|
44
58
|
}
|
|
59
|
+
/** Lower-cased names by code unit, then MRI: the same order on every machine, whatever its locale. */
|
|
60
|
+
export function byNameThenMri(a, b) {
|
|
61
|
+
const x = a.name.toLowerCase();
|
|
62
|
+
const y = b.name.toLowerCase();
|
|
63
|
+
if (x !== y)
|
|
64
|
+
return x < y ? -1 : 1;
|
|
65
|
+
return a.mri < b.mri ? -1 : a.mri > b.mri ? 1 : 0;
|
|
66
|
+
}
|
|
45
67
|
/**
|
|
46
|
-
* The title for a group chat from its messages (newest first):
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
68
|
+
* The title for a group chat from its messages (newest first): its distinct
|
|
69
|
+
* senders other than the user, sorted by name ({@link byNameThenMri}), the
|
|
70
|
+
* first three named and the rest counted as "+N" — all of whom are its
|
|
71
|
+
* `participants`, in that order. Who wrote most recently does not change it:
|
|
72
|
+
* it depends only on who is in the messages read. A sender is distinct by MRI
|
|
73
|
+
* (named by their newest message, so a rename shows) and by display name
|
|
74
|
+
* ignoring case (of two accounts under one name, the lower MRI is kept), so
|
|
75
|
+
* one person under two accounts appears once. System events are skipped —
|
|
76
|
+
* their display name is whoever triggered them. `undefined` when no one else
|
|
77
|
+
* wrote.
|
|
52
78
|
*/
|
|
53
79
|
export function groupTitleFrom(messagesNewestFirst, meMri) {
|
|
54
|
-
const
|
|
55
|
-
const seenNames = new Set();
|
|
56
|
-
const participants = [];
|
|
80
|
+
const byMri = new Map();
|
|
57
81
|
for (const m of messagesNewestFirst) {
|
|
58
82
|
if (!isUserMessage(m))
|
|
59
83
|
continue;
|
|
60
84
|
const mri = senderMri(m.from);
|
|
61
85
|
const name = m.imdisplayname?.trim();
|
|
62
|
-
if (mri === undefined || mri === meMri || !name)
|
|
86
|
+
if (mri === undefined || mri === meMri || !name || byMri.has(mri))
|
|
63
87
|
continue;
|
|
88
|
+
byMri.set(mri, name);
|
|
89
|
+
}
|
|
90
|
+
const byName = new Map();
|
|
91
|
+
for (const [mri, name] of byMri) {
|
|
64
92
|
const key = name.toLowerCase();
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
seenNames.add(key);
|
|
69
|
-
participants.push(name);
|
|
93
|
+
const kept = byName.get(key);
|
|
94
|
+
if (kept === undefined || mri < kept.mri)
|
|
95
|
+
byName.set(key, { name, mri });
|
|
70
96
|
}
|
|
97
|
+
const participants = [...byName.values()].sort(byNameThenMri).map((p) => p.name);
|
|
71
98
|
if (participants.length === 0)
|
|
72
99
|
return undefined;
|
|
73
100
|
const named = participants.slice(0, NAMED_PARTICIPANTS);
|
|
@@ -178,3 +205,59 @@ export async function enrichTitles(chatsvc, raw, me, rows) {
|
|
|
178
205
|
return { ...row, title: row.kind === 'oneOnOne' ? UNTITLED_ONE_ON_ONE_TITLE : UNTITLED_GROUP_TITLE };
|
|
179
206
|
});
|
|
180
207
|
}
|
|
208
|
+
/** `{ participants }` when a (titled) summary has them — an untitled chat's — else nothing, for spreading into a row. */
|
|
209
|
+
export function participantsOf(s) {
|
|
210
|
+
return s.participants !== undefined ? { participants: s.participants } : {};
|
|
211
|
+
}
|
|
212
|
+
/** The naming fields of a (titled) summary, for a result that carries a conversation by id. */
|
|
213
|
+
export function conversationName(s) {
|
|
214
|
+
return {
|
|
215
|
+
id: s.id,
|
|
216
|
+
kind: s.kind,
|
|
217
|
+
title: s.title,
|
|
218
|
+
...(s.team !== undefined ? { team: s.team } : {}),
|
|
219
|
+
...participantsOf(s),
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Starts the listing read (conversations and the user's MRI) NOW and returns
|
|
224
|
+
* a namer that uses it, so a tool can overlap that read with its own work —
|
|
225
|
+
* the Activity feed scan — rather than waiting for it afterwards. A failed
|
|
226
|
+
* listing is swallowed as soon as it settles (no unhandled rejection, even
|
|
227
|
+
* if the namer is never called) and names nothing.
|
|
228
|
+
*/
|
|
229
|
+
export function conversationNamer(chatsvc) {
|
|
230
|
+
const listing = Promise.all([chatsvc.listConversations(), chatsvc.meMri()]).then(([raw, me]) => ({ raw, me }), () => undefined);
|
|
231
|
+
return async (ids) => {
|
|
232
|
+
const out = new Map();
|
|
233
|
+
const wanted = new Set(ids);
|
|
234
|
+
if (wanted.size === 0)
|
|
235
|
+
return out;
|
|
236
|
+
const read = await listing;
|
|
237
|
+
if (read === undefined)
|
|
238
|
+
return out;
|
|
239
|
+
try {
|
|
240
|
+
const rows = summariseAll(read.raw, read.me).filter((s) => wanted.has(s.id));
|
|
241
|
+
for (const s of await enrichTitles(chatsvc, read.raw, read.me, rows))
|
|
242
|
+
out.set(s.id, conversationName(s));
|
|
243
|
+
}
|
|
244
|
+
catch {
|
|
245
|
+
// Unnamed, not failed: the caller still has every id.
|
|
246
|
+
}
|
|
247
|
+
return out;
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Names for the conversations `ids`, for a tool whose result carries ids it
|
|
252
|
+
* did not get from the listing (the Activity feed, an attachment): one listing
|
|
253
|
+
* read, then {@link enrichTitles} on just those conversations, so an untitled
|
|
254
|
+
* group chat gets its participant title and a 1:1 the other person's name. An
|
|
255
|
+
* id the listing does not carry is left out. Never throws — a failed listing
|
|
256
|
+
* names nothing, a failed title read keeps the listing's title — since a name
|
|
257
|
+
* is never worth failing the call over.
|
|
258
|
+
*/
|
|
259
|
+
export async function nameConversations(chatsvc, ids) {
|
|
260
|
+
if (ids.length === 0)
|
|
261
|
+
return new Map();
|
|
262
|
+
return conversationNamer(chatsvc)(ids);
|
|
263
|
+
}
|
package/dist/tools/unread.js
CHANGED
|
@@ -3,7 +3,7 @@ import { CONFIRM_INJECTION_RULE, confirmTokenParam, mapWithConcurrency, McpToolE
|
|
|
3
3
|
import { conversationSummary, isUnread, lastChangeMs, matchConversations, normaliseMessage, oldestFirst, readHorizon, } from '../model.js';
|
|
4
4
|
import { CONFIRM_CONCURRENCY, confirmedSummary, confirmUnreadCandidates, isUnreachable, olderUnreadArg, olderUnreadConversations, olderUnreadReport, sinceCutoff, sinceDaysArg, } from './confirm.js';
|
|
5
5
|
import { GROUP_TITLE_DESCRIPTION, includeHiddenArg, isUnreadCandidateFor, MATCH_REASON_DESCRIPTION } from './listing.js';
|
|
6
|
-
import { enrichTitles } from './titles.js';
|
|
6
|
+
import { enrichTitles, participantsOf } from './titles.js';
|
|
7
7
|
import { wrapApiError } from './errors.js';
|
|
8
8
|
import { untrustedResult, UNTRUSTED_DESCRIPTION_SUFFIX } from './untrusted.js';
|
|
9
9
|
import { resolveTimeZone, TIME_ZONE_DESCRIPTION, tzArg } from './timezone.js';
|
|
@@ -39,7 +39,7 @@ const TRUNCATED_SKIP = {
|
|
|
39
39
|
skipped: 'truncated',
|
|
40
40
|
hint: 'The read marker was left where it was: per_conversation_limit cut this read, so unread messages older ' +
|
|
41
41
|
`than those returned were not returned. Read again with a larger per_conversation_limit (max ${MAX_PER_CONVERSATION}) ` +
|
|
42
|
-
'or with
|
|
42
|
+
'or with teams_list_messages (unread_only) to mark it read, or use teams_mark_read to mark it all read deliberately.',
|
|
43
43
|
};
|
|
44
44
|
/** Newest activity first; a conversation with no messages at all sorts last. */
|
|
45
45
|
function byLastActivityDesc(a, b) {
|
|
@@ -138,7 +138,7 @@ async function unreadFrom(chatsvc, raw, me, candidates, pos, { limit, timeZone,
|
|
|
138
138
|
/** The arguments that shape a per-conversation answer, which a `from` page replaces. */
|
|
139
139
|
const NOT_WITH_FROM = ['since_days', 'cursors', 'per_conversation_limit', 'max_conversations', 'mark_read', 'older_unread'];
|
|
140
140
|
export function registerUnreadTools(server, { chatsvc }) {
|
|
141
|
-
server.registerTool('
|
|
141
|
+
server.registerTool('teams_list_unread_messages', {
|
|
142
142
|
title: 'Get unread Teams messages',
|
|
143
143
|
description: 'Get every unread message across all the chats and channels the signed-in user is in ' +
|
|
144
144
|
'(or those matching kinds / query), grouped by conversation, most recent activity ' +
|
|
@@ -160,7 +160,7 @@ export function registerUnreadTools(server, { chatsvc }) {
|
|
|
160
160
|
'otherwise). Chats the user muted in Teams (muted: true) are left out too and counted in ' +
|
|
161
161
|
'muted_skipped, without being read; include_muted adds them. ' +
|
|
162
162
|
'Unread conversations past max_conversations are listed by id, title and unread_count in ' +
|
|
163
|
-
'more_unread_conversations; read one with
|
|
163
|
+
'more_unread_conversations; read one with teams_list_messages. A conversation that ' +
|
|
164
164
|
'could not be read is listed in errors and the rest still come back. total_unread covers ' +
|
|
165
165
|
'every unread conversation found; total_unread_exact is false when a per-conversation ' +
|
|
166
166
|
'limit truncated or a read failed. cursors ({ conversationId: messageId }) returns only unread ' +
|
|
@@ -325,7 +325,7 @@ export function registerUnreadTools(server, { chatsvc }) {
|
|
|
325
325
|
plans.push({ summary, previous: horizonMessageId(conv), target });
|
|
326
326
|
}
|
|
327
327
|
if (plans.length > 0) {
|
|
328
|
-
const gate = await confirmMarks(ctx, { tool: '
|
|
328
|
+
const gate = await confirmMarks(ctx, { tool: 'teams_list_unread_messages', me, plans, confirmToken });
|
|
329
329
|
if (gate)
|
|
330
330
|
return gate;
|
|
331
331
|
}
|
|
@@ -353,7 +353,7 @@ export function registerUnreadTools(server, { chatsvc }) {
|
|
|
353
353
|
returned: messages.length,
|
|
354
354
|
hint: `Only the newest ${messages.length} unread messages were returned; pass a larger ` +
|
|
355
355
|
`per_conversation_limit (max ${MAX_PER_CONVERSATION}) or read the conversation ` +
|
|
356
|
-
'with
|
|
356
|
+
'with teams_list_messages (unread_only).',
|
|
357
357
|
},
|
|
358
358
|
}
|
|
359
359
|
: {}),
|
|
@@ -387,6 +387,7 @@ export function registerUnreadTools(server, { chatsvc }) {
|
|
|
387
387
|
more_unread_conversations: rest.map(({ summary, read }) => ({
|
|
388
388
|
id: summary.id,
|
|
389
389
|
title: summary.title,
|
|
390
|
+
...participantsOf(summary),
|
|
390
391
|
unread_count: read.messages.length,
|
|
391
392
|
})),
|
|
392
393
|
}
|
package/dist/version.js
CHANGED
package/mint.yaml
CHANGED
|
@@ -72,6 +72,11 @@ env:
|
|
|
72
72
|
help: >-
|
|
73
73
|
Default IANA time zone (e.g. America/New_York) for the tz argument of
|
|
74
74
|
the read tools; messages then carry time_local. Unset means UTC only.
|
|
75
|
+
- name: TEAMS_OUTPUT_DIR
|
|
76
|
+
required: false
|
|
77
|
+
help: >-
|
|
78
|
+
Folder teams_export_messages writes exports into (each export gets its own
|
|
79
|
+
subfolder). Unset means ~/Downloads/microsoft-teams-mcp.
|
|
75
80
|
- name: TEAMS_SUBSTRATE_TOKEN_FILE
|
|
76
81
|
required: false
|
|
77
82
|
help: >-
|
|
@@ -111,3 +116,16 @@ egress:
|
|
|
111
116
|
- us-prod.asyncgw.teams.microsoft.com
|
|
112
117
|
- substrate.office.com
|
|
113
118
|
- '*.sharepoint.com'
|
|
119
|
+
# Sample prompts for the public catalog — each is answered by the read tools
|
|
120
|
+
# alone (teams_list_unread_messages, teams_search_messages, teams_list_activity), and none
|
|
121
|
+
# marks anything read.
|
|
122
|
+
examples:
|
|
123
|
+
- prompt: >-
|
|
124
|
+
Catch me up on my unread Teams messages and tell me which ones need a
|
|
125
|
+
reply from me.
|
|
126
|
+
note: Reads unread chats and channels; nothing is marked read.
|
|
127
|
+
- prompt: >-
|
|
128
|
+
Search my Teams chats from the last two weeks for messages about the
|
|
129
|
+
quarterly budget review.
|
|
130
|
+
note: Uses the same search the Teams search box does.
|
|
131
|
+
- prompt: What mentions and replies have I had in my Teams Activity feed today?
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chrischall/microsoft-teams-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.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>",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"typecheck": "tsc -p tsconfig.check.json"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@chrischall/mcp-utils": "^3.
|
|
48
|
+
"@chrischall/mcp-utils": "^3.3.0",
|
|
49
49
|
"@fetchproxy/server": "^3.6.2",
|
|
50
50
|
"@modelcontextprotocol/server": "^2.3.0",
|
|
51
51
|
"dotenv": "^18.0.1",
|
|
@@ -58,5 +58,9 @@
|
|
|
58
58
|
"esbuild": "^0.28.1",
|
|
59
59
|
"typescript": "^7.0.2",
|
|
60
60
|
"vitest": "^5.0.0"
|
|
61
|
+
},
|
|
62
|
+
"allowScripts": {
|
|
63
|
+
"esbuild": false,
|
|
64
|
+
"fsevents": false
|
|
61
65
|
}
|
|
62
66
|
}
|
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.7.0",
|
|
10
10
|
"packages": [
|
|
11
11
|
{
|
|
12
12
|
"registryType": "npm",
|
|
13
13
|
"identifier": "@chrischall/microsoft-teams-mcp",
|
|
14
|
-
"version": "0.
|
|
14
|
+
"version": "0.7.0",
|
|
15
15
|
"transport": {
|
|
16
16
|
"type": "stdio"
|
|
17
17
|
},
|
|
@@ -107,6 +107,13 @@
|
|
|
107
107
|
"format": "string",
|
|
108
108
|
"isSecret": false
|
|
109
109
|
},
|
|
110
|
+
{
|
|
111
|
+
"name": "TEAMS_OUTPUT_DIR",
|
|
112
|
+
"description": "Folder teams_export_messages writes exports into. Unset means ~/Downloads/microsoft-teams-mcp.",
|
|
113
|
+
"isRequired": false,
|
|
114
|
+
"format": "string",
|
|
115
|
+
"isSecret": false
|
|
116
|
+
},
|
|
110
117
|
{
|
|
111
118
|
"name": "MCP_CONFIRM_MODE",
|
|
112
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.",
|