@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) => {
@@ -252829,12 +252829,27 @@ function parseResponseData(error40) {
252829
252829
  }
252830
252830
  return void 0;
252831
252831
  }
252832
+ 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;
252833
+ function isRecord(value) {
252834
+ return typeof value === "object" && value !== null && !Array.isArray(value);
252835
+ }
252832
252836
  function isAuthenticationError(error40) {
252833
- if (error40 && typeof error40 === "object" && "code" in error40) {
252834
- const errorCode = error40["code"];
252835
- if (typeof errorCode === "number" && errorCode === 401) {
252837
+ const friendly = toFriendlyError(error40);
252838
+ if (friendly instanceof UnauthorizedError) {
252839
+ return true;
252840
+ }
252841
+ if (isRecord(error40)) {
252842
+ const code = error40["code"] ?? error40["status"] ?? error40["statusCode"];
252843
+ if (code === 401 || code === "401") {
252836
252844
  return true;
252837
252845
  }
252846
+ const response = error40["response"];
252847
+ if (isRecord(response)) {
252848
+ const responseCode = response["status"] ?? response["statusCode"];
252849
+ if (responseCode === 401 || responseCode === "401") {
252850
+ return true;
252851
+ }
252852
+ }
252838
252853
  }
252839
252854
  if (error40 instanceof Error && error40.name === "UnauthorizedError") {
252840
252855
  return true;
@@ -252843,7 +252858,7 @@ function isAuthenticationError(error40) {
252843
252858
  return true;
252844
252859
  }
252845
252860
  const message = getErrorMessage(error40);
252846
- if (message.includes("401")) {
252861
+ if (HTTP_401_REGEX.test(message)) {
252847
252862
  return true;
252848
252863
  }
252849
252864
  return false;
@@ -274170,14 +274185,14 @@ function safeJsonToMarkdown(text) {
274170
274185
  return text;
274171
274186
  }
274172
274187
  }
274173
- function isRecord(value) {
274188
+ function isRecord2(value) {
274174
274189
  return typeof value === "object" && value !== null && !Array.isArray(value);
274175
274190
  }
274176
274191
  function isArrayOfSimilarObjects(data) {
274177
274192
  if (data.length === 0) {
274178
274193
  return false;
274179
274194
  }
274180
- if (!data.every(isRecord)) return false;
274195
+ if (!data.every(isRecord2)) return false;
274181
274196
  const firstKeys = Object.keys(data[0]).sort().join(",");
274182
274197
  return data.every((item) => Object.keys(item).sort().join(",") === firstKeys);
274183
274198
  }
@@ -274548,7 +274563,7 @@ var DeclarativeTool = class {
274548
274563
  * Type guard to check if an unknown value represents a ToolParameterSchema object.
274549
274564
  */
274550
274565
  isParameterSchema(obj) {
274551
- return isRecord(obj) && "type" in obj;
274566
+ return isRecord2(obj) && "type" in obj;
274552
274567
  }
274553
274568
  /**
274554
274569
  * Adds the `wait_for_previous` parameter to the tool's schema.
@@ -274561,7 +274576,7 @@ var DeclarativeTool = class {
274561
274576
  const props = schema2.properties;
274562
274577
  let propertiesObj = {};
274563
274578
  if (props !== void 0) {
274564
- if (!isRecord(props)) {
274579
+ if (!isRecord2(props)) {
274565
274580
  return schema2;
274566
274581
  }
274567
274582
  propertiesObj = props;
@@ -279070,7 +279085,7 @@ var KeychainService = class {
279070
279085
  async loadKeychainModule() {
279071
279086
  const moduleName = "@github/keytar";
279072
279087
  const module2 = await import(moduleName);
279073
- const potential = isRecord(module2) && module2["default"] || module2;
279088
+ const potential = isRecord2(module2) && module2["default"] || module2;
279074
279089
  const result2 = KeychainSchema.safeParse(potential);
279075
279090
  if (result2.success) {
279076
279091
  return potential;
@@ -284008,7 +284023,7 @@ function isValidToolName(name3, options = {}) {
284008
284023
  }
284009
284024
 
284010
284025
  // packages/core/src/generated/git-commit.ts
284011
- var GIT_COMMIT_INFO = "ed96faedf";
284026
+ var GIT_COMMIT_INFO = "b041de017";
284012
284027
  var CLI_VERSION = "0.66.0-nightly.20261013.g204db94ae";
284013
284028
 
284014
284029
  // packages/core/src/ide/detect-ide.ts
@@ -310412,8 +310427,8 @@ var BaseLlmClient = class {
310412
310427
  const parsed = JSON.parse(
310413
310428
  this.cleanJsonResponse(getResponseText(result2).trim(), model)
310414
310429
  );
310415
- const isRecord3 = (val) => typeof val === "object" && val !== null && !Array.isArray(val);
310416
- if (isRecord3(parsed)) {
310430
+ const isRecord4 = (val) => typeof val === "object" && val !== null && !Array.isArray(val);
310431
+ if (isRecord4(parsed)) {
310417
310432
  return parsed;
310418
310433
  }
310419
310434
  throw new Error("Invalid JSON response format from LLM");
@@ -316488,7 +316503,7 @@ function getSafeGitEnv(baseEnv = process.env) {
316488
316503
  GIT_SSH_COMMAND: gitSshCommand,
316489
316504
  GH_PROMPT_DISABLED: "1",
316490
316505
  GCM_INTERACTIVE: "never",
316491
- GIT_CONFIG_GLOBAL: devNullPath,
316506
+ ...baseEnv["GIT_CONFIG_GLOBAL"] ? { GIT_CONFIG_GLOBAL: baseEnv["GIT_CONFIG_GLOBAL"] } : {},
316492
316507
  GIT_CONFIG_SYSTEM: devNullPath,
316493
316508
  GIT_CONFIG_NOSYSTEM: "1",
316494
316509
  GIT_CONFIG_COUNT: "7",
@@ -327149,14 +327164,15 @@ ${truncated}`;
327149
327164
  for (const key of gitConfigKeys) {
327150
327165
  baseEnv[key] = sourceEnv[key];
327151
327166
  }
327167
+ if (!baseEnv["GIT_CONFIG_GLOBAL"]) {
327168
+ delete baseEnv["GIT_CONFIG_GLOBAL"];
327169
+ }
327152
327170
  let gitConfigCount = parseInt(baseEnv["GIT_CONFIG_COUNT"] || "0", 10);
327153
327171
  const devNullPath = os31.platform() === "win32" ? "NUL" : "/dev/null";
327154
- baseEnv["GIT_CONFIG_GLOBAL"] = devNullPath;
327155
327172
  baseEnv["GIT_CONFIG_SYSTEM"] = devNullPath;
327156
327173
  baseEnv["GIT_CONFIG_NOSYSTEM"] = "1";
327157
327174
  sanitizationConfig.allowedEnvironmentVariables.push(
327158
327175
  "GIT_CONFIG_COUNT",
327159
- "GIT_CONFIG_GLOBAL",
327160
327176
  "GIT_CONFIG_SYSTEM",
327161
327177
  "GIT_CONFIG_NOSYSTEM"
327162
327178
  );
@@ -329568,6 +329584,31 @@ function isAddressPrivate(address) {
329568
329584
  return true;
329569
329585
  }
329570
329586
  }
329587
+ function isEnterprisePrivateAddress(addressOrHost) {
329588
+ const normalized2 = sanitizeHostname(addressOrHost).toLowerCase();
329589
+ if (normalized2.endsWith(".internal") || normalized2.endsWith(".local")) {
329590
+ return true;
329591
+ }
329592
+ if (normalized2 === "localhost" || normalized2.endsWith(".localhost")) {
329593
+ return false;
329594
+ }
329595
+ try {
329596
+ if (!import_ipaddr.default.isValid(normalized2)) {
329597
+ return false;
329598
+ }
329599
+ let addr2 = import_ipaddr.default.parse(normalized2);
329600
+ if (addr2 instanceof import_ipaddr.default.IPv6 && addr2.isIPv4MappedAddress()) {
329601
+ addr2 = addr2.toIPv4Address();
329602
+ }
329603
+ if (isBenchmarkAddress(addr2)) {
329604
+ return false;
329605
+ }
329606
+ const range2 = addr2.range();
329607
+ return range2 === "private" || range2 === "carrierGradeNat" || range2 === "uniqueLocal";
329608
+ } catch {
329609
+ return false;
329610
+ }
329611
+ }
329571
329612
  async function isPrivateIpAsync(url3) {
329572
329613
  let parsedUrl;
329573
329614
  try {
@@ -344872,6 +344913,7 @@ var import_google_auth_library5 = __toESM(require_src10(), 1);
344872
344913
 
344873
344914
  // packages/core/src/mcp/oauth-utils.ts
344874
344915
  import { lookup as lookup2 } from "node:dns/promises";
344916
+ import { isIP as isIP2 } from "node:net";
344875
344917
  var ResourceMismatchError = class extends Error {
344876
344918
  constructor(message) {
344877
344919
  super(message);
@@ -344892,6 +344934,7 @@ function isLoopbackUrl(urlStr) {
344892
344934
  return false;
344893
344935
  }
344894
344936
  }
344937
+ var PRIVATE_NETWORK_REMEDIATION_HINT = 'Set "oauth.allowPrivateNetwork": true in settings.json for this MCP server if it is on a trusted private network.';
344895
344938
  async function validateOAuthEndpointUrl(urlStr, options) {
344896
344939
  let resolvedUrl = urlStr.trim();
344897
344940
  if (options?.allowRelative && options.baseUri) {
@@ -344949,9 +344992,16 @@ async function validateOAuthEndpointUrl(urlStr, options) {
344949
344992
  return parsed.toString();
344950
344993
  }
344951
344994
  if (isAddressPrivate(hostname3)) {
344952
- throw new OAuthSecurityError(
344953
- `OAuth endpoint "${resolvedUrl}" points to private or reserved IP address which is blocked.`
344954
- );
344995
+ const isEnterprisePrivate = isEnterprisePrivateAddress(hostname3);
344996
+ if (!options?.allowPrivateNetwork || !isEnterprisePrivate) {
344997
+ const hint = isEnterprisePrivate ? ` ${PRIVATE_NETWORK_REMEDIATION_HINT}` : "";
344998
+ throw new OAuthSecurityError(
344999
+ `OAuth endpoint "${resolvedUrl}" points to private or reserved IP address which is blocked.${hint}`
345000
+ );
345001
+ }
345002
+ if (isIP2(hostname3) !== 0) {
345003
+ return parsed.toString();
345004
+ }
344955
345005
  }
344956
345006
  try {
344957
345007
  const addresses = await lookup2(hostname3, { all: true });
@@ -344962,9 +345012,13 @@ async function validateOAuthEndpointUrl(urlStr, options) {
344962
345012
  }
344963
345013
  for (const addr2 of addresses) {
344964
345014
  if (isAddressPrivate(addr2.address)) {
344965
- throw new OAuthSecurityError(
344966
- `OAuth endpoint "${resolvedUrl}" resolves to private network address "${addr2.address}" which is blocked.`
344967
- );
345015
+ const isEnterprisePrivate = isEnterprisePrivateAddress(addr2.address);
345016
+ if (!options?.allowPrivateNetwork || !isEnterprisePrivate) {
345017
+ const hint = isEnterprisePrivate ? ` ${PRIVATE_NETWORK_REMEDIATION_HINT}` : "";
345018
+ throw new OAuthSecurityError(
345019
+ `OAuth endpoint "${resolvedUrl}" resolves to private network address "${addr2.address}" which is blocked.${hint}`
345020
+ );
345021
+ }
344968
345022
  }
344969
345023
  }
344970
345024
  } catch (error40) {
@@ -345019,7 +345073,8 @@ var OAuthUtils = class {
345019
345073
  try {
345020
345074
  const validatedUrl = await validateOAuthEndpointUrl(resourceMetadataUrl, {
345021
345075
  allowLoopback: options?.allowLoopback,
345022
- expectedOrigin: options?.expectedOrigin
345076
+ expectedOrigin: options?.expectedOrigin,
345077
+ allowPrivateNetwork: options?.allowPrivateNetwork
345023
345078
  });
345024
345079
  const response = await fetch(validatedUrl);
345025
345080
  if (!response.ok) {
@@ -345048,7 +345103,8 @@ var OAuthUtils = class {
345048
345103
  const validatedUrl = await validateOAuthEndpointUrl(
345049
345104
  authServerMetadataUrl,
345050
345105
  {
345051
- allowLoopback: options?.allowLoopback
345106
+ allowLoopback: options?.allowLoopback,
345107
+ allowPrivateNetwork: options?.allowPrivateNetwork
345052
345108
  }
345053
345109
  );
345054
345110
  const response = await fetch(validatedUrl);
@@ -345097,7 +345153,8 @@ var OAuthUtils = class {
345097
345153
  */
345098
345154
  static async discoverAuthorizationServerMetadata(authServerUrl, options) {
345099
345155
  const validatedBaseUrl = await validateOAuthEndpointUrl(authServerUrl, {
345100
- allowLoopback: options?.allowLoopback
345156
+ allowLoopback: options?.allowLoopback,
345157
+ allowPrivateNetwork: options?.allowPrivateNetwork
345101
345158
  });
345102
345159
  const authServerUrlObj = new URL(validatedBaseUrl);
345103
345160
  const base = `${authServerUrlObj.protocol}//${authServerUrlObj.host}`;
@@ -345148,14 +345205,15 @@ var OAuthUtils = class {
345148
345205
  * @param serverUrl The base URL of the server
345149
345206
  * @returns The discovered OAuth configuration or null if not available
345150
345207
  */
345151
- static async discoverOAuthConfig(serverUrl) {
345208
+ static async discoverOAuthConfig(serverUrl, options) {
345152
345209
  try {
345153
345210
  const allowLoopback = isLoopbackUrl(serverUrl);
345211
+ const allowPrivateNetwork = options?.allowPrivateNetwork;
345154
345212
  const expectedOrigin = new URL(serverUrl).origin;
345155
345213
  const wellKnownUrls = this.buildWellKnownUrls(serverUrl);
345156
345214
  let resourceMetadata = await this.fetchProtectedResourceMetadata(
345157
345215
  wellKnownUrls.protectedResource,
345158
- { allowLoopback, expectedOrigin }
345216
+ { allowLoopback, expectedOrigin, allowPrivateNetwork }
345159
345217
  );
345160
345218
  if (!resourceMetadata) {
345161
345219
  const url3 = new URL(serverUrl);
@@ -345163,7 +345221,7 @@ var OAuthUtils = class {
345163
345221
  const rootBasedUrls = this.buildWellKnownUrls(serverUrl, true);
345164
345222
  resourceMetadata = await this.fetchProtectedResourceMetadata(
345165
345223
  rootBasedUrls.protectedResource,
345166
- { allowLoopback, expectedOrigin }
345224
+ { allowLoopback, expectedOrigin, allowPrivateNetwork }
345167
345225
  );
345168
345226
  }
345169
345227
  }
@@ -345178,11 +345236,16 @@ var OAuthUtils = class {
345178
345236
  );
345179
345237
  }
345180
345238
  }
345239
+ const authServerDiscoveryOptions = {
345240
+ allowLoopback,
345241
+ ...allowPrivateNetwork !== void 0 ? { allowPrivateNetwork } : {}
345242
+ };
345181
345243
  if (resourceMetadata?.authorization_servers?.length) {
345182
345244
  const authServerUrl = resourceMetadata.authorization_servers[0];
345183
- const authServerMetadata2 = await this.discoverAuthorizationServerMetadata(authServerUrl, {
345184
- allowLoopback
345185
- });
345245
+ const authServerMetadata2 = await this.discoverAuthorizationServerMetadata(
345246
+ authServerUrl,
345247
+ authServerDiscoveryOptions
345248
+ );
345186
345249
  if (authServerMetadata2) {
345187
345250
  const config2 = this.metadataToOAuthConfig(authServerMetadata2);
345188
345251
  if (authServerMetadata2.registration_endpoint) {
@@ -345197,9 +345260,7 @@ var OAuthUtils = class {
345197
345260
  debugLogger.debug(`Trying OAuth discovery fallback at ${serverUrl}`);
345198
345261
  const authServerMetadata = await this.discoverAuthorizationServerMetadata(
345199
345262
  serverUrl,
345200
- {
345201
- allowLoopback
345202
- }
345263
+ authServerDiscoveryOptions
345203
345264
  );
345204
345265
  if (authServerMetadata) {
345205
345266
  const config2 = this.metadataToOAuthConfig(authServerMetadata);
@@ -345242,12 +345303,13 @@ var OAuthUtils = class {
345242
345303
  * @param mcpServerUrl Optional MCP server URL to validate against the resource metadata
345243
345304
  * @returns The discovered OAuth configuration or null if not available
345244
345305
  */
345245
- static async discoverOAuthFromWWWAuthenticate(wwwAuthenticate, mcpServerUrl) {
345306
+ static async discoverOAuthFromWWWAuthenticate(wwwAuthenticate, mcpServerUrl, options) {
345246
345307
  const resourceMetadataUri = this.parseWWWAuthenticateHeader(wwwAuthenticate);
345247
345308
  if (!resourceMetadataUri) {
345248
345309
  return null;
345249
345310
  }
345250
345311
  const allowLoopback = mcpServerUrl ? isLoopbackUrl(mcpServerUrl) : false;
345312
+ const allowPrivateNetwork = options?.allowPrivateNetwork;
345251
345313
  const expectedOrigin = mcpServerUrl ? new URL(mcpServerUrl).origin : void 0;
345252
345314
  const validatedResourceMetadataUrl = await validateOAuthEndpointUrl(
345253
345315
  resourceMetadataUri,
@@ -345255,14 +345317,16 @@ var OAuthUtils = class {
345255
345317
  allowLoopback,
345256
345318
  expectedOrigin,
345257
345319
  allowRelative: true,
345258
- baseUri: mcpServerUrl
345320
+ baseUri: mcpServerUrl,
345321
+ allowPrivateNetwork
345259
345322
  }
345260
345323
  );
345261
345324
  const resourceMetadata = await this.fetchProtectedResourceMetadata(
345262
345325
  validatedResourceMetadataUrl,
345263
345326
  {
345264
345327
  allowLoopback,
345265
- expectedOrigin
345328
+ expectedOrigin,
345329
+ allowPrivateNetwork
345266
345330
  }
345267
345331
  );
345268
345332
  if (resourceMetadata && mcpServerUrl) {
@@ -345283,7 +345347,8 @@ var OAuthUtils = class {
345283
345347
  const authServerMetadata = await this.discoverAuthorizationServerMetadata(
345284
345348
  authServerUrl,
345285
345349
  {
345286
- allowLoopback
345350
+ allowLoopback,
345351
+ ...allowPrivateNetwork !== void 0 ? { allowPrivateNetwork } : {}
345287
345352
  }
345288
345353
  );
345289
345354
  if (authServerMetadata) {
@@ -345485,7 +345550,7 @@ var A2AAuthProviderFactory = class _A2AAuthProviderFactory {
345485
345550
  return provider;
345486
345551
  }
345487
345552
  case "oauth2": {
345488
- const { OAuth2AuthProvider } = await import("./oauth2-provider-RMF7U2UN.js");
345553
+ const { OAuth2AuthProvider } = await import("./oauth2-provider-LVJMV7QY.js");
345489
345554
  const provider = new OAuth2AuthProvider(
345490
345555
  authConfig,
345491
345556
  options.agentName ?? "unknown",
@@ -349444,7 +349509,7 @@ function isNumberArray(value) {
349444
349509
  }
349445
349510
  function isTaskArray(value) {
349446
349511
  return Array.isArray(value) && value.every((item) => {
349447
- if (!isRecord(item)) return false;
349512
+ if (!isRecord2(item)) return false;
349448
349513
  const id = item["id"];
349449
349514
  const desc = item["description"];
349450
349515
  return typeof id === "string" && typeof desc === "string";
@@ -349460,7 +349525,7 @@ function isSnapshotState(text) {
349460
349525
  }
349461
349526
  try {
349462
349527
  const parsed = JSON.parse(trimmed2);
349463
- if (!isRecord(parsed)) return false;
349528
+ if (!isRecord2(parsed)) return false;
349464
349529
  const isSnap = Array.isArray(parsed["active_tasks"]) && Array.isArray(parsed["discovered_facts"]) && Array.isArray(parsed["constraints_and_preferences"]) && Array.isArray(parsed["recent_arc"]);
349465
349530
  if (!isSnap) {
349466
349531
  debugLogger.log(
@@ -349509,7 +349574,7 @@ var SnapshotGenerator = class {
349509
349574
  if (previousStateJson) {
349510
349575
  try {
349511
349576
  const parsed = JSON.parse(previousStateJson);
349512
- if (isRecord(parsed)) {
349577
+ if (isRecord2(parsed)) {
349513
349578
  let loadedArc = [];
349514
349579
  if (isStringArray(parsed["recent_arc"])) {
349515
349580
  loadedArc = parsed["recent_arc"];
@@ -349608,7 +349673,7 @@ ${formatNodesForLlm(nodes)}`;
349608
349673
  promptId: this.env.promptId,
349609
349674
  abortSignal: new AbortController().signal
349610
349675
  });
349611
- if (isRecord(result2)) {
349676
+ if (isRecord2(result2)) {
349612
349677
  patch = result2;
349613
349678
  }
349614
349679
  } catch {
@@ -349644,7 +349709,7 @@ ${formatNodesForLlm(nodes)}`;
349644
349709
  const newTasks = patch["new_tasks"];
349645
349710
  if (Array.isArray(newTasks)) {
349646
349711
  for (const t2 of newTasks) {
349647
- if (isRecord(t2)) {
349712
+ if (isRecord2(t2)) {
349648
349713
  const desc = t2["description"];
349649
349714
  if (typeof desc === "string" && desc) {
349650
349715
  newState.active_tasks.push({
@@ -360311,11 +360376,11 @@ var AgentTool = class extends BaseDeclarativeTool {
360311
360376
  }
360312
360377
  mapParams(prompt, schema2) {
360313
360378
  const schemaObj = schema2;
360314
- if (!isRecord(schemaObj)) {
360379
+ if (!isRecord2(schemaObj)) {
360315
360380
  return { prompt };
360316
360381
  }
360317
360382
  const properties = schemaObj["properties"];
360318
- if (isRecord(properties)) {
360383
+ if (isRecord2(properties)) {
360319
360384
  const keys = Object.keys(properties);
360320
360385
  if (keys.length === 1) {
360321
360386
  return { [keys[0]]: prompt };
@@ -360432,11 +360497,11 @@ var DelegateInvocation = class extends BaseToolInvocation {
360432
360497
  return agentArgs;
360433
360498
  }
360434
360499
  const schemaObj = this.definition.inputConfig.inputSchema;
360435
- if (!isRecord(schemaObj)) {
360500
+ if (!isRecord2(schemaObj)) {
360436
360501
  return agentArgs;
360437
360502
  }
360438
360503
  const properties = schemaObj["properties"];
360439
- if (isRecord(properties)) {
360504
+ if (isRecord2(properties)) {
360440
360505
  const keys = Object.keys(properties);
360441
360506
  const primaryKey = keys.length === 1 ? keys[0] : "prompt";
360442
360507
  const value = agentArgs[primaryKey];
@@ -360993,8 +361058,8 @@ ${reminder}`;
360993
361058
  );
360994
361059
  }
360995
361060
  const parsed = JSON.parse(result2.text);
360996
- const isRecord3 = (val) => typeof val === "object" && val !== null && !Array.isArray(val);
360997
- if (isRecord3(parsed)) {
361061
+ const isRecord4 = (val) => typeof val === "object" && val !== null && !Array.isArray(val);
361062
+ if (isRecord4(parsed)) {
360998
361063
  return parsed;
360999
361064
  }
361000
361065
  throw new Error("Invalid JSON response format from Local LLM");
@@ -365998,7 +366063,7 @@ var realPathCache = /* @__PURE__ */ new Map();
365998
366063
  function parseTrustedFoldersJson(content) {
365999
366064
  return JSON.parse((0, import_strip_json_comments.default)(content));
366000
366065
  }
366001
- function isRecord2(value) {
366066
+ function isRecord3(value) {
366002
366067
  return typeof value === "object" && value !== null && !Array.isArray(value);
366003
366068
  }
366004
366069
  function clearRealPathCacheForTesting() {
@@ -366092,7 +366157,7 @@ Please fix the file manually before trying to update it.`
366092
366157
  const config2 = {};
366093
366158
  try {
366094
366159
  const parsed = parseTrustedFoldersJson(content);
366095
- if (isRecord2(parsed)) {
366160
+ if (isRecord3(parsed)) {
366096
366161
  for (const [rawPath, value] of Object.entries(parsed)) {
366097
366162
  if (isTrustLevel(value)) {
366098
366163
  config2[rawPath] = value;
@@ -366139,7 +366204,7 @@ function loadTrustedFolders() {
366139
366204
  if (fs67.existsSync(userPath)) {
366140
366205
  const content = fs67.readFileSync(userPath, "utf-8");
366141
366206
  const parsed = parseTrustedFoldersJson(content);
366142
- if (!isRecord2(parsed)) {
366207
+ if (!isRecord3(parsed)) {
366143
366208
  errors.push({
366144
366209
  message: "Trusted folders file is not a valid JSON object.",
366145
366210
  path: userPath
@@ -370245,7 +370310,7 @@ var PolicyEngine = class {
370245
370310
  let decision;
370246
370311
  const toolNamesToTry = toolCall.name ? getToolAliases(toolCall.name) : [];
370247
370312
  if (toolCall.name === AGENT_TOOL_NAME) {
370248
- if (isRecord(toolCall.args)) {
370313
+ if (isRecord2(toolCall.args)) {
370249
370314
  const subagentName = toolCall.args["agent_name"];
370250
370315
  if (typeof subagentName === "string") {
370251
370316
  toolNamesToTry.push(subagentName);
@@ -376861,7 +376926,7 @@ async function parseTokenEndpointResponse(response, operationName, defaultErrorC
376861
376926
  scope: scope || void 0
376862
376927
  };
376863
376928
  }
376864
- async function exchangeCodeForToken(config2, code, codeVerifier, redirectPort, resource) {
376929
+ async function exchangeCodeForToken(config2, code, codeVerifier, redirectPort, resource, options) {
376865
376930
  const redirectUri = getRedirectUri(config2, redirectPort);
376866
376931
  const params = new URLSearchParams({
376867
376932
  grant_type: "authorization_code",
@@ -376881,7 +376946,8 @@ async function exchangeCodeForToken(config2, code, codeVerifier, redirectPort, r
376881
376946
  }
376882
376947
  const allowLoopback = resource ? isLoopbackUrl(resource) : isLoopbackUrl(config2.tokenUrl);
376883
376948
  const validatedTokenUrl = await validateOAuthEndpointUrl(config2.tokenUrl, {
376884
- allowLoopback
376949
+ allowLoopback,
376950
+ allowPrivateNetwork: options?.allowPrivateNetwork
376885
376951
  });
376886
376952
  const response = await fetch(validatedTokenUrl, {
376887
376953
  method: "POST",
@@ -376897,7 +376963,7 @@ async function exchangeCodeForToken(config2, code, codeVerifier, redirectPort, r
376897
376963
  "no_access_token"
376898
376964
  );
376899
376965
  }
376900
- async function refreshAccessToken(config2, refreshToken, tokenUrl, resource) {
376966
+ async function refreshAccessToken(config2, refreshToken, tokenUrl, resource, options) {
376901
376967
  const params = new URLSearchParams({
376902
376968
  grant_type: "refresh_token",
376903
376969
  refresh_token: refreshToken,
@@ -376917,7 +376983,8 @@ async function refreshAccessToken(config2, refreshToken, tokenUrl, resource) {
376917
376983
  }
376918
376984
  const allowLoopback = resource ? isLoopbackUrl(resource) : isLoopbackUrl(tokenUrl);
376919
376985
  const validatedTokenUrl = await validateOAuthEndpointUrl(tokenUrl, {
376920
- allowLoopback
376986
+ allowLoopback,
376987
+ allowPrivateNetwork: options?.allowPrivateNetwork
376921
376988
  });
376922
376989
  const response = await fetch(validatedTokenUrl, {
376923
376990
  method: "POST",
@@ -376949,7 +377016,8 @@ var MCPOAuthProvider = class {
376949
377016
  const validatedRegistrationUrl = await validateOAuthEndpointUrl(
376950
377017
  registrationUrl,
376951
377018
  {
376952
- allowLoopback
377019
+ allowLoopback,
377020
+ allowPrivateNetwork: config2.allowPrivateNetwork
376953
377021
  }
376954
377022
  );
376955
377023
  const redirectUri = getRedirectUri(config2, redirectPort);
@@ -376983,10 +377051,10 @@ var MCPOAuthProvider = class {
376983
377051
  * @param mcpServerUrl The MCP server URL
376984
377052
  * @returns OAuth configuration if discovered, null otherwise
376985
377053
  */
376986
- async discoverOAuthFromMCPServer(mcpServerUrl) {
376987
- return OAuthUtils.discoverOAuthConfig(mcpServerUrl);
377054
+ async discoverOAuthFromMCPServer(mcpServerUrl, options) {
377055
+ return OAuthUtils.discoverOAuthConfig(mcpServerUrl, options);
376988
377056
  }
376989
- async discoverAuthServerMetadataForRegistration(issuer, mcpServerUrl) {
377057
+ async discoverAuthServerMetadataForRegistration(issuer, mcpServerUrl, options) {
376990
377058
  const allowLoopback = mcpServerUrl ? isLoopbackUrl(mcpServerUrl) : isLoopbackUrl(issuer);
376991
377059
  const authUrl = new URL7(issuer);
376992
377060
  const oidcPatterns = [
@@ -377026,7 +377094,10 @@ var MCPOAuthProvider = class {
377026
377094
  debugLogger.debug(` Trying issuer URL: ${issuerCandidate}`);
377027
377095
  const metadata2 = await OAuthUtils.discoverAuthorizationServerMetadata(
377028
377096
  issuerCandidate,
377029
- { allowLoopback }
377097
+ {
377098
+ allowLoopback,
377099
+ ...options?.allowPrivateNetwork !== void 0 ? { allowPrivateNetwork: options.allowPrivateNetwork } : {}
377100
+ }
377030
377101
  );
377031
377102
  if (metadata2) {
377032
377103
  selectedIssuer = issuerCandidate;
@@ -377082,7 +377153,8 @@ var MCPOAuthProvider = class {
377082
377153
  },
377083
377154
  refreshToken,
377084
377155
  tokenUrl,
377085
- this.buildResourceParam(mcpServerUrl)
377156
+ this.buildResourceParam(mcpServerUrl),
377157
+ { allowPrivateNetwork: config2.allowPrivateNetwork }
377086
377158
  );
377087
377159
  }
377088
377160
  /**
@@ -377112,7 +377184,8 @@ var MCPOAuthProvider = class {
377112
377184
  if (wwwAuthenticate) {
377113
377185
  const discoveredConfig = await OAuthUtils.discoverOAuthFromWWWAuthenticate(
377114
377186
  wwwAuthenticate,
377115
- mcpServerUrl
377187
+ mcpServerUrl,
377188
+ { allowPrivateNetwork: config2.allowPrivateNetwork }
377116
377189
  );
377117
377190
  if (discoveredConfig) {
377118
377191
  config2 = {
@@ -377138,7 +377211,10 @@ var MCPOAuthProvider = class {
377138
377211
  );
377139
377212
  }
377140
377213
  if (!config2.authorizationUrl) {
377141
- const discoveredConfig = await this.discoverOAuthFromMCPServer(mcpServerUrl);
377214
+ const discoveredConfig = await this.discoverOAuthFromMCPServer(
377215
+ mcpServerUrl,
377216
+ { allowPrivateNetwork: config2.allowPrivateNetwork }
377217
+ );
377142
377218
  if (discoveredConfig) {
377143
377219
  config2 = {
377144
377220
  ...config2,
@@ -377159,6 +377235,19 @@ var MCPOAuthProvider = class {
377159
377235
  }
377160
377236
  }
377161
377237
  }
377238
+ const allowLoopback = mcpServerUrl ? isLoopbackUrl(mcpServerUrl) : (config2.authorizationUrl ? isLoopbackUrl(config2.authorizationUrl) : false) || (config2.tokenUrl ? isLoopbackUrl(config2.tokenUrl) : false);
377239
+ if (config2.authorizationUrl) {
377240
+ await validateOAuthEndpointUrl(config2.authorizationUrl, {
377241
+ allowLoopback,
377242
+ allowPrivateNetwork: config2.allowPrivateNetwork
377243
+ });
377244
+ }
377245
+ if (config2.tokenUrl) {
377246
+ await validateOAuthEndpointUrl(config2.tokenUrl, {
377247
+ allowLoopback,
377248
+ allowPrivateNetwork: config2.allowPrivateNetwork
377249
+ });
377250
+ }
377162
377251
  const pkceParams = generatePKCEParams();
377163
377252
  const preferredPort = getPortFromUrl(config2.redirectUri);
377164
377253
  debugLogger.debug(
@@ -377171,89 +377260,96 @@ var MCPOAuthProvider = class {
377171
377260
  config2.issuer,
377172
377261
  requireIssInResponse
377173
377262
  );
377174
- const redirectPort = await callbackServer.port;
377175
- debugLogger.debug(`Callback server listening on port ${redirectPort}`);
377176
- if (!config2.clientId) {
377177
- let registrationUrl = config2.registrationUrl;
377178
- if (!registrationUrl) {
377179
- if (!config2.issuer) {
377180
- throw new Error("Cannot perform dynamic registration without issuer");
377181
- }
377182
- debugLogger.debug("\u2192 Attempting dynamic client registration...");
377183
- const { metadata: authServerMetadata } = await this.discoverAuthServerMetadataForRegistration(
377184
- config2.issuer,
377185
- mcpServerUrl
377186
- );
377187
- registrationUrl = authServerMetadata.registration_endpoint;
377188
- }
377189
- if (registrationUrl) {
377190
- const clientRegistration = await this.registerClient(
377191
- registrationUrl,
377192
- config2,
377193
- redirectPort,
377194
- mcpServerUrl
377195
- );
377196
- config2.clientId = clientRegistration.client_id;
377197
- if (clientRegistration.client_secret) {
377198
- config2.clientSecret = clientRegistration.client_secret;
377263
+ callbackServer.response.catch(() => {
377264
+ });
377265
+ let code;
377266
+ let redirectPort;
377267
+ let flowConfig;
377268
+ let resource;
377269
+ try {
377270
+ redirectPort = await callbackServer.port;
377271
+ debugLogger.debug(`Callback server listening on port ${redirectPort}`);
377272
+ if (!config2.clientId) {
377273
+ let registrationUrl = config2.registrationUrl;
377274
+ if (!registrationUrl) {
377275
+ if (!config2.issuer) {
377276
+ throw new Error(
377277
+ "Cannot perform dynamic registration without issuer"
377278
+ );
377279
+ }
377280
+ debugLogger.debug("\u2192 Attempting dynamic client registration...");
377281
+ const { metadata: authServerMetadata } = await this.discoverAuthServerMetadataForRegistration(
377282
+ config2.issuer,
377283
+ mcpServerUrl,
377284
+ { allowPrivateNetwork: config2.allowPrivateNetwork }
377285
+ );
377286
+ registrationUrl = authServerMetadata.registration_endpoint;
377287
+ }
377288
+ if (registrationUrl) {
377289
+ const clientRegistration = await this.registerClient(
377290
+ registrationUrl,
377291
+ config2,
377292
+ redirectPort,
377293
+ mcpServerUrl
377294
+ );
377295
+ config2.clientId = clientRegistration.client_id;
377296
+ if (clientRegistration.client_secret) {
377297
+ config2.clientSecret = clientRegistration.client_secret;
377298
+ }
377299
+ debugLogger.debug("\u2713 Dynamic client registration successful");
377300
+ } else {
377301
+ throw new Error(
377302
+ "No client ID provided and dynamic registration not supported"
377303
+ );
377199
377304
  }
377200
- debugLogger.debug("\u2713 Dynamic client registration successful");
377201
- } else {
377305
+ }
377306
+ if (!config2.clientId || !config2.authorizationUrl || !config2.tokenUrl) {
377202
377307
  throw new Error(
377203
- "No client ID provided and dynamic registration not supported"
377308
+ "Missing required OAuth configuration after discovery and registration"
377204
377309
  );
377205
377310
  }
377206
- }
377207
- if (!config2.clientId || !config2.authorizationUrl || !config2.tokenUrl) {
377208
- throw new Error(
377209
- "Missing required OAuth configuration after discovery and registration"
377311
+ flowConfig = {
377312
+ clientId: config2.clientId,
377313
+ clientSecret: config2.clientSecret,
377314
+ authorizationUrl: config2.authorizationUrl,
377315
+ tokenUrl: config2.tokenUrl,
377316
+ scopes: config2.scopes,
377317
+ audiences: config2.audiences,
377318
+ redirectUri: config2.redirectUri
377319
+ };
377320
+ resource = this.buildResourceParam(mcpServerUrl);
377321
+ const authUrl = buildAuthorizationUrl(
377322
+ flowConfig,
377323
+ pkceParams,
377324
+ redirectPort,
377325
+ resource
377210
377326
  );
377211
- }
377212
- const allowLoopback = mcpServerUrl ? isLoopbackUrl(mcpServerUrl) : (config2.authorizationUrl ? isLoopbackUrl(config2.authorizationUrl) : false) || (config2.tokenUrl ? isLoopbackUrl(config2.tokenUrl) : false);
377213
- await validateOAuthEndpointUrl(config2.authorizationUrl, {
377214
- allowLoopback
377215
- });
377216
- await validateOAuthEndpointUrl(config2.tokenUrl, {
377217
- allowLoopback
377218
- });
377219
- const flowConfig = {
377220
- clientId: config2.clientId,
377221
- clientSecret: config2.clientSecret,
377222
- authorizationUrl: config2.authorizationUrl,
377223
- tokenUrl: config2.tokenUrl,
377224
- scopes: config2.scopes,
377225
- audiences: config2.audiences,
377226
- redirectUri: config2.redirectUri
377227
- };
377228
- const resource = this.buildResourceParam(mcpServerUrl);
377229
- const authUrl = buildAuthorizationUrl(
377230
- flowConfig,
377231
- pkceParams,
377232
- redirectPort,
377233
- resource
377234
- );
377235
- const userConsent = await getConsentForOauth(
377236
- `Authentication required for MCP Server: '${serverName}.'`
377237
- );
377238
- if (!userConsent) {
377239
- throw new FatalCancellationError("Authentication cancelled by user.");
377240
- }
377241
- displayMessage(`\u2192 Opening your browser for OAuth sign-in...
377327
+ const userConsent = await getConsentForOauth(
377328
+ `Authentication required for MCP Server: '${serverName}.'`
377329
+ );
377330
+ if (!userConsent) {
377331
+ throw new FatalCancellationError("Authentication cancelled by user.");
377332
+ }
377333
+ displayMessage(`\u2192 Opening your browser for OAuth sign-in...
377242
377334
 
377243
377335
  If the browser does not open, copy and paste this URL into your browser:
377244
377336
  ${authUrl}
377245
377337
 
377246
377338
  \u{1F4A1} TIP: Triple-click to select the entire URL, then copy and paste it into your browser.
377247
377339
  \u26A0\uFE0F Make sure to copy the COMPLETE URL - it may wrap across multiple lines.`);
377248
- try {
377249
- await openBrowserSecurely(authUrl);
377340
+ try {
377341
+ await openBrowserSecurely(authUrl);
377342
+ } catch (error40) {
377343
+ debugLogger.warn(
377344
+ "Failed to open browser automatically:",
377345
+ getErrorMessage(error40)
377346
+ );
377347
+ }
377348
+ ({ code } = await callbackServer.response);
377250
377349
  } catch (error40) {
377251
- debugLogger.warn(
377252
- "Failed to open browser automatically:",
377253
- getErrorMessage(error40)
377254
- );
377350
+ callbackServer.cancel?.(error40 instanceof Error ? error40 : void 0);
377351
+ throw error40;
377255
377352
  }
377256
- const { code } = await callbackServer.response;
377257
377353
  debugLogger.debug(
377258
377354
  "\u2713 Authorization code received, exchanging for tokens..."
377259
377355
  );
@@ -377262,7 +377358,8 @@ ${authUrl}
377262
377358
  code,
377263
377359
  pkceParams.codeVerifier,
377264
377360
  redirectPort,
377265
- resource
377361
+ resource,
377362
+ { allowPrivateNetwork: config2.allowPrivateNetwork }
377266
377363
  );
377267
377364
  if (!tokenResponse.access_token) {
377268
377365
  throw new Error("No access token received from token endpoint");
@@ -377449,7 +377546,7 @@ var DynamicStoredOAuthProvider = class {
377449
377546
  if (this.isCachedTokenValid()) {
377450
377547
  return this.cachedToken;
377451
377548
  }
377452
- const oauthConfig = this.serverConfig.oauth?.enabled && this.serverConfig.oauth ? this.serverConfig.oauth : {};
377549
+ const oauthConfig = this.serverConfig.oauth ?? {};
377453
377550
  const tokenMeta = await this.oauthProvider.getValidTokenWithMetadata(
377454
377551
  this.serverName,
377455
377552
  oauthConfig
@@ -378103,13 +378200,20 @@ async function handleAutomaticOAuth(mcpServerName, mcpServerConfig, wwwAuthentic
378103
378200
  try {
378104
378201
  debugLogger.log(`\u{1F510} '${mcpServerName}' requires OAuth authentication`);
378105
378202
  const serverUrl = mcpServerConfig.httpUrl || mcpServerConfig.url;
378203
+ const discoveryOptions = {
378204
+ allowPrivateNetwork: mcpServerConfig.oauth?.allowPrivateNetwork
378205
+ };
378106
378206
  let oauthConfig = await OAuthUtils.discoverOAuthFromWWWAuthenticate(
378107
378207
  wwwAuthenticate,
378108
- serverUrl
378208
+ serverUrl,
378209
+ discoveryOptions
378109
378210
  );
378110
378211
  if (!oauthConfig && hasNetworkTransport(mcpServerConfig)) {
378111
378212
  const baseUrl = OAuthUtils.extractBaseUrl(serverUrl);
378112
- oauthConfig = await OAuthUtils.discoverOAuthConfig(baseUrl);
378213
+ oauthConfig = await OAuthUtils.discoverOAuthConfig(
378214
+ baseUrl,
378215
+ discoveryOptions
378216
+ );
378113
378217
  }
378114
378218
  if (!oauthConfig) {
378115
378219
  cliConfig.emitMcpDiagnostic(
@@ -378126,7 +378230,8 @@ async function handleAutomaticOAuth(mcpServerName, mcpServerConfig, wwwAuthentic
378126
378230
  issuer: oauthConfig.issuer,
378127
378231
  tokenUrl: oauthConfig.tokenUrl,
378128
378232
  scopes: oauthConfig.scopes || [],
378129
- authorizationResponseIssParameterSupported: mcpServerConfig.oauth?.authorizationResponseIssParameterSupported ?? oauthConfig.authorizationResponseIssParameterSupported
378233
+ authorizationResponseIssParameterSupported: mcpServerConfig.oauth?.authorizationResponseIssParameterSupported ?? oauthConfig.authorizationResponseIssParameterSupported,
378234
+ allowPrivateNetwork: mcpServerConfig.oauth?.allowPrivateNetwork
378130
378235
  };
378131
378236
  debugLogger.log(
378132
378237
  `Starting OAuth authentication for server '${mcpServerName}'...`
@@ -378582,14 +378687,15 @@ async function invokeMcpPrompt(mcpServerName, mcpClient, promptName, promptParam
378582
378687
  function hasNetworkTransport(config2) {
378583
378688
  return !!(config2.url || config2.httpUrl);
378584
378689
  }
378585
- async function getStoredOAuthToken(serverName) {
378690
+ async function getStoredOAuthToken(serverName, oauthConfig) {
378586
378691
  const tokenStorage = new MCPOAuthTokenStorage();
378587
378692
  const credentials3 = await tokenStorage.getCredentials(serverName);
378588
378693
  if (!credentials3) return null;
378589
378694
  const authProvider = new MCPOAuthProvider(tokenStorage);
378590
378695
  return authProvider.getValidToken(serverName, {
378696
+ ...oauthConfig,
378591
378697
  // Pass client ID if available
378592
- clientId: credentials3.clientId
378698
+ clientId: oauthConfig?.clientId ?? credentials3.clientId
378593
378699
  });
378594
378700
  }
378595
378701
  function createSSETransportWithAuth(config2, accessToken) {
@@ -378609,8 +378715,11 @@ async function connectWithSSETransport(client, config2, accessToken) {
378609
378715
  timeout: config2.timeout ?? MCP_DEFAULT_TIMEOUT_MSEC
378610
378716
  });
378611
378717
  }
378612
- async function showAuthRequiredMessage(serverName, cliConfig) {
378613
- const hasRejectedToken = !!await getStoredOAuthToken(serverName);
378718
+ async function showAuthRequiredMessage(serverName, cliConfig, oauthConfig) {
378719
+ const hasRejectedToken = !!await getStoredOAuthToken(
378720
+ serverName,
378721
+ oauthConfig
378722
+ );
378614
378723
  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}`;
378615
378724
  cliConfig.emitMcpDiagnostic("info", message, void 0, serverName);
378616
378725
  throw new UnauthorizedError(message);
@@ -378736,7 +378845,7 @@ async function connectToMcpServer(clientVersion, mcpServerName, mcpServerConfig,
378736
378845
  await connectWithSSETransport(
378737
378846
  mcpClient,
378738
378847
  mcpServerConfig,
378739
- await getStoredOAuthToken(mcpServerName)
378848
+ await getStoredOAuthToken(mcpServerName, mcpServerConfig.oauth)
378740
378849
  );
378741
378850
  debugLogger.log(
378742
378851
  `MCP server '${mcpServerName}': Successfully connected using SSE transport.`
@@ -378761,7 +378870,11 @@ async function connectToMcpServer(clientVersion, mcpServerName, mcpServerConfig,
378761
378870
  mcpServerRequiresOAuth.set(mcpServerName, true);
378762
378871
  const shouldTriggerOAuth = mcpServerConfig.oauth?.enabled;
378763
378872
  if (!shouldTriggerOAuth) {
378764
- await showAuthRequiredMessage(mcpServerName, cliConfig);
378873
+ await showAuthRequiredMessage(
378874
+ mcpServerName,
378875
+ cliConfig,
378876
+ mcpServerConfig.oauth
378877
+ );
378765
378878
  }
378766
378879
  const errorString = String(error40);
378767
378880
  let wwwAuthenticate = extractWWWAuthenticateHeader(errorString);
@@ -378817,7 +378930,10 @@ async function connectToMcpServer(clientVersion, mcpServerName, mcpServerConfig,
378817
378930
  cliConfig
378818
378931
  );
378819
378932
  if (oauthSuccess) {
378820
- const accessToken = await getStoredOAuthToken(mcpServerName);
378933
+ const accessToken = await getStoredOAuthToken(
378934
+ mcpServerName,
378935
+ mcpServerConfig.oauth
378936
+ );
378821
378937
  if (!accessToken) {
378822
378938
  throw new Error(
378823
378939
  `Failed to get OAuth token for server '${mcpServerName}'`
@@ -378840,7 +378956,11 @@ async function connectToMcpServer(clientVersion, mcpServerName, mcpServerConfig,
378840
378956
  } else {
378841
378957
  const shouldTryDiscovery = mcpServerConfig.oauth?.enabled;
378842
378958
  if (!shouldTryDiscovery) {
378843
- await showAuthRequiredMessage(mcpServerName, cliConfig);
378959
+ await showAuthRequiredMessage(
378960
+ mcpServerName,
378961
+ cliConfig,
378962
+ mcpServerConfig.oauth
378963
+ );
378844
378964
  }
378845
378965
  debugLogger.log(
378846
378966
  `\u{1F50D} Attempting OAuth discovery for '${mcpServerName}'...`
@@ -378850,7 +378970,13 @@ async function connectToMcpServer(clientVersion, mcpServerName, mcpServerConfig,
378850
378970
  mcpServerConfig.httpUrl || mcpServerConfig.url
378851
378971
  );
378852
378972
  const baseUrl = `${serverUrl.protocol}//${serverUrl.host}`;
378853
- const oauthConfig = await OAuthUtils.discoverOAuthConfig(baseUrl);
378973
+ const discoveryOptions = {
378974
+ allowPrivateNetwork: mcpServerConfig.oauth?.allowPrivateNetwork
378975
+ };
378976
+ const oauthConfig = await OAuthUtils.discoverOAuthConfig(
378977
+ baseUrl,
378978
+ discoveryOptions
378979
+ );
378854
378980
  if (oauthConfig) {
378855
378981
  debugLogger.log(
378856
378982
  `Discovered OAuth configuration from base URL for server '${mcpServerName}'`
@@ -378861,7 +378987,8 @@ async function connectToMcpServer(clientVersion, mcpServerName, mcpServerConfig,
378861
378987
  issuer: oauthConfig.issuer,
378862
378988
  tokenUrl: oauthConfig.tokenUrl,
378863
378989
  scopes: oauthConfig.scopes || [],
378864
- authorizationResponseIssParameterSupported: mcpServerConfig.oauth?.authorizationResponseIssParameterSupported ?? oauthConfig.authorizationResponseIssParameterSupported
378990
+ authorizationResponseIssParameterSupported: mcpServerConfig.oauth?.authorizationResponseIssParameterSupported ?? oauthConfig.authorizationResponseIssParameterSupported,
378991
+ allowPrivateNetwork: mcpServerConfig.oauth?.allowPrivateNetwork
378865
378992
  };
378866
378993
  const authServerUrl = mcpServerConfig.httpUrl || mcpServerConfig.url;
378867
378994
  debugLogger.log(
@@ -378875,7 +379002,10 @@ async function connectToMcpServer(clientVersion, mcpServerName, mcpServerConfig,
378875
379002
  oauthAuthConfig,
378876
379003
  authServerUrl
378877
379004
  );
378878
- const accessToken = await getStoredOAuthToken(mcpServerName);
379005
+ const accessToken = await getStoredOAuthToken(
379006
+ mcpServerName,
379007
+ mcpServerConfig.oauth
379008
+ );
378879
379009
  if (!accessToken) {
378880
379010
  throw new Error(
378881
379011
  `Failed to get OAuth token for server '${mcpServerName}'`
@@ -407602,7 +407732,7 @@ export {
407602
407732
  SchemaValidator,
407603
407733
  jsonToMarkdown,
407604
407734
  safeJsonToMarkdown,
407605
- isRecord,
407735
+ isRecord2 as isRecord,
407606
407736
  MessageBusType,
407607
407737
  QuestionType,
407608
407738
  isBackgroundExecutionData,
@@ -408251,6 +408381,7 @@ export {
408251
408381
  sanitizeHostname,
408252
408382
  isLoopbackHost,
408253
408383
  isAddressPrivate,
408384
+ isEnterprisePrivateAddress,
408254
408385
  isPrivateIpAsync,
408255
408386
  isPrivateIp,
408256
408387
  validateUrlDestination,