@chrischall/microsoft-teams-mcp 0.8.2 → 0.8.4
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 +6 -4
- package/dist/bundle.js +2434 -2041
- package/dist/tools/attachment.js +97 -45
- package/dist/tools/export.js +23 -12
- package/dist/version.js +1 -1
- package/package.json +2 -2
- package/server.json +2 -2
package/dist/tools/attachment.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { McpToolError, errorKindOf, errorStatusOf, toolAnnotations } from '@chrischall/mcp-utils';
|
|
2
|
+
import { McpToolError, errorKindOf, errorStatusOf, expandPath, readEnvVar, toolAnnotations, } from '@chrischall/mcp-utils';
|
|
3
|
+
import { deliverFile, isHostedEnv } from '@chrischall/mcp-utils/export';
|
|
4
|
+
import { homedir } from 'node:os';
|
|
5
|
+
import { join } from 'node:path';
|
|
3
6
|
import { normaliseMessage } from '../model.js';
|
|
4
7
|
import { wrapApiError } from './errors.js';
|
|
5
8
|
import { untrustedResult, UNTRUSTED_DESCRIPTION_SUFFIX } from './untrusted.js';
|
|
6
9
|
import { nameConversations } from './titles.js';
|
|
7
10
|
import { workMeta } from './hints.js';
|
|
11
|
+
import { EXPORT_OUTPUT_ENV, EXPORT_SERVER_NAME } from './export.js';
|
|
8
12
|
/**
|
|
9
13
|
* Raw messages read looking for the one asked for (20 pages of 200). The
|
|
10
14
|
* `stopAt` boundary — paging past the message's arrival time — is the real
|
|
@@ -12,13 +16,15 @@ import { workMeta } from './hints.js';
|
|
|
12
16
|
*/
|
|
13
17
|
const MAX_RAW_MESSAGES = 4000;
|
|
14
18
|
/**
|
|
15
|
-
* Largest shared file whose contents are downloaded
|
|
16
|
-
*
|
|
17
|
-
*
|
|
19
|
+
* Largest shared file whose contents are downloaded. Past this the bounded read
|
|
20
|
+
* in `SharePointClient` aborts and the file degrades to metadata + its open
|
|
21
|
+
* link. What is downloaded is not necessarily inlined: `deliverFile` inlines
|
|
22
|
+
* only up to 10 MiB and hands anything larger over as a link or a saved file.
|
|
18
23
|
*/
|
|
19
24
|
export const MAX_FILE_BYTES = 25 * 1024 * 1024;
|
|
20
25
|
const FILE_HINT = 'A shared file is downloaded from SharePoint and returned as its contents (an image as an image, ' +
|
|
21
|
-
'anything else as an embedded resource
|
|
26
|
+
'anything else as an embedded resource; over 10 MiB as a download link, or a saved file on a local ' +
|
|
27
|
+
'install). The first file from a given SharePoint host may need ' +
|
|
22
28
|
'opening once in Teams to mint a short-lived token; a file your account cannot open comes back as ' +
|
|
23
29
|
'metadata and its link.';
|
|
24
30
|
export function registerAttachmentTools(server, { chatsvc, sharepoint }) {
|
|
@@ -28,7 +34,10 @@ export function registerAttachmentTools(server, { chatsvc, sharepoint }) {
|
|
|
28
34
|
'teams_list_messages / teams_list_unread_messages. An inline image (attachments.images[].ref) ' +
|
|
29
35
|
'is returned as the image itself. A shared file (attachments.files[].name) is downloaded ' +
|
|
30
36
|
'from SharePoint and returned as its contents: an image as the image, anything else as an ' +
|
|
31
|
-
'embedded resource carrying the bytes.
|
|
37
|
+
'embedded resource carrying the bytes. Anything over 10 MiB comes back instead as a signed, ' +
|
|
38
|
+
'expiring download link (downloadUrl) on a hosted install, or saved to a fresh file (path) under ' +
|
|
39
|
+
`${EXPORT_OUTPUT_ENV}, else ~/Downloads/${EXPORT_SERVER_NAME}, on a local one; the caption's via ` +
|
|
40
|
+
'says which. The first file from a given SharePoint host in a ' +
|
|
32
41
|
'session may need opening once in Teams to mint a short-lived token; a file your account ' +
|
|
33
42
|
'cannot open, or one that could not be fetched, comes back as metadata and its open link ' +
|
|
34
43
|
'instead of failing. Its caption names the conversation beside its id: title (as teams_list_conversations ' +
|
|
@@ -71,6 +80,7 @@ export function registerAttachmentTools(server, { chatsvc, sharepoint }) {
|
|
|
71
80
|
if (!mimeType.startsWith('image/')) {
|
|
72
81
|
throw new McpToolError(`The attachment ${ref} is not an image (the image store returned ${mimeType}).`);
|
|
73
82
|
}
|
|
83
|
+
const delivered = await deliver(data, imageFileName(ref, mimeType), mimeType);
|
|
74
84
|
const caption = untrustedResult({
|
|
75
85
|
ref,
|
|
76
86
|
message_id,
|
|
@@ -78,12 +88,11 @@ export function registerAttachmentTools(server, { chatsvc, sharepoint }) {
|
|
|
78
88
|
...(await naming),
|
|
79
89
|
sender: message.sender,
|
|
80
90
|
time: message.time,
|
|
81
|
-
mimeType,
|
|
82
|
-
bytes:
|
|
91
|
+
mimeType: delivered.mimeType,
|
|
92
|
+
bytes: delivered.sizeBytes,
|
|
93
|
+
...deliveryFields(delivered),
|
|
83
94
|
});
|
|
84
|
-
return {
|
|
85
|
-
content: [{ type: 'image', data: data.toString('base64'), mimeType }, ...caption.content],
|
|
86
|
-
};
|
|
95
|
+
return { content: [...delivered.content, ...caption.content] };
|
|
87
96
|
}
|
|
88
97
|
const file = message.attachments.files.find((f) => f.name === ref);
|
|
89
98
|
if (file !== undefined) {
|
|
@@ -111,47 +120,90 @@ async function downloadSharedFile(sharepoint, file, message, ids, naming) {
|
|
|
111
120
|
if (file.url === undefined) {
|
|
112
121
|
return untrustedResult({ ...file, content_available: false, hint: FILE_HINT });
|
|
113
122
|
}
|
|
123
|
+
let downloaded;
|
|
114
124
|
try {
|
|
115
|
-
|
|
116
|
-
const caption = untrustedResult({
|
|
117
|
-
name: file.name,
|
|
118
|
-
...(file.type !== undefined ? { type: file.type } : {}),
|
|
119
|
-
...(file.openUrl !== undefined ? { openUrl: file.openUrl } : {}),
|
|
120
|
-
// The degrade path carries `content_available: false`; a successful
|
|
121
|
-
// download must carry the matching `true` so a caller keying on the field
|
|
122
|
-
// does not read a downloaded file as unavailable.
|
|
123
|
-
content_available: true,
|
|
124
|
-
mimeType,
|
|
125
|
-
bytes: size,
|
|
126
|
-
sender: message.sender,
|
|
127
|
-
time: message.time,
|
|
128
|
-
message_id: ids.message_id,
|
|
129
|
-
conversation: ids.conversation,
|
|
130
|
-
...(await naming),
|
|
131
|
-
});
|
|
132
|
-
if (mimeType.startsWith('image/')) {
|
|
133
|
-
return { content: [{ type: 'image', data: data.toString('base64'), mimeType }, ...caption.content] };
|
|
134
|
-
}
|
|
135
|
-
// An embedded resource carries the raw bytes; the installed
|
|
136
|
-
// `@modelcontextprotocol/server` (2.3.0) accepts a `{type:'resource'}`
|
|
137
|
-
// content block with a `BlobResourceContents` body ({uri, mimeType, blob}),
|
|
138
|
-
// so no base64-text fallback is needed. The `uri` is the file's open link
|
|
139
|
-
// (its SharePoint object url otherwise) — an identifier, not a re-fetch.
|
|
140
|
-
return {
|
|
141
|
-
content: [
|
|
142
|
-
{
|
|
143
|
-
type: 'resource',
|
|
144
|
-
resource: { uri: file.openUrl ?? file.url, mimeType, blob: data.toString('base64') },
|
|
145
|
-
},
|
|
146
|
-
...caption.content,
|
|
147
|
-
],
|
|
148
|
-
};
|
|
125
|
+
downloaded = await sharepoint.downloadFile(file.url, MAX_FILE_BYTES);
|
|
149
126
|
}
|
|
150
127
|
catch (err) {
|
|
151
128
|
// Graceful degrade: a file that could not be fetched comes back as metadata
|
|
152
129
|
// and its link, never as a tool failure (see the docblock).
|
|
153
130
|
return untrustedResult({ ...file, content_available: false, hint: degradeHint(err, hostOf(file.url)) });
|
|
154
131
|
}
|
|
132
|
+
// A file that WAS fetched but has no route back to the caller (over the inline
|
|
133
|
+
// cap, hosted with no blob store) is a real error, not a degrade: say so, and
|
|
134
|
+
// keep the open link in the hint so the file is still reachable.
|
|
135
|
+
let delivered;
|
|
136
|
+
try {
|
|
137
|
+
delivered = await deliver(downloaded.data, file.name, downloaded.mimeType);
|
|
138
|
+
}
|
|
139
|
+
catch (err) {
|
|
140
|
+
if (err instanceof McpToolError && file.openUrl !== undefined) {
|
|
141
|
+
throw new McpToolError(err.message, {
|
|
142
|
+
kind: err.kind,
|
|
143
|
+
hint: `Open it in SharePoint instead: ${file.openUrl}`,
|
|
144
|
+
cause: err,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
throw err;
|
|
148
|
+
}
|
|
149
|
+
const caption = untrustedResult({
|
|
150
|
+
name: file.name,
|
|
151
|
+
...(file.type !== undefined ? { type: file.type } : {}),
|
|
152
|
+
...(file.openUrl !== undefined ? { openUrl: file.openUrl } : {}),
|
|
153
|
+
// The degrade path carries `content_available: false`; a successful
|
|
154
|
+
// download must carry the matching `true` so a caller keying on the field
|
|
155
|
+
// does not read a downloaded file as unavailable.
|
|
156
|
+
content_available: true,
|
|
157
|
+
mimeType: delivered.mimeType,
|
|
158
|
+
bytes: downloaded.size,
|
|
159
|
+
...deliveryFields(delivered),
|
|
160
|
+
sender: message.sender,
|
|
161
|
+
time: message.time,
|
|
162
|
+
message_id: ids.message_id,
|
|
163
|
+
conversation: ids.conversation,
|
|
164
|
+
...(await naming),
|
|
165
|
+
});
|
|
166
|
+
// An embedded resource's `uri` is the file's open link (its SharePoint object
|
|
167
|
+
// url otherwise) — an identifier, not a re-fetch — rather than deliverFile's
|
|
168
|
+
// placeholder `attachment:///<name>`.
|
|
169
|
+
const uri = file.openUrl ?? file.url;
|
|
170
|
+
const content = delivered.content.map((block) => block.type === 'resource' ? { ...block, resource: { ...block.resource, uri } } : block);
|
|
171
|
+
return { content: [...content, ...caption.content] };
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Hand bytes back by the first route that reaches the caller (`deliverFile`):
|
|
175
|
+
* inline up to 10 MiB, else a signed link from the blob store (hosted), else a
|
|
176
|
+
* fresh, never-overwriting file in the download folder — offered only on a
|
|
177
|
+
* local install, since a hosted runner's disk is unreachable from the session.
|
|
178
|
+
*/
|
|
179
|
+
function deliver(bytes, fileName, mimeType) {
|
|
180
|
+
return deliverFile({
|
|
181
|
+
bytes,
|
|
182
|
+
fileName,
|
|
183
|
+
mimeType,
|
|
184
|
+
keyPrefix: 'attachments',
|
|
185
|
+
...(isHostedEnv() ? {} : { disk: { dir: downloadDir() } }),
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
/** `TEAMS_OUTPUT_DIR`, else `~/Downloads/microsoft-teams-mcp` — the folder the export tools default to. */
|
|
189
|
+
function downloadDir() {
|
|
190
|
+
const configured = readEnvVar(EXPORT_OUTPUT_ENV);
|
|
191
|
+
return configured !== undefined ? expandPath(configured) : join(homedir(), 'Downloads', EXPORT_SERVER_NAME);
|
|
192
|
+
}
|
|
193
|
+
/** An inline image has only a ref; name it `<ref>.<subtype>` for a link or a saved file. */
|
|
194
|
+
function imageFileName(ref, mimeType) {
|
|
195
|
+
const ext = (mimeType.split('/')[1] ?? '').split(/[;+]/)[0].replace(/[^a-z0-9]/gi, '');
|
|
196
|
+
return ext ? `${ref}.${ext}` : ref;
|
|
197
|
+
}
|
|
198
|
+
/** How the bytes were handed over, for the caption: the route, and where to find them when not inline. */
|
|
199
|
+
function deliveryFields(d) {
|
|
200
|
+
return {
|
|
201
|
+
via: d.via,
|
|
202
|
+
...(d.url !== undefined ? { downloadUrl: d.url } : {}),
|
|
203
|
+
...(d.expiresAt !== undefined ? { downloadExpiresAt: d.expiresAt } : {}),
|
|
204
|
+
...(d.path !== undefined ? { path: d.path } : {}),
|
|
205
|
+
...(d.note !== undefined ? { note: d.note } : {}),
|
|
206
|
+
};
|
|
155
207
|
}
|
|
156
208
|
function nameFields(n) {
|
|
157
209
|
if (n === undefined)
|
package/dist/tools/export.js
CHANGED
|
@@ -16,10 +16,12 @@
|
|
|
16
16
|
* `budget_seconds`, whichever comes first, and returns `has_more` with a
|
|
17
17
|
* `cursor`; passing the cursor back continues the SAME export (the same
|
|
18
18
|
* directory on disk, the next `part-NNNN.zip` in the blob store). The cursor
|
|
19
|
-
* carries the original arguments,
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
19
|
+
* carries the original arguments, what is still to do — for an export of
|
|
20
|
+
* named conversations the ids they resolved to; otherwise (or when that list
|
|
21
|
+
* is too long for a cursor) only the id to go on from, so the cursor stays
|
|
22
|
+
* short: conversations are exported in id order and the next part re-lists
|
|
23
|
+
* them from there, so one that first appears between parts is exported only
|
|
24
|
+
* if its id sorts after that point — and where in the current
|
|
23
25
|
* conversation it stopped, as a `from.ts` position. The budget is checked
|
|
24
26
|
* between conversations and between pages of a read; a read cut by it is
|
|
25
27
|
* redone whole by the next part, except the first conversation of a call,
|
|
@@ -426,13 +428,22 @@ async function runExport({ chatsvc, sharepoint }, input, opts) {
|
|
|
426
428
|
args,
|
|
427
429
|
...(stopPos !== undefined ? { pos: stopPos } : {}),
|
|
428
430
|
};
|
|
429
|
-
|
|
430
|
-
|
|
431
|
+
// A whole-account export re-lists on resume, so it goes on from an id: the cursor stays
|
|
432
|
+
// short however many conversations remain. A named one keeps the conversations its names
|
|
433
|
+
// resolved to (a short list), so a resume never resolves them again.
|
|
434
|
+
const fromId = encodeExportCursor({ ...base, from_id: queue[0] });
|
|
435
|
+
if (args.conversations === undefined) {
|
|
436
|
+
cursor = fromId;
|
|
431
437
|
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
438
|
+
else {
|
|
439
|
+
try {
|
|
440
|
+
cursor = encodeExportCursor({ ...base, ids: queue });
|
|
441
|
+
}
|
|
442
|
+
catch (err) {
|
|
443
|
+
if (!(err instanceof TypeError))
|
|
444
|
+
throw err;
|
|
445
|
+
cursor = fromId;
|
|
446
|
+
}
|
|
436
447
|
}
|
|
437
448
|
}
|
|
438
449
|
else {
|
|
@@ -488,8 +499,8 @@ export function registerExportTools(server, deps, opts = {}) {
|
|
|
488
499
|
`(default ${DEFAULT_MAX_ITEMS}, max ${MAX_ITEMS}) or budget_seconds (default ${DEFAULT_BUDGET_SECONDS}, ` +
|
|
489
500
|
`max ${MAX_BUDGET_SECONDS}); when has_more is true pass cursor back (alone, or with max_items / ` +
|
|
490
501
|
'budget_seconds) to continue the same export into the same folder (a hosted install returns a new link ' +
|
|
491
|
-
'per part).
|
|
492
|
-
'conversation that first appears between parts
|
|
502
|
+
'per part). Conversations are exported in id order and a cursor resumes from an id, so a ' +
|
|
503
|
+
'conversation that first appears between parts is included only if it sorts after that point. A rejected credential or persistent rate limiting stops early with a cursor and keeps what ' +
|
|
493
504
|
'was written; a conversation that cannot be read is listed in errors and skipped. Never marks anything ' +
|
|
494
505
|
'read. A name matching several conversations returns {ambiguous: true, candidates} and writes nothing. ' +
|
|
495
506
|
'With attachments true, inline images and shared files (up to 25 MB) are saved under ' +
|
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.8.
|
|
3
|
+
"version": "0.8.4",
|
|
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.7.0",
|
|
49
49
|
"@fetchproxy/server": "^3.6.2",
|
|
50
50
|
"@modelcontextprotocol/server": "^2.3.0",
|
|
51
51
|
"dotenv": "^18.0.1",
|
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.8.
|
|
9
|
+
"version": "0.8.4",
|
|
10
10
|
"packages": [
|
|
11
11
|
{
|
|
12
12
|
"registryType": "npm",
|
|
13
13
|
"identifier": "@chrischall/microsoft-teams-mcp",
|
|
14
|
-
"version": "0.8.
|
|
14
|
+
"version": "0.8.4",
|
|
15
15
|
"transport": {
|
|
16
16
|
"type": "stdio"
|
|
17
17
|
},
|