@aidalinfo/m365-mcp 0.4.1 → 0.4.2

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
@@ -664,6 +664,10 @@ snapshot, signals and comparison end to end.
664
664
 
665
665
  ## Validation status
666
666
 
667
+ - 0.4.2: a connection dropped while the answer is read (Node's `terminated`) is retried like a failed
668
+ request, then reported as `transient` with the HTTP status and the Microsoft request-id — it used to
669
+ surface as `unexpected: terminated`, which hid whether Exchange or the network had refused.
670
+
667
671
  - 0.4.1: `M365_EXCHANGE_CLIENT_ID` may equal `M365_WRITE_CLIENT_ID` (warning at startup); every other
668
672
  check unchanged.
669
673
 
@@ -1,6 +1,6 @@
1
1
  import { randomUUID } from "node:crypto";
2
2
  import { M365Error } from "../errors.js";
3
- import { defaultFetcher, defaultSleep, DEFAULT_TIMEOUT_MS } from "../http.js";
3
+ import { bodyError, defaultFetcher, defaultSleep, DEFAULT_TIMEOUT_MS } from "../http.js";
4
4
  import { redactString } from "../redact.js";
5
5
  const RETRY = new Set([429, 502, 503, 504]);
6
6
  const MAX_RETRIES = 3;
@@ -102,7 +102,22 @@ export class ExternalClient {
102
102
  throw new M365Error("transient", `transient: ${this.opts.name} ${method} failed (${err instanceof Error ? err.message : String(err)})`, { clientRequestId });
103
103
  }
104
104
  const requestId = res.headers.get("request-id") ?? res.headers.get("x-ms-request-id") ?? res.headers.get("sprequestguid") ?? undefined;
105
- const text = await res.text();
105
+ let text;
106
+ try {
107
+ text = await res.text();
108
+ }
109
+ catch (err) {
110
+ // the connection dropped while the answer was read: same policy as a failed request, never "unexpected"
111
+ if (attempt < MAX_RETRIES) {
112
+ await this.sleep(1000 * 2 ** attempt);
113
+ continue;
114
+ }
115
+ throw new M365Error("transient", `transient: ${this.opts.name} ${method} — connection closed while reading the HTTP ${res.status} answer (${bodyError(err)})`, {
116
+ status: res.status,
117
+ requestId,
118
+ clientRequestId,
119
+ });
120
+ }
106
121
  if (text.length > MAX_BODY_CHARS)
107
122
  throw new M365Error("unexpected", `unexpected: ${this.opts.name} response larger than ${MAX_BODY_CHARS / 1e6} M characters`, { requestId });
108
123
  if (res.ok) {
@@ -1,6 +1,6 @@
1
1
  import { randomUUID } from "node:crypto";
2
2
  import { fromGraphResponse, M365Error } from "./errors.js";
3
- import { defaultFetcher, defaultSleep, DEFAULT_TIMEOUT_MS } from "./http.js";
3
+ import { bodyError, defaultFetcher, defaultSleep, DEFAULT_TIMEOUT_MS } from "./http.js";
4
4
  /** Stable Graph only. `beta` is never used by this server. */
5
5
  export const GRAPH_BASE = "https://graph.microsoft.com/v1.0";
6
6
  /** Statuses retried with a bounded backoff (429 always; 5xx only for idempotent requests). */
@@ -160,7 +160,17 @@ export class GraphClient {
160
160
  }
161
161
  throw new M365Error("transient", `transient: report download failed (${err instanceof Error ? err.message : String(err)})`, { requestId: res.requestId });
162
162
  }
163
- const text = await dl.text();
163
+ let text;
164
+ try {
165
+ text = await dl.text();
166
+ }
167
+ catch (err) {
168
+ if (attempt < MAX_RETRIES) {
169
+ await this.sleep(this.backoff(attempt));
170
+ continue;
171
+ }
172
+ throw new M365Error("transient", `transient: report download — connection closed while reading the answer (${bodyError(err)})`, { requestId: res.requestId });
173
+ }
164
174
  if (dl.ok)
165
175
  return { csv: text, requestId: res.requestId };
166
176
  if (RETRY_STATUSES.has(dl.status) && attempt < MAX_RETRIES) {
@@ -244,7 +254,22 @@ export class GraphClient {
244
254
  throw new M365Error("unexpected", `unexpected: HTTP ${res.status} without Location on ${new URL(url).pathname}`, { requestId, clientRequestId });
245
255
  return { status: res.status, data: undefined, requestId, clientRequestId, url, location };
246
256
  }
247
- const text = await res.text();
257
+ let text;
258
+ try {
259
+ text = await res.text();
260
+ }
261
+ catch (err) {
262
+ // the connection dropped mid-answer: retried only when the request is idempotent, never "unexpected"
263
+ if (idempotent && attempt < MAX_RETRIES) {
264
+ await this.sleep(this.backoff(attempt));
265
+ continue;
266
+ }
267
+ throw new M365Error("transient", `transient: ${method} ${new URL(url).pathname} — connection closed while reading the HTTP ${res.status} answer (${bodyError(err)})`, {
268
+ status: res.status,
269
+ requestId,
270
+ clientRequestId,
271
+ });
272
+ }
248
273
  if (res.ok) {
249
274
  let data = undefined;
250
275
  if (text) {
package/dist/http.js CHANGED
@@ -1,3 +1,5 @@
1
1
  export const DEFAULT_TIMEOUT_MS = 30_000;
2
2
  export const defaultFetcher = (url, init) => fetch(url, init);
3
+ /** Message of a failure while reading a response body ("terminated" when the connection drops mid-body). */
4
+ export const bodyError = (err) => (err instanceof Error ? err.message : String(err));
3
5
  export const defaultSleep = (ms) => new Promise((r) => setTimeout(r, ms));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aidalinfo/m365-mcp",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "Microsoft 365 MCP server over Microsoft Graph — Entra ID users, groups and applications, licences, Teams, SharePoint, usage reports, service health, roles, MFA, audit, access review, shared mailbox delegation (Exchange Online). Read-only by default; full mode uses separate scoped identities with two-step confirmed, audited writes",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",