@google/gemini-cli-a2a-server 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.
- package/dist/a2a-server.mjs +237 -142
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
package/dist/a2a-server.mjs
CHANGED
|
@@ -34497,7 +34497,7 @@ var require_request = __commonJS({
|
|
|
34497
34497
|
"node_modules/express/lib/request.js"(exports2, module2) {
|
|
34498
34498
|
"use strict";
|
|
34499
34499
|
var accepts = require_accepts();
|
|
34500
|
-
var
|
|
34500
|
+
var isIP5 = __require("node:net").isIP;
|
|
34501
34501
|
var typeis = require_type_is();
|
|
34502
34502
|
var http7 = __require("node:http");
|
|
34503
34503
|
var fresh = require_fresh();
|
|
@@ -34588,7 +34588,7 @@ var require_request = __commonJS({
|
|
|
34588
34588
|
var hostname3 = this.hostname;
|
|
34589
34589
|
if (!hostname3) return [];
|
|
34590
34590
|
var offset = this.app.get("subdomain offset");
|
|
34591
|
-
var subdomains2 = !
|
|
34591
|
+
var subdomains2 = !isIP5(hostname3) ? hostname3.split(".").reverse() : [hostname3];
|
|
34592
34592
|
return subdomains2.slice(offset);
|
|
34593
34593
|
});
|
|
34594
34594
|
defineGetter(req, "path", function path103() {
|
|
@@ -67278,12 +67278,26 @@ function parseResponseData(error2) {
|
|
|
67278
67278
|
}
|
|
67279
67279
|
return void 0;
|
|
67280
67280
|
}
|
|
67281
|
+
function isRecord(value) {
|
|
67282
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
67283
|
+
}
|
|
67281
67284
|
function isAuthenticationError(error2) {
|
|
67282
|
-
|
|
67283
|
-
|
|
67284
|
-
|
|
67285
|
+
const friendly = toFriendlyError(error2);
|
|
67286
|
+
if (friendly instanceof UnauthorizedError) {
|
|
67287
|
+
return true;
|
|
67288
|
+
}
|
|
67289
|
+
if (isRecord(error2)) {
|
|
67290
|
+
const code = error2["code"] ?? error2["status"] ?? error2["statusCode"];
|
|
67291
|
+
if (code === 401 || code === "401") {
|
|
67285
67292
|
return true;
|
|
67286
67293
|
}
|
|
67294
|
+
const response = error2["response"];
|
|
67295
|
+
if (isRecord(response)) {
|
|
67296
|
+
const responseCode = response["status"] ?? response["statusCode"];
|
|
67297
|
+
if (responseCode === 401 || responseCode === "401") {
|
|
67298
|
+
return true;
|
|
67299
|
+
}
|
|
67300
|
+
}
|
|
67287
67301
|
}
|
|
67288
67302
|
if (error2 instanceof Error && error2.name === "UnauthorizedError") {
|
|
67289
67303
|
return true;
|
|
@@ -67292,12 +67306,12 @@ function isAuthenticationError(error2) {
|
|
|
67292
67306
|
return true;
|
|
67293
67307
|
}
|
|
67294
67308
|
const message = getErrorMessage(error2);
|
|
67295
|
-
if (
|
|
67309
|
+
if (HTTP_401_REGEX.test(message)) {
|
|
67296
67310
|
return true;
|
|
67297
67311
|
}
|
|
67298
67312
|
return false;
|
|
67299
67313
|
}
|
|
67300
|
-
var FatalError, FatalAuthenticationError, FatalConfigError, FatalCancellationError, ForbiddenError, AccountSuspendedError, UnauthorizedError, BadRequestError, ChangeAuthRequestedError;
|
|
67314
|
+
var FatalError, FatalAuthenticationError, FatalConfigError, FatalCancellationError, ForbiddenError, AccountSuspendedError, UnauthorizedError, BadRequestError, ChangeAuthRequestedError, HTTP_401_REGEX;
|
|
67301
67315
|
var init_errors2 = __esm({
|
|
67302
67316
|
"packages/core/dist/src/utils/errors.js"() {
|
|
67303
67317
|
"use strict";
|
|
@@ -67362,6 +67376,7 @@ var init_errors2 = __esm({
|
|
|
67362
67376
|
this.name = "ChangeAuthRequestedError";
|
|
67363
67377
|
}
|
|
67364
67378
|
};
|
|
67379
|
+
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;
|
|
67365
67380
|
}
|
|
67366
67381
|
});
|
|
67367
67382
|
|
|
@@ -121054,8 +121069,8 @@ var require_utils7 = __commonJS({
|
|
|
121054
121069
|
var HOST_DELIMS = { "@": "%40", "/": "%2F", "?": "%3F", "#": "%23", ":": "%3A" };
|
|
121055
121070
|
var HOST_DELIM_RE = /[@/?#:]/g;
|
|
121056
121071
|
var HOST_DELIM_NO_COLON_RE = /[@/?#]/g;
|
|
121057
|
-
function reescapeHostDelimiters(host,
|
|
121058
|
-
const re3 =
|
|
121072
|
+
function reescapeHostDelimiters(host, isIP5) {
|
|
121073
|
+
const re3 = isIP5 ? HOST_DELIM_NO_COLON_RE : HOST_DELIM_RE;
|
|
121059
121074
|
re3.lastIndex = 0;
|
|
121060
121075
|
return host.replace(re3, (ch) => HOST_DELIMS[ch]);
|
|
121061
121076
|
}
|
|
@@ -121537,7 +121552,7 @@ var require_fast_uri = __commonJS({
|
|
|
121537
121552
|
fragment: void 0
|
|
121538
121553
|
};
|
|
121539
121554
|
let malformedAuthorityOrPort = false;
|
|
121540
|
-
let
|
|
121555
|
+
let isIP5 = false;
|
|
121541
121556
|
if (options.reference === "suffix") {
|
|
121542
121557
|
if (options.scheme) {
|
|
121543
121558
|
uri = options.scheme + ":" + uri;
|
|
@@ -121567,9 +121582,9 @@ var require_fast_uri = __commonJS({
|
|
|
121567
121582
|
if (ipv4result === false) {
|
|
121568
121583
|
const ipv6result = normalizeIPv6(parsed.host);
|
|
121569
121584
|
parsed.host = ipv6result.host.toLowerCase();
|
|
121570
|
-
|
|
121585
|
+
isIP5 = ipv6result.isIPV6;
|
|
121571
121586
|
} else {
|
|
121572
|
-
|
|
121587
|
+
isIP5 = true;
|
|
121573
121588
|
}
|
|
121574
121589
|
}
|
|
121575
121590
|
if (parsed.scheme === void 0 && parsed.userinfo === void 0 && parsed.host === void 0 && parsed.port === void 0 && parsed.query === void 0 && !parsed.path) {
|
|
@@ -121586,7 +121601,7 @@ var require_fast_uri = __commonJS({
|
|
|
121586
121601
|
}
|
|
121587
121602
|
const schemeHandler = getSchemeHandler(options.scheme || parsed.scheme);
|
|
121588
121603
|
if (!options.unicodeSupport && (!schemeHandler || !schemeHandler.unicodeSupport)) {
|
|
121589
|
-
if (parsed.host && (options.domainHost || schemeHandler && schemeHandler.domainHost) &&
|
|
121604
|
+
if (parsed.host && (options.domainHost || schemeHandler && schemeHandler.domainHost) && isIP5 === false && nonSimpleDomain(parsed.host)) {
|
|
121590
121605
|
try {
|
|
121591
121606
|
parsed.host = URL.domainToASCII(parsed.host.toLowerCase());
|
|
121592
121607
|
} catch (e3) {
|
|
@@ -121600,7 +121615,7 @@ var require_fast_uri = __commonJS({
|
|
|
121600
121615
|
parsed.scheme = unescape(parsed.scheme);
|
|
121601
121616
|
}
|
|
121602
121617
|
if (parsed.host !== void 0) {
|
|
121603
|
-
parsed.host = reescapeHostDelimiters(unescape(parsed.host),
|
|
121618
|
+
parsed.host = reescapeHostDelimiters(unescape(parsed.host), isIP5);
|
|
121604
121619
|
}
|
|
121605
121620
|
}
|
|
121606
121621
|
if (parsed.path) {
|
|
@@ -131230,7 +131245,7 @@ var init_schemaValidator = __esm({
|
|
|
131230
131245
|
});
|
|
131231
131246
|
|
|
131232
131247
|
// packages/core/dist/src/utils/markdownUtils.js
|
|
131233
|
-
function
|
|
131248
|
+
function isRecord2(value) {
|
|
131234
131249
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
131235
131250
|
}
|
|
131236
131251
|
var init_markdownUtils = __esm({
|
|
@@ -131668,7 +131683,7 @@ var init_tools = __esm({
|
|
|
131668
131683
|
* Type guard to check if an unknown value represents a ToolParameterSchema object.
|
|
131669
131684
|
*/
|
|
131670
131685
|
isParameterSchema(obj) {
|
|
131671
|
-
return
|
|
131686
|
+
return isRecord2(obj) && "type" in obj;
|
|
131672
131687
|
}
|
|
131673
131688
|
/**
|
|
131674
131689
|
* Adds the `wait_for_previous` parameter to the tool's schema.
|
|
@@ -131681,7 +131696,7 @@ var init_tools = __esm({
|
|
|
131681
131696
|
const props = schema2.properties;
|
|
131682
131697
|
let propertiesObj = {};
|
|
131683
131698
|
if (props !== void 0) {
|
|
131684
|
-
if (!
|
|
131699
|
+
if (!isRecord2(props)) {
|
|
131685
131700
|
return schema2;
|
|
131686
131701
|
}
|
|
131687
131702
|
propertiesObj = props;
|
|
@@ -139286,7 +139301,7 @@ var init_keychainService = __esm({
|
|
|
139286
139301
|
async loadKeychainModule() {
|
|
139287
139302
|
const moduleName = "@github/keytar";
|
|
139288
139303
|
const module2 = await import(moduleName);
|
|
139289
|
-
const potential =
|
|
139304
|
+
const potential = isRecord2(module2) && module2["default"] || module2;
|
|
139290
139305
|
const result2 = KeychainSchema.safeParse(potential);
|
|
139291
139306
|
if (result2.success) {
|
|
139292
139307
|
return potential;
|
|
@@ -221428,8 +221443,8 @@ var GIT_COMMIT_INFO, CLI_VERSION;
|
|
|
221428
221443
|
var init_git_commit = __esm({
|
|
221429
221444
|
"packages/core/dist/src/generated/git-commit.js"() {
|
|
221430
221445
|
"use strict";
|
|
221431
|
-
GIT_COMMIT_INFO = "
|
|
221432
|
-
CLI_VERSION = "0.66.0-
|
|
221446
|
+
GIT_COMMIT_INFO = "b041de017";
|
|
221447
|
+
CLI_VERSION = "0.66.0-preview.0";
|
|
221433
221448
|
}
|
|
221434
221449
|
});
|
|
221435
221450
|
|
|
@@ -323899,7 +323914,7 @@ var require_dump = __commonJS({
|
|
|
323899
323914
|
var require_dns = __commonJS({
|
|
323900
323915
|
"packages/core/node_modules/undici/lib/interceptor/dns.js"(exports2, module2) {
|
|
323901
323916
|
"use strict";
|
|
323902
|
-
var { isIP:
|
|
323917
|
+
var { isIP: isIP5 } = __require("node:net");
|
|
323903
323918
|
var { lookup: lookup3 } = __require("node:dns");
|
|
323904
323919
|
var DecoratorHandler = require_decorator_handler();
|
|
323905
323920
|
var { InvalidArgumentError, InformationalError } = require_errors7();
|
|
@@ -324198,7 +324213,7 @@ var require_dns = __commonJS({
|
|
|
324198
324213
|
return (dispatch) => {
|
|
324199
324214
|
return function dnsInterceptor(origDispatchOpts, handler) {
|
|
324200
324215
|
const origin = origDispatchOpts.origin.constructor === URL ? origDispatchOpts.origin : new URL(origDispatchOpts.origin);
|
|
324201
|
-
if (
|
|
324216
|
+
if (isIP5(origin.hostname) !== 0) {
|
|
324202
324217
|
return dispatch(origDispatchOpts, handler);
|
|
324203
324218
|
}
|
|
324204
324219
|
instance2.runLookup(origin, origDispatchOpts, (err2, newOrigin) => {
|
|
@@ -337767,7 +337782,7 @@ function getVersion() {
|
|
|
337767
337782
|
}
|
|
337768
337783
|
versionPromise = (async () => {
|
|
337769
337784
|
const pkgJson = await getPackageJson(__dirname4);
|
|
337770
|
-
return "0.66.0-
|
|
337785
|
+
return "0.66.0-preview.0";
|
|
337771
337786
|
})();
|
|
337772
337787
|
return versionPromise;
|
|
337773
337788
|
}
|
|
@@ -339540,8 +339555,8 @@ var init_baseLlmClient = __esm({
|
|
|
339540
339555
|
}
|
|
339541
339556
|
}, shouldRetryOnContent, "generateJson", role);
|
|
339542
339557
|
const parsed = JSON.parse(this.cleanJsonResponse(getResponseText(result2).trim(), model));
|
|
339543
|
-
const
|
|
339544
|
-
if (
|
|
339558
|
+
const isRecord4 = (val) => typeof val === "object" && val !== null && !Array.isArray(val);
|
|
339559
|
+
if (isRecord4(parsed)) {
|
|
339545
339560
|
return parsed;
|
|
339546
339561
|
}
|
|
339547
339562
|
throw new Error("Invalid JSON response format from LLM");
|
|
@@ -345588,7 +345603,7 @@ function getSafeGitEnv(baseEnv = process.env) {
|
|
|
345588
345603
|
GIT_SSH_COMMAND: gitSshCommand,
|
|
345589
345604
|
GH_PROMPT_DISABLED: "1",
|
|
345590
345605
|
GCM_INTERACTIVE: "never",
|
|
345591
|
-
GIT_CONFIG_GLOBAL:
|
|
345606
|
+
...baseEnv["GIT_CONFIG_GLOBAL"] ? { GIT_CONFIG_GLOBAL: baseEnv["GIT_CONFIG_GLOBAL"] } : {},
|
|
345592
345607
|
GIT_CONFIG_SYSTEM: devNullPath,
|
|
345593
345608
|
GIT_CONFIG_NOSYSTEM: "1",
|
|
345594
345609
|
GIT_CONFIG_COUNT: "7",
|
|
@@ -359579,12 +359594,14 @@ ${truncated}`;
|
|
|
359579
359594
|
for (const key of gitConfigKeys) {
|
|
359580
359595
|
baseEnv[key] = sourceEnv[key];
|
|
359581
359596
|
}
|
|
359597
|
+
if (!baseEnv["GIT_CONFIG_GLOBAL"]) {
|
|
359598
|
+
delete baseEnv["GIT_CONFIG_GLOBAL"];
|
|
359599
|
+
}
|
|
359582
359600
|
let gitConfigCount = parseInt(baseEnv["GIT_CONFIG_COUNT"] || "0", 10);
|
|
359583
359601
|
const devNullPath = os31.platform() === "win32" ? "NUL" : "/dev/null";
|
|
359584
|
-
baseEnv["GIT_CONFIG_GLOBAL"] = devNullPath;
|
|
359585
359602
|
baseEnv["GIT_CONFIG_SYSTEM"] = devNullPath;
|
|
359586
359603
|
baseEnv["GIT_CONFIG_NOSYSTEM"] = "1";
|
|
359587
|
-
sanitizationConfig.allowedEnvironmentVariables.push("GIT_CONFIG_COUNT", "
|
|
359604
|
+
sanitizationConfig.allowedEnvironmentVariables.push("GIT_CONFIG_COUNT", "GIT_CONFIG_SYSTEM", "GIT_CONFIG_NOSYSTEM");
|
|
359588
359605
|
const defaultGitOverrides = [
|
|
359589
359606
|
["credential.helper", ""],
|
|
359590
359607
|
["core.fsmonitor", ""],
|
|
@@ -361815,6 +361832,31 @@ function isAddressPrivate(address) {
|
|
|
361815
361832
|
return true;
|
|
361816
361833
|
}
|
|
361817
361834
|
}
|
|
361835
|
+
function isEnterprisePrivateAddress(addressOrHost) {
|
|
361836
|
+
const normalized = sanitizeHostname(addressOrHost).toLowerCase();
|
|
361837
|
+
if (normalized.endsWith(".internal") || normalized.endsWith(".local")) {
|
|
361838
|
+
return true;
|
|
361839
|
+
}
|
|
361840
|
+
if (normalized === "localhost" || normalized.endsWith(".localhost")) {
|
|
361841
|
+
return false;
|
|
361842
|
+
}
|
|
361843
|
+
try {
|
|
361844
|
+
if (!import_ipaddr.default.isValid(normalized)) {
|
|
361845
|
+
return false;
|
|
361846
|
+
}
|
|
361847
|
+
let addr2 = import_ipaddr.default.parse(normalized);
|
|
361848
|
+
if (addr2 instanceof import_ipaddr.default.IPv6 && addr2.isIPv4MappedAddress()) {
|
|
361849
|
+
addr2 = addr2.toIPv4Address();
|
|
361850
|
+
}
|
|
361851
|
+
if (isBenchmarkAddress(addr2)) {
|
|
361852
|
+
return false;
|
|
361853
|
+
}
|
|
361854
|
+
const range2 = addr2.range();
|
|
361855
|
+
return range2 === "private" || range2 === "carrierGradeNat" || range2 === "uniqueLocal";
|
|
361856
|
+
} catch {
|
|
361857
|
+
return false;
|
|
361858
|
+
}
|
|
361859
|
+
}
|
|
361818
361860
|
async function isPrivateIpAsync(url5) {
|
|
361819
361861
|
let parsedUrl;
|
|
361820
361862
|
try {
|
|
@@ -377161,6 +377203,7 @@ var init_http_provider = __esm({
|
|
|
377161
377203
|
|
|
377162
377204
|
// packages/core/dist/src/mcp/oauth-utils.js
|
|
377163
377205
|
import { lookup as lookup2 } from "node:dns/promises";
|
|
377206
|
+
import { isIP as isIP4 } from "node:net";
|
|
377164
377207
|
function isLoopbackUrl(urlStr) {
|
|
377165
377208
|
try {
|
|
377166
377209
|
const url5 = new URL(urlStr);
|
|
@@ -377212,7 +377255,14 @@ async function validateOAuthEndpointUrl(urlStr, options) {
|
|
|
377212
377255
|
return parsed.toString();
|
|
377213
377256
|
}
|
|
377214
377257
|
if (isAddressPrivate(hostname3)) {
|
|
377215
|
-
|
|
377258
|
+
const isEnterprisePrivate = isEnterprisePrivateAddress(hostname3);
|
|
377259
|
+
if (!options?.allowPrivateNetwork || !isEnterprisePrivate) {
|
|
377260
|
+
const hint = isEnterprisePrivate ? ` ${PRIVATE_NETWORK_REMEDIATION_HINT}` : "";
|
|
377261
|
+
throw new OAuthSecurityError(`OAuth endpoint "${resolvedUrl}" points to private or reserved IP address which is blocked.${hint}`);
|
|
377262
|
+
}
|
|
377263
|
+
if (isIP4(hostname3) !== 0) {
|
|
377264
|
+
return parsed.toString();
|
|
377265
|
+
}
|
|
377216
377266
|
}
|
|
377217
377267
|
try {
|
|
377218
377268
|
const addresses = await lookup2(hostname3, { all: true });
|
|
@@ -377221,7 +377271,11 @@ async function validateOAuthEndpointUrl(urlStr, options) {
|
|
|
377221
377271
|
}
|
|
377222
377272
|
for (const addr2 of addresses) {
|
|
377223
377273
|
if (isAddressPrivate(addr2.address)) {
|
|
377224
|
-
|
|
377274
|
+
const isEnterprisePrivate = isEnterprisePrivateAddress(addr2.address);
|
|
377275
|
+
if (!options?.allowPrivateNetwork || !isEnterprisePrivate) {
|
|
377276
|
+
const hint = isEnterprisePrivate ? ` ${PRIVATE_NETWORK_REMEDIATION_HINT}` : "";
|
|
377277
|
+
throw new OAuthSecurityError(`OAuth endpoint "${resolvedUrl}" resolves to private network address "${addr2.address}" which is blocked.${hint}`);
|
|
377278
|
+
}
|
|
377225
377279
|
}
|
|
377226
377280
|
}
|
|
377227
377281
|
} catch (error2) {
|
|
@@ -377232,7 +377286,7 @@ async function validateOAuthEndpointUrl(urlStr, options) {
|
|
|
377232
377286
|
}
|
|
377233
377287
|
return parsed.toString();
|
|
377234
377288
|
}
|
|
377235
|
-
var ResourceMismatchError, OAuthSecurityError, FIVE_MIN_BUFFER_MS, OAuthUtils;
|
|
377289
|
+
var ResourceMismatchError, OAuthSecurityError, PRIVATE_NETWORK_REMEDIATION_HINT, FIVE_MIN_BUFFER_MS, OAuthUtils;
|
|
377236
377290
|
var init_oauth_utils = __esm({
|
|
377237
377291
|
"packages/core/dist/src/mcp/oauth-utils.js"() {
|
|
377238
377292
|
"use strict";
|
|
@@ -377251,6 +377305,7 @@ var init_oauth_utils = __esm({
|
|
|
377251
377305
|
this.name = "OAuthSecurityError";
|
|
377252
377306
|
}
|
|
377253
377307
|
};
|
|
377308
|
+
PRIVATE_NETWORK_REMEDIATION_HINT = 'Set "oauth.allowPrivateNetwork": true in settings.json for this MCP server if it is on a trusted private network.';
|
|
377254
377309
|
FIVE_MIN_BUFFER_MS = 5 * 60 * 1e3;
|
|
377255
377310
|
OAuthUtils = class {
|
|
377256
377311
|
/**
|
|
@@ -377287,7 +377342,8 @@ var init_oauth_utils = __esm({
|
|
|
377287
377342
|
try {
|
|
377288
377343
|
const validatedUrl = await validateOAuthEndpointUrl(resourceMetadataUrl, {
|
|
377289
377344
|
allowLoopback: options?.allowLoopback,
|
|
377290
|
-
expectedOrigin: options?.expectedOrigin
|
|
377345
|
+
expectedOrigin: options?.expectedOrigin,
|
|
377346
|
+
allowPrivateNetwork: options?.allowPrivateNetwork
|
|
377291
377347
|
});
|
|
377292
377348
|
const response = await fetch(validatedUrl);
|
|
377293
377349
|
if (!response.ok) {
|
|
@@ -377312,7 +377368,8 @@ var init_oauth_utils = __esm({
|
|
|
377312
377368
|
static async fetchAuthorizationServerMetadata(authServerMetadataUrl, options) {
|
|
377313
377369
|
try {
|
|
377314
377370
|
const validatedUrl = await validateOAuthEndpointUrl(authServerMetadataUrl, {
|
|
377315
|
-
allowLoopback: options?.allowLoopback
|
|
377371
|
+
allowLoopback: options?.allowLoopback,
|
|
377372
|
+
allowPrivateNetwork: options?.allowPrivateNetwork
|
|
377316
377373
|
});
|
|
377317
377374
|
const response = await fetch(validatedUrl);
|
|
377318
377375
|
if (!response.ok) {
|
|
@@ -377358,7 +377415,8 @@ var init_oauth_utils = __esm({
|
|
|
377358
377415
|
*/
|
|
377359
377416
|
static async discoverAuthorizationServerMetadata(authServerUrl, options) {
|
|
377360
377417
|
const validatedBaseUrl = await validateOAuthEndpointUrl(authServerUrl, {
|
|
377361
|
-
allowLoopback: options?.allowLoopback
|
|
377418
|
+
allowLoopback: options?.allowLoopback,
|
|
377419
|
+
allowPrivateNetwork: options?.allowPrivateNetwork
|
|
377362
377420
|
});
|
|
377363
377421
|
const authServerUrlObj = new URL(validatedBaseUrl);
|
|
377364
377422
|
const base = `${authServerUrlObj.protocol}//${authServerUrlObj.host}`;
|
|
@@ -377385,17 +377443,18 @@ var init_oauth_utils = __esm({
|
|
|
377385
377443
|
* @param serverUrl The base URL of the server
|
|
377386
377444
|
* @returns The discovered OAuth configuration or null if not available
|
|
377387
377445
|
*/
|
|
377388
|
-
static async discoverOAuthConfig(serverUrl) {
|
|
377446
|
+
static async discoverOAuthConfig(serverUrl, options) {
|
|
377389
377447
|
try {
|
|
377390
377448
|
const allowLoopback = isLoopbackUrl(serverUrl);
|
|
377449
|
+
const allowPrivateNetwork = options?.allowPrivateNetwork;
|
|
377391
377450
|
const expectedOrigin = new URL(serverUrl).origin;
|
|
377392
377451
|
const wellKnownUrls = this.buildWellKnownUrls(serverUrl);
|
|
377393
|
-
let resourceMetadata = await this.fetchProtectedResourceMetadata(wellKnownUrls.protectedResource, { allowLoopback, expectedOrigin });
|
|
377452
|
+
let resourceMetadata = await this.fetchProtectedResourceMetadata(wellKnownUrls.protectedResource, { allowLoopback, expectedOrigin, allowPrivateNetwork });
|
|
377394
377453
|
if (!resourceMetadata) {
|
|
377395
377454
|
const url5 = new URL(serverUrl);
|
|
377396
377455
|
if (url5.pathname && url5.pathname !== "/") {
|
|
377397
377456
|
const rootBasedUrls = this.buildWellKnownUrls(serverUrl, true);
|
|
377398
|
-
resourceMetadata = await this.fetchProtectedResourceMetadata(rootBasedUrls.protectedResource, { allowLoopback, expectedOrigin });
|
|
377457
|
+
resourceMetadata = await this.fetchProtectedResourceMetadata(rootBasedUrls.protectedResource, { allowLoopback, expectedOrigin, allowPrivateNetwork });
|
|
377399
377458
|
}
|
|
377400
377459
|
}
|
|
377401
377460
|
if (resourceMetadata) {
|
|
@@ -377404,11 +377463,13 @@ var init_oauth_utils = __esm({
|
|
|
377404
377463
|
throw new ResourceMismatchError(`Protected resource ${resourceMetadata.resource} does not match expected ${expectedResource}`);
|
|
377405
377464
|
}
|
|
377406
377465
|
}
|
|
377466
|
+
const authServerDiscoveryOptions = {
|
|
377467
|
+
allowLoopback,
|
|
377468
|
+
...allowPrivateNetwork !== void 0 ? { allowPrivateNetwork } : {}
|
|
377469
|
+
};
|
|
377407
377470
|
if (resourceMetadata?.authorization_servers?.length) {
|
|
377408
377471
|
const authServerUrl = resourceMetadata.authorization_servers[0];
|
|
377409
|
-
const authServerMetadata2 = await this.discoverAuthorizationServerMetadata(authServerUrl,
|
|
377410
|
-
allowLoopback
|
|
377411
|
-
});
|
|
377472
|
+
const authServerMetadata2 = await this.discoverAuthorizationServerMetadata(authServerUrl, authServerDiscoveryOptions);
|
|
377412
377473
|
if (authServerMetadata2) {
|
|
377413
377474
|
const config2 = this.metadataToOAuthConfig(authServerMetadata2);
|
|
377414
377475
|
if (authServerMetadata2.registration_endpoint) {
|
|
@@ -377418,9 +377479,7 @@ var init_oauth_utils = __esm({
|
|
|
377418
377479
|
}
|
|
377419
377480
|
}
|
|
377420
377481
|
debugLogger.debug(`Trying OAuth discovery fallback at ${serverUrl}`);
|
|
377421
|
-
const authServerMetadata = await this.discoverAuthorizationServerMetadata(serverUrl,
|
|
377422
|
-
allowLoopback
|
|
377423
|
-
});
|
|
377482
|
+
const authServerMetadata = await this.discoverAuthorizationServerMetadata(serverUrl, authServerDiscoveryOptions);
|
|
377424
377483
|
if (authServerMetadata) {
|
|
377425
377484
|
const config2 = this.metadataToOAuthConfig(authServerMetadata);
|
|
377426
377485
|
if (authServerMetadata.registration_endpoint) {
|
|
@@ -377457,22 +377516,25 @@ var init_oauth_utils = __esm({
|
|
|
377457
377516
|
* @param mcpServerUrl Optional MCP server URL to validate against the resource metadata
|
|
377458
377517
|
* @returns The discovered OAuth configuration or null if not available
|
|
377459
377518
|
*/
|
|
377460
|
-
static async discoverOAuthFromWWWAuthenticate(wwwAuthenticate, mcpServerUrl) {
|
|
377519
|
+
static async discoverOAuthFromWWWAuthenticate(wwwAuthenticate, mcpServerUrl, options) {
|
|
377461
377520
|
const resourceMetadataUri = this.parseWWWAuthenticateHeader(wwwAuthenticate);
|
|
377462
377521
|
if (!resourceMetadataUri) {
|
|
377463
377522
|
return null;
|
|
377464
377523
|
}
|
|
377465
377524
|
const allowLoopback = mcpServerUrl ? isLoopbackUrl(mcpServerUrl) : false;
|
|
377525
|
+
const allowPrivateNetwork = options?.allowPrivateNetwork;
|
|
377466
377526
|
const expectedOrigin = mcpServerUrl ? new URL(mcpServerUrl).origin : void 0;
|
|
377467
377527
|
const validatedResourceMetadataUrl = await validateOAuthEndpointUrl(resourceMetadataUri, {
|
|
377468
377528
|
allowLoopback,
|
|
377469
377529
|
expectedOrigin,
|
|
377470
377530
|
allowRelative: true,
|
|
377471
|
-
baseUri: mcpServerUrl
|
|
377531
|
+
baseUri: mcpServerUrl,
|
|
377532
|
+
allowPrivateNetwork
|
|
377472
377533
|
});
|
|
377473
377534
|
const resourceMetadata = await this.fetchProtectedResourceMetadata(validatedResourceMetadataUrl, {
|
|
377474
377535
|
allowLoopback,
|
|
377475
|
-
expectedOrigin
|
|
377536
|
+
expectedOrigin,
|
|
377537
|
+
allowPrivateNetwork
|
|
377476
377538
|
});
|
|
377477
377539
|
if (resourceMetadata && mcpServerUrl) {
|
|
377478
377540
|
const expectedResource = this.buildResourceParameter(mcpServerUrl);
|
|
@@ -377485,7 +377547,8 @@ var init_oauth_utils = __esm({
|
|
|
377485
377547
|
}
|
|
377486
377548
|
const authServerUrl = resourceMetadata.authorization_servers[0];
|
|
377487
377549
|
const authServerMetadata = await this.discoverAuthorizationServerMetadata(authServerUrl, {
|
|
377488
|
-
allowLoopback
|
|
377550
|
+
allowLoopback,
|
|
377551
|
+
...allowPrivateNetwork !== void 0 ? { allowPrivateNetwork } : {}
|
|
377489
377552
|
});
|
|
377490
377553
|
if (authServerMetadata) {
|
|
377491
377554
|
return this.metadataToOAuthConfig(authServerMetadata);
|
|
@@ -381423,7 +381486,7 @@ async function parseTokenEndpointResponse(response, operationName, defaultErrorC
|
|
|
381423
381486
|
scope: scope || void 0
|
|
381424
381487
|
};
|
|
381425
381488
|
}
|
|
381426
|
-
async function exchangeCodeForToken(config2, code, codeVerifier, redirectPort, resource) {
|
|
381489
|
+
async function exchangeCodeForToken(config2, code, codeVerifier, redirectPort, resource, options) {
|
|
381427
381490
|
const redirectUri = getRedirectUri(config2, redirectPort);
|
|
381428
381491
|
const params = new URLSearchParams({
|
|
381429
381492
|
grant_type: "authorization_code",
|
|
@@ -381443,7 +381506,8 @@ async function exchangeCodeForToken(config2, code, codeVerifier, redirectPort, r
|
|
|
381443
381506
|
}
|
|
381444
381507
|
const allowLoopback = resource ? isLoopbackUrl(resource) : isLoopbackUrl(config2.tokenUrl);
|
|
381445
381508
|
const validatedTokenUrl = await validateOAuthEndpointUrl(config2.tokenUrl, {
|
|
381446
|
-
allowLoopback
|
|
381509
|
+
allowLoopback,
|
|
381510
|
+
allowPrivateNetwork: options?.allowPrivateNetwork
|
|
381447
381511
|
});
|
|
381448
381512
|
const response = await fetch(validatedTokenUrl, {
|
|
381449
381513
|
method: "POST",
|
|
@@ -381455,7 +381519,7 @@ async function exchangeCodeForToken(config2, code, codeVerifier, redirectPort, r
|
|
|
381455
381519
|
});
|
|
381456
381520
|
return parseTokenEndpointResponse(response, "Token exchange", "no_access_token");
|
|
381457
381521
|
}
|
|
381458
|
-
async function refreshAccessToken(config2, refreshToken, tokenUrl, resource) {
|
|
381522
|
+
async function refreshAccessToken(config2, refreshToken, tokenUrl, resource, options) {
|
|
381459
381523
|
const params = new URLSearchParams({
|
|
381460
381524
|
grant_type: "refresh_token",
|
|
381461
381525
|
refresh_token: refreshToken,
|
|
@@ -381475,7 +381539,8 @@ async function refreshAccessToken(config2, refreshToken, tokenUrl, resource) {
|
|
|
381475
381539
|
}
|
|
381476
381540
|
const allowLoopback = resource ? isLoopbackUrl(resource) : isLoopbackUrl(tokenUrl);
|
|
381477
381541
|
const validatedTokenUrl = await validateOAuthEndpointUrl(tokenUrl, {
|
|
381478
|
-
allowLoopback
|
|
381542
|
+
allowLoopback,
|
|
381543
|
+
allowPrivateNetwork: options?.allowPrivateNetwork
|
|
381479
381544
|
});
|
|
381480
381545
|
const response = await fetch(validatedTokenUrl, {
|
|
381481
381546
|
method: "POST",
|
|
@@ -385582,7 +385647,7 @@ function isNumberArray(value) {
|
|
|
385582
385647
|
}
|
|
385583
385648
|
function isTaskArray(value) {
|
|
385584
385649
|
return Array.isArray(value) && value.every((item) => {
|
|
385585
|
-
if (!
|
|
385650
|
+
if (!isRecord2(item))
|
|
385586
385651
|
return false;
|
|
385587
385652
|
const id = item["id"];
|
|
385588
385653
|
const desc = item["description"];
|
|
@@ -385599,7 +385664,7 @@ function isSnapshotState(text) {
|
|
|
385599
385664
|
}
|
|
385600
385665
|
try {
|
|
385601
385666
|
const parsed = JSON.parse(trimmed2);
|
|
385602
|
-
if (!
|
|
385667
|
+
if (!isRecord2(parsed))
|
|
385603
385668
|
return false;
|
|
385604
385669
|
const isSnap = Array.isArray(parsed["active_tasks"]) && Array.isArray(parsed["discovered_facts"]) && Array.isArray(parsed["constraints_and_preferences"]) && Array.isArray(parsed["recent_arc"]);
|
|
385605
385670
|
if (!isSnap) {
|
|
@@ -385653,7 +385718,7 @@ var init_snapshotGenerator = __esm({
|
|
|
385653
385718
|
if (previousStateJson) {
|
|
385654
385719
|
try {
|
|
385655
385720
|
const parsed = JSON.parse(previousStateJson);
|
|
385656
|
-
if (
|
|
385721
|
+
if (isRecord2(parsed)) {
|
|
385657
385722
|
let loadedArc = [];
|
|
385658
385723
|
if (isStringArray(parsed["recent_arc"])) {
|
|
385659
385724
|
loadedArc = parsed["recent_arc"];
|
|
@@ -385750,7 +385815,7 @@ ${formatNodesForLlm(nodes)}`;
|
|
|
385750
385815
|
promptId: this.env.promptId,
|
|
385751
385816
|
abortSignal: new AbortController().signal
|
|
385752
385817
|
});
|
|
385753
|
-
if (
|
|
385818
|
+
if (isRecord2(result2)) {
|
|
385754
385819
|
patch = result2;
|
|
385755
385820
|
}
|
|
385756
385821
|
} catch {
|
|
@@ -385782,7 +385847,7 @@ ${formatNodesForLlm(nodes)}`;
|
|
|
385782
385847
|
const newTasks = patch["new_tasks"];
|
|
385783
385848
|
if (Array.isArray(newTasks)) {
|
|
385784
385849
|
for (const t3 of newTasks) {
|
|
385785
|
-
if (
|
|
385850
|
+
if (isRecord2(t3)) {
|
|
385786
385851
|
const desc = t3["description"];
|
|
385787
385852
|
if (typeof desc === "string" && desc) {
|
|
385788
385853
|
newState.active_tasks.push({
|
|
@@ -395716,11 +395781,11 @@ var init_agent_tool = __esm({
|
|
|
395716
395781
|
}
|
|
395717
395782
|
mapParams(prompt, schema2) {
|
|
395718
395783
|
const schemaObj = schema2;
|
|
395719
|
-
if (!
|
|
395784
|
+
if (!isRecord2(schemaObj)) {
|
|
395720
395785
|
return { prompt };
|
|
395721
395786
|
}
|
|
395722
395787
|
const properties = schemaObj["properties"];
|
|
395723
|
-
if (
|
|
395788
|
+
if (isRecord2(properties)) {
|
|
395724
395789
|
const keys = Object.keys(properties);
|
|
395725
395790
|
if (keys.length === 1) {
|
|
395726
395791
|
return { [keys[0]]: prompt };
|
|
@@ -395802,11 +395867,11 @@ var init_agent_tool = __esm({
|
|
|
395802
395867
|
return agentArgs;
|
|
395803
395868
|
}
|
|
395804
395869
|
const schemaObj = this.definition.inputConfig.inputSchema;
|
|
395805
|
-
if (!
|
|
395870
|
+
if (!isRecord2(schemaObj)) {
|
|
395806
395871
|
return agentArgs;
|
|
395807
395872
|
}
|
|
395808
395873
|
const properties = schemaObj["properties"];
|
|
395809
|
-
if (
|
|
395874
|
+
if (isRecord2(properties)) {
|
|
395810
395875
|
const keys = Object.keys(properties);
|
|
395811
395876
|
const primaryKey = keys.length === 1 ? keys[0] : "prompt";
|
|
395812
395877
|
const value = agentArgs[primaryKey];
|
|
@@ -396344,8 +396409,8 @@ ${reminder}`;
|
|
|
396344
396409
|
throw new Error("Invalid response from Local Gemini API: No text found");
|
|
396345
396410
|
}
|
|
396346
396411
|
const parsed = JSON.parse(result2.text);
|
|
396347
|
-
const
|
|
396348
|
-
if (
|
|
396412
|
+
const isRecord4 = (val) => typeof val === "object" && val !== null && !Array.isArray(val);
|
|
396413
|
+
if (isRecord4(parsed)) {
|
|
396349
396414
|
return parsed;
|
|
396350
396415
|
}
|
|
396351
396416
|
throw new Error("Invalid JSON response format from Local LLM");
|
|
@@ -401411,7 +401476,7 @@ Please fix the configuration file and try again.`);
|
|
|
401411
401476
|
function parseTrustedFoldersJson(content) {
|
|
401412
401477
|
return JSON.parse((0, import_strip_json_comments.default)(content));
|
|
401413
401478
|
}
|
|
401414
|
-
function
|
|
401479
|
+
function isRecord3(value) {
|
|
401415
401480
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
401416
401481
|
}
|
|
401417
401482
|
function getRealPath(location) {
|
|
@@ -401438,7 +401503,7 @@ function loadTrustedFolders() {
|
|
|
401438
401503
|
if (fs72.existsSync(userPath)) {
|
|
401439
401504
|
const content = fs72.readFileSync(userPath, "utf-8");
|
|
401440
401505
|
const parsed = parseTrustedFoldersJson(content);
|
|
401441
|
-
if (!
|
|
401506
|
+
if (!isRecord3(parsed)) {
|
|
401442
401507
|
errors.push({
|
|
401443
401508
|
message: "Trusted folders file is not a valid JSON object.",
|
|
401444
401509
|
path: userPath
|
|
@@ -401582,7 +401647,7 @@ Please fix the file manually before trying to update it.`);
|
|
|
401582
401647
|
const config2 = {};
|
|
401583
401648
|
try {
|
|
401584
401649
|
const parsed = parseTrustedFoldersJson(content);
|
|
401585
|
-
if (
|
|
401650
|
+
if (isRecord3(parsed)) {
|
|
401586
401651
|
for (const [rawPath, value] of Object.entries(parsed)) {
|
|
401587
401652
|
if (isTrustLevel(value)) {
|
|
401588
401653
|
config2[rawPath] = value;
|
|
@@ -405457,7 +405522,7 @@ var init_policy_engine = __esm({
|
|
|
405457
405522
|
let decision;
|
|
405458
405523
|
const toolNamesToTry = toolCall.name ? getToolAliases(toolCall.name) : [];
|
|
405459
405524
|
if (toolCall.name === AGENT_TOOL_NAME) {
|
|
405460
|
-
if (
|
|
405525
|
+
if (isRecord2(toolCall.args)) {
|
|
405461
405526
|
const subagentName = toolCall.args["agent_name"];
|
|
405462
405527
|
if (typeof subagentName === "string") {
|
|
405463
405528
|
toolNamesToTry.push(subagentName);
|
|
@@ -410840,7 +410905,8 @@ var init_oauth_provider = __esm({
|
|
|
410840
410905
|
async registerClient(registrationUrl, config2, redirectPort, mcpServerUrl) {
|
|
410841
410906
|
const allowLoopback = mcpServerUrl ? isLoopbackUrl(mcpServerUrl) : isLoopbackUrl(registrationUrl);
|
|
410842
410907
|
const validatedRegistrationUrl = await validateOAuthEndpointUrl(registrationUrl, {
|
|
410843
|
-
allowLoopback
|
|
410908
|
+
allowLoopback,
|
|
410909
|
+
allowPrivateNetwork: config2.allowPrivateNetwork
|
|
410844
410910
|
});
|
|
410845
410911
|
const redirectUri = getRedirectUri(config2, redirectPort);
|
|
410846
410912
|
const registrationRequest = {
|
|
@@ -410871,10 +410937,10 @@ var init_oauth_provider = __esm({
|
|
|
410871
410937
|
* @param mcpServerUrl The MCP server URL
|
|
410872
410938
|
* @returns OAuth configuration if discovered, null otherwise
|
|
410873
410939
|
*/
|
|
410874
|
-
async discoverOAuthFromMCPServer(mcpServerUrl) {
|
|
410875
|
-
return OAuthUtils.discoverOAuthConfig(mcpServerUrl);
|
|
410940
|
+
async discoverOAuthFromMCPServer(mcpServerUrl, options) {
|
|
410941
|
+
return OAuthUtils.discoverOAuthConfig(mcpServerUrl, options);
|
|
410876
410942
|
}
|
|
410877
|
-
async discoverAuthServerMetadataForRegistration(issuer, mcpServerUrl) {
|
|
410943
|
+
async discoverAuthServerMetadataForRegistration(issuer, mcpServerUrl, options) {
|
|
410878
410944
|
const allowLoopback = mcpServerUrl ? isLoopbackUrl(mcpServerUrl) : isLoopbackUrl(issuer);
|
|
410879
410945
|
const authUrl = new URL9(issuer);
|
|
410880
410946
|
const oidcPatterns = [
|
|
@@ -410910,7 +410976,10 @@ var init_oauth_provider = __esm({
|
|
|
410910
410976
|
let discoveredMetadata = null;
|
|
410911
410977
|
for (const issuerCandidate of attemptedIssuers) {
|
|
410912
410978
|
debugLogger.debug(` Trying issuer URL: ${issuerCandidate}`);
|
|
410913
|
-
const metadata2 = await OAuthUtils.discoverAuthorizationServerMetadata(issuerCandidate, {
|
|
410979
|
+
const metadata2 = await OAuthUtils.discoverAuthorizationServerMetadata(issuerCandidate, {
|
|
410980
|
+
allowLoopback,
|
|
410981
|
+
...options?.allowPrivateNetwork !== void 0 ? { allowPrivateNetwork: options.allowPrivateNetwork } : {}
|
|
410982
|
+
});
|
|
410914
410983
|
if (metadata2) {
|
|
410915
410984
|
selectedIssuer = issuerCandidate;
|
|
410916
410985
|
discoveredMetadata = metadata2;
|
|
@@ -410958,7 +411027,7 @@ var init_oauth_provider = __esm({
|
|
|
410958
411027
|
clientSecret: config2.clientSecret,
|
|
410959
411028
|
scopes: config2.scopes,
|
|
410960
411029
|
audiences: config2.audiences
|
|
410961
|
-
}, refreshToken, tokenUrl, this.buildResourceParam(mcpServerUrl));
|
|
411030
|
+
}, refreshToken, tokenUrl, this.buildResourceParam(mcpServerUrl), { allowPrivateNetwork: config2.allowPrivateNetwork });
|
|
410962
411031
|
}
|
|
410963
411032
|
/**
|
|
410964
411033
|
* Perform the full OAuth authorization code flow with PKCE.
|
|
@@ -410985,7 +411054,7 @@ var init_oauth_provider = __esm({
|
|
|
410985
411054
|
if (response.status === 401 || response.status === 307) {
|
|
410986
411055
|
const wwwAuthenticate = response.headers.get("www-authenticate");
|
|
410987
411056
|
if (wwwAuthenticate) {
|
|
410988
|
-
const discoveredConfig = await OAuthUtils.discoverOAuthFromWWWAuthenticate(wwwAuthenticate, mcpServerUrl);
|
|
411057
|
+
const discoveredConfig = await OAuthUtils.discoverOAuthFromWWWAuthenticate(wwwAuthenticate, mcpServerUrl, { allowPrivateNetwork: config2.allowPrivateNetwork });
|
|
410989
411058
|
if (discoveredConfig) {
|
|
410990
411059
|
config2 = {
|
|
410991
411060
|
...config2,
|
|
@@ -411008,7 +411077,7 @@ var init_oauth_provider = __esm({
|
|
|
411008
411077
|
debugLogger.debug(`Failed to check endpoint for authentication requirements: ${getErrorMessage(error2)}`);
|
|
411009
411078
|
}
|
|
411010
411079
|
if (!config2.authorizationUrl) {
|
|
411011
|
-
const discoveredConfig = await this.discoverOAuthFromMCPServer(mcpServerUrl);
|
|
411080
|
+
const discoveredConfig = await this.discoverOAuthFromMCPServer(mcpServerUrl, { allowPrivateNetwork: config2.allowPrivateNetwork });
|
|
411012
411081
|
if (discoveredConfig) {
|
|
411013
411082
|
config2 = {
|
|
411014
411083
|
...config2,
|
|
@@ -411027,74 +411096,91 @@ var init_oauth_provider = __esm({
|
|
|
411027
411096
|
}
|
|
411028
411097
|
}
|
|
411029
411098
|
}
|
|
411099
|
+
const allowLoopback = mcpServerUrl ? isLoopbackUrl(mcpServerUrl) : (config2.authorizationUrl ? isLoopbackUrl(config2.authorizationUrl) : false) || (config2.tokenUrl ? isLoopbackUrl(config2.tokenUrl) : false);
|
|
411100
|
+
if (config2.authorizationUrl) {
|
|
411101
|
+
await validateOAuthEndpointUrl(config2.authorizationUrl, {
|
|
411102
|
+
allowLoopback,
|
|
411103
|
+
allowPrivateNetwork: config2.allowPrivateNetwork
|
|
411104
|
+
});
|
|
411105
|
+
}
|
|
411106
|
+
if (config2.tokenUrl) {
|
|
411107
|
+
await validateOAuthEndpointUrl(config2.tokenUrl, {
|
|
411108
|
+
allowLoopback,
|
|
411109
|
+
allowPrivateNetwork: config2.allowPrivateNetwork
|
|
411110
|
+
});
|
|
411111
|
+
}
|
|
411030
411112
|
const pkceParams = generatePKCEParams();
|
|
411031
411113
|
const preferredPort = getPortFromUrl(config2.redirectUri);
|
|
411032
411114
|
debugLogger.debug(`Starting callback server for "${serverName}" (expected issuer: ${config2.issuer || "none"})...`);
|
|
411033
411115
|
const requireIssInResponse = config2.authorizationResponseIssParameterSupported ?? Boolean(config2.issuer);
|
|
411034
411116
|
const callbackServer = startCallbackServer(pkceParams.state, preferredPort, config2.issuer, requireIssInResponse);
|
|
411035
|
-
|
|
411036
|
-
debugLogger.debug(`Callback server listening on port ${redirectPort}`);
|
|
411037
|
-
if (!config2.clientId) {
|
|
411038
|
-
let registrationUrl = config2.registrationUrl;
|
|
411039
|
-
if (!registrationUrl) {
|
|
411040
|
-
if (!config2.issuer) {
|
|
411041
|
-
throw new Error("Cannot perform dynamic registration without issuer");
|
|
411042
|
-
}
|
|
411043
|
-
debugLogger.debug("\u2192 Attempting dynamic client registration...");
|
|
411044
|
-
const { metadata: authServerMetadata } = await this.discoverAuthServerMetadataForRegistration(config2.issuer, mcpServerUrl);
|
|
411045
|
-
registrationUrl = authServerMetadata.registration_endpoint;
|
|
411046
|
-
}
|
|
411047
|
-
if (registrationUrl) {
|
|
411048
|
-
const clientRegistration = await this.registerClient(registrationUrl, config2, redirectPort, mcpServerUrl);
|
|
411049
|
-
config2.clientId = clientRegistration.client_id;
|
|
411050
|
-
if (clientRegistration.client_secret) {
|
|
411051
|
-
config2.clientSecret = clientRegistration.client_secret;
|
|
411052
|
-
}
|
|
411053
|
-
debugLogger.debug("\u2713 Dynamic client registration successful");
|
|
411054
|
-
} else {
|
|
411055
|
-
throw new Error("No client ID provided and dynamic registration not supported");
|
|
411056
|
-
}
|
|
411057
|
-
}
|
|
411058
|
-
if (!config2.clientId || !config2.authorizationUrl || !config2.tokenUrl) {
|
|
411059
|
-
throw new Error("Missing required OAuth configuration after discovery and registration");
|
|
411060
|
-
}
|
|
411061
|
-
const allowLoopback = mcpServerUrl ? isLoopbackUrl(mcpServerUrl) : (config2.authorizationUrl ? isLoopbackUrl(config2.authorizationUrl) : false) || (config2.tokenUrl ? isLoopbackUrl(config2.tokenUrl) : false);
|
|
411062
|
-
await validateOAuthEndpointUrl(config2.authorizationUrl, {
|
|
411063
|
-
allowLoopback
|
|
411064
|
-
});
|
|
411065
|
-
await validateOAuthEndpointUrl(config2.tokenUrl, {
|
|
411066
|
-
allowLoopback
|
|
411117
|
+
callbackServer.response.catch(() => {
|
|
411067
411118
|
});
|
|
411068
|
-
|
|
411069
|
-
|
|
411070
|
-
|
|
411071
|
-
|
|
411072
|
-
|
|
411073
|
-
|
|
411074
|
-
|
|
411075
|
-
|
|
411076
|
-
|
|
411077
|
-
|
|
411078
|
-
|
|
411079
|
-
|
|
411080
|
-
|
|
411081
|
-
|
|
411082
|
-
|
|
411083
|
-
|
|
411119
|
+
let code;
|
|
411120
|
+
let redirectPort;
|
|
411121
|
+
let flowConfig;
|
|
411122
|
+
let resource;
|
|
411123
|
+
try {
|
|
411124
|
+
redirectPort = await callbackServer.port;
|
|
411125
|
+
debugLogger.debug(`Callback server listening on port ${redirectPort}`);
|
|
411126
|
+
if (!config2.clientId) {
|
|
411127
|
+
let registrationUrl = config2.registrationUrl;
|
|
411128
|
+
if (!registrationUrl) {
|
|
411129
|
+
if (!config2.issuer) {
|
|
411130
|
+
throw new Error("Cannot perform dynamic registration without issuer");
|
|
411131
|
+
}
|
|
411132
|
+
debugLogger.debug("\u2192 Attempting dynamic client registration...");
|
|
411133
|
+
const { metadata: authServerMetadata } = await this.discoverAuthServerMetadataForRegistration(config2.issuer, mcpServerUrl, { allowPrivateNetwork: config2.allowPrivateNetwork });
|
|
411134
|
+
registrationUrl = authServerMetadata.registration_endpoint;
|
|
411135
|
+
}
|
|
411136
|
+
if (registrationUrl) {
|
|
411137
|
+
const clientRegistration = await this.registerClient(registrationUrl, config2, redirectPort, mcpServerUrl);
|
|
411138
|
+
config2.clientId = clientRegistration.client_id;
|
|
411139
|
+
if (clientRegistration.client_secret) {
|
|
411140
|
+
config2.clientSecret = clientRegistration.client_secret;
|
|
411141
|
+
}
|
|
411142
|
+
debugLogger.debug("\u2713 Dynamic client registration successful");
|
|
411143
|
+
} else {
|
|
411144
|
+
throw new Error("No client ID provided and dynamic registration not supported");
|
|
411145
|
+
}
|
|
411146
|
+
}
|
|
411147
|
+
if (!config2.clientId || !config2.authorizationUrl || !config2.tokenUrl) {
|
|
411148
|
+
throw new Error("Missing required OAuth configuration after discovery and registration");
|
|
411149
|
+
}
|
|
411150
|
+
flowConfig = {
|
|
411151
|
+
clientId: config2.clientId,
|
|
411152
|
+
clientSecret: config2.clientSecret,
|
|
411153
|
+
authorizationUrl: config2.authorizationUrl,
|
|
411154
|
+
tokenUrl: config2.tokenUrl,
|
|
411155
|
+
scopes: config2.scopes,
|
|
411156
|
+
audiences: config2.audiences,
|
|
411157
|
+
redirectUri: config2.redirectUri
|
|
411158
|
+
};
|
|
411159
|
+
resource = this.buildResourceParam(mcpServerUrl);
|
|
411160
|
+
const authUrl = buildAuthorizationUrl(flowConfig, pkceParams, redirectPort, resource);
|
|
411161
|
+
const userConsent = await getConsentForOauth(`Authentication required for MCP Server: '${serverName}.'`);
|
|
411162
|
+
if (!userConsent) {
|
|
411163
|
+
throw new FatalCancellationError("Authentication cancelled by user.");
|
|
411164
|
+
}
|
|
411165
|
+
displayMessage(`\u2192 Opening your browser for OAuth sign-in...
|
|
411084
411166
|
|
|
411085
411167
|
If the browser does not open, copy and paste this URL into your browser:
|
|
411086
411168
|
${authUrl}
|
|
411087
411169
|
|
|
411088
411170
|
\u{1F4A1} TIP: Triple-click to select the entire URL, then copy and paste it into your browser.
|
|
411089
411171
|
\u26A0\uFE0F Make sure to copy the COMPLETE URL - it may wrap across multiple lines.`);
|
|
411090
|
-
|
|
411091
|
-
|
|
411172
|
+
try {
|
|
411173
|
+
await openBrowserSecurely(authUrl);
|
|
411174
|
+
} catch (error2) {
|
|
411175
|
+
debugLogger.warn("Failed to open browser automatically:", getErrorMessage(error2));
|
|
411176
|
+
}
|
|
411177
|
+
({ code } = await callbackServer.response);
|
|
411092
411178
|
} catch (error2) {
|
|
411093
|
-
|
|
411179
|
+
callbackServer.cancel?.(error2 instanceof Error ? error2 : void 0);
|
|
411180
|
+
throw error2;
|
|
411094
411181
|
}
|
|
411095
|
-
const { code } = await callbackServer.response;
|
|
411096
411182
|
debugLogger.debug("\u2713 Authorization code received, exchanging for tokens...");
|
|
411097
|
-
const tokenResponse = await exchangeCodeForToken(flowConfig, code, pkceParams.codeVerifier, redirectPort, resource);
|
|
411183
|
+
const tokenResponse = await exchangeCodeForToken(flowConfig, code, pkceParams.codeVerifier, redirectPort, resource, { allowPrivateNetwork: config2.allowPrivateNetwork });
|
|
411098
411184
|
if (!tokenResponse.access_token) {
|
|
411099
411185
|
throw new Error("No access token received from token endpoint");
|
|
411100
411186
|
}
|
|
@@ -411247,7 +411333,7 @@ var init_stored_token_provider = __esm({
|
|
|
411247
411333
|
if (this.isCachedTokenValid()) {
|
|
411248
411334
|
return this.cachedToken;
|
|
411249
411335
|
}
|
|
411250
|
-
const oauthConfig = this.serverConfig.oauth
|
|
411336
|
+
const oauthConfig = this.serverConfig.oauth ?? {};
|
|
411251
411337
|
const tokenMeta = await this.oauthProvider.getValidTokenWithMetadata(this.serverName, oauthConfig);
|
|
411252
411338
|
if (!tokenMeta?.accessToken) {
|
|
411253
411339
|
this.cachedToken = void 0;
|
|
@@ -411414,10 +411500,13 @@ async function handleAutomaticOAuth(mcpServerName, mcpServerConfig, wwwAuthentic
|
|
|
411414
411500
|
try {
|
|
411415
411501
|
debugLogger.log(`\u{1F510} '${mcpServerName}' requires OAuth authentication`);
|
|
411416
411502
|
const serverUrl = mcpServerConfig.httpUrl || mcpServerConfig.url;
|
|
411417
|
-
|
|
411503
|
+
const discoveryOptions = {
|
|
411504
|
+
allowPrivateNetwork: mcpServerConfig.oauth?.allowPrivateNetwork
|
|
411505
|
+
};
|
|
411506
|
+
let oauthConfig = await OAuthUtils.discoverOAuthFromWWWAuthenticate(wwwAuthenticate, serverUrl, discoveryOptions);
|
|
411418
411507
|
if (!oauthConfig && hasNetworkTransport(mcpServerConfig)) {
|
|
411419
411508
|
const baseUrl = OAuthUtils.extractBaseUrl(serverUrl);
|
|
411420
|
-
oauthConfig = await OAuthUtils.discoverOAuthConfig(baseUrl);
|
|
411509
|
+
oauthConfig = await OAuthUtils.discoverOAuthConfig(baseUrl, discoveryOptions);
|
|
411421
411510
|
}
|
|
411422
411511
|
if (!oauthConfig) {
|
|
411423
411512
|
cliConfig.emitMcpDiagnostic("error", `Could not configure OAuth for '${mcpServerName}' - please authenticate manually with /mcp auth ${mcpServerName}`, void 0, mcpServerName);
|
|
@@ -411429,7 +411518,8 @@ async function handleAutomaticOAuth(mcpServerName, mcpServerConfig, wwwAuthentic
|
|
|
411429
411518
|
issuer: oauthConfig.issuer,
|
|
411430
411519
|
tokenUrl: oauthConfig.tokenUrl,
|
|
411431
411520
|
scopes: oauthConfig.scopes || [],
|
|
411432
|
-
authorizationResponseIssParameterSupported: mcpServerConfig.oauth?.authorizationResponseIssParameterSupported ?? oauthConfig.authorizationResponseIssParameterSupported
|
|
411521
|
+
authorizationResponseIssParameterSupported: mcpServerConfig.oauth?.authorizationResponseIssParameterSupported ?? oauthConfig.authorizationResponseIssParameterSupported,
|
|
411522
|
+
allowPrivateNetwork: mcpServerConfig.oauth?.allowPrivateNetwork
|
|
411433
411523
|
};
|
|
411434
411524
|
debugLogger.log(`Starting OAuth authentication for server '${mcpServerName}'...`);
|
|
411435
411525
|
const authProvider = new MCPOAuthProvider(new MCPOAuthTokenStorage());
|
|
@@ -411631,15 +411721,16 @@ async function invokeMcpPrompt(mcpServerName, mcpClient, promptName, promptParam
|
|
|
411631
411721
|
function hasNetworkTransport(config2) {
|
|
411632
411722
|
return !!(config2.url || config2.httpUrl);
|
|
411633
411723
|
}
|
|
411634
|
-
async function getStoredOAuthToken(serverName) {
|
|
411724
|
+
async function getStoredOAuthToken(serverName, oauthConfig) {
|
|
411635
411725
|
const tokenStorage = new MCPOAuthTokenStorage();
|
|
411636
411726
|
const credentials3 = await tokenStorage.getCredentials(serverName);
|
|
411637
411727
|
if (!credentials3)
|
|
411638
411728
|
return null;
|
|
411639
411729
|
const authProvider = new MCPOAuthProvider(tokenStorage);
|
|
411640
411730
|
return authProvider.getValidToken(serverName, {
|
|
411731
|
+
...oauthConfig,
|
|
411641
411732
|
// Pass client ID if available
|
|
411642
|
-
clientId: credentials3.clientId
|
|
411733
|
+
clientId: oauthConfig?.clientId ?? credentials3.clientId
|
|
411643
411734
|
});
|
|
411644
411735
|
}
|
|
411645
411736
|
function createSSETransportWithAuth(config2, accessToken) {
|
|
@@ -411659,8 +411750,8 @@ async function connectWithSSETransport(client, config2, accessToken) {
|
|
|
411659
411750
|
timeout: config2.timeout ?? MCP_DEFAULT_TIMEOUT_MSEC
|
|
411660
411751
|
});
|
|
411661
411752
|
}
|
|
411662
|
-
async function showAuthRequiredMessage(serverName, cliConfig) {
|
|
411663
|
-
const hasRejectedToken = !!await getStoredOAuthToken(serverName);
|
|
411753
|
+
async function showAuthRequiredMessage(serverName, cliConfig, oauthConfig) {
|
|
411754
|
+
const hasRejectedToken = !!await getStoredOAuthToken(serverName, oauthConfig);
|
|
411664
411755
|
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}`;
|
|
411665
411756
|
cliConfig.emitMcpDiagnostic("info", message, void 0, serverName);
|
|
411666
411757
|
throw new UnauthorizedError(message);
|
|
@@ -411760,7 +411851,7 @@ async function connectToMcpServer(clientVersion, mcpServerName, mcpServerConfig,
|
|
|
411760
411851
|
const logMessage = httpReturned404 ? `HTTP returned 404, trying SSE transport...` : `HTTP connection failed, attempting SSE fallback...`;
|
|
411761
411852
|
debugLogger.log(`MCP server '${mcpServerName}': ${logMessage}`);
|
|
411762
411853
|
try {
|
|
411763
|
-
await connectWithSSETransport(mcpClient, mcpServerConfig, await getStoredOAuthToken(mcpServerName));
|
|
411854
|
+
await connectWithSSETransport(mcpClient, mcpServerConfig, await getStoredOAuthToken(mcpServerName, mcpServerConfig.oauth));
|
|
411764
411855
|
debugLogger.log(`MCP server '${mcpServerName}': Successfully connected using SSE transport.`);
|
|
411765
411856
|
return mcpClient;
|
|
411766
411857
|
} catch (sseFallbackError) {
|
|
@@ -411778,7 +411869,7 @@ async function connectToMcpServer(clientVersion, mcpServerName, mcpServerConfig,
|
|
|
411778
411869
|
mcpServerRequiresOAuth.set(mcpServerName, true);
|
|
411779
411870
|
const shouldTriggerOAuth = mcpServerConfig.oauth?.enabled;
|
|
411780
411871
|
if (!shouldTriggerOAuth) {
|
|
411781
|
-
await showAuthRequiredMessage(mcpServerName, cliConfig);
|
|
411872
|
+
await showAuthRequiredMessage(mcpServerName, cliConfig, mcpServerConfig.oauth);
|
|
411782
411873
|
}
|
|
411783
411874
|
const errorString = String(error2);
|
|
411784
411875
|
let wwwAuthenticate = extractWWWAuthenticateHeader(errorString);
|
|
@@ -411819,7 +411910,7 @@ async function connectToMcpServer(clientVersion, mcpServerName, mcpServerConfig,
|
|
|
411819
411910
|
debugLogger.log(`Received 401 with www-authenticate header: ${wwwAuthenticate}`);
|
|
411820
411911
|
const oauthSuccess = await handleAutomaticOAuth(mcpServerName, mcpServerConfig, wwwAuthenticate, cliConfig);
|
|
411821
411912
|
if (oauthSuccess) {
|
|
411822
|
-
const accessToken = await getStoredOAuthToken(mcpServerName);
|
|
411913
|
+
const accessToken = await getStoredOAuthToken(mcpServerName, mcpServerConfig.oauth);
|
|
411823
411914
|
if (!accessToken) {
|
|
411824
411915
|
throw new Error(`Failed to get OAuth token for server '${mcpServerName}'`);
|
|
411825
411916
|
}
|
|
@@ -411831,13 +411922,16 @@ async function connectToMcpServer(clientVersion, mcpServerName, mcpServerConfig,
|
|
|
411831
411922
|
} else {
|
|
411832
411923
|
const shouldTryDiscovery = mcpServerConfig.oauth?.enabled;
|
|
411833
411924
|
if (!shouldTryDiscovery) {
|
|
411834
|
-
await showAuthRequiredMessage(mcpServerName, cliConfig);
|
|
411925
|
+
await showAuthRequiredMessage(mcpServerName, cliConfig, mcpServerConfig.oauth);
|
|
411835
411926
|
}
|
|
411836
411927
|
debugLogger.log(`\u{1F50D} Attempting OAuth discovery for '${mcpServerName}'...`);
|
|
411837
411928
|
if (hasNetworkTransport(mcpServerConfig)) {
|
|
411838
411929
|
const serverUrl = new URL(mcpServerConfig.httpUrl || mcpServerConfig.url);
|
|
411839
411930
|
const baseUrl = `${serverUrl.protocol}//${serverUrl.host}`;
|
|
411840
|
-
const
|
|
411931
|
+
const discoveryOptions = {
|
|
411932
|
+
allowPrivateNetwork: mcpServerConfig.oauth?.allowPrivateNetwork
|
|
411933
|
+
};
|
|
411934
|
+
const oauthConfig = await OAuthUtils.discoverOAuthConfig(baseUrl, discoveryOptions);
|
|
411841
411935
|
if (oauthConfig) {
|
|
411842
411936
|
debugLogger.log(`Discovered OAuth configuration from base URL for server '${mcpServerName}'`);
|
|
411843
411937
|
const oauthAuthConfig = {
|
|
@@ -411846,13 +411940,14 @@ async function connectToMcpServer(clientVersion, mcpServerName, mcpServerConfig,
|
|
|
411846
411940
|
issuer: oauthConfig.issuer,
|
|
411847
411941
|
tokenUrl: oauthConfig.tokenUrl,
|
|
411848
411942
|
scopes: oauthConfig.scopes || [],
|
|
411849
|
-
authorizationResponseIssParameterSupported: mcpServerConfig.oauth?.authorizationResponseIssParameterSupported ?? oauthConfig.authorizationResponseIssParameterSupported
|
|
411943
|
+
authorizationResponseIssParameterSupported: mcpServerConfig.oauth?.authorizationResponseIssParameterSupported ?? oauthConfig.authorizationResponseIssParameterSupported,
|
|
411944
|
+
allowPrivateNetwork: mcpServerConfig.oauth?.allowPrivateNetwork
|
|
411850
411945
|
};
|
|
411851
411946
|
const authServerUrl = mcpServerConfig.httpUrl || mcpServerConfig.url;
|
|
411852
411947
|
debugLogger.log(`Starting OAuth authentication for server '${mcpServerName}'...`);
|
|
411853
411948
|
const authProvider = new MCPOAuthProvider(new MCPOAuthTokenStorage());
|
|
411854
411949
|
await authProvider.authenticate(mcpServerName, oauthAuthConfig, authServerUrl);
|
|
411855
|
-
const accessToken = await getStoredOAuthToken(mcpServerName);
|
|
411950
|
+
const accessToken = await getStoredOAuthToken(mcpServerName, mcpServerConfig.oauth);
|
|
411856
411951
|
if (!accessToken) {
|
|
411857
411952
|
throw new Error(`Failed to get OAuth token for server '${mcpServerName}'`);
|
|
411858
411953
|
}
|