@kentico/management-api-mcp 30.12.3-preview → 31.0.1-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 (3) hide show
  1. package/README.md +57 -7
  2. package/dist/index.js +351 -326
  3. package/package.json +53 -28
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node --use-system-ca
1
+ #!/usr/bin/env node
2
2
  var __create = Object.create;
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -12525,7 +12525,6 @@ function $constructor(name, initializer3, params) {
12525
12525
  Object.defineProperty(_, "name", { value: name });
12526
12526
  return _;
12527
12527
  }
12528
- var $brand = Symbol("zod_brand");
12529
12528
  var $ZodAsyncError = class extends Error {
12530
12529
  constructor() {
12531
12530
  super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`);
@@ -15029,8 +15028,6 @@ function en_default() {
15029
15028
  }
15030
15029
 
15031
15030
  // node_modules/zod/v4/core/registries.js
15032
- var $output = Symbol("ZodOutput");
15033
- var $input = Symbol("ZodInput");
15034
15031
  var $ZodRegistry = class {
15035
15032
  constructor() {
15036
15033
  this._map = /* @__PURE__ */ new Map();
@@ -16384,10 +16381,10 @@ var ZodType = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
16384
16381
  };
16385
16382
  inst.clone = (def2, params) => clone(inst, def2, params);
16386
16383
  inst.brand = () => inst;
16387
- inst.register = (reg, meta) => {
16384
+ inst.register = ((reg, meta) => {
16388
16385
  reg.add(inst, meta);
16389
16386
  return inst;
16390
- };
16387
+ });
16391
16388
  inst.parse = (data, params) => parse2(inst, data, params, { callee: inst.parse });
16392
16389
  inst.safeParse = (data, params) => safeParse2(inst, data, params);
16393
16390
  inst.parseAsync = async (data, params) => parseAsync2(inst, data, params, { callee: inst.parseAsync });
@@ -16998,7 +16995,10 @@ var TaskCreationParamsSchema = looseObject({
16998
16995
  */
16999
16996
  pollInterval: number2().optional()
17000
16997
  });
17001
- var RelatedTaskMetadataSchema = looseObject({
16998
+ var TaskMetadataSchema = object({
16999
+ ttl: number2().optional()
17000
+ });
17001
+ var RelatedTaskMetadataSchema = object({
17002
17002
  taskId: string2()
17003
17003
  });
17004
17004
  var RequestMetaSchema = looseObject({
@@ -17011,48 +17011,45 @@ var RequestMetaSchema = looseObject({
17011
17011
  */
17012
17012
  [RELATED_TASK_META_KEY]: RelatedTaskMetadataSchema.optional()
17013
17013
  });
17014
- var BaseRequestParamsSchema = looseObject({
17015
- /**
17016
- * If specified, the caller is requesting that the receiver create a task to represent the request.
17017
- * Task creation parameters are now at the top level instead of in _meta.
17018
- */
17019
- task: TaskCreationParamsSchema.optional(),
17014
+ var BaseRequestParamsSchema = object({
17020
17015
  /**
17021
17016
  * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage.
17022
17017
  */
17023
17018
  _meta: RequestMetaSchema.optional()
17024
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;
17025
17032
  var RequestSchema = object({
17026
17033
  method: string2(),
17027
- params: BaseRequestParamsSchema.optional()
17034
+ params: BaseRequestParamsSchema.loose().optional()
17028
17035
  });
17029
- var NotificationsParamsSchema = looseObject({
17036
+ var NotificationsParamsSchema = object({
17030
17037
  /**
17031
17038
  * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
17032
17039
  * for notes on _meta usage.
17033
17040
  */
17034
- _meta: object({
17035
- /**
17036
- * If specified, this notification is related to the provided task.
17037
- */
17038
- [RELATED_TASK_META_KEY]: optional(RelatedTaskMetadataSchema)
17039
- }).passthrough().optional()
17041
+ _meta: RequestMetaSchema.optional()
17040
17042
  });
17041
17043
  var NotificationSchema = object({
17042
17044
  method: string2(),
17043
- params: NotificationsParamsSchema.optional()
17045
+ params: NotificationsParamsSchema.loose().optional()
17044
17046
  });
17045
17047
  var ResultSchema = looseObject({
17046
17048
  /**
17047
17049
  * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
17048
17050
  * for notes on _meta usage.
17049
17051
  */
17050
- _meta: looseObject({
17051
- /**
17052
- * If specified, this result is related to the provided task.
17053
- */
17054
- [RELATED_TASK_META_KEY]: RelatedTaskMetadataSchema.optional()
17055
- }).optional()
17052
+ _meta: RequestMetaSchema.optional()
17056
17053
  });
17057
17054
  var RequestIdSchema = union([string2(), number2().int()]);
17058
17055
  var JSONRPCRequestSchema = object({
@@ -17066,12 +17063,12 @@ var JSONRPCNotificationSchema = object({
17066
17063
  ...NotificationSchema.shape
17067
17064
  }).strict();
17068
17065
  var isJSONRPCNotification = (value) => JSONRPCNotificationSchema.safeParse(value).success;
17069
- var JSONRPCResponseSchema = object({
17066
+ var JSONRPCResultResponseSchema = object({
17070
17067
  jsonrpc: literal(JSONRPC_VERSION),
17071
17068
  id: RequestIdSchema,
17072
17069
  result: ResultSchema
17073
17070
  }).strict();
17074
- var isJSONRPCResponse = (value) => JSONRPCResponseSchema.safeParse(value).success;
17071
+ var isJSONRPCResultResponse = (value) => JSONRPCResultResponseSchema.safeParse(value).success;
17075
17072
  var ErrorCode;
17076
17073
  (function(ErrorCode2) {
17077
17074
  ErrorCode2[ErrorCode2["ConnectionClosed"] = -32e3] = "ConnectionClosed";
@@ -17083,9 +17080,9 @@ var ErrorCode;
17083
17080
  ErrorCode2[ErrorCode2["InternalError"] = -32603] = "InternalError";
17084
17081
  ErrorCode2[ErrorCode2["UrlElicitationRequired"] = -32042] = "UrlElicitationRequired";
17085
17082
  })(ErrorCode || (ErrorCode = {}));
17086
- var JSONRPCErrorSchema = object({
17083
+ var JSONRPCErrorResponseSchema = object({
17087
17084
  jsonrpc: literal(JSONRPC_VERSION),
17088
- id: RequestIdSchema,
17085
+ id: RequestIdSchema.optional(),
17089
17086
  error: object({
17090
17087
  /**
17091
17088
  * The error type that occurred.
@@ -17098,11 +17095,17 @@ var JSONRPCErrorSchema = object({
17098
17095
  /**
17099
17096
  * Additional information about the error. The value of this member is defined by the sender (e.g. detailed error information, nested errors etc.).
17100
17097
  */
17101
- data: optional(unknown())
17098
+ data: unknown().optional()
17102
17099
  })
17103
17100
  }).strict();
17104
- var isJSONRPCError = (value) => JSONRPCErrorSchema.safeParse(value).success;
17105
- 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]);
17106
17109
  var EmptyResultSchema = ResultSchema.strict();
17107
17110
  var CancelledNotificationParamsSchema = NotificationsParamsSchema.extend({
17108
17111
  /**
@@ -17110,7 +17113,7 @@ var CancelledNotificationParamsSchema = NotificationsParamsSchema.extend({
17110
17113
  *
17111
17114
  * This MUST correspond to the ID of a request previously issued in the same direction.
17112
17115
  */
17113
- requestId: RequestIdSchema,
17116
+ requestId: RequestIdSchema.optional(),
17114
17117
  /**
17115
17118
  * An optional string describing the reason for the cancellation. This MAY be logged or presented to the user.
17116
17119
  */
@@ -17135,7 +17138,15 @@ var IconSchema = object({
17135
17138
  *
17136
17139
  * If not provided, the client should assume that the icon can be used at any size.
17137
17140
  */
17138
- 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()
17139
17150
  });
17140
17151
  var IconsSchema = object({
17141
17152
  /**
@@ -17171,7 +17182,15 @@ var ImplementationSchema = BaseMetadataSchema.extend({
17171
17182
  /**
17172
17183
  * An optional URL of the website for this implementation.
17173
17184
  */
17174
- 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()
17175
17194
  });
17176
17195
  var FormElicitationCapabilitySchema = intersection(object({
17177
17196
  applyDefaults: boolean2().optional()
@@ -17187,54 +17206,54 @@ var ElicitationCapabilitySchema = preprocess((value) => {
17187
17206
  form: FormElicitationCapabilitySchema.optional(),
17188
17207
  url: AssertObjectSchema.optional()
17189
17208
  }), record(string2(), unknown()).optional()));
17190
- var ClientTasksCapabilitySchema = object({
17209
+ var ClientTasksCapabilitySchema = looseObject({
17191
17210
  /**
17192
17211
  * Present if the client supports listing tasks.
17193
17212
  */
17194
- list: optional(object({}).passthrough()),
17213
+ list: AssertObjectSchema.optional(),
17195
17214
  /**
17196
17215
  * Present if the client supports cancelling tasks.
17197
17216
  */
17198
- cancel: optional(object({}).passthrough()),
17217
+ cancel: AssertObjectSchema.optional(),
17199
17218
  /**
17200
17219
  * Capabilities for task creation on specific request types.
17201
17220
  */
17202
- requests: optional(object({
17221
+ requests: looseObject({
17203
17222
  /**
17204
17223
  * Task support for sampling requests.
17205
17224
  */
17206
- sampling: optional(object({
17207
- createMessage: optional(object({}).passthrough())
17208
- }).passthrough()),
17225
+ sampling: looseObject({
17226
+ createMessage: AssertObjectSchema.optional()
17227
+ }).optional(),
17209
17228
  /**
17210
17229
  * Task support for elicitation requests.
17211
17230
  */
17212
- elicitation: optional(object({
17213
- create: optional(object({}).passthrough())
17214
- }).passthrough())
17215
- }).passthrough())
17216
- }).passthrough();
17217
- var ServerTasksCapabilitySchema = object({
17231
+ elicitation: looseObject({
17232
+ create: AssertObjectSchema.optional()
17233
+ }).optional()
17234
+ }).optional()
17235
+ });
17236
+ var ServerTasksCapabilitySchema = looseObject({
17218
17237
  /**
17219
17238
  * Present if the server supports listing tasks.
17220
17239
  */
17221
- list: optional(object({}).passthrough()),
17240
+ list: AssertObjectSchema.optional(),
17222
17241
  /**
17223
17242
  * Present if the server supports cancelling tasks.
17224
17243
  */
17225
- cancel: optional(object({}).passthrough()),
17244
+ cancel: AssertObjectSchema.optional(),
17226
17245
  /**
17227
17246
  * Capabilities for task creation on specific request types.
17228
17247
  */
17229
- requests: optional(object({
17248
+ requests: looseObject({
17230
17249
  /**
17231
17250
  * Task support for tool requests.
17232
17251
  */
17233
- tools: optional(object({
17234
- call: optional(object({}).passthrough())
17235
- }).passthrough())
17236
- }).passthrough())
17237
- }).passthrough();
17252
+ tools: looseObject({
17253
+ call: AssertObjectSchema.optional()
17254
+ }).optional()
17255
+ }).optional()
17256
+ });
17238
17257
  var ClientCapabilitiesSchema = object({
17239
17258
  /**
17240
17259
  * Experimental, non-standard capabilities that the client supports.
@@ -17270,7 +17289,7 @@ var ClientCapabilitiesSchema = object({
17270
17289
  /**
17271
17290
  * Present if the client supports task creation.
17272
17291
  */
17273
- tasks: optional(ClientTasksCapabilitySchema)
17292
+ tasks: ClientTasksCapabilitySchema.optional()
17274
17293
  });
17275
17294
  var InitializeRequestParamsSchema = BaseRequestParamsSchema.extend({
17276
17295
  /**
@@ -17300,12 +17319,12 @@ var ServerCapabilitiesSchema = object({
17300
17319
  /**
17301
17320
  * Present if the server offers any prompt templates.
17302
17321
  */
17303
- prompts: optional(object({
17322
+ prompts: object({
17304
17323
  /**
17305
17324
  * Whether this server supports issuing notifications for changes to the prompt list.
17306
17325
  */
17307
- listChanged: optional(boolean2())
17308
- })),
17326
+ listChanged: boolean2().optional()
17327
+ }).optional(),
17309
17328
  /**
17310
17329
  * Present if the server offers any resources to read.
17311
17330
  */
@@ -17331,8 +17350,8 @@ var ServerCapabilitiesSchema = object({
17331
17350
  /**
17332
17351
  * Present if the server supports task creation.
17333
17352
  */
17334
- tasks: optional(ServerTasksCapabilitySchema)
17335
- }).passthrough();
17353
+ tasks: ServerTasksCapabilitySchema.optional()
17354
+ });
17336
17355
  var InitializeResultSchema = ResultSchema.extend({
17337
17356
  /**
17338
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.
@@ -17348,10 +17367,12 @@ var InitializeResultSchema = ResultSchema.extend({
17348
17367
  instructions: string2().optional()
17349
17368
  });
17350
17369
  var InitializedNotificationSchema = NotificationSchema.extend({
17351
- method: literal("notifications/initialized")
17370
+ method: literal("notifications/initialized"),
17371
+ params: NotificationsParamsSchema.optional()
17352
17372
  });
17353
17373
  var PingRequestSchema = RequestSchema.extend({
17354
- method: literal("ping")
17374
+ method: literal("ping"),
17375
+ params: BaseRequestParamsSchema.optional()
17355
17376
  });
17356
17377
  var ProgressSchema = object({
17357
17378
  /**
@@ -17394,11 +17415,12 @@ var PaginatedResultSchema = ResultSchema.extend({
17394
17415
  * An opaque token representing the pagination position after the last returned result.
17395
17416
  * If present, there may be more results available.
17396
17417
  */
17397
- nextCursor: optional(CursorSchema)
17418
+ nextCursor: CursorSchema.optional()
17398
17419
  });
17420
+ var TaskStatusSchema = _enum(["working", "input_required", "completed", "failed", "cancelled"]);
17399
17421
  var TaskSchema = object({
17400
17422
  taskId: string2(),
17401
- status: _enum(["working", "input_required", "completed", "failed", "cancelled"]),
17423
+ status: TaskStatusSchema,
17402
17424
  /**
17403
17425
  * Time in milliseconds to keep task results available after completion.
17404
17426
  * If null, the task has unlimited lifetime until manually cleaned up.
@@ -17439,6 +17461,7 @@ var GetTaskPayloadRequestSchema = RequestSchema.extend({
17439
17461
  taskId: string2()
17440
17462
  })
17441
17463
  });
17464
+ var GetTaskPayloadResultSchema = ResultSchema.loose();
17442
17465
  var ListTasksRequestSchema = PaginatedRequestSchema.extend({
17443
17466
  method: literal("tasks/list")
17444
17467
  });
@@ -17477,7 +17500,7 @@ var Base64Schema = string2().refine((val) => {
17477
17500
  try {
17478
17501
  atob(val);
17479
17502
  return true;
17480
- } catch (_a) {
17503
+ } catch {
17481
17504
  return false;
17482
17505
  }
17483
17506
  }, { message: "Invalid Base64 string" });
@@ -17487,11 +17510,12 @@ var BlobResourceContentsSchema = ResourceContentsSchema.extend({
17487
17510
  */
17488
17511
  blob: Base64Schema
17489
17512
  });
17513
+ var RoleSchema = _enum(["user", "assistant"]);
17490
17514
  var AnnotationsSchema = object({
17491
17515
  /**
17492
17516
  * Intended audience(s) for the resource.
17493
17517
  */
17494
- audience: array(_enum(["user", "assistant"])).optional(),
17518
+ audience: array(RoleSchema).optional(),
17495
17519
  /**
17496
17520
  * Importance hint for the resource, from 0 (least) to 1 (most).
17497
17521
  */
@@ -17584,7 +17608,8 @@ var ReadResourceResultSchema = ResultSchema.extend({
17584
17608
  contents: array(union([TextResourceContentsSchema, BlobResourceContentsSchema]))
17585
17609
  });
17586
17610
  var ResourceListChangedNotificationSchema = NotificationSchema.extend({
17587
- method: literal("notifications/resources/list_changed")
17611
+ method: literal("notifications/resources/list_changed"),
17612
+ params: NotificationsParamsSchema.optional()
17588
17613
  });
17589
17614
  var SubscribeRequestParamsSchema = ResourceRequestParamsSchema;
17590
17615
  var SubscribeRequestSchema = RequestSchema.extend({
@@ -17729,13 +17754,13 @@ var ToolUseContentSchema = object({
17729
17754
  * Arguments to pass to the tool.
17730
17755
  * Must conform to the tool's inputSchema.
17731
17756
  */
17732
- input: object({}).passthrough(),
17757
+ input: record(string2(), unknown()),
17733
17758
  /**
17734
17759
  * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
17735
17760
  * for notes on _meta usage.
17736
17761
  */
17737
- _meta: optional(object({}).passthrough())
17738
- }).passthrough();
17762
+ _meta: record(string2(), unknown()).optional()
17763
+ });
17739
17764
  var EmbeddedResourceSchema = object({
17740
17765
  type: literal("resource"),
17741
17766
  resource: union([TextResourceContentsSchema, BlobResourceContentsSchema]),
@@ -17760,18 +17785,19 @@ var ContentBlockSchema = union([
17760
17785
  EmbeddedResourceSchema
17761
17786
  ]);
17762
17787
  var PromptMessageSchema = object({
17763
- role: _enum(["user", "assistant"]),
17788
+ role: RoleSchema,
17764
17789
  content: ContentBlockSchema
17765
17790
  });
17766
17791
  var GetPromptResultSchema = ResultSchema.extend({
17767
17792
  /**
17768
17793
  * An optional description for the prompt.
17769
17794
  */
17770
- description: optional(string2()),
17795
+ description: string2().optional(),
17771
17796
  messages: array(PromptMessageSchema)
17772
17797
  });
17773
17798
  var PromptListChangedNotificationSchema = NotificationSchema.extend({
17774
- method: literal("notifications/prompts/list_changed")
17799
+ method: literal("notifications/prompts/list_changed"),
17800
+ params: NotificationsParamsSchema.optional()
17775
17801
  });
17776
17802
  var ToolAnnotationsSchema = object({
17777
17803
  /**
@@ -17852,11 +17878,11 @@ var ToolSchema = object({
17852
17878
  /**
17853
17879
  * Optional additional tool information.
17854
17880
  */
17855
- annotations: optional(ToolAnnotationsSchema),
17881
+ annotations: ToolAnnotationsSchema.optional(),
17856
17882
  /**
17857
17883
  * Execution-related properties for this tool.
17858
17884
  */
17859
- execution: optional(ToolExecutionSchema),
17885
+ execution: ToolExecutionSchema.optional(),
17860
17886
  /**
17861
17887
  * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
17862
17888
  * for notes on _meta usage.
@@ -17897,12 +17923,12 @@ var CallToolResultSchema = ResultSchema.extend({
17897
17923
  * server does not support tool calls, or any other exceptional conditions,
17898
17924
  * should be reported as an MCP error response.
17899
17925
  */
17900
- isError: optional(boolean2())
17926
+ isError: boolean2().optional()
17901
17927
  });
17902
17928
  var CompatibilityCallToolResultSchema = CallToolResultSchema.or(ResultSchema.extend({
17903
17929
  toolResult: unknown()
17904
17930
  }));
17905
- var CallToolRequestParamsSchema = BaseRequestParamsSchema.extend({
17931
+ var CallToolRequestParamsSchema = TaskAugmentedRequestParamsSchema.extend({
17906
17932
  /**
17907
17933
  * The name of the tool to call.
17908
17934
  */
@@ -17910,14 +17936,35 @@ var CallToolRequestParamsSchema = BaseRequestParamsSchema.extend({
17910
17936
  /**
17911
17937
  * Arguments to pass to the tool.
17912
17938
  */
17913
- arguments: optional(record(string2(), unknown()))
17939
+ arguments: record(string2(), unknown()).optional()
17914
17940
  });
17915
17941
  var CallToolRequestSchema = RequestSchema.extend({
17916
17942
  method: literal("tools/call"),
17917
17943
  params: CallToolRequestParamsSchema
17918
17944
  });
17919
17945
  var ToolListChangedNotificationSchema = NotificationSchema.extend({
17920
- 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)
17921
17968
  });
17922
17969
  var LoggingLevelSchema = _enum(["debug", "info", "notice", "warning", "error", "critical", "alert", "emergency"]);
17923
17970
  var SetLevelRequestParamsSchema = BaseRequestParamsSchema.extend({
@@ -17958,19 +18005,19 @@ var ModelPreferencesSchema = object({
17958
18005
  /**
17959
18006
  * Optional hints to use for model selection.
17960
18007
  */
17961
- hints: optional(array(ModelHintSchema)),
18008
+ hints: array(ModelHintSchema).optional(),
17962
18009
  /**
17963
18010
  * How much to prioritize cost when selecting a model.
17964
18011
  */
17965
- costPriority: optional(number2().min(0).max(1)),
18012
+ costPriority: number2().min(0).max(1).optional(),
17966
18013
  /**
17967
18014
  * How much to prioritize sampling speed (latency) when selecting a model.
17968
18015
  */
17969
- speedPriority: optional(number2().min(0).max(1)),
18016
+ speedPriority: number2().min(0).max(1).optional(),
17970
18017
  /**
17971
18018
  * How much to prioritize intelligence and capabilities when selecting a model.
17972
18019
  */
17973
- intelligencePriority: optional(number2().min(0).max(1))
18020
+ intelligencePriority: number2().min(0).max(1).optional()
17974
18021
  });
17975
18022
  var ToolChoiceSchema = object({
17976
18023
  /**
@@ -17979,20 +18026,20 @@ var ToolChoiceSchema = object({
17979
18026
  * - "required": Model MUST use at least one tool before completing
17980
18027
  * - "none": Model MUST NOT use any tools
17981
18028
  */
17982
- mode: optional(_enum(["auto", "required", "none"]))
18029
+ mode: _enum(["auto", "required", "none"]).optional()
17983
18030
  });
17984
18031
  var ToolResultContentSchema = object({
17985
18032
  type: literal("tool_result"),
17986
18033
  toolUseId: string2().describe("The unique identifier for the corresponding tool call."),
17987
18034
  content: array(ContentBlockSchema).default([]),
17988
- structuredContent: object({}).passthrough().optional(),
17989
- isError: optional(boolean2()),
18035
+ structuredContent: object({}).loose().optional(),
18036
+ isError: boolean2().optional(),
17990
18037
  /**
17991
18038
  * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
17992
18039
  * for notes on _meta usage.
17993
18040
  */
17994
- _meta: optional(object({}).passthrough())
17995
- }).passthrough();
18041
+ _meta: record(string2(), unknown()).optional()
18042
+ });
17996
18043
  var SamplingContentSchema = discriminatedUnion("type", [TextContentSchema, ImageContentSchema, AudioContentSchema]);
17997
18044
  var SamplingMessageContentBlockSchema = discriminatedUnion("type", [
17998
18045
  TextContentSchema,
@@ -18002,15 +18049,15 @@ var SamplingMessageContentBlockSchema = discriminatedUnion("type", [
18002
18049
  ToolResultContentSchema
18003
18050
  ]);
18004
18051
  var SamplingMessageSchema = object({
18005
- role: _enum(["user", "assistant"]),
18052
+ role: RoleSchema,
18006
18053
  content: union([SamplingMessageContentBlockSchema, array(SamplingMessageContentBlockSchema)]),
18007
18054
  /**
18008
18055
  * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
18009
18056
  * for notes on _meta usage.
18010
18057
  */
18011
- _meta: optional(object({}).passthrough())
18012
- }).passthrough();
18013
- var CreateMessageRequestParamsSchema = BaseRequestParamsSchema.extend({
18058
+ _meta: record(string2(), unknown()).optional()
18059
+ });
18060
+ var CreateMessageRequestParamsSchema = TaskAugmentedRequestParamsSchema.extend({
18014
18061
  messages: array(SamplingMessageSchema),
18015
18062
  /**
18016
18063
  * The server's preferences for which model to select. The client MAY modify or omit this request.
@@ -18044,13 +18091,13 @@ var CreateMessageRequestParamsSchema = BaseRequestParamsSchema.extend({
18044
18091
  * Tools that the model may use during generation.
18045
18092
  * The client MUST return an error if this field is provided but ClientCapabilities.sampling.tools is not declared.
18046
18093
  */
18047
- tools: optional(array(ToolSchema)),
18094
+ tools: array(ToolSchema).optional(),
18048
18095
  /**
18049
18096
  * Controls how the model uses tools.
18050
18097
  * The client MUST return an error if this field is provided but ClientCapabilities.sampling.tools is not declared.
18051
18098
  * Default is `{ mode: "auto" }`.
18052
18099
  */
18053
- toolChoice: optional(ToolChoiceSchema)
18100
+ toolChoice: ToolChoiceSchema.optional()
18054
18101
  });
18055
18102
  var CreateMessageRequestSchema = RequestSchema.extend({
18056
18103
  method: literal("sampling/createMessage"),
@@ -18072,7 +18119,7 @@ var CreateMessageResultSchema = ResultSchema.extend({
18072
18119
  * This field is an open string to allow for provider-specific stop reasons.
18073
18120
  */
18074
18121
  stopReason: optional(_enum(["endTurn", "stopSequence", "maxTokens"]).or(string2())),
18075
- role: _enum(["user", "assistant"]),
18122
+ role: RoleSchema,
18076
18123
  /**
18077
18124
  * Response content. Single content block (text, image, or audio).
18078
18125
  */
@@ -18095,7 +18142,7 @@ var CreateMessageResultWithToolsSchema = ResultSchema.extend({
18095
18142
  * This field is an open string to allow for provider-specific stop reasons.
18096
18143
  */
18097
18144
  stopReason: optional(_enum(["endTurn", "stopSequence", "maxTokens", "toolUse"]).or(string2())),
18098
- role: _enum(["user", "assistant"]),
18145
+ role: RoleSchema,
18099
18146
  /**
18100
18147
  * Response content. May be a single block or array. May include ToolUseContent if stopReason is "toolUse".
18101
18148
  */
@@ -18179,7 +18226,7 @@ var TitledMultiSelectEnumSchemaSchema = object({
18179
18226
  var MultiSelectEnumSchemaSchema = union([UntitledMultiSelectEnumSchemaSchema, TitledMultiSelectEnumSchemaSchema]);
18180
18227
  var EnumSchemaSchema = union([LegacyTitledEnumSchemaSchema, SingleSelectEnumSchemaSchema, MultiSelectEnumSchemaSchema]);
18181
18228
  var PrimitiveSchemaDefinitionSchema = union([EnumSchemaSchema, BooleanSchemaSchema, StringSchemaSchema, NumberSchemaSchema]);
18182
- var ElicitRequestFormParamsSchema = BaseRequestParamsSchema.extend({
18229
+ var ElicitRequestFormParamsSchema = TaskAugmentedRequestParamsSchema.extend({
18183
18230
  /**
18184
18231
  * The elicitation mode.
18185
18232
  *
@@ -18200,7 +18247,7 @@ var ElicitRequestFormParamsSchema = BaseRequestParamsSchema.extend({
18200
18247
  required: array(string2()).optional()
18201
18248
  })
18202
18249
  });
18203
- var ElicitRequestURLParamsSchema = BaseRequestParamsSchema.extend({
18250
+ var ElicitRequestURLParamsSchema = TaskAugmentedRequestParamsSchema.extend({
18204
18251
  /**
18205
18252
  * The elicitation mode.
18206
18253
  */
@@ -18294,11 +18341,13 @@ function assertCompleteRequestPrompt(request) {
18294
18341
  if (request.params.ref.type !== "ref/prompt") {
18295
18342
  throw new TypeError(`Expected CompleteRequestPrompt, but got ${request.params.ref.type}`);
18296
18343
  }
18344
+ void request;
18297
18345
  }
18298
18346
  function assertCompleteRequestResourceTemplate(request) {
18299
18347
  if (request.params.ref.type !== "ref/resource") {
18300
18348
  throw new TypeError(`Expected CompleteRequestResourceTemplate, but got ${request.params.ref.type}`);
18301
18349
  }
18350
+ void request;
18302
18351
  }
18303
18352
  var CompleteResultSchema = ResultSchema.extend({
18304
18353
  completion: looseObject({
@@ -18332,13 +18381,15 @@ var RootSchema = object({
18332
18381
  _meta: record(string2(), unknown()).optional()
18333
18382
  });
18334
18383
  var ListRootsRequestSchema = RequestSchema.extend({
18335
- method: literal("roots/list")
18384
+ method: literal("roots/list"),
18385
+ params: BaseRequestParamsSchema.optional()
18336
18386
  });
18337
18387
  var ListRootsResultSchema = ResultSchema.extend({
18338
18388
  roots: array(RootSchema)
18339
18389
  });
18340
18390
  var RootsListChangedNotificationSchema = NotificationSchema.extend({
18341
- method: literal("notifications/roots/list_changed")
18391
+ method: literal("notifications/roots/list_changed"),
18392
+ params: NotificationsParamsSchema.optional()
18342
18393
  });
18343
18394
  var ClientRequestSchema = union([
18344
18395
  PingRequestSchema,
@@ -18356,7 +18407,8 @@ var ClientRequestSchema = union([
18356
18407
  ListToolsRequestSchema,
18357
18408
  GetTaskRequestSchema,
18358
18409
  GetTaskPayloadRequestSchema,
18359
- ListTasksRequestSchema
18410
+ ListTasksRequestSchema,
18411
+ CancelTaskRequestSchema
18360
18412
  ]);
18361
18413
  var ClientNotificationSchema = union([
18362
18414
  CancelledNotificationSchema,
@@ -18382,7 +18434,8 @@ var ServerRequestSchema = union([
18382
18434
  ListRootsRequestSchema,
18383
18435
  GetTaskRequestSchema,
18384
18436
  GetTaskPayloadRequestSchema,
18385
- ListTasksRequestSchema
18437
+ ListTasksRequestSchema,
18438
+ CancelTaskRequestSchema
18386
18439
  ]);
18387
18440
  var ServerNotificationSchema = union([
18388
18441
  CancelledNotificationSchema,
@@ -18437,8 +18490,7 @@ var UrlElicitationRequiredError = class extends McpError {
18437
18490
  });
18438
18491
  }
18439
18492
  get elicitations() {
18440
- var _a, _b;
18441
- return (_b = (_a = this.data) === null || _a === void 0 ? void 0 : _a.elicitations) !== null && _b !== void 0 ? _b : [];
18493
+ return this.data?.elicitations ?? [];
18442
18494
  }
18443
18495
  };
18444
18496
 
@@ -18482,8 +18534,7 @@ var StdioServerTransport = class {
18482
18534
  this.processReadBuffer();
18483
18535
  };
18484
18536
  this._onerror = (error2) => {
18485
- var _a;
18486
- (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error2);
18537
+ this.onerror?.(error2);
18487
18538
  };
18488
18539
  }
18489
18540
  /**
@@ -18498,21 +18549,19 @@ var StdioServerTransport = class {
18498
18549
  this._stdin.on("error", this._onerror);
18499
18550
  }
18500
18551
  processReadBuffer() {
18501
- var _a, _b;
18502
18552
  while (true) {
18503
18553
  try {
18504
18554
  const message = this._readBuffer.readMessage();
18505
18555
  if (message === null) {
18506
18556
  break;
18507
18557
  }
18508
- (_a = this.onmessage) === null || _a === void 0 ? void 0 : _a.call(this, message);
18558
+ this.onmessage?.(message);
18509
18559
  } catch (error2) {
18510
- (_b = this.onerror) === null || _b === void 0 ? void 0 : _b.call(this, error2);
18560
+ this.onerror?.(error2);
18511
18561
  }
18512
18562
  }
18513
18563
  }
18514
18564
  async close() {
18515
- var _a;
18516
18565
  this._stdin.off("data", this._ondata);
18517
18566
  this._stdin.off("error", this._onerror);
18518
18567
  const remainingDataListeners = this._stdin.listenerCount("data");
@@ -18520,7 +18569,7 @@ var StdioServerTransport = class {
18520
18569
  this._stdin.pause();
18521
18570
  }
18522
18571
  this._readBuffer.clear();
18523
- (_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this);
18572
+ this.onclose?.();
18524
18573
  }
18525
18574
  send(message) {
18526
18575
  return new Promise((resolve) => {
@@ -22362,7 +22411,7 @@ ZodNaN.create = (params) => {
22362
22411
  ...processCreateParams(params)
22363
22412
  });
22364
22413
  };
22365
- var BRAND = Symbol("zod_brand");
22414
+ var BRAND = /* @__PURE__ */ Symbol("zod_brand");
22366
22415
  var ZodBranded = class extends ZodType2 {
22367
22416
  _parse(input) {
22368
22417
  const { ctx } = this._processInputParams(input);
@@ -22564,14 +22613,14 @@ var ostring = () => stringType().optional();
22564
22613
  var onumber = () => numberType().optional();
22565
22614
  var oboolean = () => booleanType().optional();
22566
22615
  var coerce = {
22567
- string: (arg) => ZodString2.create({ ...arg, coerce: true }),
22568
- number: (arg) => ZodNumber2.create({ ...arg, coerce: true }),
22569
- boolean: (arg) => ZodBoolean2.create({
22616
+ string: ((arg) => ZodString2.create({ ...arg, coerce: true })),
22617
+ number: ((arg) => ZodNumber2.create({ ...arg, coerce: true })),
22618
+ boolean: ((arg) => ZodBoolean2.create({
22570
22619
  ...arg,
22571
22620
  coerce: true
22572
- }),
22573
- bigint: (arg) => ZodBigInt.create({ ...arg, coerce: true }),
22574
- date: (arg) => ZodDate.create({ ...arg, coerce: true })
22621
+ })),
22622
+ bigint: ((arg) => ZodBigInt.create({ ...arg, coerce: true })),
22623
+ date: ((arg) => ZodDate.create({ ...arg, coerce: true }))
22575
22624
  };
22576
22625
  var NEVER2 = INVALID;
22577
22626
 
@@ -22599,10 +22648,10 @@ var ZodMiniType = /* @__PURE__ */ $constructor("ZodMiniType", (inst, def) => {
22599
22648
  };
22600
22649
  inst.clone = (_def, params) => clone(inst, _def, params);
22601
22650
  inst.brand = () => inst;
22602
- inst.register = (reg, meta) => {
22651
+ inst.register = ((reg, meta) => {
22603
22652
  reg.add(inst, meta);
22604
22653
  return inst;
22605
- };
22654
+ });
22606
22655
  });
22607
22656
  var ZodMiniObject = /* @__PURE__ */ $constructor("ZodMiniObject", (inst, def) => {
22608
22657
  $ZodObject.init(inst, def);
@@ -22657,13 +22706,12 @@ async function safeParseAsync3(schema, data) {
22657
22706
  return result;
22658
22707
  }
22659
22708
  function getObjectShape(schema) {
22660
- var _a, _b;
22661
22709
  if (!schema)
22662
22710
  return void 0;
22663
22711
  let rawShape;
22664
22712
  if (isZ4Schema(schema)) {
22665
22713
  const v4Schema = schema;
22666
- 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;
22667
22715
  } else {
22668
22716
  const v3Schema = schema;
22669
22717
  rawShape = v3Schema.shape;
@@ -22673,14 +22721,13 @@ function getObjectShape(schema) {
22673
22721
  if (typeof rawShape === "function") {
22674
22722
  try {
22675
22723
  return rawShape();
22676
- } catch (_c) {
22724
+ } catch {
22677
22725
  return void 0;
22678
22726
  }
22679
22727
  }
22680
22728
  return rawShape;
22681
22729
  }
22682
22730
  function normalizeObjectSchema(schema) {
22683
- var _a;
22684
22731
  if (!schema)
22685
22732
  return void 0;
22686
22733
  if (typeof schema === "object") {
@@ -22695,7 +22742,7 @@ function normalizeObjectSchema(schema) {
22695
22742
  }
22696
22743
  if (isZ4Schema(schema)) {
22697
22744
  const v4Schema = schema;
22698
- const def = (_a = v4Schema._zod) === null || _a === void 0 ? void 0 : _a.def;
22745
+ const def = v4Schema._zod?.def;
22699
22746
  if (def && (def.type === "object" || def.shape !== void 0)) {
22700
22747
  return schema;
22701
22748
  }
@@ -22720,38 +22767,30 @@ function getParseErrorMessage(error2) {
22720
22767
  }
22721
22768
  try {
22722
22769
  return JSON.stringify(error2);
22723
- } catch (_a) {
22770
+ } catch {
22724
22771
  return String(error2);
22725
22772
  }
22726
22773
  }
22727
22774
  return String(error2);
22728
22775
  }
22729
22776
  function getSchemaDescription(schema) {
22730
- var _a, _b, _c, _d;
22731
- if (isZ4Schema(schema)) {
22732
- const v4Schema = schema;
22733
- return (_b = (_a = v4Schema._zod) === null || _a === void 0 ? void 0 : _a.def) === null || _b === void 0 ? void 0 : _b.description;
22734
- }
22735
- const v3Schema = schema;
22736
- return (_c = schema.description) !== null && _c !== void 0 ? _c : (_d = v3Schema._def) === null || _d === void 0 ? void 0 : _d.description;
22777
+ return schema.description;
22737
22778
  }
22738
22779
  function isSchemaOptional(schema) {
22739
- var _a, _b, _c;
22740
22780
  if (isZ4Schema(schema)) {
22741
22781
  const v4Schema = schema;
22742
- 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";
22743
22783
  }
22744
22784
  const v3Schema = schema;
22745
22785
  if (typeof schema.isOptional === "function") {
22746
22786
  return schema.isOptional();
22747
22787
  }
22748
- return ((_c = v3Schema._def) === null || _c === void 0 ? void 0 : _c.typeName) === "ZodOptional";
22788
+ return v3Schema._def?.typeName === "ZodOptional";
22749
22789
  }
22750
22790
  function getLiteralValue(schema) {
22751
- var _a;
22752
22791
  if (isZ4Schema(schema)) {
22753
22792
  const v4Schema = schema;
22754
- const def2 = (_a = v4Schema._zod) === null || _a === void 0 ? void 0 : _a.def;
22793
+ const def2 = v4Schema._zod?.def;
22755
22794
  if (def2) {
22756
22795
  if (def2.value !== void 0)
22757
22796
  return def2.value;
@@ -22781,7 +22820,7 @@ function isTerminal(status) {
22781
22820
  }
22782
22821
 
22783
22822
  // node_modules/zod-to-json-schema/dist/esm/Options.js
22784
- var ignoreOverride = Symbol("Let zodToJsonSchema decide on which parser to use");
22823
+ var ignoreOverride = /* @__PURE__ */ Symbol("Let zodToJsonSchema decide on which parser to use");
22785
22824
  var defaultOptions = {
22786
22825
  name: void 0,
22787
22826
  $refStrategy: "root",
@@ -24075,21 +24114,20 @@ function mapMiniTarget(t) {
24075
24114
  return "draft-7";
24076
24115
  }
24077
24116
  function toJsonSchemaCompat(schema, opts) {
24078
- var _a, _b, _c;
24079
24117
  if (isZ4Schema(schema)) {
24080
24118
  return toJSONSchema(schema, {
24081
- target: mapMiniTarget(opts === null || opts === void 0 ? void 0 : opts.target),
24082
- 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"
24083
24121
  });
24084
24122
  }
24085
24123
  return zodToJsonSchema(schema, {
24086
- strictUnions: (_b = opts === null || opts === void 0 ? void 0 : opts.strictUnions) !== null && _b !== void 0 ? _b : true,
24087
- 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"
24088
24126
  });
24089
24127
  }
24090
24128
  function getMethodLiteral(schema) {
24091
24129
  const shape = getObjectShape(schema);
24092
- const methodSchema = shape === null || shape === void 0 ? void 0 : shape.method;
24130
+ const methodSchema = shape?.method;
24093
24131
  if (!methodSchema) {
24094
24132
  throw new Error("Schema is missing a method literal");
24095
24133
  }
@@ -24133,8 +24171,8 @@ var Protocol = class {
24133
24171
  // Automatic pong by default.
24134
24172
  (_request) => ({})
24135
24173
  );
24136
- this._taskStore = _options === null || _options === void 0 ? void 0 : _options.taskStore;
24137
- this._taskMessageQueue = _options === null || _options === void 0 ? void 0 : _options.taskMessageQueue;
24174
+ this._taskStore = _options?.taskStore;
24175
+ this._taskMessageQueue = _options?.taskMessageQueue;
24138
24176
  if (this._taskStore) {
24139
24177
  this.setRequestHandler(GetTaskRequestSchema, async (request, extra) => {
24140
24178
  const task = await this._taskStore.getTask(request.params.taskId, extra.sessionId);
@@ -24147,7 +24185,6 @@ var Protocol = class {
24147
24185
  });
24148
24186
  this.setRequestHandler(GetTaskPayloadRequestSchema, async (request, extra) => {
24149
24187
  const handleTaskResult = async () => {
24150
- var _a;
24151
24188
  const taskId = request.params.taskId;
24152
24189
  if (this._taskMessageQueue) {
24153
24190
  let queuedMessage;
@@ -24171,7 +24208,7 @@ var Protocol = class {
24171
24208
  }
24172
24209
  continue;
24173
24210
  }
24174
- 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 });
24175
24212
  }
24176
24213
  }
24177
24214
  const task = await this._taskStore.getTask(taskId, extra.sessionId);
@@ -24200,9 +24237,8 @@ var Protocol = class {
24200
24237
  return await handleTaskResult();
24201
24238
  });
24202
24239
  this.setRequestHandler(ListTasksRequestSchema, async (request, extra) => {
24203
- var _a;
24204
24240
  try {
24205
- 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);
24206
24242
  return {
24207
24243
  tasks,
24208
24244
  nextCursor,
@@ -24241,8 +24277,11 @@ var Protocol = class {
24241
24277
  }
24242
24278
  }
24243
24279
  async _oncancel(notification) {
24280
+ if (!notification.params.requestId) {
24281
+ return;
24282
+ }
24244
24283
  const controller = this._requestHandlerAbortControllers.get(notification.params.requestId);
24245
- controller === null || controller === void 0 ? void 0 : controller.abort(notification.params.reason);
24284
+ controller?.abort(notification.params.reason);
24246
24285
  }
24247
24286
  _setupTimeout(messageId, timeout, maxTotalTimeout, onTimeout, resetTimeoutOnProgress = false) {
24248
24287
  this._timeoutInfo.set(messageId, {
@@ -24283,22 +24322,21 @@ var Protocol = class {
24283
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.
24284
24323
  */
24285
24324
  async connect(transport2) {
24286
- var _a, _b, _c;
24287
24325
  this._transport = transport2;
24288
- const _onclose = (_a = this.transport) === null || _a === void 0 ? void 0 : _a.onclose;
24326
+ const _onclose = this.transport?.onclose;
24289
24327
  this._transport.onclose = () => {
24290
- _onclose === null || _onclose === void 0 ? void 0 : _onclose();
24328
+ _onclose?.();
24291
24329
  this._onclose();
24292
24330
  };
24293
- const _onerror = (_b = this.transport) === null || _b === void 0 ? void 0 : _b.onerror;
24331
+ const _onerror = this.transport?.onerror;
24294
24332
  this._transport.onerror = (error2) => {
24295
- _onerror === null || _onerror === void 0 ? void 0 : _onerror(error2);
24333
+ _onerror?.(error2);
24296
24334
  this._onerror(error2);
24297
24335
  };
24298
- const _onmessage = (_c = this._transport) === null || _c === void 0 ? void 0 : _c.onmessage;
24336
+ const _onmessage = this._transport?.onmessage;
24299
24337
  this._transport.onmessage = (message, extra) => {
24300
- _onmessage === null || _onmessage === void 0 ? void 0 : _onmessage(message, extra);
24301
- if (isJSONRPCResponse(message) || isJSONRPCError(message)) {
24338
+ _onmessage?.(message, extra);
24339
+ if (isJSONRPCResultResponse(message) || isJSONRPCErrorResponse(message)) {
24302
24340
  this._onresponse(message);
24303
24341
  } else if (isJSONRPCRequest(message)) {
24304
24342
  this._onrequest(message, extra);
@@ -24311,7 +24349,6 @@ var Protocol = class {
24311
24349
  await this._transport.start();
24312
24350
  }
24313
24351
  _onclose() {
24314
- var _a;
24315
24352
  const responseHandlers = this._responseHandlers;
24316
24353
  this._responseHandlers = /* @__PURE__ */ new Map();
24317
24354
  this._progressHandlers.clear();
@@ -24319,28 +24356,25 @@ var Protocol = class {
24319
24356
  this._pendingDebouncedNotifications.clear();
24320
24357
  const error2 = McpError.fromError(ErrorCode.ConnectionClosed, "Connection closed");
24321
24358
  this._transport = void 0;
24322
- (_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this);
24359
+ this.onclose?.();
24323
24360
  for (const handler of responseHandlers.values()) {
24324
24361
  handler(error2);
24325
24362
  }
24326
24363
  }
24327
24364
  _onerror(error2) {
24328
- var _a;
24329
- (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error2);
24365
+ this.onerror?.(error2);
24330
24366
  }
24331
24367
  _onnotification(notification) {
24332
- var _a;
24333
- 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;
24334
24369
  if (handler === void 0) {
24335
24370
  return;
24336
24371
  }
24337
24372
  Promise.resolve().then(() => handler(notification)).catch((error2) => this._onerror(new Error(`Uncaught error in notification handler: ${error2}`)));
24338
24373
  }
24339
24374
  _onrequest(request, extra) {
24340
- var _a, _b, _c, _d, _e, _f;
24341
- 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;
24342
24376
  const capturedTransport = this._transport;
24343
- 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;
24344
24378
  if (handler === void 0) {
24345
24379
  const errorResponse = {
24346
24380
  jsonrpc: "2.0",
@@ -24355,20 +24389,20 @@ var Protocol = class {
24355
24389
  type: "error",
24356
24390
  message: errorResponse,
24357
24391
  timestamp: Date.now()
24358
- }, 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}`)));
24359
24393
  } else {
24360
- 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}`)));
24361
24395
  }
24362
24396
  return;
24363
24397
  }
24364
24398
  const abortController = new AbortController();
24365
24399
  this._requestHandlerAbortControllers.set(request.id, abortController);
24366
- const taskCreationParams = (_e = request.params) === null || _e === void 0 ? void 0 : _e.task;
24367
- 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;
24368
24402
  const fullExtra = {
24369
24403
  signal: abortController.signal,
24370
- sessionId: capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.sessionId,
24371
- _meta: (_f = request.params) === null || _f === void 0 ? void 0 : _f._meta,
24404
+ sessionId: capturedTransport?.sessionId,
24405
+ _meta: request.params?._meta,
24372
24406
  sendNotification: async (notification) => {
24373
24407
  const notificationOptions = { relatedRequestId: request.id };
24374
24408
  if (relatedTaskId) {
@@ -24377,25 +24411,24 @@ var Protocol = class {
24377
24411
  await this.notification(notification, notificationOptions);
24378
24412
  },
24379
24413
  sendRequest: async (r, resultSchema, options) => {
24380
- var _a2, _b2;
24381
24414
  const requestOptions = { ...options, relatedRequestId: request.id };
24382
24415
  if (relatedTaskId && !requestOptions.relatedTask) {
24383
24416
  requestOptions.relatedTask = { taskId: relatedTaskId };
24384
24417
  }
24385
- 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;
24386
24419
  if (effectiveTaskId && taskStore) {
24387
24420
  await taskStore.updateTaskStatus(effectiveTaskId, "input_required");
24388
24421
  }
24389
24422
  return await this.request(r, resultSchema, requestOptions);
24390
24423
  },
24391
- authInfo: extra === null || extra === void 0 ? void 0 : extra.authInfo,
24424
+ authInfo: extra?.authInfo,
24392
24425
  requestId: request.id,
24393
- requestInfo: extra === null || extra === void 0 ? void 0 : extra.requestInfo,
24426
+ requestInfo: extra?.requestInfo,
24394
24427
  taskId: relatedTaskId,
24395
24428
  taskStore,
24396
- taskRequestedTtl: taskCreationParams === null || taskCreationParams === void 0 ? void 0 : taskCreationParams.ttl,
24397
- closeSSEStream: extra === null || extra === void 0 ? void 0 : extra.closeSSEStream,
24398
- closeStandaloneSSEStream: extra === null || extra === void 0 ? void 0 : extra.closeStandaloneSSEStream
24429
+ taskRequestedTtl: taskCreationParams?.ttl,
24430
+ closeSSEStream: extra?.closeSSEStream,
24431
+ closeStandaloneSSEStream: extra?.closeStandaloneSSEStream
24399
24432
  };
24400
24433
  Promise.resolve().then(() => {
24401
24434
  if (taskCreationParams) {
@@ -24415,12 +24448,11 @@ var Protocol = class {
24415
24448
  type: "response",
24416
24449
  message: response,
24417
24450
  timestamp: Date.now()
24418
- }, capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.sessionId);
24451
+ }, capturedTransport?.sessionId);
24419
24452
  } else {
24420
- await (capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.send(response));
24453
+ await capturedTransport?.send(response);
24421
24454
  }
24422
24455
  }, async (error2) => {
24423
- var _a2;
24424
24456
  if (abortController.signal.aborted) {
24425
24457
  return;
24426
24458
  }
@@ -24429,7 +24461,7 @@ var Protocol = class {
24429
24461
  id: request.id,
24430
24462
  error: {
24431
24463
  code: Number.isSafeInteger(error2["code"]) ? error2["code"] : ErrorCode.InternalError,
24432
- message: (_a2 = error2.message) !== null && _a2 !== void 0 ? _a2 : "Internal error",
24464
+ message: error2.message ?? "Internal error",
24433
24465
  ...error2["data"] !== void 0 && { data: error2["data"] }
24434
24466
  }
24435
24467
  };
@@ -24438,9 +24470,9 @@ var Protocol = class {
24438
24470
  type: "error",
24439
24471
  message: errorResponse,
24440
24472
  timestamp: Date.now()
24441
- }, capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.sessionId);
24473
+ }, capturedTransport?.sessionId);
24442
24474
  } else {
24443
- await (capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.send(errorResponse));
24475
+ await capturedTransport?.send(errorResponse);
24444
24476
  }
24445
24477
  }).catch((error2) => this._onerror(new Error(`Failed to send response: ${error2}`))).finally(() => {
24446
24478
  this._requestHandlerAbortControllers.delete(request.id);
@@ -24474,7 +24506,7 @@ var Protocol = class {
24474
24506
  const resolver = this._requestResolvers.get(messageId);
24475
24507
  if (resolver) {
24476
24508
  this._requestResolvers.delete(messageId);
24477
- if (isJSONRPCResponse(response)) {
24509
+ if (isJSONRPCResultResponse(response)) {
24478
24510
  resolver(response);
24479
24511
  } else {
24480
24512
  const error2 = new McpError(response.error.code, response.error.message, response.error.data);
@@ -24490,7 +24522,7 @@ var Protocol = class {
24490
24522
  this._responseHandlers.delete(messageId);
24491
24523
  this._cleanupTimeout(messageId);
24492
24524
  let isTaskResponse = false;
24493
- if (isJSONRPCResponse(response) && response.result && typeof response.result === "object") {
24525
+ if (isJSONRPCResultResponse(response) && response.result && typeof response.result === "object") {
24494
24526
  const result = response.result;
24495
24527
  if (result.task && typeof result.task === "object") {
24496
24528
  const task = result.task;
@@ -24503,7 +24535,7 @@ var Protocol = class {
24503
24535
  if (!isTaskResponse) {
24504
24536
  this._progressHandlers.delete(messageId);
24505
24537
  }
24506
- if (isJSONRPCResponse(response)) {
24538
+ if (isJSONRPCResultResponse(response)) {
24507
24539
  handler(response);
24508
24540
  } else {
24509
24541
  const error2 = McpError.fromError(response.error.code, response.error.message, response.error.data);
@@ -24517,8 +24549,7 @@ var Protocol = class {
24517
24549
  * Closes the connection.
24518
24550
  */
24519
24551
  async close() {
24520
- var _a;
24521
- await ((_a = this._transport) === null || _a === void 0 ? void 0 : _a.close());
24552
+ await this._transport?.close();
24522
24553
  }
24523
24554
  /**
24524
24555
  * Sends a request and returns an AsyncGenerator that yields response messages.
@@ -24548,8 +24579,7 @@ var Protocol = class {
24548
24579
  * @experimental Use `client.experimental.tasks.requestStream()` to access this method.
24549
24580
  */
24550
24581
  async *requestStream(request, resultSchema, options) {
24551
- var _a, _b, _c, _d;
24552
- const { task } = options !== null && options !== void 0 ? options : {};
24582
+ const { task } = options ?? {};
24553
24583
  if (!task) {
24554
24584
  try {
24555
24585
  const result = await this.request(request, resultSchema, options);
@@ -24596,9 +24626,9 @@ var Protocol = class {
24596
24626
  yield { type: "result", result };
24597
24627
  return;
24598
24628
  }
24599
- 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;
24600
24630
  await new Promise((resolve) => setTimeout(resolve, pollInterval));
24601
- (_d = options === null || options === void 0 ? void 0 : options.signal) === null || _d === void 0 ? void 0 : _d.throwIfAborted();
24631
+ options?.signal?.throwIfAborted();
24602
24632
  }
24603
24633
  } catch (error2) {
24604
24634
  yield {
@@ -24613,9 +24643,8 @@ var Protocol = class {
24613
24643
  * Do not use this method to emit notifications! Use notification() instead.
24614
24644
  */
24615
24645
  request(request, resultSchema, options) {
24616
- const { relatedRequestId, resumptionToken, onresumptiontoken, task, relatedTask } = options !== null && options !== void 0 ? options : {};
24646
+ const { relatedRequestId, resumptionToken, onresumptiontoken, task, relatedTask } = options ?? {};
24617
24647
  return new Promise((resolve, reject) => {
24618
- var _a, _b, _c, _d, _e, _f, _g;
24619
24648
  const earlyReject = (error2) => {
24620
24649
  reject(error2);
24621
24650
  };
@@ -24623,7 +24652,7 @@ var Protocol = class {
24623
24652
  earlyReject(new Error("Not connected"));
24624
24653
  return;
24625
24654
  }
24626
- if (((_a = this._options) === null || _a === void 0 ? void 0 : _a.enforceStrictCapabilities) === true) {
24655
+ if (this._options?.enforceStrictCapabilities === true) {
24627
24656
  try {
24628
24657
  this.assertCapabilityForMethod(request.method);
24629
24658
  if (task) {
@@ -24634,19 +24663,19 @@ var Protocol = class {
24634
24663
  return;
24635
24664
  }
24636
24665
  }
24637
- (_b = options === null || options === void 0 ? void 0 : options.signal) === null || _b === void 0 ? void 0 : _b.throwIfAborted();
24666
+ options?.signal?.throwIfAborted();
24638
24667
  const messageId = this._requestMessageId++;
24639
24668
  const jsonrpcRequest = {
24640
24669
  ...request,
24641
24670
  jsonrpc: "2.0",
24642
24671
  id: messageId
24643
24672
  };
24644
- if (options === null || options === void 0 ? void 0 : options.onprogress) {
24673
+ if (options?.onprogress) {
24645
24674
  this._progressHandlers.set(messageId, options.onprogress);
24646
24675
  jsonrpcRequest.params = {
24647
24676
  ...request.params,
24648
24677
  _meta: {
24649
- ...((_c = request.params) === null || _c === void 0 ? void 0 : _c._meta) || {},
24678
+ ...request.params?._meta || {},
24650
24679
  progressToken: messageId
24651
24680
  }
24652
24681
  };
@@ -24661,17 +24690,16 @@ var Protocol = class {
24661
24690
  jsonrpcRequest.params = {
24662
24691
  ...jsonrpcRequest.params,
24663
24692
  _meta: {
24664
- ...((_d = jsonrpcRequest.params) === null || _d === void 0 ? void 0 : _d._meta) || {},
24693
+ ...jsonrpcRequest.params?._meta || {},
24665
24694
  [RELATED_TASK_META_KEY]: relatedTask
24666
24695
  }
24667
24696
  };
24668
24697
  }
24669
24698
  const cancel = (reason) => {
24670
- var _a2;
24671
24699
  this._responseHandlers.delete(messageId);
24672
24700
  this._progressHandlers.delete(messageId);
24673
24701
  this._cleanupTimeout(messageId);
24674
- (_a2 = this._transport) === null || _a2 === void 0 ? void 0 : _a2.send({
24702
+ this._transport?.send({
24675
24703
  jsonrpc: "2.0",
24676
24704
  method: "notifications/cancelled",
24677
24705
  params: {
@@ -24683,8 +24711,7 @@ var Protocol = class {
24683
24711
  reject(error2);
24684
24712
  };
24685
24713
  this._responseHandlers.set(messageId, (response) => {
24686
- var _a2;
24687
- if ((_a2 = options === null || options === void 0 ? void 0 : options.signal) === null || _a2 === void 0 ? void 0 : _a2.aborted) {
24714
+ if (options?.signal?.aborted) {
24688
24715
  return;
24689
24716
  }
24690
24717
  if (response instanceof Error) {
@@ -24701,14 +24728,13 @@ var Protocol = class {
24701
24728
  reject(error2);
24702
24729
  }
24703
24730
  });
24704
- (_e = options === null || options === void 0 ? void 0 : options.signal) === null || _e === void 0 ? void 0 : _e.addEventListener("abort", () => {
24705
- var _a2;
24706
- 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);
24707
24733
  });
24708
- 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;
24709
24735
  const timeoutHandler = () => cancel(McpError.fromError(ErrorCode.RequestTimeout, "Request timed out", { timeout }));
24710
- 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);
24711
- 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;
24712
24738
  if (relatedTaskId) {
24713
24739
  const responseResolver = (response) => {
24714
24740
  const handler = this._responseHandlers.get(messageId);
@@ -24771,12 +24797,11 @@ var Protocol = class {
24771
24797
  * Emits a notification, which is a one-way message that does not expect a response.
24772
24798
  */
24773
24799
  async notification(notification, options) {
24774
- var _a, _b, _c, _d, _e;
24775
24800
  if (!this._transport) {
24776
24801
  throw new Error("Not connected");
24777
24802
  }
24778
24803
  this.assertNotificationCapability(notification.method);
24779
- 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;
24780
24805
  if (relatedTaskId) {
24781
24806
  const jsonrpcNotification2 = {
24782
24807
  ...notification,
@@ -24784,7 +24809,7 @@ var Protocol = class {
24784
24809
  params: {
24785
24810
  ...notification.params,
24786
24811
  _meta: {
24787
- ...((_b = notification.params) === null || _b === void 0 ? void 0 : _b._meta) || {},
24812
+ ...notification.params?._meta || {},
24788
24813
  [RELATED_TASK_META_KEY]: options.relatedTask
24789
24814
  }
24790
24815
  }
@@ -24796,15 +24821,14 @@ var Protocol = class {
24796
24821
  });
24797
24822
  return;
24798
24823
  }
24799
- const debouncedMethods = (_d = (_c = this._options) === null || _c === void 0 ? void 0 : _c.debouncedNotificationMethods) !== null && _d !== void 0 ? _d : [];
24800
- 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;
24801
24826
  if (canDebounce) {
24802
24827
  if (this._pendingDebouncedNotifications.has(notification.method)) {
24803
24828
  return;
24804
24829
  }
24805
24830
  this._pendingDebouncedNotifications.add(notification.method);
24806
24831
  Promise.resolve().then(() => {
24807
- var _a2, _b2;
24808
24832
  this._pendingDebouncedNotifications.delete(notification.method);
24809
24833
  if (!this._transport) {
24810
24834
  return;
@@ -24813,19 +24837,19 @@ var Protocol = class {
24813
24837
  ...notification,
24814
24838
  jsonrpc: "2.0"
24815
24839
  };
24816
- if (options === null || options === void 0 ? void 0 : options.relatedTask) {
24840
+ if (options?.relatedTask) {
24817
24841
  jsonrpcNotification2 = {
24818
24842
  ...jsonrpcNotification2,
24819
24843
  params: {
24820
24844
  ...jsonrpcNotification2.params,
24821
24845
  _meta: {
24822
- ...((_a2 = jsonrpcNotification2.params) === null || _a2 === void 0 ? void 0 : _a2._meta) || {},
24846
+ ...jsonrpcNotification2.params?._meta || {},
24823
24847
  [RELATED_TASK_META_KEY]: options.relatedTask
24824
24848
  }
24825
24849
  }
24826
24850
  };
24827
24851
  }
24828
- (_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));
24829
24853
  });
24830
24854
  return;
24831
24855
  }
@@ -24833,13 +24857,13 @@ var Protocol = class {
24833
24857
  ...notification,
24834
24858
  jsonrpc: "2.0"
24835
24859
  };
24836
- if (options === null || options === void 0 ? void 0 : options.relatedTask) {
24860
+ if (options?.relatedTask) {
24837
24861
  jsonrpcNotification = {
24838
24862
  ...jsonrpcNotification,
24839
24863
  params: {
24840
24864
  ...jsonrpcNotification.params,
24841
24865
  _meta: {
24842
- ...((_e = jsonrpcNotification.params) === null || _e === void 0 ? void 0 : _e._meta) || {},
24866
+ ...jsonrpcNotification.params?._meta || {},
24843
24867
  [RELATED_TASK_META_KEY]: options.relatedTask
24844
24868
  }
24845
24869
  }
@@ -24915,11 +24939,10 @@ var Protocol = class {
24915
24939
  * simply propagates the error.
24916
24940
  */
24917
24941
  async _enqueueTaskMessage(taskId, message, sessionId) {
24918
- var _a;
24919
24942
  if (!this._taskStore || !this._taskMessageQueue) {
24920
24943
  throw new Error("Cannot enqueue task message: taskStore and taskMessageQueue are not configured");
24921
24944
  }
24922
- const maxQueueSize = (_a = this._options) === null || _a === void 0 ? void 0 : _a.maxTaskQueueSize;
24945
+ const maxQueueSize = this._options?.maxTaskQueueSize;
24923
24946
  await this._taskMessageQueue.enqueue(taskId, message, sessionId, maxQueueSize);
24924
24947
  }
24925
24948
  /**
@@ -24952,14 +24975,13 @@ var Protocol = class {
24952
24975
  * @returns Promise that resolves when an update occurs or rejects if aborted
24953
24976
  */
24954
24977
  async _waitForTaskUpdate(taskId, signal) {
24955
- var _a, _b, _c;
24956
- 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;
24957
24979
  try {
24958
- const task = await ((_c = this._taskStore) === null || _c === void 0 ? void 0 : _c.getTask(taskId));
24959
- if (task === null || task === void 0 ? void 0 : task.pollInterval) {
24980
+ const task = await this._taskStore?.getTask(taskId);
24981
+ if (task?.pollInterval) {
24960
24982
  interval = task.pollInterval;
24961
24983
  }
24962
- } catch (_d) {
24984
+ } catch {
24963
24985
  }
24964
24986
  return new Promise((resolve, reject) => {
24965
24987
  if (signal.aborted) {
@@ -25063,7 +25085,7 @@ function mergeCapabilities(base, additional) {
25063
25085
  var import_ajv = __toESM(require_ajv(), 1);
25064
25086
  var import_ajv_formats = __toESM(require_dist(), 1);
25065
25087
  function createDefaultAjvInstance() {
25066
- const ajv = new import_ajv.Ajv({
25088
+ const ajv = new import_ajv.default({
25067
25089
  strict: false,
25068
25090
  validateFormats: true,
25069
25091
  validateSchema: false,
@@ -25095,7 +25117,7 @@ var AjvJsonSchemaValidator = class {
25095
25117
  * ```
