@softeria/ms-365-mcp-server 0.188.1 → 0.189.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/README.md CHANGED
@@ -1086,6 +1086,20 @@ whatever the outcome, and the upload is attached as the identity that minted it,
1086
1086
  downloads are fetched. An upload ticket presented to `GET` (or a download ticket to `PUT`)
1087
1087
  is refused with the same 404 as any other bad ticket.
1088
1088
 
1089
+ ### Several files in one call
1090
+
1091
+ An agent that moves many files would otherwise spend one tool call per file. Both tools
1092
+ take a list instead of a single entry: `get-download-url` takes `targets`, up to 20 paths of
1093
+ the form `target` takes, and `get-upload-url` takes `files`, up to 20 entries with the
1094
+ fields of a single upload (`target`, `name`, and the optional `contentType`, `contentId`
1095
+ and `conflictBehavior`). Each entry is checked and minted exactly as a single call would be.
1096
+ The result is `{ "results": [...] }`, one item per entry in the order given, naming its
1097
+ `target` (and `name`) next to its URL or its `error`; the call is an error only when every
1098
+ entry failed. Every URL this server mints keeps its own single use and TTL (two minutes by
1099
+ default), and a transfer has to start before its URL expires, so mint a list right before
1100
+ the transfers and start them all at once, in parallel or in one command, rather than one
1101
+ after another.
1102
+
1089
1103
  ### Attaching a local file in stdio mode
1090
1104
 
1091
1105
  In stdio mode the server and the files are on the same machine, so no URL is needed.
@@ -841,6 +841,7 @@ async function mintUploadUrl(target, name, contentType, accountParam, authManage
841
841
  expiresAt: new Date(ticket.expiresAtMs).toISOString(),
842
842
  singleUse: true,
843
843
  maxBytes: MAX_UPLOAD_BYTES,
844
+ name: cleanName,
844
845
  ...drive && { conflictBehavior: drive.conflictBehavior },
845
846
  note: 'PUT the raw file bytes with a Content-Length (e.g. curl -T <file> "<uploadUrl>"). Served by this server; valid for one upload until it expires.'
846
847
  })
@@ -999,17 +1000,86 @@ function invalidAcceptResult(accept) {
999
1000
  isError: true
1000
1001
  };
1001
1002
  }
