@google/gemini-cli 0.66.0-nightly.20261019.ged96faedf → 0.66.0-preview.0

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.
Files changed (68) hide show
  1. package/bundle/{chunk-NU74STQ5.js → chunk-3IDBGHHH.js} +9 -1
  2. package/bundle/{chunk-6P5R6RYB.js → chunk-3RUC6ZA6.js} +1 -1
  3. package/bundle/{chunk-R7UPATQC.js → chunk-5ILL3HFF.js} +2 -2
  4. package/bundle/{chunk-L5EUR3NN.js → chunk-7KFTNUNE.js} +9 -1
  5. package/bundle/{chunk-G3S7WMRG.js → chunk-BAGLLEOA.js} +237 -141
  6. package/bundle/{chunk-J5QPCO3J.js → chunk-D4FKL6WQ.js} +7 -7
  7. package/bundle/{chunk-QCWGLPCO.js → chunk-D6WVFS5S.js} +292 -161
  8. package/bundle/{chunk-NAPT3FAL.js → chunk-EONTJM32.js} +7 -7
  9. package/bundle/{chunk-LPQB7ZQE.js → chunk-EZIYD2G6.js} +58 -71
  10. package/bundle/{chunk-ERBSM2HU.js → chunk-GA6BNFA6.js} +3 -3
  11. package/bundle/{chunk-AWUJQFYP.js → chunk-HH6UGBJR.js} +1 -1
  12. package/bundle/{chunk-ZFQ347ZN.js → chunk-I6Q2CIAC.js} +15211 -8012
  13. package/bundle/{chunk-IDCWFZU3.js → chunk-ITTQBJIT.js} +1 -1
  14. package/bundle/{chunk-464WBVYM.js → chunk-LC5SKSCL.js} +1 -1
  15. package/bundle/{chunk-CTWJ3T77.js → chunk-OCM26AU2.js} +2 -2
  16. package/bundle/{chunk-5P6HIACT.js → chunk-OGLIOKXL.js} +3 -3
  17. package/bundle/{chunk-5VQUE3OF.js → chunk-PWTTZOSA.js} +1 -1
  18. package/bundle/{chunk-V5XDOSXJ.js → chunk-RJ3GGOMU.js} +13 -7
  19. package/bundle/{chunk-O5W3WYI5.js → chunk-SZE3LGYD.js} +1 -1
  20. package/bundle/{chunk-RE4V6I3G.js → chunk-TZZ34RGM.js} +1 -1
  21. package/bundle/{chunk-7UDRNCIH.js → chunk-VDKR3AIQ.js} +3 -3
  22. package/bundle/{chunk-YP27UYI4.js → chunk-VN6QPF5Z.js} +1 -1
  23. package/bundle/{chunk-GCW52DLB.js → chunk-XH7KGX2J.js} +2 -2
  24. package/bundle/{chunk-7K5J3ME2.js → chunk-Z3NAT6YU.js} +8 -9
  25. package/bundle/{cleanup-5DK3CVRM.js → cleanup-5UHD34BY.js} +2 -2
  26. package/bundle/{cleanup-6FAZDCL3.js → cleanup-D3DWTLIR.js} +2 -2
  27. package/bundle/{cleanup-WAU2KYGS.js → cleanup-GF4YFJWT.js} +2 -2
  28. package/bundle/{core-AGGXDQOT.js → core-CEUTCQ3Z.js} +3 -1
  29. package/bundle/{dist-2ELAEESC.js → core-GH3VFZSV.js} +3 -1
  30. package/bundle/{devtoolsService-UO6ZB72B.js → devtoolsService-3EKYJHGL.js} +95 -32
  31. package/bundle/{devtoolsService-FBTSVQ57.js → devtoolsService-KQTX22AU.js} +96 -34
  32. package/bundle/{devtoolsService-AWYBM7VP.js → devtoolsService-YPLYVNTF.js} +95 -32
  33. package/bundle/{dist-4PMK5N6W.js → dist-Q63VF7PG.js} +3 -1
  34. package/bundle/docs/cli/plan-mode.md +1 -1
  35. package/bundle/docs/tools/mcp-server.md +6 -0
  36. package/bundle/{gemini-GK2XZNXB.js → gemini-LRDBGCHF.js} +14 -14
  37. package/bundle/{gemini-OUEDCH4P.js → gemini-VE6EAOCY.js} +198 -214
  38. package/bundle/{gemini-DOXUDJDY.js → gemini-WV55NKMQ.js} +13 -13
  39. package/bundle/gemini.js +7 -7
  40. package/bundle/{interactiveCli-7LIKGDTJ.js → interactiveCli-3XUYDTSL.js} +10 -9
  41. package/bundle/{interactiveCli-TG7PGV4V.js → interactiveCli-S5K6P65K.js} +10 -9
  42. package/bundle/{interactiveCli-GZ4N4JS2.js → interactiveCli-U2CP5B64.js} +301 -319
  43. package/bundle/{liteRtServerManager-KAPXZ3EU.js → liteRtServerManager-HYOFIRWR.js} +4 -4
  44. package/bundle/{liteRtServerManager-KJI7ARTA.js → liteRtServerManager-KF2BIFPA.js} +4 -4
  45. package/bundle/{liteRtServerManager-MSJIWMWP.js → liteRtServerManager-RYZUX64K.js} +4 -4
  46. package/bundle/{oauth2-provider-RMF7U2UN.js → oauth2-provider-LVJMV7QY.js} +1 -1
  47. package/bundle/{oauth2-provider-OISPWSWH.js → oauth2-provider-O2MBVTUX.js} +1 -1
  48. package/bundle/{oauth2-provider-ZM5GWCNX.js → oauth2-provider-XAA7HRXL.js} +79 -41
  49. package/bundle/{start-5GIUIER3.js → start-234HHUMV.js} +6 -6
  50. package/bundle/{start-APIVGXZ3.js → start-JWGPML6R.js} +6 -6
  51. package/bundle/{start-GRIS2RDP.js → start-TRMMLCHR.js} +6 -6
  52. package/package.json +1 -1
  53. package/bundle/chunk-5YXWOKC2.js +0 -402181
  54. package/bundle/chunk-CYBHTFCS.js +0 -154
  55. package/bundle/chunk-HDP6V6JI.js +0 -1956
  56. package/bundle/chunk-RACMC24X.js +0 -118
  57. package/bundle/chunk-VGPHCSAB.js +0 -101859
  58. package/bundle/chunk-VXYA6LA4.js +0 -1571
  59. package/bundle/chunk-W6ALEP4H.js +0 -512
  60. package/bundle/chunk-XY2QSBID.js +0 -17603
  61. package/bundle/cleanup-WTTU6IKS.js +0 -32
  62. package/bundle/devtoolsService-TFBVUD5K.js +0 -4359
  63. package/bundle/dist-F22VU44K.js +0 -2280
  64. package/bundle/gemini-XDNOFFX7.js +0 -17970
  65. package/bundle/interactiveCli-MGIJ7GNE.js +0 -35601
  66. package/bundle/liteRtServerManager-OY2ULYPZ.js +0 -65
  67. package/bundle/oauth2-provider-VT6UHLKR.js +0 -273
  68. package/bundle/start-XQGNK32L.js +0 -18
