@chrischall/microsoft-teams-mcp 0.6.1 → 0.6.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/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/dist/auth-fetchproxy.js +25 -63
- package/dist/bundle.js +361 -383
- package/dist/capture-window.js +4 -19
- package/dist/chatsvc.js +14 -78
- package/dist/network-error.js +20 -149
- package/dist/sharepoint-auth.js +19 -64
- package/dist/sharepoint-token-cache.js +2 -12
- package/dist/sharepoint.js +7 -33
- package/dist/substrate-auth.js +14 -47
- package/dist/substrate-token-cache.js +2 -12
- package/dist/substrate.js +7 -23
- package/dist/token-cache.js +2 -11
- package/dist/tools/markread.js +2 -3
- package/dist/tools/react.js +2 -3
- package/dist/tools/send.js +11 -28
- package/dist/version.js +1 -1
- package/package.json +2 -2
- package/server.json +2 -2
package/dist/bundle.js
CHANGED
|
@@ -35421,10 +35421,33 @@ function redactJsonCookie(quote) {
|
|
|
35421
35421
|
function redactSecrets(text) {
|
|
35422
35422
|
return text.replace(BEARER_RE, "$1[REDACTED]").replace(BASIC_AUTH_RE, "$1[REDACTED]").replace(SET_COOKIE_RE, "$1$2=[REDACTED]").replace(COOKIE_HEADER_RE, (_m, prefix, pairs) => `${prefix}${pairs.replace(/=[^;,\s]*/g, "=[REDACTED]")}`).replace(API_KEY_RE, "[REDACTED]").replace(GOOGLE_OAUTH_TOKEN_RE, "[REDACTED]").replace(HEADER_SECRET_RE, "$1[REDACTED]").replace(QUERY_SECRET_RE, "$1[REDACTED]").replace(OAUTH_CODE_RE, "$1[REDACTED]").replace(FORM_PASSWORD_RE, "$1[REDACTED]").replace(AWS_SIGV4_RE, "$1[REDACTED]").replace(JSON_COOKIE_DQ_RE, redactJsonCookie('"')).replace(JSON_COOKIE_SQ_RE, redactJsonCookie("'")).replace(JSON_SECRET_DQ_RE, "$1[REDACTED]$2").replace(JSON_SECRET_SQ_RE, "$1[REDACTED]$2").replace(JSON_SECRET_NUM_RE, "$1[REDACTED]").replace(JWT_RE, "[REDACTED]");
|
|
35423
35423
|
}
|
|
35424
|
-
function
|
|
35424
|
+
function redactValues(text, values, opts = {}) {
|
|
35425
|
+
const placeholder = opts.placeholder ?? "[REDACTED]";
|
|
35426
|
+
const minLength = Math.max(1, opts.minLength ?? 1);
|
|
35427
|
+
const needles = /* @__PURE__ */ new Set();
|
|
35428
|
+
for (const value of values) {
|
|
35429
|
+
if (typeof value !== "string" || value.length < minLength)
|
|
35430
|
+
continue;
|
|
35431
|
+
needles.add(value);
|
|
35432
|
+
if (opts.jsonEscaped !== false) {
|
|
35433
|
+
const escaped = JSON.stringify(value).slice(1, -1);
|
|
35434
|
+
if (escaped !== value && escaped.length >= minLength)
|
|
35435
|
+
needles.add(escaped);
|
|
35436
|
+
}
|
|
35437
|
+
}
|
|
35438
|
+
let out = String(text ?? "");
|
|
35439
|
+
for (const needle of [...needles].sort((a, b) => b.length - a.length)) {
|
|
35440
|
+
if (out.includes(needle))
|
|
35441
|
+
out = out.split(needle).join(placeholder);
|
|
35442
|
+
}
|
|
35443
|
+
return out;
|
|
35444
|
+
}
|
|
35445
|
+
function truncateErrorMessage(text, max = DEFAULT_ERROR_MESSAGE_MAX, opts = {}) {
|
|
35425
35446
|
const str3 = text === null || text === void 0 ? "" : String(text);
|
|
35426
35447
|
const cap = Math.max(ERROR_REDACTION_INPUT_MAX, max);
|
|
35427
|
-
const
|
|
35448
|
+
const capped = str3.length > cap ? str3.slice(0, cap) : str3;
|
|
35449
|
+
const scrubbed = opts.values !== void 0 ? redactValues(capped, opts.values, opts.placeholder !== void 0 ? { placeholder: opts.placeholder } : {}) : capped;
|
|
35450
|
+
const redacted = redactSecrets(scrubbed);
|
|
35428
35451
|
if (redacted.length <= max)
|
|
35429
35452
|
return redacted;
|
|
35430
35453
|
return `${redacted.slice(0, max)}\u2026 [truncated]`;
|
|
@@ -35533,15 +35556,6 @@ var init_zod = __esm({
|
|
|
35533
35556
|
}
|
|
35534
35557
|
});
|
|
35535
35558
|
|
|
35536
|
-
// node_modules/@chrischall/mcp-utils/dist/response/view.js
|
|
35537
|
-
function minifiedResult(data) {
|
|
35538
|
-
return { content: [{ type: "text", text: JSON.stringify(data) }] };
|
|
35539
|
-
}
|
|
35540
|
-
var init_view = __esm({
|
|
35541
|
-
"node_modules/@chrischall/mcp-utils/dist/response/view.js"() {
|
|
35542
|
-
}
|
|
35543
|
-
});
|
|
35544
|
-
|
|
35545
35559
|
// node_modules/@chrischall/mcp-utils/dist/response/media.js
|
|
35546
35560
|
var MEDIA_NOUN, MEDIA_QUALIFIER, MEDIA_KEY;
|
|
35547
35561
|
var init_media = __esm({
|
|
@@ -35552,6 +35566,16 @@ var init_media = __esm({
|
|
|
35552
35566
|
}
|
|
35553
35567
|
});
|
|
35554
35568
|
|
|
35569
|
+
// node_modules/@chrischall/mcp-utils/dist/response/view.js
|
|
35570
|
+
function minifiedResult(data) {
|
|
35571
|
+
return { content: [{ type: "text", text: JSON.stringify(data) }] };
|
|
35572
|
+
}
|
|
35573
|
+
var init_view = __esm({
|
|
35574
|
+
"node_modules/@chrischall/mcp-utils/dist/response/view.js"() {
|
|
35575
|
+
init_media();
|
|
35576
|
+
}
|
|
35577
|
+
});
|
|
35578
|
+
|
|
35555
35579
|
// node_modules/@chrischall/mcp-utils/dist/response/untrusted.js
|
|
35556
35580
|
function isPlainObject3(value) {
|
|
35557
35581
|
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
@@ -36851,6 +36875,126 @@ var init_url_safety = __esm({
|
|
|
36851
36875
|
}
|
|
36852
36876
|
});
|
|
36853
36877
|
|
|
36878
|
+
// node_modules/@chrischall/mcp-utils/dist/http/transport-failure.js
|
|
36879
|
+
function codeOf(e) {
|
|
36880
|
+
if (e === null || typeof e !== "object")
|
|
36881
|
+
return void 0;
|
|
36882
|
+
const code2 = e.code;
|
|
36883
|
+
return typeof code2 === "string" && code2 !== "" ? code2 : void 0;
|
|
36884
|
+
}
|
|
36885
|
+
function causes(err) {
|
|
36886
|
+
const out = [];
|
|
36887
|
+
let at = err;
|
|
36888
|
+
for (let depth = 0; depth < MAX_CAUSE_DEPTH && at !== void 0 && at !== null; depth++) {
|
|
36889
|
+
out.push(at);
|
|
36890
|
+
if (at instanceof AggregateError)
|
|
36891
|
+
out.push(...at.errors);
|
|
36892
|
+
at = at.cause;
|
|
36893
|
+
}
|
|
36894
|
+
return out;
|
|
36895
|
+
}
|
|
36896
|
+
function transportCauseCode(err) {
|
|
36897
|
+
for (const e of causes(err)) {
|
|
36898
|
+
const code2 = codeOf(e);
|
|
36899
|
+
if (code2 !== void 0)
|
|
36900
|
+
return code2;
|
|
36901
|
+
}
|
|
36902
|
+
return void 0;
|
|
36903
|
+
}
|
|
36904
|
+
function causeMessage(err) {
|
|
36905
|
+
const chain = causes(err).slice(1);
|
|
36906
|
+
for (let i = chain.length - 1; i >= 0; i--) {
|
|
36907
|
+
const e = chain[i];
|
|
36908
|
+
if (e instanceof Error && e.message !== "")
|
|
36909
|
+
return e.message;
|
|
36910
|
+
}
|
|
36911
|
+
return void 0;
|
|
36912
|
+
}
|
|
36913
|
+
function isFetchFailedError(err) {
|
|
36914
|
+
return err instanceof TypeError && err.message === "fetch failed";
|
|
36915
|
+
}
|
|
36916
|
+
function proxyRefusalStatus(err) {
|
|
36917
|
+
for (const e of causes(err)) {
|
|
36918
|
+
if (codeOf(e) === "ERR_PROXY_TUNNEL") {
|
|
36919
|
+
const m = /\b(\d{3})\b/.exec(e instanceof Error ? e.message.slice(0, 500) : "");
|
|
36920
|
+
return m ? Number(m[1]) : "unknown";
|
|
36921
|
+
}
|
|
36922
|
+
if (e instanceof Error) {
|
|
36923
|
+
const m = /^Proxy response \((\d{3})\) !== 200 when HTTP Tunneling/.exec(e.message);
|
|
36924
|
+
if (m)
|
|
36925
|
+
return Number(m[1]);
|
|
36926
|
+
}
|
|
36927
|
+
}
|
|
36928
|
+
return void 0;
|
|
36929
|
+
}
|
|
36930
|
+
function classify(err, code2) {
|
|
36931
|
+
const refused = proxyRefusalStatus(err);
|
|
36932
|
+
if (refused !== void 0) {
|
|
36933
|
+
return { cls: refused === 403 || refused === 407 || refused === "unknown" ? "egress" : "proxy", proxyStatus: refused };
|
|
36934
|
+
}
|
|
36935
|
+
if (code2 !== void 0 && DNS_CODES.has(code2))
|
|
36936
|
+
return { cls: "dns" };
|
|
36937
|
+
if (code2 !== void 0 && CERT_CODES.has(code2))
|
|
36938
|
+
return { cls: "tls" };
|
|
36939
|
+
if (code2 !== void 0 && CONNECT_CODES.has(code2))
|
|
36940
|
+
return { cls: "connect" };
|
|
36941
|
+
return { cls: "other" };
|
|
36942
|
+
}
|
|
36943
|
+
function describeTransportFailure(err, url2, service, opts = {}) {
|
|
36944
|
+
if (!isFetchFailedError(err))
|
|
36945
|
+
return void 0;
|
|
36946
|
+
let host;
|
|
36947
|
+
try {
|
|
36948
|
+
host = new URL(url2).hostname;
|
|
36949
|
+
} catch {
|
|
36950
|
+
host = "(unknown host)";
|
|
36951
|
+
}
|
|
36952
|
+
const code2 = transportCauseCode(err);
|
|
36953
|
+
const detail = [code2, causeMessage(err)].filter((s) => s !== void 0);
|
|
36954
|
+
const why = detail.length > 0 ? ` (${[...new Set(detail)].join(": ")})` : "";
|
|
36955
|
+
const { cls, proxyStatus } = classify(err, code2);
|
|
36956
|
+
const ctx = { host, service, code: code2, ...proxyStatus !== void 0 ? { proxyStatus } : {} };
|
|
36957
|
+
const hint = (opts.hints?.[cls] ?? DEFAULT_HINTS[cls])(host, ctx);
|
|
36958
|
+
return new McpToolError(`Could not reach ${service} at ${host}${why}.`, { kind: "transport", hint, cause: err });
|
|
36959
|
+
}
|
|
36960
|
+
var MAX_CAUSE_DEPTH, DNS_CODES, CONNECT_CODES, CERT_CODES, DEFAULT_HINTS;
|
|
36961
|
+
var init_transport_failure = __esm({
|
|
36962
|
+
"node_modules/@chrischall/mcp-utils/dist/http/transport-failure.js"() {
|
|
36963
|
+
init_errors3();
|
|
36964
|
+
MAX_CAUSE_DEPTH = 5;
|
|
36965
|
+
DNS_CODES = /* @__PURE__ */ new Set(["ENOTFOUND", "EAI_AGAIN", "EAI_FAIL", "EAI_NONAME"]);
|
|
36966
|
+
CONNECT_CODES = /* @__PURE__ */ new Set([
|
|
36967
|
+
"ECONNREFUSED",
|
|
36968
|
+
"ECONNRESET",
|
|
36969
|
+
"ETIMEDOUT",
|
|
36970
|
+
"ENETUNREACH",
|
|
36971
|
+
"EHOSTUNREACH",
|
|
36972
|
+
"EPIPE",
|
|
36973
|
+
"UND_ERR_CONNECT_TIMEOUT",
|
|
36974
|
+
"UND_ERR_SOCKET",
|
|
36975
|
+
"UND_ERR_HEADERS_TIMEOUT"
|
|
36976
|
+
]);
|
|
36977
|
+
CERT_CODES = /* @__PURE__ */ new Set([
|
|
36978
|
+
"UNABLE_TO_GET_ISSUER_CERT_LOCALLY",
|
|
36979
|
+
"UNABLE_TO_GET_ISSUER_CERT",
|
|
36980
|
+
"UNABLE_TO_VERIFY_LEAF_SIGNATURE",
|
|
36981
|
+
"SELF_SIGNED_CERT_IN_CHAIN",
|
|
36982
|
+
"DEPTH_ZERO_SELF_SIGNED_CERT",
|
|
36983
|
+
"CERT_HAS_EXPIRED",
|
|
36984
|
+
"CERT_NOT_YET_VALID",
|
|
36985
|
+
"ERR_TLS_CERT_ALTNAME_INVALID"
|
|
36986
|
+
]);
|
|
36987
|
+
DEFAULT_HINTS = {
|
|
36988
|
+
egress: (host) => `The outbound proxy this server runs behind refused the connection to ${host}: its egress policy does not allow that host. On a hosted (mcp-host) registration, the host must be on the registration's egress allow-list \u2014 the owner accepts the manifest's egress proposal (or adds the host) on the registration, then retries. Elsewhere, ask whoever runs the proxy to allow it.`,
|
|
36989
|
+
proxy: (host, ctx) => `The outbound proxy this server runs behind could not open a connection to ${host} (it answered ${String(ctx.proxyStatus)}). Retry; if it persists, check the proxy can reach the host.`,
|
|
36990
|
+
dns: (host) => `This machine could not resolve ${host}. Check DNS and VPN: a split-tunnel VPN that resolves some of a service's hosts but not others fails exactly like this. \`nslookup ${host}\` on the machine running this server tells you which.`,
|
|
36991
|
+
tls: (host) => `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.`,
|
|
36992
|
+
connect: (host, ctx) => `The connection to ${host} was refused, reset or timed out before ${ctx.service} 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.`,
|
|
36993
|
+
other: (host) => `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.`
|
|
36994
|
+
};
|
|
36995
|
+
}
|
|
36996
|
+
});
|
|
36997
|
+
|
|
36854
36998
|
// node_modules/@chrischall/mcp-utils/dist/internal/retry-after.js
|
|
36855
36999
|
var init_retry_after = __esm({
|
|
36856
37000
|
"node_modules/@chrischall/mcp-utils/dist/internal/retry-after.js"() {
|
|
@@ -36858,6 +37002,27 @@ var init_retry_after = __esm({
|
|
|
36858
37002
|
});
|
|
36859
37003
|
|
|
36860
37004
|
// node_modules/@chrischall/mcp-utils/dist/http/index.js
|
|
37005
|
+
function writeOutcomeStatus(err) {
|
|
37006
|
+
const status = err.cause?.status;
|
|
37007
|
+
return typeof status === "number" ? status : void 0;
|
|
37008
|
+
}
|
|
37009
|
+
function unknownOutcomeReason(err, opts = {}) {
|
|
37010
|
+
if (err.timedOut)
|
|
37011
|
+
return "it did not answer in time";
|
|
37012
|
+
const status = writeOutcomeStatus(err);
|
|
37013
|
+
if (status !== void 0)
|
|
37014
|
+
return `it answered HTTP ${status} after ${opts.sent ?? "the request"} was sent`;
|
|
37015
|
+
return "the connection dropped";
|
|
37016
|
+
}
|
|
37017
|
+
async function writeOrUnknown(run, onUnknown) {
|
|
37018
|
+
try {
|
|
37019
|
+
return { ok: true, value: await run() };
|
|
37020
|
+
} catch (err) {
|
|
37021
|
+
if (!(err instanceof WriteOutcomeUnknownError))
|
|
37022
|
+
throw err;
|
|
37023
|
+
return { ok: false, result: await onUnknown(err, unknownOutcomeReason(err)) };
|
|
37024
|
+
}
|
|
37025
|
+
}
|
|
36861
37026
|
function headerOf(headers, name) {
|
|
36862
37027
|
if (headers === void 0)
|
|
36863
37028
|
return void 0;
|
|
@@ -36928,6 +37093,7 @@ var init_http = __esm({
|
|
|
36928
37093
|
init_net_atoms();
|
|
36929
37094
|
init_fetch_bounded();
|
|
36930
37095
|
init_url_safety();
|
|
37096
|
+
init_transport_failure();
|
|
36931
37097
|
init_body_limit();
|
|
36932
37098
|
init_net_atoms();
|
|
36933
37099
|
init_url_safety();
|
|
@@ -37170,7 +37336,7 @@ var init_version = __esm({
|
|
|
37170
37336
|
"src/version.ts"() {
|
|
37171
37337
|
"use strict";
|
|
37172
37338
|
PACKAGE_NAME = "microsoft-teams-mcp";
|
|
37173
|
-
VERSION = "0.6.
|
|
37339
|
+
VERSION = "0.6.2";
|
|
37174
37340
|
}
|
|
37175
37341
|
});
|
|
37176
37342
|
|
|
@@ -47502,6 +47668,71 @@ function createBootstrapOpts(args) {
|
|
|
47502
47668
|
...nonEmpty2(b.domSelectors) ? { domSelectors: b.domSelectors } : {}
|
|
47503
47669
|
};
|
|
47504
47670
|
}
|
|
47671
|
+
function stripBearer(raw) {
|
|
47672
|
+
const m = /^\s*Bearer\s+(.+)$/i.exec(raw);
|
|
47673
|
+
return (m?.[1] ?? raw).trim();
|
|
47674
|
+
}
|
|
47675
|
+
async function raceCaptures(attempts, windowMs) {
|
|
47676
|
+
for (const a of attempts)
|
|
47677
|
+
a.catch(() => {
|
|
47678
|
+
});
|
|
47679
|
+
let timer;
|
|
47680
|
+
const expiry = new Promise((_resolve, reject) => {
|
|
47681
|
+
timer = setTimeout(() => reject(new Error(`timed out after ${Math.round(windowMs / 1e3)}s waiting for the page to make a request we could read`)), windowMs);
|
|
47682
|
+
});
|
|
47683
|
+
try {
|
|
47684
|
+
return await Promise.race([
|
|
47685
|
+
Promise.any(attempts).catch((e) => {
|
|
47686
|
+
throw new Error(e instanceof AggregateError ? e.errors.map((x) => messageOf(x)).join("; ") : messageOf(e));
|
|
47687
|
+
}),
|
|
47688
|
+
expiry
|
|
47689
|
+
]);
|
|
47690
|
+
} finally {
|
|
47691
|
+
clearTimeout(timer);
|
|
47692
|
+
}
|
|
47693
|
+
}
|
|
47694
|
+
async function captureBearerHeader(opts) {
|
|
47695
|
+
if (opts.captures.length === 0)
|
|
47696
|
+
throw new Error("captureBearerHeader: at least one capture declaration is required.");
|
|
47697
|
+
const minLength = opts.minLength ?? 100;
|
|
47698
|
+
const normalise = opts.normalise ?? stripBearer;
|
|
47699
|
+
const domains = opts.domains ?? [...new Set(opts.captures.map((c) => c.host))];
|
|
47700
|
+
const build2 = opts.createTransport ?? ((o) => createFetchproxyTransport(o));
|
|
47701
|
+
const transport = build2({
|
|
47702
|
+
...opts.transportOptions,
|
|
47703
|
+
...createBootstrapOpts({ domains: [...domains], bootstrap: { captureHeaders: opts.captures.map((c) => ({ ...c })) } }),
|
|
47704
|
+
...opts.port !== void 0 ? { port: opts.port } : {},
|
|
47705
|
+
// Both: the explicit deadline for every bridge version, and the declared
|
|
47706
|
+
// window so the transport's own derivation agrees with it.
|
|
47707
|
+
fetchTimeoutMs: deadlineForCaptureWindow(void 0, opts.windowMs) ?? SERVER_DEFAULT_FETCH_TIMEOUT_MS,
|
|
47708
|
+
captureWindowMs: opts.windowMs,
|
|
47709
|
+
serverName: opts.serverName,
|
|
47710
|
+
version: opts.version
|
|
47711
|
+
});
|
|
47712
|
+
const one = async (decl) => {
|
|
47713
|
+
const raw = await transport.server.captureRequestHeader({ ...decl, timeoutMs: opts.windowMs });
|
|
47714
|
+
if (typeof raw !== "string")
|
|
47715
|
+
throw new Error(`${decl.host}: capture returned no header`);
|
|
47716
|
+
const token = normalise(raw);
|
|
47717
|
+
if (token.length < minLength) {
|
|
47718
|
+
throw new Error(`${decl.host}: ${decl.headerName} header was present but too short to be a token (${token.length} chars)`);
|
|
47719
|
+
}
|
|
47720
|
+
return token;
|
|
47721
|
+
};
|
|
47722
|
+
try {
|
|
47723
|
+
await transport.start();
|
|
47724
|
+
try {
|
|
47725
|
+
return opts.captures.length === 1 ? await one(opts.captures[0]) : await raceCaptures(opts.captures.map(one), opts.windowMs);
|
|
47726
|
+
} catch (e) {
|
|
47727
|
+
throw new Error(`could not capture ${opts.what} from the browser (${messageOf(e)}). ${opts.guidance}`);
|
|
47728
|
+
}
|
|
47729
|
+
} finally {
|
|
47730
|
+
try {
|
|
47731
|
+
await transport.close();
|
|
47732
|
+
} catch {
|
|
47733
|
+
}
|
|
47734
|
+
}
|
|
47735
|
+
}
|
|
47505
47736
|
var PLACEHOLDER_RE2, SERVER_DEFAULT_FETCH_TIMEOUT_MS, CAPTURE_DEADLINE_MARGIN_MS;
|
|
47506
47737
|
var init_fetchproxy = __esm({
|
|
47507
47738
|
"node_modules/@chrischall/mcp-utils/dist/fetchproxy/index.js"() {
|
|
@@ -47522,17 +47753,12 @@ function captureWindowMs(env = process.env) {
|
|
|
47522
47753
|
const ms = readTtlMsEnv("TEAMS_CAPTURE_TIMEOUT", DEFAULT_CAPTURE_WINDOW_MS, { env });
|
|
47523
47754
|
return ms > 0 ? ms : DEFAULT_CAPTURE_WINDOW_MS;
|
|
47524
47755
|
}
|
|
47525
|
-
|
|
47526
|
-
return Math.max(windowMs + DEADLINE_MARGIN_MS, MIN_DEADLINE_MS);
|
|
47527
|
-
}
|
|
47528
|
-
var DEFAULT_CAPTURE_WINDOW_MS, DEADLINE_MARGIN_MS, MIN_DEADLINE_MS;
|
|
47756
|
+
var DEFAULT_CAPTURE_WINDOW_MS;
|
|
47529
47757
|
var init_capture_window = __esm({
|
|
47530
47758
|
"src/capture-window.ts"() {
|
|
47531
47759
|
"use strict";
|
|
47532
47760
|
init_dist2();
|
|
47533
47761
|
DEFAULT_CAPTURE_WINDOW_MS = 3e4;
|
|
47534
|
-
DEADLINE_MARGIN_MS = 15e3;
|
|
47535
|
-
MIN_DEADLINE_MS = 3e4;
|
|
47536
47762
|
}
|
|
47537
47763
|
});
|
|
47538
47764
|
|
|
@@ -47542,67 +47768,28 @@ __export(auth_fetchproxy_exports, {
|
|
|
47542
47768
|
CAPTURE_DECL: () => CAPTURE_DECL,
|
|
47543
47769
|
TRUST_DOMAINS: () => TRUST_DOMAINS,
|
|
47544
47770
|
captureTokenViaFetchproxy: () => captureTokenViaFetchproxy,
|
|
47771
|
+
createCaptureTransport: () => createCaptureTransport,
|
|
47545
47772
|
getWsPort: () => getWsPort,
|
|
47546
47773
|
stripBearer: () => stripBearer
|
|
47547
47774
|
});
|
|
47548
47775
|
function getWsPort() {
|
|
47549
47776
|
return readPortEnv("TEAMS_WS_PORT", DEFAULT_WS_PORT);
|
|
47550
47777
|
}
|
|
47551
|
-
function stripBearer(raw) {
|
|
47552
|
-
const m = /^\s*Bearer\s+(.+)$/i.exec(raw);
|
|
47553
|
-
return (m ? m[1] : raw).trim();
|
|
47554
|
-
}
|
|
47555
47778
|
async function captureTokenViaFetchproxy(env = process.env) {
|
|
47556
|
-
|
|
47557
|
-
|
|
47558
|
-
|
|
47559
|
-
//
|
|
47560
|
-
|
|
47561
|
-
// This is the same set as before the Activity feed left the page, so an
|
|
47562
|
-
// existing pairing needs no re-approval.
|
|
47563
|
-
...createBootstrapOpts({
|
|
47564
|
-
domains: [...TRUST_DOMAINS],
|
|
47565
|
-
bootstrap: { captureHeaders: [{ ...CAPTURE_DECL }] }
|
|
47566
|
-
}),
|
|
47779
|
+
return captureBearerHeader({
|
|
47780
|
+
captures: [CAPTURE_DECL],
|
|
47781
|
+
domains: TRUST_DOMAINS,
|
|
47782
|
+
// Read per capture, not at import: see `capture-window.ts`.
|
|
47783
|
+
windowMs: captureWindowMs(env),
|
|
47567
47784
|
port: getWsPort(),
|
|
47568
|
-
// Both: the explicit deadline for every bridge version, and the declared
|
|
47569
|
-
// window so mcp-utils' own derivation agrees with it.
|
|
47570
|
-
fetchTimeoutMs: bridgeDeadlineMs(windowMs),
|
|
47571
|
-
captureWindowMs: windowMs,
|
|
47572
47785
|
serverName: PACKAGE_NAME,
|
|
47573
|
-
version: VERSION
|
|
47786
|
+
version: VERSION,
|
|
47787
|
+
what: "a Teams token",
|
|
47788
|
+
guidance: "Open a signed-in teams.cloud.microsoft tab and click into any chat \u2014 that is what makes the page call the chat service; an idle tab never does \u2014 then retry.",
|
|
47789
|
+
createTransport: createCaptureTransport
|
|
47574
47790
|
});
|
|
47575
|
-
try {
|
|
47576
|
-
await transport.start();
|
|
47577
|
-
try {
|
|
47578
|
-
const raw = await transport.server.captureRequestHeader({
|
|
47579
|
-
...CAPTURE_DECL,
|
|
47580
|
-
timeoutMs: windowMs
|
|
47581
|
-
});
|
|
47582
|
-
if (typeof raw !== "string") {
|
|
47583
|
-
throw new Error(`${CAPTURE_DECL.host}: capture returned no header`);
|
|
47584
|
-
}
|
|
47585
|
-
const token = stripBearer(raw);
|
|
47586
|
-
if (token.length < MIN_TOKEN_LENGTH) {
|
|
47587
|
-
throw new Error(
|
|
47588
|
-
`${CAPTURE_DECL.host}: authorization header was present but too short to be a token (${token.length} chars)`
|
|
47589
|
-
);
|
|
47590
|
-
}
|
|
47591
|
-
return token;
|
|
47592
|
-
} catch (e) {
|
|
47593
|
-
const detail = e.message;
|
|
47594
|
-
throw new Error(
|
|
47595
|
-
`could not capture a Teams token from the browser (${detail}). Open a signed-in teams.cloud.microsoft tab and click into any chat \u2014 that is what makes the page call the chat service; an idle tab never does \u2014 then retry.`
|
|
47596
|
-
);
|
|
47597
|
-
}
|
|
47598
|
-
} finally {
|
|
47599
|
-
try {
|
|
47600
|
-
await transport.close();
|
|
47601
|
-
} catch {
|
|
47602
|
-
}
|
|
47603
|
-
}
|
|
47604
47791
|
}
|
|
47605
|
-
var DEFAULT_WS_PORT, CAPTURE_DECL, TRUST_DOMAINS,
|
|
47792
|
+
var DEFAULT_WS_PORT, CAPTURE_DECL, TRUST_DOMAINS, createCaptureTransport;
|
|
47606
47793
|
var init_auth_fetchproxy = __esm({
|
|
47607
47794
|
"src/auth-fetchproxy.ts"() {
|
|
47608
47795
|
"use strict";
|
|
@@ -47610,6 +47797,7 @@ var init_auth_fetchproxy = __esm({
|
|
|
47610
47797
|
init_dist2();
|
|
47611
47798
|
init_capture_window();
|
|
47612
47799
|
init_version();
|
|
47800
|
+
init_fetchproxy();
|
|
47613
47801
|
DEFAULT_WS_PORT = 37149;
|
|
47614
47802
|
CAPTURE_DECL = {
|
|
47615
47803
|
host: "teams.cloud.microsoft",
|
|
@@ -47617,7 +47805,7 @@ var init_auth_fetchproxy = __esm({
|
|
|
47617
47805
|
headerName: "authorization"
|
|
47618
47806
|
};
|
|
47619
47807
|
TRUST_DOMAINS = [CAPTURE_DECL.host];
|
|
47620
|
-
|
|
47808
|
+
createCaptureTransport = (opts) => createFetchproxyTransport(opts);
|
|
47621
47809
|
}
|
|
47622
47810
|
});
|
|
47623
47811
|
|
|
@@ -47644,56 +47832,26 @@ async function captureSharePointTokenViaFetchproxy(host, env = process.env) {
|
|
|
47644
47832
|
`refusing to capture a SharePoint token for ${JSON.stringify(host)}: not a *.sharepoint.com host`
|
|
47645
47833
|
);
|
|
47646
47834
|
}
|
|
47647
|
-
|
|
47648
|
-
|
|
47649
|
-
|
|
47650
|
-
// `
|
|
47651
|
-
|
|
47652
|
-
//
|
|
47653
|
-
// trusts `sharepoint.com`
|
|
47654
|
-
|
|
47655
|
-
|
|
47656
|
-
|
|
47657
|
-
|
|
47835
|
+
return captureBearerHeader({
|
|
47836
|
+
// The one request we capture from: any call the browser makes to this
|
|
47837
|
+
// OneDrive host (the caller resolves it from the file's host via
|
|
47838
|
+
// `captureHostFor`). A concrete host, never a wildcard — see the module note.
|
|
47839
|
+
captures: [{ host, path: "/*", headerName: "authorization" }],
|
|
47840
|
+
// The broad family domain as the trust scope. Same verb set as the chatsvc
|
|
47841
|
+
// capture, so an existing pairing that already trusts `sharepoint.com`
|
|
47842
|
+
// needs no re-approval.
|
|
47843
|
+
domains: SHAREPOINT_TRUST_DOMAINS,
|
|
47844
|
+
// Read per capture, not at import: see `capture-window.ts`.
|
|
47845
|
+
windowMs: captureWindowMs(env),
|
|
47658
47846
|
port: getWsPort(),
|
|
47659
|
-
// Both: the explicit deadline for every bridge version, and the declared
|
|
47660
|
-
// window so mcp-utils' own derivation agrees with it.
|
|
47661
|
-
fetchTimeoutMs: bridgeDeadlineMs(windowMs),
|
|
47662
|
-
captureWindowMs: windowMs,
|
|
47663
47847
|
serverName: PACKAGE_NAME,
|
|
47664
|
-
version: VERSION
|
|
47848
|
+
version: VERSION,
|
|
47849
|
+
what: `a SharePoint token for ${host}`,
|
|
47850
|
+
guidance: `Click around Teams or open one of your own OneDrive files \u2014 that makes the browser request ${host}, which is where the SharePoint token is captured from \u2014 then retry.`,
|
|
47851
|
+
createTransport: createCaptureTransport
|
|
47665
47852
|
});
|
|
47666
|
-
try {
|
|
47667
|
-
await transport.start();
|
|
47668
|
-
try {
|
|
47669
|
-
const raw = await transport.server.captureRequestHeader({
|
|
47670
|
-
...captureDecl,
|
|
47671
|
-
timeoutMs: windowMs
|
|
47672
|
-
});
|
|
47673
|
-
if (typeof raw !== "string") {
|
|
47674
|
-
throw new Error(`${host}: capture returned no header`);
|
|
47675
|
-
}
|
|
47676
|
-
const token = stripBearer(raw);
|
|
47677
|
-
if (token.length < MIN_TOKEN_LENGTH2) {
|
|
47678
|
-
throw new Error(
|
|
47679
|
-
`${host}: authorization header was present but too short to be a token (${token.length} chars)`
|
|
47680
|
-
);
|
|
47681
|
-
}
|
|
47682
|
-
return token;
|
|
47683
|
-
} catch (e) {
|
|
47684
|
-
const detail = e.message;
|
|
47685
|
-
throw new Error(
|
|
47686
|
-
`could not capture a SharePoint token for ${host} (${detail}). Click around Teams or open one of your own OneDrive files \u2014 that makes the browser request ${host}, which is where the SharePoint token is captured from \u2014 then retry.`
|
|
47687
|
-
);
|
|
47688
|
-
}
|
|
47689
|
-
} finally {
|
|
47690
|
-
try {
|
|
47691
|
-
await transport.close();
|
|
47692
|
-
} catch {
|
|
47693
|
-
}
|
|
47694
|
-
}
|
|
47695
47853
|
}
|
|
47696
|
-
var SHAREPOINT_TRUST_DOMAINS
|
|
47854
|
+
var SHAREPOINT_TRUST_DOMAINS;
|
|
47697
47855
|
var init_sharepoint_auth = __esm({
|
|
47698
47856
|
"src/sharepoint-auth.ts"() {
|
|
47699
47857
|
"use strict";
|
|
@@ -47702,7 +47860,6 @@ var init_sharepoint_auth = __esm({
|
|
|
47702
47860
|
init_auth_fetchproxy();
|
|
47703
47861
|
init_version();
|
|
47704
47862
|
SHAREPOINT_TRUST_DOMAINS = ["sharepoint.com"];
|
|
47705
|
-
MIN_TOKEN_LENGTH2 = 100;
|
|
47706
47863
|
}
|
|
47707
47864
|
});
|
|
47708
47865
|
|
|
@@ -47714,48 +47871,22 @@ __export(substrate_auth_exports, {
|
|
|
47714
47871
|
captureSubstrateTokenViaFetchproxy: () => captureSubstrateTokenViaFetchproxy
|
|
47715
47872
|
});
|
|
47716
47873
|
async function captureSubstrateTokenViaFetchproxy(env = process.env) {
|
|
47717
|
-
|
|
47718
|
-
const transport = createFetchproxyTransport({
|
|
47874
|
+
return captureBearerHeader({
|
|
47719
47875
|
// Same verb set as the other two captures (`capture_request_header` beside
|
|
47720
47876
|
// the always-on `fetch`); only the trusted domain differs.
|
|
47721
|
-
|
|
47722
|
-
|
|
47723
|
-
|
|
47724
|
-
|
|
47877
|
+
captures: [SUBSTRATE_CAPTURE_DECL],
|
|
47878
|
+
domains: SUBSTRATE_TRUST_DOMAINS,
|
|
47879
|
+
// Read per capture, not at import: see `capture-window.ts`.
|
|
47880
|
+
windowMs: captureWindowMs(env),
|
|
47725
47881
|
port: getWsPort(),
|
|
47726
|
-
fetchTimeoutMs: bridgeDeadlineMs(windowMs),
|
|
47727
|
-
captureWindowMs: windowMs,
|
|
47728
47882
|
serverName: PACKAGE_NAME,
|
|
47729
|
-
version: VERSION
|
|
47883
|
+
version: VERSION,
|
|
47884
|
+
what: "a Substrate search token",
|
|
47885
|
+
guidance: 'In a signed-in teams.cloud.microsoft tab, type anything into the search box at the top and press Enter \u2014 that is what makes Teams call substrate.office.com, where the token is read from \u2014 then retry. A "not in declared set" error means the ContextMint Bridge pairing does not trust substrate.office.com yet: re-pair microsoft-teams-mcp once.',
|
|
47886
|
+
createTransport: createCaptureTransport
|
|
47730
47887
|
});
|
|
47731
|
-
try {
|
|
47732
|
-
await transport.start();
|
|
47733
|
-
try {
|
|
47734
|
-
const raw = await transport.server.captureRequestHeader({ ...SUBSTRATE_CAPTURE_DECL, timeoutMs: windowMs });
|
|
47735
|
-
if (typeof raw !== "string") {
|
|
47736
|
-
throw new Error(`${SUBSTRATE_CAPTURE_DECL.host}: capture returned no header`);
|
|
47737
|
-
}
|
|
47738
|
-
const token = stripBearer(raw);
|
|
47739
|
-
if (token.length < MIN_TOKEN_LENGTH3) {
|
|
47740
|
-
throw new Error(
|
|
47741
|
-
`${SUBSTRATE_CAPTURE_DECL.host}: authorization header was present but too short to be a token (${token.length} chars)`
|
|
47742
|
-
);
|
|
47743
|
-
}
|
|
47744
|
-
return token;
|
|
47745
|
-
} catch (e) {
|
|
47746
|
-
const detail = e.message;
|
|
47747
|
-
throw new Error(
|
|
47748
|
-
`could not capture a Substrate search token from the browser (${detail}). In a signed-in teams.cloud.microsoft tab, type anything into the search box at the top and press Enter \u2014 that is what makes Teams call substrate.office.com, where the token is read from \u2014 then retry. A "not in declared set" error means the ContextMint Bridge pairing does not trust substrate.office.com yet: re-pair microsoft-teams-mcp once.`
|
|
47749
|
-
);
|
|
47750
|
-
}
|
|
47751
|
-
} finally {
|
|
47752
|
-
try {
|
|
47753
|
-
await transport.close();
|
|
47754
|
-
} catch {
|
|
47755
|
-
}
|
|
47756
|
-
}
|
|
47757
47888
|
}
|
|
47758
|
-
var SUBSTRATE_CAPTURE_DECL, SUBSTRATE_TRUST_DOMAINS
|
|
47889
|
+
var SUBSTRATE_CAPTURE_DECL, SUBSTRATE_TRUST_DOMAINS;
|
|
47759
47890
|
var init_substrate_auth = __esm({
|
|
47760
47891
|
"src/substrate-auth.ts"() {
|
|
47761
47892
|
"use strict";
|
|
@@ -47769,7 +47900,6 @@ var init_substrate_auth = __esm({
|
|
|
47769
47900
|
headerName: "authorization"
|
|
47770
47901
|
};
|
|
47771
47902
|
SUBSTRATE_TRUST_DOMAINS = [SUBSTRATE_CAPTURE_DECL.host];
|
|
47772
|
-
MIN_TOKEN_LENGTH3 = 100;
|
|
47773
47903
|
}
|
|
47774
47904
|
});
|
|
47775
47905
|
|
|
@@ -48351,6 +48481,46 @@ var TokenManager = class {
|
|
|
48351
48481
|
return res;
|
|
48352
48482
|
}
|
|
48353
48483
|
};
|
|
48484
|
+
var RECAPTURE_SENTINEL = "fetchproxy:recapture";
|
|
48485
|
+
var UNKNOWN_CAPTURED_TOKEN_TTL_MS = 10 * 60 * 1e3;
|
|
48486
|
+
function capturedBearerTokens(accessToken, opts = {}) {
|
|
48487
|
+
const now = opts.now ?? Date.now;
|
|
48488
|
+
let expiresAt;
|
|
48489
|
+
try {
|
|
48490
|
+
expiresAt = decodeJwtExp(accessToken) * 1e3;
|
|
48491
|
+
} catch {
|
|
48492
|
+
expiresAt = now() + (opts.unknownTtlMs ?? UNKNOWN_CAPTURED_TOKEN_TTL_MS);
|
|
48493
|
+
}
|
|
48494
|
+
return { accessToken, refreshToken: RECAPTURE_SENTINEL, expiresAt };
|
|
48495
|
+
}
|
|
48496
|
+
function createCapturedTokenManager(opts) {
|
|
48497
|
+
const { direct } = opts;
|
|
48498
|
+
const wrap = (token) => capturedBearerTokens(token, {
|
|
48499
|
+
...opts.unknownTtlMs !== void 0 ? { unknownTtlMs: opts.unknownTtlMs } : {},
|
|
48500
|
+
...opts.now !== void 0 ? { now: opts.now } : {}
|
|
48501
|
+
});
|
|
48502
|
+
const persistence = direct === void 0 ? opts.persistence ?? void 0 : void 0;
|
|
48503
|
+
return new TokenManager({
|
|
48504
|
+
initial: async () => wrap(direct ?? await opts.capture()),
|
|
48505
|
+
refresh: async () => {
|
|
48506
|
+
if (direct !== void 0) {
|
|
48507
|
+
throw opts.onDirectRejected ? opts.onDirectRejected() : new McpToolError("The directly supplied access token was rejected (401).", {
|
|
48508
|
+
status: 401,
|
|
48509
|
+
kind: "credential_rejected",
|
|
48510
|
+
hint: "A directly supplied token cannot be refreshed automatically. Replace it with a current one, or unset it to capture from a signed-in browser tab instead."
|
|
48511
|
+
});
|
|
48512
|
+
}
|
|
48513
|
+
return wrap(await opts.capture());
|
|
48514
|
+
},
|
|
48515
|
+
...persistence !== void 0 ? { persistence } : {},
|
|
48516
|
+
// Never fatal: the token is in hand and re-capturable.
|
|
48517
|
+
onPersistError: (err) => {
|
|
48518
|
+
opts.onPersistError?.(err);
|
|
48519
|
+
},
|
|
48520
|
+
...opts.skewMs !== void 0 ? { skewMs: opts.skewMs } : {},
|
|
48521
|
+
...opts.now !== void 0 ? { now: opts.now } : {}
|
|
48522
|
+
});
|
|
48523
|
+
}
|
|
48354
48524
|
|
|
48355
48525
|
// src/token-cache.ts
|
|
48356
48526
|
init_dist2();
|
|
@@ -48362,11 +48532,6 @@ function tokenCachePath(env = process.env) {
|
|
|
48362
48532
|
fileName: "token.json"
|
|
48363
48533
|
});
|
|
48364
48534
|
}
|
|
48365
|
-
function isToken(raw) {
|
|
48366
|
-
if (raw === null || typeof raw !== "object") return false;
|
|
48367
|
-
const t = raw;
|
|
48368
|
-
return typeof t.accessToken === "string" && t.accessToken !== "" && typeof t.expiresAt === "number" && (t.refreshToken === void 0 || typeof t.refreshToken === "string");
|
|
48369
|
-
}
|
|
48370
48535
|
function bindingFor(env) {
|
|
48371
48536
|
if (readEnvVar("TEAMS_ACCESS_TOKEN", { env }) !== void 0) return null;
|
|
48372
48537
|
if (parseBoolEnv("TEAMS_DISABLE_FETCHPROXY", { env })) return null;
|
|
@@ -48379,7 +48544,7 @@ function createTokenCache(env = process.env) {
|
|
|
48379
48544
|
return createFileStatePersistence({
|
|
48380
48545
|
filePath: tokenCachePath(env),
|
|
48381
48546
|
boundTo,
|
|
48382
|
-
validate: (raw) =>
|
|
48547
|
+
validate: (raw) => isBearerTokens(raw) ? raw : null
|
|
48383
48548
|
});
|
|
48384
48549
|
}
|
|
48385
48550
|
function reportCacheWriteFailure(err) {
|
|
@@ -48798,113 +48963,15 @@ function hasRealTitle(s) {
|
|
|
48798
48963
|
|
|
48799
48964
|
// src/network-error.ts
|
|
48800
48965
|
init_dist2();
|
|
48801
|
-
|
|
48802
|
-
var
|
|
48803
|
-
|
|
48804
|
-
|
|
48805
|
-
"
|
|
48806
|
-
|
|
48807
|
-
|
|
48808
|
-
|
|
48809
|
-
|
|
48810
|
-
"UND_ERR_CONNECT_TIMEOUT",
|
|
48811
|
-
"UND_ERR_SOCKET",
|
|
48812
|
-
"UND_ERR_HEADERS_TIMEOUT"
|
|
48813
|
-
]);
|
|
48814
|
-
var CERT_CODES = /* @__PURE__ */ new Set([
|
|
48815
|
-
"UNABLE_TO_GET_ISSUER_CERT_LOCALLY",
|
|
48816
|
-
"UNABLE_TO_GET_ISSUER_CERT",
|
|
48817
|
-
"UNABLE_TO_VERIFY_LEAF_SIGNATURE",
|
|
48818
|
-
"SELF_SIGNED_CERT_IN_CHAIN",
|
|
48819
|
-
"DEPTH_ZERO_SELF_SIGNED_CERT",
|
|
48820
|
-
"CERT_HAS_EXPIRED",
|
|
48821
|
-
"CERT_NOT_YET_VALID",
|
|
48822
|
-
"ERR_TLS_CERT_ALTNAME_INVALID"
|
|
48823
|
-
]);
|
|
48824
|
-
function codeOf(e) {
|
|
48825
|
-
if (e === null || typeof e !== "object") return void 0;
|
|
48826
|
-
const code2 = e.code;
|
|
48827
|
-
return typeof code2 === "string" && code2 !== "" ? code2 : void 0;
|
|
48828
|
-
}
|
|
48829
|
-
function causes(err) {
|
|
48830
|
-
const out = [];
|
|
48831
|
-
let at = err;
|
|
48832
|
-
for (let depth = 0; depth < MAX_CAUSE_DEPTH && at !== void 0 && at !== null; depth++) {
|
|
48833
|
-
out.push(at);
|
|
48834
|
-
if (at instanceof AggregateError) out.push(...at.errors);
|
|
48835
|
-
at = at.cause;
|
|
48836
|
-
}
|
|
48837
|
-
return out;
|
|
48838
|
-
}
|
|
48839
|
-
function transportCauseCode(err) {
|
|
48840
|
-
for (const e of causes(err)) {
|
|
48841
|
-
const code2 = codeOf(e);
|
|
48842
|
-
if (code2 !== void 0) return code2;
|
|
48843
|
-
}
|
|
48844
|
-
return void 0;
|
|
48845
|
-
}
|
|
48846
|
-
function causeMessage(err) {
|
|
48847
|
-
const chain = causes(err).slice(1);
|
|
48848
|
-
for (let i = chain.length - 1; i >= 0; i--) {
|
|
48849
|
-
const e = chain[i];
|
|
48850
|
-
if (e instanceof Error && e.message !== "") return e.message;
|
|
48851
|
-
}
|
|
48852
|
-
return void 0;
|
|
48853
|
-
}
|
|
48854
|
-
function isFetchFailed(err) {
|
|
48855
|
-
return err instanceof TypeError && err.message === "fetch failed";
|
|
48856
|
-
}
|
|
48857
|
-
function proxyRefusalStatus(err) {
|
|
48858
|
-
for (const e of causes(err)) {
|
|
48859
|
-
if (codeOf(e) === "ERR_PROXY_TUNNEL") {
|
|
48860
|
-
const m = /\b(\d{3})\b/.exec(e instanceof Error ? e.message : "");
|
|
48861
|
-
return m ? Number(m[1]) : "unknown";
|
|
48862
|
-
}
|
|
48863
|
-
if (e instanceof Error) {
|
|
48864
|
-
const m = /^Proxy response \((\d{3})\) !== 200 when HTTP Tunneling/.exec(e.message);
|
|
48865
|
-
if (m) return Number(m[1]);
|
|
48866
|
-
}
|
|
48867
|
-
}
|
|
48868
|
-
return void 0;
|
|
48869
|
-
}
|
|
48870
|
-
function proxyRefusalHint(status, host) {
|
|
48871
|
-
if (status !== 403 && status !== 407 && status !== "unknown") return void 0;
|
|
48872
|
-
return `The outbound proxy this server runs behind refused the connection to ${host}: its egress policy does not allow that host. On a hosted (mcp-host) registration, the host must be on the registration's egress allow-list \u2014 the owner accepts the manifest's egress proposal (or adds the host) on the registration, then retries. Elsewhere, ask whoever runs the proxy to allow it.`;
|
|
48873
|
-
}
|
|
48874
|
-
function hintFor(code2, host, err) {
|
|
48875
|
-
const refused = proxyRefusalStatus(err);
|
|
48876
|
-
if (refused !== void 0) {
|
|
48877
|
-
const policy = proxyRefusalHint(refused, host);
|
|
48878
|
-
if (policy !== void 0) return policy;
|
|
48879
|
-
return `The outbound proxy this server runs behind could not open a connection to ${host} (it answered ${refused}). Retry; if it persists, check the proxy can reach the host.`;
|
|
48880
|
-
}
|
|
48881
|
-
if (code2 !== void 0 && DNS_CODES.has(code2)) {
|
|
48882
|
-
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.`;
|
|
48883
|
-
}
|
|
48884
|
-
if (code2 !== void 0 && CERT_CODES.has(code2)) {
|
|
48885
|
-
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.`;
|
|
48886
|
-
}
|
|
48887
|
-
if (code2 !== void 0 && CONNECT_CODES.has(code2)) {
|
|
48888
|
-
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.`;
|
|
48889
|
-
}
|
|
48890
|
-
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.`;
|
|
48891
|
-
}
|
|
48892
|
-
function describeTransportFailure(err, url2, service) {
|
|
48893
|
-
if (!isFetchFailed(err)) return void 0;
|
|
48894
|
-
let host;
|
|
48895
|
-
try {
|
|
48896
|
-
host = new URL(url2).hostname;
|
|
48897
|
-
} catch {
|
|
48898
|
-
host = "(unknown host)";
|
|
48899
|
-
}
|
|
48900
|
-
const code2 = transportCauseCode(err);
|
|
48901
|
-
const detail = [code2, causeMessage(err)].filter((s) => s !== void 0);
|
|
48902
|
-
const why = detail.length > 0 ? ` (${[...new Set(detail)].join(": ")})` : "";
|
|
48903
|
-
return new McpToolError(`Could not reach ${service} at ${host}${why}.`, {
|
|
48904
|
-
kind: "transport",
|
|
48905
|
-
hint: hintFor(code2, host, err),
|
|
48906
|
-
cause: err
|
|
48907
|
-
});
|
|
48966
|
+
init_dist2();
|
|
48967
|
+
var TEAMS_HINTS = {
|
|
48968
|
+
// Name the hosts a split-tunnel VPN actually fails on for Teams.
|
|
48969
|
+
dns: (host) => `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.`,
|
|
48970
|
+
// "before Teams answered", whichever Teams host (image store, gateway, SharePoint) it was.
|
|
48971
|
+
connect: (host) => `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.`
|
|
48972
|
+
};
|
|
48973
|
+
function describeTransportFailure2(err, url2, service) {
|
|
48974
|
+
return describeTransportFailure(err, url2, service, { hints: TEAMS_HINTS });
|
|
48908
48975
|
}
|
|
48909
48976
|
|
|
48910
48977
|
// src/chatsvc.ts
|
|
@@ -48919,8 +48986,6 @@ function chatServiceBase(env = process.env) {
|
|
|
48919
48986
|
const region = readEnvVar("TEAMS_CHATSVC_REGION", { env }) ?? DEFAULT_REGION;
|
|
48920
48987
|
return `https://teams.cloud.microsoft/api/chatsvc/${encodeURIComponent(region)}/v1`;
|
|
48921
48988
|
}
|
|
48922
|
-
var UNKNOWN_TOKEN_TTL_MS = 10 * 60 * 1e3;
|
|
48923
|
-
var RECAPTURE_SENTINEL = "fetchproxy:recapture";
|
|
48924
48989
|
var REQUEST_TIMEOUT_MS = 6e4;
|
|
48925
48990
|
var MAX_CONVERSATION_PAGES = 10;
|
|
48926
48991
|
var MAX_MESSAGE_PAGES = 20;
|
|
@@ -48947,19 +49012,6 @@ function outcomeUnknown(method, e, hint) {
|
|
|
48947
49012
|
var SEND_OUTCOME_HINT = "The message may already have been posted \u2014 check the conversation (teams_read_conversation) before retrying; do not resend blindly.";
|
|
48948
49013
|
var REACTION_OUTCOME_HINT = "The reaction change may already have been applied \u2014 check the message (teams_read_conversation) before retrying.";
|
|
48949
49014
|
var HORIZON_OUTCOME_HINT = "The read marker may already have moved \u2014 check the conversation (teams_read_conversation) before retrying; moving it again to the same message is harmless.";
|
|
48950
|
-
function outcomeUnknownStatus(e) {
|
|
48951
|
-
const status = e.cause?.status;
|
|
48952
|
-
return typeof status === "number" ? status : void 0;
|
|
48953
|
-
}
|
|
48954
|
-
function toBearerTokens(accessToken) {
|
|
48955
|
-
let expiresAt;
|
|
48956
|
-
try {
|
|
48957
|
-
expiresAt = decodeJwtExp(accessToken) * 1e3;
|
|
48958
|
-
} catch {
|
|
48959
|
-
expiresAt = Date.now() + UNKNOWN_TOKEN_TTL_MS;
|
|
48960
|
-
}
|
|
48961
|
-
return { accessToken, refreshToken: RECAPTURE_SENTINEL, expiresAt };
|
|
48962
|
-
}
|
|
48963
49015
|
var ChatServiceClient = class {
|
|
48964
49016
|
#baseUrl;
|
|
48965
49017
|
/**
|
|
@@ -49234,39 +49286,12 @@ var ChatServiceClient = class {
|
|
|
49234
49286
|
if (this.#configError) throw this.#configError;
|
|
49235
49287
|
}
|
|
49236
49288
|
#tokenManager() {
|
|
49237
|
-
|
|
49238
|
-
|
|
49239
|
-
|
|
49240
|
-
|
|
49241
|
-
|
|
49242
|
-
|
|
49243
|
-
// There is no refresh grant — re-capture instead. But a token supplied as
|
|
49244
|
-
// TEAMS_ACCESS_TOKEN must NOT be "refreshed" from the browser: that would
|
|
49245
|
-
// silently swap the operator's chosen credential for whichever account a
|
|
49246
|
-
// tab is signed into.
|
|
49247
|
-
refresh: async () => {
|
|
49248
|
-
if (direct !== void 0) throw this.#directRejected();
|
|
49249
|
-
return toBearerTokens(await this.#capture());
|
|
49250
|
-
},
|
|
49251
|
-
// A failed cache write must not fail the call that triggered it.
|
|
49252
|
-
...persistence ? {
|
|
49253
|
-
persistence: {
|
|
49254
|
-
load: () => persistence.load(),
|
|
49255
|
-
save: (t) => {
|
|
49256
|
-
try {
|
|
49257
|
-
persistence.save(t);
|
|
49258
|
-
} catch (e) {
|
|
49259
|
-
reportCacheWriteFailure(e);
|
|
49260
|
-
}
|
|
49261
|
-
},
|
|
49262
|
-
clear: () => {
|
|
49263
|
-
try {
|
|
49264
|
-
persistence.clear();
|
|
49265
|
-
} catch {
|
|
49266
|
-
}
|
|
49267
|
-
}
|
|
49268
|
-
}
|
|
49269
|
-
} : {}
|
|
49289
|
+
this.#tokens ??= createCapturedTokenManager({
|
|
49290
|
+
capture: () => this.#capture(),
|
|
49291
|
+
direct: this.#direct,
|
|
49292
|
+
onDirectRejected: () => this.#directRejected(),
|
|
49293
|
+
persistence: this.#direct === void 0 ? createTokenCache(this.#env) : null,
|
|
49294
|
+
onPersistError: reportCacheWriteFailure
|
|
49270
49295
|
});
|
|
49271
49296
|
return this.#tokens;
|
|
49272
49297
|
}
|
|
@@ -49309,7 +49334,7 @@ var ChatServiceClient = class {
|
|
|
49309
49334
|
r = await fetchBounded(url2, init, opts);
|
|
49310
49335
|
} catch (e) {
|
|
49311
49336
|
if (write) throw outcomeUnknown(method, e, write.hint);
|
|
49312
|
-
throw
|
|
49337
|
+
throw describeTransportFailure2(e, url2, serviceFor(url2)) ?? e;
|
|
49313
49338
|
}
|
|
49314
49339
|
body = r.body;
|
|
49315
49340
|
return r.res;
|
|
@@ -49416,16 +49441,11 @@ function sharePointTokenCachePath(env = process.env) {
|
|
|
49416
49441
|
fileName: "sharepoint-tokens.json"
|
|
49417
49442
|
});
|
|
49418
49443
|
}
|
|
49419
|
-
function isToken2(raw) {
|
|
49420
|
-
if (raw === null || typeof raw !== "object") return false;
|
|
49421
|
-
const t = raw;
|
|
49422
|
-
return typeof t.accessToken === "string" && t.accessToken !== "" && typeof t.expiresAt === "number" && (t.refreshToken === void 0 || typeof t.refreshToken === "string");
|
|
49423
|
-
}
|
|
49424
49444
|
function validateMap(raw) {
|
|
49425
49445
|
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return null;
|
|
49426
49446
|
const out = {};
|
|
49427
49447
|
for (const [host, value] of Object.entries(raw)) {
|
|
49428
|
-
if (
|
|
49448
|
+
if (isBearerTokens(value)) out[host] = value;
|
|
49429
49449
|
}
|
|
49430
49450
|
return out;
|
|
49431
49451
|
}
|
|
@@ -49472,24 +49492,13 @@ async function captureSharePointTokenLazily(host) {
|
|
|
49472
49492
|
const mod = await Promise.resolve().then(() => (init_sharepoint_auth(), sharepoint_auth_exports));
|
|
49473
49493
|
return mod.captureSharePointTokenViaFetchproxy(host);
|
|
49474
49494
|
}
|
|
49475
|
-
var UNKNOWN_TOKEN_TTL_MS2 = 10 * 60 * 1e3;
|
|
49476
|
-
var RECAPTURE_SENTINEL2 = "fetchproxy:recapture";
|
|
49477
49495
|
var REQUEST_TIMEOUT_MS2 = 6e4;
|
|
49478
49496
|
async function reachable(url2, run) {
|
|
49479
49497
|
try {
|
|
49480
49498
|
return await run();
|
|
49481
49499
|
} catch (e) {
|
|
49482
|
-
throw
|
|
49483
|
-
}
|
|
49484
|
-
}
|
|
49485
|
-
function toBearerTokens2(accessToken) {
|
|
49486
|
-
let expiresAt;
|
|
49487
|
-
try {
|
|
49488
|
-
expiresAt = decodeJwtExp(accessToken) * 1e3;
|
|
49489
|
-
} catch {
|
|
49490
|
-
expiresAt = Date.now() + UNKNOWN_TOKEN_TTL_MS2;
|
|
49500
|
+
throw describeTransportFailure2(e, url2, "SharePoint") ?? e;
|
|
49491
49501
|
}
|
|
49492
|
-
return { accessToken, refreshToken: RECAPTURE_SENTINEL2, expiresAt };
|
|
49493
49502
|
}
|
|
49494
49503
|
var SharePointClient = class {
|
|
49495
49504
|
#env;
|
|
@@ -49573,12 +49582,9 @@ var SharePointClient = class {
|
|
|
49573
49582
|
#managerFor(host) {
|
|
49574
49583
|
const existing = this.#managers.get(host);
|
|
49575
49584
|
if (existing) return existing;
|
|
49576
|
-
const
|
|
49577
|
-
|
|
49578
|
-
|
|
49579
|
-
// No refresh grant — re-capture instead.
|
|
49580
|
-
refresh: async () => toBearerTokens2(await this.#capture(host)),
|
|
49581
|
-
...persistence ? { persistence } : {}
|
|
49585
|
+
const mgr = createCapturedTokenManager({
|
|
49586
|
+
capture: () => this.#capture(host),
|
|
49587
|
+
persistence: this.#cache?.forHost(host) ?? null
|
|
49582
49588
|
});
|
|
49583
49589
|
this.#managers.set(host, mgr);
|
|
49584
49590
|
return mgr;
|
|
@@ -49706,18 +49712,13 @@ function substrateTokenCachePath(env = process.env) {
|
|
|
49706
49712
|
fileName: "substrate-token.json"
|
|
49707
49713
|
});
|
|
49708
49714
|
}
|
|
49709
|
-
function isToken3(raw) {
|
|
49710
|
-
if (raw === null || typeof raw !== "object") return false;
|
|
49711
|
-
const t = raw;
|
|
49712
|
-
return typeof t.accessToken === "string" && t.accessToken !== "" && typeof t.expiresAt === "number" && (t.refreshToken === void 0 || typeof t.refreshToken === "string");
|
|
49713
|
-
}
|
|
49714
49715
|
function createSubstrateTokenCache(env = process.env) {
|
|
49715
49716
|
if (!parseBoolEnv("TEAMS_TOKEN_CACHE", { env, default: true })) return null;
|
|
49716
49717
|
if (parseBoolEnv("TEAMS_DISABLE_FETCHPROXY", { env })) return null;
|
|
49717
49718
|
const file2 = createFileStatePersistence({
|
|
49718
49719
|
filePath: substrateTokenCachePath(env),
|
|
49719
49720
|
boundTo: "fetchproxy",
|
|
49720
|
-
validate: (raw) =>
|
|
49721
|
+
validate: (raw) => isBearerTokens(raw) ? raw : null
|
|
49721
49722
|
});
|
|
49722
49723
|
return {
|
|
49723
49724
|
load: () => file2.load(),
|
|
@@ -49741,19 +49742,8 @@ function createSubstrateTokenCache(env = process.env) {
|
|
|
49741
49742
|
// src/substrate.ts
|
|
49742
49743
|
var SUBSTRATE_QUERY_URL = "https://substrate.office.com/searchservice/api/v2/query";
|
|
49743
49744
|
var CAPTURE_RETRY_COOLDOWN_MS = 10 * 60 * 1e3;
|
|
49744
|
-
var UNKNOWN_TOKEN_TTL_MS3 = 10 * 60 * 1e3;
|
|
49745
|
-
var RECAPTURE_SENTINEL3 = "fetchproxy:recapture";
|
|
49746
49745
|
var REQUEST_TIMEOUT_MS3 = 3e4;
|
|
49747
49746
|
var MAX_RESPONSE_BYTES = 8 * 1024 * 1024;
|
|
49748
|
-
function toBearerTokens3(accessToken) {
|
|
49749
|
-
let expiresAt;
|
|
49750
|
-
try {
|
|
49751
|
-
expiresAt = decodeJwtExp(accessToken) * 1e3;
|
|
49752
|
-
} catch {
|
|
49753
|
-
expiresAt = Date.now() + UNKNOWN_TOKEN_TTL_MS3;
|
|
49754
|
-
}
|
|
49755
|
-
return { accessToken, refreshToken: RECAPTURE_SENTINEL3, expiresAt };
|
|
49756
|
-
}
|
|
49757
49747
|
async function captureSubstrateTokenLazily() {
|
|
49758
49748
|
const mod = await Promise.resolve().then(() => (init_substrate_auth(), substrate_auth_exports));
|
|
49759
49749
|
return mod.captureSubstrateTokenViaFetchproxy();
|
|
@@ -49872,19 +49862,17 @@ var SubstrateClient = class {
|
|
|
49872
49862
|
this.#fetchImpl = opts.fetchImpl ?? ((input2, init) => fetch(input2, init));
|
|
49873
49863
|
const recapture = async () => {
|
|
49874
49864
|
try {
|
|
49875
|
-
const
|
|
49865
|
+
const token = await capture();
|
|
49876
49866
|
this.#captureFailure = null;
|
|
49877
|
-
return
|
|
49867
|
+
return token;
|
|
49878
49868
|
} catch (error62) {
|
|
49879
49869
|
this.#captureFailure = { at: Date.now(), error: error62 };
|
|
49880
49870
|
throw error62;
|
|
49881
49871
|
}
|
|
49882
49872
|
};
|
|
49883
|
-
|
|
49884
|
-
|
|
49885
|
-
|
|
49886
|
-
refresh: recapture,
|
|
49887
|
-
...persistence ? { persistence } : {}
|
|
49873
|
+
this.#manager = createCapturedTokenManager({
|
|
49874
|
+
capture: recapture,
|
|
49875
|
+
persistence: createSubstrateTokenCache(env)
|
|
49888
49876
|
});
|
|
49889
49877
|
if (parseBoolEnv("TEAMS_DISABLE_FETCHPROXY", { env })) {
|
|
49890
49878
|
this.#configError = new McpToolError("Substrate search is disabled (no token source).", {
|
|
@@ -49926,7 +49914,7 @@ var SubstrateClient = class {
|
|
|
49926
49914
|
}
|
|
49927
49915
|
);
|
|
49928
49916
|
} catch (e) {
|
|
49929
|
-
throw
|
|
49917
|
+
throw describeTransportFailure2(e, SUBSTRATE_QUERY_URL, "Substrate search") ?? e;
|
|
49930
49918
|
}
|
|
49931
49919
|
text = r.body;
|
|
49932
49920
|
return r.res;
|
|
@@ -50999,7 +50987,7 @@ async function confirmMarks(ctx, opts) {
|
|
|
50999
50987
|
});
|
|
51000
50988
|
}
|
|
51001
50989
|
function unconfirmedWhy(e) {
|
|
51002
|
-
const status =
|
|
50990
|
+
const status = writeOutcomeStatus(e);
|
|
51003
50991
|
return e.timedOut ? "it did not answer in time" : status !== void 0 ? `it answered HTTP ${status}` : "the connection dropped";
|
|
51004
50992
|
}
|
|
51005
50993
|
async function applyMarks(chatsvc, plans) {
|
|
@@ -52053,22 +52041,12 @@ async function threadRoot(chatsvc, channelId, id, me) {
|
|
|
52053
52041
|
});
|
|
52054
52042
|
}
|
|
52055
52043
|
}
|
|
52056
|
-
|
|
52057
|
-
|
|
52058
|
-
|
|
52059
|
-
|
|
52060
|
-
|
|
52061
|
-
|
|
52062
|
-
const why = e.timedOut ? "it did not answer in time" : status !== void 0 ? `it answered HTTP ${status} after the post was sent` : "the connection dropped";
|
|
52063
|
-
return {
|
|
52064
|
-
ok: false,
|
|
52065
|
-
result: untrustedResult2({
|
|
52066
|
-
status: "unknown",
|
|
52067
|
-
conversation,
|
|
52068
|
-
warning: `Teams did not confirm this post (${why}), so it may already be in the conversation. Check the conversation before retrying (teams_read_conversation); do not resend blindly.`
|
|
52069
|
-
})
|
|
52070
|
-
};
|
|
52071
|
-
}
|
|
52044
|
+
function unconfirmedPost(conversation) {
|
|
52045
|
+
return (e) => untrustedResult2({
|
|
52046
|
+
status: "unknown",
|
|
52047
|
+
conversation,
|
|
52048
|
+
warning: `Teams did not confirm this post (${unknownOutcomeReason(e, { sent: "the post" })}), so it may already be in the conversation. Check the conversation before retrying (teams_read_conversation); do not resend blindly.`
|
|
52049
|
+
});
|
|
52072
52050
|
}
|
|
52073
52051
|
function registerSendTools(server, { chatsvc }) {
|
|
52074
52052
|
server.registerTool(
|
|
@@ -52160,7 +52138,7 @@ function registerSendTools(server, { chatsvc }) {
|
|
|
52160
52138
|
now: /* @__PURE__ */ new Date(),
|
|
52161
52139
|
...properties
|
|
52162
52140
|
});
|
|
52163
|
-
const sent = await writeOrUnknown(() => chatsvc.sendMessage(postTo, body), target);
|
|
52141
|
+
const sent = await writeOrUnknown(() => chatsvc.sendMessage(postTo, body), unconfirmedPost(target));
|
|
52164
52142
|
if (!sent.ok) return sent.result;
|
|
52165
52143
|
let found;
|
|
52166
52144
|
let readBackFailed = false;
|
|
@@ -52308,7 +52286,7 @@ function registerReactTools(server, { chatsvc }) {
|
|
|
52308
52286
|
}
|
|
52309
52287
|
const shown = remove ? "gone" : "present";
|
|
52310
52288
|
if (unconfirmed !== void 0 && verified !== true) {
|
|
52311
|
-
const status =
|
|
52289
|
+
const status = writeOutcomeStatus(unconfirmed);
|
|
52312
52290
|
const why = unconfirmed.timedOut ? "it did not answer in time" : status !== void 0 ? `it answered HTTP ${status}` : "the connection dropped";
|
|
52313
52291
|
return untrustedResult2({
|
|
52314
52292
|
status: "unknown",
|