mcp-remote 0.1.17 → 0.1.19

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.
@@ -10301,10 +10301,11 @@ var z = /* @__PURE__ */ Object.freeze({
10301
10301
  ZodError
10302
10302
  });
10303
10303
 
10304
- // node_modules/.pnpm/@modelcontextprotocol+sdk@https+++pkg.pr.new+geelen+typescript-sdk+@modelcontextprotocol+sdk@cdf3508/node_modules/@modelcontextprotocol/sdk/dist/esm/types.js
10305
- var LATEST_PROTOCOL_VERSION = "2025-03-26";
10304
+ // node_modules/.pnpm/@modelcontextprotocol+sdk@1.17.4/node_modules/@modelcontextprotocol/sdk/dist/esm/types.js
10305
+ var LATEST_PROTOCOL_VERSION = "2025-06-18";
10306
10306
  var SUPPORTED_PROTOCOL_VERSIONS = [
10307
10307
  LATEST_PROTOCOL_VERSION,
10308
+ "2025-03-26",
10308
10309
  "2024-11-05",
10309
10310
  "2024-10-07"
10310
10311
  ];
@@ -10326,7 +10327,8 @@ var RequestSchema = z.object({
10326
10327
  });
10327
10328
  var BaseNotificationParamsSchema = z.object({
10328
10329
  /**
10329
- * This parameter name is reserved by MCP to allow clients and servers to attach additional metadata to their notifications.
10330
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
10331
+ * for notes on _meta usage.
10330
10332
  */
10331
10333
  _meta: z.optional(z.object({}).passthrough())
10332
10334
  }).passthrough();
@@ -10336,7 +10338,8 @@ var NotificationSchema = z.object({
10336
10338
  });
10337
10339
  var ResultSchema = z.object({
10338
10340
  /**
10339
- * This result property is reserved by the protocol to allow clients and servers to attach additional metadata to their responses.
10341
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
10342
+ * for notes on _meta usage.
10340
10343
  */
10341
10344
  _meta: z.optional(z.object({}).passthrough())
10342
10345
  }).passthrough();
@@ -10407,10 +10410,22 @@ var CancelledNotificationSchema = NotificationSchema.extend({
10407
10410
  reason: z.string().optional()
10408
10411
  })
10409
10412
  });