1003
+ const MAX_TRANSFER_ENTRIES = 20;
1004
+ function withTransferList(listKey, entryParams, single) {
1005
+ const listError = (message) => ({
1006
+ content: [{ type: "text", text: JSON.stringify({ error: message }) }],
1007
+ isError: true
1008
+ });
1009
+ return async (params, ctx) => {
1010
+ const list = params[listKey];
1011
+ if (list == null) return single(params, ctx);
1012
+ if (!Array.isArray(list) || list.length === 0 || list.length > MAX_TRANSFER_ENTRIES) {
1013
+ return listError(`${listKey} must be a list of 1 to ${MAX_TRANSFER_ENTRIES} entries.`);
1014
+ }
1015
+ const mixed = Object.keys(params).filter(
1016
+ (key) => key !== listKey && key !== "account" && params[key] != null && params[key] !== ""
1017
+ );
1018
+ if (mixed.length > 0) {
1019
+ return listError(
1020
+ `With ${listKey}, give every other field inside its entries, not next to it (got ${mixed.join(", ")}).`
1021
+ );
1022
+ }
1023
+ const results = [];
1024
+ let failed = 0;
1025
+ for (const entry of list) {
1026
+ const entryInput = entryParams(entry);
1027
+ let result;
1028
+ try {
1029
+ result = await single({ ...entryInput, account: params.account }, ctx);
1030
+ } catch (error) {
1031
+ const message = error instanceof Error ? error.message : String(error);
1032
+ result = {
1033
+ content: [{ type: "text", text: JSON.stringify({ error: message || "Failed." }) }],
1034
+ isError: true
1035
+ };
1036
+ }
1037
+ const text = result.content?.[0]?.type === "text" ? result.content[0].text : "";
1038
+ let body;
1039
+ try {
1040
+ body = JSON.parse(text);
1041
+ } catch {
1042
+ body = void 0;
1043
+ }
1044
+ let entryFailed = result.isError === true;
1045
+ if (typeof body !== "object" || body === null || Array.isArray(body)) {
1046
+ body = { error: text || "No result." };
1047
+ entryFailed = true;
1048
+ }
1049
+ if (entryFailed) failed++;
1050
+ results.push({
1051
+ target: entryInput.target,
1052
+ ...entryInput.name !== void 0 && { name: entryInput.name },
1053
+ ...body
1054
+ });
1055
+ }
1056
+ return {
1057
+ content: [{ type: "text", text: JSON.stringify({ results }) }],
1058
+ // For the audit log: how many links this call handed out
1059
+ _meta: { result_count: list.length - failed },
1060
+ ...failed === list.length && { isError: true }
1061
+ };
1062
+ };
1063
+ }
1064
+ function uploadEntryParams(entry) {
1065
+ if (typeof entry !== "object" || entry === null) return {};
1066
+ const { target, name, contentType, contentId, conflictBehavior } = entry;
1067
+ return { target, name, contentType, contentId, conflictBehavior };
1068
+ }
1069
+ function downloadEntryParams(entry) {
1070
+ return { target: entry };
1071
+ }
1002
1072
  const UTILITY_TOOLS = [
1003
1073
  {
1004
1074
  name: "get-upload-url",
1005
1075
  method: "PUT",
1006
1076
  path: "tool:get-upload-url",
1007
1077
  searchKeywords: "upload attachment attach file draft email attach file event large attachment send file out-of-band upload url upload onedrive file upload sharepoint file",
1008
- 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, or as a file in a OneDrive/SharePoint folder, 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; or a drive folder: /me/drive/root, /me/drive/items/{folder-id}, /drives/{drive-id}/items/{folder-id}, /sites/{site-id}/drive/items/{folder-id}. PUT the raw file bytes to the returned uploadUrl with a Content-Length (e.g. curl -T file "<uploadUrl>"); the response confirms the upload. Up to 150 MB. Pass contentId to attach inline, e.g. a signature picture the HTML body shows with <img src="cid:<contentId>">. For a drive folder, conflictBehavior says what happens when the name is taken (default fail; contentId does not apply). Requires --enable-attachment-urls. Returns { uploadUrl, method, expiresAt, singleUse, maxBytes, conflictBehavior? }.',
1078
+ 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, or as a file in a OneDrive/SharePoint folder, 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; or a drive folder: /me/drive/root, /me/drive/items/{folder-id}, /drives/{drive-id}/items/{folder-id}, /sites/{site-id}/drive/items/{folder-id}. PUT the raw file bytes to the returned uploadUrl with a Content-Length (e.g. curl -T file "<uploadUrl>"); the response confirms the upload. Up to 150 MB. Pass contentId to attach inline, e.g. a signature picture the HTML body shows with <img src="cid:<contentId>">. For a drive folder, conflictBehavior says what happens when the name is taken (default fail; contentId does not apply). Requires --enable-attachment-urls. Returns { uploadUrl, method, expiresAt, singleUse, maxBytes, name, conflictBehavior? }. For several files, pass files (up to 20 entries of target, name and the optional fields) instead: one call returns { results: [...] }, one item per entry with its uploadUrl or its error. The links expire minutes after minting, so start every upload right away, in parallel or in one command.',
1009
1079
  readOnlyHint: false,
1010
1080
  openWorldHint: true,
1011
1081
  buildSchema: (ctx) => {
1012
- const schema = {
1082
+ const entry = {
1013
1083
  target: z.string().describe(
1014
1084
  "Attachments collection of a draft message or an event, e.g. /me/messages/{message-id}/attachments, /me/events/{event-id}/attachments, or /users/{user-id}/messages/{message-id}/attachments for another mailbox. Or a OneDrive/SharePoint folder: /me/drive/root, /me/drive/items/{folder-id}, /drives/{drive-id}/items/{folder-id}, /sites/{site-id}/drive/items/{folder-id}."
1015
1085
  ),
@@ -1024,6 +1094,15 @@ const UTILITY_TOOLS = [
1024
1094
  "Drive folder targets only: what happens when the folder already has a file with this name. fail (default), replace, or rename."
1025
1095
  )
1026
1096
  };
1097
+ const schema = {
1098
+ ...entry,
1099
+ // Optional so that files can stand in for them; execute still requires one form.
1100
+ target: entry.target.optional(),
1101
+ name: entry.name.optional(),
1102
+ files: z.array(z.object(entry)).min(1).max(MAX_TRANSFER_ENTRIES).optional().describe(
1103
+ `Several files at once, instead of target and name: up to ${MAX_TRANSFER_ENTRIES} entries, each with the fields of a single upload.`
1104
+ )
1105
+ };
1027
1106
  if (ctx.multiAccount) {
1028
1107
  schema["account"] = z.string().optional().describe(
1029
1108
  "Account to use when multiple Microsoft accounts are configured. Required when multiple accounts exist (see list-accounts)."
@@ -1031,7 +1110,7 @@ const UTILITY_TOOLS = [
1031
1110
  }
1032
1111
  return schema;
1033
1112
  },
1034
- execute: async (params, { authManager }) => {
1113
+ execute: withTransferList("files", uploadEntryParams, async (params, { authManager }) => {
1035
1114
  const target = params.target;
1036
1115
  const name = params.name;
1037
1116
  if (typeof target !== "string" || target.length === 0) {
@@ -1050,7 +1129,7 @@ const UTILITY_TOOLS = [
1050
1129
  optionalContentId(params.contentId),
1051
1130
  params.conflictBehavior === "" ? void 0 : params.conflictBehavior
1052
1131
  );
1053
- }
1132
+ })
1054
1133
  },
1055
1134
  {
1056
1135
  name: "upload-attachment-from-file",
@@ -1582,13 +1661,17 @@ const UTILITY_TOOLS = [
1582
1661
  method: "GET",
1583
1662
  path: "tool:get-download-url",
1584
1663
  searchKeywords: "download file download drive file download onedrive file sharepoint file download large drive file large sharepoint file large file out-of-band download pre-authenticated url",
1585
- description: "Resolve a short-lived, pre-authenticated download URL for Microsoft Graph binary content that exposes one (drive/SharePoint file content). The returned URL streams the bytes with NO Authorization header, so the client can fetch it straight to disk (e.g. curl) without round-tripping base64 through the agent context. Prefer this over download-bytes for any file above a few KB or any bulk download. Returns { downloadUrl, name?, size?, contentType? }. Mail file attachments (/messages/{id}/attachments/{id}/$value), meeting recordings and other $value byte endpoints have no pre-authenticated URL from Graph itself, but call this tool for them anyway: a server running with --enable-attachment-urls mints its own single-use URL for them, and one without it answers with the reason and points at download-bytes. With --enable-attachment-urls, drive files get a short single-use URL from this server as well, instead of the long one from Graph.",
1664
+ description: "Resolve a short-lived, pre-authenticated download URL for Microsoft Graph binary content that exposes one (drive/SharePoint file content). The returned URL streams the bytes with NO Authorization header, so the client can fetch it straight to disk (e.g. curl) without round-tripping base64 through the agent context. Prefer this over download-bytes for any file above a few KB or any bulk download. Returns { downloadUrl, name?, size?, contentType? }. Mail file attachments (/messages/{id}/attachments/{id}/$value), meeting recordings and other $value byte endpoints have no pre-authenticated URL from Graph itself, but call this tool for them anyway: a server running with --enable-attachment-urls mints its own single-use URL for them, and one without it answers with the reason and points at download-bytes. With --enable-attachment-urls, drive files get a short single-use URL from this server as well, instead of the long one from Graph. For several files, pass targets (up to 20) instead of target: one call returns { results: [...] }, one item per target with its downloadUrl or its error. Server-minted links expire minutes after minting, so start every download right away, in parallel or in one command.",
1586
1665
  readOnlyHint: true,
1587
1666
  openWorldHint: true,
1588
1667
  buildSchema: (ctx) => {
1589
1668
  const schema = {
1590
- target: z.string().describe(
1669
+ // Optional so that targets can stand in for it; execute still requires one form.
1670
+ target: z.string().optional().describe(
1591
1671
  'Relative Microsoft Graph path starting with "/". Either a driveItem content path or the item path itself, e.g. /drives/{drive-id}/items/{driveItem-id}/content, /me/drive/items/{driveItem-id}/content, or /sites/{site-id}/drive/items/{driveItem-id}. A trailing /content is optional and is stripped automatically for drive items. Mail attachment $value paths and meeting recordings are accepted on a server running with --enable-attachment-urls.'
1672
+ ),
1673
+ targets: z.array(z.string()).min(1).max(MAX_TRANSFER_ENTRIES).optional().describe(
1674
+ `Several files at once, instead of target: up to ${MAX_TRANSFER_ENTRIES} paths, each of the form target takes.`
1592
1675
  )
1593
1676
  };
1594
1677
  if (ctx.multiAccount) {
@@ -1598,7 +1681,8 @@ const UTILITY_TOOLS = [
1598
1681
  }
1599
1682
  return schema;
1600
1683
  },
1601
- execute: async (params, { graphClient, authManager, userFields }) => {
1684
+ execute: withTransferList("targets", downloadEntryParams, async (params, context) => {
1685
+ const { graphClient, authManager, userFields } = context;
1602
1686
  const target = params.target;
1603
1687
  const accountParam = params.account;
1604
1688
  if (typeof target !== "string" || target.length === 0) {
@@ -1839,7 +1923,7 @@ const UTILITY_TOOLS = [
1839
1923
  ...Object.keys(metadata).length > 0 ? { _meta: metadata } : {}
1840
1924
  };
1841
1925
  }
1842
- }
1926
+ })
1843
1927
  }
1844
1928
  ];
1845
1929
  function registerUtilityToolWithMcp(server, utility, ctx) {
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.188.1",
4
+ "version": "0.189.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",