@softeria/ms-365-mcp-server 0.180.5 → 0.180.7

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/Dockerfile CHANGED
@@ -13,10 +13,11 @@ FROM node:24-alpine AS release
13
13
 
14
14
  WORKDIR /app
15
15
 
16
- COPY --from=builder /app/dist /app/dist
17
16
  COPY --from=builder /app/package*.json ./
18
17
 
19
18
  ENV NODE_ENV=production
20
19
  RUN npm ci --ignore-scripts --omit=dev
21
20
 
21
+ COPY --from=builder /app/dist /app/dist
22
+
22
23
  ENTRYPOINT ["node", "dist/index.js"]
@@ -2630,7 +2630,11 @@
2630
2630
  "presets": ["teams", "work"],
2631
2631
  "workScopes": ["OnlineMeetingTranscript.Read.All"],
2632
2632
  "acceptType": "text/vtt",
2633
- "llmTip": "Returns the transcript content in WebVTT format with speaker identification and timestamps."
2633
+ "acceptFallback": {
2634
+ "innerErrorCode": "SpeakerAttributionNotAllowed",
2635
+ "accept": "application/vnd.microsoft.graph.transcript+text"
2636
+ },
2637
+ "llmTip": "Returns the transcript content in WebVTT format with speaker identification and timestamps. When the tenant disables speaker attribution, the server retries once and returns timestamped text without speaker names."
2634
2638
  },
2635
2639
  {
2636
2640
  "pathPattern": "/me/adhocCalls/getAllTranscripts(userId='{userId}',startDateTime={startDateTime},endDateTime={endDateTime})",
@@ -2648,7 +2652,11 @@
2648
2652
  "presets": ["teams", "work"],
2649
2653
  "workScopes": ["CallTranscripts.Read.All"],
2650
2654
  "acceptType": "text/vtt",
2651
- "llmTip": "Returns the transcript of an ad hoc call as WebVTT with speaker tags and timestamps. Take adhocCallId (the callId) and callTranscriptId (the id) from list-adhoc-call-transcripts; copy both exactly. On 403 SpeakerAttributionNotAllowed retry with Accept set to application/vnd.microsoft.graph.transcript+text."
2655
+ "acceptFallback": {
2656
+ "innerErrorCode": "SpeakerAttributionNotAllowed",
2657
+ "accept": "application/vnd.microsoft.graph.transcript+text"
2658
+ },
2659
+ "llmTip": "Returns the transcript of an ad hoc call as WebVTT with speaker tags and timestamps. Take adhocCallId (the callId) and callTranscriptId (the id) from list-adhoc-call-transcripts; copy both exactly. Falls back to text without speaker names when the tenant disables speaker attribution."
2652
2660
  },
2653
2661
  {
2654
2662
  "pathPattern": "/me/onlineMeetings/{onlineMeeting-id}/recordings",
@@ -34,6 +34,21 @@ function isBinaryContentType(contentType) {
34
34
  }
35
35
  return false;
36
36
  }
