@softeria/ms-365-mcp-server 0.184.0 → 0.184.1

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
@@ -954,7 +954,11 @@ SharePoint files get a minted URL too, instead of Graph's own: that one is about
954
954
  characters, too long for an agent that has to type it into a command, such as `curl` in a
955
955
  sandbox that cannot see tool results. A minted URL only
956
956
  works if the preset's scopes cover the resource: a contacts, tasks or excel preset has no Mail
957
- scopes, so a URL minted for a mail attachment fails when fetched.
957
+ scopes, so it cannot read a mail attachment. For a mail or calendar attachment addressed by
958
+ its message or event id (such as `/me/messages/{id}/attachments/{id}/$value`),
959
+ `get-download-url` asks Graph about the attachment first. When Graph rejects the ids, finds no
960
+ such attachment or denies access, it returns Graph's error instead of a URL; otherwise the URL
961
+ comes with the attachment's `name`, `size` and `contentType`, when Graph reports them.
958
962
 
959
963
  The minted URL looks like:
960
964
 
@@ -986,7 +990,7 @@ URL handoff only:
986
990
  {"tool":"list-mail-attachments","arguments":{"messageId":"example-message","select":"id,name,contentType,size,isInline"}}
987
991
  {"value":[{"id":"example-attachment","name":"example.pdf","contentType":"application/pdf","size":75000,"isInline":false}]}
988
992
  {"tool":"get-download-url","arguments":{"target":"/me/messages/example-message/attachments/example-attachment/$value"}}
989
- {"downloadUrl":"<fresh single-use URL>"}
993
+ {"downloadUrl":"<fresh single-use URL>","name":"example.pdf","size":75000,"contentType":"application/pdf"}
990
994
  ```
991
995
 
992
996
  The client gives the returned URL to any external downloader or document-processing MCP
@@ -18,6 +18,7 @@ import { api as betaApi } from "./generated/client-beta.js";
18
18
  import { api } from "./generated/client.js";
19
19
  import {
20
20
  getBlobMaxBytes,
21
+ GraphApiError,
21
22
  isBlobOutputEnabled
22
23
  } from "./graph-client.js";
23
24
  import { getAttachmentMinting } from "./lib/attachment-minting.js";
@@ -841,19 +842,50 @@ async function mintUploadUrl(target, name, contentType, accountParam, authManage
841
842
  };
842
843
  }
843
844
  const MAIL_EVENT_ATTACHMENT_VALUE = /^(?:\/me|\/users\/[^/]+|\/groups\/[^/]+)\/(?:messages|events)\/[^/]+\/attachments\/[^/]+\/\$value$/;
844
- async function probeAttachment(target, graphClient, accessToken) {
845
- if (!MAIL_EVENT_ATTACHMENT_VALUE.test(target)) return {};
845
+ const UNFETCHABLE_ATTACHMENT_STATUSES = /* @__PURE__ */ new Set([400, 403, 404]);
846
+ function isWrongIdCode(code) {
847
+ return code !== void 0 && (code.startsWith("ErrorInvalidId") || code === "ErrorItemNotFound");
848
+ }
849
+ async function probeAttachment(target, graphClient, accessToken, ticketKeepsToken) {
850
+ if (!MAIL_EVENT_ATTACHMENT_VALUE.test(target)) return { probe: {}, fields: {} };
846
851
  try {
847
852
  const meta = await graphClient.makeRequest(
848
- `${target.slice(0, -"/$value".length)}?$select=name,contentType`,
853
+ `${target.slice(0, -"/$value".length)}?$select=name,contentType,size`,
849
854
  { accessToken }
850
855
  );
851
856
  return {
852
- ...typeof meta?.contentType === "string" && { probedContentType: meta.contentType },
853
- ...typeof meta?.name === "string" && { probedName: meta.name }
857
+ probe: {
858
+ ...typeof meta?.contentType === "string" && { probedContentType: meta.contentType },
859
+ ...typeof meta?.name === "string" && { probedName: meta.name }
860
+ },
861
+ fields: {
862
+ ...typeof meta?.name === "string" && { name: meta.name },
863
+ ...typeof meta?.size === "number" && { size: meta.size },
864
+ ...typeof meta?.contentType === "string" && { contentType: meta.contentType }
865
+ }
854
866
  };
855
- } catch {
856
- return {};
867
+ } catch (error) {
868
+ if (error instanceof GraphApiError && (UNFETCHABLE_ATTACHMENT_STATUSES.has(error.httpStatus) || error.httpStatus === 401 && ticketKeepsToken)) {
869
+ const idHint = isWrongIdCode(error.graphErrorCode) ? ' Check the ids in the target: copy them exactly as Graph returned them, including any trailing "=".' : "";
870
+ return {
871
+ refusal: {
872
+ content: [
873
+ {
874
+ type: "text",
875
+ text: JSON.stringify({
876
+ error: `No download URL was made: ${error.message}${idHint}`
877
+ })
878
+ }
879
+ ],
880
+ isError: true,
881
+ _meta: {
882
+ http_status: error.httpStatus,
883
+ ...error.graphErrorCode ? { error_code: error.graphErrorCode } : {}
884
+ }
885
+ }
886
+ };
887
+ }
888
+ return { probe: {}, fields: {} };
857
889
  }
858
890
  }
859
891
  async function mintDownloadUrl(target, accountParam, authManager, probeWith, known) {
@@ -894,11 +926,28 @@ async function mintDownloadUrl(target, accountParam, authManager, probeWith, kno
894
926
  isError: true
895
927
  };
896
928
  }
897
- const probe = known ? known.probe : probeWith ? await probeAttachment(
898
- target,
899
- probeWith,
900
- requestToken ?? await authManager?.getTokenForAccount(accountParam).catch(() => void 0)
901
- ) : {};
929
+ let accountToken;
930
+ if (!requestToken && authManager) {
931
+ try {
932
+ accountToken = await authManager.getTokenForAccount(accountParam);
933
+ } catch (error) {
934
+ return {
935
+ content: [
936
+ {
937
+ type: "text",
938
+ text: JSON.stringify({
939
+ error: `No download URL was made: ${error.message}`
940
+ })
941
+ }
942
+ ],
943
+ isError: true
944
+ };
945
+ }
946
+ }
947
+ const probeToken = requestToken ?? accountToken;
948
+ const probed = known ? known : probeWith && probeToken ? await probeAttachment(target, probeWith, probeToken, Boolean(requestToken)) : void 0;
949
+ if (probed && "refusal" in probed) return probed.refusal;
950
+ const probe = probed?.probe ?? {};
902
951
  let ticket;
903
952
  try {
904
953
  ticket = requestToken ? minting.store.mintWithToken(target, requestToken, void 0, probe) : minting.store.mint(target, accountParam, void 0, probe);
@@ -917,7 +966,7 @@ async function mintDownloadUrl(target, accountParam, authManager, probeWith, kno
917
966
  type: "text",
918
967
  text: JSON.stringify({
919
968
  downloadUrl: buildAttachmentUrl(minting.config, ticket.id),
920
- ...known?.fields,
969
+ ...probed?.fields,
921
970
  expiresAt: new Date(ticket.expiresAtMs).toISOString(),
922
971
  singleUse: true,
923
972
  note: "Served by this server, not by Microsoft Graph. Valid for one fetch until it expires."
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.184.0",
4
+ "version": "0.184.1",
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",