@softeria/ms-365-mcp-server 0.193.2 → 0.193.3

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.
@@ -131,7 +131,11 @@
131
131
  "appScopes": ["Mail.ReadWrite"],
132
132
  "mcpApp": {
133
133
  "view": "mail-draft",
134
- "tools": { "get": "get-shared-mailbox-message", "send": "send-shared-mailbox-draft" }
134
+ "tools": {
135
+ "get": "get-shared-mailbox-message",
136
+ "attachments": "list-shared-mailbox-attachments",
137
+ "send": "send-shared-mailbox-draft"
138
+ }
135
139
  }
136
140
  },
137
141
  {
@@ -190,7 +194,11 @@
190
194
  "llmTip": "Create a reply draft in a shared mailbox preserving thread metadata (conversationId, In-Reply-To, References). The 'user-id' is the shared mailbox email address (e.g. support@contoso.com). Does not send — use send-shared-mailbox-draft to send afterwards. Message.body (contentType 'html' for HTML) replaces the whole draft body, dropping the quoted history; 'comment' keeps it. Specifying both 'comment' and Message.body returns 400.",
191
195
  "mcpApp": {
192
196
  "view": "mail-draft",
193
- "tools": { "get": "get-shared-mailbox-message", "send": "send-shared-mailbox-draft" }
197
+ "tools": {
198
+ "get": "get-shared-mailbox-message",
199
+ "attachments": "list-shared-mailbox-attachments",
200
+ "send": "send-shared-mailbox-draft"
201
+ }
194
202
  }
195
203
  },
196
204
  {
@@ -203,7 +211,11 @@
203
211
  "llmTip": "Create a reply-all draft in a shared mailbox preserving thread metadata (conversationId, In-Reply-To, References). The 'user-id' is the shared mailbox email address. Does not send — use send-shared-mailbox-draft to send afterwards. Message.body (contentType 'html' for HTML) replaces the whole draft body, dropping the quoted history; 'comment' keeps it. Specifying both 'comment' and Message.body returns 400.",
204
212
  "mcpApp": {
205
213
  "view": "mail-draft",
206
- "tools": { "get": "get-shared-mailbox-message", "send": "send-shared-mailbox-draft" }
214
+ "tools": {
215
+ "get": "get-shared-mailbox-message",
216
+ "attachments": "list-shared-mailbox-attachments",
217
+ "send": "send-shared-mailbox-draft"
218
+ }
207
219
  }
208
220
  },
209
221
  {
@@ -216,7 +228,11 @@
216
228
  "llmTip": "Create a forward draft in a shared mailbox without sending. The 'user-id' is the shared mailbox email address. Does not send — use send-shared-mailbox-draft to send afterwards. Useful when the user wants to review before the forward goes out.",
217
229
  "mcpApp": {
218
230
  "view": "mail-draft",
219
- "tools": { "get": "get-shared-mailbox-message", "send": "send-shared-mailbox-draft" }
231
+ "tools": {
232
+ "get": "get-shared-mailbox-message",
233
+ "attachments": "list-shared-mailbox-attachments",
234
+ "send": "send-shared-mailbox-draft"
235
+ }
220
236
  }
221
237
  },
222
238
  {
@@ -268,6 +284,7 @@
268
284
  "pathPattern": "/users/{user-id}/messages/{message-id}/attachments",
269
285
  "method": "get",
270
286
  "toolName": "list-shared-mailbox-attachments",
287
+ "supportsDraftAttachmentInventory": true,
271
288
  "descriptionOverride": "List the attachments on a message in another user's mailbox or a shared mailbox. The user-id is the mailbox owner's ID or email address.",
272
289
  "presets": ["work"],
273
290
  "workScopes": ["Mail.Read.Shared"],
@@ -311,7 +328,11 @@
311
328
  "scopes": ["Mail.ReadWrite"],
312
329
  "mcpApp": {
313
330
  "view": "mail-draft",
314
- "tools": { "get": "get-mail-message", "send": "send-draft-message" }
331
+ "tools": {
332
+ "get": "get-mail-message",
333
+ "attachments": "list-mail-attachments",
334
+ "send": "send-draft-message"
335
+ }
315
336
  }
316
337
  },
