@settlemint/sdk-mcp 2.6.4-pr836c05ff → 2.6.4-pr855d66d3

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/dist/mcp.js +971 -110
  2. package/dist/mcp.js.map +13 -9
  3. package/package.json +4 -4
package/dist/mcp.js CHANGED
@@ -60238,7 +60238,7 @@ function object(shape, params) {
60238
60238
  };
60239
60239
  return new ZodMiniObject(def);
60240
60240
  }
60241
- // ../../node_modules/.bun/@modelcontextprotocol+sdk@1.23.0/node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-compat.js
60241
+ // ../../node_modules/.bun/@modelcontextprotocol+sdk@1.24.3/node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-compat.js
60242
60242
  function isZ4Schema(s) {
60243
60243
  const schema = s;
60244
60244
  return !!schema._zod;
@@ -60313,7 +60313,7 @@ function normalizeObjectSchema(schema) {
60313
60313
  if (isZ4Schema(schema)) {
60314
60314
  const v4Schema = schema;
60315
60315
  const def = (_a = v4Schema._zod) === null || _a === undefined ? undefined : _a.def;
60316
- if (def && (def.typeName === "object" || def.shape !== undefined)) {
60316
+ if (def && (def.type === "object" || def.shape !== undefined)) {
60317
60317
  return schema;
60318
60318
  }
60319
60319
  } else {
@@ -60356,7 +60356,7 @@ function isSchemaOptional(schema) {
60356
60356
  var _a, _b, _c;
60357
60357
  if (isZ4Schema(schema)) {
60358
60358
  const v4Schema = schema;
60359
- return ((_b = (_a = v4Schema._zod) === null || _a === undefined ? undefined : _a.def) === null || _b === undefined ? undefined : _b.typeName) === "ZodOptional";
60359
+ return ((_b = (_a = v4Schema._zod) === null || _a === undefined ? undefined : _a.def) === null || _b === undefined ? undefined : _b.type) === "optional";
60360
60360
  }
60361
60361
  const v3Schema = schema;
60362
60362
  if (typeof schema.isOptional === "function") {
@@ -61730,17 +61730,27 @@ function date4(params) {
61730
61730
  // ../../node_modules/.bun/zod@4.1.12/node_modules/zod/v4/classic/external.js
61731
61731
  config(en_default2());
61732
61732
 
61733
- // ../../node_modules/.bun/@modelcontextprotocol+sdk@1.23.0/node_modules/@modelcontextprotocol/sdk/dist/esm/types.js
61734
- var LATEST_PROTOCOL_VERSION = "2025-06-18";
61735
- var SUPPORTED_PROTOCOL_VERSIONS = [LATEST_PROTOCOL_VERSION, "2025-03-26", "2024-11-05", "2024-10-07"];
61733
+ // ../../node_modules/.bun/@modelcontextprotocol+sdk@1.24.3/node_modules/@modelcontextprotocol/sdk/dist/esm/types.js
61734
+ var LATEST_PROTOCOL_VERSION = "2025-11-25";
61735
+ var SUPPORTED_PROTOCOL_VERSIONS = [LATEST_PROTOCOL_VERSION, "2025-06-18", "2025-03-26", "2024-11-05", "2024-10-07"];
61736
+ var RELATED_TASK_META_KEY = "io.modelcontextprotocol/related-task";
61736
61737
  var JSONRPC_VERSION = "2.0";
61737
61738
  var AssertObjectSchema = custom((v) => v !== null && (typeof v === "object" || typeof v === "function"));
61738
61739
  var ProgressTokenSchema = union([string2(), number2().int()]);
61739
61740
  var CursorSchema = string2();
61741
+ var TaskCreationParamsSchema = looseObject({
61742
+ ttl: union([number2(), _null3()]).optional(),
61743
+ pollInterval: number2().optional()
61744
+ });
61745
+ var RelatedTaskMetadataSchema = looseObject({
61746
+ taskId: string2()
61747
+ });
61740
61748
  var RequestMetaSchema = looseObject({
61741
- progressToken: ProgressTokenSchema.optional()
61749
+ progressToken: ProgressTokenSchema.optional(),
61750
+ [RELATED_TASK_META_KEY]: RelatedTaskMetadataSchema.optional()
61742
61751
  });
61743
61752
  var BaseRequestParamsSchema = looseObject({
61753
+ task: TaskCreationParamsSchema.optional(),
61744
61754
  _meta: RequestMetaSchema.optional()
61745
61755
  });
61746
61756
  var RequestSchema = object2({
@@ -61748,14 +61758,18 @@ var RequestSchema = object2({
61748
61758
  params: BaseRequestParamsSchema.optional()
61749
61759
  });
61750
61760
  var NotificationsParamsSchema = looseObject({
61751
- _meta: record(string2(), unknown()).optional()
61761
+ _meta: object2({
61762
+ [RELATED_TASK_META_KEY]: optional(RelatedTaskMetadataSchema)
61763
+ }).passthrough().optional()
61752
61764
  });
61753
61765
  var NotificationSchema = object2({
61754
61766
  method: string2(),
61755
61767
  params: NotificationsParamsSchema.optional()
61756
61768
  });
61757
61769
  var ResultSchema = looseObject({
61758
- _meta: record(string2(), unknown()).optional()
61770
+ _meta: looseObject({
61771
+ [RELATED_TASK_META_KEY]: RelatedTaskMetadataSchema.optional()
61772
+ }).optional()
61759
61773
  });
61760
61774
  var RequestIdSchema = union([string2(), number2().int()]);
61761
61775
  var JSONRPCRequestSchema = object2({
@@ -61838,6 +61852,27 @@ var ElicitationCapabilitySchema = preprocess((value) => {
61838
61852
  form: FormElicitationCapabilitySchema.optional(),
61839
61853
  url: AssertObjectSchema.optional()
61840
61854
  }), record(string2(), unknown()).optional()));
61855
+ var ClientTasksCapabilitySchema = object2({
61856
+ list: optional(object2({}).passthrough()),
61857
+ cancel: optional(object2({}).passthrough()),
61858
+ requests: optional(object2({
61859
+ sampling: optional(object2({
61860
+ createMessage: optional(object2({}).passthrough())
61861
+ }).passthrough()),
61862
+ elicitation: optional(object2({
61863
+ create: optional(object2({}).passthrough())
61864
+ }).passthrough())
61865
+ }).passthrough())
61866
+ }).passthrough();
61867
+ var ServerTasksCapabilitySchema = object2({
61868
+ list: optional(object2({}).passthrough()),
61869
+ cancel: optional(object2({}).passthrough()),
61870
+ requests: optional(object2({
61871
+ tools: optional(object2({
61872
+ call: optional(object2({}).passthrough())
61873
+ }).passthrough())
61874
+ }).passthrough())
61875
+ }).passthrough();
61841
61876
  var ClientCapabilitiesSchema = object2({
61842
61877
  experimental: record(string2(), AssertObjectSchema).optional(),
61843
61878
  sampling: object2({
@@ -61847,7 +61882,8 @@ var ClientCapabilitiesSchema = object2({
61847
61882
  elicitation: ElicitationCapabilitySchema.optional(),
61848
61883
  roots: object2({
61849
61884
  listChanged: boolean2().optional()
61850
- }).optional()
61885
+ }).optional(),
61886
+ tasks: optional(ClientTasksCapabilitySchema)
61851
61887
  });
61852
61888
  var InitializeRequestParamsSchema = BaseRequestParamsSchema.extend({
61853
61889
  protocolVersion: string2(),
@@ -61871,8 +61907,9 @@ var ServerCapabilitiesSchema = object2({
61871
61907
  }).optional(),
61872
61908
  tools: object2({
61873
61909
  listChanged: boolean2().optional()
61874
- }).optional()
61875
- });
61910
+ }).optional(),
61911
+ tasks: optional(ServerTasksCapabilitySchema)
61912
+ }).passthrough();
61876
61913
  var InitializeResultSchema = ResultSchema.extend({
61877
61914
  protocolVersion: string2(),
61878
61915
  capabilities: ServerCapabilitiesSchema,
@@ -61908,6 +61945,49 @@ var PaginatedRequestSchema = RequestSchema.extend({
61908
61945
  var PaginatedResultSchema = ResultSchema.extend({
61909
61946
  nextCursor: optional(CursorSchema)
61910
61947
  });
61948
+ var TaskSchema = object2({
61949
+ taskId: string2(),
61950
+ status: _enum2(["working", "input_required", "completed", "failed", "cancelled"]),
61951
+ ttl: union([number2(), _null3()]),
61952
+ createdAt: string2(),
61953
+ lastUpdatedAt: string2(),
61954
+ pollInterval: optional(number2()),
61955
+ statusMessage: optional(string2())
61956
+ });
61957
+ var CreateTaskResultSchema = ResultSchema.extend({
61958
+ task: TaskSchema
61959
+ });
61960
+ var TaskStatusNotificationParamsSchema = NotificationsParamsSchema.merge(TaskSchema);
61961
+ var TaskStatusNotificationSchema = NotificationSchema.extend({
61962
+ method: literal("notifications/tasks/status"),
61963
+ params: TaskStatusNotificationParamsSchema
61964
+ });
61965
+ var GetTaskRequestSchema = RequestSchema.extend({
61966
+ method: literal("tasks/get"),
61967
+ params: BaseRequestParamsSchema.extend({
61968
+ taskId: string2()
61969
+ })
61970
+ });
61971
+ var GetTaskResultSchema = ResultSchema.merge(TaskSchema);
61972
+ var GetTaskPayloadRequestSchema = RequestSchema.extend({
61973
+ method: literal("tasks/result"),
61974
+ params: BaseRequestParamsSchema.extend({
61975
+ taskId: string2()
61976
+ })
61977
+ });
61978
+ var ListTasksRequestSchema = PaginatedRequestSchema.extend({
61979
+ method: literal("tasks/list")
61980
+ });
61981
+ var ListTasksResultSchema = PaginatedResultSchema.extend({
61982
+ tasks: array(TaskSchema)
61983
+ });
61984
+ var CancelTaskRequestSchema = RequestSchema.extend({
61985
+ method: literal("tasks/cancel"),
61986
+ params: BaseRequestParamsSchema.extend({
61987
+ taskId: string2()
61988
+ })
61989
+ });
61990
+ var CancelTaskResultSchema = ResultSchema.merge(TaskSchema);
61911
61991
  var ResourceContentsSchema = object2({
61912
61992
  uri: string2(),
61913
61993
  mimeType: optional(string2()),
@@ -61927,12 +62007,18 @@ var Base64Schema = string2().refine((val) => {
61927
62007
  var BlobResourceContentsSchema = ResourceContentsSchema.extend({
61928
62008
  blob: Base64Schema
61929
62009
  });
62010
+ var AnnotationsSchema = object2({
62011
+ audience: array(_enum2(["user", "assistant"])).optional(),
62012
+ priority: number2().min(0).max(1).optional(),
62013
+ lastModified: exports_iso2.datetime({ offset: true }).optional()
62014
+ });
61930
62015
  var ResourceSchema = object2({
61931
62016
  ...BaseMetadataSchema.shape,
61932
62017
  ...IconsSchema.shape,
61933
62018
  uri: string2(),
61934
62019
  description: optional(string2()),
61935
62020
  mimeType: optional(string2()),
62021
+ annotations: AnnotationsSchema.optional(),
61936
62022
  _meta: optional(looseObject({}))
61937
62023
  });
61938
62024
  var ResourceTemplateSchema = object2({
@@ -61941,6 +62027,7 @@ var ResourceTemplateSchema = object2({
61941
62027
  uriTemplate: string2(),
61942
62028
  description: optional(string2()),
61943
62029
  mimeType: optional(string2()),
62030
+ annotations: AnnotationsSchema.optional(),
61944
62031
  _meta: optional(looseObject({}))
61945
62032
  });
61946
62033
  var ListResourcesRequestSchema = PaginatedRequestSchema.extend({
@@ -62015,18 +62102,21 @@ var GetPromptRequestSchema = RequestSchema.extend({
62015
62102
  var TextContentSchema = object2({
62016
62103
  type: literal("text"),
62017
62104
  text: string2(),
62105
+ annotations: AnnotationsSchema.optional(),
62018
62106
  _meta: record(string2(), unknown()).optional()
62019
62107
  });
62020
62108
  var ImageContentSchema = object2({
62021
62109
  type: literal("image"),
62022
62110
  data: Base64Schema,
62023
62111
  mimeType: string2(),
62112
+ annotations: AnnotationsSchema.optional(),
62024
62113
  _meta: record(string2(), unknown()).optional()
62025
62114
  });
62026
62115
  var AudioContentSchema = object2({
62027
62116
  type: literal("audio"),
62028
62117
  data: Base64Schema,
62029
62118
  mimeType: string2(),
62119
+ annotations: AnnotationsSchema.optional(),
62030
62120
  _meta: record(string2(), unknown()).optional()
62031
62121
  });
62032
62122
  var ToolUseContentSchema = object2({
@@ -62039,6 +62129,7 @@ var ToolUseContentSchema = object2({
62039
62129
  var EmbeddedResourceSchema = object2({
62040
62130
  type: literal("resource"),
62041
62131
  resource: union([TextResourceContentsSchema, BlobResourceContentsSchema]),
62132
+ annotations: AnnotationsSchema.optional(),
62042
62133
  _meta: record(string2(), unknown()).optional()
62043
62134
  });
62044
62135
  var ResourceLinkSchema = ResourceSchema.extend({
@@ -62069,6 +62160,9 @@ var ToolAnnotationsSchema = object2({
62069
62160
  idempotentHint: boolean2().optional(),
62070
62161
  openWorldHint: boolean2().optional()
62071
62162
  });
62163
+ var ToolExecutionSchema = object2({
62164
+ taskSupport: _enum2(["required", "optional", "forbidden"]).optional()
62165
+ });
62072
62166
  var ToolSchema = object2({
62073
62167
  ...BaseMetadataSchema.shape,
62074
62168
  ...IconsSchema.shape,
@@ -62084,6 +62178,7 @@ var ToolSchema = object2({
62084
62178
  required: array(string2()).optional()
62085
62179
  }).catchall(unknown()).optional(),
62086
62180
  annotations: optional(ToolAnnotationsSchema),
62181
+ execution: optional(ToolExecutionSchema),
62087
62182
  _meta: record(string2(), unknown()).optional()
62088
62183
  });
62089
62184
  var ListToolsRequestSchema = PaginatedRequestSchema.extend({
@@ -62148,6 +62243,7 @@ var ToolResultContentSchema = object2({
62148
62243
  isError: optional(boolean2()),
62149
62244
  _meta: optional(object2({}).passthrough())
62150
62245
  }).passthrough();
62246
+ var SamplingContentSchema = discriminatedUnion("type", [TextContentSchema, ImageContentSchema, AudioContentSchema]);
62151
62247
  var SamplingMessageContentBlockSchema = discriminatedUnion("type", [
62152
62248
  TextContentSchema,
62153
62249
  ImageContentSchema,
@@ -62177,6 +62273,12 @@ var CreateMessageRequestSchema = RequestSchema.extend({
62177
62273
  params: CreateMessageRequestParamsSchema
62178
62274
  });
62179
62275
  var CreateMessageResultSchema = ResultSchema.extend({
62276
+ model: string2(),
62277
+ stopReason: optional(_enum2(["endTurn", "stopSequence", "maxTokens"]).or(string2())),
62278
+ role: _enum2(["user", "assistant"]),
62279
+ content: SamplingContentSchema
62280
+ });
62281
+ var CreateMessageResultWithToolsSchema = ResultSchema.extend({
62180
62282
  model: string2(),
62181
62283
  stopReason: optional(_enum2(["endTurn", "stopSequence", "maxTokens", "toolUse"]).or(string2())),
62182
62284
  role: _enum2(["user", "assistant"]),
@@ -62289,7 +62391,7 @@ var ElicitationCompleteNotificationSchema = NotificationSchema.extend({
62289
62391
  });
62290
62392
  var ElicitResultSchema = ResultSchema.extend({
62291
62393
  action: _enum2(["accept", "decline", "cancel"]),
62292
- content: record(string2(), union([string2(), number2(), boolean2(), array(string2())])).optional()
62394
+ content: preprocess((val) => val === null ? undefined : val, record(string2(), union([string2(), number2(), boolean2(), array(string2())])).optional())
62293
62395
  });
62294
62396
  var ResourceTemplateReferenceSchema = object2({
62295
62397
  type: literal("ref/resource"),
@@ -62357,16 +62459,37 @@ var ClientRequestSchema = union([
62357
62459
  SubscribeRequestSchema,
62358
62460
  UnsubscribeRequestSchema,
62359
62461
  CallToolRequestSchema,
62360
- ListToolsRequestSchema
62462
+ ListToolsRequestSchema,
62463
+ GetTaskRequestSchema,
62464
+ GetTaskPayloadRequestSchema,
62465
+ ListTasksRequestSchema
62361
62466
  ]);
62362
62467
  var ClientNotificationSchema = union([
62363
62468
  CancelledNotificationSchema,
62364
62469
  ProgressNotificationSchema,
62365
62470
  InitializedNotificationSchema,
62366
- RootsListChangedNotificationSchema
62471
+ RootsListChangedNotificationSchema,
62472
+ TaskStatusNotificationSchema
62473
+ ]);
62474
+ var ClientResultSchema = union([
62475
+ EmptyResultSchema,
62476
+ CreateMessageResultSchema,
62477
+ CreateMessageResultWithToolsSchema,
62478
+ ElicitResultSchema,
62479
+ ListRootsResultSchema,
62480
+ GetTaskResultSchema,
62481
+ ListTasksResultSchema,
62482
+ CreateTaskResultSchema
62483
+ ]);
62484
+ var ServerRequestSchema = union([
62485
+ PingRequestSchema,
62486
+ CreateMessageRequestSchema,
62487
+ ElicitRequestSchema,
62488
+ ListRootsRequestSchema,
62489
+ GetTaskRequestSchema,
62490
+ GetTaskPayloadRequestSchema,
62491
+ ListTasksRequestSchema
62367
62492
  ]);
62368
- var ClientResultSchema = union([EmptyResultSchema, CreateMessageResultSchema, ElicitResultSchema, ListRootsResultSchema]);
62369
- var ServerRequestSchema = union([PingRequestSchema, CreateMessageRequestSchema, ElicitRequestSchema, ListRootsRequestSchema]);
62370
62493
  var ServerNotificationSchema = union([
62371
62494
  CancelledNotificationSchema,
62372
62495
  ProgressNotificationSchema,
@@ -62375,6 +62498,7 @@ var ServerNotificationSchema = union([
62375
62498
  ResourceListChangedNotificationSchema,
62376
62499
  ToolListChangedNotificationSchema,
62377
62500
  PromptListChangedNotificationSchema,
62501
+ TaskStatusNotificationSchema,
62378
62502
  ElicitationCompleteNotificationSchema
62379
62503
  ]);
62380
62504
  var ServerResultSchema = union([
@@ -62387,7 +62511,10 @@ var ServerResultSchema = union([
62387
62511
  ListResourceTemplatesResultSchema,
62388
62512
  ReadResourceResultSchema,
62389
62513
  CallToolResultSchema,
62390
- ListToolsResultSchema
62514
+ ListToolsResultSchema,
62515
+ GetTaskResultSchema,
62516
+ ListTasksResultSchema,
62517
+ CreateTaskResultSchema
62391
62518
  ]);
62392
62519
 
62393
62520
  class McpError extends Error {
@@ -62420,6 +62547,11 @@ class UrlElicitationRequiredError extends McpError {
62420
62547
  }
62421
62548
  }
62422
62549
 
62550
+ // ../../node_modules/.bun/@modelcontextprotocol+sdk@1.24.3/node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/interfaces.js
62551
+ function isTerminal(status) {
62552
+ return status === "completed" || status === "failed" || status === "cancelled";
62553
+ }
62554
+
62423
62555
  // ../../node_modules/.bun/zod-to-json-schema@3.25.0+5954958163efbb2a/node_modules/zod-to-json-schema/dist/esm/Options.js
62424
62556
  var ignoreOverride = Symbol("Let zodToJsonSchema decide on which parser to use");
62425
62557
  var defaultOptions = {
@@ -63656,7 +63788,7 @@ var zodToJsonSchema = (schema, options) => {
63656
63788
  }
63657
63789
  return combined;
63658
63790
  };
63659
- // ../../node_modules/.bun/@modelcontextprotocol+sdk@1.23.0/node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-json-schema-compat.js
63791
+ // ../../node_modules/.bun/@modelcontextprotocol+sdk@1.24.3/node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-json-schema-compat.js
63660
63792
  function mapMiniTarget(t) {
63661
63793
  if (!t)
63662
63794
  return "draft-7";
@@ -63699,7 +63831,7 @@ function parseWithCompat(schema, data) {
63699
63831
  return result.data;
63700
63832
  }
63701
63833
 
63702
- // ../../node_modules/.bun/@modelcontextprotocol+sdk@1.23.0/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/protocol.js
63834
+ // ../../node_modules/.bun/@modelcontextprotocol+sdk@1.24.3/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/protocol.js
63703
63835
  var DEFAULT_REQUEST_TIMEOUT_MSEC = 60000;
63704
63836
 
63705
63837
  class Protocol {
@@ -63713,14 +63845,125 @@ class Protocol {
63713
63845
  this._progressHandlers = new Map;
63714
63846
  this._timeoutInfo = new Map;
63715
63847
  this._pendingDebouncedNotifications = new Set;
63848
+ this._taskProgressTokens = new Map;
63849
+ this._requestResolvers = new Map;
63716
63850
  this.setNotificationHandler(CancelledNotificationSchema, (notification) => {
63717
- const controller = this._requestHandlerAbortControllers.get(notification.params.requestId);
63718
- controller === null || controller === undefined || controller.abort(notification.params.reason);
63851
+ this._oncancel(notification);
63719
63852
  });
63720
63853
  this.setNotificationHandler(ProgressNotificationSchema, (notification) => {
63721
63854
  this._onprogress(notification);
63722
63855
  });
63723
63856
  this.setRequestHandler(PingRequestSchema, (_request) => ({}));
63857
+ this._taskStore = _options === null || _options === undefined ? undefined : _options.taskStore;
63858
+ this._taskMessageQueue = _options === null || _options === undefined ? undefined : _options.taskMessageQueue;
63859
+ if (this._taskStore) {
63860
+ this.setRequestHandler(GetTaskRequestSchema, async (request, extra) => {
63861
+ const task = await this._taskStore.getTask(request.params.taskId, extra.sessionId);
63862
+ if (!task) {
63863
+ throw new McpError(ErrorCode.InvalidParams, "Failed to retrieve task: Task not found");
63864
+ }
63865
+ return {
63866
+ ...task
63867
+ };
63868
+ });
63869
+ this.setRequestHandler(GetTaskPayloadRequestSchema, async (request, extra) => {
63870
+ const handleTaskResult = async () => {
63871
+ var _a;
63872
+ const taskId = request.params.taskId;
63873
+ if (this._taskMessageQueue) {
63874
+ let queuedMessage;
63875
+ while (queuedMessage = await this._taskMessageQueue.dequeue(taskId, extra.sessionId)) {
63876
+ if (queuedMessage.type === "response" || queuedMessage.type === "error") {
63877
+ const message = queuedMessage.message;
63878
+ const requestId = message.id;
63879
+ const resolver = this._requestResolvers.get(requestId);
63880
+ if (resolver) {
63881
+ this._requestResolvers.delete(requestId);
63882
+ if (queuedMessage.type === "response") {
63883
+ resolver(message);
63884
+ } else {
63885
+ const errorMessage = message;
63886
+ const error46 = new McpError(errorMessage.error.code, errorMessage.error.message, errorMessage.error.data);
63887
+ resolver(error46);
63888
+ }
63889
+ } else {
63890
+ const messageType = queuedMessage.type === "response" ? "Response" : "Error";
63891
+ this._onerror(new Error(`${messageType} handler missing for request ${requestId}`));
63892
+ }
63893
+ continue;
63894
+ }
63895
+ await ((_a = this._transport) === null || _a === undefined ? undefined : _a.send(queuedMessage.message, { relatedRequestId: extra.requestId }));
63896
+ }
63897
+ }
63898
+ const task = await this._taskStore.getTask(taskId, extra.sessionId);
63899
+ if (!task) {
63900
+ throw new McpError(ErrorCode.InvalidParams, `Task not found: ${taskId}`);
63901
+ }
63902
+ if (!isTerminal(task.status)) {
63903
+ await this._waitForTaskUpdate(taskId, extra.signal);
63904
+ return await handleTaskResult();
63905
+ }
63906
+ if (isTerminal(task.status)) {
63907
+ const result = await this._taskStore.getTaskResult(taskId, extra.sessionId);
63908
+ this._clearTaskQueue(taskId);
63909
+ return {
63910
+ ...result,
63911
+ _meta: {
63912
+ ...result._meta,
63913
+ [RELATED_TASK_META_KEY]: {
63914
+ taskId
63915
+ }
63916
+ }
63917
+ };
63918
+ }
63919
+ return await handleTaskResult();
63920
+ };
63921
+ return await handleTaskResult();
63922
+ });
63923
+ this.setRequestHandler(ListTasksRequestSchema, async (request, extra) => {
63924
+ var _a;
63925
+ try {
63926
+ const { tasks, nextCursor } = await this._taskStore.listTasks((_a = request.params) === null || _a === undefined ? undefined : _a.cursor, extra.sessionId);
63927
+ return {
63928
+ tasks,
63929
+ nextCursor,
63930
+ _meta: {}
63931
+ };
63932
+ } catch (error46) {
63933
+ throw new McpError(ErrorCode.InvalidParams, `Failed to list tasks: ${error46 instanceof Error ? error46.message : String(error46)}`);
63934
+ }
63935
+ });
63936
+ this.setRequestHandler(CancelTaskRequestSchema, async (request, extra) => {
63937
+ try {
63938
+ const task = await this._taskStore.getTask(request.params.taskId, extra.sessionId);
63939
+ if (!task) {
63940
+ throw new McpError(ErrorCode.InvalidParams, `Task not found: ${request.params.taskId}`);
63941
+ }
63942
+ if (isTerminal(task.status)) {
63943
+ throw new McpError(ErrorCode.InvalidParams, `Cannot cancel task in terminal status: ${task.status}`);
63944
+ }
63945
+ await this._taskStore.updateTaskStatus(request.params.taskId, "cancelled", "Client cancelled task execution.", extra.sessionId);
63946
+ this._clearTaskQueue(request.params.taskId);
63947
+ const cancelledTask = await this._taskStore.getTask(request.params.taskId, extra.sessionId);
63948
+ if (!cancelledTask) {
63949
+ throw new McpError(ErrorCode.InvalidParams, `Task not found after cancellation: ${request.params.taskId}`);
63950
+ }
63951
+ return {
63952
+ _meta: {},
63953
+ ...cancelledTask
63954
+ };
63955
+ } catch (error46) {
63956
+ if (error46 instanceof McpError) {
63957
+ throw error46;
63958
+ }
63959
+ throw new McpError(ErrorCode.InvalidRequest, `Failed to cancel task: ${error46 instanceof Error ? error46.message : String(error46)}`);
63960
+ }
63961
+ });
63962
+ }
63963
+ }
63964
+ async _oncancel(notification) {
63965
+ const controller = this._requestHandlerAbortControllers.get(notification.params.requestId);
63966
+ controller === null || controller === undefined || controller.abort(notification.params.reason);
63724
63967
  }
63725
63968
  _setupTimeout(messageId, timeout, maxTotalTimeout, onTimeout, resetTimeoutOnProgress = false) {
63726
63969
  this._timeoutInfo.set(messageId, {
@@ -63788,10 +64031,11 @@ class Protocol {
63788
64031
  const responseHandlers = this._responseHandlers;
63789
64032
  this._responseHandlers = new Map;
63790
64033
  this._progressHandlers.clear();
64034
+ this._taskProgressTokens.clear();
63791
64035
  this._pendingDebouncedNotifications.clear();
64036
+ const error46 = McpError.fromError(ErrorCode.ConnectionClosed, "Connection closed");
63792
64037
  this._transport = undefined;
63793
64038
  (_a = this.onclose) === null || _a === undefined || _a.call(this);
63794
- const error46 = McpError.fromError(ErrorCode.ConnectionClosed, "Connection closed");
63795
64039
  for (const handler of responseHandlers.values()) {
63796
64040
  handler(error46);
63797
64041
  }
@@ -63809,47 +64053,94 @@ class Protocol {
63809
64053
  Promise.resolve().then(() => handler(notification)).catch((error46) => this._onerror(new Error(`Uncaught error in notification handler: ${error46}`)));
63810
64054
  }
63811
64055
  _onrequest(request, extra) {
63812
- var _a, _b;
64056
+ var _a, _b, _c, _d, _e, _f;
63813
64057
  const handler = (_a = this._requestHandlers.get(request.method)) !== null && _a !== undefined ? _a : this.fallbackRequestHandler;
63814
64058
  const capturedTransport = this._transport;
64059
+ const relatedTaskId = (_d = (_c = (_b = request.params) === null || _b === undefined ? undefined : _b._meta) === null || _c === undefined ? undefined : _c[RELATED_TASK_META_KEY]) === null || _d === undefined ? undefined : _d.taskId;
63815
64060
  if (handler === undefined) {
63816
- capturedTransport === null || capturedTransport === undefined || capturedTransport.send({
64061
+ const errorResponse = {
63817
64062
  jsonrpc: "2.0",
63818
64063
  id: request.id,
63819
64064
  error: {
63820
64065
  code: ErrorCode.MethodNotFound,
63821
64066
  message: "Method not found"
63822
64067
  }
63823
- }).catch((error46) => this._onerror(new Error(`Failed to send an error response: ${error46}`)));
64068
+ };
64069
+ if (relatedTaskId && this._taskMessageQueue) {
64070
+ this._enqueueTaskMessage(relatedTaskId, {
64071
+ type: "error",
64072
+ message: errorResponse,
64073
+ timestamp: Date.now()
64074
+ }, capturedTransport === null || capturedTransport === undefined ? undefined : capturedTransport.sessionId).catch((error46) => this._onerror(new Error(`Failed to enqueue error response: ${error46}`)));
64075
+ } else {
64076
+ capturedTransport === null || capturedTransport === undefined || capturedTransport.send(errorResponse).catch((error46) => this._onerror(new Error(`Failed to send an error response: ${error46}`)));
64077
+ }
63824
64078
  return;
63825
64079
  }
63826
64080
  const abortController = new AbortController;
63827
64081
  this._requestHandlerAbortControllers.set(request.id, abortController);
64082
+ const taskCreationParams = (_e = request.params) === null || _e === undefined ? undefined : _e.task;
64083
+ const taskStore = this._taskStore ? this.requestTaskStore(request, capturedTransport === null || capturedTransport === undefined ? undefined : capturedTransport.sessionId) : undefined;
63828
64084
  const fullExtra = {
63829
64085
  signal: abortController.signal,
63830
64086
  sessionId: capturedTransport === null || capturedTransport === undefined ? undefined : capturedTransport.sessionId,
63831
- _meta: (_b = request.params) === null || _b === undefined ? undefined : _b._meta,
63832
- sendNotification: (notification) => this.notification(notification, { relatedRequestId: request.id }),
63833
- sendRequest: (r, resultSchema, options) => this.request(r, resultSchema, { ...options, relatedRequestId: request.id }),
64087
+ _meta: (_f = request.params) === null || _f === undefined ? undefined : _f._meta,
64088
+ sendNotification: async (notification) => {
64089
+ const notificationOptions = { relatedRequestId: request.id };
64090
+ if (relatedTaskId) {
64091
+ notificationOptions.relatedTask = { taskId: relatedTaskId };
64092
+ }
64093
+ await this.notification(notification, notificationOptions);
64094
+ },
64095
+ sendRequest: async (r, resultSchema, options) => {
64096
+ var _a2, _b2;
64097
+ const requestOptions = { ...options, relatedRequestId: request.id };
64098
+ if (relatedTaskId && !requestOptions.relatedTask) {
64099
+ requestOptions.relatedTask = { taskId: relatedTaskId };
64100
+ }
64101
+ const effectiveTaskId = (_b2 = (_a2 = requestOptions.relatedTask) === null || _a2 === undefined ? undefined : _a2.taskId) !== null && _b2 !== undefined ? _b2 : relatedTaskId;
64102
+ if (effectiveTaskId && taskStore) {
64103
+ await taskStore.updateTaskStatus(effectiveTaskId, "input_required");
64104
+ }
64105
+ return await this.request(r, resultSchema, requestOptions);
64106
+ },
63834
64107
  authInfo: extra === null || extra === undefined ? undefined : extra.authInfo,
63835
64108
  requestId: request.id,
63836
- requestInfo: extra === null || extra === undefined ? undefined : extra.requestInfo
64109
+ requestInfo: extra === null || extra === undefined ? undefined : extra.requestInfo,
64110
+ taskId: relatedTaskId,
64111
+ taskStore,
64112
+ taskRequestedTtl: taskCreationParams === null || taskCreationParams === undefined ? undefined : taskCreationParams.ttl,
64113
+ closeSSEStream: extra === null || extra === undefined ? undefined : extra.closeSSEStream,
64114
+ closeStandaloneSSEStream: extra === null || extra === undefined ? undefined : extra.closeStandaloneSSEStream
63837
64115
  };
63838
- Promise.resolve().then(() => handler(request, fullExtra)).then((result) => {
64116
+ Promise.resolve().then(() => {
64117
+ if (taskCreationParams) {
64118
+ this.assertTaskHandlerCapability(request.method);
64119
+ }
64120
+ }).then(() => handler(request, fullExtra)).then(async (result) => {
63839
64121
  if (abortController.signal.aborted) {
63840
64122
  return;
63841
64123
  }
63842
- return capturedTransport === null || capturedTransport === undefined ? undefined : capturedTransport.send({
64124
+ const response = {
63843
64125
  result,
63844
64126
  jsonrpc: "2.0",
63845
64127
  id: request.id
63846
- });
63847
- }, (error46) => {
64128
+ };
64129
+ if (relatedTaskId && this._taskMessageQueue) {
64130
+ await this._enqueueTaskMessage(relatedTaskId, {
64131
+ type: "response",
64132
+ message: response,
64133
+ timestamp: Date.now()
64134
+ }, capturedTransport === null || capturedTransport === undefined ? undefined : capturedTransport.sessionId);
64135
+ } else {
64136
+ await (capturedTransport === null || capturedTransport === undefined ? undefined : capturedTransport.send(response));
64137
+ }
64138
+ }, async (error46) => {
63848
64139
  var _a2;
63849
64140
  if (abortController.signal.aborted) {
63850
64141
  return;
63851
64142
  }
63852
- return capturedTransport === null || capturedTransport === undefined ? undefined : capturedTransport.send({
64143
+ const errorResponse = {
63853
64144
  jsonrpc: "2.0",
63854
64145
  id: request.id,
63855
64146
  error: {
@@ -63857,7 +64148,16 @@ class Protocol {
63857
64148
  message: (_a2 = error46.message) !== null && _a2 !== undefined ? _a2 : "Internal error",
63858
64149
  ...error46["data"] !== undefined && { data: error46["data"] }
63859
64150
  }
63860
- });
64151
+ };
64152
+ if (relatedTaskId && this._taskMessageQueue) {
64153
+ await this._enqueueTaskMessage(relatedTaskId, {
64154
+ type: "error",
64155
+ message: errorResponse,
64156
+ timestamp: Date.now()
64157
+ }, capturedTransport === null || capturedTransport === undefined ? undefined : capturedTransport.sessionId);
64158
+ } else {
64159
+ await (capturedTransport === null || capturedTransport === undefined ? undefined : capturedTransport.send(errorResponse));
64160
+ }
63861
64161
  }).catch((error46) => this._onerror(new Error(`Failed to send response: ${error46}`))).finally(() => {
63862
64162
  this._requestHandlerAbortControllers.delete(request.id);
63863
64163
  });
@@ -63876,6 +64176,9 @@ class Protocol {
63876
64176
  try {
63877
64177
  this._resetTimeout(messageId);
63878
64178
  } catch (error46) {
64179
+ this._responseHandlers.delete(messageId);
64180
+ this._progressHandlers.delete(messageId);
64181
+ this._cleanupTimeout(messageId);
63879
64182
  responseHandler(error46);
63880
64183
  return;
63881
64184
  }
@@ -63884,14 +64187,38 @@ class Protocol {
63884
64187
  }
63885
64188
  _onresponse(response) {
63886
64189
  const messageId = Number(response.id);
64190
+ const resolver = this._requestResolvers.get(messageId);
64191
+ if (resolver) {
64192
+ this._requestResolvers.delete(messageId);
64193
+ if (isJSONRPCResponse(response)) {
64194
+ resolver(response);
64195
+ } else {
64196
+ const error46 = new McpError(response.error.code, response.error.message, response.error.data);
64197
+ resolver(error46);
64198
+ }
64199
+ return;
64200
+ }
63887
64201
  const handler = this._responseHandlers.get(messageId);
63888
64202
  if (handler === undefined) {
63889
64203
  this._onerror(new Error(`Received a response for an unknown message ID: ${JSON.stringify(response)}`));
63890
64204
  return;
63891
64205
  }
63892
64206
  this._responseHandlers.delete(messageId);
63893
- this._progressHandlers.delete(messageId);
63894
64207
  this._cleanupTimeout(messageId);
64208
+ let isTaskResponse = false;
64209
+ if (isJSONRPCResponse(response) && response.result && typeof response.result === "object") {
64210
+ const result = response.result;
64211
+ if (result.task && typeof result.task === "object") {
64212
+ const task = result.task;
64213
+ if (typeof task.taskId === "string") {
64214
+ isTaskResponse = true;
64215
+ this._taskProgressTokens.set(task.taskId, messageId);
64216
+ }
64217
+ }
64218
+ }
64219
+ if (!isTaskResponse) {
64220
+ this._progressHandlers.delete(messageId);
64221
+ }
63895
64222
  if (isJSONRPCResponse(response)) {
63896
64223
  handler(response);
63897
64224
  } else {
@@ -63906,16 +64233,87 @@ class Protocol {
63906
64233
  var _a;
63907
64234
  await ((_a = this._transport) === null || _a === undefined ? undefined : _a.close());
63908
64235
  }
64236
+ async* requestStream(request, resultSchema, options) {
64237
+ var _a, _b, _c, _d;
64238
+ const { task } = options !== null && options !== undefined ? options : {};
64239
+ if (!task) {
64240
+ try {
64241
+ const result = await this.request(request, resultSchema, options);
64242
+ yield { type: "result", result };
64243
+ } catch (error46) {
64244
+ yield {
64245
+ type: "error",
64246
+ error: error46 instanceof McpError ? error46 : new McpError(ErrorCode.InternalError, String(error46))
64247
+ };
64248
+ }
64249
+ return;
64250
+ }
64251
+ let taskId;
64252
+ try {
64253
+ const createResult = await this.request(request, CreateTaskResultSchema, options);
64254
+ if (createResult.task) {
64255
+ taskId = createResult.task.taskId;
64256
+ yield { type: "taskCreated", task: createResult.task };
64257
+ } else {
64258
+ throw new McpError(ErrorCode.InternalError, "Task creation did not return a task");
64259
+ }
64260
+ while (true) {
64261
+ const task2 = await this.getTask({ taskId }, options);
64262
+ yield { type: "taskStatus", task: task2 };
64263
+ if (isTerminal(task2.status)) {
64264
+ if (task2.status === "completed") {
64265
+ const result = await this.getTaskResult({ taskId }, resultSchema, options);
64266
+ yield { type: "result", result };
64267
+ } else if (task2.status === "failed") {
64268
+ yield {
64269
+ type: "error",
64270
+ error: new McpError(ErrorCode.InternalError, `Task ${taskId} failed`)
64271
+ };
64272
+ } else if (task2.status === "cancelled") {
64273
+ yield {
64274
+ type: "error",
64275
+ error: new McpError(ErrorCode.InternalError, `Task ${taskId} was cancelled`)
64276
+ };
64277
+ }
64278
+ return;
64279
+ }
64280
+ if (task2.status === "input_required") {
64281
+ const result = await this.getTaskResult({ taskId }, resultSchema, options);
64282
+ yield { type: "result", result };
64283
+ return;
64284
+ }
64285
+ const pollInterval = (_c = (_a = task2.pollInterval) !== null && _a !== undefined ? _a : (_b = this._options) === null || _b === undefined ? undefined : _b.defaultTaskPollInterval) !== null && _c !== undefined ? _c : 1000;
64286
+ await new Promise((resolve) => setTimeout(resolve, pollInterval));
64287
+ (_d = options === null || options === undefined ? undefined : options.signal) === null || _d === undefined || _d.throwIfAborted();
64288
+ }
64289
+ } catch (error46) {
64290
+ yield {
64291
+ type: "error",
64292
+ error: error46 instanceof McpError ? error46 : new McpError(ErrorCode.InternalError, String(error46))
64293
+ };
64294
+ }
64295
+ }
63909
64296
  request(request, resultSchema, options) {
63910
- const { relatedRequestId, resumptionToken, onresumptiontoken } = options !== null && options !== undefined ? options : {};
64297
+ const { relatedRequestId, resumptionToken, onresumptiontoken, task, relatedTask } = options !== null && options !== undefined ? options : {};
63911
64298
  return new Promise((resolve, reject) => {
63912
- var _a, _b, _c, _d, _e, _f;
64299
+ var _a, _b, _c, _d, _e, _f, _g;
64300
+ const earlyReject = (error46) => {
64301
+ reject(error46);
64302
+ };
63913
64303
  if (!this._transport) {
63914
- reject(new Error("Not connected"));
64304
+ earlyReject(new Error("Not connected"));
63915
64305
  return;
63916
64306
  }
63917
64307
  if (((_a = this._options) === null || _a === undefined ? undefined : _a.enforceStrictCapabilities) === true) {
63918
- this.assertCapabilityForMethod(request.method);
64308
+ try {
64309
+ this.assertCapabilityForMethod(request.method);
64310
+ if (task) {
64311
+ this.assertTaskCapability(request.method);
64312
+ }
64313
+ } catch (e) {
64314
+ earlyReject(e);
64315
+ return;
64316
+ }
63919
64317
  }
63920
64318
  (_b = options === null || options === undefined ? undefined : options.signal) === null || _b === undefined || _b.throwIfAborted();
63921
64319
  const messageId = this._requestMessageId++;
@@ -63934,6 +64332,21 @@ class Protocol {
63934
64332
  }
63935
64333
  };
63936
64334
  }
64335
+ if (task) {
64336
+ jsonrpcRequest.params = {
64337
+ ...jsonrpcRequest.params,
64338
+ task
64339
+ };
64340
+ }
64341
+ if (relatedTask) {
64342
+ jsonrpcRequest.params = {
64343
+ ...jsonrpcRequest.params,
64344
+ _meta: {
64345
+ ...((_d = jsonrpcRequest.params) === null || _d === undefined ? undefined : _d._meta) || {},
64346
+ [RELATED_TASK_META_KEY]: relatedTask
64347
+ }
64348
+ };
64349
+ }
63937
64350
  const cancel = (reason) => {
63938
64351
  var _a2;
63939
64352
  this._responseHandlers.delete(messageId);
@@ -63946,8 +64359,9 @@ class Protocol {
63946
64359
  requestId: messageId,
63947
64360
  reason: String(reason)
63948
64361
  }
63949
- }, { relatedRequestId, resumptionToken, onresumptiontoken }).catch((error46) => this._onerror(new Error(`Failed to send cancellation: ${error46}`)));
63950
- reject(reason);
64362
+ }, { relatedRequestId, resumptionToken, onresumptiontoken }).catch((error47) => this._onerror(new Error(`Failed to send cancellation: ${error47}`)));
64363
+ const error46 = reason instanceof McpError ? reason : new McpError(ErrorCode.RequestTimeout, String(reason));
64364
+ reject(error46);
63951
64365
  };
63952
64366
  this._responseHandlers.set(messageId, (response) => {
63953
64367
  var _a2;
@@ -63968,50 +64382,127 @@ class Protocol {
63968
64382
  reject(error46);
63969
64383
  }
63970
64384
  });
63971
- (_d = options === null || options === undefined ? undefined : options.signal) === null || _d === undefined || _d.addEventListener("abort", () => {
64385
+ (_e = options === null || options === undefined ? undefined : options.signal) === null || _e === undefined || _e.addEventListener("abort", () => {
63972
64386
  var _a2;
63973
64387
  cancel((_a2 = options === null || options === undefined ? undefined : options.signal) === null || _a2 === undefined ? undefined : _a2.reason);
63974
64388
  });
63975
- const timeout = (_e = options === null || options === undefined ? undefined : options.timeout) !== null && _e !== undefined ? _e : DEFAULT_REQUEST_TIMEOUT_MSEC;
64389
+ const timeout = (_f = options === null || options === undefined ? undefined : options.timeout) !== null && _f !== undefined ? _f : DEFAULT_REQUEST_TIMEOUT_MSEC;
63976
64390
  const timeoutHandler = () => cancel(McpError.fromError(ErrorCode.RequestTimeout, "Request timed out", { timeout }));
63977
- this._setupTimeout(messageId, timeout, options === null || options === undefined ? undefined : options.maxTotalTimeout, timeoutHandler, (_f = options === null || options === undefined ? undefined : options.resetTimeoutOnProgress) !== null && _f !== undefined ? _f : false);
63978
- this._transport.send(jsonrpcRequest, { relatedRequestId, resumptionToken, onresumptiontoken }).catch((error46) => {
63979
- this._cleanupTimeout(messageId);
63980
- reject(error46);
63981
- });
64391
+ this._setupTimeout(messageId, timeout, options === null || options === undefined ? undefined : options.maxTotalTimeout, timeoutHandler, (_g = options === null || options === undefined ? undefined : options.resetTimeoutOnProgress) !== null && _g !== undefined ? _g : false);
64392
+ const relatedTaskId = relatedTask === null || relatedTask === undefined ? undefined : relatedTask.taskId;
64393
+ if (relatedTaskId) {
64394
+ const responseResolver = (response) => {
64395
+ const handler = this._responseHandlers.get(messageId);
64396
+ if (handler) {
64397
+ handler(response);
64398
+ } else {
64399
+ this._onerror(new Error(`Response handler missing for side-channeled request ${messageId}`));
64400
+ }
64401
+ };
64402
+ this._requestResolvers.set(messageId, responseResolver);
64403
+ this._enqueueTaskMessage(relatedTaskId, {
64404
+ type: "request",
64405
+ message: jsonrpcRequest,
64406
+ timestamp: Date.now()
64407
+ }).catch((error46) => {
64408
+ this._cleanupTimeout(messageId);
64409
+ reject(error46);
64410
+ });
64411
+ } else {
64412
+ this._transport.send(jsonrpcRequest, { relatedRequestId, resumptionToken, onresumptiontoken }).catch((error46) => {
64413
+ this._cleanupTimeout(messageId);
64414
+ reject(error46);
64415
+ });
64416
+ }
63982
64417
  });
63983
64418
  }
64419
+ async getTask(params, options) {
64420
+ return this.request({ method: "tasks/get", params }, GetTaskResultSchema, options);
64421
+ }
64422
+ async getTaskResult(params, resultSchema, options) {
64423
+ return this.request({ method: "tasks/result", params }, resultSchema, options);
64424
+ }
64425
+ async listTasks(params, options) {
64426
+ return this.request({ method: "tasks/list", params }, ListTasksResultSchema, options);
64427
+ }
64428
+ async cancelTask(params, options) {
64429
+ return this.request({ method: "tasks/cancel", params }, CancelTaskResultSchema, options);
64430
+ }
63984
64431
  async notification(notification, options) {
63985
- var _a, _b;
64432
+ var _a, _b, _c, _d, _e;
63986
64433
  if (!this._transport) {
63987
64434
  throw new Error("Not connected");
63988
64435
  }
63989
64436
  this.assertNotificationCapability(notification.method);
63990
- const debouncedMethods = (_b = (_a = this._options) === null || _a === undefined ? undefined : _a.debouncedNotificationMethods) !== null && _b !== undefined ? _b : [];
63991
- const canDebounce = debouncedMethods.includes(notification.method) && !notification.params && !(options === null || options === undefined ? undefined : options.relatedRequestId);
64437
+ const relatedTaskId = (_a = options === null || options === undefined ? undefined : options.relatedTask) === null || _a === undefined ? undefined : _a.taskId;
64438
+ if (relatedTaskId) {
64439
+ const jsonrpcNotification2 = {
64440
+ ...notification,
64441
+ jsonrpc: "2.0",
64442
+ params: {
64443
+ ...notification.params,
64444
+ _meta: {
64445
+ ...((_b = notification.params) === null || _b === undefined ? undefined : _b._meta) || {},
64446
+ [RELATED_TASK_META_KEY]: options.relatedTask
64447
+ }
64448
+ }
64449
+ };
64450
+ await this._enqueueTaskMessage(relatedTaskId, {
64451
+ type: "notification",
64452
+ message: jsonrpcNotification2,
64453
+ timestamp: Date.now()
64454
+ });
64455
+ return;
64456
+ }
64457
+ const debouncedMethods = (_d = (_c = this._options) === null || _c === undefined ? undefined : _c.debouncedNotificationMethods) !== null && _d !== undefined ? _d : [];
64458
+ const canDebounce = debouncedMethods.includes(notification.method) && !notification.params && !(options === null || options === undefined ? undefined : options.relatedRequestId) && !(options === null || options === undefined ? undefined : options.relatedTask);
63992
64459
  if (canDebounce) {
63993
64460
  if (this._pendingDebouncedNotifications.has(notification.method)) {
63994
64461
  return;
63995
64462
  }
63996
64463
  this._pendingDebouncedNotifications.add(notification.method);
63997
64464
  Promise.resolve().then(() => {
63998
- var _a2;
64465
+ var _a2, _b2;
63999
64466
  this._pendingDebouncedNotifications.delete(notification.method);
64000
64467
  if (!this._transport) {
64001
64468
  return;
64002
64469
  }
64003
- const jsonrpcNotification2 = {
64470
+ let jsonrpcNotification2 = {
64004
64471
  ...notification,
64005
64472
  jsonrpc: "2.0"
64006
64473
  };
64007
- (_a2 = this._transport) === null || _a2 === undefined || _a2.send(jsonrpcNotification2, options).catch((error46) => this._onerror(error46));
64474
+ if (options === null || options === undefined ? undefined : options.relatedTask) {
64475
+ jsonrpcNotification2 = {
64476
+ ...jsonrpcNotification2,
64477
+ params: {
64478
+ ...jsonrpcNotification2.params,
64479
+ _meta: {
64480
+ ...((_a2 = jsonrpcNotification2.params) === null || _a2 === undefined ? undefined : _a2._meta) || {},
64481
+ [RELATED_TASK_META_KEY]: options.relatedTask
64482
+ }
64483
+ }
64484
+ };
64485
+ }
64486
+ (_b2 = this._transport) === null || _b2 === undefined || _b2.send(jsonrpcNotification2, options).catch((error46) => this._onerror(error46));
64008
64487
  });
64009
64488
  return;
64010
64489
  }
64011
- const jsonrpcNotification = {
64490
+ let jsonrpcNotification = {
64012
64491
  ...notification,
64013
64492
  jsonrpc: "2.0"
64014
64493
  };
64494
+ if (options === null || options === undefined ? undefined : options.relatedTask) {
64495
+ jsonrpcNotification = {
64496
+ ...jsonrpcNotification,
64497
+ params: {
64498
+ ...jsonrpcNotification.params,
64499
+ _meta: {
64500
+ ...((_e = jsonrpcNotification.params) === null || _e === undefined ? undefined : _e._meta) || {},
64501
+ [RELATED_TASK_META_KEY]: options.relatedTask
64502
+ }
64503
+ }
64504
+ };
64505
+ }
64015
64506
  await this._transport.send(jsonrpcNotification, options);
64016
64507
  }
64017
64508
  setRequestHandler(requestSchema, handler) {
@@ -64040,6 +64531,124 @@ class Protocol {
64040
64531
  removeNotificationHandler(method) {
64041
64532
  this._notificationHandlers.delete(method);
64042
64533
  }
64534
+ _cleanupTaskProgressHandler(taskId) {
64535
+ const progressToken = this._taskProgressTokens.get(taskId);
64536
+ if (progressToken !== undefined) {
64537
+ this._progressHandlers.delete(progressToken);
64538
+ this._taskProgressTokens.delete(taskId);
64539
+ }
64540
+ }
64541
+ async _enqueueTaskMessage(taskId, message, sessionId) {
64542
+ var _a;
64543
+ if (!this._taskStore || !this._taskMessageQueue) {
64544
+ throw new Error("Cannot enqueue task message: taskStore and taskMessageQueue are not configured");
64545
+ }
64546
+ const maxQueueSize = (_a = this._options) === null || _a === undefined ? undefined : _a.maxTaskQueueSize;
64547
+ await this._taskMessageQueue.enqueue(taskId, message, sessionId, maxQueueSize);
64548
+ }
64549
+ async _clearTaskQueue(taskId, sessionId) {
64550
+ if (this._taskMessageQueue) {
64551
+ const messages = await this._taskMessageQueue.dequeueAll(taskId, sessionId);
64552
+ for (const message of messages) {
64553
+ if (message.type === "request" && isJSONRPCRequest(message.message)) {
64554
+ const requestId = message.message.id;
64555
+ const resolver = this._requestResolvers.get(requestId);
64556
+ if (resolver) {
64557
+ resolver(new McpError(ErrorCode.InternalError, "Task cancelled or completed"));
64558
+ this._requestResolvers.delete(requestId);
64559
+ } else {
64560
+ this._onerror(new Error(`Resolver missing for request ${requestId} during task ${taskId} cleanup`));
64561
+ }
64562
+ }
64563
+ }
64564
+ }
64565
+ }
64566
+ async _waitForTaskUpdate(taskId, signal) {
64567
+ var _a, _b, _c;
64568
+ let interval = (_b = (_a = this._options) === null || _a === undefined ? undefined : _a.defaultTaskPollInterval) !== null && _b !== undefined ? _b : 1000;
64569
+ try {
64570
+ const task = await ((_c = this._taskStore) === null || _c === undefined ? undefined : _c.getTask(taskId));
64571
+ if (task === null || task === undefined ? undefined : task.pollInterval) {
64572
+ interval = task.pollInterval;
64573
+ }
64574
+ } catch (_d) {}
64575
+ return new Promise((resolve, reject) => {
64576
+ if (signal.aborted) {
64577
+ reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
64578
+ return;
64579
+ }
64580
+ const timeoutId = setTimeout(resolve, interval);
64581
+ signal.addEventListener("abort", () => {
64582
+ clearTimeout(timeoutId);
64583
+ reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
64584
+ }, { once: true });
64585
+ });
64586
+ }
64587
+ requestTaskStore(request, sessionId) {
64588
+ const taskStore = this._taskStore;
64589
+ if (!taskStore) {
64590
+ throw new Error("No task store configured");
64591
+ }
64592
+ return {
64593
+ createTask: async (taskParams) => {
64594
+ if (!request) {
64595
+ throw new Error("No request provided");
64596
+ }
64597
+ return await taskStore.createTask(taskParams, request.id, {
64598
+ method: request.method,
64599
+ params: request.params
64600
+ }, sessionId);
64601
+ },
64602
+ getTask: async (taskId) => {
64603
+ const task = await taskStore.getTask(taskId, sessionId);
64604
+ if (!task) {
64605
+ throw new McpError(ErrorCode.InvalidParams, "Failed to retrieve task: Task not found");
64606
+ }
64607
+ return task;
64608
+ },
64609
+ storeTaskResult: async (taskId, status, result) => {
64610
+ await taskStore.storeTaskResult(taskId, status, result, sessionId);
64611
+ const task = await taskStore.getTask(taskId, sessionId);
64612
+ if (task) {
64613
+ const notification = TaskStatusNotificationSchema.parse({
64614
+ method: "notifications/tasks/status",
64615
+ params: task
64616
+ });
64617
+ await this.notification(notification);
64618
+ if (isTerminal(task.status)) {
64619
+ this._cleanupTaskProgressHandler(taskId);
64620
+ }
64621
+ }
64622
+ },
64623
+ getTaskResult: (taskId) => {
64624
+ return taskStore.getTaskResult(taskId, sessionId);
64625
+ },
64626
+ updateTaskStatus: async (taskId, status, statusMessage) => {
64627
+ const task = await taskStore.getTask(taskId, sessionId);
64628
+ if (!task) {
64629
+ throw new McpError(ErrorCode.InvalidParams, `Task "${taskId}" not found - it may have been cleaned up`);
64630
+ }
64631
+ if (isTerminal(task.status)) {
64632
+ throw new McpError(ErrorCode.InvalidParams, `Cannot update task "${taskId}" from terminal status "${task.status}" to "${status}". Terminal states (completed, failed, cancelled) cannot transition to other states.`);
64633
+ }
64634
+ await taskStore.updateTaskStatus(taskId, status, statusMessage, sessionId);
64635
+ const updatedTask = await taskStore.getTask(taskId, sessionId);
64636
+ if (updatedTask) {
64637
+ const notification = TaskStatusNotificationSchema.parse({
64638
+ method: "notifications/tasks/status",
64639
+ params: updatedTask
64640
+ });
64641
+ await this.notification(notification);
64642
+ if (isTerminal(updatedTask.status)) {
64643
+ this._cleanupTaskProgressHandler(taskId);
64644
+ }
64645
+ }
64646
+ },
64647
+ listTasks: (cursor) => {
64648
+ return taskStore.listTasks(cursor, sessionId);
64649
+ }
64650
+ };
64651
+ }
64043
64652
  }
64044
64653
  function isPlainObject2(value) {
64045
64654
  return value !== null && typeof value === "object" && !Array.isArray(value);
@@ -64061,7 +64670,7 @@ function mergeCapabilities(base, additional) {
64061
64670
  return result;
64062
64671
  }
64063
64672
 
64064
- // ../../node_modules/.bun/@modelcontextprotocol+sdk@1.23.0/node_modules/@modelcontextprotocol/sdk/dist/esm/validation/ajv-provider.js
64673
+ // ../../node_modules/.bun/@modelcontextprotocol+sdk@1.24.3/node_modules/@modelcontextprotocol/sdk/dist/esm/validation/ajv-provider.js
64065
64674
  var import_ajv = __toESM(require_ajv(), 1);
64066
64675
  var import_ajv_formats = __toESM(require_dist(), 1);
64067
64676
  function createDefaultAjvInstance() {
@@ -64102,7 +64711,66 @@ class AjvJsonSchemaValidator {
64102
64711
  }
64103
64712
  }
64104
64713
 
64105
- // ../../node_modules/.bun/@modelcontextprotocol+sdk@1.23.0/node_modules/@modelcontextprotocol/sdk/dist/esm/server/index.js
64714
+ // ../../node_modules/.bun/@modelcontextprotocol+sdk@1.24.3/node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/server.js
64715
+ class ExperimentalServerTasks {
64716
+ constructor(_server) {
64717
+ this._server = _server;
64718
+ }
64719
+ requestStream(request, resultSchema, options) {
64720
+ return this._server.requestStream(request, resultSchema, options);
64721
+ }
64722
+ async getTask(taskId, options) {
64723
+ return this._server.getTask({ taskId }, options);
64724
+ }
64725
+ async getTaskResult(taskId, resultSchema, options) {
64726
+ return this._server.getTaskResult({ taskId }, resultSchema, options);
64727
+ }
64728
+ async listTasks(cursor, options) {
64729
+ return this._server.listTasks(cursor ? { cursor } : undefined, options);
64730
+ }
64731
+ async cancelTask(taskId, options) {
64732
+ return this._server.cancelTask({ taskId }, options);
64733
+ }
64734
+ }
64735
+
64736
+ // ../../node_modules/.bun/@modelcontextprotocol+sdk@1.24.3/node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/helpers.js
64737
+ function assertToolsCallTaskCapability(requests, method, entityName) {
64738
+ var _a;
64739
+ if (!requests) {
64740
+ throw new Error(`${entityName} does not support task creation (required for ${method})`);
64741
+ }
64742
+ switch (method) {
64743
+ case "tools/call":
64744
+ if (!((_a = requests.tools) === null || _a === undefined ? undefined : _a.call)) {
64745
+ throw new Error(`${entityName} does not support task creation for tools/call (required for ${method})`);
64746
+ }
64747
+ break;
64748
+ default:
64749
+ break;
64750
+ }
64751
+ }
64752
+ function assertClientRequestTaskCapability(requests, method, entityName) {
64753
+ var _a, _b;
64754
+ if (!requests) {
64755
+ throw new Error(`${entityName} does not support task creation (required for ${method})`);
64756
+ }
64757
+ switch (method) {
64758
+ case "sampling/createMessage":
64759
+ if (!((_a = requests.sampling) === null || _a === undefined ? undefined : _a.createMessage)) {
64760
+ throw new Error(`${entityName} does not support task creation for sampling/createMessage (required for ${method})`);
64761
+ }
64762
+ break;
64763
+ case "elicitation/create":
64764
+ if (!((_b = requests.elicitation) === null || _b === undefined ? undefined : _b.create)) {
64765
+ throw new Error(`${entityName} does not support task creation for elicitation/create (required for ${method})`);
64766
+ }
64767
+ break;
64768
+ default:
64769
+ break;
64770
+ }
64771
+ }
64772
+
64773
+ // ../../node_modules/.bun/@modelcontextprotocol+sdk@1.24.3/node_modules/@modelcontextprotocol/sdk/dist/esm/server/index.js
64106
64774
  class Server extends Protocol {
64107
64775
  constructor(_serverInfo, options) {
64108
64776
  var _a, _b;
@@ -64135,12 +64803,69 @@ class Server extends Protocol {
64135
64803
  });
64136
64804
  }
64137
64805
  }
64806
+ get experimental() {
64807
+ if (!this._experimental) {
64808
+ this._experimental = {
64809
+ tasks: new ExperimentalServerTasks(this)
64810
+ };
64811
+ }
64812
+ return this._experimental;
64813
+ }
64138
64814
  registerCapabilities(capabilities) {
64139
64815
  if (this.transport) {
64140
64816
  throw new Error("Cannot register capabilities after connecting to transport");
64141
64817
  }
64142
64818
  this._capabilities = mergeCapabilities(this._capabilities, capabilities);
64143
64819
  }
64820
+ setRequestHandler(requestSchema, handler) {
64821
+ var _a, _b, _c;
64822
+ const shape = getObjectShape(requestSchema);
64823
+ const methodSchema = shape === null || shape === undefined ? undefined : shape.method;
64824
+ if (!methodSchema) {
64825
+ throw new Error("Schema is missing a method literal");
64826
+ }
64827
+ let methodValue;
64828
+ if (isZ4Schema(methodSchema)) {
64829
+ const v4Schema = methodSchema;
64830
+ const v4Def = (_a = v4Schema._zod) === null || _a === undefined ? undefined : _a.def;
64831
+ methodValue = (_b = v4Def === null || v4Def === undefined ? undefined : v4Def.value) !== null && _b !== undefined ? _b : v4Schema.value;
64832
+ } else {
64833
+ const v3Schema = methodSchema;
64834
+ const legacyDef = v3Schema._def;
64835
+ methodValue = (_c = legacyDef === null || legacyDef === undefined ? undefined : legacyDef.value) !== null && _c !== undefined ? _c : v3Schema.value;
64836
+ }
64837
+ if (typeof methodValue !== "string") {
64838
+ throw new Error("Schema method literal must be a string");
64839
+ }
64840
+ const method = methodValue;
64841
+ if (method === "tools/call") {
64842
+ const wrappedHandler = async (request, extra) => {
64843
+ const validatedRequest = safeParse2(CallToolRequestSchema, request);
64844
+ if (!validatedRequest.success) {
64845
+ const errorMessage = validatedRequest.error instanceof Error ? validatedRequest.error.message : String(validatedRequest.error);
64846
+ throw new McpError(ErrorCode.InvalidParams, `Invalid tools/call request: ${errorMessage}`);
64847
+ }
64848
+ const { params } = validatedRequest.data;
64849
+ const result = await Promise.resolve(handler(request, extra));
64850
+ if (params.task) {
64851
+ const taskValidationResult = safeParse2(CreateTaskResultSchema, result);
64852
+ if (!taskValidationResult.success) {
64853
+ const errorMessage = taskValidationResult.error instanceof Error ? taskValidationResult.error.message : String(taskValidationResult.error);
64854
+ throw new McpError(ErrorCode.InvalidParams, `Invalid task creation result: ${errorMessage}`);
64855
+ }
64856
+ return taskValidationResult.data;
64857
+ }
64858
+ const validationResult = safeParse2(CallToolResultSchema, result);
64859
+ if (!validationResult.success) {
64860
+ const errorMessage = validationResult.error instanceof Error ? validationResult.error.message : String(validationResult.error);
64861
+ throw new McpError(ErrorCode.InvalidParams, `Invalid tools/call result: ${errorMessage}`);
64862
+ }
64863
+ return validationResult.data;
64864
+ };
64865
+ return super.setRequestHandler(requestSchema, wrappedHandler);
64866
+ }
64867
+ return super.setRequestHandler(requestSchema, handler);
64868
+ }
64144
64869
  assertCapabilityForMethod(method) {
64145
64870
  var _a, _b, _c;
64146
64871
  switch (method) {
@@ -64199,6 +64924,9 @@ class Server extends Protocol {
64199
64924
  }
64200
64925
  }
64201
64926
  assertRequestHandlerCapability(method) {
64927
+ if (!this._capabilities) {
64928
+ return;
64929
+ }
64202
64930
  switch (method) {
64203
64931
  case "completion/complete":
64204
64932
  if (!this._capabilities.completions) {
@@ -64229,11 +64957,30 @@ class Server extends Protocol {
64229
64957
  throw new Error(`Server does not support tools (required for ${method})`);
64230
64958
  }
64231
64959
  break;
64960
+ case "tasks/get":
64961
+ case "tasks/list":
64962
+ case "tasks/result":
64963
+ case "tasks/cancel":
64964
+ if (!this._capabilities.tasks) {
64965
+ throw new Error(`Server does not support tasks capability (required for ${method})`);
64966
+ }
64967
+ break;
64232
64968
  case "ping":
64233
64969
  case "initialize":
64234
64970
  break;
64235
64971
  }
64236
64972
  }
64973
+ assertTaskCapability(method) {
64974
+ var _a, _b;
64975
+ assertClientRequestTaskCapability((_b = (_a = this._clientCapabilities) === null || _a === undefined ? undefined : _a.tasks) === null || _b === undefined ? undefined : _b.requests, method, "Client");
64976
+ }
64977
+ assertTaskHandlerCapability(method) {
64978
+ var _a;
64979
+ if (!this._capabilities) {
64980
+ return;
64981
+ }
64982
+ assertToolsCallTaskCapability((_a = this._capabilities.tasks) === null || _a === undefined ? undefined : _a.requests, method, "Server");
64983
+ }
64237
64984
  async _oninitialize(request) {
64238
64985
  const requestedVersion = request.params.protocolVersion;
64239
64986
  this._clientCapabilities = request.params.capabilities;
@@ -64288,6 +65035,9 @@ class Server extends Protocol {
64288
65035
  }
64289
65036
  }
64290
65037
  }
65038
+ if (params.tools) {
65039
+ return this.request({ method: "sampling/createMessage", params }, CreateMessageResultWithToolsSchema, options);
65040
+ }
64291
65041
  return this.request({ method: "sampling/createMessage", params }, CreateMessageResultSchema, options);
64292
65042
  }
64293
65043
  async elicitInput(params, options) {
@@ -64366,7 +65116,7 @@ class Server extends Protocol {
64366
65116
  }
64367
65117
  }
64368
65118
 
64369
- // ../../node_modules/.bun/@modelcontextprotocol+sdk@1.23.0/node_modules/@modelcontextprotocol/sdk/dist/esm/server/completable.js
65119
+ // ../../node_modules/.bun/@modelcontextprotocol+sdk@1.24.3/node_modules/@modelcontextprotocol/sdk/dist/esm/server/completable.js
64370
65120
  var COMPLETABLE_SYMBOL = Symbol.for("mcp.completable");
64371
65121
  function isCompletable(schema) {
64372
65122
  return !!schema && typeof schema === "object" && COMPLETABLE_SYMBOL in schema;
@@ -64380,7 +65130,7 @@ var McpZodTypeKind;
64380
65130
  McpZodTypeKind2["Completable"] = "McpCompletable";
64381
65131
  })(McpZodTypeKind || (McpZodTypeKind = {}));
64382
65132
 
64383
- // ../../node_modules/.bun/@modelcontextprotocol+sdk@1.23.0/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/toolNameValidation.js
65133
+ // ../../node_modules/.bun/@modelcontextprotocol+sdk@1.24.3/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/toolNameValidation.js
64384
65134
  var TOOL_NAME_REGEX = /^[A-Za-z0-9._-]{1,128}$/;
64385
65135
  function validateToolName(name) {
64386
65136
  const warnings = [];
@@ -64438,7 +65188,22 @@ function validateAndWarnToolName(name) {
64438
65188
  return result.isValid;
64439
65189
  }
64440
65190
 
64441
- // ../../node_modules/.bun/@modelcontextprotocol+sdk@1.23.0/node_modules/@modelcontextprotocol/sdk/dist/esm/server/mcp.js
65191
+ // ../../node_modules/.bun/@modelcontextprotocol+sdk@1.24.3/node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/mcp-server.js
65192
+ class ExperimentalMcpServerTasks {
65193
+ constructor(_mcpServer) {
65194
+ this._mcpServer = _mcpServer;
65195
+ }
65196
+ registerToolTask(name, config2, handler) {
65197
+ const execution = { taskSupport: "required", ...config2.execution };
65198
+ if (execution.taskSupport === "forbidden") {
65199
+ throw new Error(`Cannot register task-based tool '${name}' with taskSupport 'forbidden'. Use registerTool() instead.`);
65200
+ }
65201
+ const mcpServerInternal = this._mcpServer;
65202
+ return mcpServerInternal._createRegisteredTool(name, config2.title, config2.description, config2.inputSchema, config2.outputSchema, config2.annotations, execution, config2._meta, handler);
65203
+ }
65204
+ }
65205
+
65206
+ // ../../node_modules/.bun/@modelcontextprotocol+sdk@1.24.3/node_modules/@modelcontextprotocol/sdk/dist/esm/server/mcp.js
64442
65207
  class McpServer {
64443
65208
  constructor(serverInfo, options) {
64444
65209
  this._registeredResources = {};
@@ -64451,6 +65216,14 @@ class McpServer {
64451
65216
  this._promptHandlersInitialized = false;
64452
65217
  this.server = new Server(serverInfo, options);
64453
65218
  }
65219
+ get experimental() {
65220
+ if (!this._experimental) {
65221
+ this._experimental = {
65222
+ tasks: new ExperimentalMcpServerTasks(this)
65223
+ };
65224
+ }
65225
+ return this._experimental;
65226
+ }
64454
65227
  async connect(transport) {
64455
65228
  return await this.server.connect(transport);
64456
65229
  }
@@ -64482,6 +65255,7 @@ class McpServer {
64482
65255
  }) : EMPTY_OBJECT_JSON_SCHEMA;
64483
65256
  })(),
64484
65257
  annotations: tool.annotations,
65258
+ execution: tool.execution,
64485
65259
  _meta: tool._meta
64486
65260
  };
64487
65261
  if (tool.outputSchema) {
@@ -64497,39 +65271,34 @@ class McpServer {
64497
65271
  })
64498
65272
  }));
64499
65273
  this.server.setRequestHandler(CallToolRequestSchema, async (request, extra) => {
64500
- const tool = this._registeredTools[request.params.name];
64501
- let result;
65274
+ var _a;
64502
65275
  try {
65276
+ const tool = this._registeredTools[request.params.name];
64503
65277
  if (!tool) {
64504
65278
  throw new McpError(ErrorCode.InvalidParams, `Tool ${request.params.name} not found`);
64505
65279
  }
64506
65280
  if (!tool.enabled) {
64507
65281
  throw new McpError(ErrorCode.InvalidParams, `Tool ${request.params.name} disabled`);
64508
65282
  }
64509
- if (tool.inputSchema) {
64510
- const cb = tool.callback;
64511
- const inputObj = normalizeObjectSchema(tool.inputSchema);
64512
- const schemaToParse = inputObj !== null && inputObj !== undefined ? inputObj : tool.inputSchema;
64513
- const parseResult = await safeParseAsync2(schemaToParse, request.params.arguments);
64514
- if (!parseResult.success) {
64515
- throw new McpError(ErrorCode.InvalidParams, `Input validation error: Invalid arguments for tool ${request.params.name}: ${getParseErrorMessage(parseResult.error)}`);
64516
- }
64517
- const args = parseResult.data;
64518
- result = await Promise.resolve(cb(args, extra));
64519
- } else {
64520
- const cb = tool.callback;
64521
- result = await Promise.resolve(cb(extra));
65283
+ const isTaskRequest = !!request.params.task;
65284
+ const taskSupport = (_a = tool.execution) === null || _a === undefined ? undefined : _a.taskSupport;
65285
+ const isTaskHandler = "createTask" in tool.handler;
65286
+ if ((taskSupport === "required" || taskSupport === "optional") && !isTaskHandler) {
65287
+ throw new McpError(ErrorCode.InternalError, `Tool ${request.params.name} has taskSupport '${taskSupport}' but was not registered with registerToolTask`);
64522
65288
  }
64523
- if (tool.outputSchema && !result.isError) {
64524
- if (!result.structuredContent) {
64525
- throw new McpError(ErrorCode.InvalidParams, `Output validation error: Tool ${request.params.name} has an output schema but no structured content was provided`);
64526
- }
64527
- const outputObj = normalizeObjectSchema(tool.outputSchema);
64528
- const parseResult = await safeParseAsync2(outputObj, result.structuredContent);
64529
- if (!parseResult.success) {
64530
- throw new McpError(ErrorCode.InvalidParams, `Output validation error: Invalid structured content for tool ${request.params.name}: ${getParseErrorMessage(parseResult.error)}`);
64531
- }
65289
+ if (taskSupport === "required" && !isTaskRequest) {
65290
+ throw new McpError(ErrorCode.MethodNotFound, `Tool ${request.params.name} requires task augmentation (taskSupport: 'required')`);
65291
+ }
65292
+ if (taskSupport === "optional" && !isTaskRequest && isTaskHandler) {
65293
+ return await this.handleAutomaticTaskPolling(tool, request, extra);
64532
65294
  }
65295
+ const args = await this.validateToolInput(tool, request.params.arguments, request.params.name);
65296
+ const result = await this.executeToolHandler(tool, args, extra);
65297
+ if (isTaskRequest) {
65298
+ return result;
65299
+ }
65300
+ await this.validateToolOutput(tool, result, request.params.name);
65301
+ return result;
64533
65302
  } catch (error46) {
64534
65303
  if (error46 instanceof McpError) {
64535
65304
  if (error46.code === ErrorCode.UrlElicitationRequired) {
@@ -64538,7 +65307,6 @@ class McpServer {
64538
65307
  }
64539
65308
  return this.createToolError(error46 instanceof Error ? error46.message : String(error46));
64540
65309
  }
64541
- return result;
64542
65310
  });
64543
65311
  this._toolHandlersInitialized = true;
64544
65312
  }
@@ -64553,6 +65321,87 @@ class McpServer {
64553
65321
  isError: true
64554
65322
  };
64555
65323
  }
65324
+ async validateToolInput(tool, args, toolName) {
65325
+ if (!tool.inputSchema) {
65326
+ return;
65327
+ }
65328
+ const inputObj = normalizeObjectSchema(tool.inputSchema);
65329
+ const schemaToParse = inputObj !== null && inputObj !== undefined ? inputObj : tool.inputSchema;
65330
+ const parseResult = await safeParseAsync2(schemaToParse, args);
65331
+ if (!parseResult.success) {
65332
+ const error46 = "error" in parseResult ? parseResult.error : "Unknown error";
65333
+ const errorMessage = getParseErrorMessage(error46);
65334
+ throw new McpError(ErrorCode.InvalidParams, `Input validation error: Invalid arguments for tool ${toolName}: ${errorMessage}`);
65335
+ }
65336
+ return parseResult.data;
65337
+ }
65338
+ async validateToolOutput(tool, result, toolName) {
65339
+ if (!tool.outputSchema) {
65340
+ return;
65341
+ }
65342
+ if (!("content" in result)) {
65343
+ return;
65344
+ }
65345
+ if (result.isError) {
65346
+ return;
65347
+ }
65348
+ if (!result.structuredContent) {
65349
+ throw new McpError(ErrorCode.InvalidParams, `Output validation error: Tool ${toolName} has an output schema but no structured content was provided`);
65350
+ }
65351
+ const outputObj = normalizeObjectSchema(tool.outputSchema);
65352
+ const parseResult = await safeParseAsync2(outputObj, result.structuredContent);
65353
+ if (!parseResult.success) {
65354
+ const error46 = "error" in parseResult ? parseResult.error : "Unknown error";
65355
+ const errorMessage = getParseErrorMessage(error46);
65356
+ throw new McpError(ErrorCode.InvalidParams, `Output validation error: Invalid structured content for tool ${toolName}: ${errorMessage}`);
65357
+ }
65358
+ }
65359
+ async executeToolHandler(tool, args, extra) {
65360
+ const handler = tool.handler;
65361
+ const isTaskHandler = "createTask" in handler;
65362
+ if (isTaskHandler) {
65363
+ if (!extra.taskStore) {
65364
+ throw new Error("No task store provided.");
65365
+ }
65366
+ const taskExtra = { ...extra, taskStore: extra.taskStore };
65367
+ if (tool.inputSchema) {
65368
+ const typedHandler = handler;
65369
+ return await Promise.resolve(typedHandler.createTask(args, taskExtra));
65370
+ } else {
65371
+ const typedHandler = handler;
65372
+ return await Promise.resolve(typedHandler.createTask(taskExtra));
65373
+ }
65374
+ }
65375
+ if (tool.inputSchema) {
65376
+ const typedHandler = handler;
65377
+ return await Promise.resolve(typedHandler(args, extra));
65378
+ } else {
65379
+ const typedHandler = handler;
65380
+ return await Promise.resolve(typedHandler(extra));
65381
+ }
65382
+ }
65383
+ async handleAutomaticTaskPolling(tool, request, extra) {
65384
+ var _a;
65385
+ if (!extra.taskStore) {
65386
+ throw new Error("No task store provided for task-capable tool.");
65387
+ }
65388
+ const args = await this.validateToolInput(tool, request.params.arguments, request.params.name);
65389
+ const handler = tool.handler;
65390
+ const taskExtra = { ...extra, taskStore: extra.taskStore };
65391
+ const createTaskResult = args ? await Promise.resolve(handler.createTask(args, taskExtra)) : await Promise.resolve(handler.createTask(taskExtra));
65392
+ const taskId = createTaskResult.task.taskId;
65393
+ let task = createTaskResult.task;
65394
+ const pollInterval = (_a = task.pollInterval) !== null && _a !== undefined ? _a : 5000;
65395
+ while (task.status !== "completed" && task.status !== "failed" && task.status !== "cancelled") {
65396
+ await new Promise((resolve) => setTimeout(resolve, pollInterval));
65397
+ const updatedTask = await extra.taskStore.getTask(taskId);
65398
+ if (!updatedTask) {
65399
+ throw new McpError(ErrorCode.InternalError, `Task ${taskId} not found during polling`);
65400
+ }
65401
+ task = updatedTask;
65402
+ }
65403
+ return await extra.taskStore.getTaskResult(taskId);
65404
+ }
64556
65405
  setCompletionRequestHandler() {
64557
65406
  if (this._completionHandlerInitialized) {
64558
65407
  return;
@@ -64707,7 +65556,9 @@ class McpServer {
64707
65556
  const argsObj = normalizeObjectSchema(prompt.argsSchema);
64708
65557
  const parseResult = await safeParseAsync2(argsObj, request.params.arguments);
64709
65558
  if (!parseResult.success) {
64710
- throw new McpError(ErrorCode.InvalidParams, `Invalid arguments for prompt ${request.params.name}: ${getParseErrorMessage(parseResult.error)}`);
65559
+ const error46 = "error" in parseResult ? parseResult.error : "Unknown error";
65560
+ const errorMessage = getParseErrorMessage(error46);
65561
+ throw new McpError(ErrorCode.InvalidParams, `Invalid arguments for prompt ${request.params.name}: ${errorMessage}`);
64711
65562
  }
64712
65563
  const args = parseResult.data;
64713
65564
  const cb = prompt.callback;
@@ -64859,7 +65710,7 @@ class McpServer {
64859
65710
  this._registeredPrompts[name] = registeredPrompt;
64860
65711
  return registeredPrompt;
64861
65712
  }
64862
- _createRegisteredTool(name, title, description, inputSchema, outputSchema, annotations, _meta, callback) {
65713
+ _createRegisteredTool(name, title, description, inputSchema, outputSchema, annotations, execution, _meta, handler) {
64863
65714
  validateAndWarnToolName(name);
64864
65715
  const registeredTool = {
64865
65716
  title,
@@ -64867,8 +65718,9 @@ class McpServer {
64867
65718
  inputSchema: getZodSchemaObject(inputSchema),
64868
65719
  outputSchema: getZodSchemaObject(outputSchema),
64869
65720
  annotations,
65721
+ execution,
64870
65722
  _meta,
64871
- callback,
65723
+ handler,
64872
65724
  enabled: true,
64873
65725
  disable: () => registeredTool.update({ enabled: false }),
64874
65726
  enable: () => registeredTool.update({ enabled: true }),
@@ -64889,7 +65741,7 @@ class McpServer {
64889
65741
  if (typeof updates.paramsSchema !== "undefined")
64890
65742
  registeredTool.inputSchema = objectFromShape(updates.paramsSchema);
64891
65743
  if (typeof updates.callback !== "undefined")
64892
- registeredTool.callback = updates.callback;
65744
+ registeredTool.handler = updates.callback;
64893
65745
  if (typeof updates.annotations !== "undefined")
64894
65746
  registeredTool.annotations = updates.annotations;
64895
65747
  if (typeof updates._meta !== "undefined")
@@ -64917,9 +65769,9 @@ class McpServer {
64917
65769
  }
64918
65770
  if (rest.length > 1) {
64919
65771
  const firstArg = rest[0];
64920
- if (isZodRawShape(firstArg)) {
65772
+ if (isZodRawShapeCompat(firstArg)) {
64921
65773
  inputSchema = rest.shift();
64922
- if (rest.length > 1 && typeof rest[0] === "object" && rest[0] !== null && !isZodRawShape(rest[0])) {
65774
+ if (rest.length > 1 && typeof rest[0] === "object" && rest[0] !== null && !isZodRawShapeCompat(rest[0])) {
64923
65775
  annotations = rest.shift();
64924
65776
  }
64925
65777
  } else if (typeof firstArg === "object" && firstArg !== null) {
@@ -64927,14 +65779,14 @@ class McpServer {
64927
65779
  }
64928
65780
  }
64929
65781
  const callback = rest[0];
64930
- return this._createRegisteredTool(name, undefined, description, inputSchema, outputSchema, annotations, undefined, callback);
65782
+ return this._createRegisteredTool(name, undefined, description, inputSchema, outputSchema, annotations, { taskSupport: "forbidden" }, undefined, callback);
64931
65783
  }
64932
65784
  registerTool(name, config2, cb) {
64933
65785
  if (this._registeredTools[name]) {
64934
65786
  throw new Error(`Tool ${name} is already registered`);
64935
65787
  }
64936
65788
  const { title, description, inputSchema, outputSchema, annotations, _meta } = config2;
64937
- return this._createRegisteredTool(name, title, description, inputSchema, outputSchema, annotations, _meta, cb);
65789
+ return this._createRegisteredTool(name, title, description, inputSchema, outputSchema, annotations, { taskSupport: "forbidden" }, _meta, cb);
64938
65790
  }
64939
65791
  prompt(name, ...rest) {
64940
65792
  if (this._registeredPrompts[name]) {
@@ -64990,20 +65842,29 @@ var EMPTY_OBJECT_JSON_SCHEMA = {
64990
65842
  type: "object",
64991
65843
  properties: {}
64992
65844
  };
64993
- function isZodRawShape(obj) {
64994
- if (typeof obj !== "object" || obj === null)
64995
- return false;
64996
- const isEmptyObject = Object.keys(obj).length === 0;
64997
- return isEmptyObject || Object.values(obj).some(isZodTypeLike);
64998
- }
64999
65845
  function isZodTypeLike(value) {
65000
65846
  return value !== null && typeof value === "object" && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
65001
65847
  }
65848
+ function isZodSchemaInstance(obj) {
65849
+ return "_def" in obj || "_zod" in obj || isZodTypeLike(obj);
65850
+ }
65851
+ function isZodRawShapeCompat(obj) {
65852
+ if (typeof obj !== "object" || obj === null) {
65853
+ return false;
65854
+ }
65855
+ if (isZodSchemaInstance(obj)) {
65856
+ return false;
65857
+ }
65858
+ if (Object.keys(obj).length === 0) {
65859
+ return true;
65860
+ }
65861
+ return Object.values(obj).some(isZodTypeLike);
65862
+ }
65002
65863
  function getZodSchemaObject(schema) {
65003
65864
  if (!schema) {
65004
65865
  return;
65005
65866
  }
65006
- if (isZodRawShape(schema)) {
65867
+ if (isZodRawShapeCompat(schema)) {
65007
65868
  return objectFromShape(schema);
65008
65869
  }
65009
65870
  return schema;
@@ -65050,10 +65911,10 @@ var EMPTY_COMPLETION_RESULT = {
65050
65911
  }
65051
65912
  };
65052
65913
 
65053
- // ../../node_modules/.bun/@modelcontextprotocol+sdk@1.23.0/node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.js
65914
+ // ../../node_modules/.bun/@modelcontextprotocol+sdk@1.24.3/node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.js
65054
65915
  import process2 from "node:process";
65055
65916
 
65056
- // ../../node_modules/.bun/@modelcontextprotocol+sdk@1.23.0/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js
65917
+ // ../../node_modules/.bun/@modelcontextprotocol+sdk@1.24.3/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js
65057
65918
  class ReadBuffer {
65058
65919
  append(chunk) {
65059
65920
  this._buffer = this._buffer ? Buffer.concat([this._buffer, chunk]) : chunk;
@@ -65083,7 +65944,7 @@ function serializeMessage(message) {
65083
65944
  `;
65084
65945
  }
65085
65946
 
65086
- // ../../node_modules/.bun/@modelcontextprotocol+sdk@1.23.0/node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.js
65947
+ // ../../node_modules/.bun/@modelcontextprotocol+sdk@1.24.3/node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.js
65087
65948
  class StdioServerTransport {
65088
65949
  constructor(_stdin = process2.stdin, _stdout = process2.stdout) {
65089
65950
  this._stdin = _stdin;
@@ -83863,7 +84724,7 @@ var portalQueries = (server, env3) => {
83863
84724
  var package_default = {
83864
84725
  name: "@settlemint/sdk-mcp",
83865
84726
  description: "MCP interface for SettleMint SDK, providing development tools and project management capabilities",
83866
- version: "2.6.4-pr836c05ff",
84727
+ version: "2.6.4-pr855d66d3",
83867
84728
  type: "module",
83868
84729
  private: false,
83869
84730
  license: "FSL-1.1-MIT",
@@ -83905,9 +84766,9 @@ var package_default = {
83905
84766
  "@commander-js/extra-typings": "14.0.0",
83906
84767
  "@graphql-tools/load": "8.1.7",
83907
84768
  "@graphql-tools/url-loader": "9.0.5",
83908
- "@modelcontextprotocol/sdk": "1.23.0",
83909
- "@settlemint/sdk-js": "2.6.4-pr836c05ff",
83910
- "@settlemint/sdk-utils": "2.6.4-pr836c05ff",
84769
+ "@modelcontextprotocol/sdk": "1.24.3",
84770
+ "@settlemint/sdk-js": "2.6.4-pr855d66d3",
84771
+ "@settlemint/sdk-utils": "2.6.4-pr855d66d3",
83911
84772
  commander: "14.0.2",
83912
84773
  graphql: "16.12.0",
83913
84774
  zod: "^4",
@@ -89987,4 +90848,4 @@ await main().catch((error47) => {
89987
90848
  process.exit(1);
89988
90849
  });
89989
90850
 
89990
- //# debugId=CF9C0606A922636564756E2164756E21
90851
+ //# debugId=77187357ACEC0E5464756E2164756E21