@softeria/ms-365-mcp-server 0.171.0 → 0.172.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/dist/attachment-route.js
CHANGED
|
@@ -187,12 +187,19 @@ function createAttachmentUploadHandler(deps) {
|
|
|
187
187
|
target: ticket.target,
|
|
188
188
|
name: ticket.name,
|
|
189
189
|
contentType: ticket.contentType,
|
|
190
|
+
contentId: ticket.contentId,
|
|
190
191
|
size: declared,
|
|
191
192
|
accessToken
|
|
192
193
|
},
|
|
193
194
|
req
|
|
194
195
|
);
|
|
195
|
-
res.status(201).json({
|
|
196
|
+
res.status(201).json({
|
|
197
|
+
ok: true,
|
|
198
|
+
name: ticket.name,
|
|
199
|
+
size: declared,
|
|
200
|
+
id: created.id,
|
|
201
|
+
...ticket.contentId ? { contentId: ticket.contentId } : {}
|
|
202
|
+
});
|
|
196
203
|
} catch (error) {
|
|
197
204
|
logger.error(`Attachment upload failed for ${ticket.target}: ${error.message}`);
|
|
198
205
|
if (!res.headersSent) res.status(502).type("text/plain").send("Upstream upload failed");
|
package/dist/graph-tools.js
CHANGED
|
@@ -619,6 +619,11 @@ async function checkAccountParamInBearerMode(accountParam, authManager) {
|
|
|
619
619
|
}
|
|
620
620
|
const UPLOAD_TARGET = /^(\/me|\/users\/[^/]+)\/(messages|events)\/[^/]+\/attachments$/;
|
|
621
621
|
const UPLOAD_CONTENT_TYPE = /^[\w.+-]+\/[\w.+-]+$/;
|
|
622
|
+
const UPLOAD_CONTENT_ID = /^[A-Za-z0-9][A-Za-z0-9._@-]{0,99}$/;
|
|
623
|
+
const UPLOAD_CONTENT_ID_ERROR = 'contentId may hold letters, digits, ".", "_", "@" and "-" (at most 100), e.g. signature-photo.';
|
|
624
|
+
const contentIdSchema = z.string().optional().describe(
|
|
625
|
+
'Attach inline under this Content-ID instead of as a regular attachment, so the HTML body can show the file with <img src="cid:<contentId>">, e.g. a picture in an email signature. Letters, digits, ".", "_", "@", "-".'
|
|
626
|
+
);
|
|
622
627
|
const UPLOAD_TARGET_ERROR = "target must be the attachments collection of a draft message or an event: /me/messages/{message-id}/attachments or /me/events/{event-id}/attachments.";
|
|
623
628
|
function uploadError(message) {
|
|
624
629
|
return { content: [{ type: "text", text: JSON.stringify({ error: message }) }], isError: true };
|
|
@@ -629,7 +634,10 @@ function cleanAttachmentName(name) {
|
|
|
629
634
|
return code > 31 && code !== 127;
|
|
630
635
|
}).join("").slice(0, 255);
|
|
631
636
|
}
|
|
632
|
-
|
|
637
|
+
function optionalContentId(value) {
|
|
638
|
+
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
639
|
+
}
|
|
640
|
+
async function mintUploadUrl(target, name, contentType, accountParam, authManager, contentId) {
|
|
633
641
|
const minting = getAttachmentMinting();
|
|
634
642
|
if (!minting) {
|
|
635
643
|
const smallFileTool = target.includes("/events/") ? "add-calendar-event-attachment" : target.startsWith("/users/") ? "add-shared-mailbox-attachment" : "add-mail-attachment";
|
|
@@ -645,6 +653,9 @@ async function mintUploadUrl(target, name, contentType, accountParam, authManage
|
|
|
645
653
|
if (!UPLOAD_CONTENT_TYPE.test(contentType)) {
|
|
646
654
|
return uploadError("contentType must be a MIME type such as application/pdf.");
|
|
647
655
|
}
|
|
656
|
+
if (contentId !== void 0 && !UPLOAD_CONTENT_ID.test(contentId)) {
|
|
657
|
+
return uploadError(UPLOAD_CONTENT_ID_ERROR);
|
|
658
|
+
}
|
|
648
659
|
const identityFromRequest = Boolean(authManager?.isOAuthModeEnabled() || getRequestTokens());
|
|
649
660
|
const requestToken = identityFromRequest ? getRequestTokens()?.accessToken ?? await authManager?.getToken().catch(() => null) ?? void 0 : void 0;
|
|
650
661
|
if (identityFromRequest && !requestToken) {
|
|
@@ -656,7 +667,7 @@ async function mintUploadUrl(target, name, contentType, accountParam, authManage
|
|
|
656
667
|
if (accountModeError) return uploadError(accountModeError);
|
|
657
668
|
let ticket;
|
|
658
669
|
try {
|
|
659
|
-
const upload = { name: cleanName, contentType };
|
|
670
|
+
const upload = { name: cleanName, contentType, ...contentId ? { contentId } : {} };
|
|
660
671
|
ticket = requestToken ? minting.store.mintUploadWithToken(target, requestToken, upload) : minting.store.mintUpload(target, accountParam, upload);
|
|
661
672
|
} catch (error) {
|
|
662
673
|
if (error instanceof TicketStoreFullError) return uploadError(error.message);
|
|
@@ -769,7 +780,7 @@ const UTILITY_TOOLS = [
|
|
|
769
780
|
method: "PUT",
|
|
770
781
|
path: "tool:get-upload-url",
|
|
771
782
|
searchKeywords: "upload attachment attach file draft email attach file event large attachment send file out-of-band upload url",
|
|
772
|
-
description: 'Mint a short-lived, single-use URL that this server serves for uploading a file as an attachment to a draft message or an event, so the bytes go straight from the caller to Microsoft Graph instead of passing as base64 through the agent context. target is the attachments collection of the item: /me/messages/{message-id}/attachments (a draft; create it first) or /me/events/{event-id}/attachments. PUT the raw file bytes to the returned uploadUrl with a Content-Length (e.g. curl -T file "<uploadUrl>"); the response confirms the attachment. Files under 3 MB are attached directly, larger ones (up to 150 MB) through a Graph upload session. Requires --enable-attachment-urls. Returns { uploadUrl, method, expiresAt, singleUse, maxBytes }.',
|
|
783
|
+
description: 'Mint a short-lived, single-use URL that this server serves for uploading a file as an attachment to a draft message or an event, so the bytes go straight from the caller to Microsoft Graph instead of passing as base64 through the agent context. target is the attachments collection of the item: /me/messages/{message-id}/attachments (a draft; create it first) or /me/events/{event-id}/attachments. PUT the raw file bytes to the returned uploadUrl with a Content-Length (e.g. curl -T file "<uploadUrl>"); the response confirms the attachment. Files under 3 MB are attached directly, larger ones (up to 150 MB) through a Graph upload session. Pass contentId to attach inline, e.g. a signature picture the HTML body shows with <img src="cid:<contentId>">. Requires --enable-attachment-urls. Returns { uploadUrl, method, expiresAt, singleUse, maxBytes }.',
|
|
773
784
|
readOnlyHint: false,
|
|
774
785
|
openWorldHint: true,
|
|
775
786
|
buildSchema: (ctx) => {
|
|
@@ -780,7 +791,8 @@ const UTILITY_TOOLS = [
|
|
|
780
791
|
name: z.string().describe("Attachment file name as the recipient will see it, e.g. report.pdf"),
|
|
781
792
|
contentType: z.string().optional().describe(
|
|
782
793
|
"MIME type of the file, e.g. application/pdf. Defaults to application/octet-stream."
|
|
783
|
-
)
|
|
794
|
+
),
|
|
795
|
+
contentId: contentIdSchema
|
|
784
796
|
};
|
|
785
797
|
if (ctx.multiAccount) {
|
|
786
798
|
schema["account"] = z.string().optional().describe(
|
|
@@ -804,7 +816,8 @@ const UTILITY_TOOLS = [
|
|
|
804
816
|
name,
|
|
805
817
|
contentType,
|
|
806
818
|
params.account,
|
|
807
|
-
authManager
|
|
819
|
+
authManager,
|
|
820
|
+
optionalContentId(params.contentId)
|
|
808
821
|
);
|
|
809
822
|
}
|
|
810
823
|
},
|
|
@@ -831,7 +844,8 @@ const UTILITY_TOOLS = [
|
|
|
831
844
|
),
|
|
832
845
|
contentType: z.string().optional().describe(
|
|
833
846
|
"MIME type of the file, e.g. application/pdf. Defaults to application/octet-stream."
|
|
834
|
-
)
|
|
847
|
+
),
|
|
848
|
+
contentId: contentIdSchema
|
|
835
849
|
};
|
|
836
850
|
if (ctx.multiAccount) {
|
|
837
851
|
schema["account"] = z.string().optional().describe(
|
|
@@ -857,6 +871,10 @@ const UTILITY_TOOLS = [
|
|
|
857
871
|
if (!UPLOAD_CONTENT_TYPE.test(contentType)) {
|
|
858
872
|
return uploadError("contentType must be a MIME type such as application/pdf.");
|
|
859
873
|
}
|
|
874
|
+
const contentId = optionalContentId(params.contentId);
|
|
875
|
+
if (contentId !== void 0 && !UPLOAD_CONTENT_ID.test(contentId)) {
|
|
876
|
+
return uploadError(UPLOAD_CONTENT_ID_ERROR);
|
|
877
|
+
}
|
|
860
878
|
const name = cleanAttachmentName(
|
|
861
879
|
typeof params.name === "string" && params.name.trim().length > 0 ? params.name : path.basename(filePath)
|
|
862
880
|
);
|
|
@@ -882,7 +900,14 @@ const UTILITY_TOOLS = [
|
|
|
882
900
|
}
|
|
883
901
|
const created = await uploadAttachment(
|
|
884
902
|
graphClient,
|
|
885
|
-
{
|
|
903
|
+
{
|
|
904
|
+
target,
|
|
905
|
+
name,
|
|
906
|
+
contentType,
|
|
907
|
+
size: file.size,
|
|
908
|
+
accessToken: accountAccessToken,
|
|
909
|
+
contentId
|
|
910
|
+
},
|
|
886
911
|
// end pins the read to the size that was declared, should the file grow meanwhile
|
|
887
912
|
file.handle.createReadStream({
|
|
888
913
|
autoClose: false,
|
|
@@ -19,7 +19,8 @@ async function putChunk(uploadUrl, chunk, start, total) {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
async function uploadAttachment(graphClient, upload, source) {
|
|
22
|
-
const { target, name, contentType, size, accessToken } = upload;
|
|
22
|
+
const { target, name, contentType, size, accessToken, contentId } = upload;
|
|
23
|
+
const inline = contentId ? { isInline: true, contentId } : {};
|
|
23
24
|
if (size < INLINE_UPLOAD_LIMIT) {
|
|
24
25
|
const chunks = [];
|
|
25
26
|
let received = 0;
|
|
@@ -36,7 +37,8 @@ async function uploadAttachment(graphClient, upload, source) {
|
|
|
36
37
|
"@odata.type": "#microsoft.graph.fileAttachment",
|
|
37
38
|
name,
|
|
38
39
|
contentType,
|
|
39
|
-
contentBytes: Buffer.concat(chunks).toString("base64")
|
|
40
|
+
contentBytes: Buffer.concat(chunks).toString("base64"),
|
|
41
|
+
...inline
|
|
40
42
|
})
|
|
41
43
|
});
|
|
42
44
|
return { id: created?.id };
|
|
@@ -45,7 +47,7 @@ async function uploadAttachment(graphClient, upload, source) {
|
|
|
45
47
|
method: "POST",
|
|
46
48
|
accessToken,
|
|
47
49
|
body: JSON.stringify({
|
|
48
|
-
AttachmentItem: { attachmentType: "file", name, size, contentType }
|
|
50
|
+
AttachmentItem: { attachmentType: "file", name, size, contentType, ...inline }
|
|
49
51
|
})
|
|
50
52
|
});
|
|
51
53
|
if (!session?.uploadUrl) throw new Error("Upload session returned no uploadUrl");
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@softeria/ms-365-mcp-server",
|
|
3
3
|
"mcpName": "io.github.Softeria/ms-365-mcp-server",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.172.0",
|
|
5
5
|
"description": " A Model Context Protocol (MCP) server for interacting with Microsoft 365 and Office services through the Graph API",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "dist/index.js",
|