37
+ function graphInnerErrorCodes(errorText) {
38
+ let error;
39
+ try {
40
+ error = JSON.parse(errorText)?.error;
41
+ } catch {
42
+ return [];
43
+ }
44
+ const codes = [];
45
+ let node = error?.innerError ?? error?.innererror;
46
+ while (node && typeof node === "object") {
47
+ if (typeof node.code === "string") codes.push(node.code);
48
+ node = node.innerError ?? node.innererror;
49
+ }
50
+ return codes;
51
+ }
37
52
  class GraphApiError extends Error {
38
53
  constructor(message, httpStatus, graphErrorCode) {
39
54
  super(message);
@@ -166,9 +181,15 @@ class GraphClient {
166
181
  throw new Error("No access token available");
167
182
  }
168
183
  try {
169
- const response = await this.performRequest(endpoint, accessToken, options);
170
- if (response.status === 403) {
171
- throw await this.createGraphApiError(response);
184
+ let response = await this.performRequest(endpoint, accessToken, options);
185
+ if (response.status === 403 && options.acceptFallback) {
186
+ response = await this.retryWithAcceptFallback(
187
+ endpoint,
188
+ accessToken,
189
+ options,
190
+ options.acceptFallback,
191
+ response
192
+ );
172
193
  }
173
194
  if (!response.ok) {
174
195
  throw await this.createGraphApiError(response);
@@ -334,22 +355,48 @@ class GraphClient {
334
355
  return "This tool requires organization mode. Please restart with --org-mode flag.";
335
356
  }
336
357
  async createGraphApiError(response) {
337
- const errorText = await response.text();
358
+ return this.buildGraphApiError(response, await response.text());
359
+ }
360
+ // `note` names a retry in the message, so a failed fallback is not mistaken for the first call.
361
+ buildGraphApiError(response, errorText, note = "") {
338
362
  const graphErrorCode = extractGraphErrorCode(errorText);
339
363
  const isPermissionOrScopeError = errorText.includes("scope") || errorText.includes("permission");
340
364
  if (response.status === 403 && isPermissionOrScopeError) {
341
365
  return new GraphApiError(
342
- `Microsoft Graph API scope error: ${response.status} ${response.statusText} - ${errorText}. ${this.scopeErrorHint()}`,
366
+ `Microsoft Graph API scope error: ${response.status} ${response.statusText}${note} - ${errorText}. ${this.scopeErrorHint()}`,
343
367
  response.status,
344
368
  graphErrorCode
345
369
  );
346
370
  }
347
371
  return new GraphApiError(
348
- `Microsoft Graph API error: ${response.status} ${response.statusText} - ${errorText}`,
372
+ `Microsoft Graph API error: ${response.status} ${response.statusText}${note} - ${errorText}`,
349
373
  response.status,
350
374
  graphErrorCode
351
375
  );
352
376
  }
377
+ // On a 403 whose innerError chain carries the endpoint's fallback code, retry once with
378
+ // the fallback Accept. Returns the retry's response when it succeeds; throws otherwise.
379
+ async retryWithAcceptFallback(endpoint, accessToken, options, fallback, response) {
380
+ const errorText = await response.text();
381
+ if (!graphInnerErrorCodes(errorText).includes(fallback.innerErrorCode) || options.headers?.["Accept"]?.toLowerCase() === fallback.accept.toLowerCase()) {
382
+ throw this.buildGraphApiError(response, errorText);
383
+ }
384
+ logger.info(
385
+ `Graph refused the requested representation (${fallback.innerErrorCode}); retrying once with Accept: ${fallback.accept}`
386
+ );
387
+ const retry = await this.performRequest(endpoint, accessToken, {
388
+ ...options,
389
+ headers: { ...options.headers, Accept: fallback.accept }
390
+ });
391
+ if (!retry.ok) {
392
+ throw this.buildGraphApiError(
393
+ retry,
394
+ await retry.text(),
395
+ ` (after retrying with Accept: ${fallback.accept} on ${fallback.innerErrorCode})`
396
+ );
397
+ }
398
+ return retry;
399
+ }
353
400
  async performRequest(endpoint, accessToken, options) {
354
401
  const apiVersion = options.apiVersion || "v1.0";
355
402
  const url = `${getGraphBaseUrl(this.secrets.cloudType)}/${apiVersion}${endpoint}`;
@@ -509,6 +556,7 @@ export {
509
556
  GraphApiError,
510
557
  graph_client_default as default,
511
558
  getBlobMaxBytes,
559
+ graphInnerErrorCodes,
512
560
  isBinaryContentType,
513
561
  isBlobOutputEnabled
514
562
  };
@@ -16,7 +16,10 @@ import {
16
16
  } from "./auth.js";
17
17
  import { api as betaApi } from "./generated/client-beta.js";
18
18
  import { api } from "./generated/client.js";
19
- import { getBlobMaxBytes, isBlobOutputEnabled } from "./graph-client.js";
19
+ import {
20
+ getBlobMaxBytes,
21
+ isBlobOutputEnabled
22
+ } from "./graph-client.js";
20
23
  import { getAttachmentMinting } from "./lib/attachment-minting.js";
21
24
  import { MAX_UPLOAD_BYTES, uploadAttachment } from "./lib/attachment-upload.js";
22
25
  import { getUploadDirs, openUploadFile } from "./lib/upload-dirs.js";
@@ -73,6 +76,12 @@ import {
73
76
  validateMailTextArgs
74
77
  } from "./lib/mail-text.js";
75
78
  import { describeToolSchema, describeUtilityToolSchema } from "./lib/tool-schema.js";
79
+ import {
80
+ ACCEPT_VALUE_ERROR,
81
+ ACCEPT_VALUE_MAX_LENGTH,
82
+ ACCEPT_VALUE_PATTERN,
83
+ isAcceptValue
84
+ } from "./lib/media-type.js";
76
85
  import {
77
86
  restrictUserFieldQuery,
78
87
  restrictUserFieldUrl,
@@ -823,6 +832,23 @@ async function mintDownloadUrl(target, accountParam, authManager, probeWith) {
823
832
  ]
824
833
  };
825
834
  }
835
+ function acceptValueSchema() {
836
+ return z.string().max(ACCEPT_VALUE_MAX_LENGTH).regex(ACCEPT_VALUE_PATTERN, ACCEPT_VALUE_ERROR).optional();
837
+ }
838
+ function acceptParamSchema() {
839
+ return acceptValueSchema().describe(
840
+ "Optional Accept header. Set only when Graph asks for another format (transcript content: application/vnd.microsoft.graph.transcript+text)."
841
+ );
842
+ }
843
+ function invalidAcceptResult(accept) {
844
+ if (accept == null || typeof accept === "string" && isAcceptValue(accept)) {
845
+ return void 0;
846
+ }
847
+ return {
848
+ content: [{ type: "text", text: JSON.stringify({ error: ACCEPT_VALUE_ERROR }) }],
849
+ isError: true
850
+ };
851
+ }
826
852
  const UTILITY_TOOLS = [
827
853
  {
828
854
  name: "get-upload-url",
@@ -1164,7 +1190,8 @@ const UTILITY_TOOLS = [
1164
1190
  ),
1165
1191
  fileName: z.string().optional().describe(
1166
1192
  "Name of the file, used as the last segment of the returned resource URI when the server runs with blob output. Optional."
1167
- )
1193
+ ),
1194
+ accept: acceptParamSchema()
1168
1195
  };
1169
1196
  if (ctx.multiAccount) {
1170
1197
  schema["account"] = z.string().optional().describe(
@@ -1204,6 +1231,9 @@ const UTILITY_TOOLS = [
1204
1231
  if (alteredTarget) return alteredTarget;
1205
1232
  const restrictedTarget = userProfilePassthroughError(target, userFields);
1206
1233
  if (restrictedTarget) return restrictedTarget;
1234
+ const acceptError = invalidAcceptResult(params.accept);
1235
+ if (acceptError) return acceptError;
1236
+ const accept = params.accept;
1207
1237
  try {
1208
1238
  const accountModeError = await checkAccountParamInBearerMode(accountParam, authManager);
1209
1239
  if (accountModeError) {
@@ -1226,7 +1256,8 @@ const UTILITY_TOOLS = [
1226
1256
  accessToken: accountAccessToken,
1227
1257
  rawResponse: true,
1228
1258
  forceBinary: true,
1229
- ...blob
1259
+ ...blob,
1260
+ ...accept ? { headers: { Accept: accept } } : {}
1230
1261
  });
1231
1262
  } catch (error) {
1232
1263
  return {
@@ -1256,7 +1287,8 @@ const UTILITY_TOOLS = [
1256
1287
  ),
1257
1288
  outputPath: z.string().describe(
1258
1289
  "Absolute path on the server's filesystem where the bytes are written, e.g. /Users/me/downloads/invoice.pdf. Must be absolute; relative paths are rejected. The parent directory must already exist, and an existing file is never overwritten (the call errors if outputPath already exists)."
1259
- )
1290
+ ),
1291
+ accept: acceptParamSchema()
1260
1292
  };
1261
1293
  if (ctx.multiAccount) {
1262
1294
  schema["account"] = z.string().optional().describe(
@@ -1310,6 +1342,9 @@ const UTILITY_TOOLS = [
1310
1342
  if (alteredTarget) return alteredTarget;
1311
1343
  const restrictedTarget = userProfilePassthroughError(target, userFields);
1312
1344
  if (restrictedTarget) return restrictedTarget;
1345
+ const acceptError = invalidAcceptResult(params.accept);
1346
+ if (acceptError) return acceptError;
1347
+ const accept = params.accept;
1313
1348
  if (!path.isAbsolute(outputPath)) {
1314
1349
  return {
1315
1350
  content: [
@@ -1353,7 +1388,8 @@ const UTILITY_TOOLS = [
1353
1388
  accountAccessToken = await authManager.getTokenForAccount(accountParam);
1354
1389
  }
1355
1390
  const result = await graphClient.downloadToFile(target, outputPath, {
1356
- accessToken: accountAccessToken
1391
+ accessToken: accountAccessToken,
1392
+ ...accept ? { headers: { Accept: accept } } : {}
1357
1393
  });
1358
1394
  return {
1359
1395
  content: [
@@ -1964,7 +2000,12 @@ async function executeGraphTool(tool, config, graphClient, params, authManager,
1964
2000
  path2 = path2.replace(`{${paramName}}`, () => encodedValue).replace(`:${paramName}`, () => encodedValue).replace(`{${camelCaseParamName}}`, () => encodedValue).replace(`:${camelCaseParamName}`, () => encodedValue);
1965
2001
  logger.info(`Path param fallback: replaced :${camelCaseParamName} with encoded value`);
1966
2002
  } else if (paramName.toLowerCase() === "accept" && config?.acceptType) {
1967
- headers["Accept"] = `${paramValue}`;
2003
+ if (paramValue !== "" && paramValue != null) {
2004
+ if (typeof paramValue !== "string" || !isAcceptValue(paramValue)) {
2005
+ throw new Error(ACCEPT_VALUE_ERROR);
2006
+ }
2007
+ headers["Accept"] = paramValue;
2008
+ }
1968
2009
  } else if (isOdataParam) {
1969
2010
  queryParams[fixedParamName] = `${paramValue}`;
1970
2011
  logger.info(`OData param fallback: forwarded ${fixedParamName}=${paramValue}`);
@@ -2075,6 +2116,10 @@ async function executeGraphTool(tool, config, graphClient, params, authManager,
2075
2116
  headers["Accept"] = config.acceptType;
2076
2117
  logger.info(`Setting custom Accept: ${config.acceptType}`);
2077
2118
  }
2119
+ const acceptFallback = (
2120
+ // Media types compare case-insensitively (RFC 9110 §8.3.1).
2121
+ config?.acceptType && headers["Accept"]?.toLowerCase() === config.acceptType.toLowerCase() && queryParams["$format"] === void 0 ? config.acceptFallback : void 0
2122
+ );
2078
2123
  const requestedSelect = parseSelectFields(queryParams["$select"]);
2079
2124
  const enforcement = userFields === void 0 ? "none" : userFieldEnforcement(path2);
2080
2125
  const isUserFieldBoundary = enforcement !== "none";
@@ -2103,7 +2148,8 @@ async function executeGraphTool(tool, config, graphClient, params, authManager,
2103
2148
  }
2104
2149
  const options = {
2105
2150
  method: tool.method.toUpperCase(),
2106
- headers
2151
+ headers,
2152
+ ...acceptFallback ? { acceptFallback } : {}
2107
2153
  };
2108
2154
  if (config?.fixedBody) {
2109
2155
  body = { ...config.fixedBody };
@@ -2404,7 +2450,9 @@ function registerGraphToolWithMcp(server, tool, endpointConfig, graphClient, opt
2404
2450
  }
2405
2451
  }
2406
2452
  if (endpointConfig?.acceptType && paramSchema["Accept"] === void 0) {
2407
- paramSchema["Accept"] = z.string().optional().describe(getAcceptParamDescription(endpointConfig.acceptType));
2453
+ paramSchema["Accept"] = acceptValueSchema().describe(
2454
+ getAcceptParamDescription(endpointConfig.acceptType)
2455
+ );
2408
2456
  }
2409
2457
  if (endpointConfig?.blobOutput && paramSchema["fileName"] === void 0) {
2410
2458
  paramSchema["fileName"] = z.string().optional().describe(
@@ -0,0 +1,18 @@
1
+ const ACCEPT_VALUE_PATTERN = /^(?:[\x21-\x7E](?:[\x20-\x7E]*[\x21-\x7E])?)?$/;
2
+ const ACCEPT_VALUE_MAX_LENGTH = 256;
3
+ const ACCEPT_VALUE_ERROR = `Accept must be a printable header value of at most ${ACCEPT_VALUE_MAX_LENGTH} characters, e.g. text/vtt.`;
4
+ function isAcceptValue(value) {
5
+ return value.length <= ACCEPT_VALUE_MAX_LENGTH && ACCEPT_VALUE_PATTERN.test(value);
6
+ }
7
+ const ACCEPT_VALUE_JSON_SCHEMA = {
8
+ type: "string",
9
+ pattern: ACCEPT_VALUE_PATTERN.source,
10
+ maxLength: ACCEPT_VALUE_MAX_LENGTH
11
+ };
12
+ export {
13
+ ACCEPT_VALUE_ERROR,
14
+ ACCEPT_VALUE_JSON_SCHEMA,
15
+ ACCEPT_VALUE_MAX_LENGTH,
16
+ ACCEPT_VALUE_PATTERN,
17
+ isAcceptValue
18
+ };
@@ -71,7 +71,7 @@ const CONFIRM_PARAM_DESCRIPTION = 'For destructive operations when the confirm g
71
71
  const TIMEZONE_PARAM_DESCRIPTION = 'IANA timezone name (e.g., "America/New_York", "Europe/London", "Asia/Tokyo") for calendar event times. If not specified, times are returned in UTC.';
72
72
  const EXPAND_EXTENDED_PROPERTIES_PARAM_DESCRIPTION = "When true, expands singleValueExtendedProperties on each event. Use this to retrieve custom extended properties (e.g., sync metadata) stored on calendar events.";
73
73
  function getAcceptParamDescription(acceptType) {
74
- return `Accept header for the response representation. Defaults to "${acceptType}". Only set this when Graph asks for a different format \u2014 e.g. a 403 SpeakerAttributionNotAllowed on transcript content names the media type to retry with.`;
74
+ return `Accept header for the response representation. Defaults to "${acceptType}". Leave unset unless you need a different format.`;
75
75
  }
76
76
  function getAccountParamDescription(accountNames) {
77
77
  const accountHint = accountNames.length > 0 ? `Known accounts: ${accountNames.join(", ")}. ` : "";
@@ -2,6 +2,7 @@ import { z } from "zod";
2
2
  import { queryParameterSchema } from "./query-parameter-schema.js";
3
3
  import { tidyToolJsonSchema, zodToToolJsonSchema } from "../normalize-tool-schema.js";
4
4
  import { isDestructiveOperation } from "./destructive-ops.js";
5
+ import { ACCEPT_VALUE_JSON_SCHEMA } from "./media-type.js";
5
6
  import {
6
7
  isFetchAllPagesApplicable,
7
8
  isSkiptokenApplicable,
@@ -140,7 +141,7 @@ function describeToolSchema(tool, config, ctx = {}) {
140
141
  in: "Header",
141
142
  required: false,
142
143
  description: getAcceptParamDescription(config.acceptType),
143
- schema: { type: "string" }
144
+ schema: { ...ACCEPT_VALUE_JSON_SCHEMA }
144
145
  });
145
146
  }
146
147
  const llmTip = config?.llmTip;
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.180.5",
4
+ "version": "0.180.7",
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",
@@ -2630,7 +2630,11 @@
2630
2630
  "presets": ["teams", "work"],
2631
2631
  "workScopes": ["OnlineMeetingTranscript.Read.All"],
2632
2632
  "acceptType": "text/vtt",
2633
- "llmTip": "Returns the transcript content in WebVTT format with speaker identification and timestamps."
2633
+ "acceptFallback": {
2634
+ "innerErrorCode": "SpeakerAttributionNotAllowed",
2635
+ "accept": "application/vnd.microsoft.graph.transcript+text"
2636
+ },
2637
+ "llmTip": "Returns the transcript content in WebVTT format with speaker identification and timestamps. When the tenant disables speaker attribution, the server retries once and returns timestamped text without speaker names."
2634
2638
  },
2635
2639
  {
2636
2640
  "pathPattern": "/me/adhocCalls/getAllTranscripts(userId='{userId}',startDateTime={startDateTime},endDateTime={endDateTime})",
@@ -2648,7 +2652,11 @@
2648
2652
  "presets": ["teams", "work"],
2649
2653
  "workScopes": ["CallTranscripts.Read.All"],
2650
2654
  "acceptType": "text/vtt",
2651
- "llmTip": "Returns the transcript of an ad hoc call as WebVTT with speaker tags and timestamps. Take adhocCallId (the callId) and callTranscriptId (the id) from list-adhoc-call-transcripts; copy both exactly. On 403 SpeakerAttributionNotAllowed retry with Accept set to application/vnd.microsoft.graph.transcript+text."
2655
+ "acceptFallback": {
2656
+ "innerErrorCode": "SpeakerAttributionNotAllowed",
2657
+ "accept": "application/vnd.microsoft.graph.transcript+text"
2658
+ },
2659
+ "llmTip": "Returns the transcript of an ad hoc call as WebVTT with speaker tags and timestamps. Take adhocCallId (the callId) and callTranscriptId (the id) from list-adhoc-call-transcripts; copy both exactly. Falls back to text without speaker names when the tenant disables speaker attribution."
2652
2660
  },
2653
2661
  {
2654
2662
  "pathPattern": "/me/onlineMeetings/{onlineMeeting-id}/recordings",