25096
25118
  */
25097
25119
  constructor(ajv) {
25098
- this._ajv = ajv !== null && ajv !== void 0 ? ajv : createDefaultAjvInstance();
25120
+ this._ajv = ajv ?? createDefaultAjvInstance();
25099
25121
  }
25100
25122
  /**
25101
25123
  * Create a validator for the given JSON Schema
@@ -25107,8 +25129,7 @@ var AjvJsonSchemaValidator = class {
25107
25129
  * @returns A validator function that validates input data
25108
25130
  */
25109
25131
  getValidator(schema) {
25110
- var _a;
25111
- 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);
25112
25133
  return (input) => {
25113
25134
  const valid = ajvValidator(input);
25114
25135
  if (valid) {
@@ -25202,13 +25223,12 @@ var ExperimentalServerTasks = class {
25202
25223
 
25203
25224
  // node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/helpers.js
25204
25225
  function assertToolsCallTaskCapability(requests, method, entityName) {
25205
- var _a;
25206
25226
  if (!requests) {
25207
25227
  throw new Error(`${entityName} does not support task creation (required for ${method})`);
25208
25228
  }
25209
25229
  switch (method) {
25210
25230
  case "tools/call":
25211
- if (!((_a = requests.tools) === null || _a === void 0 ? void 0 : _a.call)) {
25231
+ if (!requests.tools?.call) {
25212
25232
  throw new Error(`${entityName} does not support task creation for tools/call (required for ${method})`);
25213
25233
  }
25214
25234
  break;
@@ -25217,18 +25237,17 @@ function assertToolsCallTaskCapability(requests, method, entityName) {
25217
25237
  }
25218
25238
  }
25219
25239
  function assertClientRequestTaskCapability(requests, method, entityName) {
25220
- var _a, _b;
25221
25240
  if (!requests) {
25222
25241
  throw new Error(`${entityName} does not support task creation (required for ${method})`);
25223
25242
  }
25224
25243
  switch (method) {
25225
25244
  case "sampling/createMessage":
25226
- if (!((_a = requests.sampling) === null || _a === void 0 ? void 0 : _a.createMessage)) {
25245
+ if (!requests.sampling?.createMessage) {
25227
25246
  throw new Error(`${entityName} does not support task creation for sampling/createMessage (required for ${method})`);
25228
25247
  }
25229
25248
  break;
25230
25249
  case "elicitation/create":
25231
- if (!((_b = requests.elicitation) === null || _b === void 0 ? void 0 : _b.create)) {
25250
+ if (!requests.elicitation?.create) {
25232
25251
  throw new Error(`${entityName} does not support task creation for elicitation/create (required for ${method})`);
25233
25252
  }
25234
25253
  break;
@@ -25243,7 +25262,6 @@ var Server = class extends Protocol {
25243
25262
  * Initializes this server with the given name and version information.
25244
25263
  */
25245
25264
  constructor(_serverInfo, options) {
25246
- var _a, _b;
25247
25265
  super(options);
25248
25266
  this._serverInfo = _serverInfo;
25249
25267
  this._loggingLevels = /* @__PURE__ */ new Map();
@@ -25252,18 +25270,14 @@ var Server = class extends Protocol {
25252
25270
  const currentLevel = this._loggingLevels.get(sessionId);
25253
25271
  return currentLevel ? this.LOG_LEVEL_SEVERITY.get(level) < this.LOG_LEVEL_SEVERITY.get(currentLevel) : false;
25254
25272
  };
25255
- this._capabilities = (_a = options === null || options === void 0 ? void 0 : options.capabilities) !== null && _a !== void 0 ? _a : {};
25256
- this._instructions = options === null || options === void 0 ? void 0 : options.instructions;
25257
- 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();
25258
25276
  this.setRequestHandler(InitializeRequestSchema, (request) => this._oninitialize(request));
25259
- this.setNotificationHandler(InitializedNotificationSchema, () => {
25260
- var _a2;
25261
- return (_a2 = this.oninitialized) === null || _a2 === void 0 ? void 0 : _a2.call(this);
25262
- });
25277
+ this.setNotificationHandler(InitializedNotificationSchema, () => this.oninitialized?.());
25263
25278
  if (this._capabilities.logging) {
25264
25279
  this.setRequestHandler(SetLevelRequestSchema, async (request, extra) => {
25265
- var _a2;
25266
- 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;
25267
25281
  const { level } = request.params;
25268
25282
  const parseResult = LoggingLevelSchema.safeParse(level);
25269
25283
  if (parseResult.success) {
@@ -25303,21 +25317,20 @@ var Server = class extends Protocol {
25303
25317
  * Override request handler registration to enforce server-side validation for tools/call.
25304
25318
  */
25305
25319
  setRequestHandler(requestSchema, handler) {
25306
- var _a, _b, _c;
25307
25320
  const shape = getObjectShape(requestSchema);
25308
- const methodSchema = shape === null || shape === void 0 ? void 0 : shape.method;
25321
+ const methodSchema = shape?.method;
25309
25322
  if (!methodSchema) {
25310
25323
  throw new Error("Schema is missing a method literal");
25311
25324
  }
25312
25325
  let methodValue;
25313
25326
  if (isZ4Schema(methodSchema)) {
25314
25327
  const v4Schema = methodSchema;
25315
- const v4Def = (_a = v4Schema._zod) === null || _a === void 0 ? void 0 : _a.def;
25316
- 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;
25317
25330
  } else {
25318
25331
  const v3Schema = methodSchema;
25319
25332
  const legacyDef = v3Schema._def;
25320
- methodValue = (_c = legacyDef === null || legacyDef === void 0 ? void 0 : legacyDef.value) !== null && _c !== void 0 ? _c : v3Schema.value;
25333
+ methodValue = legacyDef?.value ?? v3Schema.value;
25321
25334
  }
25322
25335
  if (typeof methodValue !== "string") {
25323
25336
  throw new Error("Schema method literal must be a string");
@@ -25352,20 +25365,19 @@ var Server = class extends Protocol {
25352
25365
  return super.setRequestHandler(requestSchema, handler);
25353
25366
  }
25354
25367
  assertCapabilityForMethod(method) {
25355
- var _a, _b, _c;
25356
25368
  switch (method) {
25357
25369
  case "sampling/createMessage":
25358
- if (!((_a = this._clientCapabilities) === null || _a === void 0 ? void 0 : _a.sampling)) {
25370
+ if (!this._clientCapabilities?.sampling) {
25359
25371
  throw new Error(`Client does not support sampling (required for ${method})`);
25360
25372
  }
25361
25373
  break;
25362
25374
  case "elicitation/create":
25363
- if (!((_b = this._clientCapabilities) === null || _b === void 0 ? void 0 : _b.elicitation)) {
25375
+ if (!this._clientCapabilities?.elicitation) {
25364
25376
  throw new Error(`Client does not support elicitation (required for ${method})`);
25365
25377
  }
25366
25378
  break;
25367
25379
  case "roots/list":
25368
- if (!((_c = this._clientCapabilities) === null || _c === void 0 ? void 0 : _c.roots)) {
25380
+ if (!this._clientCapabilities?.roots) {
25369
25381
  throw new Error(`Client does not support listing roots (required for ${method})`);
25370
25382
  }
25371
25383
  break;
@@ -25374,7 +25386,6 @@ var Server = class extends Protocol {
25374
25386
  }
25375
25387
  }
25376
25388
  assertNotificationCapability(method) {
25377
- var _a, _b;
25378
25389
  switch (method) {
25379
25390
  case "notifications/message":
25380
25391
  if (!this._capabilities.logging) {
@@ -25398,7 +25409,7 @@ var Server = class extends Protocol {
25398
25409
  }
25399
25410
  break;
25400
25411
  case "notifications/elicitation/complete":
25401
- 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) {
25402
25413
  throw new Error(`Client does not support URL elicitation (required for ${method})`);
25403
25414
  }
25404
25415
  break;
@@ -25456,15 +25467,13 @@ var Server = class extends Protocol {
25456
25467
  }
25457
25468
  }
25458
25469
  assertTaskCapability(method) {
25459
- var _a, _b;
25460
- 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");
25461
25471
  }
25462
25472
  assertTaskHandlerCapability(method) {
25463
- var _a;
25464
25473
  if (!this._capabilities) {
25465
25474
  return;
25466
25475
  }
25467
- assertToolsCallTaskCapability((_a = this._capabilities.tasks) === null || _a === void 0 ? void 0 : _a.requests, method, "Server");
25476
+ assertToolsCallTaskCapability(this._capabilities.tasks?.requests, method, "Server");
25468
25477
  }
25469
25478
  async _oninitialize(request) {
25470
25479
  const requestedVersion = request.params.protocolVersion;
@@ -25498,9 +25507,8 @@ var Server = class extends Protocol {
25498
25507
  }
25499
25508
  // Implementation
25500
25509
  async createMessage(params, options) {
25501
- var _a, _b;
25502
25510
  if (params.tools || params.toolChoice) {
25503
- 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) {
25504
25512
  throw new Error("Client does not support sampling tools capability.");
25505
25513
  }
25506
25514
  }
@@ -25540,18 +25548,17 @@ var Server = class extends Protocol {
25540
25548
  * @returns The result of the elicitation request.
25541
25549
  */
25542
25550
  async elicitInput(params, options) {
25543
- var _a, _b, _c, _d, _e;
25544
- const mode = (_a = params.mode) !== null && _a !== void 0 ? _a : "form";
25551
+ const mode = params.mode ?? "form";
25545
25552
  switch (mode) {
25546
25553
  case "url": {
25547
- 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) {
25548
25555
  throw new Error("Client does not support url elicitation.");
25549
25556
  }
25550
25557
  const urlParams = params;
25551
25558
  return this.request({ method: "elicitation/create", params: urlParams }, ElicitResultSchema, options);
25552
25559
  }
25553
25560
  case "form": {
25554
- 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) {
25555
25562
  throw new Error("Client does not support form elicitation.");
25556
25563
  }
25557
25564
  const formParams = params.mode === "form" ? params : { ...params, mode: "form" };
@@ -25583,8 +25590,7 @@ var Server = class extends Protocol {
25583
25590
  * @returns A function that emits the completion notification when awaited.
25584
25591
  */
25585
25592
  createElicitationCompletionNotifier(elicitationId, options) {
25586
- var _a, _b;
25587
- 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) {
25588
25594
  throw new Error("Client does not support URL elicitation (required for notifications/elicitation/complete)");
25589
25595
  }
25590
25596
  return () => this.notification({
@@ -25631,13 +25637,13 @@ var Server = class extends Protocol {
25631
25637
  };
25632
25638
 
25633
25639
  // node_modules/@modelcontextprotocol/sdk/dist/esm/server/completable.js
25634
- var COMPLETABLE_SYMBOL = Symbol.for("mcp.completable");
25640
+ var COMPLETABLE_SYMBOL = /* @__PURE__ */ Symbol.for("mcp.completable");
25635
25641
  function isCompletable(schema) {
25636
25642
  return !!schema && typeof schema === "object" && COMPLETABLE_SYMBOL in schema;
25637
25643
  }
25638
25644
  function getCompleter(schema) {
25639
25645
  const meta = schema[COMPLETABLE_SYMBOL];
25640
- return meta === null || meta === void 0 ? void 0 : meta.complete;
25646
+ return meta?.complete;
25641
25647
  }
25642
25648
  var McpZodTypeKind;
25643
25649
  (function(McpZodTypeKind2) {
@@ -25800,7 +25806,6 @@ var McpServer = class {
25800
25806
  })
25801
25807
  }));
25802
25808
  this.server.setRequestHandler(CallToolRequestSchema, async (request, extra) => {
25803
- var _a;
25804
25809
  try {
25805
25810
  const tool = this._registeredTools[request.params.name];
25806
25811
  if (!tool) {
@@ -25810,7 +25815,7 @@ var McpServer = class {
25810
25815
  throw new McpError(ErrorCode.InvalidParams, `Tool ${request.params.name} disabled`);
25811
25816
  }
25812
25817
  const isTaskRequest = !!request.params.task;
25813
- const taskSupport = (_a = tool.execution) === null || _a === void 0 ? void 0 : _a.taskSupport;
25818
+ const taskSupport = tool.execution?.taskSupport;
25814
25819
  const isTaskHandler = "createTask" in tool.handler;
25815
25820
  if ((taskSupport === "required" || taskSupport === "optional") && !isTaskHandler) {
25816
25821
  throw new McpError(ErrorCode.InternalError, `Tool ${request.params.name} has taskSupport '${taskSupport}' but was not registered with registerToolTask`);
@@ -25864,7 +25869,7 @@ var McpServer = class {
25864
25869
  return void 0;
25865
25870
  }
25866
25871
  const inputObj = normalizeObjectSchema(tool.inputSchema);
25867
- const schemaToParse = inputObj !== null && inputObj !== void 0 ? inputObj : tool.inputSchema;
25872
+ const schemaToParse = inputObj ?? tool.inputSchema;
25868
25873
  const parseResult = await safeParseAsync3(schemaToParse, args);
25869
25874
  if (!parseResult.success) {
25870
25875
  const error2 = "error" in parseResult ? parseResult.error : "Unknown error";
@@ -25928,7 +25933,6 @@ var McpServer = class {
25928
25933
  * Handles automatic task polling for tools with taskSupport 'optional'.
25929
25934
  */
25930
25935
  async handleAutomaticTaskPolling(tool, request, extra) {
25931
- var _a;
25932
25936
  if (!extra.taskStore) {
25933
25937
  throw new Error("No task store provided for task-capable tool.");
25934
25938
  }
@@ -25941,7 +25945,7 @@ var McpServer = class {
25941
25945
  );
25942
25946
  const taskId = createTaskResult.task.taskId;
25943
25947
  let task = createTaskResult.task;
25944
- const pollInterval = (_a = task.pollInterval) !== null && _a !== void 0 ? _a : 5e3;
25948
+ const pollInterval = task.pollInterval ?? 5e3;
25945
25949
  while (task.status !== "completed" && task.status !== "failed" && task.status !== "cancelled") {
25946
25950
  await new Promise((resolve) => setTimeout(resolve, pollInterval));
25947
25951
  const updatedTask = await extra.taskStore.getTask(taskId);
@@ -25986,7 +25990,7 @@ var McpServer = class {
25986
25990
  return EMPTY_COMPLETION_RESULT;
25987
25991
  }
25988
25992
  const promptShape = getObjectShape(prompt.argsSchema);
25989
- const field = promptShape === null || promptShape === void 0 ? void 0 : promptShape[request.params.argument.name];
25993
+ const field = promptShape?.[request.params.argument.name];
25990
25994
  if (!isCompletable(field)) {
25991
25995
  return EMPTY_COMPLETION_RESULT;
25992
25996
  }
@@ -26071,7 +26075,6 @@ var McpServer = class {
26071
26075
  }
26072
26076
  throw new McpError(ErrorCode.InvalidParams, `Resource ${uri} not found`);
26073
26077
  });
26074
- this.setCompletionRequestHandler();
26075
26078
  this._resourceHandlersInitialized = true;
26076
26079
  }
26077
26080
  setPromptRequestHandlers() {
@@ -26119,7 +26122,6 @@ var McpServer = class {
26119
26122
  return await Promise.resolve(cb(extra));
26120
26123
  }
26121
26124
  });
26122
- this.setCompletionRequestHandler();
26123
26125
  this._promptHandlersInitialized = true;
26124
26126
  }
26125
26127
  resource(name, uriOrTemplate, ...rest) {
@@ -26227,6 +26229,11 @@ var McpServer = class {
26227
26229
  }
26228
26230
  };
26229
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
+ }
26230
26237
  return registeredResourceTemplate;
26231
26238
  }
26232
26239
  _createRegisteredPrompt(name, title, description, argsSchema, callback) {
@@ -26259,6 +26266,15 @@ var McpServer = class {
26259
26266
  }
26260
26267
  };
26261
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
+ }
26262
26278
  return registeredPrompt;
26263
26279
  }
26264
26280
  _createRegisteredTool(name, title, description, inputSchema, outputSchema, annotations, execution, _meta, handler) {
@@ -26291,6 +26307,8 @@ var McpServer = class {
26291
26307
  registeredTool.description = updates.description;
26292
26308
  if (typeof updates.paramsSchema !== "undefined")
26293
26309
  registeredTool.inputSchema = objectFromShape(updates.paramsSchema);
26310
+ if (typeof updates.outputSchema !== "undefined")
26311
+ registeredTool.outputSchema = objectFromShape(updates.outputSchema);
26294
26312
  if (typeof updates.callback !== "undefined")
26295
26313
  registeredTool.handler = updates.callback;
26296
26314
  if (typeof updates.annotations !== "undefined")
@@ -26465,7 +26483,7 @@ function promptArgumentsFromSchema(schema) {
26465
26483
  }
26466
26484
  function getMethodValue(schema) {
26467
26485
  const shape = getObjectShape(schema);
26468
- const methodSchema = shape === null || shape === void 0 ? void 0 : shape.method;
26486
+ const methodSchema = shape?.method;
26469
26487
  if (!methodSchema) {
26470
26488
  throw new Error("Schema is missing a method literal");
26471
26489
  }
@@ -26502,7 +26520,6 @@ function requestBodyToZod(requestBody, components) {
26502
26520
  } else if ("text/plain" in requestBody.content && requestBody.content["text/plain"].schema) {
26503
26521
  schema = external_exports.string();
26504
26522
  } else {
26505
- console.error(`Unsupported media type in request body: ${JSON.stringify(requestBody.content, null, 2)}`);
26506
26523
  return external_exports.never();
26507
26524
  }
26508
26525
  if (!requestBody.required) {
@@ -26550,7 +26567,13 @@ function jsonToZodValidation(_schema, components) {
26550
26567
  let combinator;
26551
26568
  if (schema.allOf) {
26552
26569
  const schemas = schema.allOf.map((s) => schemaToZod(s, components));
26553
- combinator = schemas.length > 0 ? schemas.reduce((acc, s) => external_exports.intersection(acc, s)) : external_exports.unknown();
26570
+ combinator = schemas.length > 0 ? schemas.reduce((acc, s) => zodMerge(acc, s)) : external_exports.unknown();
26571
+ if (combinator && isZodObject(combinator)) {
26572
+ const { discriminatorKey, discriminatorValue } = findDiscriminator(schema, components);
26573
+ if (discriminatorKey && discriminatorValue) {
26574
+ combinator = combinator.extend({ [discriminatorKey]: external_exports.literal(discriminatorValue) });
26575
+ }
26576
+ }
26554
26577
  }
26555
26578
  if (schema.oneOf) {
26556
26579
  const schemas = schema.oneOf.map((s) => schemaToZod(s, components));
@@ -26591,14 +26614,9 @@ function jsonToZodValidation(_schema, components) {
26591
26614
  const shape = {};
26592
26615
  if (schema.properties) {
26593
26616
  for (const [key, property] of Object.entries(schema.properties)) {
26594
- if ("discriminator" in schema && schema.discriminator?.propertyName === key) {
26595
- const values = Object.keys(schema.discriminator.mapping ?? {});
26596
- shape[key] = external_exports.union(values.map((v) => external_exports.literal(v))).describe("Discriminator property for a union.");
26597
- } else {
26598
- shape[key] = schemaToZod(property, components);
26599
- if (!schema.required?.includes(key)) {
26600
- shape[key] = shape[key].nullish();
26601
- }
26617
+ shape[key] = schemaToZod(property, components);
26618
+ if (!schema.required?.includes(key)) {
26619
+ shape[key] = shape[key].nullish();
26602
26620
  }
26603
26621
  }
26604
26622
  }
@@ -26606,7 +26624,7 @@ function jsonToZodValidation(_schema, components) {
26606
26624
  if (schema.additionalProperties) {
26607
26625
  return objectSchema.passthrough();
26608
26626
  }
26609
- return combinator ? external_exports.intersection(combinator, objectSchema) : objectSchema;
26627
+ return combinator ? zodMerge(combinator, objectSchema) : objectSchema;
26610
26628
  }
26611
26629
  }
26612
26630
  }
@@ -26633,7 +26651,7 @@ function resolveRef(ref, components) {
26633
26651
  throw new Error(`Unknown components section: ${section}`);
26634
26652
  }
26635
26653
  const resolved = group[name];
26636
- if (!resolved) {
26654
+ if (resolved === void 0 || resolved === null) {
26637
26655
  throw new Error(`Reference not found: ${ref}`);
26638
26656
  }
26639
26657
  if (resolved && typeof resolved === "object" && "$ref" in resolved && typeof resolved.$ref === "string") {
@@ -26641,6 +26659,29 @@ function resolveRef(ref, components) {
26641
26659
  }
26642
26660
  return resolved;
26643
26661
  }
26662
+ function findDiscriminator(schema, components) {
26663
+ const partWithDiscriminator = schema.allOf?.map((s) => deref(s, components)).find((s) => typeof s === "object" && "discriminator" in s);
26664
+ const discriminator = partWithDiscriminator?.discriminator;
26665
+ if (discriminator?.mapping) {
26666
+ const discriminatorMappingEntry = Object.entries(discriminator.mapping ?? {}).find(
26667
+ ([, discriminatorRef]) => resolveRef(discriminatorRef, components) === schema
26668
+ );
26669
+ if (discriminatorMappingEntry) {
26670
+ const [discriminatorValue] = discriminatorMappingEntry;
26671
+ return { discriminatorKey: discriminator.propertyName, discriminatorValue };
26672
+ }
26673
+ }
26674
+ return {};
26675
+ }
26676
+ function zodMerge(a, b) {
26677
+ if (isZodObject(a) && isZodObject(b)) {
26678
+ return a.extend(b.shape);
26679
+ }
26680
+ return external_exports.intersection(a, b);
26681
+ }
26682
+ function isZodObject(obj) {
26683
+ return "shape" in obj && "extend" in obj;
26684
+ }
26644
26685
 
26645
26686
  // src/utils.ts
26646
26687
  function info(...parts) {
@@ -26735,17 +26776,17 @@ function generateMcpTool(description, config2) {
26735
26776
  isError: true
26736
26777
  };
26737
26778
  }
26779
+ const isJsonResponse = response.headers.get("Content-Type")?.includes("application/json");
26738
26780
  if (!response.ok) {
26739
26781
  const errorObj = {
26740
26782
  url,
26741
26783
  method,
26742
26784
  body: "data" in params ? params.data : void 0,
26743
- response: await prettyRead(response)
26785
+ response: isJsonResponse ? await response.json() : await response.text()
26744
26786
  };
26745
26787
  const errorMsg = JSON.stringify(errorObj, null, 2);
26746
- return { content: [{ type: "text", text: errorMsg }], isError: true };
26788
+ return { content: [{ type: "text", text: "```json\n" + errorMsg + "\n```" }], isError: true };
26747
26789
  }
26748
- const isJsonResponse = response.headers.get("Content-Type")?.includes("application/json");
26749
26790
  try {
26750
26791
  if (isJsonResponse) {
26751
26792
  const text = JSON.stringify(await response.json(), null, 2);
@@ -26854,18 +26895,13 @@ function write(newStorage) {
26854
26895
  async function lookupOpenApiSpec(managementApiUrl2, secret) {
26855
26896
  const workingDir2 = process.cwd();
26856
26897
  let openApiSpec2 = await fetchOpenApiSpec(managementApiUrl2, secret);
26857
- if (!openApiSpec2 && workingDir2 && process.env.CACHE_OPENAPI !== "false") {
26858
- openApiSpec2 = storage.openapiSpecs?.[workingDir2];
26859
- }
26860
- if (!openApiSpec2) {
26861
- openApiSpec2 = await fetchOpenApiSpec(managementApiUrl2, secret);
26862
- if (!openApiSpec2) {
26863
- return;
26864
- }
26865
- if (workingDir2 && process.env.CACHE_OPENAPI !== "false") {
26898
+ if (workingDir2 && process.env.CACHE_OPENAPI !== "false") {
26899
+ if (openApiSpec2) {
26866
26900
  const openApiSpecs = storage.openapiSpecs ?? {};
26867
26901
  openApiSpecs[workingDir2] = openApiSpec2;
26868
26902
  storage.openapiSpecs = openApiSpecs;
26903
+ } else {
26904
+ openApiSpec2 = storage.openapiSpecs?.[workingDir2];
26869
26905
  }
26870
26906
  }
26871
26907
  return openApiSpec2;
@@ -26901,18 +26937,7 @@ var managementApiUrl = process.env.MANAGEMENT_API_URL;
26901
26937
  if (!managementApiUrl) {
26902
26938
  err(
26903
26939
  "MANAGEMENT_API_URL environment variable is not set.",
26904
- "Please configure your mcp config to set the MANAGEMENT_API_URL environment variable, example:",
26905
- {
26906
- mcpServers: {
26907
- xperience: {
26908
- type: "stdio",
26909
- command: "@kentico/management-api-mcp",
26910
- env: {
26911
- MANAGEMENT_API_URL: "https://localhost:12345/kentico-api/management"
26912
- }
26913
- }
26914
- }
26915
- }
26940
+ "Please configure your mcp config to set the MANAGEMENT_API_URL environment variable."
26916
26941
  );
26917
26942
  process.exit(1);
26918
26943
  }