kfc-code-cli 0.0.1-alpha.2 → 0.0.1-alpha.4

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.
@@ -1,1530 +0,0 @@
1
- #!/usr/bin/env node
2
- import { H as isJSONRPCResultResponse, R as isInitializedNotification, V as isJSONRPCRequest, b as LATEST_PROTOCOL_VERSION, y as JSONRPCMessageSchema } from "./types-CdOcSyeC.mjs";
3
- import * as z from "zod/v4";
4
- //#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.29.0_zod@4.3.6/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/transport.js
5
- /**
6
- * Normalizes HeadersInit to a plain Record<string, string> for manipulation.
7
- * Handles Headers objects, arrays of tuples, and plain objects.
8
- */
9
- function normalizeHeaders(headers) {
10
- if (!headers) return {};
11
- if (headers instanceof Headers) return Object.fromEntries(headers.entries());
12
- if (Array.isArray(headers)) return Object.fromEntries(headers);
13
- return { ...headers };
14
- }
15
- /**
16
- * Creates a fetch function that includes base RequestInit options.
17
- * This ensures requests inherit settings like credentials, mode, headers, etc. from the base init.
18
- *
19
- * @param baseFetch - The base fetch function to wrap (defaults to global fetch)
20
- * @param baseInit - The base RequestInit to merge with each request
21
- * @returns A wrapped fetch function that merges base options with call-specific options
22
- */
23
- function createFetchWithInit(baseFetch = fetch, baseInit) {
24
- if (!baseInit) return baseFetch;
25
- return async (url, init) => {
26
- return baseFetch(url, {
27
- ...baseInit,
28
- ...init,
29
- headers: init?.headers ? {
30
- ...normalizeHeaders(baseInit.headers),
31
- ...normalizeHeaders(init.headers)
32
- } : baseInit.headers
33
- });
34
- };
35
- }
36
- //#endregion
37
- //#region ../../node_modules/.pnpm/pkce-challenge@5.0.1/node_modules/pkce-challenge/dist/index.node.js
38
- let crypto;
39
- crypto = globalThis.crypto?.webcrypto ?? globalThis.crypto ?? import("node:crypto").then((m) => m.webcrypto);
40
- /**
41
- * Creates an array of length `size` of random bytes
42
- * @param size
43
- * @returns Array of random ints (0 to 255)
44
- */
45
- async function getRandomValues(size) {
46
- return (await crypto).getRandomValues(new Uint8Array(size));
47
- }
48
- /** Generate cryptographically strong random string
49
- * @param size The desired length of the string
50
- * @returns The random string
51
- */
52
- async function random(size) {
53
- const mask = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~";
54
- const evenDistCutoff = Math.pow(2, 8) - Math.pow(2, 8) % 66;
55
- let result = "";
56
- while (result.length < size) {
57
- const randomBytes = await getRandomValues(size - result.length);
58
- for (const randomByte of randomBytes) if (randomByte < evenDistCutoff) result += mask[randomByte % 66];
59
- }
60
- return result;
61
- }
62
- /** Generate a PKCE challenge verifier
63
- * @param length Length of the verifier
64
- * @returns A random verifier `length` characters long
65
- */
66
- async function generateVerifier(length) {
67
- return await random(length);
68
- }
69
- /** Generate a PKCE code challenge from a code verifier
70
- * @param code_verifier
71
- * @returns The base64 url encoded code challenge
72
- */
73
- async function generateChallenge(code_verifier) {
74
- const buffer = await (await crypto).subtle.digest("SHA-256", new TextEncoder().encode(code_verifier));
75
- return btoa(String.fromCharCode(...new Uint8Array(buffer))).replace(/\//g, "_").replace(/\+/g, "-").replace(/=/g, "");
76
- }
77
- /** Generate a PKCE challenge pair
78
- * @param length Length of the verifer (between 43-128). Defaults to 43.
79
- * @returns PKCE challenge pair
80
- */
81
- async function pkceChallenge(length) {
82
- if (!length) length = 43;
83
- if (length < 43 || length > 128) throw `Expected a length between 43 and 128. Received ${length}.`;
84
- const verifier = await generateVerifier(length);
85
- return {
86
- code_verifier: verifier,
87
- code_challenge: await generateChallenge(verifier)
88
- };
89
- }
90
- //#endregion
91
- //#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.29.0_zod@4.3.6/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/auth.js
92
- /**
93
- * Reusable URL validation that disallows javascript: scheme
94
- */
95
- const SafeUrlSchema = z.url().superRefine((val, ctx) => {
96
- if (!URL.canParse(val)) {
97
- ctx.addIssue({
98
- code: z.ZodIssueCode.custom,
99
- message: "URL must be parseable",
100
- fatal: true
101
- });
102
- return z.NEVER;
103
- }
104
- }).refine((url) => {
105
- const u = new URL(url);
106
- return u.protocol !== "javascript:" && u.protocol !== "data:" && u.protocol !== "vbscript:";
107
- }, { message: "URL cannot use javascript:, data:, or vbscript: scheme" });
108
- /**
109
- * RFC 9728 OAuth Protected Resource Metadata
110
- */
111
- const OAuthProtectedResourceMetadataSchema = z.looseObject({
112
- resource: z.string().url(),
113
- authorization_servers: z.array(SafeUrlSchema).optional(),
114
- jwks_uri: z.string().url().optional(),
115
- scopes_supported: z.array(z.string()).optional(),
116
- bearer_methods_supported: z.array(z.string()).optional(),
117
- resource_signing_alg_values_supported: z.array(z.string()).optional(),
118
- resource_name: z.string().optional(),
119
- resource_documentation: z.string().optional(),
120
- resource_policy_uri: z.string().url().optional(),
121
- resource_tos_uri: z.string().url().optional(),
122
- tls_client_certificate_bound_access_tokens: z.boolean().optional(),
123
- authorization_details_types_supported: z.array(z.string()).optional(),
124
- dpop_signing_alg_values_supported: z.array(z.string()).optional(),
125
- dpop_bound_access_tokens_required: z.boolean().optional()
126
- });
127
- /**
128
- * RFC 8414 OAuth 2.0 Authorization Server Metadata
129
- */
130
- const OAuthMetadataSchema = z.looseObject({
131
- issuer: z.string(),
132
- authorization_endpoint: SafeUrlSchema,
133
- token_endpoint: SafeUrlSchema,
134
- registration_endpoint: SafeUrlSchema.optional(),
135
- scopes_supported: z.array(z.string()).optional(),
136
- response_types_supported: z.array(z.string()),
137
- response_modes_supported: z.array(z.string()).optional(),
138
- grant_types_supported: z.array(z.string()).optional(),
139
- token_endpoint_auth_methods_supported: z.array(z.string()).optional(),
140
- token_endpoint_auth_signing_alg_values_supported: z.array(z.string()).optional(),
141
- service_documentation: SafeUrlSchema.optional(),
142
- revocation_endpoint: SafeUrlSchema.optional(),
143
- revocation_endpoint_auth_methods_supported: z.array(z.string()).optional(),
144
- revocation_endpoint_auth_signing_alg_values_supported: z.array(z.string()).optional(),
145
- introspection_endpoint: z.string().optional(),
146
- introspection_endpoint_auth_methods_supported: z.array(z.string()).optional(),
147
- introspection_endpoint_auth_signing_alg_values_supported: z.array(z.string()).optional(),
148
- code_challenge_methods_supported: z.array(z.string()).optional(),
149
- client_id_metadata_document_supported: z.boolean().optional()
150
- });
151
- /**
152
- * OpenID Connect Discovery 1.0 Provider Metadata
153
- * see: https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata
154
- */
155
- const OpenIdProviderMetadataSchema = z.looseObject({
156
- issuer: z.string(),
157
- authorization_endpoint: SafeUrlSchema,
158
- token_endpoint: SafeUrlSchema,
159
- userinfo_endpoint: SafeUrlSchema.optional(),
160
- jwks_uri: SafeUrlSchema,
161
- registration_endpoint: SafeUrlSchema.optional(),
162
- scopes_supported: z.array(z.string()).optional(),
163
- response_types_supported: z.array(z.string()),
164
- response_modes_supported: z.array(z.string()).optional(),
165
- grant_types_supported: z.array(z.string()).optional(),
166
- acr_values_supported: z.array(z.string()).optional(),
167
- subject_types_supported: z.array(z.string()),
168
- id_token_signing_alg_values_supported: z.array(z.string()),
169
- id_token_encryption_alg_values_supported: z.array(z.string()).optional(),
170
- id_token_encryption_enc_values_supported: z.array(z.string()).optional(),
171
- userinfo_signing_alg_values_supported: z.array(z.string()).optional(),
172
- userinfo_encryption_alg_values_supported: z.array(z.string()).optional(),
173
- userinfo_encryption_enc_values_supported: z.array(z.string()).optional(),
174
- request_object_signing_alg_values_supported: z.array(z.string()).optional(),
175
- request_object_encryption_alg_values_supported: z.array(z.string()).optional(),
176
- request_object_encryption_enc_values_supported: z.array(z.string()).optional(),
177
- token_endpoint_auth_methods_supported: z.array(z.string()).optional(),
178
- token_endpoint_auth_signing_alg_values_supported: z.array(z.string()).optional(),
179
- display_values_supported: z.array(z.string()).optional(),
180
- claim_types_supported: z.array(z.string()).optional(),
181
- claims_supported: z.array(z.string()).optional(),
182
- service_documentation: z.string().optional(),
183
- claims_locales_supported: z.array(z.string()).optional(),
184
- ui_locales_supported: z.array(z.string()).optional(),
185
- claims_parameter_supported: z.boolean().optional(),
186
- request_parameter_supported: z.boolean().optional(),
187
- request_uri_parameter_supported: z.boolean().optional(),
188
- require_request_uri_registration: z.boolean().optional(),
189
- op_policy_uri: SafeUrlSchema.optional(),
190
- op_tos_uri: SafeUrlSchema.optional(),
191
- client_id_metadata_document_supported: z.boolean().optional()
192
- });
193
- /**
194
- * OpenID Connect Discovery metadata that may include OAuth 2.0 fields
195
- * This schema represents the real-world scenario where OIDC providers
196
- * return a mix of OpenID Connect and OAuth 2.0 metadata fields
197
- */
198
- const OpenIdProviderDiscoveryMetadataSchema = z.object({
199
- ...OpenIdProviderMetadataSchema.shape,
200
- ...OAuthMetadataSchema.pick({ code_challenge_methods_supported: true }).shape
201
- });
202
- /**
203
- * OAuth 2.1 token response
204
- */
205
- const OAuthTokensSchema = z.object({
206
- access_token: z.string(),
207
- id_token: z.string().optional(),
208
- token_type: z.string(),
209
- expires_in: z.coerce.number().optional(),
210
- scope: z.string().optional(),
211
- refresh_token: z.string().optional()
212
- }).strip();
213
- /**
214
- * OAuth 2.1 error response
215
- */
216
- const OAuthErrorResponseSchema = z.object({
217
- error: z.string(),
218
- error_description: z.string().optional(),
219
- error_uri: z.string().optional()
220
- });
221
- /**
222
- * Optional version of SafeUrlSchema that allows empty string for retrocompatibility on tos_uri and logo_uri
223
- */
224
- const OptionalSafeUrlSchema = SafeUrlSchema.optional().or(z.literal("").transform(() => void 0));
225
- /**
226
- * RFC 7591 OAuth 2.0 Dynamic Client Registration metadata
227
- */
228
- const OAuthClientMetadataSchema = z.object({
229
- redirect_uris: z.array(SafeUrlSchema),
230
- token_endpoint_auth_method: z.string().optional(),
231
- grant_types: z.array(z.string()).optional(),
232
- response_types: z.array(z.string()).optional(),
233
- client_name: z.string().optional(),
234
- client_uri: SafeUrlSchema.optional(),
235
- logo_uri: OptionalSafeUrlSchema,
236
- scope: z.string().optional(),
237
- contacts: z.array(z.string()).optional(),
238
- tos_uri: OptionalSafeUrlSchema,
239
- policy_uri: z.string().optional(),
240
- jwks_uri: SafeUrlSchema.optional(),
241
- jwks: z.any().optional(),
242
- software_id: z.string().optional(),
243
- software_version: z.string().optional(),
244
- software_statement: z.string().optional()
245
- }).strip();
246
- /**
247
- * RFC 7591 OAuth 2.0 Dynamic Client Registration client information
248
- */
249
- const OAuthClientInformationSchema = z.object({
250
- client_id: z.string(),
251
- client_secret: z.string().optional(),
252
- client_id_issued_at: z.number().optional(),
253
- client_secret_expires_at: z.number().optional()
254
- }).strip();
255
- /**
256
- * RFC 7591 OAuth 2.0 Dynamic Client Registration full response (client information plus metadata)
257
- */
258
- const OAuthClientInformationFullSchema = OAuthClientMetadataSchema.merge(OAuthClientInformationSchema);
259
- z.object({
260
- error: z.string(),
261
- error_description: z.string().optional()
262
- }).strip();
263
- z.object({
264
- token: z.string(),
265
- token_type_hint: z.string().optional()
266
- }).strip();
267
- //#endregion
268
- //#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.29.0_zod@4.3.6/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/auth-utils.js
269
- /**
270
- * Utilities for handling OAuth resource URIs.
271
- */
272
- /**
273
- * Converts a server URL to a resource URL by removing the fragment.
274
- * RFC 8707 section 2 states that resource URIs "MUST NOT include a fragment component".
275
- * Keeps everything else unchanged (scheme, domain, port, path, query).
276
- */
277
- function resourceUrlFromServerUrl(url) {
278
- const resourceURL = typeof url === "string" ? new URL(url) : new URL(url.href);
279
- resourceURL.hash = "";
280
- return resourceURL;
281
- }
282
- /**
283
- * Checks if a requested resource URL matches a configured resource URL.
284
- * A requested resource matches if it has the same scheme, domain, port,
285
- * and its path starts with the configured resource's path.
286
- *
287
- * @param requestedResource The resource URL being requested
288
- * @param configuredResource The resource URL that has been configured
289
- * @returns true if the requested resource matches the configured resource, false otherwise
290
- */
291
- function checkResourceAllowed({ requestedResource, configuredResource }) {
292
- const requested = typeof requestedResource === "string" ? new URL(requestedResource) : new URL(requestedResource.href);
293
- const configured = typeof configuredResource === "string" ? new URL(configuredResource) : new URL(configuredResource.href);
294
- if (requested.origin !== configured.origin) return false;
295
- if (requested.pathname.length < configured.pathname.length) return false;
296
- const requestedPath = requested.pathname.endsWith("/") ? requested.pathname : requested.pathname + "/";
297
- const configuredPath = configured.pathname.endsWith("/") ? configured.pathname : configured.pathname + "/";
298
- return requestedPath.startsWith(configuredPath);
299
- }
300
- //#endregion
301
- //#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.29.0_zod@4.3.6/node_modules/@modelcontextprotocol/sdk/dist/esm/server/auth/errors.js
302
- /**
303
- * Base class for all OAuth errors
304
- */
305
- var OAuthError = class extends Error {
306
- constructor(message, errorUri) {
307
- super(message);
308
- this.errorUri = errorUri;
309
- this.name = this.constructor.name;
310
- }
311
- /**
312
- * Converts the error to a standard OAuth error response object
313
- */
314
- toResponseObject() {
315
- const response = {
316
- error: this.errorCode,
317
- error_description: this.message
318
- };
319
- if (this.errorUri) response.error_uri = this.errorUri;
320
- return response;
321
- }
322
- get errorCode() {
323
- return this.constructor.errorCode;
324
- }
325
- };
326
- /**
327
- * Invalid request error - The request is missing a required parameter,
328
- * includes an invalid parameter value, includes a parameter more than once,
329
- * or is otherwise malformed.
330
- */
331
- var InvalidRequestError = class extends OAuthError {};
332
- InvalidRequestError.errorCode = "invalid_request";
333
- /**
334
- * Invalid client error - Client authentication failed (e.g., unknown client, no client
335
- * authentication included, or unsupported authentication method).
336
- */
337
- var InvalidClientError = class extends OAuthError {};
338
- InvalidClientError.errorCode = "invalid_client";
339
- /**
340
- * Invalid grant error - The provided authorization grant or refresh token is
341
- * invalid, expired, revoked, does not match the redirection URI used in the
342
- * authorization request, or was issued to another client.
343
- */
344
- var InvalidGrantError = class extends OAuthError {};
345
- InvalidGrantError.errorCode = "invalid_grant";
346
- /**
347
- * Unauthorized client error - The authenticated client is not authorized to use
348
- * this authorization grant type.
349
- */
350
- var UnauthorizedClientError = class extends OAuthError {};
351
- UnauthorizedClientError.errorCode = "unauthorized_client";
352
- /**
353
- * Unsupported grant type error - The authorization grant type is not supported
354
- * by the authorization server.
355
- */
356
- var UnsupportedGrantTypeError = class extends OAuthError {};
357
- UnsupportedGrantTypeError.errorCode = "unsupported_grant_type";
358
- /**
359
- * Invalid scope error - The requested scope is invalid, unknown, malformed, or
360
- * exceeds the scope granted by the resource owner.
361
- */
362
- var InvalidScopeError = class extends OAuthError {};
363
- InvalidScopeError.errorCode = "invalid_scope";
364
- /**
365
- * Access denied error - The resource owner or authorization server denied the request.
366
- */
367
- var AccessDeniedError = class extends OAuthError {};
368
- AccessDeniedError.errorCode = "access_denied";
369
- /**
370
- * Server error - The authorization server encountered an unexpected condition
371
- * that prevented it from fulfilling the request.
372
- */
373
- var ServerError = class extends OAuthError {};
374
- ServerError.errorCode = "server_error";
375
- /**
376
- * Temporarily unavailable error - The authorization server is currently unable to
377
- * handle the request due to a temporary overloading or maintenance of the server.
378
- */
379
- var TemporarilyUnavailableError = class extends OAuthError {};
380
- TemporarilyUnavailableError.errorCode = "temporarily_unavailable";
381
- /**
382
- * Unsupported response type error - The authorization server does not support
383
- * obtaining an authorization code using this method.
384
- */
385
- var UnsupportedResponseTypeError = class extends OAuthError {};
386
- UnsupportedResponseTypeError.errorCode = "unsupported_response_type";
387
- /**
388
- * Unsupported token type error - The authorization server does not support
389
- * the requested token type.
390
- */
391
- var UnsupportedTokenTypeError = class extends OAuthError {};
392
- UnsupportedTokenTypeError.errorCode = "unsupported_token_type";
393
- /**
394
- * Invalid token error - The access token provided is expired, revoked, malformed,
395
- * or invalid for other reasons.
396
- */
397
- var InvalidTokenError = class extends OAuthError {};
398
- InvalidTokenError.errorCode = "invalid_token";
399
- /**
400
- * Method not allowed error - The HTTP method used is not allowed for this endpoint.
401
- * (Custom, non-standard error)
402
- */
403
- var MethodNotAllowedError = class extends OAuthError {};
404
- MethodNotAllowedError.errorCode = "method_not_allowed";
405
- /**
406
- * Too many requests error - Rate limit exceeded.
407
- * (Custom, non-standard error based on RFC 6585)
408
- */
409
- var TooManyRequestsError = class extends OAuthError {};
410
- TooManyRequestsError.errorCode = "too_many_requests";
411
- /**
412
- * Invalid client metadata error - The client metadata is invalid.
413
- * (Custom error for dynamic client registration - RFC 7591)
414
- */
415
- var InvalidClientMetadataError = class extends OAuthError {};
416
- InvalidClientMetadataError.errorCode = "invalid_client_metadata";
417
- /**
418
- * Insufficient scope error - The request requires higher privileges than provided by the access token.
419
- */
420
- var InsufficientScopeError = class extends OAuthError {};
421
- InsufficientScopeError.errorCode = "insufficient_scope";
422
- /**
423
- * Invalid target error - The requested resource is invalid, missing, unknown, or malformed.
424
- * (Custom error for resource indicators - RFC 8707)
425
- */
426
- var InvalidTargetError = class extends OAuthError {};
427
- InvalidTargetError.errorCode = "invalid_target";
428
- /**
429
- * A full list of all OAuthErrors, enabling parsing from error responses
430
- */
431
- const OAUTH_ERRORS = {
432
- [InvalidRequestError.errorCode]: InvalidRequestError,
433
- [InvalidClientError.errorCode]: InvalidClientError,
434
- [InvalidGrantError.errorCode]: InvalidGrantError,
435
- [UnauthorizedClientError.errorCode]: UnauthorizedClientError,
436
- [UnsupportedGrantTypeError.errorCode]: UnsupportedGrantTypeError,
437
- [InvalidScopeError.errorCode]: InvalidScopeError,
438
- [AccessDeniedError.errorCode]: AccessDeniedError,
439
- [ServerError.errorCode]: ServerError,
440
- [TemporarilyUnavailableError.errorCode]: TemporarilyUnavailableError,
441
- [UnsupportedResponseTypeError.errorCode]: UnsupportedResponseTypeError,
442
- [UnsupportedTokenTypeError.errorCode]: UnsupportedTokenTypeError,
443
- [InvalidTokenError.errorCode]: InvalidTokenError,
444
- [MethodNotAllowedError.errorCode]: MethodNotAllowedError,
445
- [TooManyRequestsError.errorCode]: TooManyRequestsError,
446
- [InvalidClientMetadataError.errorCode]: InvalidClientMetadataError,
447
- [InsufficientScopeError.errorCode]: InsufficientScopeError,
448
- [InvalidTargetError.errorCode]: InvalidTargetError
449
- };
450
- //#endregion
451
- //#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.29.0_zod@4.3.6/node_modules/@modelcontextprotocol/sdk/dist/esm/client/auth.js
452
- var UnauthorizedError = class extends Error {
453
- constructor(message) {
454
- super(message ?? "Unauthorized");
455
- }
456
- };
457
- function isClientAuthMethod(method) {
458
- return [
459
- "client_secret_basic",
460
- "client_secret_post",
461
- "none"
462
- ].includes(method);
463
- }
464
- const AUTHORIZATION_CODE_RESPONSE_TYPE = "code";
465
- const AUTHORIZATION_CODE_CHALLENGE_METHOD = "S256";
466
- /**
467
- * Determines the best client authentication method to use based on server support and client configuration.
468
- *
469
- * Priority order (highest to lowest):
470
- * 1. client_secret_basic (if client secret is available)
471
- * 2. client_secret_post (if client secret is available)
472
- * 3. none (for public clients)
473
- *
474
- * @param clientInformation - OAuth client information containing credentials
475
- * @param supportedMethods - Authentication methods supported by the authorization server
476
- * @returns The selected authentication method
477
- */
478
- function selectClientAuthMethod(clientInformation, supportedMethods) {
479
- const hasClientSecret = clientInformation.client_secret !== void 0;
480
- if ("token_endpoint_auth_method" in clientInformation && clientInformation.token_endpoint_auth_method && isClientAuthMethod(clientInformation.token_endpoint_auth_method) && (supportedMethods.length === 0 || supportedMethods.includes(clientInformation.token_endpoint_auth_method))) return clientInformation.token_endpoint_auth_method;
481
- if (supportedMethods.length === 0) return hasClientSecret ? "client_secret_basic" : "none";
482
- if (hasClientSecret && supportedMethods.includes("client_secret_basic")) return "client_secret_basic";
483
- if (hasClientSecret && supportedMethods.includes("client_secret_post")) return "client_secret_post";
484
- if (supportedMethods.includes("none")) return "none";
485
- return hasClientSecret ? "client_secret_post" : "none";
486
- }
487
- /**
488
- * Applies client authentication to the request based on the specified method.
489
- *
490
- * Implements OAuth 2.1 client authentication methods:
491
- * - client_secret_basic: HTTP Basic authentication (RFC 6749 Section 2.3.1)
492
- * - client_secret_post: Credentials in request body (RFC 6749 Section 2.3.1)
493
- * - none: Public client authentication (RFC 6749 Section 2.1)
494
- *
495
- * @param method - The authentication method to use
496
- * @param clientInformation - OAuth client information containing credentials
497
- * @param headers - HTTP headers object to modify
498
- * @param params - URL search parameters to modify
499
- * @throws {Error} When required credentials are missing
500
- */
501
- function applyClientAuthentication(method, clientInformation, headers, params) {
502
- const { client_id, client_secret } = clientInformation;
503
- switch (method) {
504
- case "client_secret_basic":
505
- applyBasicAuth(client_id, client_secret, headers);
506
- return;
507
- case "client_secret_post":
508
- applyPostAuth(client_id, client_secret, params);
509
- return;
510
- case "none":
511
- applyPublicAuth(client_id, params);
512
- return;
513
- default: throw new Error(`Unsupported client authentication method: ${method}`);
514
- }
515
- }
516
- /**
517
- * Applies HTTP Basic authentication (RFC 6749 Section 2.3.1)
518
- */
519
- function applyBasicAuth(clientId, clientSecret, headers) {
520
- if (!clientSecret) throw new Error("client_secret_basic authentication requires a client_secret");
521
- const credentials = btoa(`${clientId}:${clientSecret}`);
522
- headers.set("Authorization", `Basic ${credentials}`);
523
- }
524
- /**
525
- * Applies POST body authentication (RFC 6749 Section 2.3.1)
526
- */
527
- function applyPostAuth(clientId, clientSecret, params) {
528
- params.set("client_id", clientId);
529
- if (clientSecret) params.set("client_secret", clientSecret);
530
- }
531
- /**
532
- * Applies public client authentication (RFC 6749 Section 2.1)
533
- */
534
- function applyPublicAuth(clientId, params) {
535
- params.set("client_id", clientId);
536
- }
537
- /**
538
- * Parses an OAuth error response from a string or Response object.
539
- *
540
- * If the input is a standard OAuth2.0 error response, it will be parsed according to the spec
541
- * and an instance of the appropriate OAuthError subclass will be returned.
542
- * If parsing fails, it falls back to a generic ServerError that includes
543
- * the response status (if available) and original content.
544
- *
545
- * @param input - A Response object or string containing the error response
546
- * @returns A Promise that resolves to an OAuthError instance
547
- */
548
- async function parseErrorResponse(input) {
549
- const statusCode = input instanceof Response ? input.status : void 0;
550
- const body = input instanceof Response ? await input.text() : input;
551
- try {
552
- const { error, error_description, error_uri } = OAuthErrorResponseSchema.parse(JSON.parse(body));
553
- return new (OAUTH_ERRORS[error] || ServerError)(error_description || "", error_uri);
554
- } catch (error) {
555
- return new ServerError(`${statusCode ? `HTTP ${statusCode}: ` : ""}Invalid OAuth error response: ${error}. Raw body: ${body}`);
556
- }
557
- }
558
- /**
559
- * Orchestrates the full auth flow with a server.
560
- *
561
- * This can be used as a single entry point for all authorization functionality,
562
- * instead of linking together the other lower-level functions in this module.
563
- */
564
- async function auth(provider, options) {
565
- try {
566
- return await authInternal(provider, options);
567
- } catch (error) {
568
- if (error instanceof InvalidClientError || error instanceof UnauthorizedClientError) {
569
- await provider.invalidateCredentials?.("all");
570
- return await authInternal(provider, options);
571
- } else if (error instanceof InvalidGrantError) {
572
- await provider.invalidateCredentials?.("tokens");
573
- return await authInternal(provider, options);
574
- }
575
- throw error;
576
- }
577
- }
578
- async function authInternal(provider, { serverUrl, authorizationCode, scope, resourceMetadataUrl, fetchFn }) {
579
- const cachedState = await provider.discoveryState?.();
580
- let resourceMetadata;
581
- let authorizationServerUrl;
582
- let metadata;
583
- let effectiveResourceMetadataUrl = resourceMetadataUrl;
584
- if (!effectiveResourceMetadataUrl && cachedState?.resourceMetadataUrl) effectiveResourceMetadataUrl = new URL(cachedState.resourceMetadataUrl);
585
- if (cachedState?.authorizationServerUrl) {
586
- authorizationServerUrl = cachedState.authorizationServerUrl;
587
- resourceMetadata = cachedState.resourceMetadata;
588
- metadata = cachedState.authorizationServerMetadata ?? await discoverAuthorizationServerMetadata(authorizationServerUrl, { fetchFn });
589
- if (!resourceMetadata) try {
590
- resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl: effectiveResourceMetadataUrl }, fetchFn);
591
- } catch {}
592
- if (metadata !== cachedState.authorizationServerMetadata || resourceMetadata !== cachedState.resourceMetadata) await provider.saveDiscoveryState?.({
593
- authorizationServerUrl: String(authorizationServerUrl),
594
- resourceMetadataUrl: effectiveResourceMetadataUrl?.toString(),
595
- resourceMetadata,
596
- authorizationServerMetadata: metadata
597
- });
598
- } else {
599
- const serverInfo = await discoverOAuthServerInfo(serverUrl, {
600
- resourceMetadataUrl: effectiveResourceMetadataUrl,
601
- fetchFn
602
- });
603
- authorizationServerUrl = serverInfo.authorizationServerUrl;
604
- metadata = serverInfo.authorizationServerMetadata;
605
- resourceMetadata = serverInfo.resourceMetadata;
606
- await provider.saveDiscoveryState?.({
607
- authorizationServerUrl: String(authorizationServerUrl),
608
- resourceMetadataUrl: effectiveResourceMetadataUrl?.toString(),
609
- resourceMetadata,
610
- authorizationServerMetadata: metadata
611
- });
612
- }
613
- const resource = await selectResourceURL(serverUrl, provider, resourceMetadata);
614
- const resolvedScope = scope || resourceMetadata?.scopes_supported?.join(" ") || provider.clientMetadata.scope;
615
- let clientInformation = await Promise.resolve(provider.clientInformation());
616
- if (!clientInformation) {
617
- if (authorizationCode !== void 0) throw new Error("Existing OAuth client information is required when exchanging an authorization code");
618
- const supportsUrlBasedClientId = metadata?.client_id_metadata_document_supported === true;
619
- const clientMetadataUrl = provider.clientMetadataUrl;
620
- if (clientMetadataUrl && !isHttpsUrl(clientMetadataUrl)) throw new InvalidClientMetadataError(`clientMetadataUrl must be a valid HTTPS URL with a non-root pathname, got: ${clientMetadataUrl}`);
621
- if (supportsUrlBasedClientId && clientMetadataUrl) {
622
- clientInformation = { client_id: clientMetadataUrl };
623
- await provider.saveClientInformation?.(clientInformation);
624
- } else {
625
- if (!provider.saveClientInformation) throw new Error("OAuth client information must be saveable for dynamic registration");
626
- const fullInformation = await registerClient(authorizationServerUrl, {
627
- metadata,
628
- clientMetadata: provider.clientMetadata,
629
- scope: resolvedScope,
630
- fetchFn
631
- });
632
- await provider.saveClientInformation(fullInformation);
633
- clientInformation = fullInformation;
634
- }
635
- }
636
- const nonInteractiveFlow = !provider.redirectUrl;
637
- if (authorizationCode !== void 0 || nonInteractiveFlow) {
638
- const tokens = await fetchToken(provider, authorizationServerUrl, {
639
- metadata,
640
- resource,
641
- authorizationCode,
642
- fetchFn
643
- });
644
- await provider.saveTokens(tokens);
645
- return "AUTHORIZED";
646
- }
647
- const tokens = await provider.tokens();
648
- if (tokens?.refresh_token) try {
649
- const newTokens = await refreshAuthorization(authorizationServerUrl, {
650
- metadata,
651
- clientInformation,
652
- refreshToken: tokens.refresh_token,
653
- resource,
654
- addClientAuthentication: provider.addClientAuthentication,
655
- fetchFn
656
- });
657
- await provider.saveTokens(newTokens);
658
- return "AUTHORIZED";
659
- } catch (error) {
660
- if (!(error instanceof OAuthError) || error instanceof ServerError) {} else throw error;
661
- }
662
- const state = provider.state ? await provider.state() : void 0;
663
- const { authorizationUrl, codeVerifier } = await startAuthorization(authorizationServerUrl, {
664
- metadata,
665
- clientInformation,
666
- state,
667
- redirectUrl: provider.redirectUrl,
668
- scope: resolvedScope,
669
- resource
670
- });
671
- await provider.saveCodeVerifier(codeVerifier);
672
- await provider.redirectToAuthorization(authorizationUrl);
673
- return "REDIRECT";
674
- }
675
- /**
676
- * SEP-991: URL-based Client IDs
677
- * Validate that the client_id is a valid URL with https scheme
678
- */
679
- function isHttpsUrl(value) {
680
- if (!value) return false;
681
- try {
682
- const url = new URL(value);
683
- return url.protocol === "https:" && url.pathname !== "/";
684
- } catch {
685
- return false;
686
- }
687
- }
688
- async function selectResourceURL(serverUrl, provider, resourceMetadata) {
689
- const defaultResource = resourceUrlFromServerUrl(serverUrl);
690
- if (provider.validateResourceURL) return await provider.validateResourceURL(defaultResource, resourceMetadata?.resource);
691
- if (!resourceMetadata) return;
692
- if (!checkResourceAllowed({
693
- requestedResource: defaultResource,
694
- configuredResource: resourceMetadata.resource
695
- })) throw new Error(`Protected resource ${resourceMetadata.resource} does not match expected ${defaultResource} (or origin)`);
696
- return new URL(resourceMetadata.resource);
697
- }
698
- /**
699
- * Extract resource_metadata, scope, and error from WWW-Authenticate header.
700
- */
701
- function extractWWWAuthenticateParams(res) {
702
- const authenticateHeader = res.headers.get("WWW-Authenticate");
703
- if (!authenticateHeader) return {};
704
- const [type, scheme] = authenticateHeader.split(" ");
705
- if (type.toLowerCase() !== "bearer" || !scheme) return {};
706
- const resourceMetadataMatch = extractFieldFromWwwAuth(res, "resource_metadata") || void 0;
707
- let resourceMetadataUrl;
708
- if (resourceMetadataMatch) try {
709
- resourceMetadataUrl = new URL(resourceMetadataMatch);
710
- } catch {}
711
- const scope = extractFieldFromWwwAuth(res, "scope") || void 0;
712
- const error = extractFieldFromWwwAuth(res, "error") || void 0;
713
- return {
714
- resourceMetadataUrl,
715
- scope,
716
- error
717
- };
718
- }
719
- /**
720
- * Extracts a specific field's value from the WWW-Authenticate header string.
721
- *
722
- * @param response The HTTP response object containing the headers.
723
- * @param fieldName The name of the field to extract (e.g., "realm", "nonce").
724
- * @returns The field value
725
- */
726
- function extractFieldFromWwwAuth(response, fieldName) {
727
- const wwwAuthHeader = response.headers.get("WWW-Authenticate");
728
- if (!wwwAuthHeader) return null;
729
- const pattern = new RegExp(`${fieldName}=(?:"([^"]+)"|([^\\s,]+))`);
730
- const match = wwwAuthHeader.match(pattern);
731
- if (match) return match[1] || match[2];
732
- return null;
733
- }
734
- /**
735
- * Looks up RFC 9728 OAuth 2.0 Protected Resource Metadata.
736
- *
737
- * If the server returns a 404 for the well-known endpoint, this function will
738
- * return `undefined`. Any other errors will be thrown as exceptions.
739
- */
740
- async function discoverOAuthProtectedResourceMetadata(serverUrl, opts, fetchFn = fetch) {
741
- const response = await discoverMetadataWithFallback(serverUrl, "oauth-protected-resource", fetchFn, {
742
- protocolVersion: opts?.protocolVersion,
743
- metadataUrl: opts?.resourceMetadataUrl
744
- });
745
- if (!response || response.status === 404) {
746
- await response?.body?.cancel();
747
- throw new Error(`Resource server does not implement OAuth 2.0 Protected Resource Metadata.`);
748
- }
749
- if (!response.ok) {
750
- await response.body?.cancel();
751
- throw new Error(`HTTP ${response.status} trying to load well-known OAuth protected resource metadata.`);
752
- }
753
- return OAuthProtectedResourceMetadataSchema.parse(await response.json());
754
- }
755
- /**
756
- * Helper function to handle fetch with CORS retry logic
757
- */
758
- async function fetchWithCorsRetry(url, headers, fetchFn = fetch) {
759
- try {
760
- return await fetchFn(url, { headers });
761
- } catch (error) {
762
- if (error instanceof TypeError) if (headers) return fetchWithCorsRetry(url, void 0, fetchFn);
763
- else return;
764
- throw error;
765
- }
766
- }
767
- /**
768
- * Constructs the well-known path for auth-related metadata discovery
769
- */
770
- function buildWellKnownPath(wellKnownPrefix, pathname = "", options = {}) {
771
- if (pathname.endsWith("/")) pathname = pathname.slice(0, -1);
772
- return options.prependPathname ? `${pathname}/.well-known/${wellKnownPrefix}` : `/.well-known/${wellKnownPrefix}${pathname}`;
773
- }
774
- /**
775
- * Tries to discover OAuth metadata at a specific URL
776
- */
777
- async function tryMetadataDiscovery(url, protocolVersion, fetchFn = fetch) {
778
- return await fetchWithCorsRetry(url, { "MCP-Protocol-Version": protocolVersion }, fetchFn);
779
- }
780
- /**
781
- * Determines if fallback to root discovery should be attempted
782
- */
783
- function shouldAttemptFallback(response, pathname) {
784
- return !response || response.status >= 400 && response.status < 500 && pathname !== "/";
785
- }
786
- /**
787
- * Generic function for discovering OAuth metadata with fallback support
788
- */
789
- async function discoverMetadataWithFallback(serverUrl, wellKnownType, fetchFn, opts) {
790
- const issuer = new URL(serverUrl);
791
- const protocolVersion = opts?.protocolVersion ?? "2025-11-25";
792
- let url;
793
- if (opts?.metadataUrl) url = new URL(opts.metadataUrl);
794
- else {
795
- const wellKnownPath = buildWellKnownPath(wellKnownType, issuer.pathname);
796
- url = new URL(wellKnownPath, opts?.metadataServerUrl ?? issuer);
797
- url.search = issuer.search;
798
- }
799
- let response = await tryMetadataDiscovery(url, protocolVersion, fetchFn);
800
- if (!opts?.metadataUrl && shouldAttemptFallback(response, issuer.pathname)) response = await tryMetadataDiscovery(new URL(`/.well-known/${wellKnownType}`, issuer), protocolVersion, fetchFn);
801
- return response;
802
- }
803
- /**
804
- * Builds a list of discovery URLs to try for authorization server metadata.
805
- * URLs are returned in priority order:
806
- * 1. OAuth metadata at the given URL
807
- * 2. OIDC metadata endpoints at the given URL
808
- */
809
- function buildDiscoveryUrls(authorizationServerUrl) {
810
- const url = typeof authorizationServerUrl === "string" ? new URL(authorizationServerUrl) : authorizationServerUrl;
811
- const hasPath = url.pathname !== "/";
812
- const urlsToTry = [];
813
- if (!hasPath) {
814
- urlsToTry.push({
815
- url: new URL("/.well-known/oauth-authorization-server", url.origin),
816
- type: "oauth"
817
- });
818
- urlsToTry.push({
819
- url: new URL(`/.well-known/openid-configuration`, url.origin),
820
- type: "oidc"
821
- });
822
- return urlsToTry;
823
- }
824
- let pathname = url.pathname;
825
- if (pathname.endsWith("/")) pathname = pathname.slice(0, -1);
826
- urlsToTry.push({
827
- url: new URL(`/.well-known/oauth-authorization-server${pathname}`, url.origin),
828
- type: "oauth"
829
- });
830
- urlsToTry.push({
831
- url: new URL(`/.well-known/openid-configuration${pathname}`, url.origin),
832
- type: "oidc"
833
- });
834
- urlsToTry.push({
835
- url: new URL(`${pathname}/.well-known/openid-configuration`, url.origin),
836
- type: "oidc"
837
- });
838
- return urlsToTry;
839
- }
840
- /**
841
- * Discovers authorization server metadata with support for RFC 8414 OAuth 2.0 Authorization Server Metadata
842
- * and OpenID Connect Discovery 1.0 specifications.
843
- *
844
- * This function implements a fallback strategy for authorization server discovery:
845
- * 1. Attempts RFC 8414 OAuth metadata discovery first
846
- * 2. If OAuth discovery fails, falls back to OpenID Connect Discovery
847
- *
848
- * @param authorizationServerUrl - The authorization server URL obtained from the MCP Server's
849
- * protected resource metadata, or the MCP server's URL if the
850
- * metadata was not found.
851
- * @param options - Configuration options
852
- * @param options.fetchFn - Optional fetch function for making HTTP requests, defaults to global fetch
853
- * @param options.protocolVersion - MCP protocol version to use, defaults to LATEST_PROTOCOL_VERSION
854
- * @returns Promise resolving to authorization server metadata, or undefined if discovery fails
855
- */
856
- async function discoverAuthorizationServerMetadata(authorizationServerUrl, { fetchFn = fetch, protocolVersion = LATEST_PROTOCOL_VERSION } = {}) {
857
- const headers = {
858
- "MCP-Protocol-Version": protocolVersion,
859
- Accept: "application/json"
860
- };
861
- const urlsToTry = buildDiscoveryUrls(authorizationServerUrl);
862
- for (const { url: endpointUrl, type } of urlsToTry) {
863
- const response = await fetchWithCorsRetry(endpointUrl, headers, fetchFn);
864
- if (!response)
865
- /**
866
- * CORS error occurred - don't throw as the endpoint may not allow CORS,
867
- * continue trying other possible endpoints
868
- */
869
- continue;
870
- if (!response.ok) {
871
- await response.body?.cancel();
872
- if (response.status >= 400 && response.status < 500) continue;
873
- throw new Error(`HTTP ${response.status} trying to load ${type === "oauth" ? "OAuth" : "OpenID provider"} metadata from ${endpointUrl}`);
874
- }
875
- if (type === "oauth") return OAuthMetadataSchema.parse(await response.json());
876
- else return OpenIdProviderDiscoveryMetadataSchema.parse(await response.json());
877
- }
878
- }
879
- /**
880
- * Discovers the authorization server for an MCP server following
881
- * {@link https://datatracker.ietf.org/doc/html/rfc9728 | RFC 9728} (OAuth 2.0 Protected
882
- * Resource Metadata), with fallback to treating the server URL as the
883
- * authorization server.
884
- *
885
- * This function combines two discovery steps into one call:
886
- * 1. Probes `/.well-known/oauth-protected-resource` on the MCP server to find the
887
- * authorization server URL (RFC 9728).
888
- * 2. Fetches authorization server metadata from that URL (RFC 8414 / OpenID Connect Discovery).
889
- *
890
- * Use this when you need the authorization server metadata for operations outside the
891
- * {@linkcode auth} orchestrator, such as token refresh or token revocation.
892
- *
893
- * @param serverUrl - The MCP resource server URL
894
- * @param opts - Optional configuration
895
- * @param opts.resourceMetadataUrl - Override URL for the protected resource metadata endpoint
896
- * @param opts.fetchFn - Custom fetch function for HTTP requests
897
- * @returns Authorization server URL, metadata, and resource metadata (if available)
898
- */
899
- async function discoverOAuthServerInfo(serverUrl, opts) {
900
- let resourceMetadata;
901
- let authorizationServerUrl;
902
- try {
903
- resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl: opts?.resourceMetadataUrl }, opts?.fetchFn);
904
- if (resourceMetadata.authorization_servers && resourceMetadata.authorization_servers.length > 0) authorizationServerUrl = resourceMetadata.authorization_servers[0];
905
- } catch {}
906
- if (!authorizationServerUrl) authorizationServerUrl = String(new URL("/", serverUrl));
907
- const authorizationServerMetadata = await discoverAuthorizationServerMetadata(authorizationServerUrl, { fetchFn: opts?.fetchFn });
908
- return {
909
- authorizationServerUrl,
910
- authorizationServerMetadata,
911
- resourceMetadata
912
- };
913
- }
914
- /**
915
- * Begins the authorization flow with the given server, by generating a PKCE challenge and constructing the authorization URL.
916
- */
917
- async function startAuthorization(authorizationServerUrl, { metadata, clientInformation, redirectUrl, scope, state, resource }) {
918
- let authorizationUrl;
919
- if (metadata) {
920
- authorizationUrl = new URL(metadata.authorization_endpoint);
921
- 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}`);
922
- 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}`);
923
- } else authorizationUrl = new URL("/authorize", authorizationServerUrl);
924
- const challenge = await pkceChallenge();
925
- const codeVerifier = challenge.code_verifier;
926
- const codeChallenge = challenge.code_challenge;
927
- authorizationUrl.searchParams.set("response_type", AUTHORIZATION_CODE_RESPONSE_TYPE);
928
- authorizationUrl.searchParams.set("client_id", clientInformation.client_id);
929
- authorizationUrl.searchParams.set("code_challenge", codeChallenge);
930
- authorizationUrl.searchParams.set("code_challenge_method", AUTHORIZATION_CODE_CHALLENGE_METHOD);
931
- authorizationUrl.searchParams.set("redirect_uri", String(redirectUrl));
932
- if (state) authorizationUrl.searchParams.set("state", state);
933
- if (scope) authorizationUrl.searchParams.set("scope", scope);
934
- if (scope?.includes("offline_access")) authorizationUrl.searchParams.append("prompt", "consent");
935
- if (resource) authorizationUrl.searchParams.set("resource", resource.href);
936
- return {
937
- authorizationUrl,
938
- codeVerifier
939
- };
940
- }
941
- /**
942
- * Prepares token request parameters for an authorization code exchange.
943
- *
944
- * This is the default implementation used by fetchToken when the provider
945
- * doesn't implement prepareTokenRequest.
946
- *
947
- * @param authorizationCode - The authorization code received from the authorization endpoint
948
- * @param codeVerifier - The PKCE code verifier
949
- * @param redirectUri - The redirect URI used in the authorization request
950
- * @returns URLSearchParams for the authorization_code grant
951
- */
952
- function prepareAuthorizationCodeRequest(authorizationCode, codeVerifier, redirectUri) {
953
- return new URLSearchParams({
954
- grant_type: "authorization_code",
955
- code: authorizationCode,
956
- code_verifier: codeVerifier,
957
- redirect_uri: String(redirectUri)
958
- });
959
- }
960
- /**
961
- * Internal helper to execute a token request with the given parameters.
962
- * Used by exchangeAuthorization, refreshAuthorization, and fetchToken.
963
- */
964
- async function executeTokenRequest(authorizationServerUrl, { metadata, tokenRequestParams, clientInformation, addClientAuthentication, resource, fetchFn }) {
965
- const tokenUrl = metadata?.token_endpoint ? new URL(metadata.token_endpoint) : new URL("/token", authorizationServerUrl);
966
- const headers = new Headers({
967
- "Content-Type": "application/x-www-form-urlencoded",
968
- Accept: "application/json"
969
- });
970
- if (resource) tokenRequestParams.set("resource", resource.href);
971
- if (addClientAuthentication) await addClientAuthentication(headers, tokenRequestParams, tokenUrl, metadata);
972
- else if (clientInformation) applyClientAuthentication(selectClientAuthMethod(clientInformation, metadata?.token_endpoint_auth_methods_supported ?? []), clientInformation, headers, tokenRequestParams);
973
- const response = await (fetchFn ?? fetch)(tokenUrl, {
974
- method: "POST",
975
- headers,
976
- body: tokenRequestParams
977
- });
978
- if (!response.ok) throw await parseErrorResponse(response);
979
- return OAuthTokensSchema.parse(await response.json());
980
- }
981
- /**
982
- * Exchange a refresh token for an updated access token.
983
- *
984
- * Supports multiple client authentication methods as specified in OAuth 2.1:
985
- * - Automatically selects the best authentication method based on server support
986
- * - Preserves the original refresh token if a new one is not returned
987
- *
988
- * @param authorizationServerUrl - The authorization server's base URL
989
- * @param options - Configuration object containing client info, refresh token, etc.
990
- * @returns Promise resolving to OAuth tokens (preserves original refresh_token if not replaced)
991
- * @throws {Error} When token refresh fails or authentication is invalid
992
- */
993
- async function refreshAuthorization(authorizationServerUrl, { metadata, clientInformation, refreshToken, resource, addClientAuthentication, fetchFn }) {
994
- return {
995
- refresh_token: refreshToken,
996
- ...await executeTokenRequest(authorizationServerUrl, {
997
- metadata,
998
- tokenRequestParams: new URLSearchParams({
999
- grant_type: "refresh_token",
1000
- refresh_token: refreshToken
1001
- }),
1002
- clientInformation,
1003
- addClientAuthentication,
1004
- resource,
1005
- fetchFn
1006
- })
1007
- };
1008
- }
1009
- /**
1010
- * Unified token fetching that works with any grant type via provider.prepareTokenRequest().
1011
- *
1012
- * This function provides a single entry point for obtaining tokens regardless of the
1013
- * OAuth grant type. The provider's prepareTokenRequest() method determines which grant
1014
- * to use and supplies the grant-specific parameters.
1015
- *
1016
- * @param provider - OAuth client provider that implements prepareTokenRequest()
1017
- * @param authorizationServerUrl - The authorization server's base URL
1018
- * @param options - Configuration for the token request
1019
- * @returns Promise resolving to OAuth tokens
1020
- * @throws {Error} When provider doesn't implement prepareTokenRequest or token fetch fails
1021
- *
1022
- * @example
1023
- * // Provider for client_credentials:
1024
- * class MyProvider implements OAuthClientProvider {
1025
- * prepareTokenRequest(scope) {
1026
- * const params = new URLSearchParams({ grant_type: 'client_credentials' });
1027
- * if (scope) params.set('scope', scope);
1028
- * return params;
1029
- * }
1030
- * // ... other methods
1031
- * }
1032
- *
1033
- * const tokens = await fetchToken(provider, authServerUrl, { metadata });
1034
- */
1035
- async function fetchToken(provider, authorizationServerUrl, { metadata, resource, authorizationCode, fetchFn } = {}) {
1036
- const scope = provider.clientMetadata.scope;
1037
- let tokenRequestParams;
1038
- if (provider.prepareTokenRequest) tokenRequestParams = await provider.prepareTokenRequest(scope);
1039
- if (!tokenRequestParams) {
1040
- if (!authorizationCode) throw new Error("Either provider.prepareTokenRequest() or authorizationCode is required");
1041
- if (!provider.redirectUrl) throw new Error("redirectUrl is required for authorization_code flow");
1042
- tokenRequestParams = prepareAuthorizationCodeRequest(authorizationCode, await provider.codeVerifier(), provider.redirectUrl);
1043
- }
1044
- const clientInformation = await provider.clientInformation();
1045
- return executeTokenRequest(authorizationServerUrl, {
1046
- metadata,
1047
- tokenRequestParams,
1048
- clientInformation: clientInformation ?? void 0,
1049
- addClientAuthentication: provider.addClientAuthentication,
1050
- resource,
1051
- fetchFn
1052
- });
1053
- }
1054
- /**
1055
- * Performs OAuth 2.0 Dynamic Client Registration according to RFC 7591.
1056
- *
1057
- * If `scope` is provided, it overrides `clientMetadata.scope` in the registration
1058
- * request body. This allows callers to apply the Scope Selection Strategy (SEP-835)
1059
- * consistently across both DCR and the subsequent authorization request.
1060
- */
1061
- async function registerClient(authorizationServerUrl, { metadata, clientMetadata, scope, fetchFn }) {
1062
- let registrationUrl;
1063
- if (metadata) {
1064
- if (!metadata.registration_endpoint) throw new Error("Incompatible auth server: does not support dynamic client registration");
1065
- registrationUrl = new URL(metadata.registration_endpoint);
1066
- } else registrationUrl = new URL("/register", authorizationServerUrl);
1067
- const response = await (fetchFn ?? fetch)(registrationUrl, {
1068
- method: "POST",
1069
- headers: { "Content-Type": "application/json" },
1070
- body: JSON.stringify({
1071
- ...clientMetadata,
1072
- ...scope !== void 0 ? { scope } : {}
1073
- })
1074
- });
1075
- if (!response.ok) throw await parseErrorResponse(response);
1076
- return OAuthClientInformationFullSchema.parse(await response.json());
1077
- }
1078
- //#endregion
1079
- //#region ../../node_modules/.pnpm/eventsource-parser@3.0.6/node_modules/eventsource-parser/dist/index.js
1080
- var ParseError = class extends Error {
1081
- constructor(message, options) {
1082
- super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
1083
- }
1084
- };
1085
- function noop(_arg) {}
1086
- function createParser(callbacks) {
1087
- if (typeof callbacks == "function") throw new TypeError("`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?");
1088
- const { onEvent = noop, onError = noop, onRetry = noop, onComment } = callbacks;
1089
- let incompleteLine = "", isFirstChunk = !0, id, data = "", eventType = "";
1090
- function feed(newChunk) {
1091
- const chunk = isFirstChunk ? newChunk.replace(/^\xEF\xBB\xBF/, "") : newChunk, [complete, incomplete] = splitLines(`${incompleteLine}${chunk}`);
1092
- for (const line of complete) parseLine(line);
1093
- incompleteLine = incomplete, isFirstChunk = !1;
1094
- }
1095
- function parseLine(line) {
1096
- if (line === "") {
1097
- dispatchEvent();
1098
- return;
1099
- }
1100
- if (line.startsWith(":")) {
1101
- onComment && onComment(line.slice(line.startsWith(": ") ? 2 : 1));
1102
- return;
1103
- }
1104
- const fieldSeparatorIndex = line.indexOf(":");
1105
- if (fieldSeparatorIndex !== -1) {
1106
- const field = line.slice(0, fieldSeparatorIndex), offset = line[fieldSeparatorIndex + 1] === " " ? 2 : 1;
1107
- processField(field, line.slice(fieldSeparatorIndex + offset), line);
1108
- return;
1109
- }
1110
- processField(line, "", line);
1111
- }
1112
- function processField(field, value, line) {
1113
- switch (field) {
1114
- case "event":
1115
- eventType = value;
1116
- break;
1117
- case "data":
1118
- data = `${data}${value}
1119
- `;
1120
- break;
1121
- case "id":
1122
- id = value.includes("\0") ? void 0 : value;
1123
- break;
1124
- case "retry":
1125
- /^\d+$/.test(value) ? onRetry(parseInt(value, 10)) : onError(new ParseError(`Invalid \`retry\` value: "${value}"`, {
1126
- type: "invalid-retry",
1127
- value,
1128
- line
1129
- }));
1130
- break;
1131
- default:
1132
- onError(new ParseError(`Unknown field "${field.length > 20 ? `${field.slice(0, 20)}\u2026` : field}"`, {
1133
- type: "unknown-field",
1134
- field,
1135
- value,
1136
- line
1137
- }));
1138
- break;
1139
- }
1140
- }
1141
- function dispatchEvent() {
1142
- data.length > 0 && onEvent({
1143
- id,
1144
- event: eventType || void 0,
1145
- data: data.endsWith(`
1146
- `) ? data.slice(0, -1) : data
1147
- }), id = void 0, data = "", eventType = "";
1148
- }
1149
- function reset(options = {}) {
1150
- incompleteLine && options.consume && parseLine(incompleteLine), isFirstChunk = !0, id = void 0, data = "", eventType = "", incompleteLine = "";
1151
- }
1152
- return {
1153
- feed,
1154
- reset
1155
- };
1156
- }
1157
- function splitLines(chunk) {
1158
- const lines = [];
1159
- let incompleteLine = "", searchIndex = 0;
1160
- for (; searchIndex < chunk.length;) {
1161
- const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
1162
- `, searchIndex);
1163
- let lineEnd = -1;
1164
- if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = Math.min(crIndex, lfIndex) : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1) {
1165
- incompleteLine = chunk.slice(searchIndex);
1166
- break;
1167
- } else {
1168
- const line = chunk.slice(searchIndex, lineEnd);
1169
- lines.push(line), searchIndex = lineEnd + 1, chunk[searchIndex - 1] === "\r" && chunk[searchIndex] === `
1170
- ` && searchIndex++;
1171
- }
1172
- }
1173
- return [lines, incompleteLine];
1174
- }
1175
- //#endregion
1176
- //#region ../../node_modules/.pnpm/eventsource-parser@3.0.6/node_modules/eventsource-parser/dist/stream.js
1177
- var EventSourceParserStream = class extends TransformStream {
1178
- constructor({ onError, onRetry, onComment } = {}) {
1179
- let parser;
1180
- super({
1181
- start(controller) {
1182
- parser = createParser({
1183
- onEvent: (event) => {
1184
- controller.enqueue(event);
1185
- },
1186
- onError(error) {
1187
- onError === "terminate" ? controller.error(error) : typeof onError == "function" && onError(error);
1188
- },
1189
- onRetry,
1190
- onComment
1191
- });
1192
- },
1193
- transform(chunk) {
1194
- parser.feed(chunk);
1195
- }
1196
- });
1197
- }
1198
- };
1199
- //#endregion
1200
- //#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.29.0_zod@4.3.6/node_modules/@modelcontextprotocol/sdk/dist/esm/client/streamableHttp.js
1201
- const DEFAULT_STREAMABLE_HTTP_RECONNECTION_OPTIONS = {
1202
- initialReconnectionDelay: 1e3,
1203
- maxReconnectionDelay: 3e4,
1204
- reconnectionDelayGrowFactor: 1.5,
1205
- maxRetries: 2
1206
- };
1207
- var StreamableHTTPError = class extends Error {
1208
- constructor(code, message) {
1209
- super(`Streamable HTTP error: ${message}`);
1210
- this.code = code;
1211
- }
1212
- };
1213
- /**
1214
- * Client transport for Streamable HTTP: this implements the MCP Streamable HTTP transport specification.
1215
- * It will connect to a server using HTTP POST for sending messages and HTTP GET with Server-Sent Events
1216
- * for receiving messages.
1217
- */
1218
- var StreamableHTTPClientTransport = class {
1219
- constructor(url, opts) {
1220
- this._hasCompletedAuthFlow = false;
1221
- this._url = url;
1222
- this._resourceMetadataUrl = void 0;
1223
- this._scope = void 0;
1224
- this._requestInit = opts?.requestInit;
1225
- this._authProvider = opts?.authProvider;
1226
- this._fetch = opts?.fetch;
1227
- this._fetchWithInit = createFetchWithInit(opts?.fetch, opts?.requestInit);
1228
- this._sessionId = opts?.sessionId;
1229
- this._reconnectionOptions = opts?.reconnectionOptions ?? DEFAULT_STREAMABLE_HTTP_RECONNECTION_OPTIONS;
1230
- }
1231
- async _authThenStart() {
1232
- if (!this._authProvider) throw new UnauthorizedError("No auth provider");
1233
- let result;
1234
- try {
1235
- result = await auth(this._authProvider, {
1236
- serverUrl: this._url,
1237
- resourceMetadataUrl: this._resourceMetadataUrl,
1238
- scope: this._scope,
1239
- fetchFn: this._fetchWithInit
1240
- });
1241
- } catch (error) {
1242
- this.onerror?.(error);
1243
- throw error;
1244
- }
1245
- if (result !== "AUTHORIZED") throw new UnauthorizedError();
1246
- return await this._startOrAuthSse({ resumptionToken: void 0 });
1247
- }
1248
- async _commonHeaders() {
1249
- const headers = {};
1250
- if (this._authProvider) {
1251
- const tokens = await this._authProvider.tokens();
1252
- if (tokens) headers["Authorization"] = `Bearer ${tokens.access_token}`;
1253
- }
1254
- if (this._sessionId) headers["mcp-session-id"] = this._sessionId;
1255
- if (this._protocolVersion) headers["mcp-protocol-version"] = this._protocolVersion;
1256
- const extraHeaders = normalizeHeaders(this._requestInit?.headers);
1257
- return new Headers({
1258
- ...headers,
1259
- ...extraHeaders
1260
- });
1261
- }
1262
- async _startOrAuthSse(options) {
1263
- const { resumptionToken } = options;
1264
- try {
1265
- const headers = await this._commonHeaders();
1266
- headers.set("Accept", "text/event-stream");
1267
- if (resumptionToken) headers.set("last-event-id", resumptionToken);
1268
- const response = await (this._fetch ?? fetch)(this._url, {
1269
- method: "GET",
1270
- headers,
1271
- signal: this._abortController?.signal
1272
- });
1273
- if (!response.ok) {
1274
- await response.body?.cancel();
1275
- if (response.status === 401 && this._authProvider) return await this._authThenStart();
1276
- if (response.status === 405) return;
1277
- throw new StreamableHTTPError(response.status, `Failed to open SSE stream: ${response.statusText}`);
1278
- }
1279
- this._handleSseStream(response.body, options, true);
1280
- } catch (error) {
1281
- this.onerror?.(error);
1282
- throw error;
1283
- }
1284
- }
1285
- /**
1286
- * Calculates the next reconnection delay using backoff algorithm
1287
- *
1288
- * @param attempt Current reconnection attempt count for the specific stream
1289
- * @returns Time to wait in milliseconds before next reconnection attempt
1290
- */
1291
- _getNextReconnectionDelay(attempt) {
1292
- if (this._serverRetryMs !== void 0) return this._serverRetryMs;
1293
- const initialDelay = this._reconnectionOptions.initialReconnectionDelay;
1294
- const growFactor = this._reconnectionOptions.reconnectionDelayGrowFactor;
1295
- const maxDelay = this._reconnectionOptions.maxReconnectionDelay;
1296
- return Math.min(initialDelay * Math.pow(growFactor, attempt), maxDelay);
1297
- }
1298
- /**
1299
- * Schedule a reconnection attempt using server-provided retry interval or backoff
1300
- *
1301
- * @param lastEventId The ID of the last received event for resumability
1302
- * @param attemptCount Current reconnection attempt count for this specific stream
1303
- */
1304
- _scheduleReconnection(options, attemptCount = 0) {
1305
- const maxRetries = this._reconnectionOptions.maxRetries;
1306
- if (attemptCount >= maxRetries) {
1307
- this.onerror?.(/* @__PURE__ */ new Error(`Maximum reconnection attempts (${maxRetries}) exceeded.`));
1308
- return;
1309
- }
1310
- const delay = this._getNextReconnectionDelay(attemptCount);
1311
- this._reconnectionTimeout = setTimeout(() => {
1312
- this._startOrAuthSse(options).catch((error) => {
1313
- this.onerror?.(/* @__PURE__ */ new Error(`Failed to reconnect SSE stream: ${error instanceof Error ? error.message : String(error)}`));
1314
- this._scheduleReconnection(options, attemptCount + 1);
1315
- });
1316
- }, delay);
1317
- }
1318
- _handleSseStream(stream, options, isReconnectable) {
1319
- if (!stream) return;
1320
- const { onresumptiontoken, replayMessageId } = options;
1321
- let lastEventId;
1322
- let hasPrimingEvent = false;
1323
- let receivedResponse = false;
1324
- const processStream = async () => {
1325
- try {
1326
- const reader = stream.pipeThrough(new TextDecoderStream()).pipeThrough(new EventSourceParserStream({ onRetry: (retryMs) => {
1327
- this._serverRetryMs = retryMs;
1328
- } })).getReader();
1329
- while (true) {
1330
- const { value: event, done } = await reader.read();
1331
- if (done) break;
1332
- if (event.id) {
1333
- lastEventId = event.id;
1334
- hasPrimingEvent = true;
1335
- onresumptiontoken?.(event.id);
1336
- }
1337
- if (!event.data) continue;
1338
- if (!event.event || event.event === "message") try {
1339
- const message = JSONRPCMessageSchema.parse(JSON.parse(event.data));
1340
- if (isJSONRPCResultResponse(message)) {
1341
- receivedResponse = true;
1342
- if (replayMessageId !== void 0) message.id = replayMessageId;
1343
- }
1344
- this.onmessage?.(message);
1345
- } catch (error) {
1346
- this.onerror?.(error);
1347
- }
1348
- }
1349
- if ((isReconnectable || hasPrimingEvent) && !receivedResponse && this._abortController && !this._abortController.signal.aborted) this._scheduleReconnection({
1350
- resumptionToken: lastEventId,
1351
- onresumptiontoken,
1352
- replayMessageId
1353
- }, 0);
1354
- } catch (error) {
1355
- this.onerror?.(/* @__PURE__ */ new Error(`SSE stream disconnected: ${error}`));
1356
- if ((isReconnectable || hasPrimingEvent) && !receivedResponse && this._abortController && !this._abortController.signal.aborted) try {
1357
- this._scheduleReconnection({
1358
- resumptionToken: lastEventId,
1359
- onresumptiontoken,
1360
- replayMessageId
1361
- }, 0);
1362
- } catch (error) {
1363
- this.onerror?.(/* @__PURE__ */ new Error(`Failed to reconnect: ${error instanceof Error ? error.message : String(error)}`));
1364
- }
1365
- }
1366
- };
1367
- processStream();
1368
- }
1369
- async start() {
1370
- if (this._abortController) throw new Error("StreamableHTTPClientTransport already started! If using Client class, note that connect() calls start() automatically.");
1371
- this._abortController = new AbortController();
1372
- }
1373
- /**
1374
- * Call this method after the user has finished authorizing via their user agent and is redirected back to the MCP client application. This will exchange the authorization code for an access token, enabling the next connection attempt to successfully auth.
1375
- */
1376
- async finishAuth(authorizationCode) {
1377
- if (!this._authProvider) throw new UnauthorizedError("No auth provider");
1378
- if (await auth(this._authProvider, {
1379
- serverUrl: this._url,
1380
- authorizationCode,
1381
- resourceMetadataUrl: this._resourceMetadataUrl,
1382
- scope: this._scope,
1383
- fetchFn: this._fetchWithInit
1384
- }) !== "AUTHORIZED") throw new UnauthorizedError("Failed to authorize");
1385
- }
1386
- async close() {
1387
- if (this._reconnectionTimeout) {
1388
- clearTimeout(this._reconnectionTimeout);
1389
- this._reconnectionTimeout = void 0;
1390
- }
1391
- this._abortController?.abort();
1392
- this.onclose?.();
1393
- }
1394
- async send(message, options) {
1395
- try {
1396
- const { resumptionToken, onresumptiontoken } = options || {};
1397
- if (resumptionToken) {
1398
- this._startOrAuthSse({
1399
- resumptionToken,
1400
- replayMessageId: isJSONRPCRequest(message) ? message.id : void 0
1401
- }).catch((err) => this.onerror?.(err));
1402
- return;
1403
- }
1404
- const headers = await this._commonHeaders();
1405
- headers.set("content-type", "application/json");
1406
- headers.set("accept", "application/json, text/event-stream");
1407
- const init = {
1408
- ...this._requestInit,
1409
- method: "POST",
1410
- headers,
1411
- body: JSON.stringify(message),
1412
- signal: this._abortController?.signal
1413
- };
1414
- const response = await (this._fetch ?? fetch)(this._url, init);
1415
- const sessionId = response.headers.get("mcp-session-id");
1416
- if (sessionId) this._sessionId = sessionId;
1417
- if (!response.ok) {
1418
- const text = await response.text().catch(() => null);
1419
- if (response.status === 401 && this._authProvider) {
1420
- if (this._hasCompletedAuthFlow) throw new StreamableHTTPError(401, "Server returned 401 after successful authentication");
1421
- const { resourceMetadataUrl, scope } = extractWWWAuthenticateParams(response);
1422
- this._resourceMetadataUrl = resourceMetadataUrl;
1423
- this._scope = scope;
1424
- if (await auth(this._authProvider, {
1425
- serverUrl: this._url,
1426
- resourceMetadataUrl: this._resourceMetadataUrl,
1427
- scope: this._scope,
1428
- fetchFn: this._fetchWithInit
1429
- }) !== "AUTHORIZED") throw new UnauthorizedError();
1430
- this._hasCompletedAuthFlow = true;
1431
- return this.send(message);
1432
- }
1433
- if (response.status === 403 && this._authProvider) {
1434
- const { resourceMetadataUrl, scope, error } = extractWWWAuthenticateParams(response);
1435
- if (error === "insufficient_scope") {
1436
- const wwwAuthHeader = response.headers.get("WWW-Authenticate");
1437
- if (this._lastUpscopingHeader === wwwAuthHeader) throw new StreamableHTTPError(403, "Server returned 403 after trying upscoping");
1438
- if (scope) this._scope = scope;
1439
- if (resourceMetadataUrl) this._resourceMetadataUrl = resourceMetadataUrl;
1440
- this._lastUpscopingHeader = wwwAuthHeader ?? void 0;
1441
- if (await auth(this._authProvider, {
1442
- serverUrl: this._url,
1443
- resourceMetadataUrl: this._resourceMetadataUrl,
1444
- scope: this._scope,
1445
- fetchFn: this._fetch
1446
- }) !== "AUTHORIZED") throw new UnauthorizedError();
1447
- return this.send(message);
1448
- }
1449
- }
1450
- throw new StreamableHTTPError(response.status, `Error POSTing to endpoint: ${text}`);
1451
- }
1452
- this._hasCompletedAuthFlow = false;
1453
- this._lastUpscopingHeader = void 0;
1454
- if (response.status === 202) {
1455
- await response.body?.cancel();
1456
- if (isInitializedNotification(message)) this._startOrAuthSse({ resumptionToken: void 0 }).catch((err) => this.onerror?.(err));
1457
- return;
1458
- }
1459
- const hasRequests = (Array.isArray(message) ? message : [message]).filter((msg) => "method" in msg && "id" in msg && msg.id !== void 0).length > 0;
1460
- const contentType = response.headers.get("content-type");
1461
- if (hasRequests) if (contentType?.includes("text/event-stream")) this._handleSseStream(response.body, { onresumptiontoken }, false);
1462
- else if (contentType?.includes("application/json")) {
1463
- const data = await response.json();
1464
- const responseMessages = Array.isArray(data) ? data.map((msg) => JSONRPCMessageSchema.parse(msg)) : [JSONRPCMessageSchema.parse(data)];
1465
- for (const msg of responseMessages) this.onmessage?.(msg);
1466
- } else {
1467
- await response.body?.cancel();
1468
- throw new StreamableHTTPError(-1, `Unexpected content type: ${contentType}`);
1469
- }
1470
- else await response.body?.cancel();
1471
- } catch (error) {
1472
- this.onerror?.(error);
1473
- throw error;
1474
- }
1475
- }
1476
- get sessionId() {
1477
- return this._sessionId;
1478
- }
1479
- /**
1480
- * Terminates the current session by sending a DELETE request to the server.
1481
- *
1482
- * Clients that no longer need a particular session
1483
- * (e.g., because the user is leaving the client application) SHOULD send an
1484
- * HTTP DELETE to the MCP endpoint with the Mcp-Session-Id header to explicitly
1485
- * terminate the session.
1486
- *
1487
- * The server MAY respond with HTTP 405 Method Not Allowed, indicating that
1488
- * the server does not allow clients to terminate sessions.
1489
- */
1490
- async terminateSession() {
1491
- if (!this._sessionId) return;
1492
- try {
1493
- const headers = await this._commonHeaders();
1494
- const init = {
1495
- ...this._requestInit,
1496
- method: "DELETE",
1497
- headers,
1498
- signal: this._abortController?.signal
1499
- };
1500
- const response = await (this._fetch ?? fetch)(this._url, init);
1501
- await response.body?.cancel();
1502
- if (!response.ok && response.status !== 405) throw new StreamableHTTPError(response.status, `Failed to terminate session: ${response.statusText}`);
1503
- this._sessionId = void 0;
1504
- } catch (error) {
1505
- this.onerror?.(error);
1506
- throw error;
1507
- }
1508
- }
1509
- setProtocolVersion(version) {
1510
- this._protocolVersion = version;
1511
- }
1512
- get protocolVersion() {
1513
- return this._protocolVersion;
1514
- }
1515
- /**
1516
- * Resume an SSE stream from a previous event ID.
1517
- * Opens a GET SSE connection with Last-Event-ID header to replay missed events.
1518
- *
1519
- * @param lastEventId The event ID to resume from
1520
- * @param options Optional callback to receive new resumption tokens
1521
- */
1522
- async resumeStream(lastEventId, options) {
1523
- await this._startOrAuthSse({
1524
- resumptionToken: lastEventId,
1525
- onresumptiontoken: options?.onresumptiontoken
1526
- });
1527
- }
1528
- };
1529
- //#endregion
1530
- export { StreamableHTTPClientTransport };