mcp-remote 0.1.18 → 0.1.20
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/{chunk-OXNXVROF.js → chunk-EP7LWBXW.js} +393 -164
- package/dist/client.js +1 -1
- package/dist/proxy.js +4 -4
- package/package.json +2 -2
|
@@ -10301,7 +10301,7 @@ var z = /* @__PURE__ */ Object.freeze({
|
|
|
10301
10301
|
ZodError
|
|
10302
10302
|
});
|
|
10303
10303
|
|
|
10304
|
-
// node_modules/.pnpm/@modelcontextprotocol+sdk@
|
|
10304
|
+
// node_modules/.pnpm/@modelcontextprotocol+sdk@1.17.4/node_modules/@modelcontextprotocol/sdk/dist/esm/types.js
|
|
10305
10305
|
var LATEST_PROTOCOL_VERSION = "2025-06-18";
|
|
10306
10306
|
var SUPPORTED_PROTOCOL_VERSIONS = [
|
|
10307
10307
|
LATEST_PROTOCOL_VERSION,
|
|
@@ -10586,11 +10586,19 @@ var TextResourceContentsSchema = ResourceContentsSchema.extend({
|
|
|
10586
10586
|
*/
|
|
10587
10587
|
text: z.string()
|
|
10588
10588
|
});
|
|
10589
|
+
var Base64Schema = z.string().refine((val) => {
|
|
10590
|
+
try {
|
|
10591
|
+
atob(val);
|
|
10592
|
+
return true;
|
|
10593
|
+
} catch (_a) {
|
|
10594
|
+
return false;
|
|
10595
|
+
}
|
|
10596
|
+
}, { message: "Invalid Base64 string" });
|
|
10589
10597
|
var BlobResourceContentsSchema = ResourceContentsSchema.extend({
|
|
10590
10598
|
/**
|
|
10591
10599
|
* A base64-encoded string representing the binary data of the item.
|
|
10592
10600
|
*/
|
|
10593
|
-
blob:
|
|
10601
|
+
blob: Base64Schema
|
|
10594
10602
|
});
|
|
10595
10603
|
var ResourceSchema = BaseMetadataSchema.extend({
|
|
10596
10604
|
/**
|
|
@@ -10753,7 +10761,7 @@ var ImageContentSchema = z.object({
|
|
|
10753
10761
|
/**
|
|
10754
10762
|
* The base64-encoded image data.
|
|
10755
10763
|
*/
|
|
10756
|
-
data:
|
|
10764
|
+
data: Base64Schema,
|
|
10757
10765
|
/**
|
|
10758
10766
|
* The MIME type of the image. Different providers may support different image types.
|
|
10759
10767
|
*/
|
|
@@ -10769,7 +10777,7 @@ var AudioContentSchema = z.object({
|
|
|
10769
10777
|
/**
|
|
10770
10778
|
* The base64-encoded audio data.
|
|
10771
10779
|
*/
|
|
10772
|
-
data:
|
|
10780
|
+
data: Base64Schema,
|
|
10773
10781
|
/**
|
|
10774
10782
|
* The MIME type of the audio. Different providers may support different audio types.
|
|
10775
10783
|
*/
|
|
@@ -11096,7 +11104,7 @@ var ElicitResultSchema = ResultSchema.extend({
|
|
|
11096
11104
|
/**
|
|
11097
11105
|
* The user's response action.
|
|
11098
11106
|
*/
|
|
11099
|
-
action: z.enum(["accept", "
|
|
11107
|
+
action: z.enum(["accept", "decline", "cancel"]),
|
|
11100
11108
|
/**
|
|
11101
11109
|
* The collected user input content (only present if action is "accept").
|
|
11102
11110
|
*/
|
|
@@ -11244,7 +11252,7 @@ var McpError = class extends Error {
|
|
|
11244
11252
|
}
|
|
11245
11253
|
};
|
|
11246
11254
|
|
|
11247
|
-
// node_modules/.pnpm/@modelcontextprotocol+sdk@
|
|
11255
|
+
// node_modules/.pnpm/@modelcontextprotocol+sdk@1.17.4/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/protocol.js
|
|
11248
11256
|
var DEFAULT_REQUEST_TIMEOUT_MSEC = 6e4;
|
|
11249
11257
|
var Protocol = class {
|
|
11250
11258
|
constructor(_options) {
|
|
@@ -11256,6 +11264,7 @@ var Protocol = class {
|
|
|
11256
11264
|
this._responseHandlers = /* @__PURE__ */ new Map();
|
|
11257
11265
|
this._progressHandlers = /* @__PURE__ */ new Map();
|
|
11258
11266
|
this._timeoutInfo = /* @__PURE__ */ new Map();
|
|
11267
|
+
this._pendingDebouncedNotifications = /* @__PURE__ */ new Set();
|
|
11259
11268
|
this.setNotificationHandler(CancelledNotificationSchema, (notification) => {
|
|
11260
11269
|
const controller = this._requestHandlerAbortControllers.get(notification.params.requestId);
|
|
11261
11270
|
controller === null || controller === void 0 ? void 0 : controller.abort(notification.params.reason);
|
|
@@ -11337,6 +11346,7 @@ var Protocol = class {
|
|
|
11337
11346
|
const responseHandlers = this._responseHandlers;
|
|
11338
11347
|
this._responseHandlers = /* @__PURE__ */ new Map();
|
|
11339
11348
|
this._progressHandlers.clear();
|
|
11349
|
+
this._pendingDebouncedNotifications.clear();
|
|
11340
11350
|
this._transport = void 0;
|
|
11341
11351
|
(_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
11342
11352
|
const error = new McpError(ErrorCode.ConnectionClosed, "Connection closed");
|
|
@@ -11357,10 +11367,11 @@ var Protocol = class {
|
|
|
11357
11367
|
Promise.resolve().then(() => handler(notification)).catch((error) => this._onerror(new Error(`Uncaught error in notification handler: ${error}`)));
|
|
11358
11368
|
}
|
|
11359
11369
|
_onrequest(request, extra) {
|
|
11360
|
-
var _a, _b
|
|
11370
|
+
var _a, _b;
|
|
11361
11371
|
const handler = (_a = this._requestHandlers.get(request.method)) !== null && _a !== void 0 ? _a : this.fallbackRequestHandler;
|
|
11372
|
+
const capturedTransport = this._transport;
|
|
11362
11373
|
if (handler === void 0) {
|
|
11363
|
-
|
|
11374
|
+
capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.send({
|
|
11364
11375
|
jsonrpc: "2.0",
|
|
11365
11376
|
id: request.id,
|
|
11366
11377
|
error: {
|
|
@@ -11374,8 +11385,8 @@ var Protocol = class {
|
|
|
11374
11385
|
this._requestHandlerAbortControllers.set(request.id, abortController);
|
|
11375
11386
|
const fullExtra = {
|
|
11376
11387
|
signal: abortController.signal,
|
|
11377
|
-
sessionId:
|
|
11378
|
-
_meta: (
|
|
11388
|
+
sessionId: capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.sessionId,
|
|
11389
|
+
_meta: (_b = request.params) === null || _b === void 0 ? void 0 : _b._meta,
|
|
11379
11390
|
sendNotification: (notification) => this.notification(notification, { relatedRequestId: request.id }),
|
|
11380
11391
|
sendRequest: (r, resultSchema, options) => this.request(r, resultSchema, { ...options, relatedRequestId: request.id }),
|
|
11381
11392
|
authInfo: extra === null || extra === void 0 ? void 0 : extra.authInfo,
|
|
@@ -11383,26 +11394,25 @@ var Protocol = class {
|
|
|
11383
11394
|
requestInfo: extra === null || extra === void 0 ? void 0 : extra.requestInfo
|
|
11384
11395
|
};
|
|
11385
11396
|
Promise.resolve().then(() => handler(request, fullExtra)).then((result) => {
|
|
11386
|
-
var _a2;
|
|
11387
11397
|
if (abortController.signal.aborted) {
|
|
11388
11398
|
return;
|
|
11389
11399
|
}
|
|
11390
|
-
return
|
|
11400
|
+
return capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.send({
|
|
11391
11401
|
result,
|
|
11392
11402
|
jsonrpc: "2.0",
|
|
11393
11403
|
id: request.id
|
|
11394
11404
|
});
|
|
11395
11405
|
}, (error) => {
|
|
11396
|
-
var _a2
|
|
11406
|
+
var _a2;
|
|
11397
11407
|
if (abortController.signal.aborted) {
|
|
11398
11408
|
return;
|
|
11399
11409
|
}
|
|
11400
|
-
return
|
|
11410
|
+
return capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.send({
|
|
11401
11411
|
jsonrpc: "2.0",
|
|
11402
11412
|
id: request.id,
|
|
11403
11413
|
error: {
|
|
11404
11414
|
code: Number.isSafeInteger(error["code"]) ? error["code"] : ErrorCode.InternalError,
|
|
11405
|
-
message: (
|
|
11415
|
+
message: (_a2 = error.message) !== null && _a2 !== void 0 ? _a2 : "Internal error"
|
|
11406
11416
|
}
|
|
11407
11417
|
});
|
|
11408
11418
|
}).catch((error) => this._onerror(new Error(`Failed to send response: ${error}`))).finally(() => {
|
|
@@ -11536,10 +11546,32 @@ var Protocol = class {
|
|
|
11536
11546
|
* Emits a notification, which is a one-way message that does not expect a response.
|
|
11537
11547
|
*/
|
|
11538
11548
|
async notification(notification, options) {
|
|
11549
|
+
var _a, _b;
|
|
11539
11550
|
if (!this._transport) {
|
|
11540
11551
|
throw new Error("Not connected");
|
|
11541
11552
|
}
|
|
11542
11553
|
this.assertNotificationCapability(notification.method);
|
|
11554
|
+
const debouncedMethods = (_b = (_a = this._options) === null || _a === void 0 ? void 0 : _a.debouncedNotificationMethods) !== null && _b !== void 0 ? _b : [];
|
|
11555
|
+
const canDebounce = debouncedMethods.includes(notification.method) && !notification.params && !(options === null || options === void 0 ? void 0 : options.relatedRequestId);
|
|
11556
|
+
if (canDebounce) {
|
|
11557
|
+
if (this._pendingDebouncedNotifications.has(notification.method)) {
|
|
11558
|
+
return;
|
|
11559
|
+
}
|
|
11560
|
+
this._pendingDebouncedNotifications.add(notification.method);
|
|
11561
|
+
Promise.resolve().then(() => {
|
|
11562
|
+
var _a2;
|
|
11563
|
+
this._pendingDebouncedNotifications.delete(notification.method);
|
|
11564
|
+
if (!this._transport) {
|
|
11565
|
+
return;
|
|
11566
|
+
}
|
|
11567
|
+
const jsonrpcNotification2 = {
|
|
11568
|
+
...notification,
|
|
11569
|
+
jsonrpc: "2.0"
|
|
11570
|
+
};
|
|
11571
|
+
(_a2 = this._transport) === null || _a2 === void 0 ? void 0 : _a2.send(jsonrpcNotification2, options).catch((error) => this._onerror(error));
|
|
11572
|
+
});
|
|
11573
|
+
return;
|
|
11574
|
+
}
|
|
11543
11575
|
const jsonrpcNotification = {
|
|
11544
11576
|
...notification,
|
|
11545
11577
|
jsonrpc: "2.0"
|
|
@@ -11598,7 +11630,7 @@ function mergeCapabilities(base, additional) {
|
|
|
11598
11630
|
}, { ...base });
|
|
11599
11631
|
}
|
|
11600
11632
|
|
|
11601
|
-
// node_modules/.pnpm/@modelcontextprotocol+sdk@
|
|
11633
|
+
// node_modules/.pnpm/@modelcontextprotocol+sdk@1.17.4/node_modules/@modelcontextprotocol/sdk/dist/esm/client/index.js
|
|
11602
11634
|
var import_ajv = __toESM(require_ajv(), 1);
|
|
11603
11635
|
var Client = class extends Protocol {
|
|
11604
11636
|
/**
|
|
@@ -11840,7 +11872,7 @@ var Client = class extends Protocol {
|
|
|
11840
11872
|
};
|
|
11841
11873
|
|
|
11842
11874
|
// package.json
|
|
11843
|
-
var version = "0.1.
|
|
11875
|
+
var version = "0.1.20";
|
|
11844
11876
|
|
|
11845
11877
|
// node_modules/.pnpm/pkce-challenge@5.0.0/node_modules/pkce-challenge/dist/index.node.js
|
|
11846
11878
|
var crypto;
|
|
@@ -11881,10 +11913,23 @@ async function pkceChallenge(length) {
|
|
|
11881
11913
|
};
|
|
11882
11914
|
}
|
|
11883
11915
|
|
|
11884
|
-
// node_modules/.pnpm/@modelcontextprotocol+sdk@
|
|
11916
|
+
// node_modules/.pnpm/@modelcontextprotocol+sdk@1.17.4/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/auth.js
|
|
11917
|
+
var SafeUrlSchema = z.string().url().superRefine((val, ctx) => {
|
|
11918
|
+
if (!URL.canParse(val)) {
|
|
11919
|
+
ctx.addIssue({
|
|
11920
|
+
code: z.ZodIssueCode.custom,
|
|
11921
|
+
message: "URL must be parseable",
|
|
11922
|
+
fatal: true
|
|
11923
|
+
});
|
|
11924
|
+
return z.NEVER;
|
|
11925
|
+
}
|
|
11926
|
+
}).refine((url) => {
|
|
11927
|
+
const u = new URL(url);
|
|
11928
|
+
return u.protocol !== "javascript:" && u.protocol !== "data:" && u.protocol !== "vbscript:";
|
|
11929
|
+
}, { message: "URL cannot use javascript:, data:, or vbscript: scheme" });
|
|
11885
11930
|
var OAuthProtectedResourceMetadataSchema = z.object({
|
|
11886
11931
|
resource: z.string().url(),
|
|
11887
|
-
authorization_servers: z.array(
|
|
11932
|
+
authorization_servers: z.array(SafeUrlSchema).optional(),
|
|
11888
11933
|
jwks_uri: z.string().url().optional(),
|
|
11889
11934
|
scopes_supported: z.array(z.string()).optional(),
|
|
11890
11935
|
bearer_methods_supported: z.array(z.string()).optional(),
|
|
@@ -11900,17 +11945,17 @@ var OAuthProtectedResourceMetadataSchema = z.object({
|
|
|
11900
11945
|
}).passthrough();
|
|
11901
11946
|
var OAuthMetadataSchema = z.object({
|
|
11902
11947
|
issuer: z.string(),
|
|
11903
|
-
authorization_endpoint:
|
|
11904
|
-
token_endpoint:
|
|
11905
|
-
registration_endpoint:
|
|
11948
|
+
authorization_endpoint: SafeUrlSchema,
|
|
11949
|
+
token_endpoint: SafeUrlSchema,
|
|
11950
|
+
registration_endpoint: SafeUrlSchema.optional(),
|
|
11906
11951
|
scopes_supported: z.array(z.string()).optional(),
|
|
11907
11952
|
response_types_supported: z.array(z.string()),
|
|
11908
11953
|
response_modes_supported: z.array(z.string()).optional(),
|
|
11909
11954
|
grant_types_supported: z.array(z.string()).optional(),
|
|
11910
11955
|
token_endpoint_auth_methods_supported: z.array(z.string()).optional(),
|
|
11911
11956
|
token_endpoint_auth_signing_alg_values_supported: z.array(z.string()).optional(),
|
|
11912
|
-
service_documentation:
|
|
11913
|
-
revocation_endpoint:
|
|
11957
|
+
service_documentation: SafeUrlSchema.optional(),
|
|
11958
|
+
revocation_endpoint: SafeUrlSchema.optional(),
|
|
11914
11959
|
revocation_endpoint_auth_methods_supported: z.array(z.string()).optional(),
|
|
11915
11960
|
revocation_endpoint_auth_signing_alg_values_supported: z.array(z.string()).optional(),
|
|
11916
11961
|
introspection_endpoint: z.string().optional(),
|
|
@@ -11918,8 +11963,50 @@ var OAuthMetadataSchema = z.object({
|
|
|
11918
11963
|
introspection_endpoint_auth_signing_alg_values_supported: z.array(z.string()).optional(),
|
|
11919
11964
|
code_challenge_methods_supported: z.array(z.string()).optional()
|
|
11920
11965
|
}).passthrough();
|
|
11966
|
+
var OpenIdProviderMetadataSchema = z.object({
|
|
11967
|
+
issuer: z.string(),
|
|
11968
|
+
authorization_endpoint: SafeUrlSchema,
|
|
11969
|
+
token_endpoint: SafeUrlSchema,
|
|
11970
|
+
userinfo_endpoint: SafeUrlSchema.optional(),
|
|
11971
|
+
jwks_uri: SafeUrlSchema,
|
|
11972
|
+
registration_endpoint: SafeUrlSchema.optional(),
|
|
11973
|
+
scopes_supported: z.array(z.string()).optional(),
|
|
11974
|
+
response_types_supported: z.array(z.string()),
|
|
11975
|
+
response_modes_supported: z.array(z.string()).optional(),
|
|
11976
|
+
grant_types_supported: z.array(z.string()).optional(),
|
|
11977
|
+
acr_values_supported: z.array(z.string()).optional(),
|
|
11978
|
+
subject_types_supported: z.array(z.string()),
|
|
11979
|
+
id_token_signing_alg_values_supported: z.array(z.string()),
|
|
11980
|
+
id_token_encryption_alg_values_supported: z.array(z.string()).optional(),
|
|
11981
|
+
id_token_encryption_enc_values_supported: z.array(z.string()).optional(),
|
|
11982
|
+
userinfo_signing_alg_values_supported: z.array(z.string()).optional(),
|
|
11983
|
+
userinfo_encryption_alg_values_supported: z.array(z.string()).optional(),
|
|
11984
|
+
userinfo_encryption_enc_values_supported: z.array(z.string()).optional(),
|
|
11985
|
+
request_object_signing_alg_values_supported: z.array(z.string()).optional(),
|
|
11986
|
+
request_object_encryption_alg_values_supported: z.array(z.string()).optional(),
|
|
11987
|
+
request_object_encryption_enc_values_supported: z.array(z.string()).optional(),
|
|
11988
|
+
token_endpoint_auth_methods_supported: z.array(z.string()).optional(),
|
|
11989
|
+
token_endpoint_auth_signing_alg_values_supported: z.array(z.string()).optional(),
|
|
11990
|
+
display_values_supported: z.array(z.string()).optional(),
|
|
11991
|
+
claim_types_supported: z.array(z.string()).optional(),
|
|
11992
|
+
claims_supported: z.array(z.string()).optional(),
|
|
11993
|
+
service_documentation: z.string().optional(),
|
|
11994
|
+
claims_locales_supported: z.array(z.string()).optional(),
|
|
11995
|
+
ui_locales_supported: z.array(z.string()).optional(),
|
|
11996
|
+
claims_parameter_supported: z.boolean().optional(),
|
|
11997
|
+
request_parameter_supported: z.boolean().optional(),
|
|
11998
|
+
request_uri_parameter_supported: z.boolean().optional(),
|
|
11999
|
+
require_request_uri_registration: z.boolean().optional(),
|
|
12000
|
+
op_policy_uri: SafeUrlSchema.optional(),
|
|
12001
|
+
op_tos_uri: SafeUrlSchema.optional()
|
|
12002
|
+
}).passthrough();
|
|
12003
|
+
var OpenIdProviderDiscoveryMetadataSchema = OpenIdProviderMetadataSchema.merge(OAuthMetadataSchema.pick({
|
|
12004
|
+
code_challenge_methods_supported: true
|
|
12005
|
+
}));
|
|
11921
12006
|
var OAuthTokensSchema = z.object({
|
|
11922
12007
|
access_token: z.string(),
|
|
12008
|
+
id_token: z.string().optional(),
|
|
12009
|
+
// Optional for OAuth 2.1, but necessary in OpenID Connect
|
|
11923
12010
|
token_type: z.string(),
|
|
11924
12011
|
expires_in: z.number().optional(),
|
|
11925
12012
|
scope: z.string().optional(),
|
|
@@ -11931,18 +12018,18 @@ var OAuthErrorResponseSchema = z.object({
|
|
|
11931
12018
|
error_uri: z.string().optional()
|
|
11932
12019
|
});
|
|
11933
12020
|
var OAuthClientMetadataSchema = z.object({
|
|
11934
|
-
redirect_uris: z.array(
|
|
12021
|
+
redirect_uris: z.array(SafeUrlSchema),
|
|
11935
12022
|
token_endpoint_auth_method: z.string().optional(),
|
|
11936
12023
|
grant_types: z.array(z.string()).optional(),
|
|
11937
12024
|
response_types: z.array(z.string()).optional(),
|
|
11938
12025
|
client_name: z.string().optional(),
|
|
11939
|
-
client_uri:
|
|
11940
|
-
logo_uri:
|
|
12026
|
+
client_uri: SafeUrlSchema.optional(),
|
|
12027
|
+
logo_uri: SafeUrlSchema.optional(),
|
|
11941
12028
|
scope: z.string().optional(),
|
|
11942
12029
|
contacts: z.array(z.string()).optional(),
|
|
11943
|
-
tos_uri:
|
|
12030
|
+
tos_uri: SafeUrlSchema.optional(),
|
|
11944
12031
|
policy_uri: z.string().optional(),
|
|
11945
|
-
jwks_uri:
|
|
12032
|
+
jwks_uri: SafeUrlSchema.optional(),
|
|
11946
12033
|
jwks: z.any().optional(),
|
|
11947
12034
|
software_id: z.string().optional(),
|
|
11948
12035
|
software_version: z.string().optional(),
|
|
@@ -11964,7 +12051,7 @@ var OAuthTokenRevocationRequestSchema = z.object({
|
|
|
11964
12051
|
token_type_hint: z.string().optional()
|
|
11965
12052
|
}).strip();
|
|
11966
12053
|
|
|
11967
|
-
// node_modules/.pnpm/@modelcontextprotocol+sdk@
|
|
12054
|
+
// node_modules/.pnpm/@modelcontextprotocol+sdk@1.17.4/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/auth-utils.js
|
|
11968
12055
|
function resourceUrlFromServerUrl(url) {
|
|
11969
12056
|
const resourceURL = typeof url === "string" ? new URL(url) : new URL(url.href);
|
|
11970
12057
|
resourceURL.hash = "";
|
|
@@ -11984,7 +12071,7 @@ function checkResourceAllowed({ requestedResource, configuredResource }) {
|
|
|
11984
12071
|
return requestedPath.startsWith(configuredPath);
|
|
11985
12072
|
}
|
|
11986
12073
|
|
|
11987
|
-
// node_modules/.pnpm/@modelcontextprotocol+sdk@
|
|
12074
|
+
// node_modules/.pnpm/@modelcontextprotocol+sdk@1.17.4/node_modules/@modelcontextprotocol/sdk/dist/esm/server/auth/errors.js
|
|
11988
12075
|
var OAuthError = class extends Error {
|
|
11989
12076
|
constructor(message, errorUri) {
|
|
11990
12077
|
super(message);
|
|
@@ -12075,12 +12162,60 @@ var OAUTH_ERRORS = {
|
|
|
12075
12162
|
[InsufficientScopeError.errorCode]: InsufficientScopeError
|
|
12076
12163
|
};
|
|
12077
12164
|
|
|
12078
|
-
// node_modules/.pnpm/@modelcontextprotocol+sdk@
|
|
12165
|
+
// node_modules/.pnpm/@modelcontextprotocol+sdk@1.17.4/node_modules/@modelcontextprotocol/sdk/dist/esm/client/auth.js
|
|
12079
12166
|
var UnauthorizedError = class extends Error {
|
|
12080
12167
|
constructor(message) {
|
|
12081
12168
|
super(message !== null && message !== void 0 ? message : "Unauthorized");
|
|
12082
12169
|
}
|
|
12083
12170
|
};
|
|
12171
|
+
function selectClientAuthMethod(clientInformation, supportedMethods) {
|
|
12172
|
+
const hasClientSecret = clientInformation.client_secret !== void 0;
|
|
12173
|
+
if (supportedMethods.length === 0) {
|
|
12174
|
+
return hasClientSecret ? "client_secret_post" : "none";
|
|
12175
|
+
}
|
|
12176
|
+
if (hasClientSecret && supportedMethods.includes("client_secret_basic")) {
|
|
12177
|
+
return "client_secret_basic";
|
|
12178
|
+
}
|
|
12179
|
+
if (hasClientSecret && supportedMethods.includes("client_secret_post")) {
|
|
12180
|
+
return "client_secret_post";
|
|
12181
|
+
}
|
|
12182
|
+
if (supportedMethods.includes("none")) {
|
|
12183
|
+
return "none";
|
|
12184
|
+
}
|
|
12185
|
+
return hasClientSecret ? "client_secret_post" : "none";
|
|
12186
|
+
}
|
|
12187
|
+
function applyClientAuthentication(method, clientInformation, headers, params) {
|
|
12188
|
+
const { client_id, client_secret } = clientInformation;
|
|
12189
|
+
switch (method) {
|
|
12190
|
+
case "client_secret_basic":
|
|
12191
|
+
applyBasicAuth(client_id, client_secret, headers);
|
|
12192
|
+
return;
|
|
12193
|
+
case "client_secret_post":
|
|
12194
|
+
applyPostAuth(client_id, client_secret, params);
|
|
12195
|
+
return;
|
|
12196
|
+
case "none":
|
|
12197
|
+
applyPublicAuth(client_id, params);
|
|
12198
|
+
return;
|
|
12199
|
+
default:
|
|
12200
|
+
throw new Error(`Unsupported client authentication method: ${method}`);
|
|
12201
|
+
}
|
|
12202
|
+
}
|
|
12203
|
+
function applyBasicAuth(clientId, clientSecret, headers) {
|
|
12204
|
+
if (!clientSecret) {
|
|
12205
|
+
throw new Error("client_secret_basic authentication requires a client_secret");
|
|
12206
|
+
}
|
|
12207
|
+
const credentials = btoa(`${clientId}:${clientSecret}`);
|
|
12208
|
+
headers.set("Authorization", `Basic ${credentials}`);
|
|
12209
|
+
}
|
|
12210
|
+
function applyPostAuth(clientId, clientSecret, params) {
|
|
12211
|
+
params.set("client_id", clientId);
|
|
12212
|
+
if (clientSecret) {
|
|
12213
|
+
params.set("client_secret", clientSecret);
|
|
12214
|
+
}
|
|
12215
|
+
}
|
|
12216
|
+
function applyPublicAuth(clientId, params) {
|
|
12217
|
+
params.set("client_id", clientId);
|
|
12218
|
+
}
|
|
12084
12219
|
async function parseErrorResponse(input) {
|
|
12085
12220
|
const statusCode = input instanceof Response ? input.status : void 0;
|
|
12086
12221
|
const body = input instanceof Response ? await input.text() : input;
|
|
@@ -12109,18 +12244,23 @@ async function auth(provider, options) {
|
|
|
12109
12244
|
throw error;
|
|
12110
12245
|
}
|
|
12111
12246
|
}
|
|
12112
|
-
async function authInternal(provider, { serverUrl, authorizationCode, scope, resourceMetadataUrl }) {
|
|
12247
|
+
async function authInternal(provider, { serverUrl, authorizationCode, scope, resourceMetadataUrl, fetchFn }) {
|
|
12113
12248
|
let resourceMetadata;
|
|
12114
|
-
let authorizationServerUrl
|
|
12249
|
+
let authorizationServerUrl;
|
|
12115
12250
|
try {
|
|
12116
|
-
resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl });
|
|
12251
|
+
resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl }, fetchFn);
|
|
12117
12252
|
if (resourceMetadata.authorization_servers && resourceMetadata.authorization_servers.length > 0) {
|
|
12118
12253
|
authorizationServerUrl = resourceMetadata.authorization_servers[0];
|
|
12119
12254
|
}
|
|
12120
12255
|
} catch (_a) {
|
|
12121
12256
|
}
|
|
12257
|
+
if (!authorizationServerUrl) {
|
|
12258
|
+
authorizationServerUrl = serverUrl;
|
|
12259
|
+
}
|
|
12122
12260
|
const resource = await selectResourceURL(serverUrl, provider, resourceMetadata);
|
|
12123
|
-
const metadata = await
|
|
12261
|
+
const metadata = await discoverAuthorizationServerMetadata(authorizationServerUrl, {
|
|
12262
|
+
fetchFn
|
|
12263
|
+
});
|
|
12124
12264
|
let clientInformation = await Promise.resolve(provider.clientInformation());
|
|
12125
12265
|
if (!clientInformation) {
|
|
12126
12266
|
if (authorizationCode !== void 0) {
|
|
@@ -12131,7 +12271,8 @@ async function authInternal(provider, { serverUrl, authorizationCode, scope, res
|
|
|
12131
12271
|
}
|
|
12132
12272
|
const fullInformation = await registerClient(authorizationServerUrl, {
|
|
12133
12273
|
metadata,
|
|
12134
|
-
clientMetadata: provider.clientMetadata
|
|
12274
|
+
clientMetadata: provider.clientMetadata,
|
|
12275
|
+
fetchFn
|
|
12135
12276
|
});
|
|
12136
12277
|
await provider.saveClientInformation(fullInformation);
|
|
12137
12278
|
clientInformation = fullInformation;
|
|
@@ -12144,7 +12285,9 @@ async function authInternal(provider, { serverUrl, authorizationCode, scope, res
|
|
|
12144
12285
|
authorizationCode,
|
|
12145
12286
|
codeVerifier: codeVerifier2,
|
|
12146
12287
|
redirectUri: provider.redirectUrl,
|
|
12147
|
-
resource
|
|
12288
|
+
resource,
|
|
12289
|
+
addClientAuthentication: provider.addClientAuthentication,
|
|
12290
|
+
fetchFn
|
|
12148
12291
|
});
|
|
12149
12292
|
await provider.saveTokens(tokens2);
|
|
12150
12293
|
return "AUTHORIZED";
|
|
@@ -12156,7 +12299,9 @@ async function authInternal(provider, { serverUrl, authorizationCode, scope, res
|
|
|
12156
12299
|
metadata,
|
|
12157
12300
|
clientInformation,
|
|
12158
12301
|
refreshToken: tokens.refresh_token,
|
|
12159
|
-
resource
|
|
12302
|
+
resource,
|
|
12303
|
+
addClientAuthentication: provider.addClientAuthentication,
|
|
12304
|
+
fetchFn
|
|
12160
12305
|
});
|
|
12161
12306
|
await provider.saveTokens(newTokens);
|
|
12162
12307
|
return "AUTHORIZED";
|
|
@@ -12213,29 +12358,12 @@ function extractResourceMetadataUrl(res) {
|
|
|
12213
12358
|
return void 0;
|
|
12214
12359
|
}
|
|
12215
12360
|
}
|
|
12216
|
-
async function discoverOAuthProtectedResourceMetadata(serverUrl, opts) {
|
|
12217
|
-
|
|
12218
|
-
|
|
12219
|
-
|
|
12220
|
-
|
|
12221
|
-
|
|
12222
|
-
url = new URL("/.well-known/oauth-protected-resource", serverUrl);
|
|
12223
|
-
}
|
|
12224
|
-
let response;
|
|
12225
|
-
try {
|
|
12226
|
-
response = await fetch(url, {
|
|
12227
|
-
headers: {
|
|
12228
|
-
"MCP-Protocol-Version": (_a = opts === null || opts === void 0 ? void 0 : opts.protocolVersion) !== null && _a !== void 0 ? _a : LATEST_PROTOCOL_VERSION
|
|
12229
|
-
}
|
|
12230
|
-
});
|
|
12231
|
-
} catch (error) {
|
|
12232
|
-
if (error instanceof TypeError) {
|
|
12233
|
-
response = await fetch(url);
|
|
12234
|
-
} else {
|
|
12235
|
-
throw error;
|
|
12236
|
-
}
|
|
12237
|
-
}
|
|
12238
|
-
if (response.status === 404) {
|
|
12361
|
+
async function discoverOAuthProtectedResourceMetadata(serverUrl, opts, fetchFn = fetch) {
|
|
12362
|
+
const response = await discoverMetadataWithFallback(serverUrl, "oauth-protected-resource", fetchFn, {
|
|
12363
|
+
protocolVersion: opts === null || opts === void 0 ? void 0 : opts.protocolVersion,
|
|
12364
|
+
metadataUrl: opts === null || opts === void 0 ? void 0 : opts.resourceMetadataUrl
|
|
12365
|
+
});
|
|
12366
|
+
if (!response || response.status === 404) {
|
|
12239
12367
|
throw new Error(`Resource server does not implement OAuth 2.0 Protected Resource Metadata.`);
|
|
12240
12368
|
}
|
|
12241
12369
|
if (!response.ok) {
|
|
@@ -12243,13 +12371,13 @@ async function discoverOAuthProtectedResourceMetadata(serverUrl, opts) {
|
|
|
12243
12371
|
}
|
|
12244
12372
|
return OAuthProtectedResourceMetadataSchema.parse(await response.json());
|
|
12245
12373
|
}
|
|
12246
|
-
async function fetchWithCorsRetry(url, headers) {
|
|
12374
|
+
async function fetchWithCorsRetry(url, headers, fetchFn = fetch) {
|
|
12247
12375
|
try {
|
|
12248
|
-
return await
|
|
12376
|
+
return await fetchFn(url, { headers });
|
|
12249
12377
|
} catch (error) {
|
|
12250
12378
|
if (error instanceof TypeError) {
|
|
12251
12379
|
if (headers) {
|
|
12252
|
-
return fetchWithCorsRetry(url);
|
|
12380
|
+
return fetchWithCorsRetry(url, void 0, fetchFn);
|
|
12253
12381
|
} else {
|
|
12254
12382
|
return void 0;
|
|
12255
12383
|
}
|
|
@@ -12257,40 +12385,103 @@ async function fetchWithCorsRetry(url, headers) {
|
|
|
12257
12385
|
throw error;
|
|
12258
12386
|
}
|
|
12259
12387
|
}
|
|
12260
|
-
function buildWellKnownPath(pathname) {
|
|
12261
|
-
let wellKnownPath = `/.well-known/oauth-authorization-server${pathname}`;
|
|
12388
|
+
function buildWellKnownPath(wellKnownPrefix, pathname = "", options = {}) {
|
|
12262
12389
|
if (pathname.endsWith("/")) {
|
|
12263
|
-
|
|
12390
|
+
pathname = pathname.slice(0, -1);
|
|
12264
12391
|
}
|
|
12265
|
-
return
|
|
12392
|
+
return options.prependPathname ? `${pathname}/.well-known/${wellKnownPrefix}` : `/.well-known/${wellKnownPrefix}${pathname}`;
|
|
12266
12393
|
}
|
|
12267
|
-
async function tryMetadataDiscovery(url, protocolVersion) {
|
|
12394
|
+
async function tryMetadataDiscovery(url, protocolVersion, fetchFn = fetch) {
|
|
12268
12395
|
const headers = {
|
|
12269
12396
|
"MCP-Protocol-Version": protocolVersion
|
|
12270
12397
|
};
|
|
12271
|
-
return await fetchWithCorsRetry(url, headers);
|
|
12398
|
+
return await fetchWithCorsRetry(url, headers, fetchFn);
|
|
12272
12399
|
}
|
|
12273
12400
|
function shouldAttemptFallback(response, pathname) {
|
|
12274
|
-
return !response || response.status
|
|
12401
|
+
return !response || response.status >= 400 && response.status < 500 && pathname !== "/";
|
|
12275
12402
|
}
|
|
12276
|
-
async function
|
|
12277
|
-
var _a;
|
|
12278
|
-
const issuer = new URL(
|
|
12403
|
+
async function discoverMetadataWithFallback(serverUrl, wellKnownType, fetchFn, opts) {
|
|
12404
|
+
var _a, _b;
|
|
12405
|
+
const issuer = new URL(serverUrl);
|
|
12279
12406
|
const protocolVersion = (_a = opts === null || opts === void 0 ? void 0 : opts.protocolVersion) !== null && _a !== void 0 ? _a : LATEST_PROTOCOL_VERSION;
|
|
12280
|
-
|
|
12281
|
-
|
|
12282
|
-
|
|
12283
|
-
|
|
12284
|
-
const
|
|
12285
|
-
|
|
12407
|
+
let url;
|
|
12408
|
+
if (opts === null || opts === void 0 ? void 0 : opts.metadataUrl) {
|
|
12409
|
+
url = new URL(opts.metadataUrl);
|
|
12410
|
+
} else {
|
|
12411
|
+
const wellKnownPath = buildWellKnownPath(wellKnownType, issuer.pathname);
|
|
12412
|
+
url = new URL(wellKnownPath, (_b = opts === null || opts === void 0 ? void 0 : opts.metadataServerUrl) !== null && _b !== void 0 ? _b : issuer);
|
|
12413
|
+
url.search = issuer.search;
|
|
12286
12414
|
}
|
|
12287
|
-
|
|
12288
|
-
|
|
12415
|
+
let response = await tryMetadataDiscovery(url, protocolVersion, fetchFn);
|
|
12416
|
+
if (!(opts === null || opts === void 0 ? void 0 : opts.metadataUrl) && shouldAttemptFallback(response, issuer.pathname)) {
|
|
12417
|
+
const rootUrl = new URL(`/.well-known/${wellKnownType}`, issuer);
|
|
12418
|
+
response = await tryMetadataDiscovery(rootUrl, protocolVersion, fetchFn);
|
|
12289
12419
|
}
|
|
12290
|
-
|
|
12291
|
-
|
|
12420
|
+
return response;
|
|
12421
|
+
}
|
|
12422
|
+
function buildDiscoveryUrls(authorizationServerUrl) {
|
|
12423
|
+
const url = typeof authorizationServerUrl === "string" ? new URL(authorizationServerUrl) : authorizationServerUrl;
|
|
12424
|
+
const hasPath = url.pathname !== "/";
|
|
12425
|
+
const urlsToTry = [];
|
|
12426
|
+
if (!hasPath) {
|
|
12427
|
+
urlsToTry.push({
|
|
12428
|
+
url: new URL("/.well-known/oauth-authorization-server", url.origin),
|
|
12429
|
+
type: "oauth"
|
|
12430
|
+
});
|
|
12431
|
+
urlsToTry.push({
|
|
12432
|
+
url: new URL(`/.well-known/openid-configuration`, url.origin),
|
|
12433
|
+
type: "oidc"
|
|
12434
|
+
});
|
|
12435
|
+
return urlsToTry;
|
|
12292
12436
|
}
|
|
12293
|
-
|
|
12437
|
+
let pathname = url.pathname;
|
|
12438
|
+
if (pathname.endsWith("/")) {
|
|
12439
|
+
pathname = pathname.slice(0, -1);
|
|
12440
|
+
}
|
|
12441
|
+
urlsToTry.push({
|
|
12442
|
+
url: new URL(`/.well-known/oauth-authorization-server${pathname}`, url.origin),
|
|
12443
|
+
type: "oauth"
|
|
12444
|
+
});
|
|
12445
|
+
urlsToTry.push({
|
|
12446
|
+
url: new URL("/.well-known/oauth-authorization-server", url.origin),
|
|
12447
|
+
type: "oauth"
|
|
12448
|
+
});
|
|
12449
|
+
urlsToTry.push({
|
|
12450
|
+
url: new URL(`/.well-known/openid-configuration${pathname}`, url.origin),
|
|
12451
|
+
type: "oidc"
|
|
12452
|
+
});
|
|
12453
|
+
urlsToTry.push({
|
|
12454
|
+
url: new URL(`${pathname}/.well-known/openid-configuration`, url.origin),
|
|
12455
|
+
type: "oidc"
|
|
12456
|
+
});
|
|
12457
|
+
return urlsToTry;
|
|
12458
|
+
}
|
|
12459
|
+
async function discoverAuthorizationServerMetadata(authorizationServerUrl, { fetchFn = fetch, protocolVersion = LATEST_PROTOCOL_VERSION } = {}) {
|
|
12460
|
+
var _a;
|
|
12461
|
+
const headers = { "MCP-Protocol-Version": protocolVersion };
|
|
12462
|
+
const urlsToTry = buildDiscoveryUrls(authorizationServerUrl);
|
|
12463
|
+
for (const { url: endpointUrl, type } of urlsToTry) {
|
|
12464
|
+
const response = await fetchWithCorsRetry(endpointUrl, headers, fetchFn);
|
|
12465
|
+
if (!response) {
|
|
12466
|
+
continue;
|
|
12467
|
+
}
|
|
12468
|
+
if (!response.ok) {
|
|
12469
|
+
if (response.status >= 400 && response.status < 500) {
|
|
12470
|
+
continue;
|
|
12471
|
+
}
|
|
12472
|
+
throw new Error(`HTTP ${response.status} trying to load ${type === "oauth" ? "OAuth" : "OpenID provider"} metadata from ${endpointUrl}`);
|
|
12473
|
+
}
|
|
12474
|
+
if (type === "oauth") {
|
|
12475
|
+
return OAuthMetadataSchema.parse(await response.json());
|
|
12476
|
+
} else {
|
|
12477
|
+
const metadata = OpenIdProviderDiscoveryMetadataSchema.parse(await response.json());
|
|
12478
|
+
if (!((_a = metadata.code_challenge_methods_supported) === null || _a === void 0 ? void 0 : _a.includes("S256"))) {
|
|
12479
|
+
throw new Error(`Incompatible OIDC provider at ${endpointUrl}: does not support S256 code challenge method required by MCP specification`);
|
|
12480
|
+
}
|
|
12481
|
+
return metadata;
|
|
12482
|
+
}
|
|
12483
|
+
}
|
|
12484
|
+
return void 0;
|
|
12294
12485
|
}
|
|
12295
12486
|
async function startAuthorization(authorizationServerUrl, { metadata, clientInformation, redirectUrl, scope, state, resource }) {
|
|
12296
12487
|
const responseType = "code";
|
|
@@ -12321,40 +12512,44 @@ async function startAuthorization(authorizationServerUrl, { metadata, clientInfo
|
|
|
12321
12512
|
if (scope) {
|
|
12322
12513
|
authorizationUrl.searchParams.set("scope", scope);
|
|
12323
12514
|
}
|
|
12515
|
+
if (scope === null || scope === void 0 ? void 0 : scope.includes("offline_access")) {
|
|
12516
|
+
authorizationUrl.searchParams.append("prompt", "consent");
|
|
12517
|
+
}
|
|
12324
12518
|
if (resource) {
|
|
12325
12519
|
authorizationUrl.searchParams.set("resource", resource.href);
|
|
12326
12520
|
}
|
|
12327
12521
|
return { authorizationUrl, codeVerifier };
|
|
12328
12522
|
}
|
|
12329
|
-
async function exchangeAuthorization(authorizationServerUrl, { metadata, clientInformation, authorizationCode, codeVerifier, redirectUri, resource }) {
|
|
12523
|
+
async function exchangeAuthorization(authorizationServerUrl, { metadata, clientInformation, authorizationCode, codeVerifier, redirectUri, resource, addClientAuthentication, fetchFn }) {
|
|
12524
|
+
var _a;
|
|
12330
12525
|
const grantType = "authorization_code";
|
|
12331
|
-
|
|
12332
|
-
if (metadata) {
|
|
12333
|
-
|
|
12334
|
-
if (metadata.grant_types_supported && !metadata.grant_types_supported.includes(grantType)) {
|
|
12335
|
-
throw new Error(`Incompatible auth server: does not support grant type ${grantType}`);
|
|
12336
|
-
}
|
|
12337
|
-
} else {
|
|
12338
|
-
tokenUrl = new URL("/token", authorizationServerUrl);
|
|
12526
|
+
const tokenUrl = (metadata === null || metadata === void 0 ? void 0 : metadata.token_endpoint) ? new URL(metadata.token_endpoint) : new URL("/token", authorizationServerUrl);
|
|
12527
|
+
if ((metadata === null || metadata === void 0 ? void 0 : metadata.grant_types_supported) && !metadata.grant_types_supported.includes(grantType)) {
|
|
12528
|
+
throw new Error(`Incompatible auth server: does not support grant type ${grantType}`);
|
|
12339
12529
|
}
|
|
12530
|
+
const headers = new Headers({
|
|
12531
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
12532
|
+
"Accept": "application/json"
|
|
12533
|
+
});
|
|
12340
12534
|
const params = new URLSearchParams({
|
|
12341
12535
|
grant_type: grantType,
|
|
12342
|
-
client_id: clientInformation.client_id,
|
|
12343
12536
|
code: authorizationCode,
|
|
12344
12537
|
code_verifier: codeVerifier,
|
|
12345
12538
|
redirect_uri: String(redirectUri)
|
|
12346
12539
|
});
|
|
12347
|
-
if (
|
|
12348
|
-
|
|
12540
|
+
if (addClientAuthentication) {
|
|
12541
|
+
addClientAuthentication(headers, params, authorizationServerUrl, metadata);
|
|
12542
|
+
} else {
|
|
12543
|
+
const supportedMethods = (_a = metadata === null || metadata === void 0 ? void 0 : metadata.token_endpoint_auth_methods_supported) !== null && _a !== void 0 ? _a : [];
|
|
12544
|
+
const authMethod = selectClientAuthMethod(clientInformation, supportedMethods);
|
|
12545
|
+
applyClientAuthentication(authMethod, clientInformation, headers, params);
|
|
12349
12546
|
}
|
|
12350
12547
|
if (resource) {
|
|
12351
12548
|
params.set("resource", resource.href);
|
|
12352
12549
|
}
|
|
12353
|
-
const response = await fetch(tokenUrl, {
|
|
12550
|
+
const response = await (fetchFn !== null && fetchFn !== void 0 ? fetchFn : fetch)(tokenUrl, {
|
|
12354
12551
|
method: "POST",
|
|
12355
|
-
headers
|
|
12356
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
12357
|
-
},
|
|
12552
|
+
headers,
|
|
12358
12553
|
body: params
|
|
12359
12554
|
});
|
|
12360
12555
|
if (!response.ok) {
|
|
@@ -12362,7 +12557,8 @@ async function exchangeAuthorization(authorizationServerUrl, { metadata, clientI
|
|
|
12362
12557
|
}
|
|
12363
12558
|
return OAuthTokensSchema.parse(await response.json());
|
|
12364
12559
|
}
|
|
12365
|
-
async function refreshAuthorization(authorizationServerUrl, { metadata, clientInformation, refreshToken, resource }) {
|
|
12560
|
+
async function refreshAuthorization(authorizationServerUrl, { metadata, clientInformation, refreshToken, resource, addClientAuthentication, fetchFn }) {
|
|
12561
|
+
var _a;
|
|
12366
12562
|
const grantType = "refresh_token";
|
|
12367
12563
|
let tokenUrl;
|
|
12368
12564
|
if (metadata) {
|
|
@@ -12373,22 +12569,26 @@ async function refreshAuthorization(authorizationServerUrl, { metadata, clientIn
|
|
|
12373
12569
|
} else {
|
|
12374
12570
|
tokenUrl = new URL("/token", authorizationServerUrl);
|
|
12375
12571
|
}
|
|
12572
|
+
const headers = new Headers({
|
|
12573
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
12574
|
+
});
|
|
12376
12575
|
const params = new URLSearchParams({
|
|
12377
12576
|
grant_type: grantType,
|
|
12378
|
-
client_id: clientInformation.client_id,
|
|
12379
12577
|
refresh_token: refreshToken
|
|
12380
12578
|
});
|
|
12381
|
-
if (
|
|
12382
|
-
|
|
12579
|
+
if (addClientAuthentication) {
|
|
12580
|
+
addClientAuthentication(headers, params, authorizationServerUrl, metadata);
|
|
12581
|
+
} else {
|
|
12582
|
+
const supportedMethods = (_a = metadata === null || metadata === void 0 ? void 0 : metadata.token_endpoint_auth_methods_supported) !== null && _a !== void 0 ? _a : [];
|
|
12583
|
+
const authMethod = selectClientAuthMethod(clientInformation, supportedMethods);
|
|
12584
|
+
applyClientAuthentication(authMethod, clientInformation, headers, params);
|
|
12383
12585
|
}
|
|
12384
12586
|
if (resource) {
|
|
12385
12587
|
params.set("resource", resource.href);
|
|
12386
12588
|
}
|
|
12387
|
-
const response = await fetch(tokenUrl, {
|
|
12589
|
+
const response = await (fetchFn !== null && fetchFn !== void 0 ? fetchFn : fetch)(tokenUrl, {
|
|
12388
12590
|
method: "POST",
|
|
12389
|
-
headers
|
|
12390
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
12391
|
-
},
|
|
12591
|
+
headers,
|
|
12392
12592
|
body: params
|
|
12393
12593
|
});
|
|
12394
12594
|
if (!response.ok) {
|
|
@@ -12396,7 +12596,7 @@ async function refreshAuthorization(authorizationServerUrl, { metadata, clientIn
|
|
|
12396
12596
|
}
|
|
12397
12597
|
return OAuthTokensSchema.parse({ refresh_token: refreshToken, ...await response.json() });
|
|
12398
12598
|
}
|
|
12399
|
-
async function registerClient(authorizationServerUrl, { metadata, clientMetadata }) {
|
|
12599
|
+
async function registerClient(authorizationServerUrl, { metadata, clientMetadata, fetchFn }) {
|
|
12400
12600
|
let registrationUrl;
|
|
12401
12601
|
if (metadata) {
|
|
12402
12602
|
if (!metadata.registration_endpoint) {
|
|
@@ -12406,7 +12606,7 @@ async function registerClient(authorizationServerUrl, { metadata, clientMetadata
|
|
|
12406
12606
|
} else {
|
|
12407
12607
|
registrationUrl = new URL("/register", authorizationServerUrl);
|
|
12408
12608
|
}
|
|
12409
|
-
const response = await fetch(registrationUrl, {
|
|
12609
|
+
const response = await (fetchFn !== null && fetchFn !== void 0 ? fetchFn : fetch)(registrationUrl, {
|
|
12410
12610
|
method: "POST",
|
|
12411
12611
|
headers: {
|
|
12412
12612
|
"Content-Type": "application/json"
|
|
@@ -12819,7 +13019,7 @@ function getBaseURL() {
|
|
|
12819
13019
|
return doc && typeof doc == "object" && "baseURI" in doc && typeof doc.baseURI == "string" ? doc.baseURI : void 0;
|
|
12820
13020
|
}
|
|
12821
13021
|
|
|
12822
|
-
// node_modules/.pnpm/@modelcontextprotocol+sdk@
|
|
13022
|
+
// node_modules/.pnpm/@modelcontextprotocol+sdk@1.17.4/node_modules/@modelcontextprotocol/sdk/dist/esm/client/sse.js
|
|
12823
13023
|
var SseError = class extends Error {
|
|
12824
13024
|
constructor(code, message, event) {
|
|
12825
13025
|
super(`SSE error: ${message}`);
|
|
@@ -12834,6 +13034,7 @@ var SSEClientTransport = class {
|
|
|
12834
13034
|
this._eventSourceInit = opts === null || opts === void 0 ? void 0 : opts.eventSourceInit;
|
|
12835
13035
|
this._requestInit = opts === null || opts === void 0 ? void 0 : opts.requestInit;
|
|
12836
13036
|
this._authProvider = opts === null || opts === void 0 ? void 0 : opts.authProvider;
|
|
13037
|
+
this._fetch = opts === null || opts === void 0 ? void 0 : opts.fetch;
|
|
12837
13038
|
}
|
|
12838
13039
|
async _authThenStart() {
|
|
12839
13040
|
var _a;
|
|
@@ -12842,7 +13043,7 @@ var SSEClientTransport = class {
|
|
|
12842
13043
|
}
|
|
12843
13044
|
let result;
|
|
12844
13045
|
try {
|
|
12845
|
-
result = await auth(this._authProvider, { serverUrl: this._url, resourceMetadataUrl: this._resourceMetadataUrl });
|
|
13046
|
+
result = await auth(this._authProvider, { serverUrl: this._url, resourceMetadataUrl: this._resourceMetadataUrl, fetchFn: this._fetch });
|
|
12846
13047
|
} catch (error) {
|
|
12847
13048
|
(_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error);
|
|
12848
13049
|
throw error;
|
|
@@ -12854,9 +13055,7 @@ var SSEClientTransport = class {
|
|
|
12854
13055
|
}
|
|
12855
13056
|
async _commonHeaders() {
|
|
12856
13057
|
var _a;
|
|
12857
|
-
const headers = {
|
|
12858
|
-
...(_a = this._requestInit) === null || _a === void 0 ? void 0 : _a.headers
|
|
12859
|
-
};
|
|
13058
|
+
const headers = {};
|
|
12860
13059
|
if (this._authProvider) {
|
|
12861
13060
|
const tokens = await this._authProvider.tokens();
|
|
12862
13061
|
if (tokens) {
|
|
@@ -12866,22 +13065,20 @@ var SSEClientTransport = class {
|
|
|
12866
13065
|
if (this._protocolVersion) {
|
|
12867
13066
|
headers["mcp-protocol-version"] = this._protocolVersion;
|
|
12868
13067
|
}
|
|
12869
|
-
return headers;
|
|
13068
|
+
return new Headers({ ...headers, ...(_a = this._requestInit) === null || _a === void 0 ? void 0 : _a.headers });
|
|
12870
13069
|
}
|
|
12871
13070
|
_startOrAuth() {
|
|
12872
|
-
var _a;
|
|
12873
|
-
const fetchImpl = ((_a = this === null || this === void 0 ? void 0 : this._eventSourceInit) === null || _a === void 0 ? void 0 : _a.fetch)
|
|
13071
|
+
var _a, _b, _c;
|
|
13072
|
+
const fetchImpl = (_c = (_b = (_a = this === null || this === void 0 ? void 0 : this._eventSourceInit) === null || _a === void 0 ? void 0 : _a.fetch) !== null && _b !== void 0 ? _b : this._fetch) !== null && _c !== void 0 ? _c : fetch;
|
|
12874
13073
|
return new Promise((resolve, reject) => {
|
|
12875
13074
|
this._eventSource = new EventSource(this._url.href, {
|
|
12876
13075
|
...this._eventSourceInit,
|
|
12877
13076
|
fetch: async (url, init) => {
|
|
12878
13077
|
const headers = await this._commonHeaders();
|
|
13078
|
+
headers.set("Accept", "text/event-stream");
|
|
12879
13079
|
const response = await fetchImpl(url, {
|
|
12880
13080
|
...init,
|
|
12881
|
-
headers
|
|
12882
|
-
...headers,
|
|
12883
|
-
Accept: "text/event-stream"
|
|
12884
|
-
})
|
|
13081
|
+
headers
|
|
12885
13082
|
});
|
|
12886
13083
|
if (response.status === 401 && response.headers.has("www-authenticate")) {
|
|
12887
13084
|
this._resourceMetadataUrl = extractResourceMetadataUrl(response);
|
|
@@ -12919,7 +13116,7 @@ var SSEClientTransport = class {
|
|
|
12919
13116
|
resolve();
|
|
12920
13117
|
});
|
|
12921
13118
|
this._eventSource.onmessage = (event) => {
|
|
12922
|
-
var _a2,
|
|
13119
|
+
var _a2, _b2;
|
|
12923
13120
|
const messageEvent = event;
|
|
12924
13121
|
let message;
|
|
12925
13122
|
try {
|
|
@@ -12928,7 +13125,7 @@ var SSEClientTransport = class {
|
|
|
12928
13125
|
(_a2 = this.onerror) === null || _a2 === void 0 ? void 0 : _a2.call(this, error);
|
|
12929
13126
|
return;
|
|
12930
13127
|
}
|
|
12931
|
-
(
|
|
13128
|
+
(_b2 = this.onmessage) === null || _b2 === void 0 ? void 0 : _b2.call(this, message);
|
|
12932
13129
|
};
|
|
12933
13130
|
});
|
|
12934
13131
|
}
|
|
@@ -12945,7 +13142,7 @@ var SSEClientTransport = class {
|
|
|
12945
13142
|
if (!this._authProvider) {
|
|
12946
13143
|
throw new UnauthorizedError("No auth provider");
|
|
12947
13144
|
}
|
|
12948
|
-
const result = await auth(this._authProvider, { serverUrl: this._url, authorizationCode, resourceMetadataUrl: this._resourceMetadataUrl });
|
|
13145
|
+
const result = await auth(this._authProvider, { serverUrl: this._url, authorizationCode, resourceMetadataUrl: this._resourceMetadataUrl, fetchFn: this._fetch });
|
|
12949
13146
|
if (result !== "AUTHORIZED") {
|
|
12950
13147
|
throw new UnauthorizedError("Failed to authorize");
|
|
12951
13148
|
}
|
|
@@ -12957,13 +13154,12 @@ var SSEClientTransport = class {
|
|
|
12957
13154
|
(_c = this.onclose) === null || _c === void 0 ? void 0 : _c.call(this);
|
|
12958
13155
|
}
|
|
12959
13156
|
async send(message) {
|
|
12960
|
-
var _a, _b;
|
|
13157
|
+
var _a, _b, _c;
|
|
12961
13158
|
if (!this._endpoint) {
|
|
12962
13159
|
throw new Error("Not connected");
|
|
12963
13160
|
}
|
|
12964
13161
|
try {
|
|
12965
|
-
const
|
|
12966
|
-
const headers = new Headers(commonHeaders);
|
|
13162
|
+
const headers = await this._commonHeaders();
|
|
12967
13163
|
headers.set("content-type", "application/json");
|
|
12968
13164
|
const init = {
|
|
12969
13165
|
...this._requestInit,
|
|
@@ -12972,11 +13168,11 @@ var SSEClientTransport = class {
|
|
|
12972
13168
|
body: JSON.stringify(message),
|
|
12973
13169
|
signal: (_a = this._abortController) === null || _a === void 0 ? void 0 : _a.signal
|
|
12974
13170
|
};
|
|
12975
|
-
const response = await fetch(this._endpoint, init);
|
|
13171
|
+
const response = await ((_b = this._fetch) !== null && _b !== void 0 ? _b : fetch)(this._endpoint, init);
|
|
12976
13172
|
if (!response.ok) {
|
|
12977
13173
|
if (response.status === 401 && this._authProvider) {
|
|
12978
13174
|
this._resourceMetadataUrl = extractResourceMetadataUrl(response);
|
|
12979
|
-
const result = await auth(this._authProvider, { serverUrl: this._url, resourceMetadataUrl: this._resourceMetadataUrl });
|
|
13175
|
+
const result = await auth(this._authProvider, { serverUrl: this._url, resourceMetadataUrl: this._resourceMetadataUrl, fetchFn: this._fetch });
|
|
12980
13176
|
if (result !== "AUTHORIZED") {
|
|
12981
13177
|
throw new UnauthorizedError();
|
|
12982
13178
|
}
|
|
@@ -12986,7 +13182,7 @@ var SSEClientTransport = class {
|
|
|
12986
13182
|
throw new Error(`Error POSTing to endpoint (HTTP ${response.status}): ${text}`);
|
|
12987
13183
|
}
|
|
12988
13184
|
} catch (error) {
|
|
12989
|
-
(
|
|
13185
|
+
(_c = this.onerror) === null || _c === void 0 ? void 0 : _c.call(this, error);
|
|
12990
13186
|
throw error;
|
|
12991
13187
|
}
|
|
12992
13188
|
}
|
|
@@ -13019,7 +13215,7 @@ var EventSourceParserStream = class extends TransformStream {
|
|
|
13019
13215
|
}
|
|
13020
13216
|
};
|
|
13021
13217
|
|
|
13022
|
-
// node_modules/.pnpm/@modelcontextprotocol+sdk@
|
|
13218
|
+
// node_modules/.pnpm/@modelcontextprotocol+sdk@1.17.4/node_modules/@modelcontextprotocol/sdk/dist/esm/client/streamableHttp.js
|
|
13023
13219
|
var DEFAULT_STREAMABLE_HTTP_RECONNECTION_OPTIONS = {
|
|
13024
13220
|
initialReconnectionDelay: 1e3,
|
|
13025
13221
|
maxReconnectionDelay: 3e4,
|
|
@@ -13039,6 +13235,7 @@ var StreamableHTTPClientTransport = class {
|
|
|
13039
13235
|
this._resourceMetadataUrl = void 0;
|
|
13040
13236
|
this._requestInit = opts === null || opts === void 0 ? void 0 : opts.requestInit;
|
|
13041
13237
|
this._authProvider = opts === null || opts === void 0 ? void 0 : opts.authProvider;
|
|
13238
|
+
this._fetch = opts === null || opts === void 0 ? void 0 : opts.fetch;
|
|
13042
13239
|
this._sessionId = opts === null || opts === void 0 ? void 0 : opts.sessionId;
|
|
13043
13240
|
this._reconnectionOptions = (_a = opts === null || opts === void 0 ? void 0 : opts.reconnectionOptions) !== null && _a !== void 0 ? _a : DEFAULT_STREAMABLE_HTTP_RECONNECTION_OPTIONS;
|
|
13044
13241
|
}
|
|
@@ -13049,7 +13246,7 @@ var StreamableHTTPClientTransport = class {
|
|
|
13049
13246
|
}
|
|
13050
13247
|
let result;
|
|
13051
13248
|
try {
|
|
13052
|
-
result = await auth(this._authProvider, { serverUrl: this._url, resourceMetadataUrl: this._resourceMetadataUrl });
|
|
13249
|
+
result = await auth(this._authProvider, { serverUrl: this._url, resourceMetadataUrl: this._resourceMetadataUrl, fetchFn: this._fetch });
|
|
13053
13250
|
} catch (error) {
|
|
13054
13251
|
(_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error);
|
|
13055
13252
|
throw error;
|
|
@@ -13081,7 +13278,7 @@ var StreamableHTTPClientTransport = class {
|
|
|
13081
13278
|
});
|
|
13082
13279
|
}
|
|
13083
13280
|
async _startOrAuthSse(options) {
|
|
13084
|
-
var _a, _b;
|
|
13281
|
+
var _a, _b, _c;
|
|
13085
13282
|
const { resumptionToken } = options;
|
|
13086
13283
|
try {
|
|
13087
13284
|
const headers = await this._commonHeaders();
|
|
@@ -13089,10 +13286,10 @@ var StreamableHTTPClientTransport = class {
|
|
|
13089
13286
|
if (resumptionToken) {
|
|
13090
13287
|
headers.set("last-event-id", resumptionToken);
|
|
13091
13288
|
}
|
|
13092
|
-
const response = await fetch(this._url, {
|
|
13289
|
+
const response = await ((_a = this._fetch) !== null && _a !== void 0 ? _a : fetch)(this._url, {
|
|
13093
13290
|
method: "GET",
|
|
13094
13291
|
headers,
|
|
13095
|
-
signal: (
|
|
13292
|
+
signal: (_b = this._abortController) === null || _b === void 0 ? void 0 : _b.signal
|
|
13096
13293
|
});
|
|
13097
13294
|
if (!response.ok) {
|
|
13098
13295
|
if (response.status === 401 && this._authProvider) {
|
|
@@ -13103,9 +13300,9 @@ var StreamableHTTPClientTransport = class {
|
|
|
13103
13300
|
}
|
|
13104
13301
|
throw new StreamableHTTPError(response.status, `Failed to open SSE stream: ${response.statusText}`);
|
|
13105
13302
|
}
|
|
13106
|
-
this._handleSseStream(response.body, options);
|
|
13303
|
+
this._handleSseStream(response.body, options, true);
|
|
13107
13304
|
} catch (error) {
|
|
13108
|
-
(
|
|
13305
|
+
(_c = this.onerror) === null || _c === void 0 ? void 0 : _c.call(this, error);
|
|
13109
13306
|
throw error;
|
|
13110
13307
|
}
|
|
13111
13308
|
}
|
|
@@ -13154,7 +13351,7 @@ var StreamableHTTPClientTransport = class {
|
|
|
13154
13351
|
});
|
|
13155
13352
|
}, delay);
|
|
13156
13353
|
}
|
|
13157
|
-
_handleSseStream(stream, options) {
|
|
13354
|
+
_handleSseStream(stream, options, isReconnectable) {
|
|
13158
13355
|
if (!stream) {
|
|
13159
13356
|
return;
|
|
13160
13357
|
}
|
|
@@ -13187,17 +13384,15 @@ var StreamableHTTPClientTransport = class {
|
|
|
13187
13384
|
}
|
|
13188
13385
|
} catch (error) {
|
|
13189
13386
|
(_c = this.onerror) === null || _c === void 0 ? void 0 : _c.call(this, new Error(`SSE stream disconnected: ${error}`));
|
|
13190
|
-
if (this._abortController && !this._abortController.signal.aborted) {
|
|
13191
|
-
|
|
13192
|
-
|
|
13193
|
-
|
|
13194
|
-
|
|
13195
|
-
|
|
13196
|
-
|
|
13197
|
-
|
|
13198
|
-
|
|
13199
|
-
(_d = this.onerror) === null || _d === void 0 ? void 0 : _d.call(this, new Error(`Failed to reconnect: ${error2 instanceof Error ? error2.message : String(error2)}`));
|
|
13200
|
-
}
|
|
13387
|
+
if (isReconnectable && this._abortController && !this._abortController.signal.aborted) {
|
|
13388
|
+
try {
|
|
13389
|
+
this._scheduleReconnection({
|
|
13390
|
+
resumptionToken: lastEventId,
|
|
13391
|
+
onresumptiontoken,
|
|
13392
|
+
replayMessageId
|
|
13393
|
+
}, 0);
|
|
13394
|
+
} catch (error2) {
|
|
13395
|
+
(_d = this.onerror) === null || _d === void 0 ? void 0 : _d.call(this, new Error(`Failed to reconnect: ${error2 instanceof Error ? error2.message : String(error2)}`));
|
|
13201
13396
|
}
|
|
13202
13397
|
}
|
|
13203
13398
|
}
|
|
@@ -13217,7 +13412,7 @@ var StreamableHTTPClientTransport = class {
|
|
|
13217
13412
|
if (!this._authProvider) {
|
|
13218
13413
|
throw new UnauthorizedError("No auth provider");
|
|
13219
13414
|
}
|
|
13220
|
-
const result = await auth(this._authProvider, { serverUrl: this._url, authorizationCode, resourceMetadataUrl: this._resourceMetadataUrl });
|
|
13415
|
+
const result = await auth(this._authProvider, { serverUrl: this._url, authorizationCode, resourceMetadataUrl: this._resourceMetadataUrl, fetchFn: this._fetch });
|
|
13221
13416
|
if (result !== "AUTHORIZED") {
|
|
13222
13417
|
throw new UnauthorizedError("Failed to authorize");
|
|
13223
13418
|
}
|
|
@@ -13228,7 +13423,7 @@ var StreamableHTTPClientTransport = class {
|
|
|
13228
13423
|
(_b = this.onclose) === null || _b === void 0 ? void 0 : _b.call(this);
|
|
13229
13424
|
}
|
|
13230
13425
|
async send(message, options) {
|
|
13231
|
-
var _a, _b, _c;
|
|
13426
|
+
var _a, _b, _c, _d;
|
|
13232
13427
|
try {
|
|
13233
13428
|
const { resumptionToken, onresumptiontoken } = options || {};
|
|
13234
13429
|
if (resumptionToken) {
|
|
@@ -13248,7 +13443,7 @@ var StreamableHTTPClientTransport = class {
|
|
|
13248
13443
|
body: JSON.stringify(message),
|
|
13249
13444
|
signal: (_a = this._abortController) === null || _a === void 0 ? void 0 : _a.signal
|
|
13250
13445
|
};
|
|
13251
|
-
const response = await fetch(this._url, init);
|
|
13446
|
+
const response = await ((_b = this._fetch) !== null && _b !== void 0 ? _b : fetch)(this._url, init);
|
|
13252
13447
|
const sessionId = response.headers.get("mcp-session-id");
|
|
13253
13448
|
if (sessionId) {
|
|
13254
13449
|
this._sessionId = sessionId;
|
|
@@ -13256,7 +13451,7 @@ var StreamableHTTPClientTransport = class {
|
|
|
13256
13451
|
if (!response.ok) {
|
|
13257
13452
|
if (response.status === 401 && this._authProvider) {
|
|
13258
13453
|
this._resourceMetadataUrl = extractResourceMetadataUrl(response);
|
|
13259
|
-
const result = await auth(this._authProvider, { serverUrl: this._url, resourceMetadataUrl: this._resourceMetadataUrl });
|
|
13454
|
+
const result = await auth(this._authProvider, { serverUrl: this._url, resourceMetadataUrl: this._resourceMetadataUrl, fetchFn: this._fetch });
|
|
13260
13455
|
if (result !== "AUTHORIZED") {
|
|
13261
13456
|
throw new UnauthorizedError();
|
|
13262
13457
|
}
|
|
@@ -13279,19 +13474,19 @@ var StreamableHTTPClientTransport = class {
|
|
|
13279
13474
|
const contentType = response.headers.get("content-type");
|
|
13280
13475
|
if (hasRequests) {
|
|
13281
13476
|
if (contentType === null || contentType === void 0 ? void 0 : contentType.includes("text/event-stream")) {
|
|
13282
|
-
this._handleSseStream(response.body, { onresumptiontoken });
|
|
13477
|
+
this._handleSseStream(response.body, { onresumptiontoken }, false);
|
|
13283
13478
|
} else if (contentType === null || contentType === void 0 ? void 0 : contentType.includes("application/json")) {
|
|
13284
13479
|
const data = await response.json();
|
|
13285
13480
|
const responseMessages = Array.isArray(data) ? data.map((msg) => JSONRPCMessageSchema.parse(msg)) : [JSONRPCMessageSchema.parse(data)];
|
|
13286
13481
|
for (const msg of responseMessages) {
|
|
13287
|
-
(
|
|
13482
|
+
(_c = this.onmessage) === null || _c === void 0 ? void 0 : _c.call(this, msg);
|
|
13288
13483
|
}
|
|
13289
13484
|
} else {
|
|
13290
13485
|
throw new StreamableHTTPError(-1, `Unexpected content type: ${contentType}`);
|
|
13291
13486
|
}
|
|
13292
13487
|
}
|
|
13293
13488
|
} catch (error) {
|
|
13294
|
-
(
|
|
13489
|
+
(_d = this.onerror) === null || _d === void 0 ? void 0 : _d.call(this, error);
|
|
13295
13490
|
throw error;
|
|
13296
13491
|
}
|
|
13297
13492
|
}
|
|
@@ -13310,7 +13505,7 @@ var StreamableHTTPClientTransport = class {
|
|
|
13310
13505
|
* the server does not allow clients to terminate sessions.
|
|
13311
13506
|
*/
|
|
13312
13507
|
async terminateSession() {
|
|
13313
|
-
var _a, _b;
|
|
13508
|
+
var _a, _b, _c;
|
|
13314
13509
|
if (!this._sessionId) {
|
|
13315
13510
|
return;
|
|
13316
13511
|
}
|
|
@@ -13322,13 +13517,13 @@ var StreamableHTTPClientTransport = class {
|
|
|
13322
13517
|
headers,
|
|
13323
13518
|
signal: (_a = this._abortController) === null || _a === void 0 ? void 0 : _a.signal
|
|
13324
13519
|
};
|
|
13325
|
-
const response = await fetch(this._url, init);
|
|
13520
|
+
const response = await ((_b = this._fetch) !== null && _b !== void 0 ? _b : fetch)(this._url, init);
|
|
13326
13521
|
if (!response.ok && response.status !== 405) {
|
|
13327
13522
|
throw new StreamableHTTPError(response.status, `Failed to terminate session: ${response.statusText}`);
|
|
13328
13523
|
}
|
|
13329
13524
|
this._sessionId = void 0;
|
|
13330
13525
|
} catch (error) {
|
|
13331
|
-
(
|
|
13526
|
+
(_c = this.onerror) === null || _c === void 0 ? void 0 : _c.call(this, error);
|
|
13332
13527
|
throw error;
|
|
13333
13528
|
}
|
|
13334
13529
|
}
|
|
@@ -13949,6 +14144,7 @@ var NodeOAuthClientProvider = class {
|
|
|
13949
14144
|
this.staticOAuthClientMetadata = options.staticOAuthClientMetadata;
|
|
13950
14145
|
this.staticOAuthClientInfo = options.staticOAuthClientInfo;
|
|
13951
14146
|
this.authorizeResource = options.authorizeResource;
|
|
14147
|
+
this._scopes = options.scopes || "openid email profile";
|
|
13952
14148
|
this._state = randomUUID();
|
|
13953
14149
|
}
|
|
13954
14150
|
serverUrlHash;
|
|
@@ -13960,6 +14156,7 @@ var NodeOAuthClientProvider = class {
|
|
|
13960
14156
|
staticOAuthClientMetadata;
|
|
13961
14157
|
staticOAuthClientInfo;
|
|
13962
14158
|
authorizeResource;
|
|
14159
|
+
_scopes;
|
|
13963
14160
|
_state;
|
|
13964
14161
|
get redirectUrl() {
|
|
13965
14162
|
return `http://${this.options.host}:${this.options.callbackPort}${this.callbackPath}`;
|
|
@@ -13974,6 +14171,7 @@ var NodeOAuthClientProvider = class {
|
|
|
13974
14171
|
client_uri: this.clientUri,
|
|
13975
14172
|
software_id: this.softwareId,
|
|
13976
14173
|
software_version: this.softwareVersion,
|
|
14174
|
+
scope: this._scopes,
|
|
13977
14175
|
...this.staticOAuthClientMetadata
|
|
13978
14176
|
};
|
|
13979
14177
|
}
|
|
@@ -13995,16 +14193,41 @@ var NodeOAuthClientProvider = class {
|
|
|
13995
14193
|
"client_info.json",
|
|
13996
14194
|
OAuthClientInformationFullSchema
|
|
13997
14195
|
);
|
|
14196
|
+
if (clientInfo) {
|
|
14197
|
+
const scopesData = await readJsonFile(this.serverUrlHash, "scopes.json", {
|
|
14198
|
+
parseAsync: async (data) => data
|
|
14199
|
+
});
|
|
14200
|
+
if (scopesData?.scopes) {
|
|
14201
|
+
this._scopes = scopesData.scopes;
|
|
14202
|
+
if (DEBUG) debugLog("Loaded stored scopes from registration", { scopes: this._scopes });
|
|
14203
|
+
}
|
|
14204
|
+
}
|
|
13998
14205
|
if (DEBUG) debugLog("Client info result:", clientInfo ? "Found" : "Not found");
|
|
13999
14206
|
return clientInfo;
|
|
14000
14207
|
}
|
|
14208
|
+
/**
|
|
14209
|
+
* Extracts scopes from OAuth registration response
|
|
14210
|
+
* @param clientInfo The client registration response
|
|
14211
|
+
* @returns The extracted scopes as a space-separated string
|
|
14212
|
+
*/
|
|
14213
|
+
extractScopesFromRegistration(clientInfo) {
|
|
14214
|
+
if (clientInfo.scope) return clientInfo.scope;
|
|
14215
|
+
if (clientInfo.default_scope) return clientInfo.default_scope;
|
|
14216
|
+
if (Array.isArray(clientInfo.scopes)) return clientInfo.scopes.join(" ");
|
|
14217
|
+
if (Array.isArray(clientInfo.default_scopes)) return clientInfo.default_scopes.join(" ");
|
|
14218
|
+
return "openid email profile";
|
|
14219
|
+
}
|
|
14001
14220
|
/**
|
|
14002
14221
|
* Saves client information
|
|
14003
14222
|
* @param clientInformation The client information to save
|
|
14004
14223
|
*/
|
|
14005
14224
|
async saveClientInformation(clientInformation) {
|
|
14006
14225
|
if (DEBUG) debugLog("Saving client info", { client_id: clientInformation.client_id });
|
|
14226
|
+
const scopes = this.extractScopesFromRegistration(clientInformation);
|
|
14227
|
+
if (DEBUG) debugLog("Extracted scopes from registration response", { scopes });
|
|
14228
|
+
this._scopes = scopes;
|
|
14007
14229
|
await writeJsonFile(this.serverUrlHash, "client_info.json", clientInformation);
|
|
14230
|
+
await writeJsonFile(this.serverUrlHash, "scopes.json", { scopes });
|
|
14008
14231
|
}
|
|
14009
14232
|
/**
|
|
14010
14233
|
* Gets the OAuth tokens if they exist
|
|
@@ -14071,6 +14294,10 @@ var NodeOAuthClientProvider = class {
|
|
|
14071
14294
|
if (this.authorizeResource) {
|
|
14072
14295
|
authorizationUrl.searchParams.set("resource", this.authorizeResource);
|
|
14073
14296
|
}
|
|
14297
|
+
if (this._scopes) {
|
|
14298
|
+
authorizationUrl.searchParams.set("scope", this._scopes);
|
|
14299
|
+
if (DEBUG) debugLog("Added scope parameter to authorization URL", { scopes: this._scopes });
|
|
14300
|
+
}
|
|
14074
14301
|
log(`
|
|
14075
14302
|
Please authorize this client by visiting:
|
|
14076
14303
|
${authorizationUrl.toString()}
|
|
@@ -14113,12 +14340,14 @@ ${authorizationUrl.toString()}
|
|
|
14113
14340
|
await Promise.all([
|
|
14114
14341
|
deleteConfigFile(this.serverUrlHash, "client_info.json"),
|
|
14115
14342
|
deleteConfigFile(this.serverUrlHash, "tokens.json"),
|
|
14116
|
-
deleteConfigFile(this.serverUrlHash, "code_verifier.txt")
|
|
14343
|
+
deleteConfigFile(this.serverUrlHash, "code_verifier.txt"),
|
|
14344
|
+
deleteConfigFile(this.serverUrlHash, "scopes.json")
|
|
14117
14345
|
]);
|
|
14118
14346
|
if (DEBUG) debugLog("All credentials invalidated");
|
|
14119
14347
|
break;
|
|
14120
14348
|
case "client":
|
|
14121
|
-
await deleteConfigFile(this.serverUrlHash, "client_info.json");
|
|
14349
|
+
await Promise.all([deleteConfigFile(this.serverUrlHash, "client_info.json"), deleteConfigFile(this.serverUrlHash, "scopes.json")]);
|
|
14350
|
+
this._scopes = this.options.scopes || "openid email profile";
|
|
14122
14351
|
if (DEBUG) debugLog("Client information invalidated");
|
|
14123
14352
|
break;
|
|
14124
14353
|
case "tokens":
|
package/dist/client.js
CHANGED
package/dist/proxy.js
CHANGED
|
@@ -9,15 +9,15 @@ import {
|
|
|
9
9
|
mcpProxy,
|
|
10
10
|
parseCommandLineArgs,
|
|
11
11
|
setupSignalHandlers
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-EP7LWBXW.js";
|
|
13
13
|
|
|
14
14
|
// src/proxy.ts
|
|
15
15
|
import { EventEmitter } from "events";
|
|
16
16
|
|
|
17
|
-
// node_modules/.pnpm/@modelcontextprotocol+sdk@
|
|
17
|
+
// node_modules/.pnpm/@modelcontextprotocol+sdk@1.17.4/node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.js
|
|
18
18
|
import process2 from "node:process";
|
|
19
19
|
|
|
20
|
-
// node_modules/.pnpm/@modelcontextprotocol+sdk@
|
|
20
|
+
// node_modules/.pnpm/@modelcontextprotocol+sdk@1.17.4/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js
|
|
21
21
|
var ReadBuffer = class {
|
|
22
22
|
append(chunk) {
|
|
23
23
|
this._buffer = this._buffer ? Buffer.concat([this._buffer, chunk]) : chunk;
|
|
@@ -45,7 +45,7 @@ function serializeMessage(message) {
|
|
|
45
45
|
return JSON.stringify(message) + "\n";
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
// node_modules/.pnpm/@modelcontextprotocol+sdk@
|
|
48
|
+
// node_modules/.pnpm/@modelcontextprotocol+sdk@1.17.4/node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.js
|
|
49
49
|
var StdioServerTransport = class {
|
|
50
50
|
constructor(_stdin = process2.stdin, _stdout = process2.stdout) {
|
|
51
51
|
this._stdin = _stdin;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mcp-remote",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.20",
|
|
4
4
|
"description": "Remote proxy for Model Context Protocol, allowing local-only clients to connect to remote servers using oAuth",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mcp",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"strict-url-sanitise": "^0.0.1"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@modelcontextprotocol/sdk": "
|
|
39
|
+
"@modelcontextprotocol/sdk": "^1.17.3",
|
|
40
40
|
"@types/express": "^5.0.0",
|
|
41
41
|
"@types/node": "^22.13.10",
|
|
42
42
|
"prettier": "^3.5.3",
|