@kentico/management-api-mcp 31.0.0-preview → 31.0.2-preview

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.
Files changed (2) hide show
  1. package/dist/index.js +292 -273
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -16995,7 +16995,10 @@ var TaskCreationParamsSchema = looseObject({
16995
16995
  */
16996
16996
  pollInterval: number2().optional()
16997
16997
  });
16998
- var RelatedTaskMetadataSchema = looseObject({
16998
+ var TaskMetadataSchema = object({
16999
+ ttl: number2().optional()
17000
+ });
17001
+ var RelatedTaskMetadataSchema = object({
16999
17002
  taskId: string2()
17000
17003
  });
17001
17004
  var RequestMetaSchema = looseObject({
@@ -17008,48 +17011,45 @@ var RequestMetaSchema = looseObject({
17008
17011
  */
17009
17012
  [RELATED_TASK_META_KEY]: RelatedTaskMetadataSchema.optional()
17010
17013
  });
17011
- var BaseRequestParamsSchema = looseObject({
17012
- /**
17013
- * If specified, the caller is requesting that the receiver create a task to represent the request.
17014
- * Task creation parameters are now at the top level instead of in _meta.
17015
- */
17016
- task: TaskCreationParamsSchema.optional(),
17014
+ var BaseRequestParamsSchema = object({
17017
17015
  /**
17018
17016
  * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage.
17019
17017
  */
17020
17018
  _meta: RequestMetaSchema.optional()
17021
17019
  });
17020
+ var TaskAugmentedRequestParamsSchema = BaseRequestParamsSchema.extend({
17021
+ /**
17022
+ * If specified, the caller is requesting task-augmented execution for this request.
17023
+ * The request will return a CreateTaskResult immediately, and the actual result can be
17024
+ * retrieved later via tasks/result.
17025
+ *
17026
+ * Task augmentation is subject to capability negotiation - receivers MUST declare support
17027
+ * for task augmentation of specific request types in their capabilities.
17028
+ */
17029
+ task: TaskMetadataSchema.optional()
17030
+ });
17031
+ var isTaskAugmentedRequestParams = (value) => TaskAugmentedRequestParamsSchema.safeParse(value).success;
17022
17032
  var RequestSchema = object({
17023
17033
  method: string2(),
17024
- params: BaseRequestParamsSchema.optional()
17034
+ params: BaseRequestParamsSchema.loose().optional()
17025
17035
  });
17026
- var NotificationsParamsSchema = looseObject({
17036
+ var NotificationsParamsSchema = object({
17027
17037
  /**
17028
17038
  * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
17029
17039
  * for notes on _meta usage.
17030
17040
  */
17031
- _meta: object({
17032
- /**
17033
- * If specified, this notification is related to the provided task.
17034
- */
17035
- [RELATED_TASK_META_KEY]: optional(RelatedTaskMetadataSchema)
17036
- }).passthrough().optional()
17041
+ _meta: RequestMetaSchema.optional()
17037
17042
  });
17038
17043
  var NotificationSchema = object({
17039
17044
  method: string2(),
17040
- params: NotificationsParamsSchema.optional()
17045
+ params: NotificationsParamsSchema.loose().optional()
17041
17046
  });
17042
17047
  var ResultSchema = looseObject({
17043
17048
  /**
17044
17049
  * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
17045
17050
  * for notes on _meta usage.
17046
17051
  */
17047
- _meta: looseObject({
17048
- /**
17049
- * If specified, this result is related to the provided task.
17050
- */
17051
- [RELATED_TASK_META_KEY]: RelatedTaskMetadataSchema.optional()
17052
- }).optional()
17052
+ _meta: RequestMetaSchema.optional()
17053
17053
  });
17054
17054
  var RequestIdSchema = union([string2(), number2().int()]);
17055
17055
  var JSONRPCRequestSchema = object({
@@ -17063,12 +17063,12 @@ var JSONRPCNotificationSchema = object({
17063
17063
  ...NotificationSchema.shape
17064
17064
  }).strict();
17065
17065
  var isJSONRPCNotification = (value) => JSONRPCNotificationSchema.safeParse(value).success;
17066
- var JSONRPCResponseSchema = object({
17066
+ var JSONRPCResultResponseSchema = object({
17067
17067
  jsonrpc: literal(JSONRPC_VERSION),
17068
17068
  id: RequestIdSchema,
17069
17069
  result: ResultSchema
17070
17070
  }).strict();
17071
- var isJSONRPCResponse = (value) => JSONRPCResponseSchema.safeParse(value).success;
17071
+ var isJSONRPCResultResponse = (value) => JSONRPCResultResponseSchema.safeParse(value).success;
17072
17072
  var ErrorCode;
17073
17073
  (function(ErrorCode2) {
17074
17074
  ErrorCode2[ErrorCode2["ConnectionClosed"] = -32e3] = "ConnectionClosed";
@@ -17080,9 +17080,9 @@ var ErrorCode;
17080
17080
  ErrorCode2[ErrorCode2["InternalError"] = -32603] = "InternalError";
17081
17081
  ErrorCode2[ErrorCode2["UrlElicitationRequired"] = -32042] = "UrlElicitationRequired";
17082
17082
  })(ErrorCode || (ErrorCode = {}));
17083
- var JSONRPCErrorSchema = object({
17083
+ var JSONRPCErrorResponseSchema = object({
17084
17084
  jsonrpc: literal(JSONRPC_VERSION),
17085
- id: RequestIdSchema,
17085
+ id: RequestIdSchema.optional(),
17086
17086
  error: object({
17087
17087
  /**
17088
17088
  * The error type that occurred.
@@ -17095,11 +17095,17 @@ var JSONRPCErrorSchema = object({
17095
17095
  /**
17096
17096
  * Additional information about the error. The value of this member is defined by the sender (e.g. detailed error information, nested errors etc.).
17097
17097
  */
17098
- data: optional(unknown())
17098
+ data: unknown().optional()
17099
17099
  })
17100
17100
  }).strict();
17101
- var isJSONRPCError = (value) => JSONRPCErrorSchema.safeParse(value).success;
17102
- var JSONRPCMessageSchema = union([JSONRPCRequestSchema, JSONRPCNotificationSchema, JSONRPCResponseSchema, JSONRPCErrorSchema]);
17101
+ var isJSONRPCErrorResponse = (value) => JSONRPCErrorResponseSchema.safeParse(value).success;
17102
+ var JSONRPCMessageSchema = union([
17103
+ JSONRPCRequestSchema,
17104
+ JSONRPCNotificationSchema,
17105
+ JSONRPCResultResponseSchema,
17106
+ JSONRPCErrorResponseSchema
17107
+ ]);
17108
+ var JSONRPCResponseSchema = union([JSONRPCResultResponseSchema, JSONRPCErrorResponseSchema]);
17103
17109
  var EmptyResultSchema = ResultSchema.strict();
17104
17110
  var CancelledNotificationParamsSchema = NotificationsParamsSchema.extend({
17105
17111
  /**
@@ -17107,7 +17113,7 @@ var CancelledNotificationParamsSchema = NotificationsParamsSchema.extend({
17107
17113
  *
17108
17114
  * This MUST correspond to the ID of a request previously issued in the same direction.
17109
17115
  */
17110
- requestId: RequestIdSchema,
17116
+ requestId: RequestIdSchema.optional(),
17111
17117
  /**
17112
17118
  * An optional string describing the reason for the cancellation. This MAY be logged or presented to the user.
17113
17119
  */
@@ -17132,7 +17138,15 @@ var IconSchema = object({
17132
17138
  *
17133
17139
  * If not provided, the client should assume that the icon can be used at any size.
17134
17140
  */
17135
- sizes: array(string2()).optional()
17141
+ sizes: array(string2()).optional(),
17142
+ /**
17143
+ * Optional specifier for the theme this icon is designed for. `light` indicates
17144
+ * the icon is designed to be used with a light background, and `dark` indicates
17145
+ * the icon is designed to be used with a dark background.
17146
+ *
17147
+ * If not provided, the client should assume the icon can be used with any theme.
17148
+ */
17149
+ theme: _enum(["light", "dark"]).optional()
17136
17150
  });
17137
17151
  var IconsSchema = object({
17138
17152
  /**
@@ -17168,7 +17182,15 @@ var ImplementationSchema = BaseMetadataSchema.extend({
17168
17182
  /**
17169
17183
  * An optional URL of the website for this implementation.
17170
17184
  */
17171
- websiteUrl: string2().optional()
17185
+ websiteUrl: string2().optional(),
17186
+ /**
17187
+ * An optional human-readable description of what this implementation does.
17188
+ *
17189
+ * This can be used by clients or servers to provide context about their purpose
17190
+ * and capabilities. For example, a server might describe the types of resources
17191
+ * or tools it provides, while a client might describe its intended use case.
17192
+ */
17193
+ description: string2().optional()
17172
17194
  });
17173
17195
  var FormElicitationCapabilitySchema = intersection(object({
17174
17196
  applyDefaults: boolean2().optional()
@@ -17184,54 +17206,54 @@ var ElicitationCapabilitySchema = preprocess((value) => {
17184
17206
  form: FormElicitationCapabilitySchema.optional(),
17185
17207
  url: AssertObjectSchema.optional()
17186
17208
  }), record(string2(), unknown()).optional()));
17187
- var ClientTasksCapabilitySchema = object({
17209
+ var ClientTasksCapabilitySchema = looseObject({
17188
17210
  /**
17189
17211
  * Present if the client supports listing tasks.
17190
17212
  */
17191
- list: optional(object({}).passthrough()),
17213
+ list: AssertObjectSchema.optional(),
17192
17214
  /**
17193
17215
  * Present if the client supports cancelling tasks.
17194
17216
  */
17195
- cancel: optional(object({}).passthrough()),
17217
+ cancel: AssertObjectSchema.optional(),
17196
17218
  /**
17197
17219
  * Capabilities for task creation on specific request types.
17198
17220
  */
17199
- requests: optional(object({
17221
+ requests: looseObject({
17200
17222
  /**
17201
17223
  * Task support for sampling requests.
17202
17224
  */
17203
- sampling: optional(object({
17204
- createMessage: optional(object({}).passthrough())
17205
- }).passthrough()),
17225
+ sampling: looseObject({
17226
+ createMessage: AssertObjectSchema.optional()
17227
+ }).optional(),
17206
17228
  /**
17207
17229
  * Task support for elicitation requests.
17208
17230
  */
17209
- elicitation: optional(object({
17210
- create: optional(object({}).passthrough())
17211
- }).passthrough())
17212
- }).passthrough())
17213
- }).passthrough();
17214
- var ServerTasksCapabilitySchema = object({
17231
+ elicitation: looseObject({
17232
+ create: AssertObjectSchema.optional()
17233
+ }).optional()
17234
+ }).optional()
17235
+ });
17236
+ var ServerTasksCapabilitySchema = looseObject({
17215
17237
  /**
17216
17238
  * Present if the server supports listing tasks.
17217
17239
  */
17218
- list: optional(object({}).passthrough()),
17240
+ list: AssertObjectSchema.optional(),
17219
17241
  /**
17220
17242
  * Present if the server supports cancelling tasks.
17221
17243
  */
17222
- cancel: optional(object({}).passthrough()),
17244
+ cancel: AssertObjectSchema.optional(),
17223
17245
  /**
17224
17246
  * Capabilities for task creation on specific request types.
17225
17247
  */
17226
- requests: optional(object({
17248
+ requests: looseObject({
17227
17249
  /**
17228
17250
  * Task support for tool requests.
17229
17251
  */
17230
- tools: optional(object({
17231
- call: optional(object({}).passthrough())
17232
- }).passthrough())
17233
- }).passthrough())
17234
- }).passthrough();
17252
+ tools: looseObject({
17253
+ call: AssertObjectSchema.optional()
17254
+ }).optional()
17255
+ }).optional()
17256
+ });
17235
17257
  var ClientCapabilitiesSchema = object({
17236
17258
  /**
17237
17259
  * Experimental, non-standard capabilities that the client supports.
@@ -17267,7 +17289,7 @@ var ClientCapabilitiesSchema = object({
17267
17289
  /**
17268
17290
  * Present if the client supports task creation.
17269
17291
  */
17270
- tasks: optional(ClientTasksCapabilitySchema)
17292
+ tasks: ClientTasksCapabilitySchema.optional()
17271
17293
  });
17272
17294
  var InitializeRequestParamsSchema = BaseRequestParamsSchema.extend({
17273
17295
  /**
@@ -17297,12 +17319,12 @@ var ServerCapabilitiesSchema = object({
17297
17319
  /**
17298
17320
  * Present if the server offers any prompt templates.
17299
17321
  */
17300
- prompts: optional(object({
17322
+ prompts: object({
17301
17323
  /**
17302
17324
  * Whether this server supports issuing notifications for changes to the prompt list.
17303
17325
  */
17304
- listChanged: optional(boolean2())
17305
- })),
17326
+ listChanged: boolean2().optional()
17327
+ }).optional(),
17306
17328
  /**
17307
17329
  * Present if the server offers any resources to read.
17308
17330
  */
@@ -17328,8 +17350,8 @@ var ServerCapabilitiesSchema = object({
17328
17350
  /**
17329
17351
  * Present if the server supports task creation.
17330
17352
  */
17331
- tasks: optional(ServerTasksCapabilitySchema)
17332
- }).passthrough();
17353
+ tasks: ServerTasksCapabilitySchema.optional()
17354
+ });
17333
17355
  var InitializeResultSchema = ResultSchema.extend({
17334
17356
  /**
17335
17357
  * 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.
@@ -17345,10 +17367,12 @@ var InitializeResultSchema = ResultSchema.extend({
17345
17367
  instructions: string2().optional()
17346
17368
  });
17347
17369
  var InitializedNotificationSchema = NotificationSchema.extend({
17348
- method: literal("notifications/initialized")
17370
+ method: literal("notifications/initialized"),
17371
+ params: NotificationsParamsSchema.optional()
17349
17372
  });
17350
17373
  var PingRequestSchema = RequestSchema.extend({
17351
- method: literal("ping")
17374
+ method: literal("ping"),
17375
+ params: BaseRequestParamsSchema.optional()
17352
17376
  });
17353
17377
  var ProgressSchema = object({
17354
17378
  /**
@@ -17391,11 +17415,12 @@ var PaginatedResultSchema = ResultSchema.extend({
17391
17415
  * An opaque token representing the pagination position after the last returned result.
17392
17416
  * If present, there may be more results available.
17393
17417
  */
17394
- nextCursor: optional(CursorSchema)
17418
+ nextCursor: CursorSchema.optional()
17395
17419
  });
17420
+ var TaskStatusSchema = _enum(["working", "input_required", "completed", "failed", "cancelled"]);
17396
17421
  var TaskSchema = object({
17397
17422
  taskId: string2(),
17398
- status: _enum(["working", "input_required", "completed", "failed", "cancelled"]),
17423
+ status: TaskStatusSchema,
17399
17424
  /**
17400
17425
  * Time in milliseconds to keep task results available after completion.
17401
17426
  * If null, the task has unlimited lifetime until manually cleaned up.
@@ -17436,6 +17461,7 @@ var GetTaskPayloadRequestSchema = RequestSchema.extend({
17436
17461
  taskId: string2()
17437
17462
  })
17438
17463
  });
17464
+ var GetTaskPayloadResultSchema = ResultSchema.loose();
17439
17465
  var ListTasksRequestSchema = PaginatedRequestSchema.extend({
17440
17466
  method: literal("tasks/list")
17441
17467
  });
@@ -17474,7 +17500,7 @@ var Base64Schema = string2().refine((val) => {
17474
17500
  try {
17475
17501
  atob(val);
17476
17502
  return true;
17477
- } catch (_a) {
17503
+ } catch {
17478
17504
  return false;
17479
17505
  }
17480
17506
  }, { message: "Invalid Base64 string" });
@@ -17484,11 +17510,12 @@ var BlobResourceContentsSchema = ResourceContentsSchema.extend({
17484
17510
  */
17485
17511
  blob: Base64Schema
17486
17512
  });
17513
+ var RoleSchema = _enum(["user", "assistant"]);
17487
17514
  var AnnotationsSchema = object({
17488
17515
  /**
17489
17516
  * Intended audience(s) for the resource.
17490
17517
  */
17491
- audience: array(_enum(["user", "assistant"])).optional(),
17518
+ audience: array(RoleSchema).optional(),
17492
17519
  /**
17493
17520
  * Importance hint for the resource, from 0 (least) to 1 (most).
17494
17521
  */
@@ -17581,7 +17608,8 @@ var ReadResourceResultSchema = ResultSchema.extend({
17581
17608
  contents: array(union([TextResourceContentsSchema, BlobResourceContentsSchema]))
17582
17609
  });
17583
17610
  var ResourceListChangedNotificationSchema = NotificationSchema.extend({
17584
- method: literal("notifications/resources/list_changed")
17611
+ method: literal("notifications/resources/list_changed"),
17612
+ params: NotificationsParamsSchema.optional()
17585
17613
  });
17586
17614
  var SubscribeRequestParamsSchema = ResourceRequestParamsSchema;
17587
17615
  var SubscribeRequestSchema = RequestSchema.extend({
@@ -17726,13 +17754,13 @@ var ToolUseContentSchema = object({
17726
17754
  * Arguments to pass to the tool.
17727
17755
  * Must conform to the tool's inputSchema.
17728
17756
  */
17729
- input: object({}).passthrough(),
17757
+ input: record(string2(), unknown()),
17730
17758
  /**
17731
17759
  * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
17732
17760
  * for notes on _meta usage.
17733
17761
  */
17734
- _meta: optional(object({}).passthrough())
17735
- }).passthrough();
17762
+ _meta: record(string2(), unknown()).optional()
17763
+ });
17736
17764
  var EmbeddedResourceSchema = object({
17737
17765
  type: literal("resource"),
17738
17766
  resource: union([TextResourceContentsSchema, BlobResourceContentsSchema]),
@@ -17757,18 +17785,19 @@ var ContentBlockSchema = union([
17757
17785
  EmbeddedResourceSchema
17758
17786
  ]);
17759
17787
  var PromptMessageSchema = object({
17760
- role: _enum(["user", "assistant"]),
17788
+ role: RoleSchema,
17761
17789
  content: ContentBlockSchema
17762
17790
  });
17763
17791
  var GetPromptResultSchema = ResultSchema.extend({
17764
17792
  /**
17765
17793
  * An optional description for the prompt.
17766
17794
  */
17767
- description: optional(string2()),
17795
+ description: string2().optional(),
17768
17796
  messages: array(PromptMessageSchema)
17769
17797
  });
17770
17798
  var PromptListChangedNotificationSchema = NotificationSchema.extend({
17771
- method: literal("notifications/prompts/list_changed")
17799
+ method: literal("notifications/prompts/list_changed"),
17800
+ params: NotificationsParamsSchema.optional()
17772
17801
  });
17773
17802
  var ToolAnnotationsSchema = object({
17774
17803
  /**
@@ -17849,11 +17878,11 @@ var ToolSchema = object({
17849
17878
  /**
17850
17879
  * Optional additional tool information.
17851
17880
  */
17852
- annotations: optional(ToolAnnotationsSchema),
17881
+ annotations: ToolAnnotationsSchema.optional(),
17853
17882
  /**
17854
17883
  * Execution-related properties for this tool.
17855
17884
  */
17856
- execution: optional(ToolExecutionSchema),
17885
+ execution: ToolExecutionSchema.optional(),
17857
17886
  /**
17858
17887
  * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
17859
17888
  * for notes on _meta usage.
@@ -17894,12 +17923,12 @@ var CallToolResultSchema = ResultSchema.extend({
17894
17923
  * server does not support tool calls, or any other exceptional conditions,
17895
17924
  * should be reported as an MCP error response.
17896
17925
  */
17897
- isError: optional(boolean2())
17926
+ isError: boolean2().optional()
17898
17927
  });
17899
17928
  var CompatibilityCallToolResultSchema = CallToolResultSchema.or(ResultSchema.extend({
17900
17929
  toolResult: unknown()
17901
17930
  }));
17902
- var CallToolRequestParamsSchema = BaseRequestParamsSchema.extend({
17931
+ var CallToolRequestParamsSchema = TaskAugmentedRequestParamsSchema.extend({
17903
17932
  /**
17904
17933
  * The name of the tool to call.
17905
17934
  */
@@ -17907,14 +17936,35 @@ var CallToolRequestParamsSchema = BaseRequestParamsSchema.extend({
17907
17936
  /**
17908
17937
  * Arguments to pass to the tool.
17909
17938
  */
17910
- arguments: optional(record(string2(), unknown()))
17939
+ arguments: record(string2(), unknown()).optional()
17911
17940
  });
17912
17941
  var CallToolRequestSchema = RequestSchema.extend({
17913
17942
  method: literal("tools/call"),
17914
17943
  params: CallToolRequestParamsSchema
17915
17944
  });
17916
17945
  var ToolListChangedNotificationSchema = NotificationSchema.extend({
17917
- method: literal("notifications/tools/list_changed")
17946
+ method: literal("notifications/tools/list_changed"),
17947
+ params: NotificationsParamsSchema.optional()
17948
+ });
17949
+ var ListChangedOptionsBaseSchema = object({
17950
+ /**
17951
+ * If true, the list will be refreshed automatically when a list changed notification is received.
17952
+ * The callback will be called with the updated list.
17953
+ *
17954
+ * If false, the callback will be called with null items, allowing manual refresh.
17955
+ *
17956
+ * @default true
17957
+ */
17958
+ autoRefresh: boolean2().default(true),
17959
+ /**
17960
+ * Debounce time in milliseconds for list changed notification processing.
17961
+ *
17962
+ * Multiple notifications received within this timeframe will only trigger one refresh.
17963
+ * Set to 0 to disable debouncing.
17964
+ *
17965
+ * @default 300
17966
+ */
17967
+ debounceMs: number2().int().nonnegative().default(300)
17918
17968
  });
17919
17969
  var LoggingLevelSchema = _enum(["debug", "info", "notice", "warning", "error", "critical", "alert", "emergency"]);
17920
17970
  var SetLevelRequestParamsSchema = BaseRequestParamsSchema.extend({
@@ -17955,19 +18005,19 @@ var ModelPreferencesSchema = object({
17955
18005
  /**
17956
18006
  * Optional hints to use for model selection.
17957
18007
  */
17958
- hints: optional(array(ModelHintSchema)),
18008
+ hints: array(ModelHintSchema).optional(),
17959
18009
  /**
17960
18010
  * How much to prioritize cost when selecting a model.
17961
18011
  */
17962
- costPriority: optional(number2().min(0).max(1)),
18012
+ costPriority: number2().min(0).max(1).optional(),
17963
18013
  /**
17964
18014
  * How much to prioritize sampling speed (latency) when selecting a model.
17965
18015
  */
17966
- speedPriority: optional(number2().min(0).max(1)),
18016
+ speedPriority: number2().min(0).max(1).optional(),
17967
18017
  /**
17968
18018
  * How much to prioritize intelligence and capabilities when selecting a model.
17969
18019
  */
17970
- intelligencePriority: optional(number2().min(0).max(1))
18020
+ intelligencePriority: number2().min(0).max(1).optional()
17971
18021
  });
17972
18022
  var ToolChoiceSchema = object({
17973
18023
  /**
@@ -17976,20 +18026,20 @@ var ToolChoiceSchema = object({
17976
18026
  * - "required": Model MUST use at least one tool before completing
17977
18027
  * - "none": Model MUST NOT use any tools
17978
18028
  */
17979
- mode: optional(_enum(["auto", "required", "none"]))
18029
+ mode: _enum(["auto", "required", "none"]).optional()
17980
18030
  });
17981
18031
  var ToolResultContentSchema = object({
17982
18032
  type: literal("tool_result"),
17983
18033
  toolUseId: string2().describe("The unique identifier for the corresponding tool call."),
17984
18034
  content: array(ContentBlockSchema).default([]),
17985
- structuredContent: object({}).passthrough().optional(),
17986
- isError: optional(boolean2()),
18035
+ structuredContent: object({}).loose().optional(),
18036
+ isError: boolean2().optional(),
17987
18037
  /**
17988
18038
  * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
17989
18039
  * for notes on _meta usage.
17990
18040
  */
17991
- _meta: optional(object({}).passthrough())
17992
- }).passthrough();
18041
+ _meta: record(string2(), unknown()).optional()
18042
+ });
17993
18043
  var SamplingContentSchema = discriminatedUnion("type", [TextContentSchema, ImageContentSchema, AudioContentSchema]);
17994
18044
  var SamplingMessageContentBlockSchema = discriminatedUnion("type", [
17995
18045
  TextContentSchema,
@@ -17999,15 +18049,15 @@ var SamplingMessageContentBlockSchema = discriminatedUnion("type", [
17999
18049
  ToolResultContentSchema
18000
18050
  ]);
18001
18051
  var SamplingMessageSchema = object({
18002
- role: _enum(["user", "assistant"]),
18052
+ role: RoleSchema,
18003
18053
  content: union([SamplingMessageContentBlockSchema, array(SamplingMessageContentBlockSchema)]),
18004
18054
  /**
18005
18055
  * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
18006
18056
  * for notes on _meta usage.
18007
18057
  */
18008
- _meta: optional(object({}).passthrough())
18009
- }).passthrough();
18010
- var CreateMessageRequestParamsSchema = BaseRequestParamsSchema.extend({
18058
+ _meta: record(string2(), unknown()).optional()
18059
+ });
18060
+ var CreateMessageRequestParamsSchema = TaskAugmentedRequestParamsSchema.extend({
18011
18061
  messages: array(SamplingMessageSchema),
18012
18062
  /**
18013
18063
  * The server's preferences for which model to select. The client MAY modify or omit this request.
@@ -18041,13 +18091,13 @@ var CreateMessageRequestParamsSchema = BaseRequestParamsSchema.extend({
18041
18091
  * Tools that the model may use during generation.
18042
18092
  * The client MUST return an error if this field is provided but ClientCapabilities.sampling.tools is not declared.
18043
18093
  */
18044
- tools: optional(array(ToolSchema)),
18094
+ tools: array(ToolSchema).optional(),
18045
18095
  /**
18046
18096
  * Controls how the model uses tools.
18047
18097
  * The client MUST return an error if this field is provided but ClientCapabilities.sampling.tools is not declared.
18048
18098
  * Default is `{ mode: "auto" }`.
18049
18099
  */
18050
- toolChoice: optional(ToolChoiceSchema)
18100
+ toolChoice: ToolChoiceSchema.optional()
18051
18101
  });
18052
18102
  var CreateMessageRequestSchema = RequestSchema.extend({
18053
18103
  method: literal("sampling/createMessage"),
@@ -18069,7 +18119,7 @@ var CreateMessageResultSchema = ResultSchema.extend({
18069
18119
  * This field is an open string to allow for provider-specific stop reasons.
18070
18120
  */
18071
18121
  stopReason: optional(_enum(["endTurn", "stopSequence", "maxTokens"]).or(string2())),
18072
- role: _enum(["user", "assistant"]),
18122
+ role: RoleSchema,
18073
18123
  /**
18074
18124
  * Response content. Single content block (text, image, or audio).
18075
18125
  */
@@ -18092,7 +18142,7 @@ var CreateMessageResultWithToolsSchema = ResultSchema.extend({
18092
18142
  * This field is an open string to allow for provider-specific stop reasons.
18093
18143
  */
18094
18144
  stopReason: optional(_enum(["endTurn", "stopSequence", "maxTokens", "toolUse"]).or(string2())),
18095
- role: _enum(["user", "assistant"]),
18145
+ role: RoleSchema,
18096
18146
  /**
18097
18147
  * Response content. May be a single block or array. May include ToolUseContent if stopReason is "toolUse".
18098
18148
  */
@@ -18176,7 +18226,7 @@ var TitledMultiSelectEnumSchemaSchema = object({
18176
18226
  var MultiSelectEnumSchemaSchema = union([UntitledMultiSelectEnumSchemaSchema, TitledMultiSelectEnumSchemaSchema]);
18177
18227
  var EnumSchemaSchema = union([LegacyTitledEnumSchemaSchema, SingleSelectEnumSchemaSchema, MultiSelectEnumSchemaSchema]);
18178
18228
  var PrimitiveSchemaDefinitionSchema = union([EnumSchemaSchema, BooleanSchemaSchema, StringSchemaSchema, NumberSchemaSchema]);
18179
- var ElicitRequestFormParamsSchema = BaseRequestParamsSchema.extend({
18229
+ var ElicitRequestFormParamsSchema = TaskAugmentedRequestParamsSchema.extend({
18180
18230
  /**
18181
18231
  * The elicitation mode.
18182
18232
  *
@@ -18197,7 +18247,7 @@ var ElicitRequestFormParamsSchema = BaseRequestParamsSchema.extend({
18197
18247
  required: array(string2()).optional()
18198
18248
  })
18199
18249
  });
18200
- var ElicitRequestURLParamsSchema = BaseRequestParamsSchema.extend({
18250
+ var ElicitRequestURLParamsSchema = TaskAugmentedRequestParamsSchema.extend({
18201
18251
  /**
18202
18252
  * The elicitation mode.
18203
18253
  */
@@ -18331,13 +18381,15 @@ var RootSchema = object({
18331
18381
  _meta: record(string2(), unknown()).optional()
18332
18382
  });
18333
18383
  var ListRootsRequestSchema = RequestSchema.extend({
18334
- method: literal("roots/list")
18384
+ method: literal("roots/list"),
18385
+ params: BaseRequestParamsSchema.optional()
18335
18386
  });
18336
18387
  var ListRootsResultSchema = ResultSchema.extend({
18337
18388
  roots: array(RootSchema)
18338
18389
  });
18339
18390
  var RootsListChangedNotificationSchema = NotificationSchema.extend({
18340
- method: literal("notifications/roots/list_changed")
18391
+ method: literal("notifications/roots/list_changed"),
18392
+ params: NotificationsParamsSchema.optional()
18341
18393
  });
18342
18394
  var ClientRequestSchema = union([
18343
18395
  PingRequestSchema,
@@ -18355,7 +18407,8 @@ var ClientRequestSchema = union([
18355
18407
  ListToolsRequestSchema,
18356
18408
  GetTaskRequestSchema,
18357
18409
  GetTaskPayloadRequestSchema,
18358
- ListTasksRequestSchema
18410
+ ListTasksRequestSchema,
18411
+ CancelTaskRequestSchema
18359
18412
  ]);
18360
18413
  var ClientNotificationSchema = union([
18361
18414
  CancelledNotificationSchema,
@@ -18381,7 +18434,8 @@ var ServerRequestSchema = union([
18381
18434
  ListRootsRequestSchema,
18382
18435
  GetTaskRequestSchema,
18383
18436
  GetTaskPayloadRequestSchema,
18384
- ListTasksRequestSchema
18437
+ ListTasksRequestSchema,
18438
+ CancelTaskRequestSchema
18385
18439
  ]);
18386
18440
  var ServerNotificationSchema = union([
18387
18441
  CancelledNotificationSchema,
@@ -18436,8 +18490,7 @@ var UrlElicitationRequiredError = class extends McpError {
18436
18490
  });
18437
18491
  }
18438
18492
  get elicitations() {
18439
- var _a, _b;
18440
- return (_b = (_a = this.data) === null || _a === void 0 ? void 0 : _a.elicitations) !== null && _b !== void 0 ? _b : [];
18493
+ return this.data?.elicitations ?? [];
18441
18494
  }
18442
18495
  };
18443
18496
 
@@ -18481,8 +18534,7 @@ var StdioServerTransport = class {
18481
18534
  this.processReadBuffer();
18482
18535
  };
18483
18536
  this._onerror = (error2) => {
18484
- var _a;
18485
- (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error2);
18537
+ this.onerror?.(error2);
18486
18538
  };
18487
18539
  }
18488
18540
  /**
@@ -18497,21 +18549,19 @@ var StdioServerTransport = class {
18497
18549
  this._stdin.on("error", this._onerror);
18498
18550
  }
18499
18551
  processReadBuffer() {
18500
- var _a, _b;
18501
18552
  while (true) {
18502
18553
  try {
18503
18554
  const message = this._readBuffer.readMessage();
18504
18555
  if (message === null) {
18505
18556
  break;
18506
18557
  }
18507
- (_a = this.onmessage) === null || _a === void 0 ? void 0 : _a.call(this, message);
18558
+ this.onmessage?.(message);
18508
18559
  } catch (error2) {
18509
- (_b = this.onerror) === null || _b === void 0 ? void 0 : _b.call(this, error2);
18560
+ this.onerror?.(error2);
18510
18561
  }
18511
18562
  }
18512
18563
  }
18513
18564
  async close() {
18514
- var _a;
18515
18565
  this._stdin.off("data", this._ondata);
18516
18566
  this._stdin.off("error", this._onerror);
18517
18567
  const remainingDataListeners = this._stdin.listenerCount("data");
@@ -18519,7 +18569,7 @@ var StdioServerTransport = class {
18519
18569
  this._stdin.pause();
18520
18570
  }
18521
18571
  this._readBuffer.clear();
18522
- (_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this);
18572
+ this.onclose?.();
18523
18573
  }
18524
18574
  send(message) {
18525
18575
  return new Promise((resolve) => {
@@ -22656,13 +22706,12 @@ async function safeParseAsync3(schema, data) {
22656
22706
  return result;
22657
22707
  }
22658
22708
  function getObjectShape(schema) {
22659
- var _a, _b;
22660
22709
  if (!schema)
22661
22710
  return void 0;
22662
22711
  let rawShape;
22663
22712
  if (isZ4Schema(schema)) {
22664
22713
  const v4Schema = schema;
22665
- rawShape = (_b = (_a = v4Schema._zod) === null || _a === void 0 ? void 0 : _a.def) === null || _b === void 0 ? void 0 : _b.shape;
22714
+ rawShape = v4Schema._zod?.def?.shape;
22666
22715
  } else {
22667
22716
  const v3Schema = schema;
22668
22717
  rawShape = v3Schema.shape;
@@ -22672,14 +22721,13 @@ function getObjectShape(schema) {
22672
22721
  if (typeof rawShape === "function") {
22673
22722
  try {
22674
22723
  return rawShape();
22675
- } catch (_c) {
22724
+ } catch {
22676
22725
  return void 0;
22677
22726
  }
22678
22727
  }
22679
22728
  return rawShape;
22680
22729
  }
22681
22730
  function normalizeObjectSchema(schema) {
22682
- var _a;
22683
22731
  if (!schema)
22684
22732
  return void 0;
22685
22733
  if (typeof schema === "object") {
@@ -22694,7 +22742,7 @@ function normalizeObjectSchema(schema) {
22694
22742
  }
22695
22743
  if (isZ4Schema(schema)) {
22696
22744
  const v4Schema = schema;
22697
- const def = (_a = v4Schema._zod) === null || _a === void 0 ? void 0 : _a.def;
22745
+ const def = v4Schema._zod?.def;
22698
22746
  if (def && (def.type === "object" || def.shape !== void 0)) {
22699
22747
  return schema;
22700
22748
  }
@@ -22719,38 +22767,30 @@ function getParseErrorMessage(error2) {
22719
22767
  }
22720
22768
  try {
22721
22769
  return JSON.stringify(error2);
22722
- } catch (_a) {
22770
+ } catch {
22723
22771
  return String(error2);
22724
22772
  }
22725
22773
  }
22726
22774
  return String(error2);
22727
22775
  }
22728
22776
  function getSchemaDescription(schema) {
22729
- var _a, _b, _c, _d;
22730
- if (isZ4Schema(schema)) {
22731
- const v4Schema = schema;
22732
- return (_b = (_a = v4Schema._zod) === null || _a === void 0 ? void 0 : _a.def) === null || _b === void 0 ? void 0 : _b.description;
22733
- }
22734
- const v3Schema = schema;
22735
- return (_c = schema.description) !== null && _c !== void 0 ? _c : (_d = v3Schema._def) === null || _d === void 0 ? void 0 : _d.description;
22777
+ return schema.description;
22736
22778
  }
22737
22779
  function isSchemaOptional(schema) {
22738
- var _a, _b, _c;
22739
22780
  if (isZ4Schema(schema)) {
22740
22781
  const v4Schema = schema;
22741
- return ((_b = (_a = v4Schema._zod) === null || _a === void 0 ? void 0 : _a.def) === null || _b === void 0 ? void 0 : _b.type) === "optional";
22782
+ return v4Schema._zod?.def?.type === "optional";
22742
22783
  }
22743
22784
  const v3Schema = schema;
22744
22785
  if (typeof schema.isOptional === "function") {
22745
22786
  return schema.isOptional();
22746
22787
  }
22747
- return ((_c = v3Schema._def) === null || _c === void 0 ? void 0 : _c.typeName) === "ZodOptional";
22788
+ return v3Schema._def?.typeName === "ZodOptional";
22748
22789
  }
22749
22790
  function getLiteralValue(schema) {
22750
- var _a;
22751
22791
  if (isZ4Schema(schema)) {
22752
22792
  const v4Schema = schema;
22753
- const def2 = (_a = v4Schema._zod) === null || _a === void 0 ? void 0 : _a.def;
22793
+ const def2 = v4Schema._zod?.def;
22754
22794
  if (def2) {
22755
22795
  if (def2.value !== void 0)
22756
22796
  return def2.value;
@@ -24074,21 +24114,20 @@ function mapMiniTarget(t) {
24074
24114
  return "draft-7";
24075
24115
  }
24076
24116
  function toJsonSchemaCompat(schema, opts) {
24077
- var _a, _b, _c;
24078
24117
  if (isZ4Schema(schema)) {
24079
24118
  return toJSONSchema(schema, {
24080
- target: mapMiniTarget(opts === null || opts === void 0 ? void 0 : opts.target),
24081
- io: (_a = opts === null || opts === void 0 ? void 0 : opts.pipeStrategy) !== null && _a !== void 0 ? _a : "input"
24119
+ target: mapMiniTarget(opts?.target),
24120
+ io: opts?.pipeStrategy ?? "input"
24082
24121
  });
24083
24122
  }
24084
24123
  return zodToJsonSchema(schema, {
24085
- strictUnions: (_b = opts === null || opts === void 0 ? void 0 : opts.strictUnions) !== null && _b !== void 0 ? _b : true,
24086
- pipeStrategy: (_c = opts === null || opts === void 0 ? void 0 : opts.pipeStrategy) !== null && _c !== void 0 ? _c : "input"
24124
+ strictUnions: opts?.strictUnions ?? true,
24125
+ pipeStrategy: opts?.pipeStrategy ?? "input"
24087
24126
  });
24088
24127
  }
24089
24128
  function getMethodLiteral(schema) {
24090
24129
  const shape = getObjectShape(schema);
24091
- const methodSchema = shape === null || shape === void 0 ? void 0 : shape.method;
24130
+ const methodSchema = shape?.method;
24092
24131
  if (!methodSchema) {
24093
24132
  throw new Error("Schema is missing a method literal");
24094
24133
  }
@@ -24132,8 +24171,8 @@ var Protocol = class {
24132
24171
  // Automatic pong by default.
24133
24172
  (_request) => ({})
24134
24173
  );
24135
- this._taskStore = _options === null || _options === void 0 ? void 0 : _options.taskStore;
24136
- this._taskMessageQueue = _options === null || _options === void 0 ? void 0 : _options.taskMessageQueue;
24174
+ this._taskStore = _options?.taskStore;
24175
+ this._taskMessageQueue = _options?.taskMessageQueue;
24137
24176
  if (this._taskStore) {
24138
24177
  this.setRequestHandler(GetTaskRequestSchema, async (request, extra) => {
24139
24178
  const task = await this._taskStore.getTask(request.params.taskId, extra.sessionId);
@@ -24146,7 +24185,6 @@ var Protocol = class {
24146
24185
  });
24147
24186
  this.setRequestHandler(GetTaskPayloadRequestSchema, async (request, extra) => {
24148
24187
  const handleTaskResult = async () => {
24149
- var _a;
24150
24188
  const taskId = request.params.taskId;
24151
24189
  if (this._taskMessageQueue) {
24152
24190
  let queuedMessage;
@@ -24170,7 +24208,7 @@ var Protocol = class {
24170
24208
  }
24171
24209
  continue;
24172
24210
  }
24173
- await ((_a = this._transport) === null || _a === void 0 ? void 0 : _a.send(queuedMessage.message, { relatedRequestId: extra.requestId }));
24211
+ await this._transport?.send(queuedMessage.message, { relatedRequestId: extra.requestId });
24174
24212
  }
24175
24213
  }
24176
24214
  const task = await this._taskStore.getTask(taskId, extra.sessionId);
@@ -24199,9 +24237,8 @@ var Protocol = class {
24199
24237
  return await handleTaskResult();
24200
24238
  });
24201
24239
  this.setRequestHandler(ListTasksRequestSchema, async (request, extra) => {
24202
- var _a;
24203
24240
  try {
24204
- const { tasks, nextCursor } = await this._taskStore.listTasks((_a = request.params) === null || _a === void 0 ? void 0 : _a.cursor, extra.sessionId);
24241
+ const { tasks, nextCursor } = await this._taskStore.listTasks(request.params?.cursor, extra.sessionId);
24205
24242
  return {
24206
24243
  tasks,
24207
24244
  nextCursor,
@@ -24240,8 +24277,11 @@ var Protocol = class {
24240
24277
  }
24241
24278
  }
24242
24279
  async _oncancel(notification) {
24280
+ if (!notification.params.requestId) {
24281
+ return;
24282
+ }
24243
24283
  const controller = this._requestHandlerAbortControllers.get(notification.params.requestId);
24244
- controller === null || controller === void 0 ? void 0 : controller.abort(notification.params.reason);
24284
+ controller?.abort(notification.params.reason);
24245
24285
  }
24246
24286
  _setupTimeout(messageId, timeout, maxTotalTimeout, onTimeout, resetTimeoutOnProgress = false) {
24247
24287
  this._timeoutInfo.set(messageId, {
@@ -24282,22 +24322,21 @@ var Protocol = class {
24282
24322
  * 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.
24283
24323
  */
24284
24324
  async connect(transport2) {
24285
- var _a, _b, _c;
24286
24325
  this._transport = transport2;
24287
- const _onclose = (_a = this.transport) === null || _a === void 0 ? void 0 : _a.onclose;
24326
+ const _onclose = this.transport?.onclose;
24288
24327
  this._transport.onclose = () => {
24289
- _onclose === null || _onclose === void 0 ? void 0 : _onclose();
24328
+ _onclose?.();
24290
24329
  this._onclose();
24291
24330
  };
24292
- const _onerror = (_b = this.transport) === null || _b === void 0 ? void 0 : _b.onerror;
24331
+ const _onerror = this.transport?.onerror;
24293
24332
  this._transport.onerror = (error2) => {
24294
- _onerror === null || _onerror === void 0 ? void 0 : _onerror(error2);
24333
+ _onerror?.(error2);
24295
24334
  this._onerror(error2);
24296
24335
  };
24297
- const _onmessage = (_c = this._transport) === null || _c === void 0 ? void 0 : _c.onmessage;
24336
+ const _onmessage = this._transport?.onmessage;
24298
24337
  this._transport.onmessage = (message, extra) => {
24299
- _onmessage === null || _onmessage === void 0 ? void 0 : _onmessage(message, extra);
24300
- if (isJSONRPCResponse(message) || isJSONRPCError(message)) {
24338
+ _onmessage?.(message, extra);
24339
+ if (isJSONRPCResultResponse(message) || isJSONRPCErrorResponse(message)) {
24301
24340
  this._onresponse(message);
24302
24341
  } else if (isJSONRPCRequest(message)) {
24303
24342
  this._onrequest(message, extra);
@@ -24310,7 +24349,6 @@ var Protocol = class {
24310
24349
  await this._transport.start();
24311
24350
  }
24312
24351
  _onclose() {
24313
- var _a;
24314
24352
  const responseHandlers = this._responseHandlers;
24315
24353
  this._responseHandlers = /* @__PURE__ */ new Map();
24316
24354
  this._progressHandlers.clear();
@@ -24318,28 +24356,25 @@ var Protocol = class {
24318
24356
  this._pendingDebouncedNotifications.clear();
24319
24357
  const error2 = McpError.fromError(ErrorCode.ConnectionClosed, "Connection closed");
24320
24358
  this._transport = void 0;
24321
- (_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this);
24359
+ this.onclose?.();
24322
24360
  for (const handler of responseHandlers.values()) {
24323
24361
  handler(error2);
24324
24362
  }
24325
24363
  }
24326
24364
  _onerror(error2) {
24327
- var _a;
24328
- (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error2);
24365
+ this.onerror?.(error2);
24329
24366
  }
24330
24367
  _onnotification(notification) {
24331
- var _a;
24332
- const handler = (_a = this._notificationHandlers.get(notification.method)) !== null && _a !== void 0 ? _a : this.fallbackNotificationHandler;
24368
+ const handler = this._notificationHandlers.get(notification.method) ?? this.fallbackNotificationHandler;
24333
24369
  if (handler === void 0) {
24334
24370
  return;
24335
24371
  }
24336
24372
  Promise.resolve().then(() => handler(notification)).catch((error2) => this._onerror(new Error(`Uncaught error in notification handler: ${error2}`)));
24337
24373
  }
24338
24374
  _onrequest(request, extra) {
24339
- var _a, _b, _c, _d, _e, _f;
24340
- const handler = (_a = this._requestHandlers.get(request.method)) !== null && _a !== void 0 ? _a : this.fallbackRequestHandler;
24375
+ const handler = this._requestHandlers.get(request.method) ?? this.fallbackRequestHandler;
24341
24376
  const capturedTransport = this._transport;
24342
- const relatedTaskId = (_d = (_c = (_b = request.params) === null || _b === void 0 ? void 0 : _b._meta) === null || _c === void 0 ? void 0 : _c[RELATED_TASK_META_KEY]) === null || _d === void 0 ? void 0 : _d.taskId;
24377
+ const relatedTaskId = request.params?._meta?.[RELATED_TASK_META_KEY]?.taskId;
24343
24378
  if (handler === void 0) {
24344
24379
  const errorResponse = {
24345
24380
  jsonrpc: "2.0",
@@ -24354,20 +24389,20 @@ var Protocol = class {
24354
24389
  type: "error",
24355
24390
  message: errorResponse,
24356
24391
  timestamp: Date.now()
24357
- }, capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.sessionId).catch((error2) => this._onerror(new Error(`Failed to enqueue error response: ${error2}`)));
24392
+ }, capturedTransport?.sessionId).catch((error2) => this._onerror(new Error(`Failed to enqueue error response: ${error2}`)));
24358
24393
  } else {
24359
- capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.send(errorResponse).catch((error2) => this._onerror(new Error(`Failed to send an error response: ${error2}`)));
24394
+ capturedTransport?.send(errorResponse).catch((error2) => this._onerror(new Error(`Failed to send an error response: ${error2}`)));
24360
24395
  }
24361
24396
  return;
24362
24397
  }
24363
24398
  const abortController = new AbortController();
24364
24399
  this._requestHandlerAbortControllers.set(request.id, abortController);
24365
- const taskCreationParams = (_e = request.params) === null || _e === void 0 ? void 0 : _e.task;
24366
- const taskStore = this._taskStore ? this.requestTaskStore(request, capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.sessionId) : void 0;
24400
+ const taskCreationParams = isTaskAugmentedRequestParams(request.params) ? request.params.task : void 0;
24401
+ const taskStore = this._taskStore ? this.requestTaskStore(request, capturedTransport?.sessionId) : void 0;
24367
24402
  const fullExtra = {
24368
24403
  signal: abortController.signal,
24369
- sessionId: capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.sessionId,
24370
- _meta: (_f = request.params) === null || _f === void 0 ? void 0 : _f._meta,
24404
+ sessionId: capturedTransport?.sessionId,
24405
+ _meta: request.params?._meta,
24371
24406
  sendNotification: async (notification) => {
24372
24407
  const notificationOptions = { relatedRequestId: request.id };
24373
24408
  if (relatedTaskId) {
@@ -24376,25 +24411,24 @@ var Protocol = class {
24376
24411
  await this.notification(notification, notificationOptions);
24377
24412
  },
24378
24413
  sendRequest: async (r, resultSchema, options) => {
24379
- var _a2, _b2;
24380
24414
  const requestOptions = { ...options, relatedRequestId: request.id };
24381
24415
  if (relatedTaskId && !requestOptions.relatedTask) {
24382
24416
  requestOptions.relatedTask = { taskId: relatedTaskId };
24383
24417
  }
24384
- const effectiveTaskId = (_b2 = (_a2 = requestOptions.relatedTask) === null || _a2 === void 0 ? void 0 : _a2.taskId) !== null && _b2 !== void 0 ? _b2 : relatedTaskId;
24418
+ const effectiveTaskId = requestOptions.relatedTask?.taskId ?? relatedTaskId;
24385
24419
  if (effectiveTaskId && taskStore) {
24386
24420
  await taskStore.updateTaskStatus(effectiveTaskId, "input_required");
24387
24421
  }
24388
24422
  return await this.request(r, resultSchema, requestOptions);
24389
24423
  },
24390
- authInfo: extra === null || extra === void 0 ? void 0 : extra.authInfo,
24424
+ authInfo: extra?.authInfo,
24391
24425
  requestId: request.id,
24392
- requestInfo: extra === null || extra === void 0 ? void 0 : extra.requestInfo,
24426
+ requestInfo: extra?.requestInfo,
24393
24427
  taskId: relatedTaskId,
24394
24428
  taskStore,
24395
- taskRequestedTtl: taskCreationParams === null || taskCreationParams === void 0 ? void 0 : taskCreationParams.ttl,
24396
- closeSSEStream: extra === null || extra === void 0 ? void 0 : extra.closeSSEStream,
24397
- closeStandaloneSSEStream: extra === null || extra === void 0 ? void 0 : extra.closeStandaloneSSEStream
24429
+ taskRequestedTtl: taskCreationParams?.ttl,
24430
+ closeSSEStream: extra?.closeSSEStream,
24431
+ closeStandaloneSSEStream: extra?.closeStandaloneSSEStream
24398
24432
  };
24399
24433
  Promise.resolve().then(() => {
24400
24434
  if (taskCreationParams) {
@@ -24414,12 +24448,11 @@ var Protocol = class {
24414
24448
  type: "response",
24415
24449
  message: response,
24416
24450
  timestamp: Date.now()
24417
- }, capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.sessionId);
24451
+ }, capturedTransport?.sessionId);
24418
24452
  } else {
24419
- await (capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.send(response));
24453
+ await capturedTransport?.send(response);
24420
24454
  }
24421
24455
  }, async (error2) => {
24422
- var _a2;
24423
24456
  if (abortController.signal.aborted) {
24424
24457
  return;
24425
24458
  }
@@ -24428,7 +24461,7 @@ var Protocol = class {
24428
24461
  id: request.id,
24429
24462
  error: {
24430
24463
  code: Number.isSafeInteger(error2["code"]) ? error2["code"] : ErrorCode.InternalError,
24431
- message: (_a2 = error2.message) !== null && _a2 !== void 0 ? _a2 : "Internal error",
24464
+ message: error2.message ?? "Internal error",
24432
24465
  ...error2["data"] !== void 0 && { data: error2["data"] }
24433
24466
  }
24434
24467
  };
@@ -24437,9 +24470,9 @@ var Protocol = class {
24437
24470
  type: "error",
24438
24471
  message: errorResponse,
24439
24472
  timestamp: Date.now()
24440
- }, capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.sessionId);
24473
+ }, capturedTransport?.sessionId);
24441
24474
  } else {
24442
- await (capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.send(errorResponse));
24475
+ await capturedTransport?.send(errorResponse);
24443
24476
  }
24444
24477
  }).catch((error2) => this._onerror(new Error(`Failed to send response: ${error2}`))).finally(() => {
24445
24478
  this._requestHandlerAbortControllers.delete(request.id);
@@ -24473,7 +24506,7 @@ var Protocol = class {
24473
24506
  const resolver = this._requestResolvers.get(messageId);
24474
24507
  if (resolver) {
24475
24508
  this._requestResolvers.delete(messageId);
24476
- if (isJSONRPCResponse(response)) {
24509
+ if (isJSONRPCResultResponse(response)) {
24477
24510
  resolver(response);
24478
24511
  } else {
24479
24512
  const error2 = new McpError(response.error.code, response.error.message, response.error.data);
@@ -24489,7 +24522,7 @@ var Protocol = class {
24489
24522
  this._responseHandlers.delete(messageId);
24490
24523
  this._cleanupTimeout(messageId);
24491
24524
  let isTaskResponse = false;
24492
- if (isJSONRPCResponse(response) && response.result && typeof response.result === "object") {
24525
+ if (isJSONRPCResultResponse(response) && response.result && typeof response.result === "object") {
24493
24526
  const result = response.result;
24494
24527
  if (result.task && typeof result.task === "object") {
24495
24528
  const task = result.task;
@@ -24502,7 +24535,7 @@ var Protocol = class {
24502
24535
  if (!isTaskResponse) {
24503
24536
  this._progressHandlers.delete(messageId);
24504
24537
  }
24505
- if (isJSONRPCResponse(response)) {
24538
+ if (isJSONRPCResultResponse(response)) {
24506
24539
  handler(response);
24507
24540
  } else {
24508
24541
  const error2 = McpError.fromError(response.error.code, response.error.message, response.error.data);
@@ -24516,8 +24549,7 @@ var Protocol = class {
24516
24549
  * Closes the connection.
24517
24550
  */
24518
24551
  async close() {
24519
- var _a;
24520
- await ((_a = this._transport) === null || _a === void 0 ? void 0 : _a.close());
24552
+ await this._transport?.close();
24521
24553
  }
24522
24554
  /**
24523
24555
  * Sends a request and returns an AsyncGenerator that yields response messages.
@@ -24547,8 +24579,7 @@ var Protocol = class {
24547
24579
  * @experimental Use `client.experimental.tasks.requestStream()` to access this method.
24548
24580
  */
24549
24581
  async *requestStream(request, resultSchema, options) {
24550
- var _a, _b, _c, _d;
24551
- const { task } = options !== null && options !== void 0 ? options : {};
24582
+ const { task } = options ?? {};
24552
24583
  if (!task) {
24553
24584
  try {
24554
24585
  const result = await this.request(request, resultSchema, options);
@@ -24595,9 +24626,9 @@ var Protocol = class {
24595
24626
  yield { type: "result", result };
24596
24627
  return;
24597
24628
  }
24598
- const pollInterval = (_c = (_a = task2.pollInterval) !== null && _a !== void 0 ? _a : (_b = this._options) === null || _b === void 0 ? void 0 : _b.defaultTaskPollInterval) !== null && _c !== void 0 ? _c : 1e3;
24629
+ const pollInterval = task2.pollInterval ?? this._options?.defaultTaskPollInterval ?? 1e3;
24599
24630
  await new Promise((resolve) => setTimeout(resolve, pollInterval));
24600
- (_d = options === null || options === void 0 ? void 0 : options.signal) === null || _d === void 0 ? void 0 : _d.throwIfAborted();
24631
+ options?.signal?.throwIfAborted();
24601
24632
  }
24602
24633
  } catch (error2) {
24603
24634
  yield {
@@ -24612,9 +24643,8 @@ var Protocol = class {
24612
24643
  * Do not use this method to emit notifications! Use notification() instead.
24613
24644
  */
24614
24645
  request(request, resultSchema, options) {
24615
- const { relatedRequestId, resumptionToken, onresumptiontoken, task, relatedTask } = options !== null && options !== void 0 ? options : {};
24646
+ const { relatedRequestId, resumptionToken, onresumptiontoken, task, relatedTask } = options ?? {};
24616
24647
  return new Promise((resolve, reject) => {
24617
- var _a, _b, _c, _d, _e, _f, _g;
24618
24648
  const earlyReject = (error2) => {
24619
24649
  reject(error2);
24620
24650
  };
@@ -24622,7 +24652,7 @@ var Protocol = class {
24622
24652
  earlyReject(new Error("Not connected"));
24623
24653
  return;
24624
24654
  }
24625
- if (((_a = this._options) === null || _a === void 0 ? void 0 : _a.enforceStrictCapabilities) === true) {
24655
+ if (this._options?.enforceStrictCapabilities === true) {
24626
24656
  try {
24627
24657
  this.assertCapabilityForMethod(request.method);
24628
24658
  if (task) {
@@ -24633,19 +24663,19 @@ var Protocol = class {
24633
24663
  return;
24634
24664
  }
24635
24665
  }
24636
- (_b = options === null || options === void 0 ? void 0 : options.signal) === null || _b === void 0 ? void 0 : _b.throwIfAborted();
24666
+ options?.signal?.throwIfAborted();
24637
24667
  const messageId = this._requestMessageId++;
24638
24668
  const jsonrpcRequest = {
24639
24669
  ...request,
24640
24670
  jsonrpc: "2.0",
24641
24671
  id: messageId
24642
24672
  };
24643
- if (options === null || options === void 0 ? void 0 : options.onprogress) {
24673
+ if (options?.onprogress) {
24644
24674
  this._progressHandlers.set(messageId, options.onprogress);
24645
24675
  jsonrpcRequest.params = {
24646
24676
  ...request.params,
24647
24677
  _meta: {
24648
- ...((_c = request.params) === null || _c === void 0 ? void 0 : _c._meta) || {},
24678
+ ...request.params?._meta || {},
24649
24679
  progressToken: messageId
24650
24680
  }
24651
24681
  };
@@ -24660,17 +24690,16 @@ var Protocol = class {
24660
24690
  jsonrpcRequest.params = {
24661
24691
  ...jsonrpcRequest.params,
24662
24692
  _meta: {
24663
- ...((_d = jsonrpcRequest.params) === null || _d === void 0 ? void 0 : _d._meta) || {},
24693
+ ...jsonrpcRequest.params?._meta || {},
24664
24694
  [RELATED_TASK_META_KEY]: relatedTask
24665
24695
  }
24666
24696
  };
24667
24697
  }
24668
24698
  const cancel = (reason) => {
24669
- var _a2;
24670
24699
  this._responseHandlers.delete(messageId);
24671
24700
  this._progressHandlers.delete(messageId);
24672
24701
  this._cleanupTimeout(messageId);
24673
- (_a2 = this._transport) === null || _a2 === void 0 ? void 0 : _a2.send({
24702
+ this._transport?.send({
24674
24703
  jsonrpc: "2.0",
24675
24704
  method: "notifications/cancelled",
24676
24705
  params: {
@@ -24682,8 +24711,7 @@ var Protocol = class {
24682
24711
  reject(error2);
24683
24712
  };
24684
24713
  this._responseHandlers.set(messageId, (response) => {
24685
- var _a2;
24686
- if ((_a2 = options === null || options === void 0 ? void 0 : options.signal) === null || _a2 === void 0 ? void 0 : _a2.aborted) {
24714
+ if (options?.signal?.aborted) {
24687
24715
  return;
24688
24716
  }
24689
24717
  if (response instanceof Error) {
@@ -24700,14 +24728,13 @@ var Protocol = class {
24700
24728
  reject(error2);
24701
24729
  }
24702
24730
  });
24703
- (_e = options === null || options === void 0 ? void 0 : options.signal) === null || _e === void 0 ? void 0 : _e.addEventListener("abort", () => {
24704
- var _a2;
24705
- cancel((_a2 = options === null || options === void 0 ? void 0 : options.signal) === null || _a2 === void 0 ? void 0 : _a2.reason);
24731
+ options?.signal?.addEventListener("abort", () => {
24732
+ cancel(options?.signal?.reason);
24706
24733
  });
24707
- const timeout = (_f = options === null || options === void 0 ? void 0 : options.timeout) !== null && _f !== void 0 ? _f : DEFAULT_REQUEST_TIMEOUT_MSEC;
24734
+ const timeout = options?.timeout ?? DEFAULT_REQUEST_TIMEOUT_MSEC;
24708
24735
  const timeoutHandler = () => cancel(McpError.fromError(ErrorCode.RequestTimeout, "Request timed out", { timeout }));
24709
- 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);
24710
- const relatedTaskId = relatedTask === null || relatedTask === void 0 ? void 0 : relatedTask.taskId;
24736
+ this._setupTimeout(messageId, timeout, options?.maxTotalTimeout, timeoutHandler, options?.resetTimeoutOnProgress ?? false);
24737
+ const relatedTaskId = relatedTask?.taskId;
24711
24738
  if (relatedTaskId) {
24712
24739
  const responseResolver = (response) => {
24713
24740
  const handler = this._responseHandlers.get(messageId);
@@ -24770,12 +24797,11 @@ var Protocol = class {
24770
24797
  * Emits a notification, which is a one-way message that does not expect a response.
24771
24798
  */
24772
24799
  async notification(notification, options) {
24773
- var _a, _b, _c, _d, _e;
24774
24800
  if (!this._transport) {
24775
24801
  throw new Error("Not connected");
24776
24802
  }
24777
24803
  this.assertNotificationCapability(notification.method);
24778
- const relatedTaskId = (_a = options === null || options === void 0 ? void 0 : options.relatedTask) === null || _a === void 0 ? void 0 : _a.taskId;
24804
+ const relatedTaskId = options?.relatedTask?.taskId;
24779
24805
  if (relatedTaskId) {
24780
24806
  const jsonrpcNotification2 = {
24781
24807
  ...notification,
@@ -24783,7 +24809,7 @@ var Protocol = class {
24783
24809
  params: {
24784
24810
  ...notification.params,
24785
24811
  _meta: {
24786
- ...((_b = notification.params) === null || _b === void 0 ? void 0 : _b._meta) || {},
24812
+ ...notification.params?._meta || {},
24787
24813
  [RELATED_TASK_META_KEY]: options.relatedTask
24788
24814
  }
24789
24815
  }
@@ -24795,15 +24821,14 @@ var Protocol = class {
24795
24821
  });
24796
24822
  return;
24797
24823
  }
24798
- const debouncedMethods = (_d = (_c = this._options) === null || _c === void 0 ? void 0 : _c.debouncedNotificationMethods) !== null && _d !== void 0 ? _d : [];
24799
- 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);
24824
+ const debouncedMethods = this._options?.debouncedNotificationMethods ?? [];
24825
+ const canDebounce = debouncedMethods.includes(notification.method) && !notification.params && !options?.relatedRequestId && !options?.relatedTask;
24800
24826
  if (canDebounce) {
24801
24827
  if (this._pendingDebouncedNotifications.has(notification.method)) {
24802
24828
  return;
24803
24829
  }
24804
24830
  this._pendingDebouncedNotifications.add(notification.method);
24805
24831
  Promise.resolve().then(() => {
24806
- var _a2, _b2;
24807
24832
  this._pendingDebouncedNotifications.delete(notification.method);
24808
24833
  if (!this._transport) {
24809
24834
  return;
@@ -24812,19 +24837,19 @@ var Protocol = class {
24812
24837
  ...notification,
24813
24838
  jsonrpc: "2.0"
24814
24839
  };
24815
- if (options === null || options === void 0 ? void 0 : options.relatedTask) {
24840
+ if (options?.relatedTask) {
24816
24841
  jsonrpcNotification2 = {
24817
24842
  ...jsonrpcNotification2,
24818
24843
  params: {
24819
24844
  ...jsonrpcNotification2.params,
24820
24845
  _meta: {
24821
- ...((_a2 = jsonrpcNotification2.params) === null || _a2 === void 0 ? void 0 : _a2._meta) || {},
24846
+ ...jsonrpcNotification2.params?._meta || {},
24822
24847
  [RELATED_TASK_META_KEY]: options.relatedTask
24823
24848
  }
24824
24849
  }
24825
24850
  };
24826
24851
  }
24827
- (_b2 = this._transport) === null || _b2 === void 0 ? void 0 : _b2.send(jsonrpcNotification2, options).catch((error2) => this._onerror(error2));
24852
+ this._transport?.send(jsonrpcNotification2, options).catch((error2) => this._onerror(error2));
24828
24853
  });
24829
24854
  return;
24830
24855
  }
@@ -24832,13 +24857,13 @@ var Protocol = class {
24832
24857
  ...notification,
24833
24858
  jsonrpc: "2.0"
24834
24859
  };
24835
- if (options === null || options === void 0 ? void 0 : options.relatedTask) {
24860
+ if (options?.relatedTask) {
24836
24861
  jsonrpcNotification = {
24837
24862
  ...jsonrpcNotification,
24838
24863
  params: {
24839
24864
  ...jsonrpcNotification.params,
24840
24865
  _meta: {
24841
- ...((_e = jsonrpcNotification.params) === null || _e === void 0 ? void 0 : _e._meta) || {},
24866
+ ...jsonrpcNotification.params?._meta || {},
24842
24867
  [RELATED_TASK_META_KEY]: options.relatedTask
24843
24868
  }
24844
24869
  }
@@ -24914,11 +24939,10 @@ var Protocol = class {
24914
24939
  * simply propagates the error.
24915
24940
  */
24916
24941
  async _enqueueTaskMessage(taskId, message, sessionId) {
24917
- var _a;
24918
24942
  if (!this._taskStore || !this._taskMessageQueue) {
24919
24943
  throw new Error("Cannot enqueue task message: taskStore and taskMessageQueue are not configured");
24920
24944
  }
24921
- const maxQueueSize = (_a = this._options) === null || _a === void 0 ? void 0 : _a.maxTaskQueueSize;
24945
+ const maxQueueSize = this._options?.maxTaskQueueSize;
24922
24946
  await this._taskMessageQueue.enqueue(taskId, message, sessionId, maxQueueSize);
24923
24947
  }
24924
24948
  /**
@@ -24951,14 +24975,13 @@ var Protocol = class {
24951
24975
  * @returns Promise that resolves when an update occurs or rejects if aborted
24952
24976
  */
24953
24977
  async _waitForTaskUpdate(taskId, signal) {
24954
- var _a, _b, _c;
24955
- let interval = (_b = (_a = this._options) === null || _a === void 0 ? void 0 : _a.defaultTaskPollInterval) !== null && _b !== void 0 ? _b : 1e3;
24978
+ let interval = this._options?.defaultTaskPollInterval ?? 1e3;
24956
24979
  try {
24957
- const task = await ((_c = this._taskStore) === null || _c === void 0 ? void 0 : _c.getTask(taskId));
24958
- if (task === null || task === void 0 ? void 0 : task.pollInterval) {
24980
+ const task = await this._taskStore?.getTask(taskId);
24981
+ if (task?.pollInterval) {
24959
24982
  interval = task.pollInterval;
24960
24983
  }
24961
- } catch (_d) {
24984
+ } catch {
24962
24985
  }
24963
24986
  return new Promise((resolve, reject) => {
24964
24987
  if (signal.aborted) {
@@ -25062,7 +25085,7 @@ function mergeCapabilities(base, additional) {
25062
25085
  var import_ajv = __toESM(require_ajv(), 1);
25063
25086
  var import_ajv_formats = __toESM(require_dist(), 1);
25064
25087
  function createDefaultAjvInstance() {
25065
- const ajv = new import_ajv.Ajv({
25088
+ const ajv = new import_ajv.default({
25066
25089
  strict: false,
25067
25090
  validateFormats: true,
25068
25091
  validateSchema: false,
@@ -25094,7 +25117,7 @@ var AjvJsonSchemaValidator = class {
25094
25117
  * ```
25095
25118
  */
25096
25119
  constructor(ajv) {
25097
- this._ajv = ajv !== null && ajv !== void 0 ? ajv : createDefaultAjvInstance();
25120
+ this._ajv = ajv ?? createDefaultAjvInstance();
25098
25121
  }
25099
25122
  /**
25100
25123
  * Create a validator for the given JSON Schema
@@ -25106,8 +25129,7 @@ var AjvJsonSchemaValidator = class {
25106
25129
  * @returns A validator function that validates input data
25107
25130
  */
25108
25131
  getValidator(schema) {
25109
- var _a;
25110
- const ajvValidator = "$id" in schema && typeof schema.$id === "string" ? (_a = this._ajv.getSchema(schema.$id)) !== null && _a !== void 0 ? _a : this._ajv.compile(schema) : this._ajv.compile(schema);
25132
+ const ajvValidator = "$id" in schema && typeof schema.$id === "string" ? this._ajv.getSchema(schema.$id) ?? this._ajv.compile(schema) : this._ajv.compile(schema);
25111
25133
  return (input) => {
25112
25134
  const valid = ajvValidator(input);
25113
25135
  if (valid) {
@@ -25201,13 +25223,12 @@ var ExperimentalServerTasks = class {
25201
25223
 
25202
25224
  // node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/helpers.js
25203
25225
  function assertToolsCallTaskCapability(requests, method, entityName) {
25204
- var _a;
25205
25226
  if (!requests) {
25206
25227
  throw new Error(`${entityName} does not support task creation (required for ${method})`);
25207
25228
  }
25208
25229
  switch (method) {
25209
25230
  case "tools/call":
25210
- if (!((_a = requests.tools) === null || _a === void 0 ? void 0 : _a.call)) {
25231
+ if (!requests.tools?.call) {
25211
25232
  throw new Error(`${entityName} does not support task creation for tools/call (required for ${method})`);
25212
25233
  }
25213
25234
  break;
@@ -25216,18 +25237,17 @@ function assertToolsCallTaskCapability(requests, method, entityName) {
25216
25237
  }
25217
25238
  }
25218
25239
  function assertClientRequestTaskCapability(requests, method, entityName) {
25219
- var _a, _b;
25220
25240
  if (!requests) {
25221
25241
  throw new Error(`${entityName} does not support task creation (required for ${method})`);
25222
25242
  }
25223
25243
  switch (method) {
25224
25244
  case "sampling/createMessage":
25225
- if (!((_a = requests.sampling) === null || _a === void 0 ? void 0 : _a.createMessage)) {
25245
+ if (!requests.sampling?.createMessage) {
25226
25246
  throw new Error(`${entityName} does not support task creation for sampling/createMessage (required for ${method})`);
25227
25247
  }
25228
25248
  break;
25229
25249
  case "elicitation/create":
25230
- if (!((_b = requests.elicitation) === null || _b === void 0 ? void 0 : _b.create)) {
25250
+ if (!requests.elicitation?.create) {
25231
25251
  throw new Error(`${entityName} does not support task creation for elicitation/create (required for ${method})`);
25232
25252
  }
25233
25253
  break;
@@ -25242,7 +25262,6 @@ var Server = class extends Protocol {
25242
25262
  * Initializes this server with the given name and version information.
25243
25263
  */
25244
25264
  constructor(_serverInfo, options) {
25245
- var _a, _b;
25246
25265
  super(options);
25247
25266
  this._serverInfo = _serverInfo;
25248
25267
  this._loggingLevels = /* @__PURE__ */ new Map();
@@ -25251,18 +25270,14 @@ var Server = class extends Protocol {
25251
25270
  const currentLevel = this._loggingLevels.get(sessionId);
25252
25271
  return currentLevel ? this.LOG_LEVEL_SEVERITY.get(level) < this.LOG_LEVEL_SEVERITY.get(currentLevel) : false;
25253
25272
  };
25254
- this._capabilities = (_a = options === null || options === void 0 ? void 0 : options.capabilities) !== null && _a !== void 0 ? _a : {};
25255
- this._instructions = options === null || options === void 0 ? void 0 : options.instructions;
25256
- this._jsonSchemaValidator = (_b = options === null || options === void 0 ? void 0 : options.jsonSchemaValidator) !== null && _b !== void 0 ? _b : new AjvJsonSchemaValidator();
25273
+ this._capabilities = options?.capabilities ?? {};
25274
+ this._instructions = options?.instructions;
25275
+ this._jsonSchemaValidator = options?.jsonSchemaValidator ?? new AjvJsonSchemaValidator();
25257
25276
  this.setRequestHandler(InitializeRequestSchema, (request) => this._oninitialize(request));
25258
- this.setNotificationHandler(InitializedNotificationSchema, () => {
25259
- var _a2;
25260
- return (_a2 = this.oninitialized) === null || _a2 === void 0 ? void 0 : _a2.call(this);
25261
- });
25277
+ this.setNotificationHandler(InitializedNotificationSchema, () => this.oninitialized?.());
25262
25278
  if (this._capabilities.logging) {
25263
25279
  this.setRequestHandler(SetLevelRequestSchema, async (request, extra) => {
25264
- var _a2;
25265
- const transportSessionId = extra.sessionId || ((_a2 = extra.requestInfo) === null || _a2 === void 0 ? void 0 : _a2.headers["mcp-session-id"]) || void 0;
25280
+ const transportSessionId = extra.sessionId || extra.requestInfo?.headers["mcp-session-id"] || void 0;
25266
25281
  const { level } = request.params;
25267
25282
  const parseResult = LoggingLevelSchema.safeParse(level);
25268
25283
  if (parseResult.success) {
@@ -25302,21 +25317,20 @@ var Server = class extends Protocol {
25302
25317
  * Override request handler registration to enforce server-side validation for tools/call.
25303
25318
  */
25304
25319
  setRequestHandler(requestSchema, handler) {
25305
- var _a, _b, _c;
25306
25320
  const shape = getObjectShape(requestSchema);
25307
- const methodSchema = shape === null || shape === void 0 ? void 0 : shape.method;
25321
+ const methodSchema = shape?.method;
25308
25322
  if (!methodSchema) {
25309
25323
  throw new Error("Schema is missing a method literal");
25310
25324
  }
25311
25325
  let methodValue;
25312
25326
  if (isZ4Schema(methodSchema)) {
25313
25327
  const v4Schema = methodSchema;
25314
- const v4Def = (_a = v4Schema._zod) === null || _a === void 0 ? void 0 : _a.def;
25315
- methodValue = (_b = v4Def === null || v4Def === void 0 ? void 0 : v4Def.value) !== null && _b !== void 0 ? _b : v4Schema.value;
25328
+ const v4Def = v4Schema._zod?.def;
25329
+ methodValue = v4Def?.value ?? v4Schema.value;
25316
25330
  } else {
25317
25331
  const v3Schema = methodSchema;
25318
25332
  const legacyDef = v3Schema._def;
25319
- methodValue = (_c = legacyDef === null || legacyDef === void 0 ? void 0 : legacyDef.value) !== null && _c !== void 0 ? _c : v3Schema.value;
25333
+ methodValue = legacyDef?.value ?? v3Schema.value;
25320
25334
  }
25321
25335
  if (typeof methodValue !== "string") {
25322
25336
  throw new Error("Schema method literal must be a string");
@@ -25351,20 +25365,19 @@ var Server = class extends Protocol {
25351
25365
  return super.setRequestHandler(requestSchema, handler);
25352
25366
  }
25353
25367
  assertCapabilityForMethod(method) {
25354
- var _a, _b, _c;
25355
25368
  switch (method) {
25356
25369
  case "sampling/createMessage":
25357
- if (!((_a = this._clientCapabilities) === null || _a === void 0 ? void 0 : _a.sampling)) {
25370
+ if (!this._clientCapabilities?.sampling) {
25358
25371
  throw new Error(`Client does not support sampling (required for ${method})`);
25359
25372
  }
25360
25373
  break;
25361
25374
  case "elicitation/create":
25362
- if (!((_b = this._clientCapabilities) === null || _b === void 0 ? void 0 : _b.elicitation)) {
25375
+ if (!this._clientCapabilities?.elicitation) {
25363
25376
  throw new Error(`Client does not support elicitation (required for ${method})`);
25364
25377
  }
25365
25378
  break;
25366
25379
  case "roots/list":
25367
- if (!((_c = this._clientCapabilities) === null || _c === void 0 ? void 0 : _c.roots)) {
25380
+ if (!this._clientCapabilities?.roots) {
25368
25381
  throw new Error(`Client does not support listing roots (required for ${method})`);
25369
25382
  }
25370
25383
  break;
@@ -25373,7 +25386,6 @@ var Server = class extends Protocol {
25373
25386
  }
25374
25387
  }
25375
25388
  assertNotificationCapability(method) {
25376
- var _a, _b;
25377
25389
  switch (method) {
25378
25390
  case "notifications/message":
25379
25391
  if (!this._capabilities.logging) {
@@ -25397,7 +25409,7 @@ var Server = class extends Protocol {
25397
25409
  }
25398
25410
  break;
25399
25411
  case "notifications/elicitation/complete":
25400
- if (!((_b = (_a = this._clientCapabilities) === null || _a === void 0 ? void 0 : _a.elicitation) === null || _b === void 0 ? void 0 : _b.url)) {
25412
+ if (!this._clientCapabilities?.elicitation?.url) {
25401
25413
  throw new Error(`Client does not support URL elicitation (required for ${method})`);
25402
25414
  }
25403
25415
  break;
@@ -25455,15 +25467,13 @@ var Server = class extends Protocol {
25455
25467
  }
25456
25468
  }
25457
25469
  assertTaskCapability(method) {
25458
- var _a, _b;
25459
- assertClientRequestTaskCapability((_b = (_a = this._clientCapabilities) === null || _a === void 0 ? void 0 : _a.tasks) === null || _b === void 0 ? void 0 : _b.requests, method, "Client");
25470
+ assertClientRequestTaskCapability(this._clientCapabilities?.tasks?.requests, method, "Client");
25460
25471
  }
25461
25472
  assertTaskHandlerCapability(method) {
25462
- var _a;
25463
25473
  if (!this._capabilities) {
25464
25474
  return;
25465
25475
  }
25466
- assertToolsCallTaskCapability((_a = this._capabilities.tasks) === null || _a === void 0 ? void 0 : _a.requests, method, "Server");
25476
+ assertToolsCallTaskCapability(this._capabilities.tasks?.requests, method, "Server");
25467
25477
  }
25468
25478
  async _oninitialize(request) {
25469
25479
  const requestedVersion = request.params.protocolVersion;
@@ -25497,9 +25507,8 @@ var Server = class extends Protocol {
25497
25507
  }
25498
25508
  // Implementation
25499
25509
  async createMessage(params, options) {
25500
- var _a, _b;
25501
25510
  if (params.tools || params.toolChoice) {
25502
- if (!((_b = (_a = this._clientCapabilities) === null || _a === void 0 ? void 0 : _a.sampling) === null || _b === void 0 ? void 0 : _b.tools)) {
25511
+ if (!this._clientCapabilities?.sampling?.tools) {
25503
25512
  throw new Error("Client does not support sampling tools capability.");
25504
25513
  }
25505
25514
  }
@@ -25539,18 +25548,17 @@ var Server = class extends Protocol {
25539
25548
  * @returns The result of the elicitation request.
25540
25549
  */
25541
25550
  async elicitInput(params, options) {
25542
- var _a, _b, _c, _d, _e;
25543
- const mode = (_a = params.mode) !== null && _a !== void 0 ? _a : "form";
25551
+ const mode = params.mode ?? "form";
25544
25552
  switch (mode) {
25545
25553
  case "url": {
25546
- if (!((_c = (_b = this._clientCapabilities) === null || _b === void 0 ? void 0 : _b.elicitation) === null || _c === void 0 ? void 0 : _c.url)) {
25554
+ if (!this._clientCapabilities?.elicitation?.url) {
25547
25555
  throw new Error("Client does not support url elicitation.");
25548
25556
  }
25549
25557
  const urlParams = params;
25550
25558
  return this.request({ method: "elicitation/create", params: urlParams }, ElicitResultSchema, options);
25551
25559
  }
25552
25560
  case "form": {
25553
- if (!((_e = (_d = this._clientCapabilities) === null || _d === void 0 ? void 0 : _d.elicitation) === null || _e === void 0 ? void 0 : _e.form)) {
25561
+ if (!this._clientCapabilities?.elicitation?.form) {
25554
25562
  throw new Error("Client does not support form elicitation.");
25555
25563
  }
25556
25564
  const formParams = params.mode === "form" ? params : { ...params, mode: "form" };
@@ -25582,8 +25590,7 @@ var Server = class extends Protocol {
25582
25590
  * @returns A function that emits the completion notification when awaited.
25583
25591
  */
25584
25592
  createElicitationCompletionNotifier(elicitationId, options) {
25585
- var _a, _b;
25586
- if (!((_b = (_a = this._clientCapabilities) === null || _a === void 0 ? void 0 : _a.elicitation) === null || _b === void 0 ? void 0 : _b.url)) {
25593
+ if (!this._clientCapabilities?.elicitation?.url) {
25587
25594
  throw new Error("Client does not support URL elicitation (required for notifications/elicitation/complete)");
25588
25595
  }
25589
25596
  return () => this.notification({
@@ -25636,7 +25643,7 @@ function isCompletable(schema) {
25636
25643
  }
25637
25644
  function getCompleter(schema) {
25638
25645
  const meta = schema[COMPLETABLE_SYMBOL];
25639
- return meta === null || meta === void 0 ? void 0 : meta.complete;
25646
+ return meta?.complete;
25640
25647
  }
25641
25648
  var McpZodTypeKind;
25642
25649
  (function(McpZodTypeKind2) {
@@ -25799,7 +25806,6 @@ var McpServer = class {
25799
25806
  })
25800
25807
  }));
25801
25808
  this.server.setRequestHandler(CallToolRequestSchema, async (request, extra) => {
25802
- var _a;
25803
25809
  try {
25804
25810
  const tool = this._registeredTools[request.params.name];
25805
25811
  if (!tool) {
@@ -25809,7 +25815,7 @@ var McpServer = class {
25809
25815
  throw new McpError(ErrorCode.InvalidParams, `Tool ${request.params.name} disabled`);
25810
25816
  }
25811
25817
  const isTaskRequest = !!request.params.task;
25812
- const taskSupport = (_a = tool.execution) === null || _a === void 0 ? void 0 : _a.taskSupport;
25818
+ const taskSupport = tool.execution?.taskSupport;
25813
25819
  const isTaskHandler = "createTask" in tool.handler;
25814
25820
  if ((taskSupport === "required" || taskSupport === "optional") && !isTaskHandler) {
25815
25821
  throw new McpError(ErrorCode.InternalError, `Tool ${request.params.name} has taskSupport '${taskSupport}' but was not registered with registerToolTask`);
@@ -25863,7 +25869,7 @@ var McpServer = class {
25863
25869
  return void 0;
25864
25870
  }
25865
25871
  const inputObj = normalizeObjectSchema(tool.inputSchema);
25866
- const schemaToParse = inputObj !== null && inputObj !== void 0 ? inputObj : tool.inputSchema;
25872
+ const schemaToParse = inputObj ?? tool.inputSchema;
25867
25873
  const parseResult = await safeParseAsync3(schemaToParse, args);
25868
25874
  if (!parseResult.success) {
25869
25875
  const error2 = "error" in parseResult ? parseResult.error : "Unknown error";
@@ -25927,7 +25933,6 @@ var McpServer = class {
25927
25933
  * Handles automatic task polling for tools with taskSupport 'optional'.
25928
25934
  */
25929
25935
  async handleAutomaticTaskPolling(tool, request, extra) {
25930
- var _a;
25931
25936
  if (!extra.taskStore) {
25932
25937
  throw new Error("No task store provided for task-capable tool.");
25933
25938
  }
@@ -25940,7 +25945,7 @@ var McpServer = class {
25940
25945
  );
25941
25946
  const taskId = createTaskResult.task.taskId;
25942
25947
  let task = createTaskResult.task;
25943
- const pollInterval = (_a = task.pollInterval) !== null && _a !== void 0 ? _a : 5e3;
25948
+ const pollInterval = task.pollInterval ?? 5e3;
25944
25949
  while (task.status !== "completed" && task.status !== "failed" && task.status !== "cancelled") {
25945
25950
  await new Promise((resolve) => setTimeout(resolve, pollInterval));
25946
25951
  const updatedTask = await extra.taskStore.getTask(taskId);
@@ -25985,7 +25990,7 @@ var McpServer = class {
25985
25990
  return EMPTY_COMPLETION_RESULT;
25986
25991
  }
25987
25992
  const promptShape = getObjectShape(prompt.argsSchema);
25988
- const field = promptShape === null || promptShape === void 0 ? void 0 : promptShape[request.params.argument.name];
25993
+ const field = promptShape?.[request.params.argument.name];
25989
25994
  if (!isCompletable(field)) {
25990
25995
  return EMPTY_COMPLETION_RESULT;
25991
25996
  }
@@ -26070,7 +26075,6 @@ var McpServer = class {
26070
26075
  }
26071
26076
  throw new McpError(ErrorCode.InvalidParams, `Resource ${uri} not found`);
26072
26077
  });
26073
- this.setCompletionRequestHandler();
26074
26078
  this._resourceHandlersInitialized = true;
26075
26079
  }
26076
26080
  setPromptRequestHandlers() {
@@ -26118,7 +26122,6 @@ var McpServer = class {
26118
26122
  return await Promise.resolve(cb(extra));
26119
26123
  }
26120
26124
  });
26121
- this.setCompletionRequestHandler();
26122
26125
  this._promptHandlersInitialized = true;
26123
26126
  }
26124
26127
  resource(name, uriOrTemplate, ...rest) {
@@ -26226,6 +26229,11 @@ var McpServer = class {
26226
26229
  }
26227
26230
  };
26228
26231
  this._registeredResourceTemplates[name] = registeredResourceTemplate;
26232
+ const variableNames = template.uriTemplate.variableNames;
26233
+ const hasCompleter = Array.isArray(variableNames) && variableNames.some((v) => !!template.completeCallback(v));
26234
+ if (hasCompleter) {
26235
+ this.setCompletionRequestHandler();
26236
+ }
26229
26237
  return registeredResourceTemplate;
26230
26238
  }
26231
26239
  _createRegisteredPrompt(name, title, description, argsSchema, callback) {
@@ -26258,6 +26266,15 @@ var McpServer = class {
26258
26266
  }
26259
26267
  };
26260
26268
  this._registeredPrompts[name] = registeredPrompt;
26269
+ if (argsSchema) {
26270
+ const hasCompletable = Object.values(argsSchema).some((field) => {
26271
+ const inner = field instanceof ZodOptional2 ? field._def?.innerType : field;
26272
+ return isCompletable(inner);
26273
+ });
26274
+ if (hasCompletable) {
26275
+ this.setCompletionRequestHandler();
26276
+ }
26277
+ }
26261
26278
  return registeredPrompt;
26262
26279
  }
26263
26280
  _createRegisteredTool(name, title, description, inputSchema, outputSchema, annotations, execution, _meta, handler) {
@@ -26290,6 +26307,8 @@ var McpServer = class {
26290
26307
  registeredTool.description = updates.description;
26291
26308
  if (typeof updates.paramsSchema !== "undefined")
26292
26309
  registeredTool.inputSchema = objectFromShape(updates.paramsSchema);
26310
+ if (typeof updates.outputSchema !== "undefined")
26311
+ registeredTool.outputSchema = objectFromShape(updates.outputSchema);
26293
26312
  if (typeof updates.callback !== "undefined")
26294
26313
  registeredTool.handler = updates.callback;
26295
26314
  if (typeof updates.annotations !== "undefined")
@@ -26464,7 +26483,7 @@ function promptArgumentsFromSchema(schema) {
26464
26483
  }
26465
26484
  function getMethodValue(schema) {
26466
26485
  const shape = getObjectShape(schema);
26467
- const methodSchema = shape === null || shape === void 0 ? void 0 : shape.method;
26486
+ const methodSchema = shape?.method;
26468
26487
  if (!methodSchema) {
26469
26488
  throw new Error("Schema is missing a method literal");
26470
26489
  }