mcp-proxy 5.11.2 → 5.12.1
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/README.md +71 -49
- package/dist/bin/mcp-proxy.js +31 -35
- package/dist/bin/mcp-proxy.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.js +516 -295
- package/dist/index.js.map +1 -1
- package/dist/{stdio-DQCs94rj.js → stdio-BAyQuMKu.js} +11135 -8848
- package/dist/stdio-BAyQuMKu.js.map +1 -0
- package/jsr.json +1 -1
- package/package.json +19 -19
- package/src/InMemoryEventStore.test.ts +58 -50
- package/src/InMemoryEventStore.ts +2 -3
- package/src/authentication.test.ts +275 -18
- package/src/authentication.ts +57 -5
- package/src/bin/mcp-proxy.ts +2 -1
- package/src/proxyServer.test.ts +40 -22
- package/src/startHTTPServer.test.ts +41 -23
- package/src/startHTTPServer.ts +132 -52
- package/src/startStdioServer.test.ts +8 -5
- package/dist/stdio-DQCs94rj.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,29 @@
|
|
|
1
|
-
import { AuthenticationMiddleware,
|
|
1
|
+
import { C as NEVER, S as _coercedNumber, T as AuthenticationMiddleware, _ as looseObject, a as startHTTPServer, b as string, c as LATEST_PROTOCOL_VERSION, d as isJSONRPCResponse, f as ZodNumber, g as literal, h as boolean, i as Client, l as isInitializedNotification, m as array, n as serializeMessage, o as proxyServer, p as any, r as Server, s as JSONRPCMessageSchema, t as ReadBuffer, u as isJSONRPCRequest, v as number$1, w as InMemoryEventStore, x as url, y as object } from "./stdio-BAyQuMKu.js";
|
|
2
2
|
import process from "node:process";
|
|
3
3
|
|
|
4
|
+
//#region node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/classic/compat.js
|
|
5
|
+
/** @deprecated Use the raw string literal codes instead, e.g. "invalid_type". */
|
|
6
|
+
const ZodIssueCode = {
|
|
7
|
+
invalid_type: "invalid_type",
|
|
8
|
+
too_big: "too_big",
|
|
9
|
+
too_small: "too_small",
|
|
10
|
+
invalid_format: "invalid_format",
|
|
11
|
+
not_multiple_of: "not_multiple_of",
|
|
12
|
+
unrecognized_keys: "unrecognized_keys",
|
|
13
|
+
invalid_union: "invalid_union",
|
|
14
|
+
invalid_key: "invalid_key",
|
|
15
|
+
invalid_element: "invalid_element",
|
|
16
|
+
invalid_value: "invalid_value",
|
|
17
|
+
custom: "custom"
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/classic/coerce.js
|
|
22
|
+
function number(params) {
|
|
23
|
+
return _coercedNumber(ZodNumber, params);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
4
27
|
//#region node_modules/.pnpm/eventsource-parser@3.0.6/node_modules/eventsource-parser/dist/index.js
|
|
5
28
|
var ParseError = class extends Error {
|
|
6
29
|
constructor(message, options) {
|
|
@@ -28,8 +51,8 @@ function createParser(callbacks) {
|
|
|
28
51
|
}
|
|
29
52
|
const fieldSeparatorIndex = line.indexOf(":");
|
|
30
53
|
if (fieldSeparatorIndex !== -1) {
|
|
31
|
-
const field = line.slice(0, fieldSeparatorIndex), offset = line[fieldSeparatorIndex + 1] === " " ? 2 : 1
|
|
32
|
-
processField(field,
|
|
54
|
+
const field = line.slice(0, fieldSeparatorIndex), offset = line[fieldSeparatorIndex + 1] === " " ? 2 : 1;
|
|
55
|
+
processField(field, line.slice(fieldSeparatorIndex + offset), line);
|
|
33
56
|
return;
|
|
34
57
|
}
|
|
35
58
|
processField(line, "", line);
|
|
@@ -163,7 +186,7 @@ var __typeError = (msg) => {
|
|
|
163
186
|
throw TypeError(msg);
|
|
164
187
|
}, __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg), __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)), __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value), __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value), __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method), _readyState, _url, _redirectUrl, _withCredentials, _fetch, _reconnectInterval, _reconnectTimer, _lastEventId, _controller, _parser, _onError, _onMessage, _onOpen, _EventSource_instances, connect_fn, _onFetchResponse, _onFetchError, getRequestOptions_fn, _onEvent, _onRetryChange, failConnection_fn, scheduleReconnect_fn, _reconnect;
|
|
165
188
|
var EventSource = class extends EventTarget {
|
|
166
|
-
constructor(url, eventSourceInitDict) {
|
|
189
|
+
constructor(url$1, eventSourceInitDict) {
|
|
167
190
|
var _a, _b;
|
|
168
191
|
super(), __privateAdd(this, _EventSource_instances), this.CONNECTING = 0, this.OPEN = 1, this.CLOSED = 2, __privateAdd(this, _readyState), __privateAdd(this, _url), __privateAdd(this, _redirectUrl), __privateAdd(this, _withCredentials), __privateAdd(this, _fetch), __privateAdd(this, _reconnectInterval), __privateAdd(this, _reconnectTimer), __privateAdd(this, _lastEventId, null), __privateAdd(this, _controller), __privateAdd(this, _parser), __privateAdd(this, _onError, null), __privateAdd(this, _onMessage, null), __privateAdd(this, _onOpen, null), __privateAdd(this, _onFetchResponse, async (response) => {
|
|
169
192
|
var _a2;
|
|
@@ -210,8 +233,8 @@ var EventSource = class extends EventTarget {
|
|
|
210
233
|
__privateSet(this, _reconnectTimer, void 0), __privateGet(this, _readyState) === this.CONNECTING && __privateMethod(this, _EventSource_instances, connect_fn).call(this);
|
|
211
234
|
});
|
|
212
235
|
try {
|
|
213
|
-
if (url instanceof URL) __privateSet(this, _url, url);
|
|
214
|
-
else if (typeof url == "string") __privateSet(this, _url, new URL(url, getBaseURL()));
|
|
236
|
+
if (url$1 instanceof URL) __privateSet(this, _url, url$1);
|
|
237
|
+
else if (typeof url$1 == "string") __privateSet(this, _url, new URL(url$1, getBaseURL()));
|
|
215
238
|
else throw new Error("Invalid URL");
|
|
216
239
|
} catch {
|
|
217
240
|
throw syntaxError("An invalid or illegal string was specified");
|
|
@@ -330,6 +353,40 @@ function getBaseURL() {
|
|
|
330
353
|
return doc && typeof doc == "object" && "baseURI" in doc && typeof doc.baseURI == "string" ? doc.baseURI : void 0;
|
|
331
354
|
}
|
|
332
355
|
|
|
356
|
+
//#endregion
|
|
357
|
+
//#region node_modules/.pnpm/@modelcontextprotocol+sdk@1.24.3_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/transport.js
|
|
358
|
+
/**
|
|
359
|
+
* Normalizes HeadersInit to a plain Record<string, string> for manipulation.
|
|
360
|
+
* Handles Headers objects, arrays of tuples, and plain objects.
|
|
361
|
+
*/
|
|
362
|
+
function normalizeHeaders(headers) {
|
|
363
|
+
if (!headers) return {};
|
|
364
|
+
if (headers instanceof Headers) return Object.fromEntries(headers.entries());
|
|
365
|
+
if (Array.isArray(headers)) return Object.fromEntries(headers);
|
|
366
|
+
return { ...headers };
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Creates a fetch function that includes base RequestInit options.
|
|
370
|
+
* This ensures requests inherit settings like credentials, mode, headers, etc. from the base init.
|
|
371
|
+
*
|
|
372
|
+
* @param baseFetch - The base fetch function to wrap (defaults to global fetch)
|
|
373
|
+
* @param baseInit - The base RequestInit to merge with each request
|
|
374
|
+
* @returns A wrapped fetch function that merges base options with call-specific options
|
|
375
|
+
*/
|
|
376
|
+
function createFetchWithInit(baseFetch = fetch, baseInit) {
|
|
377
|
+
if (!baseInit) return baseFetch;
|
|
378
|
+
return async (url$1, init) => {
|
|
379
|
+
return baseFetch(url$1, {
|
|
380
|
+
...baseInit,
|
|
381
|
+
...init,
|
|
382
|
+
headers: (init === null || init === void 0 ? void 0 : init.headers) ? {
|
|
383
|
+
...normalizeHeaders(baseInit.headers),
|
|
384
|
+
...normalizeHeaders(init.headers)
|
|
385
|
+
} : baseInit.headers
|
|
386
|
+
});
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
|
|
333
390
|
//#endregion
|
|
334
391
|
//#region node_modules/.pnpm/pkce-challenge@5.0.0/node_modules/pkce-challenge/dist/index.node.js
|
|
335
392
|
let crypto;
|
|
@@ -379,19 +436,18 @@ async function pkceChallenge(length) {
|
|
|
379
436
|
if (!length) length = 43;
|
|
380
437
|
if (length < 43 || length > 128) throw `Expected a length between 43 and 128. Received ${length}.`;
|
|
381
438
|
const verifier = await generateVerifier(length);
|
|
382
|
-
const challenge = await generateChallenge(verifier);
|
|
383
439
|
return {
|
|
384
440
|
code_verifier: verifier,
|
|
385
|
-
code_challenge:
|
|
441
|
+
code_challenge: await generateChallenge(verifier)
|
|
386
442
|
};
|
|
387
443
|
}
|
|
388
444
|
|
|
389
445
|
//#endregion
|
|
390
|
-
//#region node_modules/.pnpm/@modelcontextprotocol+sdk@1.
|
|
446
|
+
//#region node_modules/.pnpm/@modelcontextprotocol+sdk@1.24.3_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/auth.js
|
|
391
447
|
/**
|
|
392
448
|
* Reusable URL validation that disallows javascript: scheme
|
|
393
449
|
*/
|
|
394
|
-
const SafeUrlSchema =
|
|
450
|
+
const SafeUrlSchema = url().superRefine((val, ctx) => {
|
|
395
451
|
if (!URL.canParse(val)) {
|
|
396
452
|
ctx.addIssue({
|
|
397
453
|
code: ZodIssueCode.custom,
|
|
@@ -400,147 +456,156 @@ const SafeUrlSchema = stringType().url().superRefine((val, ctx) => {
|
|
|
400
456
|
});
|
|
401
457
|
return NEVER;
|
|
402
458
|
}
|
|
403
|
-
}).refine((url) => {
|
|
404
|
-
const u = new URL(url);
|
|
459
|
+
}).refine((url$1) => {
|
|
460
|
+
const u = new URL(url$1);
|
|
405
461
|
return u.protocol !== "javascript:" && u.protocol !== "data:" && u.protocol !== "vbscript:";
|
|
406
462
|
}, { message: "URL cannot use javascript:, data:, or vbscript: scheme" });
|
|
407
463
|
/**
|
|
408
464
|
* RFC 9728 OAuth Protected Resource Metadata
|
|
409
465
|
*/
|
|
410
|
-
const OAuthProtectedResourceMetadataSchema =
|
|
411
|
-
resource:
|
|
412
|
-
authorization_servers:
|
|
413
|
-
jwks_uri:
|
|
414
|
-
scopes_supported:
|
|
415
|
-
bearer_methods_supported:
|
|
416
|
-
resource_signing_alg_values_supported:
|
|
417
|
-
resource_name:
|
|
418
|
-
resource_documentation:
|
|
419
|
-
resource_policy_uri:
|
|
420
|
-
resource_tos_uri:
|
|
421
|
-
tls_client_certificate_bound_access_tokens:
|
|
422
|
-
authorization_details_types_supported:
|
|
423
|
-
dpop_signing_alg_values_supported:
|
|
424
|
-
dpop_bound_access_tokens_required:
|
|
425
|
-
})
|
|
466
|
+
const OAuthProtectedResourceMetadataSchema = looseObject({
|
|
467
|
+
resource: string().url(),
|
|
468
|
+
authorization_servers: array(SafeUrlSchema).optional(),
|
|
469
|
+
jwks_uri: string().url().optional(),
|
|
470
|
+
scopes_supported: array(string()).optional(),
|
|
471
|
+
bearer_methods_supported: array(string()).optional(),
|
|
472
|
+
resource_signing_alg_values_supported: array(string()).optional(),
|
|
473
|
+
resource_name: string().optional(),
|
|
474
|
+
resource_documentation: string().optional(),
|
|
475
|
+
resource_policy_uri: string().url().optional(),
|
|
476
|
+
resource_tos_uri: string().url().optional(),
|
|
477
|
+
tls_client_certificate_bound_access_tokens: boolean().optional(),
|
|
478
|
+
authorization_details_types_supported: array(string()).optional(),
|
|
479
|
+
dpop_signing_alg_values_supported: array(string()).optional(),
|
|
480
|
+
dpop_bound_access_tokens_required: boolean().optional()
|
|
481
|
+
});
|
|
426
482
|
/**
|
|
427
483
|
* RFC 8414 OAuth 2.0 Authorization Server Metadata
|
|
428
484
|
*/
|
|
429
|
-
const OAuthMetadataSchema =
|
|
430
|
-
issuer:
|
|
485
|
+
const OAuthMetadataSchema = looseObject({
|
|
486
|
+
issuer: string(),
|
|
431
487
|
authorization_endpoint: SafeUrlSchema,
|
|
432
488
|
token_endpoint: SafeUrlSchema,
|
|
433
489
|
registration_endpoint: SafeUrlSchema.optional(),
|
|
434
|
-
scopes_supported:
|
|
435
|
-
response_types_supported:
|
|
436
|
-
response_modes_supported:
|
|
437
|
-
grant_types_supported:
|
|
438
|
-
token_endpoint_auth_methods_supported:
|
|
439
|
-
token_endpoint_auth_signing_alg_values_supported:
|
|
490
|
+
scopes_supported: array(string()).optional(),
|
|
491
|
+
response_types_supported: array(string()),
|
|
492
|
+
response_modes_supported: array(string()).optional(),
|
|
493
|
+
grant_types_supported: array(string()).optional(),
|
|
494
|
+
token_endpoint_auth_methods_supported: array(string()).optional(),
|
|
495
|
+
token_endpoint_auth_signing_alg_values_supported: array(string()).optional(),
|
|
440
496
|
service_documentation: SafeUrlSchema.optional(),
|
|
441
497
|
revocation_endpoint: SafeUrlSchema.optional(),
|
|
442
|
-
revocation_endpoint_auth_methods_supported:
|
|
443
|
-
revocation_endpoint_auth_signing_alg_values_supported:
|
|
444
|
-
introspection_endpoint:
|
|
445
|
-
introspection_endpoint_auth_methods_supported:
|
|
446
|
-
introspection_endpoint_auth_signing_alg_values_supported:
|
|
447
|
-
code_challenge_methods_supported:
|
|
448
|
-
|
|
498
|
+
revocation_endpoint_auth_methods_supported: array(string()).optional(),
|
|
499
|
+
revocation_endpoint_auth_signing_alg_values_supported: array(string()).optional(),
|
|
500
|
+
introspection_endpoint: string().optional(),
|
|
501
|
+
introspection_endpoint_auth_methods_supported: array(string()).optional(),
|
|
502
|
+
introspection_endpoint_auth_signing_alg_values_supported: array(string()).optional(),
|
|
503
|
+
code_challenge_methods_supported: array(string()).optional(),
|
|
504
|
+
client_id_metadata_document_supported: boolean().optional()
|
|
505
|
+
});
|
|
449
506
|
/**
|
|
450
507
|
* OpenID Connect Discovery 1.0 Provider Metadata
|
|
451
508
|
* see: https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata
|
|
452
509
|
*/
|
|
453
|
-
const OpenIdProviderMetadataSchema =
|
|
454
|
-
issuer:
|
|
510
|
+
const OpenIdProviderMetadataSchema = looseObject({
|
|
511
|
+
issuer: string(),
|
|
455
512
|
authorization_endpoint: SafeUrlSchema,
|
|
456
513
|
token_endpoint: SafeUrlSchema,
|
|
457
514
|
userinfo_endpoint: SafeUrlSchema.optional(),
|
|
458
515
|
jwks_uri: SafeUrlSchema,
|
|
459
516
|
registration_endpoint: SafeUrlSchema.optional(),
|
|
460
|
-
scopes_supported:
|
|
461
|
-
response_types_supported:
|
|
462
|
-
response_modes_supported:
|
|
463
|
-
grant_types_supported:
|
|
464
|
-
acr_values_supported:
|
|
465
|
-
subject_types_supported:
|
|
466
|
-
id_token_signing_alg_values_supported:
|
|
467
|
-
id_token_encryption_alg_values_supported:
|
|
468
|
-
id_token_encryption_enc_values_supported:
|
|
469
|
-
userinfo_signing_alg_values_supported:
|
|
470
|
-
userinfo_encryption_alg_values_supported:
|
|
471
|
-
userinfo_encryption_enc_values_supported:
|
|
472
|
-
request_object_signing_alg_values_supported:
|
|
473
|
-
request_object_encryption_alg_values_supported:
|
|
474
|
-
request_object_encryption_enc_values_supported:
|
|
475
|
-
token_endpoint_auth_methods_supported:
|
|
476
|
-
token_endpoint_auth_signing_alg_values_supported:
|
|
477
|
-
display_values_supported:
|
|
478
|
-
claim_types_supported:
|
|
479
|
-
claims_supported:
|
|
480
|
-
service_documentation:
|
|
481
|
-
claims_locales_supported:
|
|
482
|
-
ui_locales_supported:
|
|
483
|
-
claims_parameter_supported:
|
|
484
|
-
request_parameter_supported:
|
|
485
|
-
request_uri_parameter_supported:
|
|
486
|
-
require_request_uri_registration:
|
|
517
|
+
scopes_supported: array(string()).optional(),
|
|
518
|
+
response_types_supported: array(string()),
|
|
519
|
+
response_modes_supported: array(string()).optional(),
|
|
520
|
+
grant_types_supported: array(string()).optional(),
|
|
521
|
+
acr_values_supported: array(string()).optional(),
|
|
522
|
+
subject_types_supported: array(string()),
|
|
523
|
+
id_token_signing_alg_values_supported: array(string()),
|
|
524
|
+
id_token_encryption_alg_values_supported: array(string()).optional(),
|
|
525
|
+
id_token_encryption_enc_values_supported: array(string()).optional(),
|
|
526
|
+
userinfo_signing_alg_values_supported: array(string()).optional(),
|
|
527
|
+
userinfo_encryption_alg_values_supported: array(string()).optional(),
|
|
528
|
+
userinfo_encryption_enc_values_supported: array(string()).optional(),
|
|
529
|
+
request_object_signing_alg_values_supported: array(string()).optional(),
|
|
530
|
+
request_object_encryption_alg_values_supported: array(string()).optional(),
|
|
531
|
+
request_object_encryption_enc_values_supported: array(string()).optional(),
|
|
532
|
+
token_endpoint_auth_methods_supported: array(string()).optional(),
|
|
533
|
+
token_endpoint_auth_signing_alg_values_supported: array(string()).optional(),
|
|
534
|
+
display_values_supported: array(string()).optional(),
|
|
535
|
+
claim_types_supported: array(string()).optional(),
|
|
536
|
+
claims_supported: array(string()).optional(),
|
|
537
|
+
service_documentation: string().optional(),
|
|
538
|
+
claims_locales_supported: array(string()).optional(),
|
|
539
|
+
ui_locales_supported: array(string()).optional(),
|
|
540
|
+
claims_parameter_supported: boolean().optional(),
|
|
541
|
+
request_parameter_supported: boolean().optional(),
|
|
542
|
+
request_uri_parameter_supported: boolean().optional(),
|
|
543
|
+
require_request_uri_registration: boolean().optional(),
|
|
487
544
|
op_policy_uri: SafeUrlSchema.optional(),
|
|
488
|
-
op_tos_uri: SafeUrlSchema.optional()
|
|
489
|
-
|
|
545
|
+
op_tos_uri: SafeUrlSchema.optional(),
|
|
546
|
+
client_id_metadata_document_supported: boolean().optional()
|
|
547
|
+
});
|
|
490
548
|
/**
|
|
491
549
|
* OpenID Connect Discovery metadata that may include OAuth 2.0 fields
|
|
492
550
|
* This schema represents the real-world scenario where OIDC providers
|
|
493
551
|
* return a mix of OpenID Connect and OAuth 2.0 metadata fields
|
|
494
552
|
*/
|
|
495
|
-
const OpenIdProviderDiscoveryMetadataSchema =
|
|
553
|
+
const OpenIdProviderDiscoveryMetadataSchema = object({
|
|
554
|
+
...OpenIdProviderMetadataSchema.shape,
|
|
555
|
+
...OAuthMetadataSchema.pick({ code_challenge_methods_supported: true }).shape
|
|
556
|
+
});
|
|
496
557
|
/**
|
|
497
558
|
* OAuth 2.1 token response
|
|
498
559
|
*/
|
|
499
|
-
const OAuthTokensSchema =
|
|
500
|
-
access_token:
|
|
501
|
-
id_token:
|
|
502
|
-
token_type:
|
|
503
|
-
expires_in:
|
|
504
|
-
scope:
|
|
505
|
-
refresh_token:
|
|
560
|
+
const OAuthTokensSchema = object({
|
|
561
|
+
access_token: string(),
|
|
562
|
+
id_token: string().optional(),
|
|
563
|
+
token_type: string(),
|
|
564
|
+
expires_in: number().optional(),
|
|
565
|
+
scope: string().optional(),
|
|
566
|
+
refresh_token: string().optional()
|
|
506
567
|
}).strip();
|
|
507
568
|
/**
|
|
508
569
|
* OAuth 2.1 error response
|
|
509
570
|
*/
|
|
510
|
-
const OAuthErrorResponseSchema =
|
|
511
|
-
error:
|
|
512
|
-
error_description:
|
|
513
|
-
error_uri:
|
|
571
|
+
const OAuthErrorResponseSchema = object({
|
|
572
|
+
error: string(),
|
|
573
|
+
error_description: string().optional(),
|
|
574
|
+
error_uri: string().optional()
|
|
514
575
|
});
|
|
515
576
|
/**
|
|
577
|
+
* Optional version of SafeUrlSchema that allows empty string for retrocompatibility on tos_uri and logo_uri
|
|
578
|
+
*/
|
|
579
|
+
const OptionalSafeUrlSchema = SafeUrlSchema.optional().or(literal("").transform(() => void 0));
|
|
580
|
+
/**
|
|
516
581
|
* RFC 7591 OAuth 2.0 Dynamic Client Registration metadata
|
|
517
582
|
*/
|
|
518
|
-
const OAuthClientMetadataSchema =
|
|
519
|
-
redirect_uris:
|
|
520
|
-
token_endpoint_auth_method:
|
|
521
|
-
grant_types:
|
|
522
|
-
response_types:
|
|
523
|
-
client_name:
|
|
583
|
+
const OAuthClientMetadataSchema = object({
|
|
584
|
+
redirect_uris: array(SafeUrlSchema),
|
|
585
|
+
token_endpoint_auth_method: string().optional(),
|
|
586
|
+
grant_types: array(string()).optional(),
|
|
587
|
+
response_types: array(string()).optional(),
|
|
588
|
+
client_name: string().optional(),
|
|
524
589
|
client_uri: SafeUrlSchema.optional(),
|
|
525
|
-
logo_uri:
|
|
526
|
-
scope:
|
|
527
|
-
contacts:
|
|
528
|
-
tos_uri:
|
|
529
|
-
policy_uri:
|
|
590
|
+
logo_uri: OptionalSafeUrlSchema,
|
|
591
|
+
scope: string().optional(),
|
|
592
|
+
contacts: array(string()).optional(),
|
|
593
|
+
tos_uri: OptionalSafeUrlSchema,
|
|
594
|
+
policy_uri: string().optional(),
|
|
530
595
|
jwks_uri: SafeUrlSchema.optional(),
|
|
531
|
-
jwks:
|
|
532
|
-
software_id:
|
|
533
|
-
software_version:
|
|
534
|
-
software_statement:
|
|
596
|
+
jwks: any().optional(),
|
|
597
|
+
software_id: string().optional(),
|
|
598
|
+
software_version: string().optional(),
|
|
599
|
+
software_statement: string().optional()
|
|
535
600
|
}).strip();
|
|
536
601
|
/**
|
|
537
602
|
* RFC 7591 OAuth 2.0 Dynamic Client Registration client information
|
|
538
603
|
*/
|
|
539
|
-
const OAuthClientInformationSchema =
|
|
540
|
-
client_id:
|
|
541
|
-
client_secret:
|
|
542
|
-
client_id_issued_at:
|
|
543
|
-
client_secret_expires_at:
|
|
604
|
+
const OAuthClientInformationSchema = object({
|
|
605
|
+
client_id: string(),
|
|
606
|
+
client_secret: string().optional(),
|
|
607
|
+
client_id_issued_at: number$1().optional(),
|
|
608
|
+
client_secret_expires_at: number$1().optional()
|
|
544
609
|
}).strip();
|
|
545
610
|
/**
|
|
546
611
|
* RFC 7591 OAuth 2.0 Dynamic Client Registration full response (client information plus metadata)
|
|
@@ -549,20 +614,20 @@ const OAuthClientInformationFullSchema = OAuthClientMetadataSchema.merge(OAuthCl
|
|
|
549
614
|
/**
|
|
550
615
|
* RFC 7591 OAuth 2.0 Dynamic Client Registration error response
|
|
551
616
|
*/
|
|
552
|
-
const OAuthClientRegistrationErrorSchema =
|
|
553
|
-
error:
|
|
554
|
-
error_description:
|
|
617
|
+
const OAuthClientRegistrationErrorSchema = object({
|
|
618
|
+
error: string(),
|
|
619
|
+
error_description: string().optional()
|
|
555
620
|
}).strip();
|
|
556
621
|
/**
|
|
557
622
|
* RFC 7009 OAuth 2.0 Token Revocation request
|
|
558
623
|
*/
|
|
559
|
-
const OAuthTokenRevocationRequestSchema =
|
|
560
|
-
token:
|
|
561
|
-
token_type_hint:
|
|
624
|
+
const OAuthTokenRevocationRequestSchema = object({
|
|
625
|
+
token: string(),
|
|
626
|
+
token_type_hint: string().optional()
|
|
562
627
|
}).strip();
|
|
563
628
|
|
|
564
629
|
//#endregion
|
|
565
|
-
//#region node_modules/.pnpm/@modelcontextprotocol+sdk@1.
|
|
630
|
+
//#region node_modules/.pnpm/@modelcontextprotocol+sdk@1.24.3_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/auth-utils.js
|
|
566
631
|
/**
|
|
567
632
|
* Utilities for handling OAuth resource URIs.
|
|
568
633
|
*/
|
|
@@ -571,8 +636,8 @@ const OAuthTokenRevocationRequestSchema = objectType({
|
|
|
571
636
|
* RFC 8707 section 2 states that resource URIs "MUST NOT include a fragment component".
|
|
572
637
|
* Keeps everything else unchanged (scheme, domain, port, path, query).
|
|
573
638
|
*/
|
|
574
|
-
function resourceUrlFromServerUrl(url) {
|
|
575
|
-
const resourceURL = typeof url === "string" ? new URL(url) : new URL(url.href);
|
|
639
|
+
function resourceUrlFromServerUrl(url$1) {
|
|
640
|
+
const resourceURL = typeof url$1 === "string" ? new URL(url$1) : new URL(url$1.href);
|
|
576
641
|
resourceURL.hash = "";
|
|
577
642
|
return resourceURL;
|
|
578
643
|
}
|
|
@@ -596,7 +661,7 @@ function checkResourceAllowed({ requestedResource, configuredResource }) {
|
|
|
596
661
|
}
|
|
597
662
|
|
|
598
663
|
//#endregion
|
|
599
|
-
//#region node_modules/.pnpm/@modelcontextprotocol+sdk@1.
|
|
664
|
+
//#region node_modules/.pnpm/@modelcontextprotocol+sdk@1.24.3_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/server/auth/errors.js
|
|
600
665
|
/**
|
|
601
666
|
* Base class for all OAuth errors
|
|
602
667
|
*/
|
|
@@ -718,6 +783,12 @@ InvalidClientMetadataError.errorCode = "invalid_client_metadata";
|
|
|
718
783
|
var InsufficientScopeError = class extends OAuthError {};
|
|
719
784
|
InsufficientScopeError.errorCode = "insufficient_scope";
|
|
720
785
|
/**
|
|
786
|
+
* Invalid target error - The requested resource is invalid, missing, unknown, or malformed.
|
|
787
|
+
* (Custom error for resource indicators - RFC 8707)
|
|
788
|
+
*/
|
|
789
|
+
var InvalidTargetError = class extends OAuthError {};
|
|
790
|
+
InvalidTargetError.errorCode = "invalid_target";
|
|
791
|
+
/**
|
|
721
792
|
* A full list of all OAuthErrors, enabling parsing from error responses
|
|
722
793
|
*/
|
|
723
794
|
const OAUTH_ERRORS = {
|
|
@@ -736,16 +807,26 @@ const OAUTH_ERRORS = {
|
|
|
736
807
|
[MethodNotAllowedError.errorCode]: MethodNotAllowedError,
|
|
737
808
|
[TooManyRequestsError.errorCode]: TooManyRequestsError,
|
|
738
809
|
[InvalidClientMetadataError.errorCode]: InvalidClientMetadataError,
|
|
739
|
-
[InsufficientScopeError.errorCode]: InsufficientScopeError
|
|
810
|
+
[InsufficientScopeError.errorCode]: InsufficientScopeError,
|
|
811
|
+
[InvalidTargetError.errorCode]: InvalidTargetError
|
|
740
812
|
};
|
|
741
813
|
|
|
742
814
|
//#endregion
|
|
743
|
-
//#region node_modules/.pnpm/@modelcontextprotocol+sdk@1.
|
|
815
|
+
//#region node_modules/.pnpm/@modelcontextprotocol+sdk@1.24.3_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/client/auth.js
|
|
744
816
|
var UnauthorizedError = class extends Error {
|
|
745
817
|
constructor(message) {
|
|
746
818
|
super(message !== null && message !== void 0 ? message : "Unauthorized");
|
|
747
819
|
}
|
|
748
820
|
};
|
|
821
|
+
function isClientAuthMethod(method) {
|
|
822
|
+
return [
|
|
823
|
+
"client_secret_basic",
|
|
824
|
+
"client_secret_post",
|
|
825
|
+
"none"
|
|
826
|
+
].includes(method);
|
|
827
|
+
}
|
|
828
|
+
const AUTHORIZATION_CODE_RESPONSE_TYPE = "code";
|
|
829
|
+
const AUTHORIZATION_CODE_CHALLENGE_METHOD = "S256";
|
|
749
830
|
/**
|
|
750
831
|
* Determines the best client authentication method to use based on server support and client configuration.
|
|
751
832
|
*
|
|
@@ -761,6 +842,7 @@ var UnauthorizedError = class extends Error {
|
|
|
761
842
|
function selectClientAuthMethod(clientInformation, supportedMethods) {
|
|
762
843
|
const hasClientSecret = clientInformation.client_secret !== void 0;
|
|
763
844
|
if (supportedMethods.length === 0) return hasClientSecret ? "client_secret_post" : "none";
|
|
845
|
+
if ("token_endpoint_auth_method" in clientInformation && clientInformation.token_endpoint_auth_method && isClientAuthMethod(clientInformation.token_endpoint_auth_method) && supportedMethods.includes(clientInformation.token_endpoint_auth_method)) return clientInformation.token_endpoint_auth_method;
|
|
764
846
|
if (hasClientSecret && supportedMethods.includes("client_secret_basic")) return "client_secret_basic";
|
|
765
847
|
if (hasClientSecret && supportedMethods.includes("client_secret_post")) return "client_secret_post";
|
|
766
848
|
if (supportedMethods.includes("none")) return "none";
|
|
@@ -834,8 +916,7 @@ async function parseErrorResponse(input) {
|
|
|
834
916
|
const { error, error_description, error_uri } = OAuthErrorResponseSchema.parse(JSON.parse(body));
|
|
835
917
|
return new (OAUTH_ERRORS[error] || ServerError)(error_description || "", error_uri);
|
|
836
918
|
} catch (error) {
|
|
837
|
-
|
|
838
|
-
return new ServerError(errorMessage);
|
|
919
|
+
return new ServerError(`${statusCode ? `HTTP ${statusCode}: ` : ""}Invalid OAuth error response: ${error}. Raw body: ${body}`);
|
|
839
920
|
}
|
|
840
921
|
}
|
|
841
922
|
/**
|
|
@@ -860,41 +941,46 @@ async function auth(provider, options) {
|
|
|
860
941
|
}
|
|
861
942
|
}
|
|
862
943
|
async function authInternal(provider, { serverUrl, authorizationCode, scope, resourceMetadataUrl, fetchFn }) {
|
|
944
|
+
var _a, _b;
|
|
863
945
|
let resourceMetadata;
|
|
864
946
|
let authorizationServerUrl;
|
|
865
947
|
try {
|
|
866
948
|
resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl }, fetchFn);
|
|
867
949
|
if (resourceMetadata.authorization_servers && resourceMetadata.authorization_servers.length > 0) authorizationServerUrl = resourceMetadata.authorization_servers[0];
|
|
868
|
-
} catch (
|
|
950
|
+
} catch (_c) {}
|
|
869
951
|
/**
|
|
870
952
|
* If we don't get a valid authorization server metadata from protected resource metadata,
|
|
871
|
-
* fallback to the legacy MCP spec's implementation (version 2025-03-26): MCP server acts as the Authorization server.
|
|
953
|
+
* fallback to the legacy MCP spec's implementation (version 2025-03-26): MCP server base URL acts as the Authorization server.
|
|
872
954
|
*/
|
|
873
|
-
if (!authorizationServerUrl) authorizationServerUrl = serverUrl;
|
|
955
|
+
if (!authorizationServerUrl) authorizationServerUrl = new URL("/", serverUrl);
|
|
874
956
|
const resource = await selectResourceURL(serverUrl, provider, resourceMetadata);
|
|
875
957
|
const metadata = await discoverAuthorizationServerMetadata(authorizationServerUrl, { fetchFn });
|
|
876
958
|
let clientInformation = await Promise.resolve(provider.clientInformation());
|
|
877
959
|
if (!clientInformation) {
|
|
878
960
|
if (authorizationCode !== void 0) throw new Error("Existing OAuth client information is required when exchanging an authorization code");
|
|
879
|
-
|
|
880
|
-
const
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
961
|
+
const supportsUrlBasedClientId = (metadata === null || metadata === void 0 ? void 0 : metadata.client_id_metadata_document_supported) === true;
|
|
962
|
+
const clientMetadataUrl = provider.clientMetadataUrl;
|
|
963
|
+
if (clientMetadataUrl && !isHttpsUrl(clientMetadataUrl)) throw new InvalidClientMetadataError(`clientMetadataUrl must be a valid HTTPS URL with a non-root pathname, got: ${clientMetadataUrl}`);
|
|
964
|
+
if (supportsUrlBasedClientId && clientMetadataUrl) {
|
|
965
|
+
clientInformation = { client_id: clientMetadataUrl };
|
|
966
|
+
await ((_a = provider.saveClientInformation) === null || _a === void 0 ? void 0 : _a.call(provider, clientInformation));
|
|
967
|
+
} else {
|
|
968
|
+
if (!provider.saveClientInformation) throw new Error("OAuth client information must be saveable for dynamic registration");
|
|
969
|
+
const fullInformation = await registerClient(authorizationServerUrl, {
|
|
970
|
+
metadata,
|
|
971
|
+
clientMetadata: provider.clientMetadata,
|
|
972
|
+
fetchFn
|
|
973
|
+
});
|
|
974
|
+
await provider.saveClientInformation(fullInformation);
|
|
975
|
+
clientInformation = fullInformation;
|
|
976
|
+
}
|
|
887
977
|
}
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
const tokens$1 = await
|
|
978
|
+
const nonInteractiveFlow = !provider.redirectUrl;
|
|
979
|
+
if (authorizationCode !== void 0 || nonInteractiveFlow) {
|
|
980
|
+
const tokens$1 = await fetchToken(provider, authorizationServerUrl, {
|
|
891
981
|
metadata,
|
|
892
|
-
clientInformation,
|
|
893
|
-
authorizationCode,
|
|
894
|
-
codeVerifier: codeVerifier$1,
|
|
895
|
-
redirectUri: provider.redirectUrl,
|
|
896
982
|
resource,
|
|
897
|
-
|
|
983
|
+
authorizationCode,
|
|
898
984
|
fetchFn
|
|
899
985
|
});
|
|
900
986
|
await provider.saveTokens(tokens$1);
|
|
@@ -921,13 +1007,26 @@ async function authInternal(provider, { serverUrl, authorizationCode, scope, res
|
|
|
921
1007
|
clientInformation,
|
|
922
1008
|
state,
|
|
923
1009
|
redirectUrl: provider.redirectUrl,
|
|
924
|
-
scope: scope || provider.clientMetadata.scope,
|
|
1010
|
+
scope: scope || ((_b = resourceMetadata === null || resourceMetadata === void 0 ? void 0 : resourceMetadata.scopes_supported) === null || _b === void 0 ? void 0 : _b.join(" ")) || provider.clientMetadata.scope,
|
|
925
1011
|
resource
|
|
926
1012
|
});
|
|
927
1013
|
await provider.saveCodeVerifier(codeVerifier);
|
|
928
1014
|
await provider.redirectToAuthorization(authorizationUrl);
|
|
929
1015
|
return "REDIRECT";
|
|
930
1016
|
}
|
|
1017
|
+
/**
|
|
1018
|
+
* SEP-991: URL-based Client IDs
|
|
1019
|
+
* Validate that the client_id is a valid URL with https scheme
|
|
1020
|
+
*/
|
|
1021
|
+
function isHttpsUrl(value) {
|
|
1022
|
+
if (!value) return false;
|
|
1023
|
+
try {
|
|
1024
|
+
const url$1 = new URL(value);
|
|
1025
|
+
return url$1.protocol === "https:" && url$1.pathname !== "/";
|
|
1026
|
+
} catch (_a) {
|
|
1027
|
+
return false;
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
931
1030
|
async function selectResourceURL(serverUrl, provider, resourceMetadata) {
|
|
932
1031
|
const defaultResource = resourceUrlFromServerUrl(serverUrl);
|
|
933
1032
|
if (provider.validateResourceURL) return await provider.validateResourceURL(defaultResource, resourceMetadata === null || resourceMetadata === void 0 ? void 0 : resourceMetadata.resource);
|
|
@@ -939,20 +1038,40 @@ async function selectResourceURL(serverUrl, provider, resourceMetadata) {
|
|
|
939
1038
|
return new URL(resourceMetadata.resource);
|
|
940
1039
|
}
|
|
941
1040
|
/**
|
|
942
|
-
* Extract resource_metadata from
|
|
1041
|
+
* Extract resource_metadata, scope, and error from WWW-Authenticate header.
|
|
943
1042
|
*/
|
|
944
|
-
function
|
|
1043
|
+
function extractWWWAuthenticateParams(res) {
|
|
945
1044
|
const authenticateHeader = res.headers.get("WWW-Authenticate");
|
|
946
|
-
if (!authenticateHeader) return;
|
|
1045
|
+
if (!authenticateHeader) return {};
|
|
947
1046
|
const [type, scheme] = authenticateHeader.split(" ");
|
|
948
|
-
if (type.toLowerCase() !== "bearer" || !scheme) return;
|
|
949
|
-
const
|
|
950
|
-
|
|
951
|
-
try {
|
|
952
|
-
|
|
953
|
-
} catch (_a) {
|
|
954
|
-
|
|
955
|
-
|
|
1047
|
+
if (type.toLowerCase() !== "bearer" || !scheme) return {};
|
|
1048
|
+
const resourceMetadataMatch = extractFieldFromWwwAuth(res, "resource_metadata") || void 0;
|
|
1049
|
+
let resourceMetadataUrl;
|
|
1050
|
+
if (resourceMetadataMatch) try {
|
|
1051
|
+
resourceMetadataUrl = new URL(resourceMetadataMatch);
|
|
1052
|
+
} catch (_a) {}
|
|
1053
|
+
const scope = extractFieldFromWwwAuth(res, "scope") || void 0;
|
|
1054
|
+
const error = extractFieldFromWwwAuth(res, "error") || void 0;
|
|
1055
|
+
return {
|
|
1056
|
+
resourceMetadataUrl,
|
|
1057
|
+
scope,
|
|
1058
|
+
error
|
|
1059
|
+
};
|
|
1060
|
+
}
|
|
1061
|
+
/**
|
|
1062
|
+
* Extracts a specific field's value from the WWW-Authenticate header string.
|
|
1063
|
+
*
|
|
1064
|
+
* @param response The HTTP response object containing the headers.
|
|
1065
|
+
* @param fieldName The name of the field to extract (e.g., "realm", "nonce").
|
|
1066
|
+
* @returns The field value
|
|
1067
|
+
*/
|
|
1068
|
+
function extractFieldFromWwwAuth(response, fieldName) {
|
|
1069
|
+
const wwwAuthHeader = response.headers.get("WWW-Authenticate");
|
|
1070
|
+
if (!wwwAuthHeader) return null;
|
|
1071
|
+
const pattern = /* @__PURE__ */ new RegExp(`${fieldName}=(?:"([^"]+)"|([^\\s,]+))`);
|
|
1072
|
+
const match = wwwAuthHeader.match(pattern);
|
|
1073
|
+
if (match) return match[1] || match[2];
|
|
1074
|
+
return null;
|
|
956
1075
|
}
|
|
957
1076
|
/**
|
|
958
1077
|
* Looks up RFC 9728 OAuth 2.0 Protected Resource Metadata.
|
|
@@ -961,22 +1080,29 @@ function extractResourceMetadataUrl(res) {
|
|
|
961
1080
|
* return `undefined`. Any other errors will be thrown as exceptions.
|
|
962
1081
|
*/
|
|
963
1082
|
async function discoverOAuthProtectedResourceMetadata(serverUrl, opts, fetchFn = fetch) {
|
|
1083
|
+
var _a, _b;
|
|
964
1084
|
const response = await discoverMetadataWithFallback(serverUrl, "oauth-protected-resource", fetchFn, {
|
|
965
1085
|
protocolVersion: opts === null || opts === void 0 ? void 0 : opts.protocolVersion,
|
|
966
1086
|
metadataUrl: opts === null || opts === void 0 ? void 0 : opts.resourceMetadataUrl
|
|
967
1087
|
});
|
|
968
|
-
if (!response || response.status === 404)
|
|
969
|
-
|
|
1088
|
+
if (!response || response.status === 404) {
|
|
1089
|
+
await ((_a = response === null || response === void 0 ? void 0 : response.body) === null || _a === void 0 ? void 0 : _a.cancel());
|
|
1090
|
+
throw new Error(`Resource server does not implement OAuth 2.0 Protected Resource Metadata.`);
|
|
1091
|
+
}
|
|
1092
|
+
if (!response.ok) {
|
|
1093
|
+
await ((_b = response.body) === null || _b === void 0 ? void 0 : _b.cancel());
|
|
1094
|
+
throw new Error(`HTTP ${response.status} trying to load well-known OAuth protected resource metadata.`);
|
|
1095
|
+
}
|
|
970
1096
|
return OAuthProtectedResourceMetadataSchema.parse(await response.json());
|
|
971
1097
|
}
|
|
972
1098
|
/**
|
|
973
1099
|
* Helper function to handle fetch with CORS retry logic
|
|
974
1100
|
*/
|
|
975
|
-
async function fetchWithCorsRetry(url, headers, fetchFn = fetch) {
|
|
1101
|
+
async function fetchWithCorsRetry(url$1, headers, fetchFn = fetch) {
|
|
976
1102
|
try {
|
|
977
|
-
return await fetchFn(url, { headers });
|
|
1103
|
+
return await fetchFn(url$1, { headers });
|
|
978
1104
|
} catch (error) {
|
|
979
|
-
if (error instanceof TypeError) if (headers) return fetchWithCorsRetry(url, void 0, fetchFn);
|
|
1105
|
+
if (error instanceof TypeError) if (headers) return fetchWithCorsRetry(url$1, void 0, fetchFn);
|
|
980
1106
|
else return;
|
|
981
1107
|
throw error;
|
|
982
1108
|
}
|
|
@@ -991,8 +1117,8 @@ function buildWellKnownPath(wellKnownPrefix, pathname = "", options = {}) {
|
|
|
991
1117
|
/**
|
|
992
1118
|
* Tries to discover OAuth metadata at a specific URL
|
|
993
1119
|
*/
|
|
994
|
-
async function tryMetadataDiscovery(url, protocolVersion, fetchFn = fetch) {
|
|
995
|
-
return await fetchWithCorsRetry(url, { "MCP-Protocol-Version": protocolVersion }, fetchFn);
|
|
1120
|
+
async function tryMetadataDiscovery(url$1, protocolVersion, fetchFn = fetch) {
|
|
1121
|
+
return await fetchWithCorsRetry(url$1, { "MCP-Protocol-Version": protocolVersion }, fetchFn);
|
|
996
1122
|
}
|
|
997
1123
|
/**
|
|
998
1124
|
* Determines if fallback to root discovery should be attempted
|
|
@@ -1007,58 +1133,50 @@ async function discoverMetadataWithFallback(serverUrl, wellKnownType, fetchFn, o
|
|
|
1007
1133
|
var _a, _b;
|
|
1008
1134
|
const issuer = new URL(serverUrl);
|
|
1009
1135
|
const protocolVersion = (_a = opts === null || opts === void 0 ? void 0 : opts.protocolVersion) !== null && _a !== void 0 ? _a : LATEST_PROTOCOL_VERSION;
|
|
1010
|
-
let url;
|
|
1011
|
-
if (opts === null || opts === void 0 ? void 0 : opts.metadataUrl) url = new URL(opts.metadataUrl);
|
|
1136
|
+
let url$1;
|
|
1137
|
+
if (opts === null || opts === void 0 ? void 0 : opts.metadataUrl) url$1 = new URL(opts.metadataUrl);
|
|
1012
1138
|
else {
|
|
1013
1139
|
const wellKnownPath = buildWellKnownPath(wellKnownType, issuer.pathname);
|
|
1014
|
-
url = new URL(wellKnownPath, (_b = opts === null || opts === void 0 ? void 0 : opts.metadataServerUrl) !== null && _b !== void 0 ? _b : issuer);
|
|
1015
|
-
url.search = issuer.search;
|
|
1016
|
-
}
|
|
1017
|
-
let response = await tryMetadataDiscovery(url, protocolVersion, fetchFn);
|
|
1018
|
-
if (!(opts === null || opts === void 0 ? void 0 : opts.metadataUrl) && shouldAttemptFallback(response, issuer.pathname)) {
|
|
1019
|
-
const rootUrl = new URL(`/.well-known/${wellKnownType}`, issuer);
|
|
1020
|
-
response = await tryMetadataDiscovery(rootUrl, protocolVersion, fetchFn);
|
|
1140
|
+
url$1 = new URL(wellKnownPath, (_b = opts === null || opts === void 0 ? void 0 : opts.metadataServerUrl) !== null && _b !== void 0 ? _b : issuer);
|
|
1141
|
+
url$1.search = issuer.search;
|
|
1021
1142
|
}
|
|
1143
|
+
let response = await tryMetadataDiscovery(url$1, protocolVersion, fetchFn);
|
|
1144
|
+
if (!(opts === null || opts === void 0 ? void 0 : opts.metadataUrl) && shouldAttemptFallback(response, issuer.pathname)) response = await tryMetadataDiscovery(new URL(`/.well-known/${wellKnownType}`, issuer), protocolVersion, fetchFn);
|
|
1022
1145
|
return response;
|
|
1023
1146
|
}
|
|
1024
1147
|
/**
|
|
1025
1148
|
* Builds a list of discovery URLs to try for authorization server metadata.
|
|
1026
1149
|
* URLs are returned in priority order:
|
|
1027
1150
|
* 1. OAuth metadata at the given URL
|
|
1028
|
-
* 2.
|
|
1029
|
-
* 3. OIDC metadata endpoints
|
|
1151
|
+
* 2. OIDC metadata endpoints at the given URL
|
|
1030
1152
|
*/
|
|
1031
1153
|
function buildDiscoveryUrls(authorizationServerUrl) {
|
|
1032
|
-
const url = typeof authorizationServerUrl === "string" ? new URL(authorizationServerUrl) : authorizationServerUrl;
|
|
1033
|
-
const hasPath = url.pathname !== "/";
|
|
1154
|
+
const url$1 = typeof authorizationServerUrl === "string" ? new URL(authorizationServerUrl) : authorizationServerUrl;
|
|
1155
|
+
const hasPath = url$1.pathname !== "/";
|
|
1034
1156
|
const urlsToTry = [];
|
|
1035
1157
|
if (!hasPath) {
|
|
1036
1158
|
urlsToTry.push({
|
|
1037
|
-
url: new URL("/.well-known/oauth-authorization-server", url.origin),
|
|
1159
|
+
url: new URL("/.well-known/oauth-authorization-server", url$1.origin),
|
|
1038
1160
|
type: "oauth"
|
|
1039
1161
|
});
|
|
1040
1162
|
urlsToTry.push({
|
|
1041
|
-
url: new URL(`/.well-known/openid-configuration`, url.origin),
|
|
1163
|
+
url: new URL(`/.well-known/openid-configuration`, url$1.origin),
|
|
1042
1164
|
type: "oidc"
|
|
1043
1165
|
});
|
|
1044
1166
|
return urlsToTry;
|
|
1045
1167
|
}
|
|
1046
|
-
let pathname = url.pathname;
|
|
1168
|
+
let pathname = url$1.pathname;
|
|
1047
1169
|
if (pathname.endsWith("/")) pathname = pathname.slice(0, -1);
|
|
1048
1170
|
urlsToTry.push({
|
|
1049
|
-
url: new URL(`/.well-known/oauth-authorization-server${pathname}`, url.origin),
|
|
1050
|
-
type: "oauth"
|
|
1051
|
-
});
|
|
1052
|
-
urlsToTry.push({
|
|
1053
|
-
url: new URL("/.well-known/oauth-authorization-server", url.origin),
|
|
1171
|
+
url: new URL(`/.well-known/oauth-authorization-server${pathname}`, url$1.origin),
|
|
1054
1172
|
type: "oauth"
|
|
1055
1173
|
});
|
|
1056
1174
|
urlsToTry.push({
|
|
1057
|
-
url: new URL(`/.well-known/openid-configuration${pathname}`, url.origin),
|
|
1175
|
+
url: new URL(`/.well-known/openid-configuration${pathname}`, url$1.origin),
|
|
1058
1176
|
type: "oidc"
|
|
1059
1177
|
});
|
|
1060
1178
|
urlsToTry.push({
|
|
1061
|
-
url: new URL(`${pathname}/.well-known/openid-configuration`, url.origin),
|
|
1179
|
+
url: new URL(`${pathname}/.well-known/openid-configuration`, url$1.origin),
|
|
1062
1180
|
type: "oidc"
|
|
1063
1181
|
});
|
|
1064
1182
|
return urlsToTry;
|
|
@@ -1081,7 +1199,10 @@ function buildDiscoveryUrls(authorizationServerUrl) {
|
|
|
1081
1199
|
*/
|
|
1082
1200
|
async function discoverAuthorizationServerMetadata(authorizationServerUrl, { fetchFn = fetch, protocolVersion = LATEST_PROTOCOL_VERSION } = {}) {
|
|
1083
1201
|
var _a;
|
|
1084
|
-
const headers = {
|
|
1202
|
+
const headers = {
|
|
1203
|
+
"MCP-Protocol-Version": protocolVersion,
|
|
1204
|
+
Accept: "application/json"
|
|
1205
|
+
};
|
|
1085
1206
|
const urlsToTry = buildDiscoveryUrls(authorizationServerUrl);
|
|
1086
1207
|
for (const { url: endpointUrl, type } of urlsToTry) {
|
|
1087
1208
|
const response = await fetchWithCorsRetry(endpointUrl, headers, fetchFn);
|
|
@@ -1092,36 +1213,31 @@ async function discoverAuthorizationServerMetadata(authorizationServerUrl, { fet
|
|
|
1092
1213
|
*/
|
|
1093
1214
|
continue;
|
|
1094
1215
|
if (!response.ok) {
|
|
1216
|
+
await ((_a = response.body) === null || _a === void 0 ? void 0 : _a.cancel());
|
|
1095
1217
|
if (response.status >= 400 && response.status < 500) continue;
|
|
1096
1218
|
throw new Error(`HTTP ${response.status} trying to load ${type === "oauth" ? "OAuth" : "OpenID provider"} metadata from ${endpointUrl}`);
|
|
1097
1219
|
}
|
|
1098
1220
|
if (type === "oauth") return OAuthMetadataSchema.parse(await response.json());
|
|
1099
|
-
else
|
|
1100
|
-
const metadata = OpenIdProviderDiscoveryMetadataSchema.parse(await response.json());
|
|
1101
|
-
if (!((_a = metadata.code_challenge_methods_supported) === null || _a === void 0 ? void 0 : _a.includes("S256"))) throw new Error(`Incompatible OIDC provider at ${endpointUrl}: does not support S256 code challenge method required by MCP specification`);
|
|
1102
|
-
return metadata;
|
|
1103
|
-
}
|
|
1221
|
+
else return OpenIdProviderDiscoveryMetadataSchema.parse(await response.json());
|
|
1104
1222
|
}
|
|
1105
1223
|
}
|
|
1106
1224
|
/**
|
|
1107
1225
|
* Begins the authorization flow with the given server, by generating a PKCE challenge and constructing the authorization URL.
|
|
1108
1226
|
*/
|
|
1109
1227
|
async function startAuthorization(authorizationServerUrl, { metadata, clientInformation, redirectUrl, scope, state, resource }) {
|
|
1110
|
-
const responseType = "code";
|
|
1111
|
-
const codeChallengeMethod = "S256";
|
|
1112
1228
|
let authorizationUrl;
|
|
1113
1229
|
if (metadata) {
|
|
1114
1230
|
authorizationUrl = new URL(metadata.authorization_endpoint);
|
|
1115
|
-
if (!metadata.response_types_supported.includes(
|
|
1116
|
-
if (
|
|
1231
|
+
if (!metadata.response_types_supported.includes(AUTHORIZATION_CODE_RESPONSE_TYPE)) throw new Error(`Incompatible auth server: does not support response type ${AUTHORIZATION_CODE_RESPONSE_TYPE}`);
|
|
1232
|
+
if (metadata.code_challenge_methods_supported && !metadata.code_challenge_methods_supported.includes(AUTHORIZATION_CODE_CHALLENGE_METHOD)) throw new Error(`Incompatible auth server: does not support code challenge method ${AUTHORIZATION_CODE_CHALLENGE_METHOD}`);
|
|
1117
1233
|
} else authorizationUrl = new URL("/authorize", authorizationServerUrl);
|
|
1118
1234
|
const challenge = await pkceChallenge();
|
|
1119
1235
|
const codeVerifier = challenge.code_verifier;
|
|
1120
1236
|
const codeChallenge = challenge.code_challenge;
|
|
1121
|
-
authorizationUrl.searchParams.set("response_type",
|
|
1237
|
+
authorizationUrl.searchParams.set("response_type", AUTHORIZATION_CODE_RESPONSE_TYPE);
|
|
1122
1238
|
authorizationUrl.searchParams.set("client_id", clientInformation.client_id);
|
|
1123
1239
|
authorizationUrl.searchParams.set("code_challenge", codeChallenge);
|
|
1124
|
-
authorizationUrl.searchParams.set("code_challenge_method",
|
|
1240
|
+
authorizationUrl.searchParams.set("code_challenge_method", AUTHORIZATION_CODE_CHALLENGE_METHOD);
|
|
1125
1241
|
authorizationUrl.searchParams.set("redirect_uri", String(redirectUrl));
|
|
1126
1242
|
if (state) authorizationUrl.searchParams.set("state", state);
|
|
1127
1243
|
if (scope) authorizationUrl.searchParams.set("scope", scope);
|
|
@@ -1133,43 +1249,42 @@ async function startAuthorization(authorizationServerUrl, { metadata, clientInfo
|
|
|
1133
1249
|
};
|
|
1134
1250
|
}
|
|
1135
1251
|
/**
|
|
1136
|
-
*
|
|
1252
|
+
* Prepares token request parameters for an authorization code exchange.
|
|
1137
1253
|
*
|
|
1138
|
-
*
|
|
1139
|
-
*
|
|
1140
|
-
* - Falls back to appropriate defaults when server metadata is unavailable
|
|
1254
|
+
* This is the default implementation used by fetchToken when the provider
|
|
1255
|
+
* doesn't implement prepareTokenRequest.
|
|
1141
1256
|
*
|
|
1142
|
-
* @param
|
|
1143
|
-
* @param
|
|
1144
|
-
* @
|
|
1145
|
-
* @
|
|
1257
|
+
* @param authorizationCode - The authorization code received from the authorization endpoint
|
|
1258
|
+
* @param codeVerifier - The PKCE code verifier
|
|
1259
|
+
* @param redirectUri - The redirect URI used in the authorization request
|
|
1260
|
+
* @returns URLSearchParams for the authorization_code grant
|
|
1146
1261
|
*/
|
|
1147
|
-
|
|
1262
|
+
function prepareAuthorizationCodeRequest(authorizationCode, codeVerifier, redirectUri) {
|
|
1263
|
+
return new URLSearchParams({
|
|
1264
|
+
grant_type: "authorization_code",
|
|
1265
|
+
code: authorizationCode,
|
|
1266
|
+
code_verifier: codeVerifier,
|
|
1267
|
+
redirect_uri: String(redirectUri)
|
|
1268
|
+
});
|
|
1269
|
+
}
|
|
1270
|
+
/**
|
|
1271
|
+
* Internal helper to execute a token request with the given parameters.
|
|
1272
|
+
* Used by exchangeAuthorization, refreshAuthorization, and fetchToken.
|
|
1273
|
+
*/
|
|
1274
|
+
async function executeTokenRequest(authorizationServerUrl, { metadata, tokenRequestParams, clientInformation, addClientAuthentication, resource, fetchFn }) {
|
|
1148
1275
|
var _a;
|
|
1149
|
-
const grantType = "authorization_code";
|
|
1150
1276
|
const tokenUrl = (metadata === null || metadata === void 0 ? void 0 : metadata.token_endpoint) ? new URL(metadata.token_endpoint) : new URL("/token", authorizationServerUrl);
|
|
1151
|
-
if ((metadata === null || metadata === void 0 ? void 0 : metadata.grant_types_supported) && !metadata.grant_types_supported.includes(grantType)) throw new Error(`Incompatible auth server: does not support grant type ${grantType}`);
|
|
1152
1277
|
const headers = new Headers({
|
|
1153
1278
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
1154
|
-
|
|
1279
|
+
Accept: "application/json"
|
|
1155
1280
|
});
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
code_verifier: codeVerifier,
|
|
1160
|
-
redirect_uri: String(redirectUri)
|
|
1161
|
-
});
|
|
1162
|
-
if (addClientAuthentication) addClientAuthentication(headers, params, authorizationServerUrl, metadata);
|
|
1163
|
-
else {
|
|
1164
|
-
const supportedMethods = (_a = metadata === null || metadata === void 0 ? void 0 : metadata.token_endpoint_auth_methods_supported) !== null && _a !== void 0 ? _a : [];
|
|
1165
|
-
const authMethod = selectClientAuthMethod(clientInformation, supportedMethods);
|
|
1166
|
-
applyClientAuthentication(authMethod, clientInformation, headers, params);
|
|
1167
|
-
}
|
|
1168
|
-
if (resource) params.set("resource", resource.href);
|
|
1281
|
+
if (resource) tokenRequestParams.set("resource", resource.href);
|
|
1282
|
+
if (addClientAuthentication) await addClientAuthentication(headers, tokenRequestParams, tokenUrl, metadata);
|
|
1283
|
+
else if (clientInformation) applyClientAuthentication(selectClientAuthMethod(clientInformation, (_a = metadata === null || metadata === void 0 ? void 0 : metadata.token_endpoint_auth_methods_supported) !== null && _a !== void 0 ? _a : []), clientInformation, headers, tokenRequestParams);
|
|
1169
1284
|
const response = await (fetchFn !== null && fetchFn !== void 0 ? fetchFn : fetch)(tokenUrl, {
|
|
1170
1285
|
method: "POST",
|
|
1171
1286
|
headers,
|
|
1172
|
-
body:
|
|
1287
|
+
body: tokenRequestParams
|
|
1173
1288
|
});
|
|
1174
1289
|
if (!response.ok) throw await parseErrorResponse(response);
|
|
1175
1290
|
return OAuthTokensSchema.parse(await response.json());
|
|
@@ -1187,34 +1302,64 @@ async function exchangeAuthorization(authorizationServerUrl, { metadata, clientI
|
|
|
1187
1302
|
* @throws {Error} When token refresh fails or authentication is invalid
|
|
1188
1303
|
*/
|
|
1189
1304
|
async function refreshAuthorization(authorizationServerUrl, { metadata, clientInformation, refreshToken, resource, addClientAuthentication, fetchFn }) {
|
|
1190
|
-
|
|
1191
|
-
const grantType = "refresh_token";
|
|
1192
|
-
let tokenUrl;
|
|
1193
|
-
if (metadata) {
|
|
1194
|
-
tokenUrl = new URL(metadata.token_endpoint);
|
|
1195
|
-
if (metadata.grant_types_supported && !metadata.grant_types_supported.includes(grantType)) throw new Error(`Incompatible auth server: does not support grant type ${grantType}`);
|
|
1196
|
-
} else tokenUrl = new URL("/token", authorizationServerUrl);
|
|
1197
|
-
const headers = new Headers({ "Content-Type": "application/x-www-form-urlencoded" });
|
|
1198
|
-
const params = new URLSearchParams({
|
|
1199
|
-
grant_type: grantType,
|
|
1200
|
-
refresh_token: refreshToken
|
|
1201
|
-
});
|
|
1202
|
-
if (addClientAuthentication) addClientAuthentication(headers, params, authorizationServerUrl, metadata);
|
|
1203
|
-
else {
|
|
1204
|
-
const supportedMethods = (_a = metadata === null || metadata === void 0 ? void 0 : metadata.token_endpoint_auth_methods_supported) !== null && _a !== void 0 ? _a : [];
|
|
1205
|
-
const authMethod = selectClientAuthMethod(clientInformation, supportedMethods);
|
|
1206
|
-
applyClientAuthentication(authMethod, clientInformation, headers, params);
|
|
1207
|
-
}
|
|
1208
|
-
if (resource) params.set("resource", resource.href);
|
|
1209
|
-
const response = await (fetchFn !== null && fetchFn !== void 0 ? fetchFn : fetch)(tokenUrl, {
|
|
1210
|
-
method: "POST",
|
|
1211
|
-
headers,
|
|
1212
|
-
body: params
|
|
1213
|
-
});
|
|
1214
|
-
if (!response.ok) throw await parseErrorResponse(response);
|
|
1215
|
-
return OAuthTokensSchema.parse({
|
|
1305
|
+
return {
|
|
1216
1306
|
refresh_token: refreshToken,
|
|
1217
|
-
...await
|
|
1307
|
+
...await executeTokenRequest(authorizationServerUrl, {
|
|
1308
|
+
metadata,
|
|
1309
|
+
tokenRequestParams: new URLSearchParams({
|
|
1310
|
+
grant_type: "refresh_token",
|
|
1311
|
+
refresh_token: refreshToken
|
|
1312
|
+
}),
|
|
1313
|
+
clientInformation,
|
|
1314
|
+
addClientAuthentication,
|
|
1315
|
+
resource,
|
|
1316
|
+
fetchFn
|
|
1317
|
+
})
|
|
1318
|
+
};
|
|
1319
|
+
}
|
|
1320
|
+
/**
|
|
1321
|
+
* Unified token fetching that works with any grant type via provider.prepareTokenRequest().
|
|
1322
|
+
*
|
|
1323
|
+
* This function provides a single entry point for obtaining tokens regardless of the
|
|
1324
|
+
* OAuth grant type. The provider's prepareTokenRequest() method determines which grant
|
|
1325
|
+
* to use and supplies the grant-specific parameters.
|
|
1326
|
+
*
|
|
1327
|
+
* @param provider - OAuth client provider that implements prepareTokenRequest()
|
|
1328
|
+
* @param authorizationServerUrl - The authorization server's base URL
|
|
1329
|
+
* @param options - Configuration for the token request
|
|
1330
|
+
* @returns Promise resolving to OAuth tokens
|
|
1331
|
+
* @throws {Error} When provider doesn't implement prepareTokenRequest or token fetch fails
|
|
1332
|
+
*
|
|
1333
|
+
* @example
|
|
1334
|
+
* // Provider for client_credentials:
|
|
1335
|
+
* class MyProvider implements OAuthClientProvider {
|
|
1336
|
+
* prepareTokenRequest(scope) {
|
|
1337
|
+
* const params = new URLSearchParams({ grant_type: 'client_credentials' });
|
|
1338
|
+
* if (scope) params.set('scope', scope);
|
|
1339
|
+
* return params;
|
|
1340
|
+
* }
|
|
1341
|
+
* // ... other methods
|
|
1342
|
+
* }
|
|
1343
|
+
*
|
|
1344
|
+
* const tokens = await fetchToken(provider, authServerUrl, { metadata });
|
|
1345
|
+
*/
|
|
1346
|
+
async function fetchToken(provider, authorizationServerUrl, { metadata, resource, authorizationCode, fetchFn } = {}) {
|
|
1347
|
+
const scope = provider.clientMetadata.scope;
|
|
1348
|
+
let tokenRequestParams;
|
|
1349
|
+
if (provider.prepareTokenRequest) tokenRequestParams = await provider.prepareTokenRequest(scope);
|
|
1350
|
+
if (!tokenRequestParams) {
|
|
1351
|
+
if (!authorizationCode) throw new Error("Either provider.prepareTokenRequest() or authorizationCode is required");
|
|
1352
|
+
if (!provider.redirectUrl) throw new Error("redirectUrl is required for authorization_code flow");
|
|
1353
|
+
tokenRequestParams = prepareAuthorizationCodeRequest(authorizationCode, await provider.codeVerifier(), provider.redirectUrl);
|
|
1354
|
+
}
|
|
1355
|
+
const clientInformation = await provider.clientInformation();
|
|
1356
|
+
return executeTokenRequest(authorizationServerUrl, {
|
|
1357
|
+
metadata,
|
|
1358
|
+
tokenRequestParams,
|
|
1359
|
+
clientInformation: clientInformation !== null && clientInformation !== void 0 ? clientInformation : void 0,
|
|
1360
|
+
addClientAuthentication: provider.addClientAuthentication,
|
|
1361
|
+
resource,
|
|
1362
|
+
fetchFn
|
|
1218
1363
|
});
|
|
1219
1364
|
}
|
|
1220
1365
|
/**
|
|
@@ -1236,7 +1381,7 @@ async function registerClient(authorizationServerUrl, { metadata, clientMetadata
|
|
|
1236
1381
|
}
|
|
1237
1382
|
|
|
1238
1383
|
//#endregion
|
|
1239
|
-
//#region node_modules/.pnpm/@modelcontextprotocol+sdk@1.
|
|
1384
|
+
//#region node_modules/.pnpm/@modelcontextprotocol+sdk@1.24.3_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/client/sse.js
|
|
1240
1385
|
var SseError = class extends Error {
|
|
1241
1386
|
constructor(code, message, event) {
|
|
1242
1387
|
super(`SSE error: ${message}`);
|
|
@@ -1247,15 +1392,18 @@ var SseError = class extends Error {
|
|
|
1247
1392
|
/**
|
|
1248
1393
|
* Client transport for SSE: this will connect to a server using Server-Sent Events for receiving
|
|
1249
1394
|
* messages and make separate POST requests for sending messages.
|
|
1395
|
+
* @deprecated SSEClientTransport is deprecated. Prefer to use StreamableHTTPClientTransport where possible instead. Note that because some servers are still using SSE, clients may need to support both transports during the migration period.
|
|
1250
1396
|
*/
|
|
1251
1397
|
var SSEClientTransport = class {
|
|
1252
|
-
constructor(url, opts) {
|
|
1253
|
-
this._url = url;
|
|
1398
|
+
constructor(url$1, opts) {
|
|
1399
|
+
this._url = url$1;
|
|
1254
1400
|
this._resourceMetadataUrl = void 0;
|
|
1401
|
+
this._scope = void 0;
|
|
1255
1402
|
this._eventSourceInit = opts === null || opts === void 0 ? void 0 : opts.eventSourceInit;
|
|
1256
1403
|
this._requestInit = opts === null || opts === void 0 ? void 0 : opts.requestInit;
|
|
1257
1404
|
this._authProvider = opts === null || opts === void 0 ? void 0 : opts.authProvider;
|
|
1258
1405
|
this._fetch = opts === null || opts === void 0 ? void 0 : opts.fetch;
|
|
1406
|
+
this._fetchWithInit = createFetchWithInit(opts === null || opts === void 0 ? void 0 : opts.fetch, opts === null || opts === void 0 ? void 0 : opts.requestInit);
|
|
1259
1407
|
}
|
|
1260
1408
|
async _authThenStart() {
|
|
1261
1409
|
var _a;
|
|
@@ -1265,7 +1413,8 @@ var SSEClientTransport = class {
|
|
|
1265
1413
|
result = await auth(this._authProvider, {
|
|
1266
1414
|
serverUrl: this._url,
|
|
1267
1415
|
resourceMetadataUrl: this._resourceMetadataUrl,
|
|
1268
|
-
|
|
1416
|
+
scope: this._scope,
|
|
1417
|
+
fetchFn: this._fetchWithInit
|
|
1269
1418
|
});
|
|
1270
1419
|
} catch (error) {
|
|
1271
1420
|
(_a = this.onerror) === null || _a === void 0 || _a.call(this, error);
|
|
@@ -1282,9 +1431,10 @@ var SSEClientTransport = class {
|
|
|
1282
1431
|
if (tokens) headers["Authorization"] = `Bearer ${tokens.access_token}`;
|
|
1283
1432
|
}
|
|
1284
1433
|
if (this._protocolVersion) headers["mcp-protocol-version"] = this._protocolVersion;
|
|
1434
|
+
const extraHeaders = normalizeHeaders((_a = this._requestInit) === null || _a === void 0 ? void 0 : _a.headers);
|
|
1285
1435
|
return new Headers({
|
|
1286
1436
|
...headers,
|
|
1287
|
-
...
|
|
1437
|
+
...extraHeaders
|
|
1288
1438
|
});
|
|
1289
1439
|
}
|
|
1290
1440
|
_startOrAuth() {
|
|
@@ -1293,14 +1443,18 @@ var SSEClientTransport = class {
|
|
|
1293
1443
|
return new Promise((resolve, reject) => {
|
|
1294
1444
|
this._eventSource = new EventSource(this._url.href, {
|
|
1295
1445
|
...this._eventSourceInit,
|
|
1296
|
-
fetch: async (url, init) => {
|
|
1446
|
+
fetch: async (url$1, init) => {
|
|
1297
1447
|
const headers = await this._commonHeaders();
|
|
1298
1448
|
headers.set("Accept", "text/event-stream");
|
|
1299
|
-
const response = await fetchImpl(url, {
|
|
1449
|
+
const response = await fetchImpl(url$1, {
|
|
1300
1450
|
...init,
|
|
1301
1451
|
headers
|
|
1302
1452
|
});
|
|
1303
|
-
if (response.status === 401 && response.headers.has("www-authenticate"))
|
|
1453
|
+
if (response.status === 401 && response.headers.has("www-authenticate")) {
|
|
1454
|
+
const { resourceMetadataUrl, scope } = extractWWWAuthenticateParams(response);
|
|
1455
|
+
this._resourceMetadataUrl = resourceMetadataUrl;
|
|
1456
|
+
this._scope = scope;
|
|
1457
|
+
}
|
|
1304
1458
|
return response;
|
|
1305
1459
|
}
|
|
1306
1460
|
});
|
|
@@ -1357,7 +1511,8 @@ var SSEClientTransport = class {
|
|
|
1357
1511
|
serverUrl: this._url,
|
|
1358
1512
|
authorizationCode,
|
|
1359
1513
|
resourceMetadataUrl: this._resourceMetadataUrl,
|
|
1360
|
-
|
|
1514
|
+
scope: this._scope,
|
|
1515
|
+
fetchFn: this._fetchWithInit
|
|
1361
1516
|
}) !== "AUTHORIZED") throw new UnauthorizedError("Failed to authorize");
|
|
1362
1517
|
}
|
|
1363
1518
|
async close() {
|
|
@@ -1367,7 +1522,7 @@ var SSEClientTransport = class {
|
|
|
1367
1522
|
(_c = this.onclose) === null || _c === void 0 || _c.call(this);
|
|
1368
1523
|
}
|
|
1369
1524
|
async send(message) {
|
|
1370
|
-
var _a, _b, _c;
|
|
1525
|
+
var _a, _b, _c, _d;
|
|
1371
1526
|
if (!this._endpoint) throw new Error("Not connected");
|
|
1372
1527
|
try {
|
|
1373
1528
|
const headers = await this._commonHeaders();
|
|
@@ -1381,20 +1536,24 @@ var SSEClientTransport = class {
|
|
|
1381
1536
|
};
|
|
1382
1537
|
const response = await ((_b = this._fetch) !== null && _b !== void 0 ? _b : fetch)(this._endpoint, init);
|
|
1383
1538
|
if (!response.ok) {
|
|
1539
|
+
const text = await response.text().catch(() => null);
|
|
1384
1540
|
if (response.status === 401 && this._authProvider) {
|
|
1385
|
-
|
|
1541
|
+
const { resourceMetadataUrl, scope } = extractWWWAuthenticateParams(response);
|
|
1542
|
+
this._resourceMetadataUrl = resourceMetadataUrl;
|
|
1543
|
+
this._scope = scope;
|
|
1386
1544
|
if (await auth(this._authProvider, {
|
|
1387
1545
|
serverUrl: this._url,
|
|
1388
1546
|
resourceMetadataUrl: this._resourceMetadataUrl,
|
|
1389
|
-
|
|
1547
|
+
scope: this._scope,
|
|
1548
|
+
fetchFn: this._fetchWithInit
|
|
1390
1549
|
}) !== "AUTHORIZED") throw new UnauthorizedError();
|
|
1391
1550
|
return this.send(message);
|
|
1392
1551
|
}
|
|
1393
|
-
const text = await response.text().catch(() => null);
|
|
1394
1552
|
throw new Error(`Error POSTing to endpoint (HTTP ${response.status}): ${text}`);
|
|
1395
1553
|
}
|
|
1554
|
+
await ((_c = response.body) === null || _c === void 0 ? void 0 : _c.cancel());
|
|
1396
1555
|
} catch (error) {
|
|
1397
|
-
(
|
|
1556
|
+
(_d = this.onerror) === null || _d === void 0 || _d.call(this, error);
|
|
1398
1557
|
throw error;
|
|
1399
1558
|
}
|
|
1400
1559
|
}
|
|
@@ -1429,7 +1588,7 @@ var EventSourceParserStream = class extends TransformStream {
|
|
|
1429
1588
|
};
|
|
1430
1589
|
|
|
1431
1590
|
//#endregion
|
|
1432
|
-
//#region node_modules/.pnpm/@modelcontextprotocol+sdk@1.
|
|
1591
|
+
//#region node_modules/.pnpm/@modelcontextprotocol+sdk@1.24.3_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/client/streamableHttp.js
|
|
1433
1592
|
const DEFAULT_STREAMABLE_HTTP_RECONNECTION_OPTIONS = {
|
|
1434
1593
|
initialReconnectionDelay: 1e3,
|
|
1435
1594
|
maxReconnectionDelay: 3e4,
|
|
@@ -1448,13 +1607,16 @@ var StreamableHTTPError = class extends Error {
|
|
|
1448
1607
|
* for receiving messages.
|
|
1449
1608
|
*/
|
|
1450
1609
|
var StreamableHTTPClientTransport = class {
|
|
1451
|
-
constructor(url, opts) {
|
|
1610
|
+
constructor(url$1, opts) {
|
|
1452
1611
|
var _a;
|
|
1453
|
-
this.
|
|
1612
|
+
this._hasCompletedAuthFlow = false;
|
|
1613
|
+
this._url = url$1;
|
|
1454
1614
|
this._resourceMetadataUrl = void 0;
|
|
1615
|
+
this._scope = void 0;
|
|
1455
1616
|
this._requestInit = opts === null || opts === void 0 ? void 0 : opts.requestInit;
|
|
1456
1617
|
this._authProvider = opts === null || opts === void 0 ? void 0 : opts.authProvider;
|
|
1457
1618
|
this._fetch = opts === null || opts === void 0 ? void 0 : opts.fetch;
|
|
1619
|
+
this._fetchWithInit = createFetchWithInit(opts === null || opts === void 0 ? void 0 : opts.fetch, opts === null || opts === void 0 ? void 0 : opts.requestInit);
|
|
1458
1620
|
this._sessionId = opts === null || opts === void 0 ? void 0 : opts.sessionId;
|
|
1459
1621
|
this._reconnectionOptions = (_a = opts === null || opts === void 0 ? void 0 : opts.reconnectionOptions) !== null && _a !== void 0 ? _a : DEFAULT_STREAMABLE_HTTP_RECONNECTION_OPTIONS;
|
|
1460
1622
|
}
|
|
@@ -1466,7 +1628,8 @@ var StreamableHTTPClientTransport = class {
|
|
|
1466
1628
|
result = await auth(this._authProvider, {
|
|
1467
1629
|
serverUrl: this._url,
|
|
1468
1630
|
resourceMetadataUrl: this._resourceMetadataUrl,
|
|
1469
|
-
|
|
1631
|
+
scope: this._scope,
|
|
1632
|
+
fetchFn: this._fetchWithInit
|
|
1470
1633
|
});
|
|
1471
1634
|
} catch (error) {
|
|
1472
1635
|
(_a = this.onerror) === null || _a === void 0 || _a.call(this, error);
|
|
@@ -1484,14 +1647,14 @@ var StreamableHTTPClientTransport = class {
|
|
|
1484
1647
|
}
|
|
1485
1648
|
if (this._sessionId) headers["mcp-session-id"] = this._sessionId;
|
|
1486
1649
|
if (this._protocolVersion) headers["mcp-protocol-version"] = this._protocolVersion;
|
|
1487
|
-
const extraHeaders =
|
|
1650
|
+
const extraHeaders = normalizeHeaders((_a = this._requestInit) === null || _a === void 0 ? void 0 : _a.headers);
|
|
1488
1651
|
return new Headers({
|
|
1489
1652
|
...headers,
|
|
1490
1653
|
...extraHeaders
|
|
1491
1654
|
});
|
|
1492
1655
|
}
|
|
1493
1656
|
async _startOrAuthSse(options) {
|
|
1494
|
-
var _a, _b, _c;
|
|
1657
|
+
var _a, _b, _c, _d;
|
|
1495
1658
|
const { resumptionToken } = options;
|
|
1496
1659
|
try {
|
|
1497
1660
|
const headers = await this._commonHeaders();
|
|
@@ -1503,13 +1666,14 @@ var StreamableHTTPClientTransport = class {
|
|
|
1503
1666
|
signal: (_b = this._abortController) === null || _b === void 0 ? void 0 : _b.signal
|
|
1504
1667
|
});
|
|
1505
1668
|
if (!response.ok) {
|
|
1669
|
+
await ((_c = response.body) === null || _c === void 0 ? void 0 : _c.cancel());
|
|
1506
1670
|
if (response.status === 401 && this._authProvider) return await this._authThenStart();
|
|
1507
1671
|
if (response.status === 405) return;
|
|
1508
1672
|
throw new StreamableHTTPError(response.status, `Failed to open SSE stream: ${response.statusText}`);
|
|
1509
1673
|
}
|
|
1510
1674
|
this._handleSseStream(response.body, options, true);
|
|
1511
1675
|
} catch (error) {
|
|
1512
|
-
(
|
|
1676
|
+
(_d = this.onerror) === null || _d === void 0 || _d.call(this, error);
|
|
1513
1677
|
throw error;
|
|
1514
1678
|
}
|
|
1515
1679
|
}
|
|
@@ -1520,19 +1684,14 @@ var StreamableHTTPClientTransport = class {
|
|
|
1520
1684
|
* @returns Time to wait in milliseconds before next reconnection attempt
|
|
1521
1685
|
*/
|
|
1522
1686
|
_getNextReconnectionDelay(attempt) {
|
|
1687
|
+
if (this._serverRetryMs !== void 0) return this._serverRetryMs;
|
|
1523
1688
|
const initialDelay = this._reconnectionOptions.initialReconnectionDelay;
|
|
1524
1689
|
const growFactor = this._reconnectionOptions.reconnectionDelayGrowFactor;
|
|
1525
1690
|
const maxDelay = this._reconnectionOptions.maxReconnectionDelay;
|
|
1526
1691
|
return Math.min(initialDelay * Math.pow(growFactor, attempt), maxDelay);
|
|
1527
1692
|
}
|
|
1528
|
-
_normalizeHeaders(headers) {
|
|
1529
|
-
if (!headers) return {};
|
|
1530
|
-
if (headers instanceof Headers) return Object.fromEntries(headers.entries());
|
|
1531
|
-
if (Array.isArray(headers)) return Object.fromEntries(headers);
|
|
1532
|
-
return { ...headers };
|
|
1533
|
-
}
|
|
1534
1693
|
/**
|
|
1535
|
-
* Schedule a reconnection attempt
|
|
1694
|
+
* Schedule a reconnection attempt using server-provided retry interval or backoff
|
|
1536
1695
|
*
|
|
1537
1696
|
* @param lastEventId The ID of the last received event for resumability
|
|
1538
1697
|
* @param attemptCount Current reconnection attempt count for this specific stream
|
|
@@ -1540,12 +1699,12 @@ var StreamableHTTPClientTransport = class {
|
|
|
1540
1699
|
_scheduleReconnection(options, attemptCount = 0) {
|
|
1541
1700
|
var _a;
|
|
1542
1701
|
const maxRetries = this._reconnectionOptions.maxRetries;
|
|
1543
|
-
if (
|
|
1702
|
+
if (attemptCount >= maxRetries) {
|
|
1544
1703
|
(_a = this.onerror) === null || _a === void 0 || _a.call(this, /* @__PURE__ */ new Error(`Maximum reconnection attempts (${maxRetries}) exceeded.`));
|
|
1545
1704
|
return;
|
|
1546
1705
|
}
|
|
1547
1706
|
const delay = this._getNextReconnectionDelay(attemptCount);
|
|
1548
|
-
setTimeout(() => {
|
|
1707
|
+
this._reconnectionTimeout = setTimeout(() => {
|
|
1549
1708
|
this._startOrAuthSse(options).catch((error) => {
|
|
1550
1709
|
var _a$1;
|
|
1551
1710
|
(_a$1 = this.onerror) === null || _a$1 === void 0 || _a$1.call(this, /* @__PURE__ */ new Error(`Failed to reconnect SSE stream: ${error instanceof Error ? error.message : String(error)}`));
|
|
@@ -1557,28 +1716,42 @@ var StreamableHTTPClientTransport = class {
|
|
|
1557
1716
|
if (!stream) return;
|
|
1558
1717
|
const { onresumptiontoken, replayMessageId } = options;
|
|
1559
1718
|
let lastEventId;
|
|
1719
|
+
let hasPrimingEvent = false;
|
|
1720
|
+
let receivedResponse = false;
|
|
1560
1721
|
const processStream = async () => {
|
|
1561
1722
|
var _a, _b, _c, _d;
|
|
1562
1723
|
try {
|
|
1563
|
-
const reader = stream.pipeThrough(new TextDecoderStream()).pipeThrough(new EventSourceParserStream(
|
|
1724
|
+
const reader = stream.pipeThrough(new TextDecoderStream()).pipeThrough(new EventSourceParserStream({ onRetry: (retryMs) => {
|
|
1725
|
+
this._serverRetryMs = retryMs;
|
|
1726
|
+
} })).getReader();
|
|
1564
1727
|
while (true) {
|
|
1565
1728
|
const { value: event, done } = await reader.read();
|
|
1566
1729
|
if (done) break;
|
|
1567
1730
|
if (event.id) {
|
|
1568
1731
|
lastEventId = event.id;
|
|
1732
|
+
hasPrimingEvent = true;
|
|
1569
1733
|
onresumptiontoken === null || onresumptiontoken === void 0 || onresumptiontoken(event.id);
|
|
1570
1734
|
}
|
|
1735
|
+
if (!event.data) continue;
|
|
1571
1736
|
if (!event.event || event.event === "message") try {
|
|
1572
1737
|
const message = JSONRPCMessageSchema.parse(JSON.parse(event.data));
|
|
1573
|
-
if (
|
|
1738
|
+
if (isJSONRPCResponse(message)) {
|
|
1739
|
+
receivedResponse = true;
|
|
1740
|
+
if (replayMessageId !== void 0) message.id = replayMessageId;
|
|
1741
|
+
}
|
|
1574
1742
|
(_a = this.onmessage) === null || _a === void 0 || _a.call(this, message);
|
|
1575
1743
|
} catch (error) {
|
|
1576
1744
|
(_b = this.onerror) === null || _b === void 0 || _b.call(this, error);
|
|
1577
1745
|
}
|
|
1578
1746
|
}
|
|
1747
|
+
if ((isReconnectable || hasPrimingEvent) && !receivedResponse && this._abortController && !this._abortController.signal.aborted) this._scheduleReconnection({
|
|
1748
|
+
resumptionToken: lastEventId,
|
|
1749
|
+
onresumptiontoken,
|
|
1750
|
+
replayMessageId
|
|
1751
|
+
}, 0);
|
|
1579
1752
|
} catch (error) {
|
|
1580
1753
|
(_c = this.onerror) === null || _c === void 0 || _c.call(this, /* @__PURE__ */ new Error(`SSE stream disconnected: ${error}`));
|
|
1581
|
-
if (isReconnectable && this._abortController && !this._abortController.signal.aborted) try {
|
|
1754
|
+
if ((isReconnectable || hasPrimingEvent) && !receivedResponse && this._abortController && !this._abortController.signal.aborted) try {
|
|
1582
1755
|
this._scheduleReconnection({
|
|
1583
1756
|
resumptionToken: lastEventId,
|
|
1584
1757
|
onresumptiontoken,
|
|
@@ -1604,16 +1777,21 @@ var StreamableHTTPClientTransport = class {
|
|
|
1604
1777
|
serverUrl: this._url,
|
|
1605
1778
|
authorizationCode,
|
|
1606
1779
|
resourceMetadataUrl: this._resourceMetadataUrl,
|
|
1607
|
-
|
|
1780
|
+
scope: this._scope,
|
|
1781
|
+
fetchFn: this._fetchWithInit
|
|
1608
1782
|
}) !== "AUTHORIZED") throw new UnauthorizedError("Failed to authorize");
|
|
1609
1783
|
}
|
|
1610
1784
|
async close() {
|
|
1611
1785
|
var _a, _b;
|
|
1786
|
+
if (this._reconnectionTimeout) {
|
|
1787
|
+
clearTimeout(this._reconnectionTimeout);
|
|
1788
|
+
this._reconnectionTimeout = void 0;
|
|
1789
|
+
}
|
|
1612
1790
|
(_a = this._abortController) === null || _a === void 0 || _a.abort();
|
|
1613
1791
|
(_b = this.onclose) === null || _b === void 0 || _b.call(this);
|
|
1614
1792
|
}
|
|
1615
1793
|
async send(message, options) {
|
|
1616
|
-
var _a, _b, _c, _d;
|
|
1794
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1617
1795
|
try {
|
|
1618
1796
|
const { resumptionToken, onresumptiontoken } = options || {};
|
|
1619
1797
|
if (resumptionToken) {
|
|
@@ -1640,19 +1818,44 @@ var StreamableHTTPClientTransport = class {
|
|
|
1640
1818
|
const sessionId = response.headers.get("mcp-session-id");
|
|
1641
1819
|
if (sessionId) this._sessionId = sessionId;
|
|
1642
1820
|
if (!response.ok) {
|
|
1821
|
+
const text = await response.text().catch(() => null);
|
|
1643
1822
|
if (response.status === 401 && this._authProvider) {
|
|
1644
|
-
this.
|
|
1823
|
+
if (this._hasCompletedAuthFlow) throw new StreamableHTTPError(401, "Server returned 401 after successful authentication");
|
|
1824
|
+
const { resourceMetadataUrl, scope } = extractWWWAuthenticateParams(response);
|
|
1825
|
+
this._resourceMetadataUrl = resourceMetadataUrl;
|
|
1826
|
+
this._scope = scope;
|
|
1645
1827
|
if (await auth(this._authProvider, {
|
|
1646
1828
|
serverUrl: this._url,
|
|
1647
1829
|
resourceMetadataUrl: this._resourceMetadataUrl,
|
|
1648
|
-
|
|
1830
|
+
scope: this._scope,
|
|
1831
|
+
fetchFn: this._fetchWithInit
|
|
1649
1832
|
}) !== "AUTHORIZED") throw new UnauthorizedError();
|
|
1833
|
+
this._hasCompletedAuthFlow = true;
|
|
1650
1834
|
return this.send(message);
|
|
1651
1835
|
}
|
|
1652
|
-
|
|
1653
|
-
|
|
1836
|
+
if (response.status === 403 && this._authProvider) {
|
|
1837
|
+
const { resourceMetadataUrl, scope, error } = extractWWWAuthenticateParams(response);
|
|
1838
|
+
if (error === "insufficient_scope") {
|
|
1839
|
+
const wwwAuthHeader = response.headers.get("WWW-Authenticate");
|
|
1840
|
+
if (this._lastUpscopingHeader === wwwAuthHeader) throw new StreamableHTTPError(403, "Server returned 403 after trying upscoping");
|
|
1841
|
+
if (scope) this._scope = scope;
|
|
1842
|
+
if (resourceMetadataUrl) this._resourceMetadataUrl = resourceMetadataUrl;
|
|
1843
|
+
this._lastUpscopingHeader = wwwAuthHeader !== null && wwwAuthHeader !== void 0 ? wwwAuthHeader : void 0;
|
|
1844
|
+
if (await auth(this._authProvider, {
|
|
1845
|
+
serverUrl: this._url,
|
|
1846
|
+
resourceMetadataUrl: this._resourceMetadataUrl,
|
|
1847
|
+
scope: this._scope,
|
|
1848
|
+
fetchFn: this._fetch
|
|
1849
|
+
}) !== "AUTHORIZED") throw new UnauthorizedError();
|
|
1850
|
+
return this.send(message);
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
1853
|
+
throw new StreamableHTTPError(response.status, `Error POSTing to endpoint: ${text}`);
|
|
1654
1854
|
}
|
|
1855
|
+
this._hasCompletedAuthFlow = false;
|
|
1856
|
+
this._lastUpscopingHeader = void 0;
|
|
1655
1857
|
if (response.status === 202) {
|
|
1858
|
+
await ((_c = response.body) === null || _c === void 0 ? void 0 : _c.cancel());
|
|
1656
1859
|
if (isInitializedNotification(message)) this._startOrAuthSse({ resumptionToken: void 0 }).catch((err) => {
|
|
1657
1860
|
var _a$1;
|
|
1658
1861
|
return (_a$1 = this.onerror) === null || _a$1 === void 0 ? void 0 : _a$1.call(this, err);
|
|
@@ -1665,10 +1868,14 @@ var StreamableHTTPClientTransport = class {
|
|
|
1665
1868
|
else if (contentType === null || contentType === void 0 ? void 0 : contentType.includes("application/json")) {
|
|
1666
1869
|
const data = await response.json();
|
|
1667
1870
|
const responseMessages = Array.isArray(data) ? data.map((msg) => JSONRPCMessageSchema.parse(msg)) : [JSONRPCMessageSchema.parse(data)];
|
|
1668
|
-
for (const msg of responseMessages) (
|
|
1669
|
-
} else
|
|
1871
|
+
for (const msg of responseMessages) (_d = this.onmessage) === null || _d === void 0 || _d.call(this, msg);
|
|
1872
|
+
} else {
|
|
1873
|
+
await ((_e = response.body) === null || _e === void 0 ? void 0 : _e.cancel());
|
|
1874
|
+
throw new StreamableHTTPError(-1, `Unexpected content type: ${contentType}`);
|
|
1875
|
+
}
|
|
1876
|
+
else await ((_f = response.body) === null || _f === void 0 ? void 0 : _f.cancel());
|
|
1670
1877
|
} catch (error) {
|
|
1671
|
-
(
|
|
1878
|
+
(_g = this.onerror) === null || _g === void 0 || _g.call(this, error);
|
|
1672
1879
|
throw error;
|
|
1673
1880
|
}
|
|
1674
1881
|
}
|
|
@@ -1687,7 +1894,7 @@ var StreamableHTTPClientTransport = class {
|
|
|
1687
1894
|
* the server does not allow clients to terminate sessions.
|
|
1688
1895
|
*/
|
|
1689
1896
|
async terminateSession() {
|
|
1690
|
-
var _a, _b, _c;
|
|
1897
|
+
var _a, _b, _c, _d;
|
|
1691
1898
|
if (!this._sessionId) return;
|
|
1692
1899
|
try {
|
|
1693
1900
|
const headers = await this._commonHeaders();
|
|
@@ -1698,10 +1905,11 @@ var StreamableHTTPClientTransport = class {
|
|
|
1698
1905
|
signal: (_a = this._abortController) === null || _a === void 0 ? void 0 : _a.signal
|
|
1699
1906
|
};
|
|
1700
1907
|
const response = await ((_b = this._fetch) !== null && _b !== void 0 ? _b : fetch)(this._url, init);
|
|
1908
|
+
await ((_c = response.body) === null || _c === void 0 ? void 0 : _c.cancel());
|
|
1701
1909
|
if (!response.ok && response.status !== 405) throw new StreamableHTTPError(response.status, `Failed to terminate session: ${response.statusText}`);
|
|
1702
1910
|
this._sessionId = void 0;
|
|
1703
1911
|
} catch (error) {
|
|
1704
|
-
(
|
|
1912
|
+
(_d = this.onerror) === null || _d === void 0 || _d.call(this, error);
|
|
1705
1913
|
throw error;
|
|
1706
1914
|
}
|
|
1707
1915
|
}
|
|
@@ -1711,12 +1919,25 @@ var StreamableHTTPClientTransport = class {
|
|
|
1711
1919
|
get protocolVersion() {
|
|
1712
1920
|
return this._protocolVersion;
|
|
1713
1921
|
}
|
|
1922
|
+
/**
|
|
1923
|
+
* Resume an SSE stream from a previous event ID.
|
|
1924
|
+
* Opens a GET SSE connection with Last-Event-ID header to replay missed events.
|
|
1925
|
+
*
|
|
1926
|
+
* @param lastEventId The event ID to resume from
|
|
1927
|
+
* @param options Optional callback to receive new resumption tokens
|
|
1928
|
+
*/
|
|
1929
|
+
async resumeStream(lastEventId, options) {
|
|
1930
|
+
await this._startOrAuthSse({
|
|
1931
|
+
resumptionToken: lastEventId,
|
|
1932
|
+
onresumptiontoken: options === null || options === void 0 ? void 0 : options.onresumptiontoken
|
|
1933
|
+
});
|
|
1934
|
+
}
|
|
1714
1935
|
};
|
|
1715
1936
|
|
|
1716
1937
|
//#endregion
|
|
1717
|
-
//#region node_modules/.pnpm/@modelcontextprotocol+sdk@1.
|
|
1938
|
+
//#region node_modules/.pnpm/@modelcontextprotocol+sdk@1.24.3_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.js
|
|
1718
1939
|
/**
|
|
1719
|
-
* Server transport for stdio: this communicates with
|
|
1940
|
+
* Server transport for stdio: this communicates with an MCP client by reading from the current process' stdin and writing to stdout.
|
|
1720
1941
|
*
|
|
1721
1942
|
* This transport is only available in Node.js environments.
|
|
1722
1943
|
*/
|
|
@@ -1778,13 +1999,13 @@ let ServerType = /* @__PURE__ */ function(ServerType$1) {
|
|
|
1778
1999
|
ServerType$1["SSE"] = "SSE";
|
|
1779
2000
|
return ServerType$1;
|
|
1780
2001
|
}({});
|
|
1781
|
-
const startStdioServer = async ({ initStdioServer, initStreamClient, serverType, transportOptions = {}, url }) => {
|
|
2002
|
+
const startStdioServer = async ({ initStdioServer, initStreamClient, serverType, transportOptions = {}, url: url$1 }) => {
|
|
1782
2003
|
let transport;
|
|
1783
2004
|
switch (serverType) {
|
|
1784
2005
|
case ServerType.SSE:
|
|
1785
|
-
transport = new SSEClientTransport(new URL(url), transportOptions);
|
|
2006
|
+
transport = new SSEClientTransport(new URL(url$1), transportOptions);
|
|
1786
2007
|
break;
|
|
1787
|
-
default: transport = new StreamableHTTPClientTransport(new URL(url), transportOptions);
|
|
2008
|
+
default: transport = new StreamableHTTPClientTransport(new URL(url$1), transportOptions);
|
|
1788
2009
|
}
|
|
1789
2010
|
const streamClient = initStreamClient ? await initStreamClient() : new Client({
|
|
1790
2011
|
name: "mcp-proxy",
|