@google-cloud/storage-mcp 0.3.2 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bundle.js CHANGED
@@ -20520,13 +20520,12 @@ async function safeParseAsync2(schema, data) {
20520
20520
  return result;
20521
20521
  }
20522
20522
  function getObjectShape(schema) {
20523
- var _a2, _b2;
20524
20523
  if (!schema)
20525
20524
  return void 0;
20526
20525
  let rawShape;
20527
20526
  if (isZ4Schema(schema)) {
20528
20527
  const v4Schema = schema;
20529
- rawShape = (_b2 = (_a2 = v4Schema._zod) === null || _a2 === void 0 ? void 0 : _a2.def) === null || _b2 === void 0 ? void 0 : _b2.shape;
20528
+ rawShape = v4Schema._zod?.def?.shape;
20530
20529
  } else {
20531
20530
  const v3Schema = schema;
20532
20531
  rawShape = v3Schema.shape;
@@ -20536,14 +20535,13 @@ function getObjectShape(schema) {
20536
20535
  if (typeof rawShape === "function") {
20537
20536
  try {
20538
20537
  return rawShape();
20539
- } catch (_c2) {
20538
+ } catch {
20540
20539
  return void 0;
20541
20540
  }
20542
20541
  }
20543
20542
  return rawShape;
20544
20543
  }
20545
20544
  function normalizeObjectSchema(schema) {
20546
- var _a2;
20547
20545
  if (!schema)
20548
20546
  return void 0;
20549
20547
  if (typeof schema === "object") {
@@ -20558,7 +20556,7 @@ function normalizeObjectSchema(schema) {
20558
20556
  }
20559
20557
  if (isZ4Schema(schema)) {
20560
20558
  const v4Schema = schema;
20561
- const def = (_a2 = v4Schema._zod) === null || _a2 === void 0 ? void 0 : _a2.def;
20559
+ const def = v4Schema._zod?.def;
20562
20560
  if (def && (def.type === "object" || def.shape !== void 0)) {
20563
20561
  return schema;
20564
20562
  }
@@ -20583,38 +20581,30 @@ function getParseErrorMessage(error2) {
20583
20581
  }
20584
20582
  try {
20585
20583
  return JSON.stringify(error2);
20586
- } catch (_a2) {
20584
+ } catch {
20587
20585
  return String(error2);
20588
20586
  }
20589
20587
  }
20590
20588
  return String(error2);
20591
20589
  }
20592
20590
  function getSchemaDescription(schema) {
20593
- var _a2, _b2, _c2, _d;
20594
- if (isZ4Schema(schema)) {
20595
- const v4Schema = schema;
20596
- return (_b2 = (_a2 = v4Schema._zod) === null || _a2 === void 0 ? void 0 : _a2.def) === null || _b2 === void 0 ? void 0 : _b2.description;
20597
- }
20598
- const v3Schema = schema;
20599
- return (_c2 = schema.description) !== null && _c2 !== void 0 ? _c2 : (_d = v3Schema._def) === null || _d === void 0 ? void 0 : _d.description;
20591
+ return schema.description;
20600
20592
  }
20601
20593
  function isSchemaOptional(schema) {
20602
- var _a2, _b2, _c2;
20603
20594
  if (isZ4Schema(schema)) {
20604
20595
  const v4Schema = schema;
20605
- return ((_b2 = (_a2 = v4Schema._zod) === null || _a2 === void 0 ? void 0 : _a2.def) === null || _b2 === void 0 ? void 0 : _b2.type) === "optional";
20596
+ return v4Schema._zod?.def?.type === "optional";
20606
20597
  }
20607
20598
  const v3Schema = schema;
20608
20599
  if (typeof schema.isOptional === "function") {
20609
20600
  return schema.isOptional();
20610
20601
  }
20611
- return ((_c2 = v3Schema._def) === null || _c2 === void 0 ? void 0 : _c2.typeName) === "ZodOptional";
20602
+ return v3Schema._def?.typeName === "ZodOptional";
20612
20603
  }
20613
20604
  function getLiteralValue(schema) {
20614
- var _a2;
20615
20605
  if (isZ4Schema(schema)) {
20616
20606
  const v4Schema = schema;
20617
- const def2 = (_a2 = v4Schema._zod) === null || _a2 === void 0 ? void 0 : _a2.def;
20607
+ const def2 = v4Schema._zod?.def;
20618
20608
  if (def2) {
20619
20609
  if (def2.value !== void 0)
20620
20610
  return def2.value;
@@ -21352,7 +21342,10 @@ var TaskCreationParamsSchema = looseObject({
21352
21342
  */
21353
21343
  pollInterval: number2().optional()
21354
21344
  });
21355
- var RelatedTaskMetadataSchema = looseObject({
21345
+ var TaskMetadataSchema = object2({
21346
+ ttl: number2().optional()
21347
+ });
21348
+ var RelatedTaskMetadataSchema = object2({
21356
21349
  taskId: string2()
21357
21350
  });
21358
21351
  var RequestMetaSchema = looseObject({
@@ -21365,48 +21358,45 @@ var RequestMetaSchema = looseObject({
21365
21358
  */
21366
21359
  [RELATED_TASK_META_KEY]: RelatedTaskMetadataSchema.optional()
21367
21360
  });
21368
- var BaseRequestParamsSchema = looseObject({
21369
- /**
21370
- * If specified, the caller is requesting that the receiver create a task to represent the request.
21371
- * Task creation parameters are now at the top level instead of in _meta.
21372
- */
21373
- task: TaskCreationParamsSchema.optional(),
21361
+ var BaseRequestParamsSchema = object2({
21374
21362
  /**
21375
21363
  * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage.
21376
21364
  */
21377
21365
  _meta: RequestMetaSchema.optional()
21378
21366
  });
21367
+ var TaskAugmentedRequestParamsSchema = BaseRequestParamsSchema.extend({
21368
+ /**
21369
+ * If specified, the caller is requesting task-augmented execution for this request.
21370
+ * The request will return a CreateTaskResult immediately, and the actual result can be
21371
+ * retrieved later via tasks/result.
21372
+ *
21373
+ * Task augmentation is subject to capability negotiation - receivers MUST declare support
21374
+ * for task augmentation of specific request types in their capabilities.
21375
+ */
21376
+ task: TaskMetadataSchema.optional()
21377
+ });
21378
+ var isTaskAugmentedRequestParams = (value) => TaskAugmentedRequestParamsSchema.safeParse(value).success;
21379
21379
  var RequestSchema = object2({
21380
21380
  method: string2(),
21381
- params: BaseRequestParamsSchema.optional()
21381
+ params: BaseRequestParamsSchema.loose().optional()
21382
21382
  });
21383
- var NotificationsParamsSchema = looseObject({
21383
+ var NotificationsParamsSchema = object2({
21384
21384
  /**
21385
21385
  * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
21386
21386
  * for notes on _meta usage.
21387
21387
  */
21388
- _meta: object2({
21389
- /**
21390
- * If specified, this notification is related to the provided task.
21391
- */
21392
- [RELATED_TASK_META_KEY]: optional(RelatedTaskMetadataSchema)
21393
- }).passthrough().optional()
21388
+ _meta: RequestMetaSchema.optional()
21394
21389
  });
21395
21390
  var NotificationSchema = object2({
21396
21391
  method: string2(),
21397
- params: NotificationsParamsSchema.optional()
21392
+ params: NotificationsParamsSchema.loose().optional()
21398
21393
  });
21399
21394
  var ResultSchema = looseObject({
21400
21395
  /**
21401
21396
  * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
21402
21397
  * for notes on _meta usage.
21403
21398
  */
21404
- _meta: looseObject({
21405
- /**
21406
- * If specified, this result is related to the provided task.
21407
- */
21408
- [RELATED_TASK_META_KEY]: RelatedTaskMetadataSchema.optional()
21409
- }).optional()
21399
+ _meta: RequestMetaSchema.optional()
21410
21400
  });
21411
21401
  var RequestIdSchema = union([string2(), number2().int()]);
21412
21402
  var JSONRPCRequestSchema = object2({
@@ -21420,12 +21410,12 @@ var JSONRPCNotificationSchema = object2({
21420
21410
  ...NotificationSchema.shape
21421
21411
  }).strict();
21422
21412
  var isJSONRPCNotification = (value) => JSONRPCNotificationSchema.safeParse(value).success;
21423
- var JSONRPCResponseSchema = object2({
21413
+ var JSONRPCResultResponseSchema = object2({
21424
21414
  jsonrpc: literal(JSONRPC_VERSION),
21425
21415
  id: RequestIdSchema,
21426
21416
  result: ResultSchema
21427
21417
  }).strict();
21428
- var isJSONRPCResponse = (value) => JSONRPCResponseSchema.safeParse(value).success;
21418
+ var isJSONRPCResultResponse = (value) => JSONRPCResultResponseSchema.safeParse(value).success;
21429
21419
  var ErrorCode;
21430
21420
  (function(ErrorCode2) {
21431
21421
  ErrorCode2[ErrorCode2["ConnectionClosed"] = -32e3] = "ConnectionClosed";
@@ -21437,9 +21427,9 @@ var ErrorCode;
21437
21427
  ErrorCode2[ErrorCode2["InternalError"] = -32603] = "InternalError";
21438
21428
  ErrorCode2[ErrorCode2["UrlElicitationRequired"] = -32042] = "UrlElicitationRequired";
21439
21429
  })(ErrorCode || (ErrorCode = {}));
21440
- var JSONRPCErrorSchema = object2({
21430
+ var JSONRPCErrorResponseSchema = object2({
21441
21431
  jsonrpc: literal(JSONRPC_VERSION),
21442
- id: RequestIdSchema,
21432
+ id: RequestIdSchema.optional(),
21443
21433
  error: object2({
21444
21434
  /**
21445
21435
  * The error type that occurred.
@@ -21452,11 +21442,17 @@ var JSONRPCErrorSchema = object2({
21452
21442
  /**
21453
21443
  * Additional information about the error. The value of this member is defined by the sender (e.g. detailed error information, nested errors etc.).
21454
21444
  */
21455
- data: optional(unknown())
21445
+ data: unknown().optional()
21456
21446
  })
21457
21447
  }).strict();
21458
- var isJSONRPCError = (value) => JSONRPCErrorSchema.safeParse(value).success;
21459
- var JSONRPCMessageSchema = union([JSONRPCRequestSchema, JSONRPCNotificationSchema, JSONRPCResponseSchema, JSONRPCErrorSchema]);
21448
+ var isJSONRPCErrorResponse = (value) => JSONRPCErrorResponseSchema.safeParse(value).success;
21449
+ var JSONRPCMessageSchema = union([
21450
+ JSONRPCRequestSchema,
21451
+ JSONRPCNotificationSchema,
21452
+ JSONRPCResultResponseSchema,
21453
+ JSONRPCErrorResponseSchema
21454
+ ]);
21455
+ var JSONRPCResponseSchema = union([JSONRPCResultResponseSchema, JSONRPCErrorResponseSchema]);
21460
21456
  var EmptyResultSchema = ResultSchema.strict();
21461
21457
  var CancelledNotificationParamsSchema = NotificationsParamsSchema.extend({
21462
21458
  /**
@@ -21464,7 +21460,7 @@ var CancelledNotificationParamsSchema = NotificationsParamsSchema.extend({
21464
21460
  *
21465
21461
  * This MUST correspond to the ID of a request previously issued in the same direction.
21466
21462
  */
21467
- requestId: RequestIdSchema,
21463
+ requestId: RequestIdSchema.optional(),
21468
21464
  /**
21469
21465
  * An optional string describing the reason for the cancellation. This MAY be logged or presented to the user.
21470
21466
  */
@@ -21489,7 +21485,15 @@ var IconSchema = object2({
21489
21485
  *
21490
21486
  * If not provided, the client should assume that the icon can be used at any size.
21491
21487
  */
21492
- sizes: array(string2()).optional()
21488
+ sizes: array(string2()).optional(),
21489
+ /**
21490
+ * Optional specifier for the theme this icon is designed for. `light` indicates
21491
+ * the icon is designed to be used with a light background, and `dark` indicates
21492
+ * the icon is designed to be used with a dark background.
21493
+ *
21494
+ * If not provided, the client should assume the icon can be used with any theme.
21495
+ */
21496
+ theme: _enum(["light", "dark"]).optional()
21493
21497
  });
21494
21498
  var IconsSchema = object2({
21495
21499
  /**
@@ -21525,7 +21529,15 @@ var ImplementationSchema = BaseMetadataSchema.extend({
21525
21529
  /**
21526
21530
  * An optional URL of the website for this implementation.
21527
21531
  */
21528
- websiteUrl: string2().optional()
21532
+ websiteUrl: string2().optional(),
21533
+ /**
21534
+ * An optional human-readable description of what this implementation does.
21535
+ *
21536
+ * This can be used by clients or servers to provide context about their purpose
21537
+ * and capabilities. For example, a server might describe the types of resources
21538
+ * or tools it provides, while a client might describe its intended use case.
21539
+ */
21540
+ description: string2().optional()
21529
21541
  });
21530
21542
  var FormElicitationCapabilitySchema = intersection(object2({
21531
21543
  applyDefaults: boolean2().optional()
@@ -21541,54 +21553,54 @@ var ElicitationCapabilitySchema = preprocess((value) => {
21541
21553
  form: FormElicitationCapabilitySchema.optional(),
21542
21554
  url: AssertObjectSchema.optional()
21543
21555
  }), record(string2(), unknown()).optional()));
21544
- var ClientTasksCapabilitySchema = object2({
21556
+ var ClientTasksCapabilitySchema = looseObject({
21545
21557
  /**
21546
21558
  * Present if the client supports listing tasks.
21547
21559
  */
21548
- list: optional(object2({}).passthrough()),
21560
+ list: AssertObjectSchema.optional(),
21549
21561
  /**
21550
21562
  * Present if the client supports cancelling tasks.
21551
21563
  */
21552
- cancel: optional(object2({}).passthrough()),
21564
+ cancel: AssertObjectSchema.optional(),
21553
21565
  /**
21554
21566
  * Capabilities for task creation on specific request types.
21555
21567
  */
21556
- requests: optional(object2({
21568
+ requests: looseObject({
21557
21569
  /**
21558
21570
  * Task support for sampling requests.
21559
21571
  */
21560
- sampling: optional(object2({
21561
- createMessage: optional(object2({}).passthrough())
21562
- }).passthrough()),
21572
+ sampling: looseObject({
21573
+ createMessage: AssertObjectSchema.optional()
21574
+ }).optional(),
21563
21575
  /**
21564
21576
  * Task support for elicitation requests.
21565
21577
  */
21566
- elicitation: optional(object2({
21567
- create: optional(object2({}).passthrough())
21568
- }).passthrough())
21569
- }).passthrough())
21570
- }).passthrough();
21571
- var ServerTasksCapabilitySchema = object2({
21578
+ elicitation: looseObject({
21579
+ create: AssertObjectSchema.optional()
21580
+ }).optional()
21581
+ }).optional()
21582
+ });
21583
+ var ServerTasksCapabilitySchema = looseObject({
21572
21584
  /**
21573
21585
  * Present if the server supports listing tasks.
21574
21586
  */
21575
- list: optional(object2({}).passthrough()),
21587
+ list: AssertObjectSchema.optional(),
21576
21588
  /**
21577
21589
  * Present if the server supports cancelling tasks.
21578
21590
  */
21579
- cancel: optional(object2({}).passthrough()),
21591
+ cancel: AssertObjectSchema.optional(),
21580
21592
  /**
21581
21593
  * Capabilities for task creation on specific request types.
21582
21594
  */
21583
- requests: optional(object2({
21595
+ requests: looseObject({
21584
21596
  /**
21585
21597
  * Task support for tool requests.
21586
21598
  */
21587
- tools: optional(object2({
21588
- call: optional(object2({}).passthrough())
21589
- }).passthrough())
21590
- }).passthrough())
21591
- }).passthrough();
21599
+ tools: looseObject({
21600
+ call: AssertObjectSchema.optional()
21601
+ }).optional()
21602
+ }).optional()
21603
+ });
21592
21604
  var ClientCapabilitiesSchema = object2({
21593
21605
  /**
21594
21606
  * Experimental, non-standard capabilities that the client supports.
@@ -21624,7 +21636,7 @@ var ClientCapabilitiesSchema = object2({
21624
21636
  /**
21625
21637
  * Present if the client supports task creation.
21626
21638
  */
21627
- tasks: optional(ClientTasksCapabilitySchema)
21639
+ tasks: ClientTasksCapabilitySchema.optional()
21628
21640
  });
21629
21641
  var InitializeRequestParamsSchema = BaseRequestParamsSchema.extend({
21630
21642
  /**
@@ -21654,12 +21666,12 @@ var ServerCapabilitiesSchema = object2({
21654
21666
  /**
21655
21667
  * Present if the server offers any prompt templates.
21656
21668
  */
21657
- prompts: optional(object2({
21669
+ prompts: object2({
21658
21670
  /**
21659
21671
  * Whether this server supports issuing notifications for changes to the prompt list.
21660
21672
  */
21661
- listChanged: optional(boolean2())
21662
- })),
21673
+ listChanged: boolean2().optional()
21674
+ }).optional(),
21663
21675
  /**
21664
21676
  * Present if the server offers any resources to read.
21665
21677
  */
@@ -21685,8 +21697,8 @@ var ServerCapabilitiesSchema = object2({
21685
21697
  /**
21686
21698
  * Present if the server supports task creation.
21687
21699
  */
21688
- tasks: optional(ServerTasksCapabilitySchema)
21689
- }).passthrough();
21700
+ tasks: ServerTasksCapabilitySchema.optional()
21701
+ });
21690
21702
  var InitializeResultSchema = ResultSchema.extend({
21691
21703
  /**
21692
21704
  * The version of the Model Context Protocol that the server wants to use. This may not match the version that the client requested. If the client cannot support this version, it MUST disconnect.
@@ -21702,10 +21714,12 @@ var InitializeResultSchema = ResultSchema.extend({
21702
21714
  instructions: string2().optional()
21703
21715
  });
21704
21716
  var InitializedNotificationSchema = NotificationSchema.extend({
21705
- method: literal("notifications/initialized")
21717
+ method: literal("notifications/initialized"),
21718
+ params: NotificationsParamsSchema.optional()
21706
21719
  });
21707
21720
  var PingRequestSchema = RequestSchema.extend({
21708
- method: literal("ping")
21721
+ method: literal("ping"),
21722
+ params: BaseRequestParamsSchema.optional()
21709
21723
  });
21710
21724
  var ProgressSchema = object2({
21711
21725
  /**
@@ -21748,11 +21762,12 @@ var PaginatedResultSchema = ResultSchema.extend({
21748
21762
  * An opaque token representing the pagination position after the last returned result.
21749
21763
  * If present, there may be more results available.
21750
21764
  */
21751
- nextCursor: optional(CursorSchema)
21765
+ nextCursor: CursorSchema.optional()
21752
21766
  });
21767
+ var TaskStatusSchema = _enum(["working", "input_required", "completed", "failed", "cancelled"]);
21753
21768
  var TaskSchema = object2({
21754
21769
  taskId: string2(),
21755
- status: _enum(["working", "input_required", "completed", "failed", "cancelled"]),
21770
+ status: TaskStatusSchema,
21756
21771
  /**
21757
21772
  * Time in milliseconds to keep task results available after completion.
21758
21773
  * If null, the task has unlimited lifetime until manually cleaned up.
@@ -21793,6 +21808,7 @@ var GetTaskPayloadRequestSchema = RequestSchema.extend({
21793
21808
  taskId: string2()
21794
21809
  })
21795
21810
  });
21811
+ var GetTaskPayloadResultSchema = ResultSchema.loose();
21796
21812
  var ListTasksRequestSchema = PaginatedRequestSchema.extend({
21797
21813
  method: literal("tasks/list")
21798
21814
  });
@@ -21831,7 +21847,7 @@ var Base64Schema = string2().refine((val) => {
21831
21847
  try {
21832
21848
  atob(val);
21833
21849
  return true;
21834
- } catch (_a2) {
21850
+ } catch {
21835
21851
  return false;
21836
21852
  }
21837
21853
  }, { message: "Invalid Base64 string" });
@@ -21841,11 +21857,12 @@ var BlobResourceContentsSchema = ResourceContentsSchema.extend({
21841
21857
  */
21842
21858
  blob: Base64Schema
21843
21859
  });
21860
+ var RoleSchema = _enum(["user", "assistant"]);
21844
21861
  var AnnotationsSchema = object2({
21845
21862
  /**
21846
21863
  * Intended audience(s) for the resource.
21847
21864
  */
21848
- audience: array(_enum(["user", "assistant"])).optional(),
21865
+ audience: array(RoleSchema).optional(),
21849
21866
  /**
21850
21867
  * Importance hint for the resource, from 0 (least) to 1 (most).
21851
21868
  */
@@ -21938,7 +21955,8 @@ var ReadResourceResultSchema = ResultSchema.extend({
21938
21955
  contents: array(union([TextResourceContentsSchema, BlobResourceContentsSchema]))
21939
21956
  });
21940
21957
  var ResourceListChangedNotificationSchema = NotificationSchema.extend({
21941
- method: literal("notifications/resources/list_changed")
21958
+ method: literal("notifications/resources/list_changed"),
21959
+ params: NotificationsParamsSchema.optional()
21942
21960
  });
21943
21961
  var SubscribeRequestParamsSchema = ResourceRequestParamsSchema;
21944
21962
  var SubscribeRequestSchema = RequestSchema.extend({
@@ -22083,13 +22101,13 @@ var ToolUseContentSchema = object2({
22083
22101
  * Arguments to pass to the tool.
22084
22102
  * Must conform to the tool's inputSchema.
22085
22103
  */
22086
- input: object2({}).passthrough(),
22104
+ input: record(string2(), unknown()),
22087
22105
  /**
22088
22106
  * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
22089
22107
  * for notes on _meta usage.
22090
22108
  */
22091
- _meta: optional(object2({}).passthrough())
22092
- }).passthrough();
22109
+ _meta: record(string2(), unknown()).optional()
22110
+ });
22093
22111
  var EmbeddedResourceSchema = object2({
22094
22112
  type: literal("resource"),
22095
22113
  resource: union([TextResourceContentsSchema, BlobResourceContentsSchema]),
@@ -22114,18 +22132,19 @@ var ContentBlockSchema = union([
22114
22132
  EmbeddedResourceSchema
22115
22133
  ]);
22116
22134
  var PromptMessageSchema = object2({
22117
- role: _enum(["user", "assistant"]),
22135
+ role: RoleSchema,
22118
22136
  content: ContentBlockSchema
22119
22137
  });
22120
22138
  var GetPromptResultSchema = ResultSchema.extend({
22121
22139
  /**
22122
22140
  * An optional description for the prompt.
22123
22141
  */
22124
- description: optional(string2()),
22142
+ description: string2().optional(),
22125
22143
  messages: array(PromptMessageSchema)
22126
22144
  });
22127
22145
  var PromptListChangedNotificationSchema = NotificationSchema.extend({
22128
- method: literal("notifications/prompts/list_changed")
22146
+ method: literal("notifications/prompts/list_changed"),
22147
+ params: NotificationsParamsSchema.optional()
22129
22148
  });
22130
22149
  var ToolAnnotationsSchema = object2({
22131
22150
  /**
@@ -22206,11 +22225,11 @@ var ToolSchema = object2({
22206
22225
  /**
22207
22226
  * Optional additional tool information.
22208
22227
  */
22209
- annotations: optional(ToolAnnotationsSchema),
22228
+ annotations: ToolAnnotationsSchema.optional(),
22210
22229
  /**
22211
22230
  * Execution-related properties for this tool.
22212
22231
  */
22213
- execution: optional(ToolExecutionSchema),
22232
+ execution: ToolExecutionSchema.optional(),
22214
22233
  /**
22215
22234
  * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
22216
22235
  * for notes on _meta usage.
@@ -22251,12 +22270,12 @@ var CallToolResultSchema = ResultSchema.extend({
22251
22270
  * server does not support tool calls, or any other exceptional conditions,
22252
22271
  * should be reported as an MCP error response.
22253
22272
  */
22254
- isError: optional(boolean2())
22273
+ isError: boolean2().optional()
22255
22274
  });
22256
22275
  var CompatibilityCallToolResultSchema = CallToolResultSchema.or(ResultSchema.extend({
22257
22276
  toolResult: unknown()
22258
22277
  }));
22259
- var CallToolRequestParamsSchema = BaseRequestParamsSchema.extend({
22278
+ var CallToolRequestParamsSchema = TaskAugmentedRequestParamsSchema.extend({
22260
22279
  /**
22261
22280
  * The name of the tool to call.
22262
22281
  */
@@ -22264,14 +22283,35 @@ var CallToolRequestParamsSchema = BaseRequestParamsSchema.extend({
22264
22283
  /**
22265
22284
  * Arguments to pass to the tool.
22266
22285
  */
22267
- arguments: optional(record(string2(), unknown()))
22286
+ arguments: record(string2(), unknown()).optional()
22268
22287
  });
22269
22288
  var CallToolRequestSchema = RequestSchema.extend({
22270
22289
  method: literal("tools/call"),
22271
22290
  params: CallToolRequestParamsSchema
22272
22291
  });
22273
22292
  var ToolListChangedNotificationSchema = NotificationSchema.extend({
22274
- method: literal("notifications/tools/list_changed")
22293
+ method: literal("notifications/tools/list_changed"),
22294
+ params: NotificationsParamsSchema.optional()
22295
+ });
22296
+ var ListChangedOptionsBaseSchema = object2({
22297
+ /**
22298
+ * If true, the list will be refreshed automatically when a list changed notification is received.
22299
+ * The callback will be called with the updated list.
22300
+ *
22301
+ * If false, the callback will be called with null items, allowing manual refresh.
22302
+ *
22303
+ * @default true
22304
+ */
22305
+ autoRefresh: boolean2().default(true),
22306
+ /**
22307
+ * Debounce time in milliseconds for list changed notification processing.
22308
+ *
22309
+ * Multiple notifications received within this timeframe will only trigger one refresh.
22310
+ * Set to 0 to disable debouncing.
22311
+ *
22312
+ * @default 300
22313
+ */
22314
+ debounceMs: number2().int().nonnegative().default(300)
22275
22315
  });
22276
22316
  var LoggingLevelSchema = _enum(["debug", "info", "notice", "warning", "error", "critical", "alert", "emergency"]);
22277
22317
  var SetLevelRequestParamsSchema = BaseRequestParamsSchema.extend({
@@ -22312,19 +22352,19 @@ var ModelPreferencesSchema = object2({
22312
22352
  /**
22313
22353
  * Optional hints to use for model selection.
22314
22354
  */
22315
- hints: optional(array(ModelHintSchema)),
22355
+ hints: array(ModelHintSchema).optional(),
22316
22356
  /**
22317
22357
  * How much to prioritize cost when selecting a model.
22318
22358
  */
22319
- costPriority: optional(number2().min(0).max(1)),
22359
+ costPriority: number2().min(0).max(1).optional(),
22320
22360
  /**
22321
22361
  * How much to prioritize sampling speed (latency) when selecting a model.
22322
22362
  */
22323
- speedPriority: optional(number2().min(0).max(1)),
22363
+ speedPriority: number2().min(0).max(1).optional(),
22324
22364
  /**
22325
22365
  * How much to prioritize intelligence and capabilities when selecting a model.
22326
22366
  */
22327
- intelligencePriority: optional(number2().min(0).max(1))
22367
+ intelligencePriority: number2().min(0).max(1).optional()
22328
22368
  });
22329
22369
  var ToolChoiceSchema = object2({
22330
22370
  /**
@@ -22333,20 +22373,20 @@ var ToolChoiceSchema = object2({
22333
22373
  * - "required": Model MUST use at least one tool before completing
22334
22374
  * - "none": Model MUST NOT use any tools
22335
22375
  */
22336
- mode: optional(_enum(["auto", "required", "none"]))
22376
+ mode: _enum(["auto", "required", "none"]).optional()
22337
22377
  });
22338
22378
  var ToolResultContentSchema = object2({
22339
22379
  type: literal("tool_result"),
22340
22380
  toolUseId: string2().describe("The unique identifier for the corresponding tool call."),
22341
22381
  content: array(ContentBlockSchema).default([]),
22342
- structuredContent: object2({}).passthrough().optional(),
22343
- isError: optional(boolean2()),
22382
+ structuredContent: object2({}).loose().optional(),
22383
+ isError: boolean2().optional(),
22344
22384
  /**
22345
22385
  * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
22346
22386
  * for notes on _meta usage.
22347
22387
  */
22348
- _meta: optional(object2({}).passthrough())
22349
- }).passthrough();
22388
+ _meta: record(string2(), unknown()).optional()
22389
+ });
22350
22390
  var SamplingContentSchema = discriminatedUnion("type", [TextContentSchema, ImageContentSchema, AudioContentSchema]);
22351
22391
  var SamplingMessageContentBlockSchema = discriminatedUnion("type", [
22352
22392
  TextContentSchema,
@@ -22356,15 +22396,15 @@ var SamplingMessageContentBlockSchema = discriminatedUnion("type", [
22356
22396
  ToolResultContentSchema
22357
22397
  ]);
22358
22398
  var SamplingMessageSchema = object2({
22359
- role: _enum(["user", "assistant"]),
22399
+ role: RoleSchema,
22360
22400
  content: union([SamplingMessageContentBlockSchema, array(SamplingMessageContentBlockSchema)]),
22361
22401
  /**
22362
22402
  * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
22363
22403
  * for notes on _meta usage.
22364
22404
  */
22365
- _meta: optional(object2({}).passthrough())
22366
- }).passthrough();
22367
- var CreateMessageRequestParamsSchema = BaseRequestParamsSchema.extend({
22405
+ _meta: record(string2(), unknown()).optional()
22406
+ });
22407
+ var CreateMessageRequestParamsSchema = TaskAugmentedRequestParamsSchema.extend({
22368
22408
  messages: array(SamplingMessageSchema),
22369
22409
  /**
22370
22410
  * The server's preferences for which model to select. The client MAY modify or omit this request.
@@ -22398,13 +22438,13 @@ var CreateMessageRequestParamsSchema = BaseRequestParamsSchema.extend({
22398
22438
  * Tools that the model may use during generation.
22399
22439
  * The client MUST return an error if this field is provided but ClientCapabilities.sampling.tools is not declared.
22400
22440
  */
22401
- tools: optional(array(ToolSchema)),
22441
+ tools: array(ToolSchema).optional(),
22402
22442
  /**
22403
22443
  * Controls how the model uses tools.
22404
22444
  * The client MUST return an error if this field is provided but ClientCapabilities.sampling.tools is not declared.
22405
22445
  * Default is `{ mode: "auto" }`.
22406
22446
  */
22407
- toolChoice: optional(ToolChoiceSchema)
22447
+ toolChoice: ToolChoiceSchema.optional()
22408
22448
  });
22409
22449
  var CreateMessageRequestSchema = RequestSchema.extend({
22410
22450
  method: literal("sampling/createMessage"),
@@ -22426,7 +22466,7 @@ var CreateMessageResultSchema = ResultSchema.extend({
22426
22466
  * This field is an open string to allow for provider-specific stop reasons.
22427
22467
  */
22428
22468
  stopReason: optional(_enum(["endTurn", "stopSequence", "maxTokens"]).or(string2())),
22429
- role: _enum(["user", "assistant"]),
22469
+ role: RoleSchema,
22430
22470
  /**
22431
22471
  * Response content. Single content block (text, image, or audio).
22432
22472
  */
@@ -22449,7 +22489,7 @@ var CreateMessageResultWithToolsSchema = ResultSchema.extend({
22449
22489
  * This field is an open string to allow for provider-specific stop reasons.
22450
22490
  */
22451
22491
  stopReason: optional(_enum(["endTurn", "stopSequence", "maxTokens", "toolUse"]).or(string2())),
22452
- role: _enum(["user", "assistant"]),
22492
+ role: RoleSchema,
22453
22493
  /**
22454
22494
  * Response content. May be a single block or array. May include ToolUseContent if stopReason is "toolUse".
22455
22495
  */
@@ -22533,7 +22573,7 @@ var TitledMultiSelectEnumSchemaSchema = object2({
22533
22573
  var MultiSelectEnumSchemaSchema = union([UntitledMultiSelectEnumSchemaSchema, TitledMultiSelectEnumSchemaSchema]);
22534
22574
  var EnumSchemaSchema = union([LegacyTitledEnumSchemaSchema, SingleSelectEnumSchemaSchema, MultiSelectEnumSchemaSchema]);
22535
22575
  var PrimitiveSchemaDefinitionSchema = union([EnumSchemaSchema, BooleanSchemaSchema, StringSchemaSchema, NumberSchemaSchema]);
22536
- var ElicitRequestFormParamsSchema = BaseRequestParamsSchema.extend({
22576
+ var ElicitRequestFormParamsSchema = TaskAugmentedRequestParamsSchema.extend({
22537
22577
  /**
22538
22578
  * The elicitation mode.
22539
22579
  *
@@ -22554,7 +22594,7 @@ var ElicitRequestFormParamsSchema = BaseRequestParamsSchema.extend({
22554
22594
  required: array(string2()).optional()
22555
22595
  })
22556
22596
  });
22557
- var ElicitRequestURLParamsSchema = BaseRequestParamsSchema.extend({
22597
+ var ElicitRequestURLParamsSchema = TaskAugmentedRequestParamsSchema.extend({
22558
22598
  /**
22559
22599
  * The elicitation mode.
22560
22600
  */
@@ -22688,13 +22728,15 @@ var RootSchema = object2({
22688
22728
  _meta: record(string2(), unknown()).optional()
22689
22729
  });
22690
22730
  var ListRootsRequestSchema = RequestSchema.extend({
22691
- method: literal("roots/list")
22731
+ method: literal("roots/list"),
22732
+ params: BaseRequestParamsSchema.optional()
22692
22733
  });
22693
22734
  var ListRootsResultSchema = ResultSchema.extend({
22694
22735
  roots: array(RootSchema)
22695
22736
  });
22696
22737
  var RootsListChangedNotificationSchema = NotificationSchema.extend({
22697
- method: literal("notifications/roots/list_changed")
22738
+ method: literal("notifications/roots/list_changed"),
22739
+ params: NotificationsParamsSchema.optional()
22698
22740
  });
22699
22741
  var ClientRequestSchema = union([
22700
22742
  PingRequestSchema,
@@ -22712,7 +22754,8 @@ var ClientRequestSchema = union([
22712
22754
  ListToolsRequestSchema,
22713
22755
  GetTaskRequestSchema,
22714
22756
  GetTaskPayloadRequestSchema,
22715
- ListTasksRequestSchema
22757
+ ListTasksRequestSchema,
22758
+ CancelTaskRequestSchema
22716
22759
  ]);
22717
22760
  var ClientNotificationSchema = union([
22718
22761
  CancelledNotificationSchema,
@@ -22738,7 +22781,8 @@ var ServerRequestSchema = union([
22738
22781
  ListRootsRequestSchema,
22739
22782
  GetTaskRequestSchema,
22740
22783
  GetTaskPayloadRequestSchema,
22741
- ListTasksRequestSchema
22784
+ ListTasksRequestSchema,
22785
+ CancelTaskRequestSchema
22742
22786
  ]);
22743
22787
  var ServerNotificationSchema = union([
22744
22788
  CancelledNotificationSchema,
@@ -22793,8 +22837,7 @@ var UrlElicitationRequiredError = class extends McpError {
22793
22837
  });
22794
22838
  }
22795
22839
  get elicitations() {
22796
- var _a2, _b2;
22797
- return (_b2 = (_a2 = this.data) === null || _a2 === void 0 ? void 0 : _a2.elicitations) !== null && _b2 !== void 0 ? _b2 : [];
22840
+ return this.data?.elicitations ?? [];
22798
22841
  }
22799
22842
  };
22800
22843
 
@@ -24098,21 +24141,20 @@ function mapMiniTarget(t) {
24098
24141
  return "draft-7";
24099
24142
  }
24100
24143
  function toJsonSchemaCompat(schema, opts) {
24101
- var _a2, _b2, _c2;
24102
24144
  if (isZ4Schema(schema)) {
24103
24145
  return toJSONSchema(schema, {
24104
- target: mapMiniTarget(opts === null || opts === void 0 ? void 0 : opts.target),
24105
- io: (_a2 = opts === null || opts === void 0 ? void 0 : opts.pipeStrategy) !== null && _a2 !== void 0 ? _a2 : "input"
24146
+ target: mapMiniTarget(opts?.target),
24147
+ io: opts?.pipeStrategy ?? "input"
24106
24148
  });
24107
24149
  }
24108
24150
  return zodToJsonSchema(schema, {
24109
- strictUnions: (_b2 = opts === null || opts === void 0 ? void 0 : opts.strictUnions) !== null && _b2 !== void 0 ? _b2 : true,
24110
- pipeStrategy: (_c2 = opts === null || opts === void 0 ? void 0 : opts.pipeStrategy) !== null && _c2 !== void 0 ? _c2 : "input"
24151
+ strictUnions: opts?.strictUnions ?? true,
24152
+ pipeStrategy: opts?.pipeStrategy ?? "input"
24111
24153
  });
24112
24154
  }
24113
24155
  function getMethodLiteral(schema) {
24114
24156
  const shape = getObjectShape(schema);
24115
- const methodSchema = shape === null || shape === void 0 ? void 0 : shape.method;
24157
+ const methodSchema = shape?.method;
24116
24158
  if (!methodSchema) {
24117
24159
  throw new Error("Schema is missing a method literal");
24118
24160
  }
@@ -24156,8 +24198,8 @@ var Protocol = class {
24156
24198
  // Automatic pong by default.
24157
24199
  (_request) => ({})
24158
24200
  );
24159
- this._taskStore = _options === null || _options === void 0 ? void 0 : _options.taskStore;
24160
- this._taskMessageQueue = _options === null || _options === void 0 ? void 0 : _options.taskMessageQueue;
24201
+ this._taskStore = _options?.taskStore;
24202
+ this._taskMessageQueue = _options?.taskMessageQueue;
24161
24203
  if (this._taskStore) {
24162
24204
  this.setRequestHandler(GetTaskRequestSchema, async (request, extra) => {
24163
24205
  const task = await this._taskStore.getTask(request.params.taskId, extra.sessionId);
@@ -24170,7 +24212,6 @@ var Protocol = class {
24170
24212
  });
24171
24213
  this.setRequestHandler(GetTaskPayloadRequestSchema, async (request, extra) => {
24172
24214
  const handleTaskResult = async () => {
24173
- var _a2;
24174
24215
  const taskId = request.params.taskId;
24175
24216
  if (this._taskMessageQueue) {
24176
24217
  let queuedMessage;
@@ -24194,7 +24235,7 @@ var Protocol = class {
24194
24235
  }
24195
24236
  continue;
24196
24237
  }
24197
- await ((_a2 = this._transport) === null || _a2 === void 0 ? void 0 : _a2.send(queuedMessage.message, { relatedRequestId: extra.requestId }));
24238
+ await this._transport?.send(queuedMessage.message, { relatedRequestId: extra.requestId });
24198
24239
  }
24199
24240
  }
24200
24241
  const task = await this._taskStore.getTask(taskId, extra.sessionId);
@@ -24223,9 +24264,8 @@ var Protocol = class {
24223
24264
  return await handleTaskResult();
24224
24265
  });
24225
24266
  this.setRequestHandler(ListTasksRequestSchema, async (request, extra) => {
24226
- var _a2;
24227
24267
  try {
24228
- const { tasks, nextCursor } = await this._taskStore.listTasks((_a2 = request.params) === null || _a2 === void 0 ? void 0 : _a2.cursor, extra.sessionId);
24268
+ const { tasks, nextCursor } = await this._taskStore.listTasks(request.params?.cursor, extra.sessionId);
24229
24269
  return {
24230
24270
  tasks,
24231
24271
  nextCursor,
@@ -24264,8 +24304,11 @@ var Protocol = class {
24264
24304
  }
24265
24305
  }
24266
24306
  async _oncancel(notification) {
24307
+ if (!notification.params.requestId) {
24308
+ return;
24309
+ }
24267
24310
  const controller = this._requestHandlerAbortControllers.get(notification.params.requestId);
24268
- controller === null || controller === void 0 ? void 0 : controller.abort(notification.params.reason);
24311
+ controller?.abort(notification.params.reason);
24269
24312
  }
24270
24313
  _setupTimeout(messageId, timeout, maxTotalTimeout, onTimeout, resetTimeoutOnProgress = false) {
24271
24314
  this._timeoutInfo.set(messageId, {
@@ -24306,22 +24349,24 @@ var Protocol = class {
24306
24349
  * 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.
24307
24350
  */
24308
24351
  async connect(transport) {
24309
- var _a2, _b2, _c2;
24352
+ if (this._transport) {
24353
+ throw new Error("Already connected to a transport. Call close() before connecting to a new transport, or use a separate Protocol instance per connection.");
24354
+ }
24310
24355
  this._transport = transport;
24311
- const _onclose = (_a2 = this.transport) === null || _a2 === void 0 ? void 0 : _a2.onclose;
24356
+ const _onclose = this.transport?.onclose;
24312
24357
  this._transport.onclose = () => {
24313
- _onclose === null || _onclose === void 0 ? void 0 : _onclose();
24358
+ _onclose?.();
24314
24359
  this._onclose();
24315
24360
  };
24316
- const _onerror = (_b2 = this.transport) === null || _b2 === void 0 ? void 0 : _b2.onerror;
24361
+ const _onerror = this.transport?.onerror;
24317
24362
  this._transport.onerror = (error2) => {
24318
- _onerror === null || _onerror === void 0 ? void 0 : _onerror(error2);
24363
+ _onerror?.(error2);
24319
24364
  this._onerror(error2);
24320
24365
  };
24321
- const _onmessage = (_c2 = this._transport) === null || _c2 === void 0 ? void 0 : _c2.onmessage;
24366
+ const _onmessage = this._transport?.onmessage;
24322
24367
  this._transport.onmessage = (message, extra) => {
24323
- _onmessage === null || _onmessage === void 0 ? void 0 : _onmessage(message, extra);
24324
- if (isJSONRPCResponse(message) || isJSONRPCError(message)) {
24368
+ _onmessage?.(message, extra);
24369
+ if (isJSONRPCResultResponse(message) || isJSONRPCErrorResponse(message)) {
24325
24370
  this._onresponse(message);
24326
24371
  } else if (isJSONRPCRequest(message)) {
24327
24372
  this._onrequest(message, extra);
@@ -24334,36 +24379,36 @@ var Protocol = class {
24334
24379
  await this._transport.start();
24335
24380
  }
24336
24381
  _onclose() {
24337
- var _a2;
24338
24382
  const responseHandlers = this._responseHandlers;
24339
24383
  this._responseHandlers = /* @__PURE__ */ new Map();
24340
24384
  this._progressHandlers.clear();
24341
24385
  this._taskProgressTokens.clear();
24342
24386
  this._pendingDebouncedNotifications.clear();
24387
+ for (const controller of this._requestHandlerAbortControllers.values()) {
24388
+ controller.abort();
24389
+ }
24390
+ this._requestHandlerAbortControllers.clear();
24343
24391
  const error2 = McpError.fromError(ErrorCode.ConnectionClosed, "Connection closed");
24344
24392
  this._transport = void 0;
24345
- (_a2 = this.onclose) === null || _a2 === void 0 ? void 0 : _a2.call(this);
24393
+ this.onclose?.();
24346
24394
  for (const handler of responseHandlers.values()) {
24347
24395
  handler(error2);
24348
24396
  }
24349
24397
  }
24350
24398
  _onerror(error2) {
24351
- var _a2;
24352
- (_a2 = this.onerror) === null || _a2 === void 0 ? void 0 : _a2.call(this, error2);
24399
+ this.onerror?.(error2);
24353
24400
  }
24354
24401
  _onnotification(notification) {
24355
- var _a2;
24356
- const handler = (_a2 = this._notificationHandlers.get(notification.method)) !== null && _a2 !== void 0 ? _a2 : this.fallbackNotificationHandler;
24402
+ const handler = this._notificationHandlers.get(notification.method) ?? this.fallbackNotificationHandler;
24357
24403
  if (handler === void 0) {
24358
24404
  return;
24359
24405
  }
24360
24406
  Promise.resolve().then(() => handler(notification)).catch((error2) => this._onerror(new Error(`Uncaught error in notification handler: ${error2}`)));
24361
24407
  }
24362
24408
  _onrequest(request, extra) {
24363
- var _a2, _b2, _c2, _d, _e, _f;
24364
- const handler = (_a2 = this._requestHandlers.get(request.method)) !== null && _a2 !== void 0 ? _a2 : this.fallbackRequestHandler;
24409
+ const handler = this._requestHandlers.get(request.method) ?? this.fallbackRequestHandler;
24365
24410
  const capturedTransport = this._transport;
24366
- const relatedTaskId = (_d = (_c2 = (_b2 = request.params) === null || _b2 === void 0 ? void 0 : _b2._meta) === null || _c2 === void 0 ? void 0 : _c2[RELATED_TASK_META_KEY]) === null || _d === void 0 ? void 0 : _d.taskId;
24411
+ const relatedTaskId = request.params?._meta?.[RELATED_TASK_META_KEY]?.taskId;
24367
24412
  if (handler === void 0) {
24368
24413
  const errorResponse = {
24369
24414
  jsonrpc: "2.0",
@@ -24378,21 +24423,23 @@ var Protocol = class {
24378
24423
  type: "error",
24379
24424
  message: errorResponse,
24380
24425
  timestamp: Date.now()
24381
- }, capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.sessionId).catch((error2) => this._onerror(new Error(`Failed to enqueue error response: ${error2}`)));
24426
+ }, capturedTransport?.sessionId).catch((error2) => this._onerror(new Error(`Failed to enqueue error response: ${error2}`)));
24382
24427
  } else {
24383
- capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.send(errorResponse).catch((error2) => this._onerror(new Error(`Failed to send an error response: ${error2}`)));
24428
+ capturedTransport?.send(errorResponse).catch((error2) => this._onerror(new Error(`Failed to send an error response: ${error2}`)));
24384
24429
  }
24385
24430
  return;
24386
24431
  }
24387
24432
  const abortController = new AbortController();
24388
24433
  this._requestHandlerAbortControllers.set(request.id, abortController);
24389
- const taskCreationParams = (_e = request.params) === null || _e === void 0 ? void 0 : _e.task;
24390
- const taskStore = this._taskStore ? this.requestTaskStore(request, capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.sessionId) : void 0;
24434
+ const taskCreationParams = isTaskAugmentedRequestParams(request.params) ? request.params.task : void 0;
24435
+ const taskStore = this._taskStore ? this.requestTaskStore(request, capturedTransport?.sessionId) : void 0;
24391
24436
  const fullExtra = {
24392
24437
  signal: abortController.signal,
24393
- sessionId: capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.sessionId,
24394
- _meta: (_f = request.params) === null || _f === void 0 ? void 0 : _f._meta,
24438
+ sessionId: capturedTransport?.sessionId,
24439
+ _meta: request.params?._meta,
24395
24440
  sendNotification: async (notification) => {
24441
+ if (abortController.signal.aborted)
24442
+ return;
24396
24443
  const notificationOptions = { relatedRequestId: request.id };
24397
24444
  if (relatedTaskId) {
24398
24445
  notificationOptions.relatedTask = { taskId: relatedTaskId };
@@ -24400,25 +24447,27 @@ var Protocol = class {
24400
24447
  await this.notification(notification, notificationOptions);
24401
24448
  },
24402
24449
  sendRequest: async (r, resultSchema, options) => {
24403
- var _a3, _b3;
24450
+ if (abortController.signal.aborted) {
24451
+ throw new McpError(ErrorCode.ConnectionClosed, "Request was cancelled");
24452
+ }
24404
24453
  const requestOptions = { ...options, relatedRequestId: request.id };
24405
24454
  if (relatedTaskId && !requestOptions.relatedTask) {
24406
24455
  requestOptions.relatedTask = { taskId: relatedTaskId };
24407
24456
  }
24408
- const effectiveTaskId = (_b3 = (_a3 = requestOptions.relatedTask) === null || _a3 === void 0 ? void 0 : _a3.taskId) !== null && _b3 !== void 0 ? _b3 : relatedTaskId;
24457
+ const effectiveTaskId = requestOptions.relatedTask?.taskId ?? relatedTaskId;
24409
24458
  if (effectiveTaskId && taskStore) {
24410
24459
  await taskStore.updateTaskStatus(effectiveTaskId, "input_required");
24411
24460
  }
24412
24461
  return await this.request(r, resultSchema, requestOptions);
24413
24462
  },
24414
- authInfo: extra === null || extra === void 0 ? void 0 : extra.authInfo,
24463
+ authInfo: extra?.authInfo,
24415
24464
  requestId: request.id,
24416
- requestInfo: extra === null || extra === void 0 ? void 0 : extra.requestInfo,
24465
+ requestInfo: extra?.requestInfo,
24417
24466
  taskId: relatedTaskId,
24418
24467
  taskStore,
24419
- taskRequestedTtl: taskCreationParams === null || taskCreationParams === void 0 ? void 0 : taskCreationParams.ttl,
24420
- closeSSEStream: extra === null || extra === void 0 ? void 0 : extra.closeSSEStream,
24421
- closeStandaloneSSEStream: extra === null || extra === void 0 ? void 0 : extra.closeStandaloneSSEStream
24468
+ taskRequestedTtl: taskCreationParams?.ttl,
24469
+ closeSSEStream: extra?.closeSSEStream,
24470
+ closeStandaloneSSEStream: extra?.closeStandaloneSSEStream
24422
24471
  };
24423
24472
  Promise.resolve().then(() => {
24424
24473
  if (taskCreationParams) {
@@ -24438,12 +24487,11 @@ var Protocol = class {
24438
24487
  type: "response",
24439
24488
  message: response,
24440
24489
  timestamp: Date.now()
24441
- }, capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.sessionId);
24490
+ }, capturedTransport?.sessionId);
24442
24491
  } else {
24443
- await (capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.send(response));
24492
+ await capturedTransport?.send(response);
24444
24493
  }
24445
24494
  }, async (error2) => {
24446
- var _a3;
24447
24495
  if (abortController.signal.aborted) {
24448
24496
  return;
24449
24497
  }
@@ -24452,7 +24500,7 @@ var Protocol = class {
24452
24500
  id: request.id,
24453
24501
  error: {
24454
24502
  code: Number.isSafeInteger(error2["code"]) ? error2["code"] : ErrorCode.InternalError,
24455
- message: (_a3 = error2.message) !== null && _a3 !== void 0 ? _a3 : "Internal error",
24503
+ message: error2.message ?? "Internal error",
24456
24504
  ...error2["data"] !== void 0 && { data: error2["data"] }
24457
24505
  }
24458
24506
  };
@@ -24461,9 +24509,9 @@ var Protocol = class {
24461
24509
  type: "error",
24462
24510
  message: errorResponse,
24463
24511
  timestamp: Date.now()
24464
- }, capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.sessionId);
24512
+ }, capturedTransport?.sessionId);
24465
24513
  } else {
24466
- await (capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.send(errorResponse));
24514
+ await capturedTransport?.send(errorResponse);
24467
24515
  }
24468
24516
  }).catch((error2) => this._onerror(new Error(`Failed to send response: ${error2}`))).finally(() => {
24469
24517
  this._requestHandlerAbortControllers.delete(request.id);
@@ -24497,7 +24545,7 @@ var Protocol = class {
24497
24545
  const resolver = this._requestResolvers.get(messageId);
24498
24546
  if (resolver) {
24499
24547
  this._requestResolvers.delete(messageId);
24500
- if (isJSONRPCResponse(response)) {
24548
+ if (isJSONRPCResultResponse(response)) {
24501
24549
  resolver(response);
24502
24550
  } else {
24503
24551
  const error2 = new McpError(response.error.code, response.error.message, response.error.data);
@@ -24513,7 +24561,7 @@ var Protocol = class {
24513
24561
  this._responseHandlers.delete(messageId);
24514
24562
  this._cleanupTimeout(messageId);
24515
24563
  let isTaskResponse = false;
24516
- if (isJSONRPCResponse(response) && response.result && typeof response.result === "object") {
24564
+ if (isJSONRPCResultResponse(response) && response.result && typeof response.result === "object") {
24517
24565
  const result = response.result;
24518
24566
  if (result.task && typeof result.task === "object") {
24519
24567
  const task = result.task;
@@ -24526,7 +24574,7 @@ var Protocol = class {
24526
24574
  if (!isTaskResponse) {
24527
24575
  this._progressHandlers.delete(messageId);
24528
24576
  }
24529
- if (isJSONRPCResponse(response)) {
24577
+ if (isJSONRPCResultResponse(response)) {
24530
24578
  handler(response);
24531
24579
  } else {
24532
24580
  const error2 = McpError.fromError(response.error.code, response.error.message, response.error.data);
@@ -24540,8 +24588,7 @@ var Protocol = class {
24540
24588
  * Closes the connection.
24541
24589
  */
24542
24590
  async close() {
24543
- var _a2;
24544
- await ((_a2 = this._transport) === null || _a2 === void 0 ? void 0 : _a2.close());
24591
+ await this._transport?.close();
24545
24592
  }
24546
24593
  /**
24547
24594
  * Sends a request and returns an AsyncGenerator that yields response messages.
@@ -24571,8 +24618,7 @@ var Protocol = class {
24571
24618
  * @experimental Use `client.experimental.tasks.requestStream()` to access this method.
24572
24619
  */
24573
24620
  async *requestStream(request, resultSchema, options) {
24574
- var _a2, _b2, _c2, _d;
24575
- const { task } = options !== null && options !== void 0 ? options : {};
24621
+ const { task } = options ?? {};
24576
24622
  if (!task) {
24577
24623
  try {
24578
24624
  const result = await this.request(request, resultSchema, options);
@@ -24619,9 +24665,9 @@ var Protocol = class {
24619
24665
  yield { type: "result", result };
24620
24666
  return;
24621
24667
  }
24622
- const pollInterval = (_c2 = (_a2 = task2.pollInterval) !== null && _a2 !== void 0 ? _a2 : (_b2 = this._options) === null || _b2 === void 0 ? void 0 : _b2.defaultTaskPollInterval) !== null && _c2 !== void 0 ? _c2 : 1e3;
24668
+ const pollInterval = task2.pollInterval ?? this._options?.defaultTaskPollInterval ?? 1e3;
24623
24669
  await new Promise((resolve5) => setTimeout(resolve5, pollInterval));
24624
- (_d = options === null || options === void 0 ? void 0 : options.signal) === null || _d === void 0 ? void 0 : _d.throwIfAborted();
24670
+ options?.signal?.throwIfAborted();
24625
24671
  }
24626
24672
  } catch (error2) {
24627
24673
  yield {
@@ -24636,9 +24682,8 @@ var Protocol = class {
24636
24682
  * Do not use this method to emit notifications! Use notification() instead.
24637
24683
  */
24638
24684
  request(request, resultSchema, options) {
24639
- const { relatedRequestId, resumptionToken, onresumptiontoken, task, relatedTask } = options !== null && options !== void 0 ? options : {};
24685
+ const { relatedRequestId, resumptionToken, onresumptiontoken, task, relatedTask } = options ?? {};
24640
24686
  return new Promise((resolve5, reject) => {
24641
- var _a2, _b2, _c2, _d, _e, _f, _g;
24642
24687
  const earlyReject = (error2) => {
24643
24688
  reject(error2);
24644
24689
  };
@@ -24646,7 +24691,7 @@ var Protocol = class {
24646
24691
  earlyReject(new Error("Not connected"));
24647
24692
  return;
24648
24693
  }
24649
- if (((_a2 = this._options) === null || _a2 === void 0 ? void 0 : _a2.enforceStrictCapabilities) === true) {
24694
+ if (this._options?.enforceStrictCapabilities === true) {
24650
24695
  try {
24651
24696
  this.assertCapabilityForMethod(request.method);
24652
24697
  if (task) {
@@ -24657,19 +24702,19 @@ var Protocol = class {
24657
24702
  return;
24658
24703
  }
24659
24704
  }
24660
- (_b2 = options === null || options === void 0 ? void 0 : options.signal) === null || _b2 === void 0 ? void 0 : _b2.throwIfAborted();
24705
+ options?.signal?.throwIfAborted();
24661
24706
  const messageId = this._requestMessageId++;
24662
24707
  const jsonrpcRequest = {
24663
24708
  ...request,
24664
24709
  jsonrpc: "2.0",
24665
24710
  id: messageId
24666
24711
  };
24667
- if (options === null || options === void 0 ? void 0 : options.onprogress) {
24712
+ if (options?.onprogress) {
24668
24713
  this._progressHandlers.set(messageId, options.onprogress);
24669
24714
  jsonrpcRequest.params = {
24670
24715
  ...request.params,
24671
24716
  _meta: {
24672
- ...((_c2 = request.params) === null || _c2 === void 0 ? void 0 : _c2._meta) || {},
24717
+ ...request.params?._meta || {},
24673
24718
  progressToken: messageId
24674
24719
  }
24675
24720
  };
@@ -24684,17 +24729,16 @@ var Protocol = class {
24684
24729
  jsonrpcRequest.params = {
24685
24730
  ...jsonrpcRequest.params,
24686
24731
  _meta: {
24687
- ...((_d = jsonrpcRequest.params) === null || _d === void 0 ? void 0 : _d._meta) || {},
24732
+ ...jsonrpcRequest.params?._meta || {},
24688
24733
  [RELATED_TASK_META_KEY]: relatedTask
24689
24734
  }
24690
24735
  };
24691
24736
  }
24692
24737
  const cancel = (reason) => {
24693
- var _a3;
24694
24738
  this._responseHandlers.delete(messageId);
24695
24739
  this._progressHandlers.delete(messageId);
24696
24740
  this._cleanupTimeout(messageId);
24697
- (_a3 = this._transport) === null || _a3 === void 0 ? void 0 : _a3.send({
24741
+ this._transport?.send({
24698
24742
  jsonrpc: "2.0",
24699
24743
  method: "notifications/cancelled",
24700
24744
  params: {
@@ -24706,8 +24750,7 @@ var Protocol = class {
24706
24750
  reject(error2);
24707
24751
  };
24708
24752
  this._responseHandlers.set(messageId, (response) => {
24709
- var _a3;
24710
- if ((_a3 = options === null || options === void 0 ? void 0 : options.signal) === null || _a3 === void 0 ? void 0 : _a3.aborted) {
24753
+ if (options?.signal?.aborted) {
24711
24754
  return;
24712
24755
  }
24713
24756
  if (response instanceof Error) {
@@ -24724,14 +24767,13 @@ var Protocol = class {
24724
24767
  reject(error2);
24725
24768
  }
24726
24769
  });
24727
- (_e = options === null || options === void 0 ? void 0 : options.signal) === null || _e === void 0 ? void 0 : _e.addEventListener("abort", () => {
24728
- var _a3;
24729
- cancel((_a3 = options === null || options === void 0 ? void 0 : options.signal) === null || _a3 === void 0 ? void 0 : _a3.reason);
24770
+ options?.signal?.addEventListener("abort", () => {
24771
+ cancel(options?.signal?.reason);
24730
24772
  });
24731
- const timeout = (_f = options === null || options === void 0 ? void 0 : options.timeout) !== null && _f !== void 0 ? _f : DEFAULT_REQUEST_TIMEOUT_MSEC;
24773
+ const timeout = options?.timeout ?? DEFAULT_REQUEST_TIMEOUT_MSEC;
24732
24774
  const timeoutHandler = () => cancel(McpError.fromError(ErrorCode.RequestTimeout, "Request timed out", { timeout }));
24733
- this._setupTimeout(messageId, timeout, options === null || options === void 0 ? void 0 : options.maxTotalTimeout, timeoutHandler, (_g = options === null || options === void 0 ? void 0 : options.resetTimeoutOnProgress) !== null && _g !== void 0 ? _g : false);
24734
- const relatedTaskId = relatedTask === null || relatedTask === void 0 ? void 0 : relatedTask.taskId;
24775
+ this._setupTimeout(messageId, timeout, options?.maxTotalTimeout, timeoutHandler, options?.resetTimeoutOnProgress ?? false);
24776
+ const relatedTaskId = relatedTask?.taskId;
24735
24777
  if (relatedTaskId) {
24736
24778
  const responseResolver = (response) => {
24737
24779
  const handler = this._responseHandlers.get(messageId);
@@ -24794,12 +24836,11 @@ var Protocol = class {
24794
24836
  * Emits a notification, which is a one-way message that does not expect a response.
24795
24837
  */
24796
24838
  async notification(notification, options) {
24797
- var _a2, _b2, _c2, _d, _e;
24798
24839
  if (!this._transport) {
24799
24840
  throw new Error("Not connected");
24800
24841
  }
24801
24842
  this.assertNotificationCapability(notification.method);
24802
- const relatedTaskId = (_a2 = options === null || options === void 0 ? void 0 : options.relatedTask) === null || _a2 === void 0 ? void 0 : _a2.taskId;
24843
+ const relatedTaskId = options?.relatedTask?.taskId;
24803
24844
  if (relatedTaskId) {
24804
24845
  const jsonrpcNotification2 = {
24805
24846
  ...notification,
@@ -24807,7 +24848,7 @@ var Protocol = class {
24807
24848
  params: {
24808
24849
  ...notification.params,
24809
24850
  _meta: {
24810
- ...((_b2 = notification.params) === null || _b2 === void 0 ? void 0 : _b2._meta) || {},
24851
+ ...notification.params?._meta || {},
24811
24852
  [RELATED_TASK_META_KEY]: options.relatedTask
24812
24853
  }
24813
24854
  }
@@ -24819,15 +24860,14 @@ var Protocol = class {
24819
24860
  });
24820
24861
  return;
24821
24862
  }
24822
- const debouncedMethods = (_d = (_c2 = this._options) === null || _c2 === void 0 ? void 0 : _c2.debouncedNotificationMethods) !== null && _d !== void 0 ? _d : [];
24823
- const canDebounce = debouncedMethods.includes(notification.method) && !notification.params && !(options === null || options === void 0 ? void 0 : options.relatedRequestId) && !(options === null || options === void 0 ? void 0 : options.relatedTask);
24863
+ const debouncedMethods = this._options?.debouncedNotificationMethods ?? [];
24864
+ const canDebounce = debouncedMethods.includes(notification.method) && !notification.params && !options?.relatedRequestId && !options?.relatedTask;
24824
24865
  if (canDebounce) {
24825
24866
  if (this._pendingDebouncedNotifications.has(notification.method)) {
24826
24867
  return;
24827
24868
  }
24828
24869
  this._pendingDebouncedNotifications.add(notification.method);
24829
24870
  Promise.resolve().then(() => {
24830
- var _a3, _b3;
24831
24871
  this._pendingDebouncedNotifications.delete(notification.method);
24832
24872
  if (!this._transport) {
24833
24873
  return;
@@ -24836,19 +24876,19 @@ var Protocol = class {
24836
24876
  ...notification,
24837
24877
  jsonrpc: "2.0"
24838
24878
  };
24839
- if (options === null || options === void 0 ? void 0 : options.relatedTask) {
24879
+ if (options?.relatedTask) {
24840
24880
  jsonrpcNotification2 = {
24841
24881
  ...jsonrpcNotification2,
24842
24882
  params: {
24843
24883
  ...jsonrpcNotification2.params,
24844
24884
  _meta: {
24845
- ...((_a3 = jsonrpcNotification2.params) === null || _a3 === void 0 ? void 0 : _a3._meta) || {},
24885
+ ...jsonrpcNotification2.params?._meta || {},
24846
24886
  [RELATED_TASK_META_KEY]: options.relatedTask
24847
24887
  }
24848
24888
  }
24849
24889
  };
24850
24890
  }
24851
- (_b3 = this._transport) === null || _b3 === void 0 ? void 0 : _b3.send(jsonrpcNotification2, options).catch((error2) => this._onerror(error2));
24891
+ this._transport?.send(jsonrpcNotification2, options).catch((error2) => this._onerror(error2));
24852
24892
  });
24853
24893
  return;
24854
24894
  }
@@ -24856,13 +24896,13 @@ var Protocol = class {
24856
24896
  ...notification,
24857
24897
  jsonrpc: "2.0"
24858
24898
  };
24859
- if (options === null || options === void 0 ? void 0 : options.relatedTask) {
24899
+ if (options?.relatedTask) {
24860
24900
  jsonrpcNotification = {
24861
24901
  ...jsonrpcNotification,
24862
24902
  params: {
24863
24903
  ...jsonrpcNotification.params,
24864
24904
  _meta: {
24865
- ...((_e = jsonrpcNotification.params) === null || _e === void 0 ? void 0 : _e._meta) || {},
24905
+ ...jsonrpcNotification.params?._meta || {},
24866
24906
  [RELATED_TASK_META_KEY]: options.relatedTask
24867
24907
  }
24868
24908
  }
@@ -24938,11 +24978,10 @@ var Protocol = class {
24938
24978
  * simply propagates the error.
24939
24979
  */
24940
24980
  async _enqueueTaskMessage(taskId, message, sessionId) {
24941
- var _a2;
24942
24981
  if (!this._taskStore || !this._taskMessageQueue) {
24943
24982
  throw new Error("Cannot enqueue task message: taskStore and taskMessageQueue are not configured");
24944
24983
  }
24945
- const maxQueueSize = (_a2 = this._options) === null || _a2 === void 0 ? void 0 : _a2.maxTaskQueueSize;
24984
+ const maxQueueSize = this._options?.maxTaskQueueSize;
24946
24985
  await this._taskMessageQueue.enqueue(taskId, message, sessionId, maxQueueSize);
24947
24986
  }
24948
24987
  /**
@@ -24975,14 +25014,13 @@ var Protocol = class {
24975
25014
  * @returns Promise that resolves when an update occurs or rejects if aborted
24976
25015
  */
24977
25016
  async _waitForTaskUpdate(taskId, signal) {
24978
- var _a2, _b2, _c2;
24979
- let interval = (_b2 = (_a2 = this._options) === null || _a2 === void 0 ? void 0 : _a2.defaultTaskPollInterval) !== null && _b2 !== void 0 ? _b2 : 1e3;
25017
+ let interval = this._options?.defaultTaskPollInterval ?? 1e3;
24980
25018
  try {
24981
- const task = await ((_c2 = this._taskStore) === null || _c2 === void 0 ? void 0 : _c2.getTask(taskId));
24982
- if (task === null || task === void 0 ? void 0 : task.pollInterval) {
25019
+ const task = await this._taskStore?.getTask(taskId);
25020
+ if (task?.pollInterval) {
24983
25021
  interval = task.pollInterval;
24984
25022
  }
24985
- } catch (_d) {
25023
+ } catch {
24986
25024
  }
24987
25025
  return new Promise((resolve5, reject) => {
24988
25026
  if (signal.aborted) {
@@ -25086,7 +25124,7 @@ function mergeCapabilities(base, additional) {
25086
25124
  var import_ajv = __toESM(require_ajv(), 1);
25087
25125
  var import_ajv_formats = __toESM(require_dist(), 1);
25088
25126
  function createDefaultAjvInstance() {
25089
- const ajv = new import_ajv.Ajv({
25127
+ const ajv = new import_ajv.default({
25090
25128
  strict: false,
25091
25129
  validateFormats: true,
25092
25130
  validateSchema: false,
@@ -25118,7 +25156,7 @@ var AjvJsonSchemaValidator = class {
25118
25156
  * ```
25119
25157
  */
25120
25158
  constructor(ajv) {
25121
- this._ajv = ajv !== null && ajv !== void 0 ? ajv : createDefaultAjvInstance();
25159
+ this._ajv = ajv ?? createDefaultAjvInstance();
25122
25160
  }
25123
25161
  /**
25124
25162
  * Create a validator for the given JSON Schema
@@ -25130,8 +25168,7 @@ var AjvJsonSchemaValidator = class {
25130
25168
  * @returns A validator function that validates input data
25131
25169
  */
25132
25170
  getValidator(schema) {
25133
- var _a2;
25134
- const ajvValidator = "$id" in schema && typeof schema.$id === "string" ? (_a2 = this._ajv.getSchema(schema.$id)) !== null && _a2 !== void 0 ? _a2 : this._ajv.compile(schema) : this._ajv.compile(schema);
25171
+ const ajvValidator = "$id" in schema && typeof schema.$id === "string" ? this._ajv.getSchema(schema.$id) ?? this._ajv.compile(schema) : this._ajv.compile(schema);
25135
25172
  return (input) => {
25136
25173
  const valid = ajvValidator(input);
25137
25174
  if (valid) {
@@ -25225,13 +25262,12 @@ var ExperimentalServerTasks = class {
25225
25262
 
25226
25263
  // ../../node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/helpers.js
25227
25264
  function assertToolsCallTaskCapability(requests, method, entityName) {
25228
- var _a2;
25229
25265
  if (!requests) {
25230
25266
  throw new Error(`${entityName} does not support task creation (required for ${method})`);
25231
25267
  }
25232
25268
  switch (method) {
25233
25269
  case "tools/call":
25234
- if (!((_a2 = requests.tools) === null || _a2 === void 0 ? void 0 : _a2.call)) {
25270
+ if (!requests.tools?.call) {
25235
25271
  throw new Error(`${entityName} does not support task creation for tools/call (required for ${method})`);
25236
25272
  }
25237
25273
  break;
@@ -25240,18 +25276,17 @@ function assertToolsCallTaskCapability(requests, method, entityName) {
25240
25276
  }
25241
25277
  }
25242
25278
  function assertClientRequestTaskCapability(requests, method, entityName) {
25243
- var _a2, _b2;
25244
25279
  if (!requests) {
25245
25280
  throw new Error(`${entityName} does not support task creation (required for ${method})`);
25246
25281
  }
25247
25282
  switch (method) {
25248
25283
  case "sampling/createMessage":
25249
- if (!((_a2 = requests.sampling) === null || _a2 === void 0 ? void 0 : _a2.createMessage)) {
25284
+ if (!requests.sampling?.createMessage) {
25250
25285
  throw new Error(`${entityName} does not support task creation for sampling/createMessage (required for ${method})`);
25251
25286
  }
25252
25287
  break;
25253
25288
  case "elicitation/create":
25254
- if (!((_b2 = requests.elicitation) === null || _b2 === void 0 ? void 0 : _b2.create)) {
25289
+ if (!requests.elicitation?.create) {
25255
25290
  throw new Error(`${entityName} does not support task creation for elicitation/create (required for ${method})`);
25256
25291
  }
25257
25292
  break;
@@ -25266,7 +25301,6 @@ var Server = class extends Protocol {
25266
25301
  * Initializes this server with the given name and version information.
25267
25302
  */
25268
25303
  constructor(_serverInfo, options) {
25269
- var _a2, _b2;
25270
25304
  super(options);
25271
25305
  this._serverInfo = _serverInfo;
25272
25306
  this._loggingLevels = /* @__PURE__ */ new Map();
@@ -25275,18 +25309,14 @@ var Server = class extends Protocol {
25275
25309
  const currentLevel = this._loggingLevels.get(sessionId);
25276
25310
  return currentLevel ? this.LOG_LEVEL_SEVERITY.get(level) < this.LOG_LEVEL_SEVERITY.get(currentLevel) : false;
25277
25311
  };
25278
- this._capabilities = (_a2 = options === null || options === void 0 ? void 0 : options.capabilities) !== null && _a2 !== void 0 ? _a2 : {};
25279
- this._instructions = options === null || options === void 0 ? void 0 : options.instructions;
25280
- this._jsonSchemaValidator = (_b2 = options === null || options === void 0 ? void 0 : options.jsonSchemaValidator) !== null && _b2 !== void 0 ? _b2 : new AjvJsonSchemaValidator();
25312
+ this._capabilities = options?.capabilities ?? {};
25313
+ this._instructions = options?.instructions;
25314
+ this._jsonSchemaValidator = options?.jsonSchemaValidator ?? new AjvJsonSchemaValidator();
25281
25315
  this.setRequestHandler(InitializeRequestSchema, (request) => this._oninitialize(request));
25282
- this.setNotificationHandler(InitializedNotificationSchema, () => {
25283
- var _a3;
25284
- return (_a3 = this.oninitialized) === null || _a3 === void 0 ? void 0 : _a3.call(this);
25285
- });
25316
+ this.setNotificationHandler(InitializedNotificationSchema, () => this.oninitialized?.());
25286
25317
  if (this._capabilities.logging) {
25287
25318
  this.setRequestHandler(SetLevelRequestSchema, async (request, extra) => {
25288
- var _a3;
25289
- const transportSessionId = extra.sessionId || ((_a3 = extra.requestInfo) === null || _a3 === void 0 ? void 0 : _a3.headers["mcp-session-id"]) || void 0;
25319
+ const transportSessionId = extra.sessionId || extra.requestInfo?.headers["mcp-session-id"] || void 0;
25290
25320
  const { level } = request.params;
25291
25321
  const parseResult = LoggingLevelSchema.safeParse(level);
25292
25322
  if (parseResult.success) {
@@ -25326,21 +25356,20 @@ var Server = class extends Protocol {
25326
25356
  * Override request handler registration to enforce server-side validation for tools/call.
25327
25357
  */
25328
25358
  setRequestHandler(requestSchema, handler) {
25329
- var _a2, _b2, _c2;
25330
25359
  const shape = getObjectShape(requestSchema);
25331
- const methodSchema = shape === null || shape === void 0 ? void 0 : shape.method;
25360
+ const methodSchema = shape?.method;
25332
25361
  if (!methodSchema) {
25333
25362
  throw new Error("Schema is missing a method literal");
25334
25363
  }
25335
25364
  let methodValue;
25336
25365
  if (isZ4Schema(methodSchema)) {
25337
25366
  const v4Schema = methodSchema;
25338
- const v4Def = (_a2 = v4Schema._zod) === null || _a2 === void 0 ? void 0 : _a2.def;
25339
- methodValue = (_b2 = v4Def === null || v4Def === void 0 ? void 0 : v4Def.value) !== null && _b2 !== void 0 ? _b2 : v4Schema.value;
25367
+ const v4Def = v4Schema._zod?.def;
25368
+ methodValue = v4Def?.value ?? v4Schema.value;
25340
25369
  } else {
25341
25370
  const v3Schema = methodSchema;
25342
25371
  const legacyDef = v3Schema._def;
25343
- methodValue = (_c2 = legacyDef === null || legacyDef === void 0 ? void 0 : legacyDef.value) !== null && _c2 !== void 0 ? _c2 : v3Schema.value;
25372
+ methodValue = legacyDef?.value ?? v3Schema.value;
25344
25373
  }
25345
25374
  if (typeof methodValue !== "string") {
25346
25375
  throw new Error("Schema method literal must be a string");
@@ -25375,20 +25404,19 @@ var Server = class extends Protocol {
25375
25404
  return super.setRequestHandler(requestSchema, handler);
25376
25405
  }
25377
25406
  assertCapabilityForMethod(method) {
25378
- var _a2, _b2, _c2;
25379
25407
  switch (method) {
25380
25408
  case "sampling/createMessage":
25381
- if (!((_a2 = this._clientCapabilities) === null || _a2 === void 0 ? void 0 : _a2.sampling)) {
25409
+ if (!this._clientCapabilities?.sampling) {
25382
25410
  throw new Error(`Client does not support sampling (required for ${method})`);
25383
25411
  }
25384
25412
  break;
25385
25413
  case "elicitation/create":
25386
- if (!((_b2 = this._clientCapabilities) === null || _b2 === void 0 ? void 0 : _b2.elicitation)) {
25414
+ if (!this._clientCapabilities?.elicitation) {
25387
25415
  throw new Error(`Client does not support elicitation (required for ${method})`);
25388
25416
  }
25389
25417
  break;
25390
25418
  case "roots/list":
25391
- if (!((_c2 = this._clientCapabilities) === null || _c2 === void 0 ? void 0 : _c2.roots)) {
25419
+ if (!this._clientCapabilities?.roots) {
25392
25420
  throw new Error(`Client does not support listing roots (required for ${method})`);
25393
25421
  }
25394
25422
  break;
@@ -25397,7 +25425,6 @@ var Server = class extends Protocol {
25397
25425
  }
25398
25426
  }
25399
25427
  assertNotificationCapability(method) {
25400
- var _a2, _b2;
25401
25428
  switch (method) {
25402
25429
  case "notifications/message":
25403
25430
  if (!this._capabilities.logging) {
@@ -25421,7 +25448,7 @@ var Server = class extends Protocol {
25421
25448
  }
25422
25449
  break;
25423
25450
  case "notifications/elicitation/complete":
25424
- if (!((_b2 = (_a2 = this._clientCapabilities) === null || _a2 === void 0 ? void 0 : _a2.elicitation) === null || _b2 === void 0 ? void 0 : _b2.url)) {
25451
+ if (!this._clientCapabilities?.elicitation?.url) {
25425
25452
  throw new Error(`Client does not support URL elicitation (required for ${method})`);
25426
25453
  }
25427
25454
  break;
@@ -25479,15 +25506,13 @@ var Server = class extends Protocol {
25479
25506
  }
25480
25507
  }
25481
25508
  assertTaskCapability(method) {
25482
- var _a2, _b2;
25483
- assertClientRequestTaskCapability((_b2 = (_a2 = this._clientCapabilities) === null || _a2 === void 0 ? void 0 : _a2.tasks) === null || _b2 === void 0 ? void 0 : _b2.requests, method, "Client");
25509
+ assertClientRequestTaskCapability(this._clientCapabilities?.tasks?.requests, method, "Client");
25484
25510
  }
25485
25511
  assertTaskHandlerCapability(method) {
25486
- var _a2;
25487
25512
  if (!this._capabilities) {
25488
25513
  return;
25489
25514
  }
25490
- assertToolsCallTaskCapability((_a2 = this._capabilities.tasks) === null || _a2 === void 0 ? void 0 : _a2.requests, method, "Server");
25515
+ assertToolsCallTaskCapability(this._capabilities.tasks?.requests, method, "Server");
25491
25516
  }
25492
25517
  async _oninitialize(request) {
25493
25518
  const requestedVersion = request.params.protocolVersion;
@@ -25521,9 +25546,8 @@ var Server = class extends Protocol {
25521
25546
  }
25522
25547
  // Implementation
25523
25548
  async createMessage(params, options) {
25524
- var _a2, _b2;
25525
25549
  if (params.tools || params.toolChoice) {
25526
- if (!((_b2 = (_a2 = this._clientCapabilities) === null || _a2 === void 0 ? void 0 : _a2.sampling) === null || _b2 === void 0 ? void 0 : _b2.tools)) {
25550
+ if (!this._clientCapabilities?.sampling?.tools) {
25527
25551
  throw new Error("Client does not support sampling tools capability.");
25528
25552
  }
25529
25553
  }
@@ -25563,18 +25587,17 @@ var Server = class extends Protocol {
25563
25587
  * @returns The result of the elicitation request.
25564
25588
  */
25565
25589
  async elicitInput(params, options) {
25566
- var _a2, _b2, _c2, _d, _e;
25567
- const mode = (_a2 = params.mode) !== null && _a2 !== void 0 ? _a2 : "form";
25590
+ const mode = params.mode ?? "form";
25568
25591
  switch (mode) {
25569
25592
  case "url": {
25570
- if (!((_c2 = (_b2 = this._clientCapabilities) === null || _b2 === void 0 ? void 0 : _b2.elicitation) === null || _c2 === void 0 ? void 0 : _c2.url)) {
25593
+ if (!this._clientCapabilities?.elicitation?.url) {
25571
25594
  throw new Error("Client does not support url elicitation.");
25572
25595
  }
25573
25596
  const urlParams = params;
25574
25597
  return this.request({ method: "elicitation/create", params: urlParams }, ElicitResultSchema, options);
25575
25598
  }
25576
25599
  case "form": {
25577
- if (!((_e = (_d = this._clientCapabilities) === null || _d === void 0 ? void 0 : _d.elicitation) === null || _e === void 0 ? void 0 : _e.form)) {
25600
+ if (!this._clientCapabilities?.elicitation?.form) {
25578
25601
  throw new Error("Client does not support form elicitation.");
25579
25602
  }
25580
25603
  const formParams = params.mode === "form" ? params : { ...params, mode: "form" };
@@ -25606,8 +25629,7 @@ var Server = class extends Protocol {
25606
25629
  * @returns A function that emits the completion notification when awaited.
25607
25630
  */
25608
25631
  createElicitationCompletionNotifier(elicitationId, options) {
25609
- var _a2, _b2;
25610
- if (!((_b2 = (_a2 = this._clientCapabilities) === null || _a2 === void 0 ? void 0 : _a2.elicitation) === null || _b2 === void 0 ? void 0 : _b2.url)) {
25632
+ if (!this._clientCapabilities?.elicitation?.url) {
25611
25633
  throw new Error("Client does not support URL elicitation (required for notifications/elicitation/complete)");
25612
25634
  }
25613
25635
  return () => this.notification({
@@ -25660,7 +25682,7 @@ function isCompletable(schema) {
25660
25682
  }
25661
25683
  function getCompleter(schema) {
25662
25684
  const meta = schema[COMPLETABLE_SYMBOL];
25663
- return meta === null || meta === void 0 ? void 0 : meta.complete;
25685
+ return meta?.complete;
25664
25686
  }
25665
25687
  var McpZodTypeKind;
25666
25688
  (function(McpZodTypeKind2) {
@@ -25823,7 +25845,6 @@ var McpServer = class {
25823
25845
  })
25824
25846
  }));
25825
25847
  this.server.setRequestHandler(CallToolRequestSchema, async (request, extra) => {
25826
- var _a2;
25827
25848
  try {
25828
25849
  const tool = this._registeredTools[request.params.name];
25829
25850
  if (!tool) {
@@ -25833,7 +25854,7 @@ var McpServer = class {
25833
25854
  throw new McpError(ErrorCode.InvalidParams, `Tool ${request.params.name} disabled`);
25834
25855
  }
25835
25856
  const isTaskRequest = !!request.params.task;
25836
- const taskSupport = (_a2 = tool.execution) === null || _a2 === void 0 ? void 0 : _a2.taskSupport;
25857
+ const taskSupport = tool.execution?.taskSupport;
25837
25858
  const isTaskHandler = "createTask" in tool.handler;
25838
25859
  if ((taskSupport === "required" || taskSupport === "optional") && !isTaskHandler) {
25839
25860
  throw new McpError(ErrorCode.InternalError, `Tool ${request.params.name} has taskSupport '${taskSupport}' but was not registered with registerToolTask`);
@@ -25887,7 +25908,7 @@ var McpServer = class {
25887
25908
  return void 0;
25888
25909
  }
25889
25910
  const inputObj = normalizeObjectSchema(tool.inputSchema);
25890
- const schemaToParse = inputObj !== null && inputObj !== void 0 ? inputObj : tool.inputSchema;
25911
+ const schemaToParse = inputObj ?? tool.inputSchema;
25891
25912
  const parseResult = await safeParseAsync2(schemaToParse, args);
25892
25913
  if (!parseResult.success) {
25893
25914
  const error2 = "error" in parseResult ? parseResult.error : "Unknown error";
@@ -25951,7 +25972,6 @@ var McpServer = class {
25951
25972
  * Handles automatic task polling for tools with taskSupport 'optional'.
25952
25973
  */
25953
25974
  async handleAutomaticTaskPolling(tool, request, extra) {
25954
- var _a2;
25955
25975
  if (!extra.taskStore) {
25956
25976
  throw new Error("No task store provided for task-capable tool.");
25957
25977
  }
@@ -25964,7 +25984,7 @@ var McpServer = class {
25964
25984
  );
25965
25985
  const taskId = createTaskResult.task.taskId;
25966
25986
  let task = createTaskResult.task;
25967
- const pollInterval = (_a2 = task.pollInterval) !== null && _a2 !== void 0 ? _a2 : 5e3;
25987
+ const pollInterval = task.pollInterval ?? 5e3;
25968
25988
  while (task.status !== "completed" && task.status !== "failed" && task.status !== "cancelled") {
25969
25989
  await new Promise((resolve5) => setTimeout(resolve5, pollInterval));
25970
25990
  const updatedTask = await extra.taskStore.getTask(taskId);
@@ -26009,7 +26029,7 @@ var McpServer = class {
26009
26029
  return EMPTY_COMPLETION_RESULT;
26010
26030
  }
26011
26031
  const promptShape = getObjectShape(prompt.argsSchema);
26012
- const field = promptShape === null || promptShape === void 0 ? void 0 : promptShape[request.params.argument.name];
26032
+ const field = promptShape?.[request.params.argument.name];
26013
26033
  if (!isCompletable(field)) {
26014
26034
  return EMPTY_COMPLETION_RESULT;
26015
26035
  }
@@ -26094,7 +26114,6 @@ var McpServer = class {
26094
26114
  }
26095
26115
  throw new McpError(ErrorCode.InvalidParams, `Resource ${uri} not found`);
26096
26116
  });
26097
- this.setCompletionRequestHandler();
26098
26117
  this._resourceHandlersInitialized = true;
26099
26118
  }
26100
26119
  setPromptRequestHandlers() {
@@ -26142,7 +26161,6 @@ var McpServer = class {
26142
26161
  return await Promise.resolve(cb(extra));
26143
26162
  }
26144
26163
  });
26145
- this.setCompletionRequestHandler();
26146
26164
  this._promptHandlersInitialized = true;
26147
26165
  }
26148
26166
  resource(name, uriOrTemplate, ...rest) {
@@ -26250,6 +26268,11 @@ var McpServer = class {
26250
26268
  }
26251
26269
  };
26252
26270
  this._registeredResourceTemplates[name] = registeredResourceTemplate;
26271
+ const variableNames = template.uriTemplate.variableNames;
26272
+ const hasCompleter = Array.isArray(variableNames) && variableNames.some((v) => !!template.completeCallback(v));
26273
+ if (hasCompleter) {
26274
+ this.setCompletionRequestHandler();
26275
+ }
26253
26276
  return registeredResourceTemplate;
26254
26277
  }
26255
26278
  _createRegisteredPrompt(name, title, description, argsSchema, callback) {
@@ -26282,6 +26305,15 @@ var McpServer = class {
26282
26305
  }
26283
26306
  };
26284
26307
  this._registeredPrompts[name] = registeredPrompt;
26308
+ if (argsSchema) {
26309
+ const hasCompletable = Object.values(argsSchema).some((field) => {
26310
+ const inner = field instanceof ZodOptional ? field._def?.innerType : field;
26311
+ return isCompletable(inner);
26312
+ });
26313
+ if (hasCompletable) {
26314
+ this.setCompletionRequestHandler();
26315
+ }
26316
+ }
26285
26317
  return registeredPrompt;
26286
26318
  }
26287
26319
  _createRegisteredTool(name, title, description, inputSchema25, outputSchema, annotations, execution, _meta, handler) {
@@ -26314,6 +26346,8 @@ var McpServer = class {
26314
26346
  registeredTool.description = updates.description;
26315
26347
  if (typeof updates.paramsSchema !== "undefined")
26316
26348
  registeredTool.inputSchema = objectFromShape(updates.paramsSchema);
26349
+ if (typeof updates.outputSchema !== "undefined")
26350
+ registeredTool.outputSchema = objectFromShape(updates.outputSchema);
26317
26351
  if (typeof updates.callback !== "undefined")
26318
26352
  registeredTool.handler = updates.callback;
26319
26353
  if (typeof updates.annotations !== "undefined")
@@ -26488,7 +26522,7 @@ function promptArgumentsFromSchema(schema) {
26488
26522
  }
26489
26523
  function getMethodValue(schema) {
26490
26524
  const shape = getObjectShape(schema);
26491
- const methodSchema = shape === null || shape === void 0 ? void 0 : shape.method;
26525
+ const methodSchema = shape?.method;
26492
26526
  if (!methodSchema) {
26493
26527
  throw new Error("Schema is missing a method literal");
26494
26528
  }
@@ -28786,8 +28820,7 @@ var StdioServerTransport = class {
28786
28820
  this.processReadBuffer();
28787
28821
  };
28788
28822
  this._onerror = (error2) => {
28789
- var _a2;
28790
- (_a2 = this.onerror) === null || _a2 === void 0 ? void 0 : _a2.call(this, error2);
28823
+ this.onerror?.(error2);
28791
28824
  };
28792
28825
  }
28793
28826
  /**
@@ -28802,21 +28835,19 @@ var StdioServerTransport = class {
28802
28835
  this._stdin.on("error", this._onerror);
28803
28836
  }
28804
28837
  processReadBuffer() {
28805
- var _a2, _b2;
28806
28838
  while (true) {
28807
28839
  try {
28808
28840
  const message = this._readBuffer.readMessage();
28809
28841
  if (message === null) {
28810
28842
  break;
28811
28843
  }
28812
- (_a2 = this.onmessage) === null || _a2 === void 0 ? void 0 : _a2.call(this, message);
28844
+ this.onmessage?.(message);
28813
28845
  } catch (error2) {
28814
- (_b2 = this.onerror) === null || _b2 === void 0 ? void 0 : _b2.call(this, error2);
28846
+ this.onerror?.(error2);
28815
28847
  }
28816
28848
  }
28817
28849
  }
28818
28850
  async close() {
28819
- var _a2;
28820
28851
  this._stdin.off("data", this._ondata);
28821
28852
  this._stdin.off("error", this._onerror);
28822
28853
  const remainingDataListeners = this._stdin.listenerCount("data");
@@ -28824,7 +28855,7 @@ var StdioServerTransport = class {
28824
28855
  this._stdin.pause();
28825
28856
  }
28826
28857
  this._readBuffer.clear();
28827
- (_a2 = this.onclose) === null || _a2 === void 0 ? void 0 : _a2.call(this);
28858
+ this.onclose?.();
28828
28859
  }
28829
28860
  send(message) {
28830
28861
  return new Promise((resolve5) => {
@@ -28841,7 +28872,7 @@ var StdioServerTransport = class {
28841
28872
  // package.json
28842
28873
  var package_default = {
28843
28874
  name: "@google-cloud/storage-mcp",
28844
- version: "0.3.2",
28875
+ version: "0.3.3",
28845
28876
  type: "module",
28846
28877
  main: "dist/bundle.js",
28847
28878
  bin: {
@@ -28904,11 +28935,11 @@ var package_default = {
28904
28935
  "@google-cloud/service-usage": "^4.2.0",
28905
28936
  "@google-cloud/storage": "^7.17.1",
28906
28937
  "@google-cloud/storageinsights": "^2.2.0",
28907
- "@modelcontextprotocol/sdk": "^1.24.0",
28938
+ "@modelcontextprotocol/sdk": "^1.26.0",
28908
28939
  "@types/yargs": "^17.0.33",
28909
28940
  chardet: "^2.1.0",
28910
28941
  "google-auth-library": "^9.11.0",
28911
- googleapis: "^169.0.0",
28942
+ googleapis: "^171.0.0",
28912
28943
  "iconv-lite": "^0.7.0",
28913
28944
  "mime-types": "^2.1.35",
28914
28945
  yargs: "^18.0.0",