@chrischall/microsoft-teams-mcp 0.5.0 → 0.5.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.
@@ -7,7 +7,7 @@
7
7
  },
8
8
  "metadata": {
9
9
  "description": "MCP server for Microsoft Teams — read any chat or channel, your unread messages, and their attachments, and send messages and reactions (each confirmed first)",
10
- "version": "0.5.0"
10
+ "version": "0.5.1"
11
11
  },
12
12
  "plugins": [
13
13
  {
@@ -15,7 +15,7 @@
15
15
  "displayName": "Microsoft Teams",
16
16
  "source": "./",
17
17
  "description": "MCP server for Microsoft Teams — read any chat or channel, your unread messages, and their attachments, and send messages and reactions (each confirmed first), via your signed-in browser session",
18
- "version": "0.5.0",
18
+ "version": "0.5.1",
19
19
  "author": {
20
20
  "name": "Chris Hall"
21
21
  },
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "microsoft-teams-mcp",
3
3
  "displayName": "Microsoft Teams",
4
- "version": "0.5.0",
4
+ "version": "0.5.1",
5
5
  "description": "Microsoft Teams for Claude — read any chat or channel, your unread messages, and their attachments, and send messages and reactions (each confirmed first), using your signed-in browser session",
6
6
  "author": {
7
7
  "name": "Chris Hall",
package/README.md CHANGED
@@ -524,6 +524,20 @@ instead.
524
524
 
525
525
  ## Things worth knowing
526
526
 
527
+ - **Corporate networks.** The server talks to several hosts:
528
+ `teams.cloud.microsoft` (chats), the regional `*.asm.skype.com` image store
529
+ (inline images), `*.sharepoint.com` (shared files) and
530
+ `substrate.office.com` (search). If one is unreachable while the others
531
+ work, the error names that host and the network cause (`ENOTFOUND`,
532
+ `ECONNREFUSED`, a certificate code, …) with a hint, instead of a bare
533
+ "fetch failed". An inline image the image store cannot be reached for is
534
+ retried through the Teams gateway (`us-prod.asyncgw.teams.microsoft.com`),
535
+ which serves the same bytes and is often allowed where `*.asm.skype.com` is
536
+ not. Two settings fix most other cases, because Node reads neither the
537
+ system keychain nor the system proxy:
538
+ - TLS inspection: `NODE_EXTRA_CA_CERTS=/path/to/corporate-root-ca.pem`.
539
+ - A required proxy: `HTTPS_PROXY=<proxy URL>` together with
540
+ `NODE_USE_ENV_PROXY=1` (Node 22.21+ / 24.5+).
527
541
  - <a id="cursors-only-what-is-new"></a>**Cursors: only what is new.** A
528
542
  message id is its arrival time in epoch milliseconds, so "newer than the
529
543
  last message I saw" is a numeric comparison and a cursor is just that
package/dist/bundle.js CHANGED
@@ -23727,11 +23727,11 @@ function assertCompleteRequestResourceTemplate(request) {
23727
23727
  function scanXMcpHeaderDeclarations(inputSchema) {
23728
23728
  const declarations = [];
23729
23729
  const seenLower = /* @__PURE__ */ new Map();
23730
- const visit2 = (node2, path, reachable) => {
23730
+ const visit2 = (node2, path, reachable2) => {
23731
23731
  if (node2 === null || typeof node2 !== "object") return void 0;
23732
23732
  const schema = node2;
23733
23733
  if (X_MCP_HEADER_KEY in schema) {
23734
- if (!reachable || path.length === 0) return `${pathName(path)}: x-mcp-header is only permitted on properties statically reachable via a chain of 'properties' keys (not under items, additionalProperties, oneOf/anyOf/allOf/not, if/then/else, or $ref)`;
23734
+ if (!reachable2 || path.length === 0) return `${pathName(path)}: x-mcp-header is only permitted on properties statically reachable via a chain of 'properties' keys (not under items, additionalProperties, oneOf/anyOf/allOf/not, if/then/else, or $ref)`;
23735
23735
  const raw = schema[X_MCP_HEADER_KEY];
23736
23736
  if (typeof raw !== "string" || raw.length === 0) return `${pathName(path)}: x-mcp-header MUST be a non-empty string`;
23737
23737
  if (!RFC9110_TOKEN.test(raw)) return `${pathName(path)}: x-mcp-header '${raw}' is not a valid RFC 9110 token (no spaces, control characters or HTTP delimiters)`;
@@ -23749,7 +23749,7 @@ function scanXMcpHeaderDeclarations(inputSchema) {
23749
23749
  }
23750
23750
  const properties = schema.properties;
23751
23751
  if (properties !== null && typeof properties === "object") for (const [key, child] of Object.entries(properties)) {
23752
- const fault$1 = visit2(child, [...path, key], reachable);
23752
+ const fault$1 = visit2(child, [...path, key], reachable2);
23753
23753
  if (fault$1 !== void 0) return fault$1;
23754
23754
  }
23755
23755
  for (const k of NON_REACHABLE_SUBSCHEMA_KEYWORDS) {
@@ -37080,7 +37080,7 @@ var init_version = __esm({
37080
37080
  "src/version.ts"() {
37081
37081
  "use strict";
37082
37082
  PACKAGE_NAME = "microsoft-teams-mcp";
37083
- VERSION = "0.5.0";
37083
+ VERSION = "0.5.1";
37084
37084
  }
37085
37085
  });
37086
37086
 
@@ -48676,6 +48676,94 @@ function hasRealTitle(s) {
48676
48676
  return s.participants === void 0;
48677
48677
  }
48678
48678
 
48679
+ // src/network-error.ts
48680
+ init_dist2();
48681
+ var MAX_CAUSE_DEPTH = 5;
48682
+ var DNS_CODES = /* @__PURE__ */ new Set(["ENOTFOUND", "EAI_AGAIN", "EAI_FAIL", "EAI_NONAME"]);
48683
+ var CONNECT_CODES = /* @__PURE__ */ new Set([
48684
+ "ECONNREFUSED",
48685
+ "ECONNRESET",
48686
+ "ETIMEDOUT",
48687
+ "ENETUNREACH",
48688
+ "EHOSTUNREACH",
48689
+ "EPIPE",
48690
+ "UND_ERR_CONNECT_TIMEOUT",
48691
+ "UND_ERR_SOCKET",
48692
+ "UND_ERR_HEADERS_TIMEOUT"
48693
+ ]);
48694
+ var CERT_CODES = /* @__PURE__ */ new Set([
48695
+ "UNABLE_TO_GET_ISSUER_CERT_LOCALLY",
48696
+ "UNABLE_TO_GET_ISSUER_CERT",
48697
+ "UNABLE_TO_VERIFY_LEAF_SIGNATURE",
48698
+ "SELF_SIGNED_CERT_IN_CHAIN",
48699
+ "DEPTH_ZERO_SELF_SIGNED_CERT",
48700
+ "CERT_HAS_EXPIRED",
48701
+ "CERT_NOT_YET_VALID",
48702
+ "ERR_TLS_CERT_ALTNAME_INVALID"
48703
+ ]);
48704
+ function codeOf(e) {
48705
+ if (e === null || typeof e !== "object") return void 0;
48706
+ const code2 = e.code;
48707
+ return typeof code2 === "string" && code2 !== "" ? code2 : void 0;
48708
+ }
48709
+ function causes(err) {
48710
+ const out = [];
48711
+ let at = err;
48712
+ for (let depth = 0; depth < MAX_CAUSE_DEPTH && at !== void 0 && at !== null; depth++) {
48713
+ out.push(at);
48714
+ if (at instanceof AggregateError) out.push(...at.errors);
48715
+ at = at.cause;
48716
+ }
48717
+ return out;
48718
+ }
48719
+ function transportCauseCode(err) {
48720
+ for (const e of causes(err)) {
48721
+ const code2 = codeOf(e);
48722
+ if (code2 !== void 0) return code2;
48723
+ }
48724
+ return void 0;
48725
+ }
48726
+ function causeMessage(err) {
48727
+ const chain = causes(err).slice(1);
48728
+ for (let i = chain.length - 1; i >= 0; i--) {
48729
+ const e = chain[i];
48730
+ if (e instanceof Error && e.message !== "") return e.message;
48731
+ }
48732
+ return void 0;
48733
+ }
48734
+ function isFetchFailed(err) {
48735
+ return err instanceof TypeError && err.message === "fetch failed";
48736
+ }
48737
+ function hintFor(code2, host) {
48738
+ if (code2 !== void 0 && DNS_CODES.has(code2)) {
48739
+ return `This machine could not resolve ${host}. Check DNS and VPN: a split-tunnel VPN that resolves teams.cloud.microsoft but not the regional *.asm.skype.com and *.sharepoint.com hosts fails exactly like this. \`nslookup ${host}\` on the machine running this server tells you which.`;
48740
+ }
48741
+ if (code2 !== void 0 && CERT_CODES.has(code2)) {
48742
+ return `Node did not trust the TLS certificate ${host} presented. On a corporate network this is usually TLS inspection: export your proxy's root CA as PEM and start this server with NODE_EXTRA_CA_CERTS=/path/to/ca.pem (Node does not read the system keychain). If the certificate is expired or not yet valid, also check the machine's clock.`;
48743
+ }
48744
+ if (code2 !== void 0 && CONNECT_CODES.has(code2)) {
48745
+ return `The connection to ${host} was refused, reset or timed out before Teams answered \u2014 usually a firewall, or a network that only lets traffic out through a proxy. Node's fetch ignores proxy settings unless told: start this server with HTTPS_PROXY=<your proxy URL> and NODE_USE_ENV_PROXY=1 (Node 22.21+ / 24.5+), or allow the host through the firewall.`;
48746
+ }
48747
+ return `No response from ${host}. Check this machine can reach it (VPN, proxy, firewall); \`curl -sI https://${host}/\` from the same machine is a quick test.`;
48748
+ }
48749
+ function describeTransportFailure(err, url2, service) {
48750
+ if (!isFetchFailed(err)) return void 0;
48751
+ let host;
48752
+ try {
48753
+ host = new URL(url2).hostname;
48754
+ } catch {
48755
+ host = "(unknown host)";
48756
+ }
48757
+ const code2 = transportCauseCode(err);
48758
+ const detail = [code2, causeMessage(err)].filter((s) => s !== void 0);
48759
+ const why = detail.length > 0 ? ` (${[...new Set(detail)].join(": ")})` : "";
48760
+ return new McpToolError(`Could not reach ${service} at ${host}${why}.`, {
48761
+ kind: "transport",
48762
+ hint: hintFor(code2, host),
48763
+ cause: err
48764
+ });
48765
+ }
48766
+
48679
48767
  // src/chatsvc.ts
48680
48768
  async function captureTokenLazily() {
48681
48769
  const mod = await Promise.resolve().then(() => (init_auth_fetchproxy(), auth_fetchproxy_exports));
@@ -48696,6 +48784,16 @@ var MAX_MESSAGE_PAGES = 20;
48696
48784
  var DEFAULT_MESSAGE_PAGE_SIZE = 200;
48697
48785
  var MAX_IMAGE_BYTES = 5 * 1024 * 1024;
48698
48786
  var IMAGE_HOST_SUFFIX2 = ".asm.skype.com";
48787
+ var IMAGE_GATEWAY_HOST = "us-prod.asyncgw.teams.microsoft.com";
48788
+ function serviceFor(url2) {
48789
+ try {
48790
+ const host = new URL(url2).hostname;
48791
+ if (host.endsWith(IMAGE_HOST_SUFFIX2)) return "Teams' image store";
48792
+ return host === IMAGE_GATEWAY_HOST ? "the Teams image gateway" : "the Teams chat service";
48793
+ } catch {
48794
+ return "the Teams chat service";
48795
+ }
48796
+ }
48699
48797
  function outcomeUnknown(method, e, hint) {
48700
48798
  if (e instanceof RequestTimeoutError) {
48701
48799
  return new WriteOutcomeUnknownError("Teams", method, { timeoutMs: e.timeoutMs, cause: e, hint });
@@ -48964,6 +49062,23 @@ var ChatServiceClient = class {
48964
49062
  hint: `Only https images on *${IMAGE_HOST_SUFFIX2} (Teams' own image store) are fetched.`
48965
49063
  });
48966
49064
  }
49065
+ try {
49066
+ return await this.#getImage(target);
49067
+ } catch (e) {
49068
+ if (errorKindOf(e) !== "transport") throw e;
49069
+ const viaGateway = new URL(target.pathname + target.search, `https://${IMAGE_GATEWAY_HOST}`);
49070
+ try {
49071
+ return await this.#getImage(viaGateway);
49072
+ } catch (e2) {
49073
+ if (errorKindOf(e2) !== "transport") throw e2;
49074
+ throw new McpToolError(
49075
+ `${e.message} The Teams gateway was tried too: ${e2.message}`,
49076
+ { kind: "transport", hint: e.hint, cause: e }
49077
+ );
49078
+ }
49079
+ }
49080
+ }
49081
+ async #getImage(target) {
48967
49082
  const { status, headers, body } = await this.#send(target.toString(), "bytes", MAX_IMAGE_BYTES);
48968
49083
  this.#checkStatus(status);
48969
49084
  const mimeType = (headers.get("content-type") ?? "application/octet-stream").split(";")[0].trim();
@@ -49047,7 +49162,8 @@ var ChatServiceClient = class {
49047
49162
  try {
49048
49163
  r = await fetchBounded(url2, init, opts);
49049
49164
  } catch (e) {
49050
- throw write ? outcomeUnknown(method, e, write.hint) : e;
49165
+ if (write) throw outcomeUnknown(method, e, write.hint);
49166
+ throw describeTransportFailure(e, url2, serviceFor(url2)) ?? e;
49051
49167
  }
49052
49168
  body = r.body;
49053
49169
  return r.res;
@@ -49213,6 +49329,13 @@ async function captureSharePointTokenLazily(host) {
49213
49329
  var UNKNOWN_TOKEN_TTL_MS2 = 10 * 60 * 1e3;
49214
49330
  var RECAPTURE_SENTINEL2 = "fetchproxy:recapture";
49215
49331
  var REQUEST_TIMEOUT_MS2 = 6e4;
49332
+ async function reachable(url2, run) {
49333
+ try {
49334
+ return await run();
49335
+ } catch (e) {
49336
+ throw describeTransportFailure(e, url2, "SharePoint") ?? e;
49337
+ }
49338
+ }
49216
49339
  function toBearerTokens2(accessToken) {
49217
49340
  let expiresAt;
49218
49341
  try {
@@ -49324,18 +49447,21 @@ var SharePointClient = class {
49324
49447
  async #getDriveItem(captureHost, url2) {
49325
49448
  let body = "";
49326
49449
  const res = await this.#managerFor(captureHost).withAuth(async (token) => {
49327
- const r = await fetchBounded(
49450
+ const r = await reachable(
49328
49451
  url2,
49329
- {
49330
- method: "GET",
49331
- headers: {
49332
- authorization: `Bearer ${token}`,
49333
- accept: "application/json",
49334
- behavioroverride: "redirectAs404"
49452
+ () => fetchBounded(
49453
+ url2,
49454
+ {
49455
+ method: "GET",
49456
+ headers: {
49457
+ authorization: `Bearer ${token}`,
49458
+ accept: "application/json",
49459
+ behavioroverride: "redirectAs404"
49460
+ },
49461
+ redirect: "error"
49335
49462
  },
49336
- redirect: "error"
49337
- },
49338
- { read: "text", service: "SharePoint", timeoutMs: REQUEST_TIMEOUT_MS2, fetchImpl: this.#fetchImpl }
49463
+ { read: "text", service: "SharePoint", timeoutMs: REQUEST_TIMEOUT_MS2, fetchImpl: this.#fetchImpl }
49464
+ )
49339
49465
  );
49340
49466
  body = r.body;
49341
49467
  return r.res;
@@ -49375,10 +49501,13 @@ var SharePointClient = class {
49375
49501
  hint: "SharePoint download links are expected to be https."
49376
49502
  });
49377
49503
  }
49378
- const r = await fetchBounded(
49504
+ const r = await reachable(
49379
49505
  target.toString(),
49380
- { method: "GET", headers: { accept: "*/*" }, redirect: "follow" },
49381
- { read: "bytes", maxBytes, service: "SharePoint", timeoutMs: REQUEST_TIMEOUT_MS2, fetchImpl: this.#fetchImpl }
49506
+ () => fetchBounded(
49507
+ target.toString(),
49508
+ { method: "GET", headers: { accept: "*/*" }, redirect: "follow" },
49509
+ { read: "bytes", maxBytes, service: "SharePoint", timeoutMs: REQUEST_TIMEOUT_MS2, fetchImpl: this.#fetchImpl }
49510
+ )
49382
49511
  );
49383
49512
  this.#checkStatus(r.status);
49384
49513
  const mimeType = (r.headers.get("content-type") ?? "application/octet-stream").split(";")[0].trim();
@@ -49628,26 +49757,31 @@ var SubstrateClient = class {
49628
49757
  if (!opts.force && failed !== null && Date.now() - failed.at < CAPTURE_RETRY_COOLDOWN_MS) throw failed.error;
49629
49758
  let text = "";
49630
49759
  const res = await this.#manager.withAuth(async (token) => {
49631
- const r = await fetchBounded(
49632
- SUBSTRATE_QUERY_URL,
49633
- {
49634
- method: "POST",
49635
- headers: {
49636
- authorization: `Bearer ${token}`,
49637
- "content-type": "application/json",
49638
- accept: "application/json"
49760
+ let r;
49761
+ try {
49762
+ r = await fetchBounded(
49763
+ SUBSTRATE_QUERY_URL,
49764
+ {
49765
+ method: "POST",
49766
+ headers: {
49767
+ authorization: `Bearer ${token}`,
49768
+ "content-type": "application/json",
49769
+ accept: "application/json"
49770
+ },
49771
+ body: JSON.stringify(buildQueryBody(req)),
49772
+ redirect: "error"
49639
49773
  },
49640
- body: JSON.stringify(buildQueryBody(req)),
49641
- redirect: "error"
49642
- },
49643
- {
49644
- read: "text",
49645
- maxBytes: MAX_RESPONSE_BYTES,
49646
- service: "Substrate",
49647
- timeoutMs: REQUEST_TIMEOUT_MS3,
49648
- fetchImpl: this.#fetchImpl
49649
- }
49650
- );
49774
+ {
49775
+ read: "text",
49776
+ maxBytes: MAX_RESPONSE_BYTES,
49777
+ service: "Substrate",
49778
+ timeoutMs: REQUEST_TIMEOUT_MS3,
49779
+ fetchImpl: this.#fetchImpl
49780
+ }
49781
+ );
49782
+ } catch (e) {
49783
+ throw describeTransportFailure(e, SUBSTRATE_QUERY_URL, "Substrate search") ?? e;
49784
+ }
49651
49785
  text = r.body;
49652
49786
  return r.res;
49653
49787
  });
@@ -51472,6 +51606,9 @@ function degradeHint(err, host) {
51472
51606
  if (errorKindOf(err) === "no_credential") {
51473
51607
  return "SharePoint file download is disabled here (no token source). Unset TEAMS_DISABLE_FETCHPROXY, then retry.";
51474
51608
  }
51609
+ if (errorKindOf(err) === "transport" && err instanceof McpToolError) {
51610
+ return err.hint !== void 0 ? `${err.message} ${err.hint}` : err.message;
51611
+ }
51475
51612
  if (err instanceof McpToolError && err.hint !== void 0) return err.hint;
51476
51613
  return `Couldn't mint a SharePoint token for ${host} \u2014 open the shared file once in a signed-in Teams tab (that browser request is where the token is captured from), then retry.`;
51477
51614
  }
package/dist/chatsvc.js CHANGED
@@ -19,10 +19,11 @@
19
19
  * live facts" section of `docs/plans/2026-10-10-chatsvc-api.md` for the
20
20
  * response shapes the types below describe.
21
21
  */
22
- import { decodeJwtClaim, decodeJwtExp, fetchBounded, McpToolError, parseBoolEnv, readEnvVar, RequestTimeoutError, WriteOutcomeUnknownError, } from '@chrischall/mcp-utils';
22
+ import { decodeJwtClaim, decodeJwtExp, fetchBounded, errorKindOf, McpToolError, parseBoolEnv, readEnvVar, RequestTimeoutError, WriteOutcomeUnknownError, } from '@chrischall/mcp-utils';
23
23
  import { TokenManager } from '@chrischall/mcp-utils/session';
24
24
  import { createTokenCache, reportCacheWriteFailure } from './token-cache.js';
25
25
  import { SELF_CHAT } from './model.js';
26
+ import { describeTransportFailure } from './network-error.js';
26
27
  /**
27
28
  * Load the bridge bootstrap lazily.
28
29
  *
@@ -79,6 +80,29 @@ const MAX_IMAGE_BYTES = 5 * 1024 * 1024;
79
80
  * host varies by region). The bearer is sent ONLY to hosts under this suffix.
80
81
  */
81
82
  const IMAGE_HOST_SUFFIX = '.asm.skype.com';
83
+ /**
84
+ * The Teams gateway in front of the same image store. Verified live
85
+ * 2026-10-12: `GET https://us-prod.asyncgw.teams.microsoft.com/v1/objects/<id>/views/imgo`
86
+ * with the chat-service bearer returns the identical bytes for objects of
87
+ * either region (`0-sin-…` and `0-eus-…`). Some networks reset every
88
+ * connection to `*.asm.skype.com` while allowing teams.microsoft.com, so an
89
+ * image the store cannot be REACHED at is retried here — never one the store
90
+ * answered. Only ever reached by rewriting a vetted `*.asm.skype.com` URL,
91
+ * never from a URL in message content.
92
+ */
93
+ const IMAGE_GATEWAY_HOST = 'us-prod.asyncgw.teams.microsoft.com';
94
+ /** What a transport failure calls the far side: the image store, or the chat service. */
95
+ function serviceFor(url) {
96
+ try {
97
+ const host = new URL(url).hostname;
98
+ if (host.endsWith(IMAGE_HOST_SUFFIX))
99
+ return "Teams' image store";
100
+ return host === IMAGE_GATEWAY_HOST ? 'the Teams image gateway' : 'the Teams chat service';
101
+ }
102
+ catch {
103
+ return 'the Teams chat service';
104
+ }
105
+ }
82
106
  /**
83
107
  * A write that failed after it may have reached Teams. A timeout or a
84
108
  * transport failure (dropped connection, broken body, the caller cancelling)
@@ -382,6 +406,24 @@ export class ChatServiceClient {
382
406
  hint: `Only https images on *${IMAGE_HOST_SUFFIX} (Teams' own image store) are fetched.`,
383
407
  });
384
408
  }
409
+ try {
410
+ return await this.#getImage(target);
411
+ }
412
+ catch (e) {
413
+ if (errorKindOf(e) !== 'transport')
414
+ throw e;
415
+ const viaGateway = new URL(target.pathname + target.search, `https://${IMAGE_GATEWAY_HOST}`);
416
+ try {
417
+ return await this.#getImage(viaGateway);
418
+ }
419
+ catch (e2) {
420
+ if (errorKindOf(e2) !== 'transport')
421
+ throw e2;
422
+ throw new McpToolError(`${e.message} The Teams gateway was tried too: ${e2.message}`, { kind: 'transport', hint: e.hint, cause: e });
423
+ }
424
+ }
425
+ }
426
+ async #getImage(target) {
385
427
  const { status, headers, body } = await this.#send(target.toString(), 'bytes', MAX_IMAGE_BYTES);
386
428
  this.#checkStatus(status);
387
429
  const mimeType = (headers.get('content-type') ?? 'application/octet-stream').split(';')[0].trim();
@@ -478,7 +520,9 @@ export class ChatServiceClient {
478
520
  r = await fetchBounded(url, init, opts);
479
521
  }
480
522
  catch (e) {
481
- throw write ? outcomeUnknown(method, e, write.hint) : e;
523
+ if (write)
524
+ throw outcomeUnknown(method, e, write.hint);
525
+ throw describeTransportFailure(e, url, serviceFor(url)) ?? e;
482
526
  }
483
527
  body = r.body;
484
528
  return r.res;
@@ -0,0 +1,124 @@
1
+ /**
2
+ * A request that never got a response, said in a way someone can act on.
3
+ *
4
+ * Node's `fetch` (undici) reports every transport failure — DNS, a refused or
5
+ * reset connection, a TLS certificate it will not trust — as the same
6
+ * `TypeError('fetch failed')`, with the real reason on its `cause` chain.
7
+ * Surfaced as is, that reads "Failed to get the attachment: fetch failed",
8
+ * which names neither the host nor the reason (2026-10-12: two inline images
9
+ * on `in-api`/`us-api.asm.skype.com` failed that way on a machine whose
10
+ * chat-service calls to `teams.cloud.microsoft` were fine, while the same refs
11
+ * downloaded on another machine). This turns it into an `McpToolError` naming
12
+ * the HOST — never the path or query, which may carry ids — the cause's code,
13
+ * and a hint keyed to that code.
14
+ */
15
+ import { McpToolError } from '@chrischall/mcp-utils';
16
+ /** How far down a cause chain (and into an AggregateError) to look for a code. */
17
+ const MAX_CAUSE_DEPTH = 5;
18
+ const DNS_CODES = new Set(['ENOTFOUND', 'EAI_AGAIN', 'EAI_FAIL', 'EAI_NONAME']);
19
+ const CONNECT_CODES = new Set([
20
+ 'ECONNREFUSED',
21
+ 'ECONNRESET',
22
+ 'ETIMEDOUT',
23
+ 'ENETUNREACH',
24
+ 'EHOSTUNREACH',
25
+ 'EPIPE',
26
+ 'UND_ERR_CONNECT_TIMEOUT',
27
+ 'UND_ERR_SOCKET',
28
+ 'UND_ERR_HEADERS_TIMEOUT',
29
+ ]);
30
+ const CERT_CODES = new Set([
31
+ 'UNABLE_TO_GET_ISSUER_CERT_LOCALLY',
32
+ 'UNABLE_TO_GET_ISSUER_CERT',
33
+ 'UNABLE_TO_VERIFY_LEAF_SIGNATURE',
34
+ 'SELF_SIGNED_CERT_IN_CHAIN',
35
+ 'DEPTH_ZERO_SELF_SIGNED_CERT',
36
+ 'CERT_HAS_EXPIRED',
37
+ 'CERT_NOT_YET_VALID',
38
+ 'ERR_TLS_CERT_ALTNAME_INVALID',
39
+ ]);
40
+ function codeOf(e) {
41
+ if (e === null || typeof e !== 'object')
42
+ return undefined;
43
+ const code = e.code;
44
+ return typeof code === 'string' && code !== '' ? code : undefined;
45
+ }
46
+ /** The causes to look at, nearest first: the cause chain, and an AggregateError's members. */
47
+ function causes(err) {
48
+ const out = [];
49
+ let at = err;
50
+ for (let depth = 0; depth < MAX_CAUSE_DEPTH && at !== undefined && at !== null; depth++) {
51
+ out.push(at);
52
+ if (at instanceof AggregateError)
53
+ out.push(...at.errors);
54
+ at = at.cause;
55
+ }
56
+ return out;
57
+ }
58
+ /** The first system/undici error code on `err`'s cause chain. */
59
+ export function transportCauseCode(err) {
60
+ for (const e of causes(err)) {
61
+ const code = codeOf(e);
62
+ if (code !== undefined)
63
+ return code;
64
+ }
65
+ return undefined;
66
+ }
67
+ /** The innermost cause's message, which is where undici puts the real reason. */
68
+ function causeMessage(err) {
69
+ const chain = causes(err).slice(1);
70
+ for (let i = chain.length - 1; i >= 0; i--) {
71
+ const e = chain[i];
72
+ if (e instanceof Error && e.message !== '')
73
+ return e.message;
74
+ }
75
+ return undefined;
76
+ }
77
+ /** Whether `err` is `fetch`'s "never got a response" failure. */
78
+ function isFetchFailed(err) {
79
+ return err instanceof TypeError && err.message === 'fetch failed';
80
+ }
81
+ function hintFor(code, host) {
82
+ if (code !== undefined && DNS_CODES.has(code)) {
83
+ return (`This machine could not resolve ${host}. Check DNS and VPN: a split-tunnel VPN that resolves ` +
84
+ 'teams.cloud.microsoft but not the regional *.asm.skype.com and *.sharepoint.com hosts ' +
85
+ `fails exactly like this. \`nslookup ${host}\` on the machine running this server tells you which.`);
86
+ }
87
+ if (code !== undefined && CERT_CODES.has(code)) {
88
+ return (`Node did not trust the TLS certificate ${host} presented. On a corporate network this is ` +
89
+ 'usually TLS inspection: export your proxy\'s root CA as PEM and start this server with ' +
90
+ 'NODE_EXTRA_CA_CERTS=/path/to/ca.pem (Node does not read the system keychain). If the ' +
91
+ 'certificate is expired or not yet valid, also check the machine\'s clock.');
92
+ }
93
+ if (code !== undefined && CONNECT_CODES.has(code)) {
94
+ return (`The connection to ${host} was refused, reset or timed out before Teams answered — usually a ` +
95
+ 'firewall, or a network that only lets traffic out through a proxy. Node\'s fetch ignores ' +
96
+ 'proxy settings unless told: start this server with HTTPS_PROXY=<your proxy URL> and ' +
97
+ 'NODE_USE_ENV_PROXY=1 (Node 22.21+ / 24.5+), or allow the host through the firewall.');
98
+ }
99
+ return (`No response from ${host}. Check this machine can reach it (VPN, proxy, firewall); ` +
100
+ `\`curl -sI https://${host}/\` from the same machine is a quick test.`);
101
+ }
102
+ /**
103
+ * An `McpToolError` describing `err` when it is `fetch`'s transport failure
104
+ * for `url`, else `undefined` (the caller rethrows `err` as it was).
105
+ */
106
+ export function describeTransportFailure(err, url, service) {
107
+ if (!isFetchFailed(err))
108
+ return undefined;
109
+ let host;
110
+ try {
111
+ host = new URL(url).hostname;
112
+ }
113
+ catch {
114
+ host = '(unknown host)';
115
+ }
116
+ const code = transportCauseCode(err);
117
+ const detail = [code, causeMessage(err)].filter((s) => s !== undefined);
118
+ const why = detail.length > 0 ? ` (${[...new Set(detail)].join(': ')})` : '';
119
+ return new McpToolError(`Could not reach ${service} at ${host}${why}.`, {
120
+ kind: 'transport',
121
+ hint: hintFor(code, host),
122
+ cause: err,
123
+ });
124
+ }
@@ -23,6 +23,7 @@
23
23
  * `fetch` — the bridge is only ever touched to capture the token.
24
24
  */
25
25
  import { decodeJwtExp, fetchBounded, McpToolError, parseBoolEnv } from '@chrischall/mcp-utils';
26
+ import { describeTransportFailure } from './network-error.js';
26
27
  import { TokenManager } from '@chrischall/mcp-utils/session';
27
28
  import { createSharePointTokenCache } from './sharepoint-token-cache.js';
28
29
  /**
@@ -53,6 +54,15 @@ const UNKNOWN_TOKEN_TTL_MS = 10 * 60 * 1000;
53
54
  const RECAPTURE_SENTINEL = 'fetchproxy:recapture';
54
55
  /** Per-request deadline, covering the body read. */
55
56
  const REQUEST_TIMEOUT_MS = 60_000;
57
+ /** Run one fetch, turning "never got a response" into an error naming the host and cause. */
58
+ async function reachable(url, run) {
59
+ try {
60
+ return await run();
61
+ }
62
+ catch (e) {
63
+ throw describeTransportFailure(e, url, 'SharePoint') ?? e;
64
+ }
65
+ }
56
66
  /** Copied faithfully from `chatsvc.ts`: a captured token as `TokenManager` input. */
57
67
  function toBearerTokens(accessToken) {
58
68
  let expiresAt;
@@ -195,7 +205,7 @@ export class SharePointClient {
195
205
  async #getDriveItem(captureHost, url) {
196
206
  let body = '';
197
207
  const res = await this.#managerFor(captureHost).withAuth(async (token) => {
198
- const r = await fetchBounded(url, {
208
+ const r = await reachable(url, () => fetchBounded(url, {
199
209
  method: 'GET',
200
210
  headers: {
201
211
  authorization: `Bearer ${token}`,
@@ -203,7 +213,7 @@ export class SharePointClient {
203
213
  behavioroverride: 'redirectAs404',
204
214
  },
205
215
  redirect: 'error',
206
- }, { read: 'text', service: 'SharePoint', timeoutMs: REQUEST_TIMEOUT_MS, fetchImpl: this.#fetchImpl });
216
+ }, { read: 'text', service: 'SharePoint', timeoutMs: REQUEST_TIMEOUT_MS, fetchImpl: this.#fetchImpl }));
207
217
  body = r.body;
208
218
  return r.res;
209
219
  });
@@ -246,7 +256,7 @@ export class SharePointClient {
246
256
  hint: 'SharePoint download links are expected to be https.',
247
257
  });
248
258
  }
249
- const r = await fetchBounded(target.toString(), { method: 'GET', headers: { accept: '*/*' }, redirect: 'follow' }, { read: 'bytes', maxBytes, service: 'SharePoint', timeoutMs: REQUEST_TIMEOUT_MS, fetchImpl: this.#fetchImpl });
259
+ const r = await reachable(target.toString(), () => fetchBounded(target.toString(), { method: 'GET', headers: { accept: '*/*' }, redirect: 'follow' }, { read: 'bytes', maxBytes, service: 'SharePoint', timeoutMs: REQUEST_TIMEOUT_MS, fetchImpl: this.#fetchImpl }));
250
260
  this.#checkStatus(r.status);
251
261
  const mimeType = (r.headers.get('content-type') ?? 'application/octet-stream').split(';')[0].trim();
252
262
  const data = Buffer.from(r.body);
package/dist/substrate.js CHANGED
@@ -51,6 +51,7 @@
51
51
  * (`substrate-auth.ts`); every request is a plain Node `fetch`.
52
52
  */
53
53
  import { decodeJwtExp, fetchBounded, McpToolError, parseBoolEnv } from '@chrischall/mcp-utils';
54
+ import { describeTransportFailure } from './network-error.js';
54
55
  import { TokenManager } from '@chrischall/mcp-utils/session';
55
56
  import { createSubstrateTokenCache } from './substrate-token-cache.js';
56
57
  export const SUBSTRATE_QUERY_URL = 'https://substrate.office.com/searchservice/api/v2/query';
@@ -258,22 +259,28 @@ export class SubstrateClient {
258
259
  throw failed.error;
259
260
  let text = '';
260
261
  const res = await this.#manager.withAuth(async (token) => {
261
- const r = await fetchBounded(SUBSTRATE_QUERY_URL, {
262
- method: 'POST',
263
- headers: {
264
- authorization: `Bearer ${token}`,
265
- 'content-type': 'application/json',
266
- accept: 'application/json',
267
- },
268
- body: JSON.stringify(buildQueryBody(req)),
269
- redirect: 'error',
270
- }, {
271
- read: 'text',
272
- maxBytes: MAX_RESPONSE_BYTES,
273
- service: 'Substrate',
274
- timeoutMs: REQUEST_TIMEOUT_MS,
275
- fetchImpl: this.#fetchImpl,
276
- });
262
+ let r;
263
+ try {
264
+ r = await fetchBounded(SUBSTRATE_QUERY_URL, {
265
+ method: 'POST',
266
+ headers: {
267
+ authorization: `Bearer ${token}`,
268
+ 'content-type': 'application/json',
269
+ accept: 'application/json',
270
+ },
271
+ body: JSON.stringify(buildQueryBody(req)),
272
+ redirect: 'error',
273
+ }, {
274
+ read: 'text',
275
+ maxBytes: MAX_RESPONSE_BYTES,
276
+ service: 'Substrate',
277
+ timeoutMs: REQUEST_TIMEOUT_MS,
278
+ fetchImpl: this.#fetchImpl,
279
+ });
280
+ }
281
+ catch (e) {
282
+ throw describeTransportFailure(e, SUBSTRATE_QUERY_URL, 'Substrate search') ?? e;
283
+ }
277
284
  text = r.body;
278
285
  return r.res;
279
286
  });
@@ -167,6 +167,11 @@ function degradeHint(err, host) {
167
167
  if (errorKindOf(err) === 'no_credential') {
168
168
  return 'SharePoint file download is disabled here (no token source). Unset TEAMS_DISABLE_FETCHPROXY, then retry.';
169
169
  }
170
+ // A network failure is about this machine's route to the host, not the token:
171
+ // say which host and why, never "open the file once in Teams".
172
+ if (errorKindOf(err) === 'transport' && err instanceof McpToolError) {
173
+ return err.hint !== undefined ? `${err.message} ${err.hint}` : err.message;
174
+ }
170
175
  if (err instanceof McpToolError && err.hint !== undefined)
171
176
  return err.hint;
172
177
  return (`Couldn't mint a SharePoint token for ${host} — open the shared file once in a signed-in Teams ` +
package/dist/version.js CHANGED
@@ -10,4 +10,4 @@
10
10
  * line below and nowhere else — not even in prose.
11
11
  */
12
12
  export const PACKAGE_NAME = 'microsoft-teams-mcp';
13
- export const VERSION = '0.5.0'; // x-release-please-version
13
+ export const VERSION = '0.5.1'; // x-release-please-version
package/mint.yaml CHANGED
@@ -88,10 +88,12 @@ state:
88
88
  egress:
89
89
  # teams.cloud.microsoft serves the chat-service API (src/chatsvc.ts). Inline
90
90
  # images download from Teams' image store on a regional *.asm.skype.com host
91
- # (us-api.asm.skype.com and the like) — the client sends its token nowhere
92
- # else. Message search goes to Microsoft Substrate (src/substrate.ts) with
93
- # its own token.
91
+ # (us-api.asm.skype.com and the like), retried through the Teams gateway
92
+ # (us-prod.asyncgw.teams.microsoft.com) when the store cannot be reached —
93
+ # the client sends its token nowhere else. Message search goes to Microsoft
94
+ # Substrate (src/substrate.ts) with its own token.
94
95
  allow:
95
96
  - teams.cloud.microsoft
96
97
  - '*.asm.skype.com'
98
+ - us-prod.asyncgw.teams.microsoft.com
97
99
  - substrate.office.com
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chrischall/microsoft-teams-mcp",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "mcpName": "io.github.chrischall/microsoft-teams-mcp",
5
5
  "description": "Microsoft Teams MCP server for Claude — developed and maintained by AI (Claude Code)",
6
6
  "author": "Claude Code (AI) <https://www.anthropic.com/claude>",
package/server.json CHANGED
@@ -6,12 +6,12 @@
6
6
  "url": "https://github.com/chrischall/microsoft-teams-mcp",
7
7
  "source": "github"
8
8
  },
9
- "version": "0.5.0",
9
+ "version": "0.5.1",
10
10
  "packages": [
11
11
  {
12
12
  "registryType": "npm",
13
13
  "identifier": "@chrischall/microsoft-teams-mcp",
14
- "version": "0.5.0",
14
+ "version": "0.5.1",
15
15
  "transport": {
16
16
  "type": "stdio"
17
17
  },