317
338
  {
@@ -367,6 +388,7 @@
367
388
  "pathPattern": "/me/messages/{message-id}/attachments",
368
389
  "method": "get",
369
390
  "toolName": "list-mail-attachments",
391
+ "supportsDraftAttachmentInventory": true,
370
392
  "presets": ["mail", "outlook", "personal"],
371
393
  "scopes": ["Mail.Read"],
372
394
  "llmTip": "Lists attachments on a message: id, name, contentType, size, isInline. For document reading with --enable-attachment-urls in HTTP mode, prefer get-download-url and an external converter or downloader. For explicit bytes or without attachment URLs, call download-bytes. Both tools take target=/me/messages/{message-id}/attachments/{attachment-id}/$value (the /$value suffix returns raw bytes; the bare attachment URL embeds contentBytes in JSON which can truncate large files)."
@@ -411,7 +433,11 @@
411
433
  "llmTip": "Create a forward draft (does not send). Useful when user wants to review before sending.",
412
434
  "mcpApp": {
413
435
  "view": "mail-draft",
414
- "tools": { "get": "get-mail-message", "send": "send-draft-message" }
436
+ "tools": {
437
+ "get": "get-mail-message",
438
+ "attachments": "list-mail-attachments",
439
+ "send": "send-draft-message"
440
+ }
415
441
  }
416
442
  },
417
443
  {
@@ -423,7 +449,11 @@
423
449
  "llmTip": "Message.body (contentType 'html' for HTML) replaces the whole draft body, dropping the quoted history; 'comment' keeps it. Specifying both 'comment' and Message.body returns 400. Signatures are added by the Outlook client only, not via Graph.",
424
450
  "mcpApp": {
425
451
  "view": "mail-draft",
426
- "tools": { "get": "get-mail-message", "send": "send-draft-message" }
452
+ "tools": {
453
+ "get": "get-mail-message",
454
+ "attachments": "list-mail-attachments",
455
+ "send": "send-draft-message"
456
+ }
427
457
  }
428
458
  },
429
459
  {
@@ -435,7 +465,11 @@
435
465
  "llmTip": "Message.body (contentType 'html' for HTML) replaces the whole draft body, dropping the quoted history; 'comment' keeps it. Specifying both 'comment' and Message.body returns 400. Signatures are added by the Outlook client only, not via Graph.",
436
466
  "mcpApp": {
437
467
  "view": "mail-draft",
438
- "tools": { "get": "get-mail-message", "send": "send-draft-message" }
468
+ "tools": {
469
+ "get": "get-mail-message",
470
+ "attachments": "list-mail-attachments",
471
+ "send": "send-draft-message"
472
+ }
439
473
  }
440
474
  },