@@ -28182,8 +28182,8 @@ var require_utils = __commonJS({
28182
28182
  var HOST_DELIMS = { "@": "%40", "/": "%2F", "?": "%3F", "#": "%23", ":": "%3A" };
28183
28183
  var HOST_DELIM_RE = /[@/?#:]/g;
28184
28184
  var HOST_DELIM_NO_COLON_RE = /[@/?#]/g;
28185
- function reescapeHostDelimiters(host, isIP2) {
28186
- const re = isIP2 ? HOST_DELIM_NO_COLON_RE : HOST_DELIM_RE;
28185
+ function reescapeHostDelimiters(host, isIP3) {
28186
+ const re = isIP3 ? HOST_DELIM_NO_COLON_RE : HOST_DELIM_RE;
28187
28187
  re.lastIndex = 0;
28188
28188
  return host.replace(re, (ch) => HOST_DELIMS[ch]);
28189
28189
  }
@@ -28665,7 +28665,7 @@ var require_fast_uri = __commonJS({
28665
28665
  fragment: void 0
28666
28666
  };
28667
28667
  let malformedAuthorityOrPort = false;
28668
- let isIP2 = false;
28668
+ let isIP3 = false;
28669
28669
  if (options.reference === "suffix") {
28670
28670
  if (options.scheme) {
28671
28671
  uri = options.scheme + ":" + uri;
@@ -28695,9 +28695,9 @@ var require_fast_uri = __commonJS({
28695
28695
  if (ipv4result === false) {
28696
28696
  const ipv6result = normalizeIPv6(parsed.host);
28697
28697
  parsed.host = ipv6result.host.toLowerCase();
28698
- isIP2 = ipv6result.isIPV6;
28698
+ isIP3 = ipv6result.isIPV6;
28699
28699
  } else {
28700
- isIP2 = true;
28700
+ isIP3 = true;
28701
28701
  }
28702
28702
  }
28703
28703
  if (parsed.scheme === void 0 && parsed.userinfo === void 0 && parsed.host === void 0 && parsed.port === void 0 && parsed.query === void 0 && !parsed.path) {
@@ -28714,7 +28714,7 @@ var require_fast_uri = __commonJS({
28714
28714
  }
28715
28715
  const schemeHandler = getSchemeHandler(options.scheme || parsed.scheme);
28716
28716
  if (!options.unicodeSupport && (!schemeHandler || !schemeHandler.unicodeSupport)) {
28717
- if (parsed.host && (options.domainHost || schemeHandler && schemeHandler.domainHost) && isIP2 === false && nonSimpleDomain(parsed.host)) {
28717
+ if (parsed.host && (options.domainHost || schemeHandler && schemeHandler.domainHost) && isIP3 === false && nonSimpleDomain(parsed.host)) {
28718
28718
  try {
28719
28719
  parsed.host = URL.domainToASCII(parsed.host.toLowerCase());
28720
28720
  } catch (e2) {
@@ -28728,7 +28728,7 @@ var require_fast_uri = __commonJS({
28728
28728
  parsed.scheme = unescape(parsed.scheme);
28729
28729
  }
28730
28730
  if (parsed.host !== void 0) {
28731
- parsed.host = reescapeHostDelimiters(unescape(parsed.host), isIP2);
28731
+ parsed.host = reescapeHostDelimiters(unescape(parsed.host), isIP3);
28732
28732
  }
28733
28733
  }
28734
28734
  if (parsed.path) {
@@ -221870,7 +221870,7 @@ var require_dump = __commonJS({
221870
221870
  var require_dns = __commonJS({
221871
221871
  "packages/core/node_modules/undici/lib/interceptor/dns.js"(exports2, module2) {
221872
221872
  "use strict";
221873
- var { isIP: isIP2 } = __require("node:net");
221873
+ var { isIP: isIP3 } = __require("node:net");
221874
221874
  var { lookup: lookup3 } = __require("node:dns");
221875
221875
  var DecoratorHandler = require_decorator_handler();
221876
221876
  var { InvalidArgumentError, InformationalError } = require_errors6();
@@ -222169,7 +222169,7 @@ var require_dns = __commonJS({
222169
222169
  return (dispatch) => {
222170
222170
  return function dnsInterceptor(origDispatchOpts, handler) {
222171
222171
  const origin = origDispatchOpts.origin.constructor === URL ? origDispatchOpts.origin : new URL(origDispatchOpts.origin);
222172
- if (isIP2(origin.hostname) !== 0) {
222172
+ if (isIP3(origin.hostname) !== 0) {
222173
222173
  return dispatch(origDispatchOpts, handler);
222174
222174
  }
222175
222175
  instance2.runLookup(origin, origDispatchOpts, (err2, newOrigin) => {
@@ -252811,12 +252811,27 @@ function parseResponseData(error40) {
252811
252811
  }
252812
252812
  return void 0;
252813
252813
  }
252814
+ var HTTP_401_REGEX = /(?:\bHTTP(?:\/\d(?:\.\d)?)?(?:\s+(?:status|error))?|(?<!\b(?:exit|exited)\s+(?:with\s+)?)\bstatus(?:code|\s*code)?)[:\s]+401\b|(?:\b401\b[^\w\r\n]{1,4}\bUnauthorized\b|\bUnauthorized\b[^\w\r\n]{1,4}\b401\b)/i;
252815
+ function isRecord(value) {
252816
+ return typeof value === "object" && value !== null && !Array.isArray(value);
252817
+ }
252814
252818
  function isAuthenticationError(error40) {
252815
- if (error40 && typeof error40 === "object" && "code" in error40) {
252816
- const errorCode = error40["code"];
252817
- if (typeof errorCode === "number" && errorCode === 401) {
252819
+ const friendly = toFriendlyError(error40);
252820
+ if (friendly instanceof UnauthorizedError) {
252821
+ return true;
252822
+ }
252823
+ if (isRecord(error40)) {
252824
+ const code = error40["code"] ?? error40["status"] ?? error40["statusCode"];
252825
+ if (code === 401 || code === "401") {
252818
252826
  return true;
252819
252827
  }
252828
+ const response = error40["response"];
252829
+ if (isRecord(response)) {
252830
+ const responseCode = response["status"] ?? response["statusCode"];
252831
+ if (responseCode === 401 || responseCode === "401") {
252832
+ return true;
252833
+ }
252834
+ }
252820
252835
  }
252821
252836
  if (error40 instanceof Error && error40.name === "UnauthorizedError") {
252822
252837
  return true;
@@ -252825,7 +252840,7 @@ function isAuthenticationError(error40) {
252825
252840
  return true;
252826
252841
  }
252827
252842
  const message = getErrorMessage(error40);
252828
- if (message.includes("401")) {
252843
+ if (HTTP_401_REGEX.test(message)) {
252829
252844
  return true;
252830
252845
  }
252831
252846
  return false;
@@ -273896,14 +273911,14 @@ function safeJsonToMarkdown(text) {
273896
273911
  return text;
273897
273912
  }
273898
273913
  }
273899
- function isRecord(value) {
273914
+ function isRecord2(value) {
273900
273915
  return typeof value === "object" && value !== null && !Array.isArray(value);
273901
273916
  }
273902
273917
  function isArrayOfSimilarObjects(data) {
273903
273918
  if (data.length === 0) {
273904
273919
  return false;
273905
273920
  }
273906
- if (!data.every(isRecord))
273921
+ if (!data.every(isRecord2))
273907
273922
  return false;
273908
273923
  const firstKeys = Object.keys(data[0]).sort().join(",");
273909
273924
  return data.every((item) => Object.keys(item).sort().join(",") === firstKeys);
@@ -274281,7 +274296,7 @@ var DeclarativeTool = class {
274281
274296
  * Type guard to check if an unknown value represents a ToolParameterSchema object.
274282
274297
  */
274283
274298
  isParameterSchema(obj) {
274284
- return isRecord(obj) && "type" in obj;
274299
+ return isRecord2(obj) && "type" in obj;
274285
274300
  }
274286
274301
  /**
274287
274302
  * Adds the `wait_for_previous` parameter to the tool's schema.
@@ -274294,7 +274309,7 @@ var DeclarativeTool = class {
274294
274309
  const props = schema2.properties;
274295
274310
  let propertiesObj = {};
274296
274311
  if (props !== void 0) {
274297
- if (!isRecord(props)) {
274312
+ if (!isRecord2(props)) {
274298
274313
  return schema2;
274299
274314
  }
274300
274315
  propertiesObj = props;
@@ -278756,7 +278771,7 @@ var KeychainService = class {
278756
278771
  async loadKeychainModule() {
278757
278772
  const moduleName = "@github/keytar";
278758
278773
  const module2 = await import(moduleName);
278759
- const potential = isRecord(module2) && module2["default"] || module2;
278774
+ const potential = isRecord2(module2) && module2["default"] || module2;
278760
278775
  const result2 = KeychainSchema.safeParse(potential);
278761
278776
  if (result2.success) {
278762
278777
  return potential;
@@ -283686,8 +283701,8 @@ function isValidToolName(name3, options = {}) {
283686
283701
  }
283687
283702
 
283688
283703
  // packages/core/dist/src/generated/git-commit.js
283689
- var GIT_COMMIT_INFO = "ed96faedf";
283690
- var CLI_VERSION = "0.66.0-nightly.20261019.ged96faedf";
283704
+ var GIT_COMMIT_INFO = "b041de017";
283705
+ var CLI_VERSION = "0.66.0-preview.0";
283691
283706
 
283692
283707
  // packages/core/dist/src/ide/detect-ide.js
283693
283708
  var IDE_DEFINITIONS = {
@@ -307808,7 +307823,7 @@ function getVersion() {
307808
307823
  }
307809
307824
  versionPromise = (async () => {
307810
307825
  const pkgJson = await getPackageJson(__dirname4);
307811
- return "0.66.0-nightly.20261019.ged96faedf";
307826
+ return "0.66.0-preview.0";
307812
307827
  })();
307813
307828
  return versionPromise;
307814
307829
  }
@@ -309461,8 +309476,8 @@ var BaseLlmClient = class {
309461
309476
  }
309462
309477
  }, shouldRetryOnContent, "generateJson", role);
309463
309478
  const parsed = JSON.parse(this.cleanJsonResponse(getResponseText(result2).trim(), model));
309464
- const isRecord3 = (val) => typeof val === "object" && val !== null && !Array.isArray(val);
309465
- if (isRecord3(parsed)) {
309479
+ const isRecord4 = (val) => typeof val === "object" && val !== null && !Array.isArray(val);
309480
+ if (isRecord4(parsed)) {
309466
309481
  return parsed;
309467
309482
  }
309468
309483
  throw new Error("Invalid JSON response format from LLM");
@@ -314750,7 +314765,7 @@ function getSafeGitEnv(baseEnv = process.env) {
314750
314765
  GIT_SSH_COMMAND: gitSshCommand,
314751
314766
  GH_PROMPT_DISABLED: "1",
314752
314767
  GCM_INTERACTIVE: "never",
314753
- GIT_CONFIG_GLOBAL: devNullPath,
314768
+ ...baseEnv["GIT_CONFIG_GLOBAL"] ? { GIT_CONFIG_GLOBAL: baseEnv["GIT_CONFIG_GLOBAL"] } : {},
314754
314769
  GIT_CONFIG_SYSTEM: devNullPath,
314755
314770
  GIT_CONFIG_NOSYSTEM: "1",
314756
314771
  GIT_CONFIG_COUNT: "7",
@@ -325066,12 +325081,14 @@ ${truncated}`;
325066
325081
  for (const key of gitConfigKeys) {
325067
325082
  baseEnv[key] = sourceEnv[key];
325068
325083
  }
325084
+ if (!baseEnv["GIT_CONFIG_GLOBAL"]) {
325085
+ delete baseEnv["GIT_CONFIG_GLOBAL"];
325086
+ }
325069
325087
  let gitConfigCount = parseInt(baseEnv["GIT_CONFIG_COUNT"] || "0", 10);
325070
325088
  const devNullPath = os31.platform() === "win32" ? "NUL" : "/dev/null";
325071
- baseEnv["GIT_CONFIG_GLOBAL"] = devNullPath;
325072
325089
  baseEnv["GIT_CONFIG_SYSTEM"] = devNullPath;
325073
325090
  baseEnv["GIT_CONFIG_NOSYSTEM"] = "1";
325074
- sanitizationConfig.allowedEnvironmentVariables.push("GIT_CONFIG_COUNT", "GIT_CONFIG_GLOBAL", "GIT_CONFIG_SYSTEM", "GIT_CONFIG_NOSYSTEM");
325091
+ sanitizationConfig.allowedEnvironmentVariables.push("GIT_CONFIG_COUNT", "GIT_CONFIG_SYSTEM", "GIT_CONFIG_NOSYSTEM");
325075
325092
  const defaultGitOverrides = [
325076
325093
  ["credential.helper", ""],
325077
325094
  ["core.fsmonitor", ""],
@@ -327289,6 +327306,31 @@ function isAddressPrivate(address) {
327289
327306
  return true;
327290
327307
  }
327291
327308
  }
327309
+ function isEnterprisePrivateAddress(addressOrHost) {
327310
+ const normalized2 = sanitizeHostname(addressOrHost).toLowerCase();
327311
+ if (normalized2.endsWith(".internal") || normalized2.endsWith(".local")) {
327312
+ return true;
327313
+ }
327314
+ if (normalized2 === "localhost" || normalized2.endsWith(".localhost")) {
327315
+ return false;
327316
+ }
327317
+ try {
327318
+ if (!import_ipaddr.default.isValid(normalized2)) {
327319
+ return false;
327320
+ }
327321
+ let addr2 = import_ipaddr.default.parse(normalized2);
327322
+ if (addr2 instanceof import_ipaddr.default.IPv6 && addr2.isIPv4MappedAddress()) {
327323
+ addr2 = addr2.toIPv4Address();
327324
+ }
327325
+ if (isBenchmarkAddress(addr2)) {
327326
+ return false;
327327
+ }
327328
+ const range2 = addr2.range();
327329
+ return range2 === "private" || range2 === "carrierGradeNat" || range2 === "uniqueLocal";
327330
+ } catch {
327331
+ return false;
327332
+ }
327333
+ }
327292
327334
  async function isPrivateIpAsync(url3) {
327293
327335
  let parsedUrl;
327294
327336
  try {
@@ -342049,6 +342091,7 @@ var import_google_auth_library5 = __toESM(require_src10(), 1);
342049
342091
 
342050
342092
  // packages/core/dist/src/mcp/oauth-utils.js
342051
342093
  import { lookup as lookup2 } from "node:dns/promises";
342094
+ import { isIP as isIP2 } from "node:net";
342052
342095
  var ResourceMismatchError = class extends Error {
342053
342096
  constructor(message) {
342054
342097
  super(message);
@@ -342069,6 +342112,7 @@ function isLoopbackUrl(urlStr) {
342069
342112
  return false;
342070
342113
  }
342071
342114
  }
342115
+ var PRIVATE_NETWORK_REMEDIATION_HINT = 'Set "oauth.allowPrivateNetwork": true in settings.json for this MCP server if it is on a trusted private network.';
342072
342116
  async function validateOAuthEndpointUrl(urlStr, options) {
342073
342117
  let resolvedUrl = urlStr.trim();
342074
342118
  if (options?.allowRelative && options.baseUri) {
@@ -342112,7 +342156,14 @@ async function validateOAuthEndpointUrl(urlStr, options) {
342112
342156
  return parsed.toString();
342113
342157
  }
342114
342158
  if (isAddressPrivate(hostname3)) {
342115
- throw new OAuthSecurityError(`OAuth endpoint "${resolvedUrl}" points to private or reserved IP address which is blocked.`);
342159
+ const isEnterprisePrivate = isEnterprisePrivateAddress(hostname3);
342160
+ if (!options?.allowPrivateNetwork || !isEnterprisePrivate) {
342161
+ const hint = isEnterprisePrivate ? ` ${PRIVATE_NETWORK_REMEDIATION_HINT}` : "";
342162
+ throw new OAuthSecurityError(`OAuth endpoint "${resolvedUrl}" points to private or reserved IP address which is blocked.${hint}`);
342163
+ }
342164
+ if (isIP2(hostname3) !== 0) {
342165
+ return parsed.toString();
342166
+ }
342116
342167
  }
342117
342168
  try {
342118
342169
  const addresses = await lookup2(hostname3, { all: true });
@@ -342121,7 +342172,11 @@ async function validateOAuthEndpointUrl(urlStr, options) {
342121
342172
  }
342122
342173
  for (const addr2 of addresses) {
342123
342174
  if (isAddressPrivate(addr2.address)) {
342124
- throw new OAuthSecurityError(`OAuth endpoint "${resolvedUrl}" resolves to private network address "${addr2.address}" which is blocked.`);
342175
+ const isEnterprisePrivate = isEnterprisePrivateAddress(addr2.address);
342176
+ if (!options?.allowPrivateNetwork || !isEnterprisePrivate) {
342177
+ const hint = isEnterprisePrivate ? ` ${PRIVATE_NETWORK_REMEDIATION_HINT}` : "";
342178
+ throw new OAuthSecurityError(`OAuth endpoint "${resolvedUrl}" resolves to private network address "${addr2.address}" which is blocked.${hint}`);
342179
+ }
342125
342180
  }
342126
342181
  }
342127
342182
  } catch (error40) {
@@ -342168,7 +342223,8 @@ var OAuthUtils = class {
342168
342223
  try {
342169
342224
  const validatedUrl = await validateOAuthEndpointUrl(resourceMetadataUrl, {
342170
342225
  allowLoopback: options?.allowLoopback,
342171
- expectedOrigin: options?.expectedOrigin
342226
+ expectedOrigin: options?.expectedOrigin,
342227
+ allowPrivateNetwork: options?.allowPrivateNetwork
342172
342228
  });
342173
342229
  const response = await fetch(validatedUrl);
342174
342230
  if (!response.ok) {
@@ -342193,7 +342249,8 @@ var OAuthUtils = class {
342193
342249
  static async fetchAuthorizationServerMetadata(authServerMetadataUrl, options) {
342194
342250
  try {
342195
342251
  const validatedUrl = await validateOAuthEndpointUrl(authServerMetadataUrl, {
342196
- allowLoopback: options?.allowLoopback
342252
+ allowLoopback: options?.allowLoopback,
342253
+ allowPrivateNetwork: options?.allowPrivateNetwork
342197
342254
  });
342198
342255
  const response = await fetch(validatedUrl);
342199
342256
  if (!response.ok) {
@@ -342239,7 +342296,8 @@ var OAuthUtils = class {
342239
342296
  */
342240
342297
  static async discoverAuthorizationServerMetadata(authServerUrl, options) {
342241
342298
  const validatedBaseUrl = await validateOAuthEndpointUrl(authServerUrl, {
342242
- allowLoopback: options?.allowLoopback
342299
+ allowLoopback: options?.allowLoopback,
342300
+ allowPrivateNetwork: options?.allowPrivateNetwork
342243
342301
  });
342244
342302
  const authServerUrlObj = new URL(validatedBaseUrl);
342245
342303
  const base = `${authServerUrlObj.protocol}//${authServerUrlObj.host}`;
@@ -342266,17 +342324,18 @@ var OAuthUtils = class {
342266
342324
  * @param serverUrl The base URL of the server
342267
342325
  * @returns The discovered OAuth configuration or null if not available
342268
342326
  */
342269
- static async discoverOAuthConfig(serverUrl) {
342327
+ static async discoverOAuthConfig(serverUrl, options) {
342270
342328
  try {
342271
342329
  const allowLoopback = isLoopbackUrl(serverUrl);
342330
+ const allowPrivateNetwork = options?.allowPrivateNetwork;
342272
342331
  const expectedOrigin = new URL(serverUrl).origin;
342273
342332
  const wellKnownUrls = this.buildWellKnownUrls(serverUrl);
342274
- let resourceMetadata = await this.fetchProtectedResourceMetadata(wellKnownUrls.protectedResource, { allowLoopback, expectedOrigin });
342333
+ let resourceMetadata = await this.fetchProtectedResourceMetadata(wellKnownUrls.protectedResource, { allowLoopback, expectedOrigin, allowPrivateNetwork });
342275
342334
  if (!resourceMetadata) {
342276
342335
  const url3 = new URL(serverUrl);
342277
342336
  if (url3.pathname && url3.pathname !== "/") {
342278
342337
  const rootBasedUrls = this.buildWellKnownUrls(serverUrl, true);
342279
- resourceMetadata = await this.fetchProtectedResourceMetadata(rootBasedUrls.protectedResource, { allowLoopback, expectedOrigin });
342338
+ resourceMetadata = await this.fetchProtectedResourceMetadata(rootBasedUrls.protectedResource, { allowLoopback, expectedOrigin, allowPrivateNetwork });
342280
342339
  }
342281
342340
  }
342282
342341
  if (resourceMetadata) {
@@ -342285,11 +342344,13 @@ var OAuthUtils = class {
342285
342344
  throw new ResourceMismatchError(`Protected resource ${resourceMetadata.resource} does not match expected ${expectedResource}`);
342286
342345
  }
342287
342346
  }
342347
+ const authServerDiscoveryOptions = {
342348
+ allowLoopback,
342349
+ ...allowPrivateNetwork !== void 0 ? { allowPrivateNetwork } : {}
342350
+ };
342288
342351
  if (resourceMetadata?.authorization_servers?.length) {
342289
342352
  const authServerUrl = resourceMetadata.authorization_servers[0];
342290
- const authServerMetadata2 = await this.discoverAuthorizationServerMetadata(authServerUrl, {
342291
- allowLoopback
342292
- });
342353
+ const authServerMetadata2 = await this.discoverAuthorizationServerMetadata(authServerUrl, authServerDiscoveryOptions);
342293
342354
  if (authServerMetadata2) {
342294
342355
  const config2 = this.metadataToOAuthConfig(authServerMetadata2);
342295
342356
  if (authServerMetadata2.registration_endpoint) {
@@ -342299,9 +342360,7 @@ var OAuthUtils = class {
342299
342360
  }
342300
342361
  }
342301
342362
  debugLogger.debug(`Trying OAuth discovery fallback at ${serverUrl}`);
342302
- const authServerMetadata = await this.discoverAuthorizationServerMetadata(serverUrl, {
342303
- allowLoopback
342304
- });
342363
+ const authServerMetadata = await this.discoverAuthorizationServerMetadata(serverUrl, authServerDiscoveryOptions);
342305
342364
  if (authServerMetadata) {
342306
342365
  const config2 = this.metadataToOAuthConfig(authServerMetadata);
342307
342366
  if (authServerMetadata.registration_endpoint) {
@@ -342338,22 +342397,25 @@ var OAuthUtils = class {
342338
342397
  * @param mcpServerUrl Optional MCP server URL to validate against the resource metadata
342339
342398
  * @returns The discovered OAuth configuration or null if not available
342340
342399
  */
342341
- static async discoverOAuthFromWWWAuthenticate(wwwAuthenticate, mcpServerUrl) {
342400
+ static async discoverOAuthFromWWWAuthenticate(wwwAuthenticate, mcpServerUrl, options) {
342342
342401
  const resourceMetadataUri = this.parseWWWAuthenticateHeader(wwwAuthenticate);
342343
342402
  if (!resourceMetadataUri) {
342344
342403
  return null;
342345
342404
  }
342346
342405
  const allowLoopback = mcpServerUrl ? isLoopbackUrl(mcpServerUrl) : false;
342406
+ const allowPrivateNetwork = options?.allowPrivateNetwork;
342347
342407
  const expectedOrigin = mcpServerUrl ? new URL(mcpServerUrl).origin : void 0;
342348
342408
  const validatedResourceMetadataUrl = await validateOAuthEndpointUrl(resourceMetadataUri, {
342349
342409
  allowLoopback,
342350
342410
  expectedOrigin,
342351
342411
  allowRelative: true,
342352
- baseUri: mcpServerUrl
342412
+ baseUri: mcpServerUrl,
342413
+ allowPrivateNetwork
342353
342414
  });
342354
342415
  const resourceMetadata = await this.fetchProtectedResourceMetadata(validatedResourceMetadataUrl, {
342355
342416
  allowLoopback,
342356
- expectedOrigin
342417
+ expectedOrigin,
342418
+ allowPrivateNetwork
342357
342419
  });
342358
342420
  if (resourceMetadata && mcpServerUrl) {
342359
342421
  const expectedResource = this.buildResourceParameter(mcpServerUrl);
@@ -342366,7 +342428,8 @@ var OAuthUtils = class {
342366
342428
  }
342367
342429
  const authServerUrl = resourceMetadata.authorization_servers[0];
342368
342430
  const authServerMetadata = await this.discoverAuthorizationServerMetadata(authServerUrl, {
342369
- allowLoopback
342431
+ allowLoopback,
342432
+ ...allowPrivateNetwork !== void 0 ? { allowPrivateNetwork } : {}
342370
342433
  });
342371
342434
  if (authServerMetadata) {
342372
342435
  return this.metadataToOAuthConfig(authServerMetadata);
@@ -342550,7 +342613,7 @@ var A2AAuthProviderFactory = class _A2AAuthProviderFactory {
342550
342613
  return provider;
342551
342614
  }
342552
342615
  case "oauth2": {
342553
- const { OAuth2AuthProvider } = await import("./oauth2-provider-VT6UHLKR.js");
342616
+ const { OAuth2AuthProvider } = await import("./oauth2-provider-O2MBVTUX.js");
342554
342617
  const provider = new OAuth2AuthProvider(authConfig, options.agentName ?? "unknown", agentCard, options.agentCardUrl);
342555
342618
  await provider.initialize();
342556
342619
  return provider;
@@ -346171,7 +346234,7 @@ function isNumberArray(value) {
346171
346234
  }
346172
346235
  function isTaskArray(value) {
346173
346236
  return Array.isArray(value) && value.every((item) => {
346174
- if (!isRecord(item))
346237
+ if (!isRecord2(item))
346175
346238
  return false;
346176
346239
  const id = item["id"];
346177
346240
  const desc = item["description"];
@@ -346188,7 +346251,7 @@ function isSnapshotState(text) {
346188
346251
  }
346189
346252
  try {
346190
346253
  const parsed = JSON.parse(trimmed2);
346191
- if (!isRecord(parsed))
346254
+ if (!isRecord2(parsed))
346192
346255
  return false;
346193
346256
  const isSnap = Array.isArray(parsed["active_tasks"]) && Array.isArray(parsed["discovered_facts"]) && Array.isArray(parsed["constraints_and_preferences"]) && Array.isArray(parsed["recent_arc"]);
346194
346257
  if (!isSnap) {
@@ -346233,7 +346296,7 @@ var SnapshotGenerator = class {
346233
346296
  if (previousStateJson) {
346234
346297
  try {
346235
346298
  const parsed = JSON.parse(previousStateJson);
346236
- if (isRecord(parsed)) {
346299
+ if (isRecord2(parsed)) {
346237
346300
  let loadedArc = [];
346238
346301
  if (isStringArray(parsed["recent_arc"])) {
346239
346302
  loadedArc = parsed["recent_arc"];
@@ -346330,7 +346393,7 @@ ${formatNodesForLlm(nodes)}`;
346330
346393
  promptId: this.env.promptId,
346331
346394
  abortSignal: new AbortController().signal
346332
346395
  });
346333
- if (isRecord(result2)) {
346396
+ if (isRecord2(result2)) {
346334
346397
  patch = result2;
346335
346398
  }
346336
346399
  } catch {
@@ -346362,7 +346425,7 @@ ${formatNodesForLlm(nodes)}`;
346362
346425
  const newTasks = patch["new_tasks"];
346363
346426
  if (Array.isArray(newTasks)) {
346364
346427
  for (const t2 of newTasks) {
346365
- if (isRecord(t2)) {
346428
+ if (isRecord2(t2)) {
346366
346429
  const desc = t2["description"];
346367
346430
  if (typeof desc === "string" && desc) {
346368
346431
  newState.active_tasks.push({
@@ -355774,11 +355837,11 @@ var AgentTool = class extends BaseDeclarativeTool {
355774
355837
  }
355775
355838
  mapParams(prompt, schema2) {
355776
355839
  const schemaObj = schema2;
355777
- if (!isRecord(schemaObj)) {
355840
+ if (!isRecord2(schemaObj)) {
355778
355841
  return { prompt };
355779
355842
  }
355780
355843
  const properties = schemaObj["properties"];
355781
- if (isRecord(properties)) {
355844
+ if (isRecord2(properties)) {
355782
355845
  const keys = Object.keys(properties);
355783
355846
  if (keys.length === 1) {
355784
355847
  return { [keys[0]]: prompt };
@@ -355860,11 +355923,11 @@ var DelegateInvocation = class extends BaseToolInvocation {
355860
355923
  return agentArgs;
355861
355924
  }
355862
355925
  const schemaObj = this.definition.inputConfig.inputSchema;
355863
- if (!isRecord(schemaObj)) {
355926
+ if (!isRecord2(schemaObj)) {
355864
355927
  return agentArgs;
355865
355928
  }
355866
355929
  const properties = schemaObj["properties"];
355867
- if (isRecord(properties)) {
355930
+ if (isRecord2(properties)) {
355868
355931
  const keys = Object.keys(properties);
355869
355932
  const primaryKey = keys.length === 1 ? keys[0] : "prompt";
355870
355933
  const value = agentArgs[primaryKey];
@@ -356352,8 +356415,8 @@ ${reminder}`;
356352
356415
  throw new Error("Invalid response from Local Gemini API: No text found");
356353
356416
  }
356354
356417
  const parsed = JSON.parse(result2.text);
356355
- const isRecord3 = (val) => typeof val === "object" && val !== null && !Array.isArray(val);
356356
- if (isRecord3(parsed)) {
356418
+ const isRecord4 = (val) => typeof val === "object" && val !== null && !Array.isArray(val);
356419
+ if (isRecord4(parsed)) {
356357
356420
  return parsed;
356358
356421
  }
356359
356422
  throw new Error("Invalid JSON response format from Local LLM");
@@ -361321,7 +361384,7 @@ var realPathCache = /* @__PURE__ */ new Map();
361321
361384
  function parseTrustedFoldersJson(content) {
361322
361385
  return JSON.parse((0, import_strip_json_comments.default)(content));
361323
361386
  }
361324
- function isRecord2(value) {
361387
+ function isRecord3(value) {
361325
361388
  return typeof value === "object" && value !== null && !Array.isArray(value);
361326
361389
  }
361327
361390
  function clearRealPathCacheForTesting() {
@@ -361414,7 +361477,7 @@ Please fix the file manually before trying to update it.`);
361414
361477
  const config2 = {};
361415
361478
  try {
361416
361479
  const parsed = parseTrustedFoldersJson(content);
361417
- if (isRecord2(parsed)) {
361480
+ if (isRecord3(parsed)) {
361418
361481
  for (const [rawPath, value] of Object.entries(parsed)) {
361419
361482
  if (isTrustLevel(value)) {
361420
361483
  config2[rawPath] = value;
@@ -361457,7 +361520,7 @@ function loadTrustedFolders() {
361457
361520
  if (fs67.existsSync(userPath)) {
361458
361521
  const content = fs67.readFileSync(userPath, "utf-8");
361459
361522
  const parsed = parseTrustedFoldersJson(content);
361460
- if (!isRecord2(parsed)) {
361523
+ if (!isRecord3(parsed)) {
361461
361524
  errors.push({
361462
361525
  message: "Trusted folders file is not a valid JSON object.",
361463
361526
  path: userPath
@@ -365150,7 +365213,7 @@ var PolicyEngine = class {
365150
365213
  let decision;
365151
365214
  const toolNamesToTry = toolCall.name ? getToolAliases(toolCall.name) : [];
365152
365215
  if (toolCall.name === AGENT_TOOL_NAME) {
365153
- if (isRecord(toolCall.args)) {
365216
+ if (isRecord2(toolCall.args)) {
365154
365217
  const subagentName = toolCall.args["agent_name"];
365155
365218
  if (typeof subagentName === "string") {
365156
365219
  toolNamesToTry.push(subagentName);
@@ -371222,7 +371285,7 @@ async function parseTokenEndpointResponse(response, operationName, defaultErrorC
371222
371285
  scope: scope || void 0
371223
371286
  };
371224
371287
  }
371225
- async function exchangeCodeForToken(config2, code, codeVerifier, redirectPort, resource) {
371288
+ async function exchangeCodeForToken(config2, code, codeVerifier, redirectPort, resource, options) {
371226
371289
  const redirectUri = getRedirectUri(config2, redirectPort);
371227
371290
  const params = new URLSearchParams({
371228
371291
  grant_type: "authorization_code",
@@ -371242,7 +371305,8 @@ async function exchangeCodeForToken(config2, code, codeVerifier, redirectPort, r
371242
371305
  }
371243
371306
  const allowLoopback = resource ? isLoopbackUrl(resource) : isLoopbackUrl(config2.tokenUrl);
371244
371307
  const validatedTokenUrl = await validateOAuthEndpointUrl(config2.tokenUrl, {
371245
- allowLoopback
371308
+ allowLoopback,
371309
+ allowPrivateNetwork: options?.allowPrivateNetwork
371246
371310
  });
371247
371311
  const response = await fetch(validatedTokenUrl, {
371248
371312
  method: "POST",
@@ -371254,7 +371318,7 @@ async function exchangeCodeForToken(config2, code, codeVerifier, redirectPort, r
371254
371318
  });
371255
371319
  return parseTokenEndpointResponse(response, "Token exchange", "no_access_token");
371256
371320
  }
371257
- async function refreshAccessToken(config2, refreshToken, tokenUrl, resource) {
371321
+ async function refreshAccessToken(config2, refreshToken, tokenUrl, resource, options) {
371258
371322
  const params = new URLSearchParams({
371259
371323
  grant_type: "refresh_token",
371260
371324
  refresh_token: refreshToken,
@@ -371274,7 +371338,8 @@ async function refreshAccessToken(config2, refreshToken, tokenUrl, resource) {
371274
371338
  }
371275
371339
  const allowLoopback = resource ? isLoopbackUrl(resource) : isLoopbackUrl(tokenUrl);
371276
371340
  const validatedTokenUrl = await validateOAuthEndpointUrl(tokenUrl, {
371277
- allowLoopback
371341
+ allowLoopback,
371342
+ allowPrivateNetwork: options?.allowPrivateNetwork
371278
371343
  });
371279
371344
  const response = await fetch(validatedTokenUrl, {
371280
371345
  method: "POST",
@@ -371304,7 +371369,8 @@ var MCPOAuthProvider = class {
371304
371369
  async registerClient(registrationUrl, config2, redirectPort, mcpServerUrl) {
371305
371370
  const allowLoopback = mcpServerUrl ? isLoopbackUrl(mcpServerUrl) : isLoopbackUrl(registrationUrl);
371306
371371
  const validatedRegistrationUrl = await validateOAuthEndpointUrl(registrationUrl, {
371307
- allowLoopback
371372
+ allowLoopback,
371373
+ allowPrivateNetwork: config2.allowPrivateNetwork
371308
371374
  });
371309
371375
  const redirectUri = getRedirectUri(config2, redirectPort);
371310
371376
  const registrationRequest = {
@@ -371335,10 +371401,10 @@ var MCPOAuthProvider = class {
371335
371401
  * @param mcpServerUrl The MCP server URL
371336
371402
  * @returns OAuth configuration if discovered, null otherwise
371337
371403
  */
371338
- async discoverOAuthFromMCPServer(mcpServerUrl) {
371339
- return OAuthUtils.discoverOAuthConfig(mcpServerUrl);
371404
+ async discoverOAuthFromMCPServer(mcpServerUrl, options) {
371405
+ return OAuthUtils.discoverOAuthConfig(mcpServerUrl, options);
371340
371406
  }
371341
- async discoverAuthServerMetadataForRegistration(issuer, mcpServerUrl) {
371407
+ async discoverAuthServerMetadataForRegistration(issuer, mcpServerUrl, options) {
371342
371408
  const allowLoopback = mcpServerUrl ? isLoopbackUrl(mcpServerUrl) : isLoopbackUrl(issuer);
371343
371409
  const authUrl = new URL7(issuer);
371344
371410
  const oidcPatterns = [
@@ -371374,7 +371440,10 @@ var MCPOAuthProvider = class {
371374
371440
  let discoveredMetadata = null;
371375
371441
  for (const issuerCandidate of attemptedIssuers) {
371376
371442
  debugLogger.debug(` Trying issuer URL: ${issuerCandidate}`);
371377
- const metadata2 = await OAuthUtils.discoverAuthorizationServerMetadata(issuerCandidate, { allowLoopback });
371443
+ const metadata2 = await OAuthUtils.discoverAuthorizationServerMetadata(issuerCandidate, {
371444
+ allowLoopback,
371445
+ ...options?.allowPrivateNetwork !== void 0 ? { allowPrivateNetwork: options.allowPrivateNetwork } : {}
371446
+ });
371378
371447
  if (metadata2) {
371379
371448
  selectedIssuer = issuerCandidate;
371380
371449
  discoveredMetadata = metadata2;
@@ -371422,7 +371491,7 @@ var MCPOAuthProvider = class {
371422
371491
  clientSecret: config2.clientSecret,
371423
371492
  scopes: config2.scopes,
371424
371493
  audiences: config2.audiences
371425
- }, refreshToken, tokenUrl, this.buildResourceParam(mcpServerUrl));
371494
+ }, refreshToken, tokenUrl, this.buildResourceParam(mcpServerUrl), { allowPrivateNetwork: config2.allowPrivateNetwork });
371426
371495
  }
371427
371496
  /**
371428
371497
  * Perform the full OAuth authorization code flow with PKCE.
@@ -371449,7 +371518,7 @@ var MCPOAuthProvider = class {
371449
371518
  if (response.status === 401 || response.status === 307) {
371450
371519
  const wwwAuthenticate = response.headers.get("www-authenticate");
371451
371520
  if (wwwAuthenticate) {
371452
- const discoveredConfig = await OAuthUtils.discoverOAuthFromWWWAuthenticate(wwwAuthenticate, mcpServerUrl);
371521
+ const discoveredConfig = await OAuthUtils.discoverOAuthFromWWWAuthenticate(wwwAuthenticate, mcpServerUrl, { allowPrivateNetwork: config2.allowPrivateNetwork });
371453
371522
  if (discoveredConfig) {
371454
371523
  config2 = {
371455
371524
  ...config2,
@@ -371472,7 +371541,7 @@ var MCPOAuthProvider = class {
371472
371541
  debugLogger.debug(`Failed to check endpoint for authentication requirements: ${getErrorMessage(error40)}`);
371473
371542
  }
371474
371543
  if (!config2.authorizationUrl) {
371475
- const discoveredConfig = await this.discoverOAuthFromMCPServer(mcpServerUrl);
371544
+ const discoveredConfig = await this.discoverOAuthFromMCPServer(mcpServerUrl, { allowPrivateNetwork: config2.allowPrivateNetwork });
371476
371545
  if (discoveredConfig) {
371477
371546
  config2 = {
371478
371547
  ...config2,
@@ -371491,74 +371560,91 @@ var MCPOAuthProvider = class {
371491
371560
  }
371492
371561
  }
371493
371562
  }
371563
+ const allowLoopback = mcpServerUrl ? isLoopbackUrl(mcpServerUrl) : (config2.authorizationUrl ? isLoopbackUrl(config2.authorizationUrl) : false) || (config2.tokenUrl ? isLoopbackUrl(config2.tokenUrl) : false);
371564
+ if (config2.authorizationUrl) {
371565
+ await validateOAuthEndpointUrl(config2.authorizationUrl, {
371566
+ allowLoopback,
371567
+ allowPrivateNetwork: config2.allowPrivateNetwork
371568
+ });
371569
+ }
371570
+ if (config2.tokenUrl) {
371571
+ await validateOAuthEndpointUrl(config2.tokenUrl, {
371572
+ allowLoopback,
371573
+ allowPrivateNetwork: config2.allowPrivateNetwork
371574
+ });
371575
+ }
371494
371576
  const pkceParams = generatePKCEParams();
371495
371577
  const preferredPort = getPortFromUrl(config2.redirectUri);
371496
371578
  debugLogger.debug(`Starting callback server for "${serverName}" (expected issuer: ${config2.issuer || "none"})...`);
371497
371579
  const requireIssInResponse = config2.authorizationResponseIssParameterSupported ?? Boolean(config2.issuer);
371498
371580
  const callbackServer = startCallbackServer(pkceParams.state, preferredPort, config2.issuer, requireIssInResponse);
371499
- const redirectPort = await callbackServer.port;
371500
- debugLogger.debug(`Callback server listening on port ${redirectPort}`);
371501
- if (!config2.clientId) {
371502
- let registrationUrl = config2.registrationUrl;
371503
- if (!registrationUrl) {
371504
- if (!config2.issuer) {
371505
- throw new Error("Cannot perform dynamic registration without issuer");
371506
- }
371507
- debugLogger.debug("\u2192 Attempting dynamic client registration...");
371508
- const { metadata: authServerMetadata } = await this.discoverAuthServerMetadataForRegistration(config2.issuer, mcpServerUrl);
371509
- registrationUrl = authServerMetadata.registration_endpoint;
371510
- }
371511
- if (registrationUrl) {
371512
- const clientRegistration = await this.registerClient(registrationUrl, config2, redirectPort, mcpServerUrl);
371513
- config2.clientId = clientRegistration.client_id;
371514
- if (clientRegistration.client_secret) {
371515
- config2.clientSecret = clientRegistration.client_secret;
371516
- }
371517
- debugLogger.debug("\u2713 Dynamic client registration successful");
371518
- } else {
371519
- throw new Error("No client ID provided and dynamic registration not supported");
371520
- }
371521
- }
371522
- if (!config2.clientId || !config2.authorizationUrl || !config2.tokenUrl) {
371523
- throw new Error("Missing required OAuth configuration after discovery and registration");
371524
- }
371525
- const allowLoopback = mcpServerUrl ? isLoopbackUrl(mcpServerUrl) : (config2.authorizationUrl ? isLoopbackUrl(config2.authorizationUrl) : false) || (config2.tokenUrl ? isLoopbackUrl(config2.tokenUrl) : false);
371526
- await validateOAuthEndpointUrl(config2.authorizationUrl, {
371527
- allowLoopback
371581
+ callbackServer.response.catch(() => {
371528
371582
  });
371529
- await validateOAuthEndpointUrl(config2.tokenUrl, {
371530
- allowLoopback
371531
- });
371532
- const flowConfig = {
371533
- clientId: config2.clientId,
371534
- clientSecret: config2.clientSecret,
371535
- authorizationUrl: config2.authorizationUrl,
371536
- tokenUrl: config2.tokenUrl,
371537
- scopes: config2.scopes,
371538
- audiences: config2.audiences,
371539
- redirectUri: config2.redirectUri
371540
- };
371541
- const resource = this.buildResourceParam(mcpServerUrl);
371542
- const authUrl = buildAuthorizationUrl(flowConfig, pkceParams, redirectPort, resource);
371543
- const userConsent = await getConsentForOauth(`Authentication required for MCP Server: '${serverName}.'`);
371544
- if (!userConsent) {
371545
- throw new FatalCancellationError("Authentication cancelled by user.");
371546
- }
371547
- displayMessage(`\u2192 Opening your browser for OAuth sign-in...
371583
+ let code;
371584
+ let redirectPort;
371585
+ let flowConfig;
371586
+ let resource;
371587
+ try {
371588
+ redirectPort = await callbackServer.port;
371589
+ debugLogger.debug(`Callback server listening on port ${redirectPort}`);
371590
+ if (!config2.clientId) {
371591
+ let registrationUrl = config2.registrationUrl;
371592
+ if (!registrationUrl) {
371593
+ if (!config2.issuer) {
371594
+ throw new Error("Cannot perform dynamic registration without issuer");
371595
+ }
371596
+ debugLogger.debug("\u2192 Attempting dynamic client registration...");
371597
+ const { metadata: authServerMetadata } = await this.discoverAuthServerMetadataForRegistration(config2.issuer, mcpServerUrl, { allowPrivateNetwork: config2.allowPrivateNetwork });
371598
+ registrationUrl = authServerMetadata.registration_endpoint;
371599
+ }
371600
+ if (registrationUrl) {
371601
+ const clientRegistration = await this.registerClient(registrationUrl, config2, redirectPort, mcpServerUrl);
371602
+ config2.clientId = clientRegistration.client_id;
371603
+ if (clientRegistration.client_secret) {
371604
+ config2.clientSecret = clientRegistration.client_secret;
371605
+ }
371606
+ debugLogger.debug("\u2713 Dynamic client registration successful");
371607
+ } else {
371608
+ throw new Error("No client ID provided and dynamic registration not supported");
371609
+ }
371610
+ }
371611
+ if (!config2.clientId || !config2.authorizationUrl || !config2.tokenUrl) {
371612
+ throw new Error("Missing required OAuth configuration after discovery and registration");
371613
+ }
371614
+ flowConfig = {
371615
+ clientId: config2.clientId,
371616
+ clientSecret: config2.clientSecret,
371617
+ authorizationUrl: config2.authorizationUrl,
371618
+ tokenUrl: config2.tokenUrl,
371619
+ scopes: config2.scopes,
371620
+ audiences: config2.audiences,
371621
+ redirectUri: config2.redirectUri
371622
+ };
371623
+ resource = this.buildResourceParam(mcpServerUrl);
371624
+ const authUrl = buildAuthorizationUrl(flowConfig, pkceParams, redirectPort, resource);
371625
+ const userConsent = await getConsentForOauth(`Authentication required for MCP Server: '${serverName}.'`);
371626
+ if (!userConsent) {
371627
+ throw new FatalCancellationError("Authentication cancelled by user.");
371628
+ }
371629
+ displayMessage(`\u2192 Opening your browser for OAuth sign-in...
371548
371630
 
371549
371631
  If the browser does not open, copy and paste this URL into your browser:
371550
371632
  ${authUrl}
371551
371633
 
371552
371634
  \u{1F4A1} TIP: Triple-click to select the entire URL, then copy and paste it into your browser.
371553
371635
  \u26A0\uFE0F Make sure to copy the COMPLETE URL - it may wrap across multiple lines.`);
371554
- try {
371555
- await openBrowserSecurely(authUrl);
371636
+ try {
371637
+ await openBrowserSecurely(authUrl);
371638
+ } catch (error40) {
371639
+ debugLogger.warn("Failed to open browser automatically:", getErrorMessage(error40));
371640
+ }
371641
+ ({ code } = await callbackServer.response);
371556
371642
  } catch (error40) {
371557
- debugLogger.warn("Failed to open browser automatically:", getErrorMessage(error40));
371643
+ callbackServer.cancel?.(error40 instanceof Error ? error40 : void 0);
371644
+ throw error40;
371558
371645
  }
371559
- const { code } = await callbackServer.response;
371560
371646
  debugLogger.debug("\u2713 Authorization code received, exchanging for tokens...");
371561
- const tokenResponse = await exchangeCodeForToken(flowConfig, code, pkceParams.codeVerifier, redirectPort, resource);
371647
+ const tokenResponse = await exchangeCodeForToken(flowConfig, code, pkceParams.codeVerifier, redirectPort, resource, { allowPrivateNetwork: config2.allowPrivateNetwork });
371562
371648
  if (!tokenResponse.access_token) {
371563
371649
  throw new Error("No access token received from token endpoint");
371564
371650
  }
@@ -371703,7 +371789,7 @@ var DynamicStoredOAuthProvider = class {
371703
371789
  if (this.isCachedTokenValid()) {
371704
371790
  return this.cachedToken;
371705
371791
  }
371706
- const oauthConfig = this.serverConfig.oauth?.enabled && this.serverConfig.oauth ? this.serverConfig.oauth : {};
371792
+ const oauthConfig = this.serverConfig.oauth ?? {};
371707
371793
  const tokenMeta = await this.oauthProvider.getValidTokenWithMetadata(this.serverName, oauthConfig);
371708
371794
  if (!tokenMeta?.accessToken) {
371709
371795
  this.cachedToken = void 0;
@@ -372230,10 +372316,13 @@ async function handleAutomaticOAuth(mcpServerName, mcpServerConfig, wwwAuthentic
372230
372316
  try {
372231
372317
  debugLogger.log(`\u{1F510} '${mcpServerName}' requires OAuth authentication`);
372232
372318
  const serverUrl = mcpServerConfig.httpUrl || mcpServerConfig.url;
372233
- let oauthConfig = await OAuthUtils.discoverOAuthFromWWWAuthenticate(wwwAuthenticate, serverUrl);
372319
+ const discoveryOptions = {
372320
+ allowPrivateNetwork: mcpServerConfig.oauth?.allowPrivateNetwork
372321
+ };
372322
+ let oauthConfig = await OAuthUtils.discoverOAuthFromWWWAuthenticate(wwwAuthenticate, serverUrl, discoveryOptions);
372234
372323
  if (!oauthConfig && hasNetworkTransport(mcpServerConfig)) {
372235
372324
  const baseUrl = OAuthUtils.extractBaseUrl(serverUrl);
372236
- oauthConfig = await OAuthUtils.discoverOAuthConfig(baseUrl);
372325
+ oauthConfig = await OAuthUtils.discoverOAuthConfig(baseUrl, discoveryOptions);
372237
372326
  }
372238
372327
  if (!oauthConfig) {
372239
372328
  cliConfig.emitMcpDiagnostic("error", `Could not configure OAuth for '${mcpServerName}' - please authenticate manually with /mcp auth ${mcpServerName}`, void 0, mcpServerName);
@@ -372245,7 +372334,8 @@ async function handleAutomaticOAuth(mcpServerName, mcpServerConfig, wwwAuthentic
372245
372334
  issuer: oauthConfig.issuer,
372246
372335
  tokenUrl: oauthConfig.tokenUrl,
372247
372336
  scopes: oauthConfig.scopes || [],
372248
- authorizationResponseIssParameterSupported: mcpServerConfig.oauth?.authorizationResponseIssParameterSupported ?? oauthConfig.authorizationResponseIssParameterSupported
372337
+ authorizationResponseIssParameterSupported: mcpServerConfig.oauth?.authorizationResponseIssParameterSupported ?? oauthConfig.authorizationResponseIssParameterSupported,
372338
+ allowPrivateNetwork: mcpServerConfig.oauth?.allowPrivateNetwork
372249
372339
  };
372250
372340
  debugLogger.log(`Starting OAuth authentication for server '${mcpServerName}'...`);
372251
372341
  const authProvider = new MCPOAuthProvider(new MCPOAuthTokenStorage());
@@ -372575,15 +372665,16 @@ async function invokeMcpPrompt(mcpServerName, mcpClient, promptName, promptParam
372575
372665
  function hasNetworkTransport(config2) {
372576
372666
  return !!(config2.url || config2.httpUrl);
372577
372667
  }
372578
- async function getStoredOAuthToken(serverName) {
372668
+ async function getStoredOAuthToken(serverName, oauthConfig) {
372579
372669
  const tokenStorage = new MCPOAuthTokenStorage();
372580
372670
  const credentials3 = await tokenStorage.getCredentials(serverName);
372581
372671
  if (!credentials3)
372582
372672
  return null;
372583
372673
  const authProvider = new MCPOAuthProvider(tokenStorage);
372584
372674
  return authProvider.getValidToken(serverName, {
372675
+ ...oauthConfig,
372585
372676
  // Pass client ID if available
372586
- clientId: credentials3.clientId
372677
+ clientId: oauthConfig?.clientId ?? credentials3.clientId
372587
372678
  });
372588
372679
  }
372589
372680
  function createSSETransportWithAuth(config2, accessToken) {
@@ -372603,8 +372694,8 @@ async function connectWithSSETransport(client, config2, accessToken) {
372603
372694
  timeout: config2.timeout ?? MCP_DEFAULT_TIMEOUT_MSEC
372604
372695
  });
372605
372696
  }
372606
- async function showAuthRequiredMessage(serverName, cliConfig) {
372607
- const hasRejectedToken = !!await getStoredOAuthToken(serverName);
372697
+ async function showAuthRequiredMessage(serverName, cliConfig, oauthConfig) {
372698
+ const hasRejectedToken = !!await getStoredOAuthToken(serverName, oauthConfig);
372608
372699
  const message = hasRejectedToken ? `MCP server '${serverName}' rejected stored OAuth token. Please re-authenticate using: /mcp auth ${serverName}` : `MCP server '${serverName}' requires authentication using: /mcp auth ${serverName}`;
372609
372700
  cliConfig.emitMcpDiagnostic("info", message, void 0, serverName);
372610
372701
  throw new UnauthorizedError(message);
@@ -372704,7 +372795,7 @@ async function connectToMcpServer(clientVersion, mcpServerName, mcpServerConfig,
372704
372795
  const logMessage = httpReturned404 ? `HTTP returned 404, trying SSE transport...` : `HTTP connection failed, attempting SSE fallback...`;
372705
372796
  debugLogger.log(`MCP server '${mcpServerName}': ${logMessage}`);
372706
372797
  try {
372707
- await connectWithSSETransport(mcpClient, mcpServerConfig, await getStoredOAuthToken(mcpServerName));
372798
+ await connectWithSSETransport(mcpClient, mcpServerConfig, await getStoredOAuthToken(mcpServerName, mcpServerConfig.oauth));
372708
372799
  debugLogger.log(`MCP server '${mcpServerName}': Successfully connected using SSE transport.`);
372709
372800
  return mcpClient;
372710
372801
  } catch (sseFallbackError) {
@@ -372722,7 +372813,7 @@ async function connectToMcpServer(clientVersion, mcpServerName, mcpServerConfig,
372722
372813
  mcpServerRequiresOAuth.set(mcpServerName, true);
372723
372814
  const shouldTriggerOAuth = mcpServerConfig.oauth?.enabled;
372724
372815
  if (!shouldTriggerOAuth) {
372725
- await showAuthRequiredMessage(mcpServerName, cliConfig);
372816
+ await showAuthRequiredMessage(mcpServerName, cliConfig, mcpServerConfig.oauth);
372726
372817
  }
372727
372818
  const errorString = String(error40);
372728
372819
  let wwwAuthenticate = extractWWWAuthenticateHeader(errorString);
@@ -372763,7 +372854,7 @@ async function connectToMcpServer(clientVersion, mcpServerName, mcpServerConfig,
372763
372854
  debugLogger.log(`Received 401 with www-authenticate header: ${wwwAuthenticate}`);
372764
372855
  const oauthSuccess = await handleAutomaticOAuth(mcpServerName, mcpServerConfig, wwwAuthenticate, cliConfig);
372765
372856
  if (oauthSuccess) {
372766
- const accessToken = await getStoredOAuthToken(mcpServerName);
372857
+ const accessToken = await getStoredOAuthToken(mcpServerName, mcpServerConfig.oauth);
372767
372858
  if (!accessToken) {
372768
372859
  throw new Error(`Failed to get OAuth token for server '${mcpServerName}'`);
372769
372860
  }
@@ -372775,13 +372866,16 @@ async function connectToMcpServer(clientVersion, mcpServerName, mcpServerConfig,
372775
372866
  } else {
372776
372867
  const shouldTryDiscovery = mcpServerConfig.oauth?.enabled;
372777
372868
  if (!shouldTryDiscovery) {
372778
- await showAuthRequiredMessage(mcpServerName, cliConfig);
372869
+ await showAuthRequiredMessage(mcpServerName, cliConfig, mcpServerConfig.oauth);
372779
372870
  }
372780
372871
  debugLogger.log(`\u{1F50D} Attempting OAuth discovery for '${mcpServerName}'...`);
372781
372872
  if (hasNetworkTransport(mcpServerConfig)) {
372782
372873
  const serverUrl = new URL(mcpServerConfig.httpUrl || mcpServerConfig.url);
372783
372874
  const baseUrl = `${serverUrl.protocol}//${serverUrl.host}`;
372784
- const oauthConfig = await OAuthUtils.discoverOAuthConfig(baseUrl);
372875
+ const discoveryOptions = {
372876
+ allowPrivateNetwork: mcpServerConfig.oauth?.allowPrivateNetwork
372877
+ };
372878
+ const oauthConfig = await OAuthUtils.discoverOAuthConfig(baseUrl, discoveryOptions);
372785
372879
  if (oauthConfig) {
372786
372880
  debugLogger.log(`Discovered OAuth configuration from base URL for server '${mcpServerName}'`);
372787
372881
  const oauthAuthConfig = {
@@ -372790,13 +372884,14 @@ async function connectToMcpServer(clientVersion, mcpServerName, mcpServerConfig,
372790
372884
  issuer: oauthConfig.issuer,
372791
372885
  tokenUrl: oauthConfig.tokenUrl,
372792
372886
  scopes: oauthConfig.scopes || [],
372793
- authorizationResponseIssParameterSupported: mcpServerConfig.oauth?.authorizationResponseIssParameterSupported ?? oauthConfig.authorizationResponseIssParameterSupported
372887
+ authorizationResponseIssParameterSupported: mcpServerConfig.oauth?.authorizationResponseIssParameterSupported ?? oauthConfig.authorizationResponseIssParameterSupported,
372888
+ allowPrivateNetwork: mcpServerConfig.oauth?.allowPrivateNetwork
372794
372889
  };
372795
372890
  const authServerUrl = mcpServerConfig.httpUrl || mcpServerConfig.url;
372796
372891
  debugLogger.log(`Starting OAuth authentication for server '${mcpServerName}'...`);
372797
372892
  const authProvider = new MCPOAuthProvider(new MCPOAuthTokenStorage());
372798
372893
  await authProvider.authenticate(mcpServerName, oauthAuthConfig, authServerUrl);
372799
- const accessToken = await getStoredOAuthToken(mcpServerName);
372894
+ const accessToken = await getStoredOAuthToken(mcpServerName, mcpServerConfig.oauth);
372800
372895
  if (!accessToken) {
372801
372896
  throw new Error(`Failed to get OAuth token for server '${mcpServerName}'`);
372802
372897
  }
@@ -400534,7 +400629,7 @@ export {
400534
400629
  SchemaValidator,
400535
400630
  jsonToMarkdown,
400536
400631
  safeJsonToMarkdown,
400537
- isRecord,
400632
+ isRecord2 as isRecord,
400538
400633
  MessageBusType,
400539
400634
  QuestionType,
400540
400635
  isBackgroundExecutionData,
@@ -401183,6 +401278,7 @@ export {
401183
401278
  sanitizeHostname,
401184
401279
  isLoopbackHost,
401185
401280
  isAddressPrivate,
401281
+ isEnterprisePrivateAddress,
401186
401282
  isPrivateIpAsync,
401187
401283
  isPrivateIp,
401188
401284
  validateUrlDestination,