10410
- var ImplementationSchema = z.object({
10413
+ var BaseMetadataSchema = z.object({
10414
+ /** Intended for programmatic or logical use, but used as a display name in past specs or fallback */
10411
10415
  name: z.string(),
10412
- version: z.string()
10416
+ /**
10417
+ * Intended for UI and end-user contexts — optimized to be human-readable and easily understood,
10418
+ * even by those unfamiliar with domain-specific terminology.
10419
+ *
10420
+ * If not provided, the name should be used for display (except for Tool,
10421
+ * where `annotations.title` should be given precedence over using `name`,
10422
+ * if present).
10423
+ */
10424
+ title: z.optional(z.string())
10413
10425
  }).passthrough();
10426
+ var ImplementationSchema = BaseMetadataSchema.extend({
10427
+ version: z.string()
10428
+ });
10414
10429
  var ClientCapabilitiesSchema = z.object({
10415
10430
  /**
10416
10431
  * Experimental, non-standard capabilities that the client supports.
@@ -10420,6 +10435,10 @@ var ClientCapabilitiesSchema = z.object({
10420
10435
  * Present if the client supports sampling from an LLM.
10421
10436
  */
10422
10437
  sampling: z.optional(z.object({}).passthrough()),
10438
+ /**
10439
+ * Present if the client supports eliciting user input.
10440
+ */
10441
+ elicitation: z.optional(z.object({}).passthrough()),
10423
10442
  /**
10424
10443
  * Present if the client supports listing roots.
10425
10444
  */
@@ -10554,7 +10573,12 @@ var ResourceContentsSchema = z.object({
10554
10573
  /**
10555
10574
  * The MIME type of this resource, if known.
10556
10575
  */
10557
- mimeType: z.optional(z.string())
10576
+ mimeType: z.optional(z.string()),
10577
+ /**
10578
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
10579
+ * for notes on _meta usage.
10580
+ */
10581
+ _meta: z.optional(z.object({}).passthrough())
10558
10582
  }).passthrough();
10559
10583
  var TextResourceContentsSchema = ResourceContentsSchema.extend({
10560
10584
  /**
@@ -10562,23 +10586,25 @@ var TextResourceContentsSchema = ResourceContentsSchema.extend({
10562
10586
  */
10563
10587
  text: z.string()
10564
10588
  });
10589
+ var Base64Schema = z.string().refine((val) => {
10590
+ try {
10591
+ atob(val);
10592
+ return true;
10593
+ } catch (_a) {
10594
+ return false;
10595
+ }
10596
+ }, { message: "Invalid Base64 string" });
10565
10597
  var BlobResourceContentsSchema = ResourceContentsSchema.extend({
10566
10598
  /**
10567
10599
  * A base64-encoded string representing the binary data of the item.
10568
10600
  */
10569
- blob: z.string().base64()
10601
+ blob: Base64Schema
10570
10602
  });
10571
- var ResourceSchema = z.object({
10603
+ var ResourceSchema = BaseMetadataSchema.extend({
10572
10604
  /**
10573
10605
  * The URI of this resource.
10574
10606
  */
10575
10607
  uri: z.string(),
10576
- /**
10577
- * A human-readable name for this resource.
10578
- *
10579
- * This can be used by clients to populate UI elements.
10580
- */
10581
- name: z.string(),
10582
10608
  /**
10583
10609
  * A description of what this resource represents.
10584
10610
  *
@@ -10588,19 +10614,18 @@ var ResourceSchema = z.object({
10588
10614
  /**
10589
10615
  * The MIME type of this resource, if known.
10590
10616
  */
10591
- mimeType: z.optional(z.string())
10592
- }).passthrough();
10593
- var ResourceTemplateSchema = z.object({
10617
+ mimeType: z.optional(z.string()),
10594
10618
  /**
10595
- * A URI template (according to RFC 6570) that can be used to construct resource URIs.
10619
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
10620
+ * for notes on _meta usage.
10596
10621
  */
10597
- uriTemplate: z.string(),
10622
+ _meta: z.optional(z.object({}).passthrough())
10623
+ });
10624
+ var ResourceTemplateSchema = BaseMetadataSchema.extend({
10598
10625
  /**
10599
- * A human-readable name for the type of resource this template refers to.
10600
- *
10601
- * This can be used by clients to populate UI elements.
10626
+ * A URI template (according to RFC 6570) that can be used to construct resource URIs.
10602
10627
  */
10603
- name: z.string(),
10628
+ uriTemplate: z.string(),
10604
10629
  /**
10605
10630
  * A description of what this template is for.
10606
10631
  *
@@ -10610,8 +10635,13 @@ var ResourceTemplateSchema = z.object({
10610
10635
  /**
10611
10636
  * The MIME type for all resources that match this template. This should only be included if all resources matching this template have the same type.
10612
10637
  */
10613
- mimeType: z.optional(z.string())
10614
- }).passthrough();
10638
+ mimeType: z.optional(z.string()),
10639
+ /**
10640
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
10641
+ * for notes on _meta usage.
10642
+ */
10643
+ _meta: z.optional(z.object({}).passthrough())
10644
+ });
10615
10645
  var ListResourcesRequestSchema = PaginatedRequestSchema.extend({
10616
10646
  method: z.literal("resources/list")
10617
10647
  });
@@ -10680,11 +10710,7 @@ var PromptArgumentSchema = z.object({
10680
10710
  */
10681
10711
  required: z.optional(z.boolean())
10682
10712
  }).passthrough();
10683
- var PromptSchema = z.object({
10684
- /**
10685
- * The name of the prompt or prompt template.
10686
- */
10687
- name: z.string(),
10713
+ var PromptSchema = BaseMetadataSchema.extend({
10688
10714
  /**
10689
10715
  * An optional description of what this prompt provides
10690
10716
  */
@@ -10692,8 +10718,13 @@ var PromptSchema = z.object({
10692
10718
  /**
10693
10719
  * A list of arguments to use for templating the prompt.
10694
10720
  */
10695
- arguments: z.optional(z.array(PromptArgumentSchema))
10696
- }).passthrough();
10721
+ arguments: z.optional(z.array(PromptArgumentSchema)),
10722
+ /**
10723
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
10724
+ * for notes on _meta usage.
10725
+ */
10726
+ _meta: z.optional(z.object({}).passthrough())
10727
+ });
10697
10728
  var ListPromptsRequestSchema = PaginatedRequestSchema.extend({
10698
10729
  method: z.literal("prompts/list")
10699
10730
  });
@@ -10718,42 +10749,67 @@ var TextContentSchema = z.object({
10718
10749
  /**
10719
10750
  * The text content of the message.
10720
10751
  */
10721
- text: z.string()
10752
+ text: z.string(),
10753
+ /**
10754
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
10755
+ * for notes on _meta usage.
10756
+ */
10757
+ _meta: z.optional(z.object({}).passthrough())
10722
10758
  }).passthrough();
10723
10759
  var ImageContentSchema = z.object({
10724
10760
  type: z.literal("image"),
10725
10761
  /**
10726
10762
  * The base64-encoded image data.
10727
10763
  */
10728
- data: z.string().base64(),
10764
+ data: Base64Schema,
10729
10765
  /**
10730
10766
  * The MIME type of the image. Different providers may support different image types.
10731
10767
  */
10732
- mimeType: z.string()
10768
+ mimeType: z.string(),
10769
+ /**
10770
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
10771
+ * for notes on _meta usage.
10772
+ */
10773
+ _meta: z.optional(z.object({}).passthrough())
10733
10774
  }).passthrough();
10734
10775
  var AudioContentSchema = z.object({
10735
10776
  type: z.literal("audio"),
10736
10777
  /**
10737
10778
  * The base64-encoded audio data.
10738
10779
  */
10739
- data: z.string().base64(),
10780
+ data: Base64Schema,
10740
10781
  /**
10741
10782
  * The MIME type of the audio. Different providers may support different audio types.
10742
10783
  */
10743
- mimeType: z.string()
10784
+ mimeType: z.string(),
10785
+ /**
10786
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
10787
+ * for notes on _meta usage.
10788
+ */
10789
+ _meta: z.optional(z.object({}).passthrough())
10744
10790
  }).passthrough();
10745
10791
  var EmbeddedResourceSchema = z.object({
10746
10792
  type: z.literal("resource"),
10747
- resource: z.union([TextResourceContentsSchema, BlobResourceContentsSchema])
10793
+ resource: z.union([TextResourceContentsSchema, BlobResourceContentsSchema]),
10794
+ /**
10795
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
10796
+ * for notes on _meta usage.
10797
+ */
10798
+ _meta: z.optional(z.object({}).passthrough())
10748
10799
  }).passthrough();
10800
+ var ResourceLinkSchema = ResourceSchema.extend({
10801
+ type: z.literal("resource_link")
10802
+ });
10803
+ var ContentBlockSchema = z.union([
10804
+ TextContentSchema,
10805
+ ImageContentSchema,
10806
+ AudioContentSchema,
10807
+ ResourceLinkSchema,
10808
+ EmbeddedResourceSchema
10809
+ ]);
10749
10810
  var PromptMessageSchema = z.object({
10750
10811
  role: z.enum(["user", "assistant"]),
10751
- content: z.union([
10752
- TextContentSchema,
10753
- ImageContentSchema,
10754
- AudioContentSchema,
10755
- EmbeddedResourceSchema
10756
- ])
10812
+ content: ContentBlockSchema
10757
10813
  }).passthrough();
10758
10814
  var GetPromptResultSchema = ResultSchema.extend({
10759
10815
  /**
@@ -10804,11 +10860,7 @@ var ToolAnnotationsSchema = z.object({
10804
10860
  */
10805
10861
  openWorldHint: z.optional(z.boolean())
10806
10862
  }).passthrough();
10807
- var ToolSchema = z.object({
10808
- /**
10809
- * The name of the tool.
10810
- */
10811
- name: z.string(),
10863
+ var ToolSchema = BaseMetadataSchema.extend({
10812
10864
  /**
10813
10865
  * A human-readable description of the tool.
10814
10866
  */
@@ -10833,8 +10885,13 @@ var ToolSchema = z.object({
10833
10885
  /**
10834
10886
  * Optional additional tool information.
10835
10887
  */
10836
- annotations: z.optional(ToolAnnotationsSchema)
10837
- }).passthrough();
10888
+ annotations: z.optional(ToolAnnotationsSchema),
10889
+ /**
10890
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
10891
+ * for notes on _meta usage.
10892
+ */
10893
+ _meta: z.optional(z.object({}).passthrough())
10894
+ });
10838
10895
  var ListToolsRequestSchema = PaginatedRequestSchema.extend({
10839
10896
  method: z.literal("tools/list")
10840
10897
  });
@@ -10848,12 +10905,7 @@ var CallToolResultSchema = ResultSchema.extend({
10848
10905
  * If the Tool does not define an outputSchema, this field MUST be present in the result.
10849
10906
  * For backwards compatibility, this field is always present, but it may be empty.
10850
10907
  */
10851
- content: z.array(z.union([
10852
- TextContentSchema,
10853
- ImageContentSchema,
10854
- AudioContentSchema,
10855
- EmbeddedResourceSchema
10856
- ])).default([]),
10908
+ content: z.array(ContentBlockSchema).default([]),
10857
10909
  /**
10858
10910
  * An object containing structured tool output.
10859
10911
  *
@@ -10997,7 +11049,68 @@ var CreateMessageResultSchema = ResultSchema.extend({
10997
11049
  AudioContentSchema
10998
11050
  ])
10999
11051
  });
11000
- var ResourceReferenceSchema = z.object({
11052
+ var BooleanSchemaSchema = z.object({
11053
+ type: z.literal("boolean"),
11054
+ title: z.optional(z.string()),
11055
+ description: z.optional(z.string()),
11056
+ default: z.optional(z.boolean())
11057
+ }).passthrough();
11058
+ var StringSchemaSchema = z.object({
11059
+ type: z.literal("string"),
11060
+ title: z.optional(z.string()),
11061
+ description: z.optional(z.string()),
11062
+ minLength: z.optional(z.number()),
11063
+ maxLength: z.optional(z.number()),
11064
+ format: z.optional(z.enum(["email", "uri", "date", "date-time"]))
11065
+ }).passthrough();
11066
+ var NumberSchemaSchema = z.object({
11067
+ type: z.enum(["number", "integer"]),
11068
+ title: z.optional(z.string()),
11069
+ description: z.optional(z.string()),
11070
+ minimum: z.optional(z.number()),
11071
+ maximum: z.optional(z.number())
11072
+ }).passthrough();
11073
+ var EnumSchemaSchema = z.object({
11074
+ type: z.literal("string"),
11075
+ title: z.optional(z.string()),
11076
+ description: z.optional(z.string()),
11077
+ enum: z.array(z.string()),
11078
+ enumNames: z.optional(z.array(z.string()))
11079
+ }).passthrough();
11080
+ var PrimitiveSchemaDefinitionSchema = z.union([
11081
+ BooleanSchemaSchema,
11082
+ StringSchemaSchema,
11083
+ NumberSchemaSchema,
11084
+ EnumSchemaSchema
11085
+ ]);
11086
+ var ElicitRequestSchema = RequestSchema.extend({
11087
+ method: z.literal("elicitation/create"),
11088
+ params: BaseRequestParamsSchema.extend({
11089
+ /**
11090
+ * The message to present to the user.
11091
+ */
11092
+ message: z.string(),
11093
+ /**
11094
+ * The schema for the requested user input.
11095
+ */
11096
+ requestedSchema: z.object({
11097
+ type: z.literal("object"),
11098
+ properties: z.record(z.string(), PrimitiveSchemaDefinitionSchema),
11099
+ required: z.optional(z.array(z.string()))
11100
+ }).passthrough()
11101
+ })
11102
+ });
11103
+ var ElicitResultSchema = ResultSchema.extend({
11104
+ /**
11105
+ * The user's response action.
11106
+ */
11107
+ action: z.enum(["accept", "decline", "cancel"]),
11108
+ /**
11109
+ * The collected user input content (only present if action is "accept").
11110
+ */
11111
+ content: z.optional(z.record(z.string(), z.unknown()))
11112
+ });
11113
+ var ResourceTemplateReferenceSchema = z.object({
11001
11114
  type: z.literal("ref/resource"),
11002
11115
  /**
11003
11116
  * The URI or URI template of the resource.
@@ -11014,7 +11127,7 @@ var PromptReferenceSchema = z.object({
11014
11127
  var CompleteRequestSchema = RequestSchema.extend({
11015
11128
  method: z.literal("completion/complete"),
11016
11129
  params: BaseRequestParamsSchema.extend({
11017
- ref: z.union([PromptReferenceSchema, ResourceReferenceSchema]),
11130
+ ref: z.union([PromptReferenceSchema, ResourceTemplateReferenceSchema]),
11018
11131
  /**
11019
11132
  * The argument's information
11020
11133
  */
@@ -11027,7 +11140,13 @@ var CompleteRequestSchema = RequestSchema.extend({
11027
11140
  * The value of the argument to use for completion matching.
11028
11141
  */
11029
11142
  value: z.string()
11030
- }).passthrough()
11143
+ }).passthrough(),
11144
+ context: z.optional(z.object({
11145
+ /**
11146
+ * Previously-resolved variables in a URI template or prompt.
11147
+ */
11148
+ arguments: z.optional(z.record(z.string(), z.string()))
11149
+ }))
11031
11150
  })
11032
11151
  });
11033
11152
  var CompleteResultSchema = ResultSchema.extend({
@@ -11054,7 +11173,12 @@ var RootSchema = z.object({
11054
11173
  /**
11055
11174
  * An optional name for the root.
11056
11175
  */
11057
- name: z.optional(z.string())
11176
+ name: z.optional(z.string()),
11177
+ /**
11178
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
11179
+ * for notes on _meta usage.
11180
+ */
11181
+ _meta: z.optional(z.object({}).passthrough())
11058
11182
  }).passthrough();
11059
11183
  var ListRootsRequestSchema = RequestSchema.extend({
11060
11184
  method: z.literal("roots/list")
@@ -11089,11 +11213,13 @@ var ClientNotificationSchema = z.union([
11089
11213
  var ClientResultSchema = z.union([
11090
11214
  EmptyResultSchema,
11091
11215
  CreateMessageResultSchema,
11216
+ ElicitResultSchema,
11092
11217
  ListRootsResultSchema
11093
11218
  ]);
11094
11219
  var ServerRequestSchema = z.union([
11095
11220
  PingRequestSchema,
11096
11221
  CreateMessageRequestSchema,
11222
+ ElicitRequestSchema,
11097
11223
  ListRootsRequestSchema
11098
11224
  ]);
11099
11225
  var ServerNotificationSchema = z.union([
@@ -11126,7 +11252,7 @@ var McpError = class extends Error {
11126
11252
  }
11127
11253
  };
11128
11254
 
11129
- // node_modules/.pnpm/@modelcontextprotocol+sdk@https+++pkg.pr.new+geelen+typescript-sdk+@modelcontextprotocol+sdk@cdf3508/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/protocol.js
11255
+ // node_modules/.pnpm/@modelcontextprotocol+sdk@1.17.4/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/protocol.js
11130
11256
  var DEFAULT_REQUEST_TIMEOUT_MSEC = 6e4;
11131
11257
  var Protocol = class {
11132
11258
  constructor(_options) {
@@ -11138,6 +11264,7 @@ var Protocol = class {
11138
11264
  this._responseHandlers = /* @__PURE__ */ new Map();
11139
11265
  this._progressHandlers = /* @__PURE__ */ new Map();
11140
11266
  this._timeoutInfo = /* @__PURE__ */ new Map();
11267
+ this._pendingDebouncedNotifications = /* @__PURE__ */ new Set();
11141
11268
  this.setNotificationHandler(CancelledNotificationSchema, (notification) => {
11142
11269
  const controller = this._requestHandlerAbortControllers.get(notification.params.requestId);
11143
11270
  controller === null || controller === void 0 ? void 0 : controller.abort(notification.params.reason);
@@ -11187,14 +11314,21 @@ var Protocol = class {
11187
11314
  * The Protocol object assumes ownership of the Transport, replacing any callbacks that have already been set, and expects that it is the only user of the Transport instance going forward.
11188
11315
  */
11189
11316
  async connect(transport) {
11317
+ var _a, _b, _c;
11190
11318
  this._transport = transport;
11319
+ const _onclose = (_a = this.transport) === null || _a === void 0 ? void 0 : _a.onclose;
11191
11320
  this._transport.onclose = () => {
11321
+ _onclose === null || _onclose === void 0 ? void 0 : _onclose();
11192
11322
  this._onclose();
11193
11323
  };
11324
+ const _onerror = (_b = this.transport) === null || _b === void 0 ? void 0 : _b.onerror;
11194
11325
  this._transport.onerror = (error) => {
11326
+ _onerror === null || _onerror === void 0 ? void 0 : _onerror(error);
11195
11327
  this._onerror(error);
11196
11328
  };
11329
+ const _onmessage = (_c = this._transport) === null || _c === void 0 ? void 0 : _c.onmessage;
11197
11330
  this._transport.onmessage = (message, extra) => {
11331
+ _onmessage === null || _onmessage === void 0 ? void 0 : _onmessage(message, extra);
11198
11332
  if (isJSONRPCResponse(message) || isJSONRPCError(message)) {
11199
11333
  this._onresponse(message);
11200
11334
  } else if (isJSONRPCRequest(message)) {
@@ -11212,6 +11346,7 @@ var Protocol = class {
11212
11346
  const responseHandlers = this._responseHandlers;
11213
11347
  this._responseHandlers = /* @__PURE__ */ new Map();
11214
11348
  this._progressHandlers.clear();
11349
+ this._pendingDebouncedNotifications.clear();
11215
11350
  this._transport = void 0;
11216
11351
  (_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this);
11217
11352
  const error = new McpError(ErrorCode.ConnectionClosed, "Connection closed");
@@ -11232,10 +11367,11 @@ var Protocol = class {
11232
11367
  Promise.resolve().then(() => handler(notification)).catch((error) => this._onerror(new Error(`Uncaught error in notification handler: ${error}`)));
11233
11368
  }
11234
11369
  _onrequest(request, extra) {
11235
- var _a, _b, _c, _d;
11370
+ var _a, _b;
11236
11371
  const handler = (_a = this._requestHandlers.get(request.method)) !== null && _a !== void 0 ? _a : this.fallbackRequestHandler;
11372
+ const capturedTransport = this._transport;
11237
11373
  if (handler === void 0) {
11238
- (_b = this._transport) === null || _b === void 0 ? void 0 : _b.send({
11374
+ capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.send({
11239
11375
  jsonrpc: "2.0",
11240
11376
  id: request.id,
11241
11377
  error: {
@@ -11249,34 +11385,34 @@ var Protocol = class {
11249
11385
  this._requestHandlerAbortControllers.set(request.id, abortController);
11250
11386
  const fullExtra = {
11251
11387
  signal: abortController.signal,
11252
- sessionId: (_c = this._transport) === null || _c === void 0 ? void 0 : _c.sessionId,
11253
- _meta: (_d = request.params) === null || _d === void 0 ? void 0 : _d._meta,
11388
+ sessionId: capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.sessionId,
11389
+ _meta: (_b = request.params) === null || _b === void 0 ? void 0 : _b._meta,
11254
11390
  sendNotification: (notification) => this.notification(notification, { relatedRequestId: request.id }),
11255
11391
  sendRequest: (r, resultSchema, options) => this.request(r, resultSchema, { ...options, relatedRequestId: request.id }),
11256
11392
  authInfo: extra === null || extra === void 0 ? void 0 : extra.authInfo,
11257
- requestId: request.id
11393
+ requestId: request.id,
11394
+ requestInfo: extra === null || extra === void 0 ? void 0 : extra.requestInfo
11258
11395
  };
11259
11396
  Promise.resolve().then(() => handler(request, fullExtra)).then((result) => {
11260
- var _a2;
11261
11397
  if (abortController.signal.aborted) {
11262
11398
  return;
11263
11399
  }
11264
- return (_a2 = this._transport) === null || _a2 === void 0 ? void 0 : _a2.send({
11400
+ return capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.send({
11265
11401
  result,
11266
11402
  jsonrpc: "2.0",
11267
11403
  id: request.id
11268
11404
  });
11269
11405
  }, (error) => {
11270
- var _a2, _b2;
11406
+ var _a2;
11271
11407
  if (abortController.signal.aborted) {
11272
11408
  return;
11273
11409
  }
11274
- return (_a2 = this._transport) === null || _a2 === void 0 ? void 0 : _a2.send({
11410
+ return capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.send({
11275
11411
  jsonrpc: "2.0",
11276
11412
  id: request.id,
11277
11413
  error: {
11278
11414
  code: Number.isSafeInteger(error["code"]) ? error["code"] : ErrorCode.InternalError,
11279
- message: (_b2 = error.message) !== null && _b2 !== void 0 ? _b2 : "Internal error"
11415
+ message: (_a2 = error.message) !== null && _a2 !== void 0 ? _a2 : "Internal error"
11280
11416
  }
11281
11417
  });
11282
11418
  }).catch((error) => this._onerror(new Error(`Failed to send response: ${error}`))).finally(() => {
@@ -11410,10 +11546,32 @@ var Protocol = class {
11410
11546
  * Emits a notification, which is a one-way message that does not expect a response.
11411
11547
  */
11412
11548
  async notification(notification, options) {
11549
+ var _a, _b;
11413
11550
  if (!this._transport) {
11414
11551
  throw new Error("Not connected");
11415
11552
  }
11416
11553
  this.assertNotificationCapability(notification.method);
11554
+ const debouncedMethods = (_b = (_a = this._options) === null || _a === void 0 ? void 0 : _a.debouncedNotificationMethods) !== null && _b !== void 0 ? _b : [];
11555
+ const canDebounce = debouncedMethods.includes(notification.method) && !notification.params && !(options === null || options === void 0 ? void 0 : options.relatedRequestId);
11556
+ if (canDebounce) {
11557
+ if (this._pendingDebouncedNotifications.has(notification.method)) {
11558
+ return;
11559
+ }
11560
+ this._pendingDebouncedNotifications.add(notification.method);
11561
+ Promise.resolve().then(() => {
11562
+ var _a2;
11563
+ this._pendingDebouncedNotifications.delete(notification.method);
11564
+ if (!this._transport) {
11565
+ return;
11566
+ }
11567
+ const jsonrpcNotification2 = {
11568
+ ...notification,
11569
+ jsonrpc: "2.0"
11570
+ };
11571
+ (_a2 = this._transport) === null || _a2 === void 0 ? void 0 : _a2.send(jsonrpcNotification2, options).catch((error) => this._onerror(error));
11572
+ });
11573
+ return;
11574
+ }
11417
11575
  const jsonrpcNotification = {
11418
11576
  ...notification,
11419
11577
  jsonrpc: "2.0"
@@ -11472,7 +11630,7 @@ function mergeCapabilities(base, additional) {
11472
11630
  }, { ...base });
11473
11631
  }
11474
11632
 
11475
- // node_modules/.pnpm/@modelcontextprotocol+sdk@https+++pkg.pr.new+geelen+typescript-sdk+@modelcontextprotocol+sdk@cdf3508/node_modules/@modelcontextprotocol/sdk/dist/esm/client/index.js
11633
+ // node_modules/.pnpm/@modelcontextprotocol+sdk@1.17.4/node_modules/@modelcontextprotocol/sdk/dist/esm/client/index.js
11476
11634
  var import_ajv = __toESM(require_ajv(), 1);
11477
11635
  var Client = class extends Protocol {
11478
11636
  /**
@@ -11525,6 +11683,9 @@ var Client = class extends Protocol {
11525
11683
  }
11526
11684
  this._serverCapabilities = result.capabilities;
11527
11685
  this._serverVersion = result.serverInfo;
11686
+ if (transport.setProtocolVersion) {
11687
+ transport.setProtocolVersion(result.protocolVersion);
11688
+ }
11528
11689
  this._instructions = result.instructions;
11529
11690
  await this.notification({
11530
11691
  method: "notifications/initialized"
@@ -11618,6 +11779,11 @@ var Client = class extends Protocol {
11618
11779
  throw new Error(`Client does not support sampling capability (required for ${method})`);
11619
11780
  }
11620
11781
  break;
11782
+ case "elicitation/create":
11783
+ if (!this._capabilities.elicitation) {
11784
+ throw new Error(`Client does not support elicitation capability (required for ${method})`);
11785
+ }
11786
+ break;
11621
11787
  case "roots/list":
11622
11788
  if (!this._capabilities.roots) {
11623
11789
  throw new Error(`Client does not support roots capability (required for ${method})`);
@@ -11687,8 +11853,7 @@ var Client = class extends Protocol {
11687
11853
  try {
11688
11854
  const validator = this._ajv.compile(tool.outputSchema);
11689
11855
  this._cachedToolOutputValidators.set(tool.name, validator);
11690
- } catch (error) {
11691
- console.warn(`Failed to compile output schema for tool ${tool.name}: ${error}`);
11856
+ } catch (_a) {
11692
11857
  }
11693
11858
  }
11694
11859
  }
@@ -11707,7 +11872,7 @@ var Client = class extends Protocol {
11707
11872
  };
11708
11873
 
11709
11874
  // package.json
11710
- var version = "0.1.17";
11875
+ var version = "0.1.19";
11711
11876
 
11712
11877
  // node_modules/.pnpm/pkce-challenge@5.0.0/node_modules/pkce-challenge/dist/index.node.js
11713
11878
  var crypto;
@@ -11748,10 +11913,23 @@ async function pkceChallenge(length) {
11748
11913
  };
11749
11914
  }
11750
11915
 
11751
- // node_modules/.pnpm/@modelcontextprotocol+sdk@https+++pkg.pr.new+geelen+typescript-sdk+@modelcontextprotocol+sdk@cdf3508/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/auth.js
11916
+ // node_modules/.pnpm/@modelcontextprotocol+sdk@1.17.4/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/auth.js
11917
+ var SafeUrlSchema = z.string().url().superRefine((val, ctx) => {
11918
+ if (!URL.canParse(val)) {
11919
+ ctx.addIssue({
11920
+ code: z.ZodIssueCode.custom,
11921
+ message: "URL must be parseable",
11922
+ fatal: true
11923
+ });
11924
+ return z.NEVER;
11925
+ }
11926
+ }).refine((url) => {
11927
+ const u = new URL(url);
11928
+ return u.protocol !== "javascript:" && u.protocol !== "data:" && u.protocol !== "vbscript:";
11929
+ }, { message: "URL cannot use javascript:, data:, or vbscript: scheme" });
11752
11930
  var OAuthProtectedResourceMetadataSchema = z.object({
11753
11931
  resource: z.string().url(),
11754
- authorization_servers: z.array(z.string().url()).optional(),
11932
+ authorization_servers: z.array(SafeUrlSchema).optional(),
11755
11933
  jwks_uri: z.string().url().optional(),
11756
11934
  scopes_supported: z.array(z.string()).optional(),
11757
11935
  bearer_methods_supported: z.array(z.string()).optional(),
@@ -11767,17 +11945,17 @@ var OAuthProtectedResourceMetadataSchema = z.object({
11767
11945
  }).passthrough();
11768
11946
  var OAuthMetadataSchema = z.object({
11769
11947
  issuer: z.string(),
11770
- authorization_endpoint: z.string(),
11771
- token_endpoint: z.string(),
11772
- registration_endpoint: z.string().optional(),
11948
+ authorization_endpoint: SafeUrlSchema,
11949
+ token_endpoint: SafeUrlSchema,
11950
+ registration_endpoint: SafeUrlSchema.optional(),
11773
11951
  scopes_supported: z.array(z.string()).optional(),
11774
11952
  response_types_supported: z.array(z.string()),
11775
11953
  response_modes_supported: z.array(z.string()).optional(),
11776
11954
  grant_types_supported: z.array(z.string()).optional(),
11777
11955
  token_endpoint_auth_methods_supported: z.array(z.string()).optional(),
11778
11956
  token_endpoint_auth_signing_alg_values_supported: z.array(z.string()).optional(),
11779
- service_documentation: z.string().optional(),
11780
- revocation_endpoint: z.string().optional(),
11957
+ service_documentation: SafeUrlSchema.optional(),
11958
+ revocation_endpoint: SafeUrlSchema.optional(),
11781
11959
  revocation_endpoint_auth_methods_supported: z.array(z.string()).optional(),
11782
11960
  revocation_endpoint_auth_signing_alg_values_supported: z.array(z.string()).optional(),
11783
11961
  introspection_endpoint: z.string().optional(),
@@ -11785,8 +11963,50 @@ var OAuthMetadataSchema = z.object({
11785
11963
  introspection_endpoint_auth_signing_alg_values_supported: z.array(z.string()).optional(),
11786
11964
  code_challenge_methods_supported: z.array(z.string()).optional()
11787
11965
  }).passthrough();
11966
+ var OpenIdProviderMetadataSchema = z.object({
11967
+ issuer: z.string(),
11968
+ authorization_endpoint: SafeUrlSchema,
11969
+ token_endpoint: SafeUrlSchema,
11970
+ userinfo_endpoint: SafeUrlSchema.optional(),
11971
+ jwks_uri: SafeUrlSchema,
11972
+ registration_endpoint: SafeUrlSchema.optional(),
11973
+ scopes_supported: z.array(z.string()).optional(),
11974
+ response_types_supported: z.array(z.string()),
11975
+ response_modes_supported: z.array(z.string()).optional(),
11976
+ grant_types_supported: z.array(z.string()).optional(),
11977
+ acr_values_supported: z.array(z.string()).optional(),
11978
+ subject_types_supported: z.array(z.string()),
11979
+ id_token_signing_alg_values_supported: z.array(z.string()),
11980
+ id_token_encryption_alg_values_supported: z.array(z.string()).optional(),
11981
+ id_token_encryption_enc_values_supported: z.array(z.string()).optional(),
11982
+ userinfo_signing_alg_values_supported: z.array(z.string()).optional(),
11983
+ userinfo_encryption_alg_values_supported: z.array(z.string()).optional(),
11984
+ userinfo_encryption_enc_values_supported: z.array(z.string()).optional(),
11985
+ request_object_signing_alg_values_supported: z.array(z.string()).optional(),
11986
+ request_object_encryption_alg_values_supported: z.array(z.string()).optional(),
11987
+ request_object_encryption_enc_values_supported: z.array(z.string()).optional(),
11988
+ token_endpoint_auth_methods_supported: z.array(z.string()).optional(),
11989
+ token_endpoint_auth_signing_alg_values_supported: z.array(z.string()).optional(),
11990
+ display_values_supported: z.array(z.string()).optional(),
11991
+ claim_types_supported: z.array(z.string()).optional(),
11992
+ claims_supported: z.array(z.string()).optional(),
11993
+ service_documentation: z.string().optional(),
11994
+ claims_locales_supported: z.array(z.string()).optional(),
11995
+ ui_locales_supported: z.array(z.string()).optional(),
11996
+ claims_parameter_supported: z.boolean().optional(),
11997
+ request_parameter_supported: z.boolean().optional(),
11998
+ request_uri_parameter_supported: z.boolean().optional(),
11999
+ require_request_uri_registration: z.boolean().optional(),
12000
+ op_policy_uri: SafeUrlSchema.optional(),
12001
+ op_tos_uri: SafeUrlSchema.optional()
12002
+ }).passthrough();
12003
+ var OpenIdProviderDiscoveryMetadataSchema = OpenIdProviderMetadataSchema.merge(OAuthMetadataSchema.pick({
12004
+ code_challenge_methods_supported: true
12005
+ }));
11788
12006
  var OAuthTokensSchema = z.object({
11789
12007
  access_token: z.string(),
12008
+ id_token: z.string().optional(),
12009
+ // Optional for OAuth 2.1, but necessary in OpenID Connect
11790
12010
  token_type: z.string(),
11791
12011
  expires_in: z.number().optional(),
11792
12012
  scope: z.string().optional(),
@@ -11798,21 +12018,22 @@ var OAuthErrorResponseSchema = z.object({
11798
12018
  error_uri: z.string().optional()
11799
12019
  });
11800
12020
  var OAuthClientMetadataSchema = z.object({
11801
- redirect_uris: z.array(z.string()).refine((uris) => uris.every((uri) => URL.canParse(uri)), { message: "redirect_uris must contain valid URLs" }),
12021
+ redirect_uris: z.array(SafeUrlSchema),
11802
12022
  token_endpoint_auth_method: z.string().optional(),
11803
12023
  grant_types: z.array(z.string()).optional(),
11804
12024
  response_types: z.array(z.string()).optional(),
11805
12025
  client_name: z.string().optional(),
11806
- client_uri: z.string().optional(),
11807
- logo_uri: z.string().optional(),
12026
+ client_uri: SafeUrlSchema.optional(),
12027
+ logo_uri: SafeUrlSchema.optional(),
11808
12028
  scope: z.string().optional(),
11809
12029
  contacts: z.array(z.string()).optional(),
11810
- tos_uri: z.string().optional(),
12030
+ tos_uri: SafeUrlSchema.optional(),
11811
12031
  policy_uri: z.string().optional(),
11812
- jwks_uri: z.string().optional(),
12032
+ jwks_uri: SafeUrlSchema.optional(),
11813
12033
  jwks: z.any().optional(),
11814
12034
  software_id: z.string().optional(),
11815
- software_version: z.string().optional()
12035
+ software_version: z.string().optional(),
12036
+ software_statement: z.string().optional()
11816
12037
  }).strip();
11817
12038
  var OAuthClientInformationSchema = z.object({
11818
12039
  client_id: z.string(),
@@ -11830,12 +12051,31 @@ var OAuthTokenRevocationRequestSchema = z.object({
11830
12051
  token_type_hint: z.string().optional()
11831
12052
  }).strip();
11832
12053
 
11833
- // node_modules/.pnpm/@modelcontextprotocol+sdk@https+++pkg.pr.new+geelen+typescript-sdk+@modelcontextprotocol+sdk@cdf3508/node_modules/@modelcontextprotocol/sdk/dist/esm/server/auth/errors.js
12054
+ // node_modules/.pnpm/@modelcontextprotocol+sdk@1.17.4/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/auth-utils.js
12055
+ function resourceUrlFromServerUrl(url) {
12056
+ const resourceURL = typeof url === "string" ? new URL(url) : new URL(url.href);
12057
+ resourceURL.hash = "";
12058
+ return resourceURL;
12059
+ }
12060
+ function checkResourceAllowed({ requestedResource, configuredResource }) {
12061
+ const requested = typeof requestedResource === "string" ? new URL(requestedResource) : new URL(requestedResource.href);
12062
+ const configured = typeof configuredResource === "string" ? new URL(configuredResource) : new URL(configuredResource.href);
12063
+ if (requested.origin !== configured.origin) {
12064
+ return false;
12065
+ }
12066
+ if (requested.pathname.length < configured.pathname.length) {
12067
+ return false;
12068
+ }
12069
+ const requestedPath = requested.pathname.endsWith("/") ? requested.pathname : requested.pathname + "/";
12070
+ const configuredPath = configured.pathname.endsWith("/") ? configured.pathname : configured.pathname + "/";
12071
+ return requestedPath.startsWith(configuredPath);
12072
+ }
12073
+
12074
+ // node_modules/.pnpm/@modelcontextprotocol+sdk@1.17.4/node_modules/@modelcontextprotocol/sdk/dist/esm/server/auth/errors.js
11834
12075
  var OAuthError = class extends Error {
11835
12076
  constructor(message, errorUri) {
11836
12077
  super(message);
11837
12078
  this.errorUri = errorUri;
11838
- this.errorCode = this.constructor.errorCode;
11839
12079
  this.name = this.constructor.name;
11840
12080
  }
11841
12081
  /**
@@ -11851,6 +12091,9 @@ var OAuthError = class extends Error {
11851
12091
  }
11852
12092
  return response;
11853
12093
  }
12094
+ get errorCode() {
12095
+ return this.constructor.errorCode;
12096
+ }
11854
12097
  };
11855
12098
  var InvalidRequestError = class extends OAuthError {
11856
12099
  };
@@ -11919,12 +12162,60 @@ var OAUTH_ERRORS = {
11919
12162
  [InsufficientScopeError.errorCode]: InsufficientScopeError
11920
12163
  };
11921
12164
 
11922
- // node_modules/.pnpm/@modelcontextprotocol+sdk@https+++pkg.pr.new+geelen+typescript-sdk+@modelcontextprotocol+sdk@cdf3508/node_modules/@modelcontextprotocol/sdk/dist/esm/client/auth.js
12165
+ // node_modules/.pnpm/@modelcontextprotocol+sdk@1.17.4/node_modules/@modelcontextprotocol/sdk/dist/esm/client/auth.js
11923
12166
  var UnauthorizedError = class extends Error {
11924
12167
  constructor(message) {
11925
12168
  super(message !== null && message !== void 0 ? message : "Unauthorized");
11926
12169
  }
11927
12170
  };
12171
+ function selectClientAuthMethod(clientInformation, supportedMethods) {
12172
+ const hasClientSecret = clientInformation.client_secret !== void 0;
12173
+ if (supportedMethods.length === 0) {
12174
+ return hasClientSecret ? "client_secret_post" : "none";
12175
+ }
12176
+ if (hasClientSecret && supportedMethods.includes("client_secret_basic")) {
12177
+ return "client_secret_basic";
12178
+ }
12179
+ if (hasClientSecret && supportedMethods.includes("client_secret_post")) {
12180
+ return "client_secret_post";
12181
+ }
12182
+ if (supportedMethods.includes("none")) {
12183
+ return "none";
12184
+ }
12185
+ return hasClientSecret ? "client_secret_post" : "none";
12186
+ }
12187
+ function applyClientAuthentication(method, clientInformation, headers, params) {
12188
+ const { client_id, client_secret } = clientInformation;
12189
+ switch (method) {
12190
+ case "client_secret_basic":
12191
+ applyBasicAuth(client_id, client_secret, headers);
12192
+ return;
12193
+ case "client_secret_post":
12194
+ applyPostAuth(client_id, client_secret, params);
12195
+ return;
12196
+ case "none":
12197
+ applyPublicAuth(client_id, params);
12198
+ return;
12199
+ default:
12200
+ throw new Error(`Unsupported client authentication method: ${method}`);
12201
+ }
12202
+ }
12203
+ function applyBasicAuth(clientId, clientSecret, headers) {
12204
+ if (!clientSecret) {
12205
+ throw new Error("client_secret_basic authentication requires a client_secret");
12206
+ }
12207
+ const credentials = btoa(`${clientId}:${clientSecret}`);
12208
+ headers.set("Authorization", `Basic ${credentials}`);
12209
+ }
12210
+ function applyPostAuth(clientId, clientSecret, params) {
12211
+ params.set("client_id", clientId);
12212
+ if (clientSecret) {
12213
+ params.set("client_secret", clientSecret);
12214
+ }
12215
+ }
12216
+ function applyPublicAuth(clientId, params) {
12217
+ params.set("client_id", clientId);
12218
+ }
11928
12219
  async function parseErrorResponse(input) {
11929
12220
  const statusCode = input instanceof Response ? input.status : void 0;
11930
12221
  const body = input instanceof Response ? await input.text() : input;
@@ -11953,17 +12244,23 @@ async function auth(provider, options) {
11953
12244
  throw error;
11954
12245
  }
11955
12246
  }
11956
- async function authInternal(provider, { serverUrl, authorizationCode, scope, resourceMetadataUrl }) {
11957
- let authorizationServerUrl = serverUrl;
12247
+ async function authInternal(provider, { serverUrl, authorizationCode, scope, resourceMetadataUrl, fetchFn }) {
12248
+ let resourceMetadata;
12249
+ let authorizationServerUrl;
11958
12250
  try {
11959
- const resourceMetadata = await discoverOAuthProtectedResourceMetadata(resourceMetadataUrl || serverUrl);
12251
+ resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl }, fetchFn);
11960
12252
  if (resourceMetadata.authorization_servers && resourceMetadata.authorization_servers.length > 0) {
11961
12253
  authorizationServerUrl = resourceMetadata.authorization_servers[0];
11962
12254
  }
11963
- } catch (error) {
11964
- console.warn("Could not load OAuth Protected Resource metadata, falling back to /.well-known/oauth-authorization-server", error);
12255
+ } catch (_a) {
12256
+ }
12257
+ if (!authorizationServerUrl) {
12258
+ authorizationServerUrl = serverUrl;
11965
12259
  }
11966
- const metadata = await discoverOAuthMetadata(authorizationServerUrl);
12260
+ const resource = await selectResourceURL(serverUrl, provider, resourceMetadata);
12261
+ const metadata = await discoverAuthorizationServerMetadata(authorizationServerUrl, {
12262
+ fetchFn
12263
+ });
11967
12264
  let clientInformation = await Promise.resolve(provider.clientInformation());
11968
12265
  if (!clientInformation) {
11969
12266
  if (authorizationCode !== void 0) {
@@ -11974,7 +12271,8 @@ async function authInternal(provider, { serverUrl, authorizationCode, scope, res
11974
12271
  }
11975
12272
  const fullInformation = await registerClient(authorizationServerUrl, {
11976
12273
  metadata,
11977
- clientMetadata: provider.clientMetadata
12274
+ clientMetadata: provider.clientMetadata,
12275
+ fetchFn
11978
12276
  });
11979
12277
  await provider.saveClientInformation(fullInformation);
11980
12278
  clientInformation = fullInformation;
@@ -11986,7 +12284,10 @@ async function authInternal(provider, { serverUrl, authorizationCode, scope, res
11986
12284
  clientInformation,
11987
12285
  authorizationCode,
11988
12286
  codeVerifier: codeVerifier2,
11989
- redirectUri: provider.redirectUrl
12287
+ redirectUri: provider.redirectUrl,
12288
+ resource,
12289
+ addClientAuthentication: provider.addClientAuthentication,
12290
+ fetchFn
11990
12291
  });
11991
12292
  await provider.saveTokens(tokens2);
11992
12293
  return "AUTHORIZED";
@@ -11997,15 +12298,16 @@ async function authInternal(provider, { serverUrl, authorizationCode, scope, res
11997
12298
  const newTokens = await refreshAuthorization(authorizationServerUrl, {
11998
12299
  metadata,
11999
12300
  clientInformation,
12000
- refreshToken: tokens.refresh_token
12301
+ refreshToken: tokens.refresh_token,
12302
+ resource,
12303
+ addClientAuthentication: provider.addClientAuthentication,
12304
+ fetchFn
12001
12305
  });
12002
12306
  await provider.saveTokens(newTokens);
12003
12307
  return "AUTHORIZED";
12004
12308
  } catch (error) {
12005
12309
  if (!(error instanceof OAuthError) || error instanceof ServerError) {
12006
- console.error("Could not refresh OAuth tokens:", error);
12007
12310
  } else {
12008
- console.warn(`OAuth token refresh failed: ${JSON.stringify(error.toResponseObject())}`);
12009
12311
  throw error;
12010
12312
  }
12011
12313
  }
@@ -12016,12 +12318,26 @@ async function authInternal(provider, { serverUrl, authorizationCode, scope, res
12016
12318
  clientInformation,
12017
12319
  state,
12018
12320
  redirectUrl: provider.redirectUrl,
12019
- scope: scope || provider.clientMetadata.scope
12321
+ scope: scope || provider.clientMetadata.scope,
12322
+ resource
12020
12323
  });
12021
12324
  await provider.saveCodeVerifier(codeVerifier);
12022
12325
  await provider.redirectToAuthorization(authorizationUrl);
12023
12326
  return "REDIRECT";
12024
12327
  }
12328
+ async function selectResourceURL(serverUrl, provider, resourceMetadata) {
12329
+ const defaultResource = resourceUrlFromServerUrl(serverUrl);
12330
+ if (provider.validateResourceURL) {
12331
+ return await provider.validateResourceURL(defaultResource, resourceMetadata === null || resourceMetadata === void 0 ? void 0 : resourceMetadata.resource);
12332
+ }
12333
+ if (!resourceMetadata) {
12334
+ return void 0;
12335
+ }
12336
+ if (!checkResourceAllowed({ requestedResource: defaultResource, configuredResource: resourceMetadata.resource })) {
12337
+ throw new Error(`Protected resource ${resourceMetadata.resource} does not match expected ${defaultResource} (or origin)`);
12338
+ }
12339
+ return new URL(resourceMetadata.resource);
12340
+ }
12025
12341
  function extractResourceMetadataUrl(res) {
12026
12342
  const authenticateHeader = res.headers.get("WWW-Authenticate");
12027
12343
  if (!authenticateHeader) {
@@ -12029,7 +12345,6 @@ function extractResourceMetadataUrl(res) {
12029
12345
  }
12030
12346
  const [type, scheme] = authenticateHeader.split(" ");
12031
12347
  if (type.toLowerCase() !== "bearer" || !scheme) {
12032
- console.log("Invalid WWW-Authenticate header format, expected 'Bearer'");
12033
12348
  return void 0;
12034
12349
  }
12035
12350
  const regex = /resource_metadata="([^"]*)"/;
@@ -12040,33 +12355,15 @@ function extractResourceMetadataUrl(res) {
12040
12355
  try {
12041
12356
  return new URL(match[1]);
12042
12357
  } catch (_a) {
12043
- console.log("Invalid resource metadata url: ", match[1]);
12044
12358
  return void 0;
12045
12359
  }
12046
12360
  }
12047
- async function discoverOAuthProtectedResourceMetadata(serverUrl, opts) {
12048
- var _a;
12049
- let url;
12050
- if (opts === null || opts === void 0 ? void 0 : opts.resourceMetadataUrl) {
12051
- url = new URL(opts === null || opts === void 0 ? void 0 : opts.resourceMetadataUrl);
12052
- } else {
12053
- url = new URL("/.well-known/oauth-protected-resource", serverUrl);
12054
- }
12055
- let response;
12056
- try {
12057
- response = await fetch(url, {
12058
- headers: {
12059
- "MCP-Protocol-Version": (_a = opts === null || opts === void 0 ? void 0 : opts.protocolVersion) !== null && _a !== void 0 ? _a : LATEST_PROTOCOL_VERSION
12060
- }
12061
- });
12062
- } catch (error) {
12063
- if (error instanceof TypeError) {
12064
- response = await fetch(url);
12065
- } else {
12066
- throw error;
12067
- }
12068
- }
12069
- if (response.status === 404) {
12361
+ async function discoverOAuthProtectedResourceMetadata(serverUrl, opts, fetchFn = fetch) {
12362
+ const response = await discoverMetadataWithFallback(serverUrl, "oauth-protected-resource", fetchFn, {
12363
+ protocolVersion: opts === null || opts === void 0 ? void 0 : opts.protocolVersion,
12364
+ metadataUrl: opts === null || opts === void 0 ? void 0 : opts.resourceMetadataUrl
12365
+ });
12366
+ if (!response || response.status === 404) {
12070
12367
  throw new Error(`Resource server does not implement OAuth 2.0 Protected Resource Metadata.`);
12071
12368
  }
12072
12369
  if (!response.ok) {
@@ -12074,32 +12371,119 @@ async function discoverOAuthProtectedResourceMetadata(serverUrl, opts) {
12074
12371
  }
12075
12372
  return OAuthProtectedResourceMetadataSchema.parse(await response.json());
12076
12373
  }
12077
- async function discoverOAuthMetadata(authorizationServerUrl, opts) {
12078
- var _a;
12079
- const url = new URL("/.well-known/oauth-authorization-server", authorizationServerUrl);
12080
- let response;
12374
+ async function fetchWithCorsRetry(url, headers, fetchFn = fetch) {
12081
12375
  try {
12082
- response = await fetch(url, {
12083
- headers: {
12084
- "MCP-Protocol-Version": (_a = opts === null || opts === void 0 ? void 0 : opts.protocolVersion) !== null && _a !== void 0 ? _a : LATEST_PROTOCOL_VERSION
12085
- }
12086
- });
12376
+ return await fetchFn(url, { headers });
12087
12377
  } catch (error) {
12088
12378
  if (error instanceof TypeError) {
12089
- response = await fetch(url);
12090
- } else {
12091
- throw error;
12379
+ if (headers) {
12380
+ return fetchWithCorsRetry(url, void 0, fetchFn);
12381
+ } else {
12382
+ return void 0;
12383
+ }
12092
12384
  }
12385
+ throw error;
12093
12386
  }
12094
- if (response.status === 404) {
12095
- return void 0;
12387
+ }
12388
+ function buildWellKnownPath(wellKnownPrefix, pathname = "", options = {}) {
12389
+ if (pathname.endsWith("/")) {
12390
+ pathname = pathname.slice(0, -1);
12096
12391
  }
12097
- if (!response.ok) {
12098
- throw new Error(`HTTP ${response.status} trying to load well-known OAuth metadata`);
12392
+ return options.prependPathname ? `${pathname}/.well-known/${wellKnownPrefix}` : `/.well-known/${wellKnownPrefix}${pathname}`;
12393
+ }
12394
+ async function tryMetadataDiscovery(url, protocolVersion, fetchFn = fetch) {
12395
+ const headers = {
12396
+ "MCP-Protocol-Version": protocolVersion
12397
+ };
12398
+ return await fetchWithCorsRetry(url, headers, fetchFn);
12399
+ }
12400
+ function shouldAttemptFallback(response, pathname) {
12401
+ return !response || response.status >= 400 && response.status < 500 && pathname !== "/";
12402
+ }
12403
+ async function discoverMetadataWithFallback(serverUrl, wellKnownType, fetchFn, opts) {
12404
+ var _a, _b;
12405
+ const issuer = new URL(serverUrl);
12406
+ const protocolVersion = (_a = opts === null || opts === void 0 ? void 0 : opts.protocolVersion) !== null && _a !== void 0 ? _a : LATEST_PROTOCOL_VERSION;
12407
+ let url;
12408
+ if (opts === null || opts === void 0 ? void 0 : opts.metadataUrl) {
12409
+ url = new URL(opts.metadataUrl);
12410
+ } else {
12411
+ const wellKnownPath = buildWellKnownPath(wellKnownType, issuer.pathname);
12412
+ url = new URL(wellKnownPath, (_b = opts === null || opts === void 0 ? void 0 : opts.metadataServerUrl) !== null && _b !== void 0 ? _b : issuer);
12413
+ url.search = issuer.search;
12414
+ }
12415
+ let response = await tryMetadataDiscovery(url, protocolVersion, fetchFn);
12416
+ if (!(opts === null || opts === void 0 ? void 0 : opts.metadataUrl) && shouldAttemptFallback(response, issuer.pathname)) {
12417
+ const rootUrl = new URL(`/.well-known/${wellKnownType}`, issuer);
12418
+ response = await tryMetadataDiscovery(rootUrl, protocolVersion, fetchFn);
12419
+ }
12420
+ return response;
12421
+ }
12422
+ function buildDiscoveryUrls(authorizationServerUrl) {
12423
+ const url = typeof authorizationServerUrl === "string" ? new URL(authorizationServerUrl) : authorizationServerUrl;
12424
+ const hasPath = url.pathname !== "/";
12425
+ const urlsToTry = [];
12426
+ if (!hasPath) {
12427
+ urlsToTry.push({
12428
+ url: new URL("/.well-known/oauth-authorization-server", url.origin),
12429
+ type: "oauth"
12430
+ });
12431
+ urlsToTry.push({
12432
+ url: new URL(`/.well-known/openid-configuration`, url.origin),
12433
+ type: "oidc"
12434
+ });
12435
+ return urlsToTry;
12436
+ }
12437
+ let pathname = url.pathname;
12438
+ if (pathname.endsWith("/")) {
12439
+ pathname = pathname.slice(0, -1);
12440
+ }
12441
+ urlsToTry.push({
12442
+ url: new URL(`/.well-known/oauth-authorization-server${pathname}`, url.origin),
12443
+ type: "oauth"
12444
+ });
12445
+ urlsToTry.push({
12446
+ url: new URL("/.well-known/oauth-authorization-server", url.origin),
12447
+ type: "oauth"
12448
+ });
12449
+ urlsToTry.push({
12450
+ url: new URL(`/.well-known/openid-configuration${pathname}`, url.origin),
12451
+ type: "oidc"
12452
+ });
12453
+ urlsToTry.push({
12454
+ url: new URL(`${pathname}/.well-known/openid-configuration`, url.origin),
12455
+ type: "oidc"
12456
+ });
12457
+ return urlsToTry;
12458
+ }
12459
+ async function discoverAuthorizationServerMetadata(authorizationServerUrl, { fetchFn = fetch, protocolVersion = LATEST_PROTOCOL_VERSION } = {}) {
12460
+ var _a;
12461
+ const headers = { "MCP-Protocol-Version": protocolVersion };
12462
+ const urlsToTry = buildDiscoveryUrls(authorizationServerUrl);
12463
+ for (const { url: endpointUrl, type } of urlsToTry) {
12464
+ const response = await fetchWithCorsRetry(endpointUrl, headers, fetchFn);
12465
+ if (!response) {
12466
+ continue;
12467
+ }
12468
+ if (!response.ok) {
12469
+ if (response.status >= 400 && response.status < 500) {
12470
+ continue;
12471
+ }
12472
+ throw new Error(`HTTP ${response.status} trying to load ${type === "oauth" ? "OAuth" : "OpenID provider"} metadata from ${endpointUrl}`);
12473
+ }
12474
+ if (type === "oauth") {
12475
+ return OAuthMetadataSchema.parse(await response.json());
12476
+ } else {
12477
+ const metadata = OpenIdProviderDiscoveryMetadataSchema.parse(await response.json());
12478
+ if (!((_a = metadata.code_challenge_methods_supported) === null || _a === void 0 ? void 0 : _a.includes("S256"))) {
12479
+ throw new Error(`Incompatible OIDC provider at ${endpointUrl}: does not support S256 code challenge method required by MCP specification`);
12480
+ }
12481
+ return metadata;
12482
+ }
12099
12483
  }
12100
- return OAuthMetadataSchema.parse(await response.json());
12484
+ return void 0;
12101
12485
  }
12102
- async function startAuthorization(authorizationServerUrl, { metadata, clientInformation, redirectUrl, scope, state }) {
12486
+ async function startAuthorization(authorizationServerUrl, { metadata, clientInformation, redirectUrl, scope, state, resource }) {
12103
12487
  const responseType = "code";
12104
12488
  const codeChallengeMethod = "S256";
12105
12489
  let authorizationUrl;
@@ -12128,34 +12512,44 @@ async function startAuthorization(authorizationServerUrl, { metadata, clientInfo
12128
12512
  if (scope) {
12129
12513
  authorizationUrl.searchParams.set("scope", scope);
12130
12514
  }
12515
+ if (scope === null || scope === void 0 ? void 0 : scope.includes("offline_access")) {
12516
+ authorizationUrl.searchParams.append("prompt", "consent");
12517
+ }
12518
+ if (resource) {
12519
+ authorizationUrl.searchParams.set("resource", resource.href);
12520
+ }
12131
12521
  return { authorizationUrl, codeVerifier };
12132
12522
  }
12133
- async function exchangeAuthorization(authorizationServerUrl, { metadata, clientInformation, authorizationCode, codeVerifier, redirectUri }) {
12523
+ async function exchangeAuthorization(authorizationServerUrl, { metadata, clientInformation, authorizationCode, codeVerifier, redirectUri, resource, addClientAuthentication, fetchFn }) {
12524
+ var _a;
12134
12525
  const grantType = "authorization_code";
12135
- let tokenUrl;
12136
- if (metadata) {
12137
- tokenUrl = new URL(metadata.token_endpoint);
12138
- if (metadata.grant_types_supported && !metadata.grant_types_supported.includes(grantType)) {
12139
- throw new Error(`Incompatible auth server: does not support grant type ${grantType}`);
12140
- }
12141
- } else {
12142
- tokenUrl = new URL("/token", authorizationServerUrl);
12526
+ const tokenUrl = (metadata === null || metadata === void 0 ? void 0 : metadata.token_endpoint) ? new URL(metadata.token_endpoint) : new URL("/token", authorizationServerUrl);
12527
+ if ((metadata === null || metadata === void 0 ? void 0 : metadata.grant_types_supported) && !metadata.grant_types_supported.includes(grantType)) {
12528
+ throw new Error(`Incompatible auth server: does not support grant type ${grantType}`);
12143
12529
  }
12530
+ const headers = new Headers({
12531
+ "Content-Type": "application/x-www-form-urlencoded",
12532
+ "Accept": "application/json"
12533
+ });
12144
12534
  const params = new URLSearchParams({
12145
12535
  grant_type: grantType,
12146
- client_id: clientInformation.client_id,
12147
12536
  code: authorizationCode,
12148
12537
  code_verifier: codeVerifier,
12149
12538
  redirect_uri: String(redirectUri)
12150
12539
  });
12151
- if (clientInformation.client_secret) {
12152
- params.set("client_secret", clientInformation.client_secret);
12540
+ if (addClientAuthentication) {
12541
+ addClientAuthentication(headers, params, authorizationServerUrl, metadata);
12542
+ } else {
12543
+ const supportedMethods = (_a = metadata === null || metadata === void 0 ? void 0 : metadata.token_endpoint_auth_methods_supported) !== null && _a !== void 0 ? _a : [];
12544
+ const authMethod = selectClientAuthMethod(clientInformation, supportedMethods);
12545
+ applyClientAuthentication(authMethod, clientInformation, headers, params);
12153
12546
  }
12154
- const response = await fetch(tokenUrl, {
12547
+ if (resource) {
12548
+ params.set("resource", resource.href);
12549
+ }
12550
+ const response = await (fetchFn !== null && fetchFn !== void 0 ? fetchFn : fetch)(tokenUrl, {
12155
12551
  method: "POST",
12156
- headers: {
12157
- "Content-Type": "application/x-www-form-urlencoded"
12158
- },
12552
+ headers,
12159
12553
  body: params
12160
12554
  });
12161
12555
  if (!response.ok) {
@@ -12163,7 +12557,8 @@ async function exchangeAuthorization(authorizationServerUrl, { metadata, clientI
12163
12557
  }
12164
12558
  return OAuthTokensSchema.parse(await response.json());
12165
12559
  }
12166
- async function refreshAuthorization(authorizationServerUrl, { metadata, clientInformation, refreshToken }) {
12560
+ async function refreshAuthorization(authorizationServerUrl, { metadata, clientInformation, refreshToken, resource, addClientAuthentication, fetchFn }) {
12561
+ var _a;
12167
12562
  const grantType = "refresh_token";
12168
12563
  let tokenUrl;
12169
12564
  if (metadata) {
@@ -12174,19 +12569,26 @@ async function refreshAuthorization(authorizationServerUrl, { metadata, clientIn
12174
12569
  } else {
12175
12570
  tokenUrl = new URL("/token", authorizationServerUrl);
12176
12571
  }
12572
+ const headers = new Headers({
12573
+ "Content-Type": "application/x-www-form-urlencoded"
12574
+ });
12177
12575
  const params = new URLSearchParams({
12178
12576
  grant_type: grantType,
12179
- client_id: clientInformation.client_id,
12180
12577
  refresh_token: refreshToken
12181
12578
  });
12182
- if (clientInformation.client_secret) {
12183
- params.set("client_secret", clientInformation.client_secret);
12579
+ if (addClientAuthentication) {
12580
+ addClientAuthentication(headers, params, authorizationServerUrl, metadata);
12581
+ } else {
12582
+ const supportedMethods = (_a = metadata === null || metadata === void 0 ? void 0 : metadata.token_endpoint_auth_methods_supported) !== null && _a !== void 0 ? _a : [];
12583
+ const authMethod = selectClientAuthMethod(clientInformation, supportedMethods);
12584
+ applyClientAuthentication(authMethod, clientInformation, headers, params);
12184
12585
  }
12185
- const response = await fetch(tokenUrl, {
12586
+ if (resource) {
12587
+ params.set("resource", resource.href);
12588
+ }
12589
+ const response = await (fetchFn !== null && fetchFn !== void 0 ? fetchFn : fetch)(tokenUrl, {
12186
12590
  method: "POST",
12187
- headers: {
12188
- "Content-Type": "application/x-www-form-urlencoded"
12189
- },
12591
+ headers,
12190
12592
  body: params
12191
12593
  });
12192
12594
  if (!response.ok) {
@@ -12194,7 +12596,7 @@ async function refreshAuthorization(authorizationServerUrl, { metadata, clientIn
12194
12596
  }
12195
12597
  return OAuthTokensSchema.parse({ refresh_token: refreshToken, ...await response.json() });
12196
12598
  }
12197
- async function registerClient(authorizationServerUrl, { metadata, clientMetadata }) {
12599
+ async function registerClient(authorizationServerUrl, { metadata, clientMetadata, fetchFn }) {
12198
12600
  let registrationUrl;
12199
12601
  if (metadata) {
12200
12602
  if (!metadata.registration_endpoint) {
@@ -12204,7 +12606,7 @@ async function registerClient(authorizationServerUrl, { metadata, clientMetadata
12204
12606
  } else {
12205
12607
  registrationUrl = new URL("/register", authorizationServerUrl);
12206
12608
  }
12207
- const response = await fetch(registrationUrl, {
12609
+ const response = await (fetchFn !== null && fetchFn !== void 0 ? fetchFn : fetch)(registrationUrl, {
12208
12610
  method: "POST",
12209
12611
  headers: {
12210
12612
  "Content-Type": "application/json"
@@ -12617,7 +13019,7 @@ function getBaseURL() {
12617
13019
  return doc && typeof doc == "object" && "baseURI" in doc && typeof doc.baseURI == "string" ? doc.baseURI : void 0;
12618
13020
  }
12619
13021
 
12620
- // node_modules/.pnpm/@modelcontextprotocol+sdk@https+++pkg.pr.new+geelen+typescript-sdk+@modelcontextprotocol+sdk@cdf3508/node_modules/@modelcontextprotocol/sdk/dist/esm/client/sse.js
13022
+ // node_modules/.pnpm/@modelcontextprotocol+sdk@1.17.4/node_modules/@modelcontextprotocol/sdk/dist/esm/client/sse.js
12621
13023
  var SseError = class extends Error {
12622
13024
  constructor(code, message, event) {
12623
13025
  super(`SSE error: ${message}`);
@@ -12632,6 +13034,7 @@ var SSEClientTransport = class {
12632
13034
  this._eventSourceInit = opts === null || opts === void 0 ? void 0 : opts.eventSourceInit;
12633
13035
  this._requestInit = opts === null || opts === void 0 ? void 0 : opts.requestInit;
12634
13036
  this._authProvider = opts === null || opts === void 0 ? void 0 : opts.authProvider;
13037
+ this._fetch = opts === null || opts === void 0 ? void 0 : opts.fetch;
12635
13038
  }
12636
13039
  async _authThenStart() {
12637
13040
  var _a;
@@ -12640,7 +13043,7 @@ var SSEClientTransport = class {
12640
13043
  }
12641
13044
  let result;
12642
13045
  try {
12643
- result = await auth(this._authProvider, { serverUrl: this._url, resourceMetadataUrl: this._resourceMetadataUrl });
13046
+ result = await auth(this._authProvider, { serverUrl: this._url, resourceMetadataUrl: this._resourceMetadataUrl, fetchFn: this._fetch });
12644
13047
  } catch (error) {
12645
13048
  (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error);
12646
13049
  throw error;
@@ -12652,26 +13055,36 @@ var SSEClientTransport = class {
12652
13055
  }
12653
13056
  async _commonHeaders() {
12654
13057
  var _a;
12655
- const headers = { ...(_a = this._requestInit) === null || _a === void 0 ? void 0 : _a.headers };
13058
+ const headers = {};
12656
13059
  if (this._authProvider) {
12657
13060
  const tokens = await this._authProvider.tokens();
12658
13061
  if (tokens) {
12659
13062
  headers["Authorization"] = `Bearer ${tokens.access_token}`;
12660
13063
  }
12661
13064
  }
12662
- return headers;
13065
+ if (this._protocolVersion) {
13066
+ headers["mcp-protocol-version"] = this._protocolVersion;
13067
+ }
13068
+ return new Headers({ ...headers, ...(_a = this._requestInit) === null || _a === void 0 ? void 0 : _a.headers });
12663
13069
  }
12664
13070
  _startOrAuth() {
13071
+ var _a, _b, _c;
13072
+ const fetchImpl = (_c = (_b = (_a = this === null || this === void 0 ? void 0 : this._eventSourceInit) === null || _a === void 0 ? void 0 : _a.fetch) !== null && _b !== void 0 ? _b : this._fetch) !== null && _c !== void 0 ? _c : fetch;
12665
13073
  return new Promise((resolve, reject) => {
12666
- var _a;
12667
- this._eventSource = new EventSource(this._url.href, (_a = this._eventSourceInit) !== null && _a !== void 0 ? _a : {
12668
- fetch: (url, init) => this._commonHeaders().then((headers) => fetch(url, {
12669
- ...init,
12670
- headers: {
12671
- ...headers,
12672
- Accept: "text/event-stream"
13074
+ this._eventSource = new EventSource(this._url.href, {
13075
+ ...this._eventSourceInit,
13076
+ fetch: async (url, init) => {
13077
+ const headers = await this._commonHeaders();
13078
+ headers.set("Accept", "text/event-stream");
13079
+ const response = await fetchImpl(url, {
13080
+ ...init,
13081
+ headers
13082
+ });
13083
+ if (response.status === 401 && response.headers.has("www-authenticate")) {
13084
+ this._resourceMetadataUrl = extractResourceMetadataUrl(response);
12673
13085
  }
12674
- }))
13086
+ return response;
13087
+ }
12675
13088
  });
12676
13089
  this._abortController = new AbortController();
12677
13090
  this._eventSource.onerror = (event) => {
@@ -12703,7 +13116,7 @@ var SSEClientTransport = class {
12703
13116
  resolve();
12704
13117
  });
12705
13118
  this._eventSource.onmessage = (event) => {
12706
- var _a2, _b;
13119
+ var _a2, _b2;
12707
13120
  const messageEvent = event;
12708
13121
  let message;
12709
13122
  try {
@@ -12712,7 +13125,7 @@ var SSEClientTransport = class {
12712
13125
  (_a2 = this.onerror) === null || _a2 === void 0 ? void 0 : _a2.call(this, error);
12713
13126
  return;
12714
13127
  }
12715
- (_b = this.onmessage) === null || _b === void 0 ? void 0 : _b.call(this, message);
13128
+ (_b2 = this.onmessage) === null || _b2 === void 0 ? void 0 : _b2.call(this, message);
12716
13129
  };
12717
13130
  });
12718
13131
  }
@@ -12729,7 +13142,7 @@ var SSEClientTransport = class {
12729
13142
  if (!this._authProvider) {
12730
13143
  throw new UnauthorizedError("No auth provider");
12731
13144
  }
12732
- const result = await auth(this._authProvider, { serverUrl: this._url, authorizationCode, resourceMetadataUrl: this._resourceMetadataUrl });
13145
+ const result = await auth(this._authProvider, { serverUrl: this._url, authorizationCode, resourceMetadataUrl: this._resourceMetadataUrl, fetchFn: this._fetch });
12733
13146
  if (result !== "AUTHORIZED") {
12734
13147
  throw new UnauthorizedError("Failed to authorize");
12735
13148
  }
@@ -12746,21 +13159,20 @@ var SSEClientTransport = class {
12746
13159
  throw new Error("Not connected");
12747
13160
  }
12748
13161
  try {
12749
- const commonHeaders = await this._commonHeaders();
12750
- const headers = new Headers({ ...commonHeaders, ...(_a = this._requestInit) === null || _a === void 0 ? void 0 : _a.headers });
13162
+ const headers = await this._commonHeaders();
12751
13163
  headers.set("content-type", "application/json");
12752
13164
  const init = {
12753
13165
  ...this._requestInit,
12754
13166
  method: "POST",
12755
13167
  headers,
12756
13168
  body: JSON.stringify(message),
12757
- signal: (_b = this._abortController) === null || _b === void 0 ? void 0 : _b.signal
13169
+ signal: (_a = this._abortController) === null || _a === void 0 ? void 0 : _a.signal
12758
13170
  };
12759
- const response = await fetch(this._endpoint, init);
13171
+ const response = await ((_b = this._fetch) !== null && _b !== void 0 ? _b : fetch)(this._endpoint, init);
12760
13172
  if (!response.ok) {
12761
13173
  if (response.status === 401 && this._authProvider) {
12762
13174
  this._resourceMetadataUrl = extractResourceMetadataUrl(response);
12763
- const result = await auth(this._authProvider, { serverUrl: this._url, resourceMetadataUrl: this._resourceMetadataUrl });
13175
+ const result = await auth(this._authProvider, { serverUrl: this._url, resourceMetadataUrl: this._resourceMetadataUrl, fetchFn: this._fetch });
12764
13176
  if (result !== "AUTHORIZED") {
12765
13177
  throw new UnauthorizedError();
12766
13178
  }
@@ -12774,6 +13186,9 @@ var SSEClientTransport = class {
12774
13186
  throw error;
12775
13187
  }
12776
13188
  }
13189
+ setProtocolVersion(version2) {
13190
+ this._protocolVersion = version2;
13191
+ }
12777
13192
  };
12778
13193
 
12779
13194
  // node_modules/.pnpm/eventsource-parser@3.0.1/node_modules/eventsource-parser/dist/stream.js
@@ -12800,7 +13215,7 @@ var EventSourceParserStream = class extends TransformStream {
12800
13215
  }
12801
13216
  };
12802
13217
 
12803
- // node_modules/.pnpm/@modelcontextprotocol+sdk@https+++pkg.pr.new+geelen+typescript-sdk+@modelcontextprotocol+sdk@cdf3508/node_modules/@modelcontextprotocol/sdk/dist/esm/client/streamableHttp.js
13218
+ // node_modules/.pnpm/@modelcontextprotocol+sdk@1.17.4/node_modules/@modelcontextprotocol/sdk/dist/esm/client/streamableHttp.js
12804
13219
  var DEFAULT_STREAMABLE_HTTP_RECONNECTION_OPTIONS = {
12805
13220
  initialReconnectionDelay: 1e3,
12806
13221
  maxReconnectionDelay: 3e4,
@@ -12820,6 +13235,7 @@ var StreamableHTTPClientTransport = class {
12820
13235
  this._resourceMetadataUrl = void 0;
12821
13236
  this._requestInit = opts === null || opts === void 0 ? void 0 : opts.requestInit;
12822
13237
  this._authProvider = opts === null || opts === void 0 ? void 0 : opts.authProvider;
13238
+ this._fetch = opts === null || opts === void 0 ? void 0 : opts.fetch;
12823
13239
  this._sessionId = opts === null || opts === void 0 ? void 0 : opts.sessionId;
12824
13240
  this._reconnectionOptions = (_a = opts === null || opts === void 0 ? void 0 : opts.reconnectionOptions) !== null && _a !== void 0 ? _a : DEFAULT_STREAMABLE_HTTP_RECONNECTION_OPTIONS;
12825
13241
  }
@@ -12830,7 +13246,7 @@ var StreamableHTTPClientTransport = class {
12830
13246
  }
12831
13247
  let result;
12832
13248
  try {
12833
- result = await auth(this._authProvider, { serverUrl: this._url, resourceMetadataUrl: this._resourceMetadataUrl });
13249
+ result = await auth(this._authProvider, { serverUrl: this._url, resourceMetadataUrl: this._resourceMetadataUrl, fetchFn: this._fetch });
12834
13250
  } catch (error) {
12835
13251
  (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error);
12836
13252
  throw error;
@@ -12852,10 +13268,17 @@ var StreamableHTTPClientTransport = class {
12852
13268
  if (this._sessionId) {
12853
13269
  headers["mcp-session-id"] = this._sessionId;
12854
13270
  }
12855
- return new Headers({ ...headers, ...(_a = this._requestInit) === null || _a === void 0 ? void 0 : _a.headers });
13271
+ if (this._protocolVersion) {
13272
+ headers["mcp-protocol-version"] = this._protocolVersion;
13273
+ }
13274
+ const extraHeaders = this._normalizeHeaders((_a = this._requestInit) === null || _a === void 0 ? void 0 : _a.headers);
13275
+ return new Headers({
13276
+ ...headers,
13277
+ ...extraHeaders
13278
+ });
12856
13279
  }
12857
13280
  async _startOrAuthSse(options) {
12858
- var _a, _b;
13281
+ var _a, _b, _c;
12859
13282
  const { resumptionToken } = options;
12860
13283
  try {
12861
13284
  const headers = await this._commonHeaders();
@@ -12863,10 +13286,10 @@ var StreamableHTTPClientTransport = class {
12863
13286
  if (resumptionToken) {
12864
13287
  headers.set("last-event-id", resumptionToken);
12865
13288
  }
12866
- const response = await fetch(this._url, {
13289
+ const response = await ((_a = this._fetch) !== null && _a !== void 0 ? _a : fetch)(this._url, {
12867
13290
  method: "GET",
12868
13291
  headers,
12869
- signal: (_a = this._abortController) === null || _a === void 0 ? void 0 : _a.signal
13292
+ signal: (_b = this._abortController) === null || _b === void 0 ? void 0 : _b.signal
12870
13293
  });
12871
13294
  if (!response.ok) {
12872
13295
  if (response.status === 401 && this._authProvider) {
@@ -12877,9 +13300,9 @@ var StreamableHTTPClientTransport = class {
12877
13300
  }
12878
13301
  throw new StreamableHTTPError(response.status, `Failed to open SSE stream: ${response.statusText}`);
12879
13302
  }
12880
- this._handleSseStream(response.body, options);
13303
+ this._handleSseStream(response.body, options, true);
12881
13304
  } catch (error) {
12882
- (_b = this.onerror) === null || _b === void 0 ? void 0 : _b.call(this, error);
13305
+ (_c = this.onerror) === null || _c === void 0 ? void 0 : _c.call(this, error);
12883
13306
  throw error;
12884
13307
  }
12885
13308
  }
@@ -12895,6 +13318,17 @@ var StreamableHTTPClientTransport = class {
12895
13318
  const maxDelay = this._reconnectionOptions.maxReconnectionDelay;
12896
13319
  return Math.min(initialDelay * Math.pow(growFactor, attempt), maxDelay);
12897
13320
  }
13321
+ _normalizeHeaders(headers) {
13322
+ if (!headers)
13323
+ return {};
13324
+ if (headers instanceof Headers) {
13325
+ return Object.fromEntries(headers.entries());
13326
+ }
13327
+ if (Array.isArray(headers)) {
13328
+ return Object.fromEntries(headers);
13329
+ }
13330
+ return { ...headers };
13331
+ }
12898
13332
  /**
12899
13333
  * Schedule a reconnection attempt with exponential backoff
12900
13334
  *
@@ -12917,7 +13351,7 @@ var StreamableHTTPClientTransport = class {
12917
13351
  });
12918
13352
  }, delay);
12919
13353
  }
12920
- _handleSseStream(stream, options) {
13354
+ _handleSseStream(stream, options, isReconnectable) {
12921
13355
  if (!stream) {
12922
13356
  return;
12923
13357
  }
@@ -12950,17 +13384,15 @@ var StreamableHTTPClientTransport = class {
12950
13384
  }
12951
13385
  } catch (error) {
12952
13386
  (_c = this.onerror) === null || _c === void 0 ? void 0 : _c.call(this, new Error(`SSE stream disconnected: ${error}`));
12953
- if (this._abortController && !this._abortController.signal.aborted) {
12954
- if (lastEventId !== void 0) {
12955
- try {
12956
- this._scheduleReconnection({
12957
- resumptionToken: lastEventId,
12958
- onresumptiontoken,
12959
- replayMessageId
12960
- }, 0);
12961
- } catch (error2) {
12962
- (_d = this.onerror) === null || _d === void 0 ? void 0 : _d.call(this, new Error(`Failed to reconnect: ${error2 instanceof Error ? error2.message : String(error2)}`));
12963
- }
13387
+ if (isReconnectable && this._abortController && !this._abortController.signal.aborted) {
13388
+ try {
13389
+ this._scheduleReconnection({
13390
+ resumptionToken: lastEventId,
13391
+ onresumptiontoken,
13392
+ replayMessageId
13393
+ }, 0);
13394
+ } catch (error2) {
13395
+ (_d = this.onerror) === null || _d === void 0 ? void 0 : _d.call(this, new Error(`Failed to reconnect: ${error2 instanceof Error ? error2.message : String(error2)}`));
12964
13396
  }
12965
13397
  }
12966
13398
  }
@@ -12980,7 +13412,7 @@ var StreamableHTTPClientTransport = class {
12980
13412
  if (!this._authProvider) {
12981
13413
  throw new UnauthorizedError("No auth provider");
12982
13414
  }
12983
- const result = await auth(this._authProvider, { serverUrl: this._url, authorizationCode, resourceMetadataUrl: this._resourceMetadataUrl });
13415
+ const result = await auth(this._authProvider, { serverUrl: this._url, authorizationCode, resourceMetadataUrl: this._resourceMetadataUrl, fetchFn: this._fetch });
12984
13416
  if (result !== "AUTHORIZED") {
12985
13417
  throw new UnauthorizedError("Failed to authorize");
12986
13418
  }
@@ -12991,7 +13423,7 @@ var StreamableHTTPClientTransport = class {
12991
13423
  (_b = this.onclose) === null || _b === void 0 ? void 0 : _b.call(this);
12992
13424
  }
12993
13425
  async send(message, options) {
12994
- var _a, _b, _c;
13426
+ var _a, _b, _c, _d;
12995
13427
  try {
12996
13428
  const { resumptionToken, onresumptiontoken } = options || {};
12997
13429
  if (resumptionToken) {
@@ -13011,7 +13443,7 @@ var StreamableHTTPClientTransport = class {
13011
13443
  body: JSON.stringify(message),
13012
13444
  signal: (_a = this._abortController) === null || _a === void 0 ? void 0 : _a.signal
13013
13445
  };
13014
- const response = await fetch(this._url, init);
13446
+ const response = await ((_b = this._fetch) !== null && _b !== void 0 ? _b : fetch)(this._url, init);
13015
13447
  const sessionId = response.headers.get("mcp-session-id");
13016
13448
  if (sessionId) {
13017
13449
  this._sessionId = sessionId;
@@ -13019,7 +13451,7 @@ var StreamableHTTPClientTransport = class {
13019
13451
  if (!response.ok) {
13020
13452
  if (response.status === 401 && this._authProvider) {
13021
13453
  this._resourceMetadataUrl = extractResourceMetadataUrl(response);
13022
- const result = await auth(this._authProvider, { serverUrl: this._url, resourceMetadataUrl: this._resourceMetadataUrl });
13454
+ const result = await auth(this._authProvider, { serverUrl: this._url, resourceMetadataUrl: this._resourceMetadataUrl, fetchFn: this._fetch });
13023
13455
  if (result !== "AUTHORIZED") {
13024
13456
  throw new UnauthorizedError();
13025
13457
  }
@@ -13042,19 +13474,19 @@ var StreamableHTTPClientTransport = class {
13042
13474
  const contentType = response.headers.get("content-type");
13043
13475
  if (hasRequests) {
13044
13476
  if (contentType === null || contentType === void 0 ? void 0 : contentType.includes("text/event-stream")) {
13045
- this._handleSseStream(response.body, { onresumptiontoken });
13477
+ this._handleSseStream(response.body, { onresumptiontoken }, false);
13046
13478
  } else if (contentType === null || contentType === void 0 ? void 0 : contentType.includes("application/json")) {
13047
13479
  const data = await response.json();
13048
13480
  const responseMessages = Array.isArray(data) ? data.map((msg) => JSONRPCMessageSchema.parse(msg)) : [JSONRPCMessageSchema.parse(data)];
13049
13481
  for (const msg of responseMessages) {
13050
- (_b = this.onmessage) === null || _b === void 0 ? void 0 : _b.call(this, msg);
13482
+ (_c = this.onmessage) === null || _c === void 0 ? void 0 : _c.call(this, msg);
13051
13483
  }
13052
13484
  } else {
13053
13485
  throw new StreamableHTTPError(-1, `Unexpected content type: ${contentType}`);
13054
13486
  }
13055
13487
  }
13056
13488
  } catch (error) {
13057
- (_c = this.onerror) === null || _c === void 0 ? void 0 : _c.call(this, error);
13489
+ (_d = this.onerror) === null || _d === void 0 ? void 0 : _d.call(this, error);
13058
13490
  throw error;
13059
13491
  }
13060
13492
  }
@@ -13073,7 +13505,7 @@ var StreamableHTTPClientTransport = class {
13073
13505
  * the server does not allow clients to terminate sessions.
13074
13506
  */
13075
13507
  async terminateSession() {
13076
- var _a, _b;
13508
+ var _a, _b, _c;
13077
13509
  if (!this._sessionId) {
13078
13510
  return;
13079
13511
  }
@@ -13085,16 +13517,22 @@ var StreamableHTTPClientTransport = class {
13085
13517
  headers,
13086
13518
  signal: (_a = this._abortController) === null || _a === void 0 ? void 0 : _a.signal
13087
13519
  };
13088
- const response = await fetch(this._url, init);
13520
+ const response = await ((_b = this._fetch) !== null && _b !== void 0 ? _b : fetch)(this._url, init);
13089
13521
  if (!response.ok && response.status !== 405) {
13090
13522
  throw new StreamableHTTPError(response.status, `Failed to terminate session: ${response.statusText}`);
13091
13523
  }
13092
13524
  this._sessionId = void 0;
13093
13525
  } catch (error) {
13094
- (_b = this.onerror) === null || _b === void 0 ? void 0 : _b.call(this, error);
13526
+ (_c = this.onerror) === null || _c === void 0 ? void 0 : _c.call(this, error);
13095
13527
  throw error;
13096
13528
  }
13097
13529
  }
13530
+ setProtocolVersion(version2) {
13531
+ this._protocolVersion = version2;
13532
+ }
13533
+ get protocolVersion() {
13534
+ return this._protocolVersion;
13535
+ }
13098
13536
  };
13099
13537
 
13100
13538
  // src/lib/mcp-auth-config.ts
@@ -13323,7 +13761,7 @@ async function connectToRemoteServer(client, serverUrl, authProvider, headers, a
13323
13761
  }
13324
13762
  };
13325
13763
  log(`Using transport strategy: ${transportStrategy}`);
13326
- const shouldAttemptFallback = transportStrategy === "http-first" || transportStrategy === "sse-first";
13764
+ const shouldAttemptFallback2 = transportStrategy === "http-first" || transportStrategy === "sse-first";
13327
13765
  const sseTransport = transportStrategy === "sse-only" || transportStrategy === "sse-first";
13328
13766
  const transport = sseTransport ? new SSEClientTransport(url, {
13329
13767
  authProvider,
@@ -13351,7 +13789,7 @@ async function connectToRemoteServer(client, serverUrl, authProvider, headers, a
13351
13789
  log(`Connected to remote server using ${transport.constructor.name}`);
13352
13790
  return transport;
13353
13791
  } catch (error) {
13354
- if (error instanceof Error && shouldAttemptFallback && (error.message.includes("405") || error.message.includes("Method Not Allowed") || error.message.includes("404") || error.message.includes("Not Found"))) {
13792
+ if (error instanceof Error && shouldAttemptFallback2 && (error.message.includes("405") || error.message.includes("Method Not Allowed") || error.message.includes("404") || error.message.includes("Not Found"))) {
13355
13793
  log(`Received error: ${error.message}`);
13356
13794
  if (recursionReasons.has(REASON_TRANSPORT_FALLBACK)) {
13357
13795
  const errorMessage = `Already attempted transport fallback. Giving up.`;
@@ -13601,6 +14039,12 @@ async function parseCommandLineArgs(args, usage) {
13601
14039
  log(`Using static OAuth client information from string`);
13602
14040
  }
13603
14041
  }
14042
+ let authorizeResource = "";
14043
+ const resourceIndex = args.indexOf("--resource");
14044
+ if (resourceIndex !== -1 && resourceIndex < args.length - 1) {
14045
+ authorizeResource = args[resourceIndex + 1];
14046
+ log(`Using authorize resource: ${authorizeResource}`);
14047
+ }
13604
14048
  if (!serverUrl) {
13605
14049
  log(usage);
13606
14050
  process.exit(1);
@@ -13651,7 +14095,17 @@ async function parseCommandLineArgs(args, usage) {
13651
14095
  }
13652
14096
  });
13653
14097
  }
13654
- return { serverUrl, callbackPort, headers, transportStrategy, host, debug, staticOAuthClientMetadata, staticOAuthClientInfo };
14098
+ return {
14099
+ serverUrl,
14100
+ callbackPort,
14101
+ headers,
14102
+ transportStrategy,
14103
+ host,
14104
+ debug,
14105
+ staticOAuthClientMetadata,
14106
+ staticOAuthClientInfo,
14107
+ authorizeResource
14108
+ };
13655
14109
  }
13656
14110
  function setupSignalHandlers(cleanup) {
13657
14111
  process.on("SIGINT", async () => {
@@ -13689,6 +14143,7 @@ var NodeOAuthClientProvider = class {
13689
14143
  this.softwareVersion = options.softwareVersion || version;
13690
14144
  this.staticOAuthClientMetadata = options.staticOAuthClientMetadata;
13691
14145
  this.staticOAuthClientInfo = options.staticOAuthClientInfo;
14146
+ this.authorizeResource = options.authorizeResource;
13692
14147
  this._state = randomUUID();
13693
14148
  }
13694
14149
  serverUrlHash;
@@ -13699,6 +14154,7 @@ var NodeOAuthClientProvider = class {
13699
14154
  softwareVersion;
13700
14155
  staticOAuthClientMetadata;
13701
14156
  staticOAuthClientInfo;
14157
+ authorizeResource;
13702
14158
  _state;
13703
14159
  get redirectUrl() {
13704
14160
  return `http://${this.options.host}:${this.options.callbackPort}${this.callbackPath}`;
@@ -13807,6 +14263,9 @@ var NodeOAuthClientProvider = class {
13807
14263
  * @param authorizationUrl The URL to redirect to
13808
14264
  */
13809
14265
  async redirectToAuthorization(authorizationUrl) {
14266
+ if (this.authorizeResource) {
14267
+ authorizationUrl.searchParams.set("resource", this.authorizeResource);
14268
+ }
13810
14269
  log(`
13811
14270
  Please authorize this client by visiting:
13812
14271
  ${authorizationUrl.toString()}