441
475
  {
@@ -96,6 +96,7 @@ import {
96
96
  import { bodyParamSchemas, buildFixedBody } from "./lib/body-params.js";
97
97
  import logger from "./logger.js";
98
98
  import {
99
+ DRAFT_ATTACHMENT_FIELDS,
99
100
  mcpAppResultWithoutBody,
100
101
  mcpAppToolMeta,
101
102
  noteMcpAppTool,
@@ -2146,6 +2147,13 @@ async function executeGraphTool(tool, config, graphClient, params, authManager,
2146
2147
  let targetResource;
2147
2148
  let body = null;
2148
2149
  try {
2150
+ let invalidDraftAttachmentPage2 = function(body2) {
2151
+ const cursor = body2["@odata.nextLink"];
2152
+ return Boolean(
2153
+ body2.truncated || body2.incomplete || Object.hasOwn(body2, "@odata.nextLink") && (typeof cursor !== "string" || !cursor)
2154
+ );
2155
+ };
2156
+ var invalidDraftAttachmentPage = invalidDraftAttachmentPage2;
2149
2157
  const accountParam = params.account;
2150
2158
  const accountModeError = await checkAccountParamInBearerMode(accountParam, authManager);
2151
2159
  if (accountModeError) {
@@ -2442,6 +2450,7 @@ async function executeGraphTool(tool, config, graphClient, params, authManager,
2442
2450
  config?.acceptType && headers["Accept"]?.toLowerCase() === config.acceptType.toLowerCase() && queryParams["$format"] === void 0 ? config.acceptFallback : void 0
2443
2451
  );
2444
2452
  const requestedSelect = parseSelectFields(queryParams["$select"]);
2453
+ const draftAttachmentProjection = config?.supportsDraftAttachmentInventory && queryParams["$select"] === DRAFT_ATTACHMENT_FIELDS && queryParams["$expand"] === void 0;
2445
2454
  const enforcement = userFields === void 0 ? "none" : userFieldEnforcement(path2);
2446
2455
  const isUserFieldBoundary = enforcement !== "none";
2447
2456
  const boundaryFields = isUserFieldBoundary && userFields !== void 0 ? restrictUserFieldQuery(queryParams, userFields, enforcement) : [];
@@ -2565,6 +2574,23 @@ async function executeGraphTool(tool, config, graphClient, params, authManager,
2565
2574
  return filtered;
2566
2575
  };
2567
2576
  const applyProjection = (body2) => {
2577
+ if (draftAttachmentProjection) {
2578
+ if (!isPlainObject(body2) || !Array.isArray(body2.value)) return {};
2579
+ const envelope = ["@odata.nextLink", "@odata.count", "incomplete", "truncated"];
2580
+ const fields = [...requestedSelect, "@odata.type"];
2581
+ return {
2582
+ ...Object.fromEntries(
2583
+ envelope.filter((key) => Object.hasOwn(body2, key)).map((key) => [key, body2[key]])
2584
+ ),
2585
+ value: body2.value.map(
2586
+ (item) => isPlainObject(item) ? Object.fromEntries(
2587
+ fields.filter(
2588
+ (key) => Object.hasOwn(item, key) && (item[key] === null || ["string", "number", "boolean"].includes(typeof item[key]))
2589
+ ).map((key) => [key, item[key]])
2590
+ ) : null
2591
+ )
2592
+ };
2593
+ }
2568
2594
  if (isTransportEnvelope(body2)) {
2569
2595
  logger.info("Skipping $select projection: body is a transport envelope, not a resource");
2570
2596
  return body2;
@@ -2585,6 +2611,9 @@ async function executeGraphTool(tool, config, graphClient, params, authManager,
2585
2611
  if (Array.isArray(firstValue)) {
2586
2612
  let allItems = firstValue;
2587
2613
  let nextLink = combinedResponse["@odata.nextLink"];
2614
+ if (draftAttachmentProjection && invalidDraftAttachmentPage2(combinedResponse)) {
2615
+ combinedResponse.incomplete = true;
2616
+ }
2588
2617
  let pageCount = 1;
2589
2618
  let totalResponseBytes = response._meta?.response_bytes;
2590
2619
  const maxPages = positiveIntFromEnv("MS365_MCP_MAX_PAGES", DEFAULT_MAX_PAGES);
@@ -2593,7 +2622,13 @@ async function executeGraphTool(tool, config, graphClient, params, authManager,
2593
2622
  while (nextLink && pageCount < maxPages && allItems.length < maxItems) {
2594
2623
  logger.info(`Fetching page ${pageCount + 1} from: ${describeUrl(nextLink)}`);
2595
2624
  const url = new URL(nextLink);
2596
- const nextPath = url.pathname.replace(/^\/(v1\.0|beta)/, "") + url.search;
2625
+ const nextEndpoint = url.pathname.replace(/^\/(v1\.0|beta)/, "");
2626
+ if (draftAttachmentProjection) {
2627
+ const sameList = (route) => JSON.stringify(route.split("/").map(decodeURIComponent));
2628
+ if (sameList(nextEndpoint) !== sameList(path2.split("?")[0])) break;
2629
+ url.searchParams.set("$select", DRAFT_ATTACHMENT_FIELDS);
2630
+ }
2631
+ const nextPath = nextEndpoint + url.search;
2597
2632
  const nextOptions = { ...options };
2598
2633
  const nextResponse = await graphClient.graphRequest(nextPath, nextOptions);
2599
2634
  if (nextResponse?.isError) {
@@ -2603,7 +2638,7 @@ async function executeGraphTool(tool, config, graphClient, params, authManager,
2603
2638
  }
2604
2639
  if (nextResponse?.content?.[0]?.text) {
2605
2640
  const nextJsonResponse = JSON.parse(nextResponse.content[0].text);
2606
- if (!Array.isArray(nextJsonResponse.value)) {
2641
+ if (!Array.isArray(nextJsonResponse.value) || draftAttachmentProjection && (invalidDraftAttachmentPage2(nextJsonResponse) || nextResponse._meta?.http_status !== void 0 && nextResponse._meta.http_status !== 200)) {
2607
2642
  logger.warn(
2608
2643
  `Pagination stopped at page ${pageCount + 1}: response was not a collection`
2609
2644
  );
@@ -2877,7 +2912,16 @@ function registerGraphToolWithMcp(server, tool, endpointConfig, graphClient, opt
2877
2912
  return executeGraphTool(tool, endpointConfig, graphClient, params, authManager, userFields);
2878
2913
  }
2879
2914
  );
2880
- if (options.mcpApps) noteMcpAppTool(server, tool.alias, appMeta ? appBinding : void 0);
2915
+ if (options.mcpApps) {
2916
+ const schema = fit?.paramSchema ?? paramSchema;
2917
+ const inventory = endpointConfig?.supportsDraftAttachmentInventory && schema.select?.safeParse(DRAFT_ATTACHMENT_FIELDS.split(",")).success;
2918
+ noteMcpAppTool(
2919
+ server,
2920
+ tool.alias,
2921
+ appMeta ? appBinding : void 0,
2922
+ inventory ? schema.fetchAllPages?.safeParse(true).success === true : void 0
2923
+ );
2924
+ }
2881
2925
  return fit;
2882
2926
  }
2883
2927
  function registerGraphTools(server, graphClient, options = {}) {
package/dist/mcp-apps.js CHANGED
@@ -49,6 +49,7 @@ function fill(page, placeholder, content) {
49
49
  if (!page.includes(placeholder)) throw new Error(`the page has no ${placeholder}`);
50
50
  return page.replace(placeholder, () => content);
51
51
  }
52
+ const DRAFT_ATTACHMENT_FIELDS = "id,name,isInline,contentType,size,lastModifiedDateTime";
52
53
  const servers = /* @__PURE__ */ new WeakMap();
53
54
  function mcpAppToolMeta(binding, toolName) {
54
55
  if (loadPage(binding.view) instanceof Error) return void 0;
@@ -70,13 +71,14 @@ function mcpAppResultWithoutBody(result) {
70
71
  ...body && typeof body === "object" && !Array.isArray(body) ? { structuredContent: body } : {}
71
72
  };
72
73
  }
73
- function noteMcpAppTool(server, toolName, binding) {
74
+ function noteMcpAppTool(server, toolName, binding, attachmentPaging) {
74
75
  let apps = servers.get(server);
75
76
  if (!apps) {
76
- apps = { tools: /* @__PURE__ */ new Set(), bindings: [] };
77
+ apps = { tools: /* @__PURE__ */ new Set(), bindings: [], attachmentPaging: /* @__PURE__ */ new Map() };
77
78
  servers.set(server, apps);
78
79
  }
79
80
  apps.tools.add(toolName);
81
+ if (attachmentPaging !== void 0) apps.attachmentPaging.set(toolName, attachmentPaging);
80
82
  if (binding) apps.bindings.push({ toolName, binding });
81
83
  }
82
84
  function registerMcpAppViews(server) {
@@ -88,9 +90,20 @@ function registerMcpAppViews(server) {
88
90
  if (page instanceof Error) continue;
89
91
  const tools = {};
90
92
  for (const [role, name] of Object.entries(binding.tools ?? {})) {
91
- if (apps.tools.has(name)) tools[role] = name;
93
+ if (binding.view === "mail-draft" && role === "attachments") {
94
+ if (apps.attachmentPaging.has(name)) tools[role] = name;
95
+ } else if (apps.tools.has(name)) tools[role] = name;
92
96
  }
93
- const config = JSON.stringify({ toolName, tools }).replace(/</g, "\\u003c");
97
+ const config = JSON.stringify({
98
+ toolName,
99
+ tools,
100
+ ...binding.view === "mail-draft" && tools.attachments ? {
101
+ attachmentInventory: {
102
+ select: DRAFT_ATTACHMENT_FIELDS.split(","),
103
+ fetchAllPages: apps.attachmentPaging.get(tools.attachments)
104
+ }
105
+ } : {}
106
+ }).replace(/</g, "\\u003c");
94
107
  const html = page.replace(CONFIG_PLACEHOLDER, () => config);
95
108
  const uri = mcpAppUri(binding.view, toolName);
96
109
  try {
@@ -114,6 +127,7 @@ function registerMcpAppViews(server) {
114
127
  }
115
128
  }
116
129
  export {
130
+ DRAFT_ATTACHMENT_FIELDS,
117
131
  MCP_APP_MIME_TYPE,
118
132
  checkMcpAppScript,
119
133
  mcpAppPath,
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.193.2",
4
+ "version": "0.193.3",
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",
@@ -61,18 +61,16 @@
61
61
  border: 1px solid var(--color-border-tertiary, rgba(127, 127, 127, 0.25));
62
62
  border-radius: var(--border-radius-sm, 4px);
63
63
  }
64
+ #attachments,
65
+ #manual {
66
+ margin-top: 8px;
67
+ overflow-wrap: anywhere;
68
+ }
64
69
  .actions {
65
70
  display: flex;
66
71
  gap: 8px;
67
72
  margin-top: 8px;
68
73
  }
69
- .primary {
70
- border: 1px solid transparent;
71
- background: var(--color-text-primary, CanvasText);
72
- color: var(--color-background-primary, Canvas);
73
- padding: 4px 16px;
74
- font-weight: var(--font-weight-semibold, 600);
75
- }
76
74
  .tool {
77
75
  border: 1px solid var(--color-border-secondary, rgba(127, 127, 127, 0.4));
78
76
  background: none;
@@ -88,11 +86,15 @@
88
86
  </style>
89
87
  </head>
90
88
  <body>
91
- <h1 id="subject">Mail draft</h1>
89
+ <h1>Mail draft</h1>
90
+ <p id="subject" hidden></p>
92
91
  <div id="fields" class="fields"></div>
92
+ <p id="body-label" hidden></p>
93
93
  <div id="body" hidden></div>
94
+ <div id="attachments" hidden></div>
95
+ <p id="manual" hidden></p>
94
96
  <div class="actions">
95
- <button id="send" class="primary" type="button" hidden>Send</button>
97
+ <button id="send" class="tool" type="button" hidden disabled>Send</button>
96
98
  <button id="open" class="tool" type="button" hidden>Open in Outlook</button>
97
99
  </div>
98
100
  <p id="status" role="status">Loading...</p>
@@ -100,10 +102,10 @@
100
102
  __MCP_APP_CONFIG__
101
103
  </script>
102
104
  <script>
103
- __MCP_APP_BRIDGE__
105
+ __MCP_APP_BRIDGE__;
104
106
  </script>
105
107
  <script>
106
- __MCP_APP_SCRIPT__
108
+ __MCP_APP_SCRIPT__;
107
109
  </script>
108
110
  </body>
109
111
  </html>