@antonytm/mcp-sitecore-server 1.3.2 → 1.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bundle.js CHANGED
@@ -4575,16 +4575,11 @@ const config = {
4575
4575
  authorizationHeader: ENV$1.AUTORIZATION_HEADER || "",
4576
4576
  };
4577
4577
 
4578
- const LATEST_PROTOCOL_VERSION = "2025-06-18";
4579
- const DEFAULT_NEGOTIATED_PROTOCOL_VERSION = "2025-03-26";
4580
- const SUPPORTED_PROTOCOL_VERSIONS = [
4581
- LATEST_PROTOCOL_VERSION,
4582
- "2025-03-26",
4583
- "2024-11-05",
4584
- "2024-10-07",
4585
- ];
4578
+ const LATEST_PROTOCOL_VERSION = '2025-06-18';
4579
+ const DEFAULT_NEGOTIATED_PROTOCOL_VERSION = '2025-03-26';
4580
+ const SUPPORTED_PROTOCOL_VERSIONS = [LATEST_PROTOCOL_VERSION, '2025-03-26', '2024-11-05', '2024-10-07'];
4586
4581
  /* JSON-RPC types */
4587
- const JSONRPC_VERSION = "2.0";
4582
+ const JSONRPC_VERSION = '2.0';
4588
4583
  /**
4589
4584
  * A progress token, used to associate progress notifications with the original request.
4590
4585
  */
@@ -4597,35 +4592,35 @@ const RequestMetaSchema = objectType({
4597
4592
  /**
4598
4593
  * If specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications.
4599
4594
  */
4600
- progressToken: optionalType(ProgressTokenSchema),
4595
+ progressToken: optionalType(ProgressTokenSchema)
4601
4596
  })
4602
4597
  .passthrough();
4603
4598
  const BaseRequestParamsSchema = objectType({
4604
- _meta: optionalType(RequestMetaSchema),
4599
+ _meta: optionalType(RequestMetaSchema)
4605
4600
  })
4606
4601
  .passthrough();
4607
4602
  const RequestSchema = objectType({
4608
4603
  method: stringType(),
4609
- params: optionalType(BaseRequestParamsSchema),
4604
+ params: optionalType(BaseRequestParamsSchema)
4610
4605
  });
4611
4606
  const BaseNotificationParamsSchema = objectType({
4612
4607
  /**
4613
4608
  * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
4614
4609
  * for notes on _meta usage.
4615
4610
  */
4616
- _meta: optionalType(objectType({}).passthrough()),
4611
+ _meta: optionalType(objectType({}).passthrough())
4617
4612
  })
4618
4613
  .passthrough();
4619
4614
  const NotificationSchema = objectType({
4620
4615
  method: stringType(),
4621
- params: optionalType(BaseNotificationParamsSchema),
4616
+ params: optionalType(BaseNotificationParamsSchema)
4622
4617
  });
4623
4618
  const ResultSchema = objectType({
4624
4619
  /**
4625
4620
  * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
4626
4621
  * for notes on _meta usage.
4627
4622
  */
4628
- _meta: optionalType(objectType({}).passthrough()),
4623
+ _meta: optionalType(objectType({}).passthrough())
4629
4624
  })
4630
4625
  .passthrough();
4631
4626
  /**
@@ -4637,7 +4632,7 @@ const RequestIdSchema = unionType([stringType(), numberType().int()]);
4637
4632
  */
4638
4633
  const JSONRPCRequestSchema = objectType({
4639
4634
  jsonrpc: literalType(JSONRPC_VERSION),
4640
- id: RequestIdSchema,
4635
+ id: RequestIdSchema
4641
4636
  })
4642
4637
  .merge(RequestSchema)
4643
4638
  .strict();
@@ -4646,7 +4641,7 @@ const isJSONRPCRequest = (value) => JSONRPCRequestSchema.safeParse(value).succes
4646
4641
  * A notification which does not expect a response.
4647
4642
  */
4648
4643
  const JSONRPCNotificationSchema = objectType({
4649
- jsonrpc: literalType(JSONRPC_VERSION),
4644
+ jsonrpc: literalType(JSONRPC_VERSION)
4650
4645
  })
4651
4646
  .merge(NotificationSchema)
4652
4647
  .strict();
@@ -4657,7 +4652,7 @@ const isJSONRPCNotification = (value) => JSONRPCNotificationSchema.safeParse(val
4657
4652
  const JSONRPCResponseSchema = objectType({
4658
4653
  jsonrpc: literalType(JSONRPC_VERSION),
4659
4654
  id: RequestIdSchema,
4660
- result: ResultSchema,
4655
+ result: ResultSchema
4661
4656
  })
4662
4657
  .strict();
4663
4658
  const isJSONRPCResponse = (value) => JSONRPCResponseSchema.safeParse(value).success;
@@ -4694,17 +4689,12 @@ const JSONRPCErrorSchema = objectType({
4694
4689
  /**
4695
4690
  * Additional information about the error. The value of this member is defined by the sender (e.g. detailed error information, nested errors etc.).
4696
4691
  */
4697
- data: optionalType(unknownType()),
4698
- }),
4692
+ data: optionalType(unknownType())
4693
+ })
4699
4694
  })
4700
4695
  .strict();
4701
4696
  const isJSONRPCError = (value) => JSONRPCErrorSchema.safeParse(value).success;
4702
- const JSONRPCMessageSchema = unionType([
4703
- JSONRPCRequestSchema,
4704
- JSONRPCNotificationSchema,
4705
- JSONRPCResponseSchema,
4706
- JSONRPCErrorSchema,
4707
- ]);
4697
+ const JSONRPCMessageSchema = unionType([JSONRPCRequestSchema, JSONRPCNotificationSchema, JSONRPCResponseSchema, JSONRPCErrorSchema]);
4708
4698
  /* Empty result */
4709
4699
  /**
4710
4700
  * A response that indicates success but carries no data.
@@ -4721,7 +4711,7 @@ const EmptyResultSchema = ResultSchema.strict();
4721
4711
  * A client MUST NOT attempt to cancel its `initialize` request.
4722
4712
  */
4723
4713
  const CancelledNotificationSchema = NotificationSchema.extend({
4724
- method: literalType("notifications/cancelled"),
4714
+ method: literalType('notifications/cancelled'),
4725
4715
  params: BaseNotificationParamsSchema.extend({
4726
4716
  /**
4727
4717
  * The ID of the request to cancel.
@@ -4732,8 +4722,8 @@ const CancelledNotificationSchema = NotificationSchema.extend({
4732
4722
  /**
4733
4723
  * An optional string describing the reason for the cancellation. This MAY be logged or presented to the user.
4734
4724
  */
4735
- reason: stringType().optional(),
4736
- }),
4725
+ reason: stringType().optional()
4726
+ })
4737
4727
  });
4738
4728
  /* Base Metadata */
4739
4729
  /**
@@ -4749,9 +4739,31 @@ const IconSchema = objectType({
4749
4739
  */
4750
4740
  mimeType: optionalType(stringType()),
4751
4741
  /**
4752
- * Optional string specifying icon dimensions (e.g., "48x48 96x96").
4742
+ * Optional array of strings that specify sizes at which the icon can be used.
4743
+ * Each string should be in WxH format (e.g., `"48x48"`, `"96x96"`) or `"any"` for scalable formats like SVG.
4744
+ *
4745
+ * If not provided, the client should assume that the icon can be used at any size.
4753
4746
  */
4754
- sizes: optionalType(stringType()),
4747
+ sizes: optionalType(arrayType(stringType()))
4748
+ })
4749
+ .passthrough();
4750
+ /**
4751
+ * Base schema to add `icons` property.
4752
+ *
4753
+ */
4754
+ const IconsSchema = objectType({
4755
+ /**
4756
+ * Optional set of sized icons that the client can display in a user interface.
4757
+ *
4758
+ * Clients that support rendering icons MUST support at least the following MIME types:
4759
+ * - `image/png` - PNG images (safe, universal compatibility)
4760
+ * - `image/jpeg` (and `image/jpg`) - JPEG images (safe, universal compatibility)
4761
+ *
4762
+ * Clients that support rendering icons SHOULD also support:
4763
+ * - `image/svg+xml` - SVG images (scalable but requires security precautions)
4764
+ * - `image/webp` - WebP images (modern, efficient format)
4765
+ */
4766
+ icons: arrayType(IconSchema).optional()
4755
4767
  })
4756
4768
  .passthrough();
4757
4769
  /**
@@ -4761,14 +4773,14 @@ const BaseMetadataSchema = objectType({
4761
4773
  /** Intended for programmatic or logical use, but used as a display name in past specs or fallback */
4762
4774
  name: stringType(),
4763
4775
  /**
4764
- * Intended for UI and end-user contexts — optimized to be human-readable and easily understood,
4765
- * even by those unfamiliar with domain-specific terminology.
4766
- *
4767
- * If not provided, the name should be used for display (except for Tool,
4768
- * where `annotations.title` should be given precedence over using `name`,
4769
- * if present).
4770
- */
4771
- title: optionalType(stringType()),
4776
+ * Intended for UI and end-user contexts — optimized to be human-readable and easily understood,
4777
+ * even by those unfamiliar with domain-specific terminology.
4778
+ *
4779
+ * If not provided, the name should be used for display (except for Tool,
4780
+ * where `annotations.title` should be given precedence over using `name`,
4781
+ * if present).
4782
+ */
4783
+ title: optionalType(stringType())
4772
4784
  })
4773
4785
  .passthrough();
4774
4786
  /* Initialization */
@@ -4780,17 +4792,8 @@ const ImplementationSchema = BaseMetadataSchema.extend({
4780
4792
  /**
4781
4793
  * An optional URL of the website for this implementation.
4782
4794
  */
4783
- websiteUrl: optionalType(stringType()),
4784
- /**
4785
- * An optional list of icons for this implementation.
4786
- * This can be used by clients to display the implementation in a user interface.
4787
- * Each icon should have a `kind` property that specifies whether it is a data representation or a URL source, a `src` property that points to the icon file or data representation, and may also include a `mimeType` and `sizes` property.
4788
- * The `mimeType` property should be a valid MIME type for the icon file, such as "image/png" or "image/svg+xml".
4789
- * The `sizes` property should be a string that specifies one or more sizes at which the icon file can be used, such as "48x48" or "any" for scalable formats like SVG.
4790
- * The `sizes` property is optional, and if not provided, the client should assume that the icon can be used at any size.
4791
- */
4792
- icons: optionalType(arrayType(IconSchema)),
4793
- });
4795
+ websiteUrl: optionalType(stringType())
4796
+ }).merge(IconsSchema);
4794
4797
  /**
4795
4798
  * Capabilities a client may support. Known capabilities are defined here, in this schema, but this is not a closed set: any client can define its own, additional capabilities.
4796
4799
  */
@@ -4814,24 +4817,24 @@ const ClientCapabilitiesSchema = objectType({
4814
4817
  /**
4815
4818
  * Whether the client supports issuing notifications for changes to the roots list.
4816
4819
  */
4817
- listChanged: optionalType(booleanType()),
4820
+ listChanged: optionalType(booleanType())
4818
4821
  })
4819
- .passthrough()),
4822
+ .passthrough())
4820
4823
  })
4821
4824
  .passthrough();
4822
4825
  /**
4823
4826
  * This request is sent from the client to the server when it first connects, asking it to begin initialization.
4824
4827
  */
4825
4828
  const InitializeRequestSchema = RequestSchema.extend({
4826
- method: literalType("initialize"),
4829
+ method: literalType('initialize'),
4827
4830
  params: BaseRequestParamsSchema.extend({
4828
4831
  /**
4829
4832
  * The latest version of the Model Context Protocol that the client supports. The client MAY decide to support older versions as well.
4830
4833
  */
4831
4834
  protocolVersion: stringType(),
4832
4835
  capabilities: ClientCapabilitiesSchema,
4833
- clientInfo: ImplementationSchema,
4834
- }),
4836
+ clientInfo: ImplementationSchema
4837
+ })
4835
4838
  });
4836
4839
  const isInitializeRequest = (value) => InitializeRequestSchema.safeParse(value).success;
4837
4840
  /**
@@ -4857,7 +4860,7 @@ const ServerCapabilitiesSchema = objectType({
4857
4860
  /**
4858
4861
  * Whether this server supports issuing notifications for changes to the prompt list.
4859
4862
  */
4860
- listChanged: optionalType(booleanType()),
4863
+ listChanged: optionalType(booleanType())
4861
4864
  })
4862
4865
  .passthrough()),
4863
4866
  /**
@@ -4871,7 +4874,7 @@ const ServerCapabilitiesSchema = objectType({
4871
4874
  /**
4872
4875
  * Whether this server supports issuing notifications for changes to the resource list.
4873
4876
  */
4874
- listChanged: optionalType(booleanType()),
4877
+ listChanged: optionalType(booleanType())
4875
4878
  })
4876
4879
  .passthrough()),
4877
4880
  /**
@@ -4881,9 +4884,9 @@ const ServerCapabilitiesSchema = objectType({
4881
4884
  /**
4882
4885
  * Whether this server supports issuing notifications for changes to the tool list.
4883
4886
  */
4884
- listChanged: optionalType(booleanType()),
4887
+ listChanged: optionalType(booleanType())
4885
4888
  })
4886
- .passthrough()),
4889
+ .passthrough())
4887
4890
  })
4888
4891
  .passthrough();
4889
4892
  /**
@@ -4901,20 +4904,20 @@ const InitializeResultSchema = ResultSchema.extend({
4901
4904
  *
4902
4905
  * This can be used by clients to improve the LLM's understanding of available tools, resources, etc. It can be thought of like a "hint" to the model. For example, this information MAY be added to the system prompt.
4903
4906
  */
4904
- instructions: optionalType(stringType()),
4907
+ instructions: optionalType(stringType())
4905
4908
  });
4906
4909
  /**
4907
4910
  * This notification is sent from the client to the server after initialization has finished.
4908
4911
  */
4909
4912
  const InitializedNotificationSchema = NotificationSchema.extend({
4910
- method: literalType("notifications/initialized"),
4913
+ method: literalType('notifications/initialized')
4911
4914
  });
4912
4915
  /* Ping */
4913
4916
  /**
4914
4917
  * A ping, issued by either the server or the client, to check that the other party is still alive. The receiver must promptly respond, or else may be disconnected.
4915
4918
  */
4916
4919
  const PingRequestSchema = RequestSchema.extend({
4917
- method: literalType("ping"),
4920
+ method: literalType('ping')
4918
4921
  });
4919
4922
  /* Progress notifications */
4920
4923
  const ProgressSchema = objectType({
@@ -4929,20 +4932,20 @@ const ProgressSchema = objectType({
4929
4932
  /**
4930
4933
  * An optional message describing the current progress.
4931
4934
  */
4932
- message: optionalType(stringType()),
4935
+ message: optionalType(stringType())
4933
4936
  })
4934
4937
  .passthrough();
4935
4938
  /**
4936
4939
  * An out-of-band notification used to inform the receiver of a progress update for a long-running request.
4937
4940
  */
4938
4941
  const ProgressNotificationSchema = NotificationSchema.extend({
4939
- method: literalType("notifications/progress"),
4942
+ method: literalType('notifications/progress'),
4940
4943
  params: BaseNotificationParamsSchema.merge(ProgressSchema).extend({
4941
4944
  /**
4942
4945
  * The progress token which was given in the initial request, used to associate this notification with the request that is proceeding.
4943
4946
  */
4944
- progressToken: ProgressTokenSchema,
4945
- }),
4947
+ progressToken: ProgressTokenSchema
4948
+ })
4946
4949
  });
4947
4950
  /* Pagination */
4948
4951
  const PaginatedRequestSchema = RequestSchema.extend({
@@ -4951,15 +4954,15 @@ const PaginatedRequestSchema = RequestSchema.extend({
4951
4954
  * An opaque token representing the current pagination position.
4952
4955
  * If provided, the server should return results starting after this cursor.
4953
4956
  */
4954
- cursor: optionalType(CursorSchema),
4955
- }).optional(),
4957
+ cursor: optionalType(CursorSchema)
4958
+ }).optional()
4956
4959
  });
4957
4960
  const PaginatedResultSchema = ResultSchema.extend({
4958
4961
  /**
4959
4962
  * An opaque token representing the pagination position after the last returned result.
4960
4963
  * If present, there may be more results available.
4961
4964
  */
4962
- nextCursor: optionalType(CursorSchema),
4965
+ nextCursor: optionalType(CursorSchema)
4963
4966
  });
4964
4967
  /* Resources */
4965
4968
  /**
@@ -4978,21 +4981,21 @@ const ResourceContentsSchema = objectType({
4978
4981
  * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
4979
4982
  * for notes on _meta usage.
4980
4983
  */
4981
- _meta: optionalType(objectType({}).passthrough()),
4984
+ _meta: optionalType(objectType({}).passthrough())
4982
4985
  })
4983
4986
  .passthrough();
4984
4987
  const TextResourceContentsSchema = ResourceContentsSchema.extend({
4985
4988
  /**
4986
4989
  * The text of the item. This must only be set if the item can actually be represented as text (not binary data).
4987
4990
  */
4988
- text: stringType(),
4991
+ text: stringType()
4989
4992
  });
4990
4993
  /**
4991
4994
  * A Zod schema for validating Base64 strings that is more performant and
4992
4995
  * robust for very large inputs than the default regex-based check. It avoids
4993
4996
  * stack overflows by using the native `atob` function for validation.
4994
4997
  */
4995
- const Base64Schema = stringType().refine((val) => {
4998
+ const Base64Schema = stringType().refine(val => {
4996
4999
  try {
4997
5000
  // atob throws a DOMException if the string contains characters
4998
5001
  // that are not part of the Base64 character set.
@@ -5002,12 +5005,12 @@ const Base64Schema = stringType().refine((val) => {
5002
5005
  catch (_a) {
5003
5006
  return false;
5004
5007
  }
5005
- }, { message: "Invalid Base64 string" });
5008
+ }, { message: 'Invalid Base64 string' });
5006
5009
  const BlobResourceContentsSchema = ResourceContentsSchema.extend({
5007
5010
  /**
5008
5011
  * A base64-encoded string representing the binary data of the item.
5009
5012
  */
5010
- blob: Base64Schema,
5013
+ blob: Base64Schema
5011
5014
  });
5012
5015
  /**
5013
5016
  * A known resource that the server is capable of reading.
@@ -5027,16 +5030,12 @@ const ResourceSchema = BaseMetadataSchema.extend({
5027
5030
  * The MIME type of this resource, if known.
5028
5031
  */
5029
5032
  mimeType: optionalType(stringType()),
5030
- /**
5031
- * An optional list of icons for this resource.
5032
- */
5033
- icons: optionalType(arrayType(IconSchema)),
5034
5033
  /**
5035
5034
  * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
5036
5035
  * for notes on _meta usage.
5037
5036
  */
5038
- _meta: optionalType(objectType({}).passthrough()),
5039
- });
5037
+ _meta: optionalType(objectType({}).passthrough())
5038
+ }).merge(IconsSchema);
5040
5039
  /**
5041
5040
  * A template description for resources available on the server.
5042
5041
  */
@@ -5059,91 +5058,91 @@ const ResourceTemplateSchema = BaseMetadataSchema.extend({
5059
5058
  * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
5060
5059
  * for notes on _meta usage.
5061
5060
  */
5062
- _meta: optionalType(objectType({}).passthrough()),
5063
- });
5061
+ _meta: optionalType(objectType({}).passthrough())
5062
+ }).merge(IconsSchema);
5064
5063
  /**
5065
5064
  * Sent from the client to request a list of resources the server has.
5066
5065
  */
5067
5066
  const ListResourcesRequestSchema = PaginatedRequestSchema.extend({
5068
- method: literalType("resources/list"),
5067
+ method: literalType('resources/list')
5069
5068
  });
5070
5069
  /**
5071
5070
  * The server's response to a resources/list request from the client.
5072
5071
  */
5073
5072
  const ListResourcesResultSchema = PaginatedResultSchema.extend({
5074
- resources: arrayType(ResourceSchema),
5073
+ resources: arrayType(ResourceSchema)
5075
5074
  });
5076
5075
  /**
5077
5076
  * Sent from the client to request a list of resource templates the server has.
5078
5077
  */
5079
5078
  const ListResourceTemplatesRequestSchema = PaginatedRequestSchema.extend({
5080
- method: literalType("resources/templates/list"),
5079
+ method: literalType('resources/templates/list')
5081
5080
  });
5082
5081
  /**
5083
5082
  * The server's response to a resources/templates/list request from the client.
5084
5083
  */
5085
5084
  const ListResourceTemplatesResultSchema = PaginatedResultSchema.extend({
5086
- resourceTemplates: arrayType(ResourceTemplateSchema),
5085
+ resourceTemplates: arrayType(ResourceTemplateSchema)
5087
5086
  });
5088
5087
  /**
5089
5088
  * Sent from the client to the server, to read a specific resource URI.
5090
5089
  */
5091
5090
  const ReadResourceRequestSchema = RequestSchema.extend({
5092
- method: literalType("resources/read"),
5091
+ method: literalType('resources/read'),
5093
5092
  params: BaseRequestParamsSchema.extend({
5094
5093
  /**
5095
5094
  * The URI of the resource to read. The URI can use any protocol; it is up to the server how to interpret it.
5096
5095
  */
5097
- uri: stringType(),
5098
- }),
5096
+ uri: stringType()
5097
+ })
5099
5098
  });
5100
5099
  /**
5101
5100
  * The server's response to a resources/read request from the client.
5102
5101
  */
5103
5102
  const ReadResourceResultSchema = ResultSchema.extend({
5104
- contents: arrayType(unionType([TextResourceContentsSchema, BlobResourceContentsSchema])),
5103
+ contents: arrayType(unionType([TextResourceContentsSchema, BlobResourceContentsSchema]))
5105
5104
  });
5106
5105
  /**
5107
5106
  * An optional notification from the server to the client, informing it that the list of resources it can read from has changed. This may be issued by servers without any previous subscription from the client.
5108
5107
  */
5109
5108
  const ResourceListChangedNotificationSchema = NotificationSchema.extend({
5110
- method: literalType("notifications/resources/list_changed"),
5109
+ method: literalType('notifications/resources/list_changed')
5111
5110
  });
5112
5111
  /**
5113
5112
  * Sent from the client to request resources/updated notifications from the server whenever a particular resource changes.
5114
5113
  */
5115
5114
  const SubscribeRequestSchema = RequestSchema.extend({
5116
- method: literalType("resources/subscribe"),
5115
+ method: literalType('resources/subscribe'),
5117
5116
  params: BaseRequestParamsSchema.extend({
5118
5117
  /**
5119
5118
  * The URI of the resource to subscribe to. The URI can use any protocol; it is up to the server how to interpret it.
5120
5119
  */
5121
- uri: stringType(),
5122
- }),
5120
+ uri: stringType()
5121
+ })
5123
5122
  });
5124
5123
  /**
5125
5124
  * Sent from the client to request cancellation of resources/updated notifications from the server. This should follow a previous resources/subscribe request.
5126
5125
  */
5127
5126
  const UnsubscribeRequestSchema = RequestSchema.extend({
5128
- method: literalType("resources/unsubscribe"),
5127
+ method: literalType('resources/unsubscribe'),
5129
5128
  params: BaseRequestParamsSchema.extend({
5130
5129
  /**
5131
5130
  * The URI of the resource to unsubscribe from.
5132
5131
  */
5133
- uri: stringType(),
5134
- }),
5132
+ uri: stringType()
5133
+ })
5135
5134
  });
5136
5135
  /**
5137
5136
  * A notification from the server to the client, informing it that a resource has changed and may need to be read again. This should only be sent if the client previously sent a resources/subscribe request.
5138
5137
  */
5139
5138
  const ResourceUpdatedNotificationSchema = NotificationSchema.extend({
5140
- method: literalType("notifications/resources/updated"),
5139
+ method: literalType('notifications/resources/updated'),
5141
5140
  params: BaseNotificationParamsSchema.extend({
5142
5141
  /**
5143
5142
  * The URI of the resource that has been updated. This might be a sub-resource of the one that the client actually subscribed to.
5144
5143
  */
5145
- uri: stringType(),
5146
- }),
5144
+ uri: stringType()
5145
+ })
5147
5146
  });
5148
5147
  /* Prompts */
5149
5148
  /**
@@ -5161,7 +5160,7 @@ const PromptArgumentSchema = objectType({
5161
5160
  /**
5162
5161
  * Whether this argument must be provided.
5163
5162
  */
5164
- required: optionalType(booleanType()),
5163
+ required: optionalType(booleanType())
5165
5164
  })
5166
5165
  .passthrough();
5167
5166
  /**
@@ -5176,33 +5175,29 @@ const PromptSchema = BaseMetadataSchema.extend({
5176
5175
  * A list of arguments to use for templating the prompt.
5177
5176
  */
5178
5177
  arguments: optionalType(arrayType(PromptArgumentSchema)),
5179
- /**
5180
- * An optional list of icons for this prompt.
5181
- */
5182
- icons: optionalType(arrayType(IconSchema)),
5183
5178
  /**
5184
5179
  * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
5185
5180
  * for notes on _meta usage.
5186
5181
  */
5187
- _meta: optionalType(objectType({}).passthrough()),
5188
- });
5182
+ _meta: optionalType(objectType({}).passthrough())
5183
+ }).merge(IconsSchema);
5189
5184
  /**
5190
5185
  * Sent from the client to request a list of prompts and prompt templates the server has.
5191
5186
  */
5192
5187
  const ListPromptsRequestSchema = PaginatedRequestSchema.extend({
5193
- method: literalType("prompts/list"),
5188
+ method: literalType('prompts/list')
5194
5189
  });
5195
5190
  /**
5196
5191
  * The server's response to a prompts/list request from the client.
5197
5192
  */
5198
5193
  const ListPromptsResultSchema = PaginatedResultSchema.extend({
5199
- prompts: arrayType(PromptSchema),
5194
+ prompts: arrayType(PromptSchema)
5200
5195
  });
5201
5196
  /**
5202
5197
  * Used by the client to get a prompt provided by the server.
5203
5198
  */
5204
5199
  const GetPromptRequestSchema = RequestSchema.extend({
5205
- method: literalType("prompts/get"),
5200
+ method: literalType('prompts/get'),
5206
5201
  params: BaseRequestParamsSchema.extend({
5207
5202
  /**
5208
5203
  * The name of the prompt or prompt template.
@@ -5211,14 +5206,14 @@ const GetPromptRequestSchema = RequestSchema.extend({
5211
5206
  /**
5212
5207
  * Arguments to use for templating the prompt.
5213
5208
  */
5214
- arguments: optionalType(recordType(stringType())),
5215
- }),
5209
+ arguments: optionalType(recordType(stringType()))
5210
+ })
5216
5211
  });
5217
5212
  /**
5218
5213
  * Text provided to or from an LLM.
5219
5214
  */
5220
5215
  const TextContentSchema = objectType({
5221
- type: literalType("text"),
5216
+ type: literalType('text'),
5222
5217
  /**
5223
5218
  * The text content of the message.
5224
5219
  */
@@ -5227,14 +5222,14 @@ const TextContentSchema = objectType({
5227
5222
  * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
5228
5223
  * for notes on _meta usage.
5229
5224
  */
5230
- _meta: optionalType(objectType({}).passthrough()),
5225
+ _meta: optionalType(objectType({}).passthrough())
5231
5226
  })
5232
5227
  .passthrough();
5233
5228
  /**
5234
5229
  * An image provided to or from an LLM.
5235
5230
  */
5236
5231
  const ImageContentSchema = objectType({
5237
- type: literalType("image"),
5232
+ type: literalType('image'),
5238
5233
  /**
5239
5234
  * The base64-encoded image data.
5240
5235
  */
@@ -5247,14 +5242,14 @@ const ImageContentSchema = objectType({
5247
5242
  * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
5248
5243
  * for notes on _meta usage.
5249
5244
  */
5250
- _meta: optionalType(objectType({}).passthrough()),
5245
+ _meta: optionalType(objectType({}).passthrough())
5251
5246
  })
5252
5247
  .passthrough();
5253
5248
  /**
5254
5249
  * An Audio provided to or from an LLM.
5255
5250
  */
5256
5251
  const AudioContentSchema = objectType({
5257
- type: literalType("audio"),
5252
+ type: literalType('audio'),
5258
5253
  /**
5259
5254
  * The base64-encoded audio data.
5260
5255
  */
@@ -5267,20 +5262,20 @@ const AudioContentSchema = objectType({
5267
5262
  * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
5268
5263
  * for notes on _meta usage.
5269
5264
  */
5270
- _meta: optionalType(objectType({}).passthrough()),
5265
+ _meta: optionalType(objectType({}).passthrough())
5271
5266
  })
5272
5267
  .passthrough();
5273
5268
  /**
5274
5269
  * The contents of a resource, embedded into a prompt or tool call result.
5275
5270
  */
5276
5271
  const EmbeddedResourceSchema = objectType({
5277
- type: literalType("resource"),
5272
+ type: literalType('resource'),
5278
5273
  resource: unionType([TextResourceContentsSchema, BlobResourceContentsSchema]),
5279
5274
  /**
5280
5275
  * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
5281
5276
  * for notes on _meta usage.
5282
5277
  */
5283
- _meta: optionalType(objectType({}).passthrough()),
5278
+ _meta: optionalType(objectType({}).passthrough())
5284
5279
  })
5285
5280
  .passthrough();
5286
5281
  /**
@@ -5289,7 +5284,7 @@ const EmbeddedResourceSchema = objectType({
5289
5284
  * Note: resource links returned by tools are not guaranteed to appear in the results of `resources/list` requests.
5290
5285
  */
5291
5286
  const ResourceLinkSchema = ResourceSchema.extend({
5292
- type: literalType("resource_link"),
5287
+ type: literalType('resource_link')
5293
5288
  });
5294
5289
  /**
5295
5290
  * A content block that can be used in prompts and tool results.
@@ -5299,14 +5294,14 @@ const ContentBlockSchema = unionType([
5299
5294
  ImageContentSchema,
5300
5295
  AudioContentSchema,
5301
5296
  ResourceLinkSchema,
5302
- EmbeddedResourceSchema,
5297
+ EmbeddedResourceSchema
5303
5298
  ]);
5304
5299
  /**
5305
5300
  * Describes a message returned as part of a prompt.
5306
5301
  */
5307
5302
  const PromptMessageSchema = objectType({
5308
- role: enumType(["user", "assistant"]),
5309
- content: ContentBlockSchema,
5303
+ role: enumType(['user', 'assistant']),
5304
+ content: ContentBlockSchema
5310
5305
  })
5311
5306
  .passthrough();
5312
5307
  /**
@@ -5317,13 +5312,13 @@ const GetPromptResultSchema = ResultSchema.extend({
5317
5312
  * An optional description for the prompt.
5318
5313
  */
5319
5314
  description: optionalType(stringType()),
5320
- messages: arrayType(PromptMessageSchema),
5315
+ messages: arrayType(PromptMessageSchema)
5321
5316
  });
5322
5317
  /**
5323
5318
  * An optional notification from the server to the client, informing it that the list of prompts it offers has changed. This may be issued by servers without any previous subscription from the client.
5324
5319
  */
5325
5320
  const PromptListChangedNotificationSchema = NotificationSchema.extend({
5326
- method: literalType("notifications/prompts/list_changed"),
5321
+ method: literalType('notifications/prompts/list_changed')
5327
5322
  });
5328
5323
  /* Tools */
5329
5324
  /**
@@ -5373,7 +5368,7 @@ const ToolAnnotationsSchema = objectType({
5373
5368
  *
5374
5369
  * Default: true
5375
5370
  */
5376
- openWorldHint: optionalType(booleanType()),
5371
+ openWorldHint: optionalType(booleanType())
5377
5372
  })
5378
5373
  .passthrough();
5379
5374
  /**
@@ -5388,9 +5383,9 @@ const ToolSchema = BaseMetadataSchema.extend({
5388
5383
  * A JSON Schema object defining the expected parameters for the tool.
5389
5384
  */
5390
5385
  inputSchema: objectType({
5391
- type: literalType("object"),
5386
+ type: literalType('object'),
5392
5387
  properties: optionalType(objectType({}).passthrough()),
5393
- required: optionalType(arrayType(stringType())),
5388
+ required: optionalType(arrayType(stringType()))
5394
5389
  })
5395
5390
  .passthrough(),
5396
5391
  /**
@@ -5398,36 +5393,32 @@ const ToolSchema = BaseMetadataSchema.extend({
5398
5393
  * the structuredContent field of a CallToolResult.
5399
5394
  */
5400
5395
  outputSchema: optionalType(objectType({
5401
- type: literalType("object"),
5396
+ type: literalType('object'),
5402
5397
  properties: optionalType(objectType({}).passthrough()),
5403
- required: optionalType(arrayType(stringType())),
5398
+ required: optionalType(arrayType(stringType()))
5404
5399
  })
5405
5400
  .passthrough()),
5406
5401
  /**
5407
5402
  * Optional additional tool information.
5408
5403
  */
5409
5404
  annotations: optionalType(ToolAnnotationsSchema),
5410
- /**
5411
- * An optional list of icons for this tool.
5412
- */
5413
- icons: optionalType(arrayType(IconSchema)),
5414
5405
  /**
5415
5406
  * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
5416
5407
  * for notes on _meta usage.
5417
5408
  */
5418
- _meta: optionalType(objectType({}).passthrough()),
5419
- });
5409
+ _meta: optionalType(objectType({}).passthrough())
5410
+ }).merge(IconsSchema);
5420
5411
  /**
5421
5412
  * Sent from the client to request a list of tools the server has.
5422
5413
  */
5423
5414
  const ListToolsRequestSchema = PaginatedRequestSchema.extend({
5424
- method: literalType("tools/list"),
5415
+ method: literalType('tools/list')
5425
5416
  });
5426
5417
  /**
5427
5418
  * The server's response to a tools/list request from the client.
5428
5419
  */
5429
5420
  const ListToolsResultSchema = PaginatedResultSchema.extend({
5430
- tools: arrayType(ToolSchema),
5421
+ tools: arrayType(ToolSchema)
5431
5422
  });
5432
5423
  /**
5433
5424
  * The server's response to a tool call.
@@ -5460,61 +5451,52 @@ const CallToolResultSchema = ResultSchema.extend({
5460
5451
  * server does not support tool calls, or any other exceptional conditions,
5461
5452
  * should be reported as an MCP error response.
5462
5453
  */
5463
- isError: optionalType(booleanType()),
5454
+ isError: optionalType(booleanType())
5464
5455
  });
5465
5456
  /**
5466
5457
  * CallToolResultSchema extended with backwards compatibility to protocol version 2024-10-07.
5467
5458
  */
5468
5459
  CallToolResultSchema.or(ResultSchema.extend({
5469
- toolResult: unknownType(),
5460
+ toolResult: unknownType()
5470
5461
  }));
5471
5462
  /**
5472
5463
  * Used by the client to invoke a tool provided by the server.
5473
5464
  */
5474
5465
  const CallToolRequestSchema = RequestSchema.extend({
5475
- method: literalType("tools/call"),
5466
+ method: literalType('tools/call'),
5476
5467
  params: BaseRequestParamsSchema.extend({
5477
5468
  name: stringType(),
5478
- arguments: optionalType(recordType(unknownType())),
5479
- }),
5469
+ arguments: optionalType(recordType(unknownType()))
5470
+ })
5480
5471
  });
5481
5472
  /**
5482
5473
  * An optional notification from the server to the client, informing it that the list of tools it offers has changed. This may be issued by servers without any previous subscription from the client.
5483
5474
  */
5484
5475
  const ToolListChangedNotificationSchema = NotificationSchema.extend({
5485
- method: literalType("notifications/tools/list_changed"),
5476
+ method: literalType('notifications/tools/list_changed')
5486
5477
  });
5487
5478
  /* Logging */
5488
5479
  /**
5489
5480
  * The severity of a log message.
5490
5481
  */
5491
- const LoggingLevelSchema = enumType([
5492
- "debug",
5493
- "info",
5494
- "notice",
5495
- "warning",
5496
- "error",
5497
- "critical",
5498
- "alert",
5499
- "emergency",
5500
- ]);
5482
+ const LoggingLevelSchema = enumType(['debug', 'info', 'notice', 'warning', 'error', 'critical', 'alert', 'emergency']);
5501
5483
  /**
5502
5484
  * A request from the client to the server, to enable or adjust logging.
5503
5485
  */
5504
5486
  const SetLevelRequestSchema = RequestSchema.extend({
5505
- method: literalType("logging/setLevel"),
5487
+ method: literalType('logging/setLevel'),
5506
5488
  params: BaseRequestParamsSchema.extend({
5507
5489
  /**
5508
5490
  * The level of logging that the client wants to receive from the server. The server should send all logs at this level and higher (i.e., more severe) to the client as notifications/logging/message.
5509
5491
  */
5510
- level: LoggingLevelSchema,
5511
- }),
5492
+ level: LoggingLevelSchema
5493
+ })
5512
5494
  });
5513
5495
  /**
5514
5496
  * Notification of a log message passed from server to client. If no logging/setLevel request has been sent from the client, the server MAY decide which messages to send automatically.
5515
5497
  */
5516
5498
  const LoggingMessageNotificationSchema = NotificationSchema.extend({
5517
- method: literalType("notifications/message"),
5499
+ method: literalType('notifications/message'),
5518
5500
  params: BaseNotificationParamsSchema.extend({
5519
5501
  /**
5520
5502
  * The severity of this log message.
@@ -5527,8 +5509,8 @@ const LoggingMessageNotificationSchema = NotificationSchema.extend({
5527
5509
  /**
5528
5510
  * The data to be logged, such as a string message or an object. Any JSON serializable type is allowed here.
5529
5511
  */
5530
- data: unknownType(),
5531
- }),
5512
+ data: unknownType()
5513
+ })
5532
5514
  });
5533
5515
  /* Sampling */
5534
5516
  /**
@@ -5538,7 +5520,7 @@ const ModelHintSchema = objectType({
5538
5520
  /**
5539
5521
  * A hint for a model name.
5540
5522
  */
5541
- name: stringType().optional(),
5523
+ name: stringType().optional()
5542
5524
  })
5543
5525
  .passthrough();
5544
5526
  /**
@@ -5560,22 +5542,22 @@ const ModelPreferencesSchema = objectType({
5560
5542
  /**
5561
5543
  * How much to prioritize intelligence and capabilities when selecting a model.
5562
5544
  */
5563
- intelligencePriority: optionalType(numberType().min(0).max(1)),
5545
+ intelligencePriority: optionalType(numberType().min(0).max(1))
5564
5546
  })
5565
5547
  .passthrough();
5566
5548
  /**
5567
5549
  * Describes a message issued to or received from an LLM API.
5568
5550
  */
5569
5551
  const SamplingMessageSchema = objectType({
5570
- role: enumType(["user", "assistant"]),
5571
- content: unionType([TextContentSchema, ImageContentSchema, AudioContentSchema]),
5552
+ role: enumType(['user', 'assistant']),
5553
+ content: unionType([TextContentSchema, ImageContentSchema, AudioContentSchema])
5572
5554
  })
5573
5555
  .passthrough();
5574
5556
  /**
5575
5557
  * A request from the server to sample an LLM via the client. The client has full discretion over which model to select. The client should also inform the user before beginning sampling, to allow them to inspect the request (human in the loop) and decide whether to approve it.
5576
5558
  */
5577
5559
  const CreateMessageRequestSchema = RequestSchema.extend({
5578
- method: literalType("sampling/createMessage"),
5560
+ method: literalType('sampling/createMessage'),
5579
5561
  params: BaseRequestParamsSchema.extend({
5580
5562
  messages: arrayType(SamplingMessageSchema),
5581
5563
  /**
@@ -5585,7 +5567,7 @@ const CreateMessageRequestSchema = RequestSchema.extend({
5585
5567
  /**
5586
5568
  * A request to include context from one or more MCP servers (including the caller), to be attached to the prompt. The client MAY ignore this request.
5587
5569
  */
5588
- includeContext: optionalType(enumType(["none", "thisServer", "allServers"])),
5570
+ includeContext: optionalType(enumType(['none', 'thisServer', 'allServers'])),
5589
5571
  temperature: optionalType(numberType()),
5590
5572
  /**
5591
5573
  * The maximum number of tokens to sample, as requested by the server. The client MAY choose to sample fewer tokens than requested.
@@ -5599,8 +5581,8 @@ const CreateMessageRequestSchema = RequestSchema.extend({
5599
5581
  /**
5600
5582
  * The server's preferences for which model to select.
5601
5583
  */
5602
- modelPreferences: optionalType(ModelPreferencesSchema),
5603
- }),
5584
+ modelPreferences: optionalType(ModelPreferencesSchema)
5585
+ })
5604
5586
  });
5605
5587
  /**
5606
5588
  * The client's response to a sampling/create_message request from the server. The client should inform the user before returning the sampled message, to allow them to inspect the response (human in the loop) and decide whether to allow the server to see it.
@@ -5613,74 +5595,65 @@ const CreateMessageResultSchema = ResultSchema.extend({
5613
5595
  /**
5614
5596
  * The reason why sampling stopped.
5615
5597
  */
5616
- stopReason: optionalType(enumType(["endTurn", "stopSequence", "maxTokens"]).or(stringType())),
5617
- role: enumType(["user", "assistant"]),
5618
- content: discriminatedUnionType("type", [
5619
- TextContentSchema,
5620
- ImageContentSchema,
5621
- AudioContentSchema
5622
- ]),
5598
+ stopReason: optionalType(enumType(['endTurn', 'stopSequence', 'maxTokens']).or(stringType())),
5599
+ role: enumType(['user', 'assistant']),
5600
+ content: discriminatedUnionType('type', [TextContentSchema, ImageContentSchema, AudioContentSchema])
5623
5601
  });
5624
5602
  /* Elicitation */
5625
5603
  /**
5626
5604
  * Primitive schema definition for boolean fields.
5627
5605
  */
5628
5606
  const BooleanSchemaSchema = objectType({
5629
- type: literalType("boolean"),
5607
+ type: literalType('boolean'),
5630
5608
  title: optionalType(stringType()),
5631
5609
  description: optionalType(stringType()),
5632
- default: optionalType(booleanType()),
5610
+ default: optionalType(booleanType())
5633
5611
  })
5634
5612
  .passthrough();
5635
5613
  /**
5636
5614
  * Primitive schema definition for string fields.
5637
5615
  */
5638
5616
  const StringSchemaSchema = objectType({
5639
- type: literalType("string"),
5617
+ type: literalType('string'),
5640
5618
  title: optionalType(stringType()),
5641
5619
  description: optionalType(stringType()),
5642
5620
  minLength: optionalType(numberType()),
5643
5621
  maxLength: optionalType(numberType()),
5644
- format: optionalType(enumType(["email", "uri", "date", "date-time"])),
5622
+ format: optionalType(enumType(['email', 'uri', 'date', 'date-time']))
5645
5623
  })
5646
5624
  .passthrough();
5647
5625
  /**
5648
5626
  * Primitive schema definition for number fields.
5649
5627
  */
5650
5628
  const NumberSchemaSchema = objectType({
5651
- type: enumType(["number", "integer"]),
5629
+ type: enumType(['number', 'integer']),
5652
5630
  title: optionalType(stringType()),
5653
5631
  description: optionalType(stringType()),
5654
5632
  minimum: optionalType(numberType()),
5655
- maximum: optionalType(numberType()),
5633
+ maximum: optionalType(numberType())
5656
5634
  })
5657
5635
  .passthrough();
5658
5636
  /**
5659
5637
  * Primitive schema definition for enum fields.
5660
5638
  */
5661
5639
  const EnumSchemaSchema = objectType({
5662
- type: literalType("string"),
5640
+ type: literalType('string'),
5663
5641
  title: optionalType(stringType()),
5664
5642
  description: optionalType(stringType()),
5665
5643
  enum: arrayType(stringType()),
5666
- enumNames: optionalType(arrayType(stringType())),
5644
+ enumNames: optionalType(arrayType(stringType()))
5667
5645
  })
5668
5646
  .passthrough();
5669
5647
  /**
5670
5648
  * Union of all primitive schema definitions.
5671
5649
  */
5672
- const PrimitiveSchemaDefinitionSchema = unionType([
5673
- BooleanSchemaSchema,
5674
- StringSchemaSchema,
5675
- NumberSchemaSchema,
5676
- EnumSchemaSchema,
5677
- ]);
5650
+ const PrimitiveSchemaDefinitionSchema = unionType([BooleanSchemaSchema, StringSchemaSchema, NumberSchemaSchema, EnumSchemaSchema]);
5678
5651
  /**
5679
5652
  * A request from the server to elicit user input via the client.
5680
5653
  * The client should present the message and form fields to the user.
5681
5654
  */
5682
5655
  const ElicitRequestSchema = RequestSchema.extend({
5683
- method: literalType("elicitation/create"),
5656
+ method: literalType('elicitation/create'),
5684
5657
  params: BaseRequestParamsSchema.extend({
5685
5658
  /**
5686
5659
  * The message to present to the user.
@@ -5690,12 +5663,12 @@ const ElicitRequestSchema = RequestSchema.extend({
5690
5663
  * The schema for the requested user input.
5691
5664
  */
5692
5665
  requestedSchema: objectType({
5693
- type: literalType("object"),
5666
+ type: literalType('object'),
5694
5667
  properties: recordType(stringType(), PrimitiveSchemaDefinitionSchema),
5695
- required: optionalType(arrayType(stringType())),
5668
+ required: optionalType(arrayType(stringType()))
5696
5669
  })
5697
- .passthrough(),
5698
- }),
5670
+ .passthrough()
5671
+ })
5699
5672
  });
5700
5673
  /**
5701
5674
  * The client's response to an elicitation/create request from the server.
@@ -5704,40 +5677,40 @@ const ElicitResultSchema = ResultSchema.extend({
5704
5677
  /**
5705
5678
  * The user's response action.
5706
5679
  */
5707
- action: enumType(["accept", "decline", "cancel"]),
5680
+ action: enumType(['accept', 'decline', 'cancel']),
5708
5681
  /**
5709
5682
  * The collected user input content (only present if action is "accept").
5710
5683
  */
5711
- content: optionalType(recordType(stringType(), unknownType())),
5684
+ content: optionalType(recordType(stringType(), unknownType()))
5712
5685
  });
5713
5686
  /* Autocomplete */
5714
5687
  /**
5715
5688
  * A reference to a resource or resource template definition.
5716
5689
  */
5717
5690
  const ResourceTemplateReferenceSchema = objectType({
5718
- type: literalType("ref/resource"),
5691
+ type: literalType('ref/resource'),
5719
5692
  /**
5720
5693
  * The URI or URI template of the resource.
5721
5694
  */
5722
- uri: stringType(),
5695
+ uri: stringType()
5723
5696
  })
5724
5697
  .passthrough();
5725
5698
  /**
5726
5699
  * Identifies a prompt.
5727
5700
  */
5728
5701
  const PromptReferenceSchema = objectType({
5729
- type: literalType("ref/prompt"),
5702
+ type: literalType('ref/prompt'),
5730
5703
  /**
5731
5704
  * The name of the prompt or prompt template
5732
5705
  */
5733
- name: stringType(),
5706
+ name: stringType()
5734
5707
  })
5735
5708
  .passthrough();
5736
5709
  /**
5737
5710
  * A request from the client to the server, to ask for completion options.
5738
5711
  */
5739
5712
  const CompleteRequestSchema = RequestSchema.extend({
5740
- method: literalType("completion/complete"),
5713
+ method: literalType('completion/complete'),
5741
5714
  params: BaseRequestParamsSchema.extend({
5742
5715
  ref: unionType([PromptReferenceSchema, ResourceTemplateReferenceSchema]),
5743
5716
  /**
@@ -5751,16 +5724,16 @@ const CompleteRequestSchema = RequestSchema.extend({
5751
5724
  /**
5752
5725
  * The value of the argument to use for completion matching.
5753
5726
  */
5754
- value: stringType(),
5727
+ value: stringType()
5755
5728
  })
5756
5729
  .passthrough(),
5757
5730
  context: optionalType(objectType({
5758
5731
  /**
5759
5732
  * Previously-resolved variables in a URI template or prompt.
5760
5733
  */
5761
- arguments: optionalType(recordType(stringType(), stringType())),
5762
- })),
5763
- }),
5734
+ arguments: optionalType(recordType(stringType(), stringType()))
5735
+ }))
5736
+ })
5764
5737
  });
5765
5738
  /**
5766
5739
  * The server's response to a completion/complete request
@@ -5778,9 +5751,9 @@ const CompleteResultSchema = ResultSchema.extend({
5778
5751
  /**
5779
5752
  * Indicates whether there are additional completion options beyond those provided in the current response, even if the exact total is unknown.
5780
5753
  */
5781
- hasMore: optionalType(booleanType()),
5754
+ hasMore: optionalType(booleanType())
5782
5755
  })
5783
- .passthrough(),
5756
+ .passthrough()
5784
5757
  });
5785
5758
  /* Roots */
5786
5759
  /**
@@ -5790,7 +5763,7 @@ const RootSchema = objectType({
5790
5763
  /**
5791
5764
  * The URI identifying the root. This *must* start with file:// for now.
5792
5765
  */
5793
- uri: stringType().startsWith("file://"),
5766
+ uri: stringType().startsWith('file://'),
5794
5767
  /**
5795
5768
  * An optional name for the root.
5796
5769
  */
@@ -5799,26 +5772,26 @@ const RootSchema = objectType({
5799
5772
  * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
5800
5773
  * for notes on _meta usage.
5801
5774
  */
5802
- _meta: optionalType(objectType({}).passthrough()),
5775
+ _meta: optionalType(objectType({}).passthrough())
5803
5776
  })
5804
5777
  .passthrough();
5805
5778
  /**
5806
5779
  * Sent from the server to request a list of root URIs from the client.
5807
5780
  */
5808
5781
  const ListRootsRequestSchema = RequestSchema.extend({
5809
- method: literalType("roots/list"),
5782
+ method: literalType('roots/list')
5810
5783
  });
5811
5784
  /**
5812
5785
  * The client's response to a roots/list request from the server.
5813
5786
  */
5814
5787
  const ListRootsResultSchema = ResultSchema.extend({
5815
- roots: arrayType(RootSchema),
5788
+ roots: arrayType(RootSchema)
5816
5789
  });
5817
5790
  /**
5818
5791
  * A notification from the client to the server, informing it that the list of roots has changed.
5819
5792
  */
5820
5793
  const RootsListChangedNotificationSchema = NotificationSchema.extend({
5821
- method: literalType("notifications/roots/list_changed"),
5794
+ method: literalType('notifications/roots/list_changed')
5822
5795
  });
5823
5796
  /* Client messages */
5824
5797
  unionType([
@@ -5834,27 +5807,17 @@ unionType([
5834
5807
  SubscribeRequestSchema,
5835
5808
  UnsubscribeRequestSchema,
5836
5809
  CallToolRequestSchema,
5837
- ListToolsRequestSchema,
5810
+ ListToolsRequestSchema
5838
5811
  ]);
5839
5812
  unionType([
5840
5813
  CancelledNotificationSchema,
5841
5814
  ProgressNotificationSchema,
5842
5815
  InitializedNotificationSchema,
5843
- RootsListChangedNotificationSchema,
5844
- ]);
5845
- unionType([
5846
- EmptyResultSchema,
5847
- CreateMessageResultSchema,
5848
- ElicitResultSchema,
5849
- ListRootsResultSchema,
5816
+ RootsListChangedNotificationSchema
5850
5817
  ]);
5818
+ unionType([EmptyResultSchema, CreateMessageResultSchema, ElicitResultSchema, ListRootsResultSchema]);
5851
5819
  /* Server messages */
5852
- unionType([
5853
- PingRequestSchema,
5854
- CreateMessageRequestSchema,
5855
- ElicitRequestSchema,
5856
- ListRootsRequestSchema,
5857
- ]);
5820
+ unionType([PingRequestSchema, CreateMessageRequestSchema, ElicitRequestSchema, ListRootsRequestSchema]);
5858
5821
  unionType([
5859
5822
  CancelledNotificationSchema,
5860
5823
  ProgressNotificationSchema,
@@ -5862,7 +5825,7 @@ unionType([
5862
5825
  ResourceUpdatedNotificationSchema,
5863
5826
  ResourceListChangedNotificationSchema,
5864
5827
  ToolListChangedNotificationSchema,
5865
- PromptListChangedNotificationSchema,
5828
+ PromptListChangedNotificationSchema
5866
5829
  ]);
5867
5830
  unionType([
5868
5831
  EmptyResultSchema,
@@ -5874,14 +5837,14 @@ unionType([
5874
5837
  ListResourceTemplatesResultSchema,
5875
5838
  ReadResourceResultSchema,
5876
5839
  CallToolResultSchema,
5877
- ListToolsResultSchema,
5840
+ ListToolsResultSchema
5878
5841
  ]);
5879
5842
  class McpError extends Error {
5880
5843
  constructor(code, message, data) {
5881
5844
  super(`MCP error ${code}: ${message}`);
5882
5845
  this.code = code;
5883
5846
  this.data = data;
5884
- this.name = "McpError";
5847
+ this.name = 'McpError';
5885
5848
  }
5886
5849
  }
5887
5850
 
@@ -5896,11 +5859,11 @@ class ReadBuffer {
5896
5859
  if (!this._buffer) {
5897
5860
  return null;
5898
5861
  }
5899
- const index = this._buffer.indexOf("\n");
5862
+ const index = this._buffer.indexOf('\n');
5900
5863
  if (index === -1) {
5901
5864
  return null;
5902
5865
  }
5903
- const line = this._buffer.toString("utf8", 0, index).replace(/\r$/, '');
5866
+ const line = this._buffer.toString('utf8', 0, index).replace(/\r$/, '');
5904
5867
  this._buffer = this._buffer.subarray(index + 1);
5905
5868
  return deserializeMessage(line);
5906
5869
  }
@@ -5912,7 +5875,7 @@ function deserializeMessage(line) {
5912
5875
  return JSONRPCMessageSchema.parse(JSON.parse(line));
5913
5876
  }
5914
5877
  function serializeMessage(message) {
5915
- return JSON.stringify(message) + "\n";
5878
+ return JSON.stringify(message) + '\n';
5916
5879
  }
5917
5880
 
5918
5881
  /**
@@ -5941,11 +5904,11 @@ class StdioServerTransport {
5941
5904
  */
5942
5905
  async start() {
5943
5906
  if (this._started) {
5944
- throw new Error("StdioServerTransport already started! If using Server class, note that connect() calls start() automatically.");
5907
+ throw new Error('StdioServerTransport already started! If using Server class, note that connect() calls start() automatically.');
5945
5908
  }
5946
5909
  this._started = true;
5947
- this._stdin.on("data", this._ondata);
5948
- this._stdin.on("error", this._onerror);
5910
+ this._stdin.on('data', this._ondata);
5911
+ this._stdin.on('error', this._onerror);
5949
5912
  }
5950
5913
  processReadBuffer() {
5951
5914
  var _a, _b;
@@ -5965,8 +5928,8 @@ class StdioServerTransport {
5965
5928
  async close() {
5966
5929
  var _a;
5967
5930
  // Remove our event listeners first
5968
- this._stdin.off("data", this._ondata);
5969
- this._stdin.off("error", this._onerror);
5931
+ this._stdin.off('data', this._ondata);
5932
+ this._stdin.off('error', this._onerror);
5970
5933
  // Check if we were the only data listener
5971
5934
  const remainingDataListeners = this._stdin.listenerCount('data');
5972
5935
  if (remainingDataListeners === 0) {
@@ -5979,13 +5942,13 @@ class StdioServerTransport {
5979
5942
  (_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this);
5980
5943
  }
5981
5944
  send(message) {
5982
- return new Promise((resolve) => {
5945
+ return new Promise(resolve => {
5983
5946
  const json = serializeMessage(message);
5984
5947
  if (this._stdout.write(json)) {
5985
5948
  resolve();
5986
5949
  }
5987
5950
  else {
5988
- this._stdout.once("drain", resolve);
5951
+ this._stdout.once('drain', resolve);
5989
5952
  }
5990
5953
  });
5991
5954
  }
@@ -6010,16 +5973,16 @@ class Protocol {
6010
5973
  this._progressHandlers = new Map();
6011
5974
  this._timeoutInfo = new Map();
6012
5975
  this._pendingDebouncedNotifications = new Set();
6013
- this.setNotificationHandler(CancelledNotificationSchema, (notification) => {
5976
+ this.setNotificationHandler(CancelledNotificationSchema, notification => {
6014
5977
  const controller = this._requestHandlerAbortControllers.get(notification.params.requestId);
6015
5978
  controller === null || controller === void 0 ? void 0 : controller.abort(notification.params.reason);
6016
5979
  });
6017
- this.setNotificationHandler(ProgressNotificationSchema, (notification) => {
5980
+ this.setNotificationHandler(ProgressNotificationSchema, notification => {
6018
5981
  this._onprogress(notification);
6019
5982
  });
6020
5983
  this.setRequestHandler(PingRequestSchema,
6021
5984
  // Automatic pong by default.
6022
- (_request) => ({}));
5985
+ _request => ({}));
6023
5986
  }
6024
5987
  _setupTimeout(messageId, timeout, maxTotalTimeout, onTimeout, resetTimeoutOnProgress = false) {
6025
5988
  this._timeoutInfo.set(messageId, {
@@ -6038,7 +6001,10 @@ class Protocol {
6038
6001
  const totalElapsed = Date.now() - info.startTime;
6039
6002
  if (info.maxTotalTimeout && totalElapsed >= info.maxTotalTimeout) {
6040
6003
  this._timeoutInfo.delete(messageId);
6041
- throw new McpError(ErrorCode.RequestTimeout, "Maximum total timeout exceeded", { maxTotalTimeout: info.maxTotalTimeout, totalElapsed });
6004
+ throw new McpError(ErrorCode.RequestTimeout, 'Maximum total timeout exceeded', {
6005
+ maxTotalTimeout: info.maxTotalTimeout,
6006
+ totalElapsed
6007
+ });
6042
6008
  }
6043
6009
  clearTimeout(info.timeoutId);
6044
6010
  info.timeoutId = setTimeout(info.onTimeout, info.timeout);
@@ -6095,7 +6061,7 @@ class Protocol {
6095
6061
  this._pendingDebouncedNotifications.clear();
6096
6062
  this._transport = undefined;
6097
6063
  (_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this);
6098
- const error = new McpError(ErrorCode.ConnectionClosed, "Connection closed");
6064
+ const error = new McpError(ErrorCode.ConnectionClosed, 'Connection closed');
6099
6065
  for (const handler of responseHandlers.values()) {
6100
6066
  handler(error);
6101
6067
  }
@@ -6114,7 +6080,7 @@ class Protocol {
6114
6080
  // Starting with Promise.resolve() puts any synchronous errors into the monad as well.
6115
6081
  Promise.resolve()
6116
6082
  .then(() => handler(notification))
6117
- .catch((error) => this._onerror(new Error(`Uncaught error in notification handler: ${error}`)));
6083
+ .catch(error => this._onerror(new Error(`Uncaught error in notification handler: ${error}`)));
6118
6084
  }
6119
6085
  _onrequest(request, extra) {
6120
6086
  var _a, _b;
@@ -6123,13 +6089,13 @@ class Protocol {
6123
6089
  const capturedTransport = this._transport;
6124
6090
  if (handler === undefined) {
6125
6091
  capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.send({
6126
- jsonrpc: "2.0",
6092
+ jsonrpc: '2.0',
6127
6093
  id: request.id,
6128
6094
  error: {
6129
6095
  code: ErrorCode.MethodNotFound,
6130
- message: "Method not found",
6131
- },
6132
- }).catch((error) => this._onerror(new Error(`Failed to send an error response: ${error}`)));
6096
+ message: 'Method not found'
6097
+ }
6098
+ }).catch(error => this._onerror(new Error(`Failed to send an error response: ${error}`)));
6133
6099
  return;
6134
6100
  }
6135
6101
  const abortController = new AbortController();
@@ -6138,7 +6104,7 @@ class Protocol {
6138
6104
  signal: abortController.signal,
6139
6105
  sessionId: capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.sessionId,
6140
6106
  _meta: (_b = request.params) === null || _b === void 0 ? void 0 : _b._meta,
6141
- sendNotification: (notification) => this.notification(notification, { relatedRequestId: request.id }),
6107
+ sendNotification: notification => this.notification(notification, { relatedRequestId: request.id }),
6142
6108
  sendRequest: (r, resultSchema, options) => this.request(r, resultSchema, { ...options, relatedRequestId: request.id }),
6143
6109
  authInfo: extra === null || extra === void 0 ? void 0 : extra.authInfo,
6144
6110
  requestId: request.id,
@@ -6147,32 +6113,30 @@ class Protocol {
6147
6113
  // Starting with Promise.resolve() puts any synchronous errors into the monad as well.
6148
6114
  Promise.resolve()
6149
6115
  .then(() => handler(request, fullExtra))
6150
- .then((result) => {
6116
+ .then(result => {
6151
6117
  if (abortController.signal.aborted) {
6152
6118
  return;
6153
6119
  }
6154
6120
  return capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.send({
6155
6121
  result,
6156
- jsonrpc: "2.0",
6157
- id: request.id,
6122
+ jsonrpc: '2.0',
6123
+ id: request.id
6158
6124
  });
6159
- }, (error) => {
6125
+ }, error => {
6160
6126
  var _a;
6161
6127
  if (abortController.signal.aborted) {
6162
6128
  return;
6163
6129
  }
6164
6130
  return capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.send({
6165
- jsonrpc: "2.0",
6131
+ jsonrpc: '2.0',
6166
6132
  id: request.id,
6167
6133
  error: {
6168
- code: Number.isSafeInteger(error["code"])
6169
- ? error["code"]
6170
- : ErrorCode.InternalError,
6171
- message: (_a = error.message) !== null && _a !== void 0 ? _a : "Internal error",
6172
- },
6134
+ code: Number.isSafeInteger(error['code']) ? error['code'] : ErrorCode.InternalError,
6135
+ message: (_a = error.message) !== null && _a !== void 0 ? _a : 'Internal error'
6136
+ }
6173
6137
  });
6174
6138
  })
6175
- .catch((error) => this._onerror(new Error(`Failed to send response: ${error}`)))
6139
+ .catch(error => this._onerror(new Error(`Failed to send response: ${error}`)))
6176
6140
  .finally(() => {
6177
6141
  this._requestHandlerAbortControllers.delete(request.id);
6178
6142
  });
@@ -6236,7 +6200,7 @@ class Protocol {
6236
6200
  return new Promise((resolve, reject) => {
6237
6201
  var _a, _b, _c, _d, _e, _f;
6238
6202
  if (!this._transport) {
6239
- reject(new Error("Not connected"));
6203
+ reject(new Error('Not connected'));
6240
6204
  return;
6241
6205
  }
6242
6206
  if (((_a = this._options) === null || _a === void 0 ? void 0 : _a.enforceStrictCapabilities) === true) {
@@ -6246,8 +6210,8 @@ class Protocol {
6246
6210
  const messageId = this._requestMessageId++;
6247
6211
  const jsonrpcRequest = {
6248
6212
  ...request,
6249
- jsonrpc: "2.0",
6250
- id: messageId,
6213
+ jsonrpc: '2.0',
6214
+ id: messageId
6251
6215
  };
6252
6216
  if (options === null || options === void 0 ? void 0 : options.onprogress) {
6253
6217
  this._progressHandlers.set(messageId, options.onprogress);
@@ -6256,7 +6220,7 @@ class Protocol {
6256
6220
  _meta: {
6257
6221
  ...(((_c = request.params) === null || _c === void 0 ? void 0 : _c._meta) || {}),
6258
6222
  progressToken: messageId
6259
- },
6223
+ }
6260
6224
  };
6261
6225
  }
6262
6226
  const cancel = (reason) => {
@@ -6265,16 +6229,16 @@ class Protocol {
6265
6229
  this._progressHandlers.delete(messageId);
6266
6230
  this._cleanupTimeout(messageId);
6267
6231
  (_a = this._transport) === null || _a === void 0 ? void 0 : _a.send({
6268
- jsonrpc: "2.0",
6269
- method: "notifications/cancelled",
6232
+ jsonrpc: '2.0',
6233
+ method: 'notifications/cancelled',
6270
6234
  params: {
6271
6235
  requestId: messageId,
6272
- reason: String(reason),
6273
- },
6274
- }, { relatedRequestId, resumptionToken, onresumptiontoken }).catch((error) => this._onerror(new Error(`Failed to send cancellation: ${error}`)));
6236
+ reason: String(reason)
6237
+ }
6238
+ }, { relatedRequestId, resumptionToken, onresumptiontoken }).catch(error => this._onerror(new Error(`Failed to send cancellation: ${error}`)));
6275
6239
  reject(reason);
6276
6240
  };
6277
- this._responseHandlers.set(messageId, (response) => {
6241
+ this._responseHandlers.set(messageId, response => {
6278
6242
  var _a;
6279
6243
  if ((_a = options === null || options === void 0 ? void 0 : options.signal) === null || _a === void 0 ? void 0 : _a.aborted) {
6280
6244
  return;
@@ -6290,14 +6254,14 @@ class Protocol {
6290
6254
  reject(error);
6291
6255
  }
6292
6256
  });
6293
- (_d = options === null || options === void 0 ? void 0 : options.signal) === null || _d === void 0 ? void 0 : _d.addEventListener("abort", () => {
6257
+ (_d = options === null || options === void 0 ? void 0 : options.signal) === null || _d === void 0 ? void 0 : _d.addEventListener('abort', () => {
6294
6258
  var _a;
6295
6259
  cancel((_a = options === null || options === void 0 ? void 0 : options.signal) === null || _a === void 0 ? void 0 : _a.reason);
6296
6260
  });
6297
6261
  const timeout = (_e = options === null || options === void 0 ? void 0 : options.timeout) !== null && _e !== void 0 ? _e : DEFAULT_REQUEST_TIMEOUT_MSEC;
6298
- const timeoutHandler = () => cancel(new McpError(ErrorCode.RequestTimeout, "Request timed out", { timeout }));
6262
+ const timeoutHandler = () => cancel(new McpError(ErrorCode.RequestTimeout, 'Request timed out', { timeout }));
6299
6263
  this._setupTimeout(messageId, timeout, options === null || options === void 0 ? void 0 : options.maxTotalTimeout, timeoutHandler, (_f = options === null || options === void 0 ? void 0 : options.resetTimeoutOnProgress) !== null && _f !== void 0 ? _f : false);
6300
- this._transport.send(jsonrpcRequest, { relatedRequestId, resumptionToken, onresumptiontoken }).catch((error) => {
6264
+ this._transport.send(jsonrpcRequest, { relatedRequestId, resumptionToken, onresumptiontoken }).catch(error => {
6301
6265
  this._cleanupTimeout(messageId);
6302
6266
  reject(error);
6303
6267
  });
@@ -6309,15 +6273,13 @@ class Protocol {
6309
6273
  async notification(notification, options) {
6310
6274
  var _a, _b;
6311
6275
  if (!this._transport) {
6312
- throw new Error("Not connected");
6276
+ throw new Error('Not connected');
6313
6277
  }
6314
6278
  this.assertNotificationCapability(notification.method);
6315
6279
  const debouncedMethods = (_b = (_a = this._options) === null || _a === void 0 ? void 0 : _a.debouncedNotificationMethods) !== null && _b !== void 0 ? _b : [];
6316
6280
  // A notification can only be debounced if it's in the list AND it's "simple"
6317
6281
  // (i.e., has no parameters and no related request ID that could be lost).
6318
- const canDebounce = debouncedMethods.includes(notification.method)
6319
- && !notification.params
6320
- && !(options === null || options === void 0 ? void 0 : options.relatedRequestId);
6282
+ const canDebounce = debouncedMethods.includes(notification.method) && !notification.params && !(options === null || options === void 0 ? void 0 : options.relatedRequestId);
6321
6283
  if (canDebounce) {
6322
6284
  // If a notification of this type is already scheduled, do nothing.
6323
6285
  if (this._pendingDebouncedNotifications.has(notification.method)) {
@@ -6337,7 +6299,7 @@ class Protocol {
6337
6299
  }
6338
6300
  const jsonrpcNotification = {
6339
6301
  ...notification,
6340
- jsonrpc: "2.0",
6302
+ jsonrpc: '2.0'
6341
6303
  };
6342
6304
  // Send the notification, but don't await it here to avoid blocking.
6343
6305
  // Handle potential errors with a .catch().
@@ -6348,7 +6310,7 @@ class Protocol {
6348
6310
  }
6349
6311
  const jsonrpcNotification = {
6350
6312
  ...notification,
6351
- jsonrpc: "2.0",
6313
+ jsonrpc: '2.0'
6352
6314
  };
6353
6315
  await this._transport.send(jsonrpcNotification, options);
6354
6316
  }
@@ -6384,7 +6346,7 @@ class Protocol {
6384
6346
  * Note that this will replace any previous notification handler for the same method.
6385
6347
  */
6386
6348
  setNotificationHandler(notificationSchema, handler) {
6387
- this._notificationHandlers.set(notificationSchema.shape.method.value, (notification) => Promise.resolve(handler(notificationSchema.parse(notification))));
6349
+ this._notificationHandlers.set(notificationSchema.shape.method.value, notification => Promise.resolve(handler(notificationSchema.parse(notification))));
6388
6350
  }
6389
6351
  /**
6390
6352
  * Removes the notification handler for the given method.
@@ -6395,7 +6357,7 @@ class Protocol {
6395
6357
  }
6396
6358
  function mergeCapabilities(base, additional) {
6397
6359
  return Object.entries(additional).reduce((acc, [key, value]) => {
6398
- if (value && typeof value === "object") {
6360
+ if (value && typeof value === 'object') {
6399
6361
  acc[key] = acc[key] ? { ...acc[key], ...value } : value;
6400
6362
  }
6401
6363
  else {
@@ -13948,13 +13910,11 @@ class Server extends Protocol {
13948
13910
  // Is a message with the given level ignored in the log level set for the given session id?
13949
13911
  this.isMessageIgnored = (level, sessionId) => {
13950
13912
  const currentLevel = this._loggingLevels.get(sessionId);
13951
- return (currentLevel)
13952
- ? this.LOG_LEVEL_SEVERITY.get(level) < this.LOG_LEVEL_SEVERITY.get(currentLevel)
13953
- : false;
13913
+ return currentLevel ? this.LOG_LEVEL_SEVERITY.get(level) < this.LOG_LEVEL_SEVERITY.get(currentLevel) : false;
13954
13914
  };
13955
13915
  this._capabilities = (_a = options === null || options === void 0 ? void 0 : options.capabilities) !== null && _a !== void 0 ? _a : {};
13956
13916
  this._instructions = options === null || options === void 0 ? void 0 : options.instructions;
13957
- this.setRequestHandler(InitializeRequestSchema, (request) => this._oninitialize(request));
13917
+ this.setRequestHandler(InitializeRequestSchema, request => this._oninitialize(request));
13958
13918
  this.setNotificationHandler(InitializedNotificationSchema, () => { var _a; return (_a = this.oninitialized) === null || _a === void 0 ? void 0 : _a.call(this); });
13959
13919
  if (this._capabilities.logging) {
13960
13920
  this.setRequestHandler(SetLevelRequestSchema, async (request, extra) => {
@@ -13976,24 +13936,24 @@ class Server extends Protocol {
13976
13936
  */
13977
13937
  registerCapabilities(capabilities) {
13978
13938
  if (this.transport) {
13979
- throw new Error("Cannot register capabilities after connecting to transport");
13939
+ throw new Error('Cannot register capabilities after connecting to transport');
13980
13940
  }
13981
13941
  this._capabilities = mergeCapabilities(this._capabilities, capabilities);
13982
13942
  }
13983
13943
  assertCapabilityForMethod(method) {
13984
13944
  var _a, _b, _c;
13985
13945
  switch (method) {
13986
- case "sampling/createMessage":
13946
+ case 'sampling/createMessage':
13987
13947
  if (!((_a = this._clientCapabilities) === null || _a === void 0 ? void 0 : _a.sampling)) {
13988
13948
  throw new Error(`Client does not support sampling (required for ${method})`);
13989
13949
  }
13990
13950
  break;
13991
- case "elicitation/create":
13951
+ case 'elicitation/create':
13992
13952
  if (!((_b = this._clientCapabilities) === null || _b === void 0 ? void 0 : _b.elicitation)) {
13993
13953
  throw new Error(`Client does not support elicitation (required for ${method})`);
13994
13954
  }
13995
13955
  break;
13996
- case "roots/list":
13956
+ case 'roots/list':
13997
13957
  if (!((_c = this._clientCapabilities) === null || _c === void 0 ? void 0 : _c.roots)) {
13998
13958
  throw new Error(`Client does not support listing roots (required for ${method})`);
13999
13959
  }
@@ -14002,23 +13962,23 @@ class Server extends Protocol {
14002
13962
  }
14003
13963
  assertNotificationCapability(method) {
14004
13964
  switch (method) {
14005
- case "notifications/message":
13965
+ case 'notifications/message':
14006
13966
  if (!this._capabilities.logging) {
14007
13967
  throw new Error(`Server does not support logging (required for ${method})`);
14008
13968
  }
14009
13969
  break;
14010
- case "notifications/resources/updated":
14011
- case "notifications/resources/list_changed":
13970
+ case 'notifications/resources/updated':
13971
+ case 'notifications/resources/list_changed':
14012
13972
  if (!this._capabilities.resources) {
14013
13973
  throw new Error(`Server does not support notifying about resources (required for ${method})`);
14014
13974
  }
14015
13975
  break;
14016
- case "notifications/tools/list_changed":
13976
+ case 'notifications/tools/list_changed':
14017
13977
  if (!this._capabilities.tools) {
14018
13978
  throw new Error(`Server does not support notifying of tool list changes (required for ${method})`);
14019
13979
  }
14020
13980
  break;
14021
- case "notifications/prompts/list_changed":
13981
+ case 'notifications/prompts/list_changed':
14022
13982
  if (!this._capabilities.prompts) {
14023
13983
  throw new Error(`Server does not support notifying of prompt list changes (required for ${method})`);
14024
13984
  }
@@ -14027,31 +13987,31 @@ class Server extends Protocol {
14027
13987
  }
14028
13988
  assertRequestHandlerCapability(method) {
14029
13989
  switch (method) {
14030
- case "sampling/createMessage":
13990
+ case 'sampling/createMessage':
14031
13991
  if (!this._capabilities.sampling) {
14032
13992
  throw new Error(`Server does not support sampling (required for ${method})`);
14033
13993
  }
14034
13994
  break;
14035
- case "logging/setLevel":
13995
+ case 'logging/setLevel':
14036
13996
  if (!this._capabilities.logging) {
14037
13997
  throw new Error(`Server does not support logging (required for ${method})`);
14038
13998
  }
14039
13999
  break;
14040
- case "prompts/get":
14041
- case "prompts/list":
14000
+ case 'prompts/get':
14001
+ case 'prompts/list':
14042
14002
  if (!this._capabilities.prompts) {
14043
14003
  throw new Error(`Server does not support prompts (required for ${method})`);
14044
14004
  }
14045
14005
  break;
14046
- case "resources/list":
14047
- case "resources/templates/list":
14048
- case "resources/read":
14006
+ case 'resources/list':
14007
+ case 'resources/templates/list':
14008
+ case 'resources/read':
14049
14009
  if (!this._capabilities.resources) {
14050
14010
  throw new Error(`Server does not support resources (required for ${method})`);
14051
14011
  }
14052
14012
  break;
14053
- case "tools/call":
14054
- case "tools/list":
14013
+ case 'tools/call':
14014
+ case 'tools/list':
14055
14015
  if (!this._capabilities.tools) {
14056
14016
  throw new Error(`Server does not support tools (required for ${method})`);
14057
14017
  }
@@ -14062,14 +14022,12 @@ class Server extends Protocol {
14062
14022
  const requestedVersion = request.params.protocolVersion;
14063
14023
  this._clientCapabilities = request.params.capabilities;
14064
14024
  this._clientVersion = request.params.clientInfo;
14065
- const protocolVersion = SUPPORTED_PROTOCOL_VERSIONS.includes(requestedVersion)
14066
- ? requestedVersion
14067
- : LATEST_PROTOCOL_VERSION;
14025
+ const protocolVersion = SUPPORTED_PROTOCOL_VERSIONS.includes(requestedVersion) ? requestedVersion : LATEST_PROTOCOL_VERSION;
14068
14026
  return {
14069
14027
  protocolVersion,
14070
14028
  capabilities: this.getCapabilities(),
14071
14029
  serverInfo: this._serverInfo,
14072
- ...(this._instructions && { instructions: this._instructions }),
14030
+ ...(this._instructions && { instructions: this._instructions })
14073
14031
  };
14074
14032
  }
14075
14033
  /**
@@ -14088,15 +14046,15 @@ class Server extends Protocol {
14088
14046
  return this._capabilities;
14089
14047
  }
14090
14048
  async ping() {
14091
- return this.request({ method: "ping" }, EmptyResultSchema);
14049
+ return this.request({ method: 'ping' }, EmptyResultSchema);
14092
14050
  }
14093
14051
  async createMessage(params, options) {
14094
- return this.request({ method: "sampling/createMessage", params }, CreateMessageResultSchema, options);
14052
+ return this.request({ method: 'sampling/createMessage', params }, CreateMessageResultSchema, options);
14095
14053
  }
14096
14054
  async elicitInput(params, options) {
14097
- const result = await this.request({ method: "elicitation/create", params }, ElicitResultSchema, options);
14055
+ const result = await this.request({ method: 'elicitation/create', params }, ElicitResultSchema, options);
14098
14056
  // Validate the response content against the requested schema if action is "accept"
14099
- if (result.action === "accept" && result.content) {
14057
+ if (result.action === 'accept' && result.content) {
14100
14058
  try {
14101
14059
  const ajv = new Ajv();
14102
14060
  const validate = ajv.compile(params.requestedSchema);
@@ -14115,7 +14073,7 @@ class Server extends Protocol {
14115
14073
  return result;
14116
14074
  }
14117
14075
  async listRoots(params, options) {
14118
- return this.request({ method: "roots/list", params }, ListRootsResultSchema, options);
14076
+ return this.request({ method: 'roots/list', params }, ListRootsResultSchema, options);
14119
14077
  }
14120
14078
  /**
14121
14079
  * Sends a logging message to the client, if connected.
@@ -14127,26 +14085,26 @@ class Server extends Protocol {
14127
14085
  async sendLoggingMessage(params, sessionId) {
14128
14086
  if (this._capabilities.logging) {
14129
14087
  if (!this.isMessageIgnored(params.level, sessionId)) {
14130
- return this.notification({ method: "notifications/message", params });
14088
+ return this.notification({ method: 'notifications/message', params });
14131
14089
  }
14132
14090
  }
14133
14091
  }
14134
14092
  async sendResourceUpdated(params) {
14135
14093
  return this.notification({
14136
- method: "notifications/resources/updated",
14137
- params,
14094
+ method: 'notifications/resources/updated',
14095
+ params
14138
14096
  });
14139
14097
  }
14140
14098
  async sendResourceListChanged() {
14141
14099
  return this.notification({
14142
- method: "notifications/resources/list_changed",
14100
+ method: 'notifications/resources/list_changed'
14143
14101
  });
14144
14102
  }
14145
14103
  async sendToolListChanged() {
14146
- return this.notification({ method: "notifications/tools/list_changed" });
14104
+ return this.notification({ method: 'notifications/tools/list_changed' });
14147
14105
  }
14148
14106
  async sendPromptListChanged() {
14149
- return this.notification({ method: "notifications/prompts/list_changed" });
14107
+ return this.notification({ method: 'notifications/prompts/list_changed' });
14150
14108
  }
14151
14109
  }
14152
14110
 
@@ -15516,7 +15474,7 @@ class Completable extends ZodType {
15516
15474
  return this._def.type._parse({
15517
15475
  data,
15518
15476
  path: ctx.path,
15519
- parent: ctx,
15477
+ parent: ctx
15520
15478
  });
15521
15479
  }
15522
15480
  unwrap() {
@@ -15528,7 +15486,7 @@ Completable.create = (type, params) => {
15528
15486
  type,
15529
15487
  typeName: McpZodTypeKind.Completable,
15530
15488
  complete: params.complete,
15531
- ...processCreateParams(params),
15489
+ ...processCreateParams(params)
15532
15490
  });
15533
15491
  };
15534
15492
  // Not sure why this isn't exported from Zod:
@@ -15545,13 +15503,13 @@ function processCreateParams(params) {
15545
15503
  const customMap = (iss, ctx) => {
15546
15504
  var _a, _b;
15547
15505
  const { message } = params;
15548
- if (iss.code === "invalid_enum_value") {
15506
+ if (iss.code === 'invalid_enum_value') {
15549
15507
  return { message: message !== null && message !== void 0 ? message : ctx.defaultError };
15550
15508
  }
15551
- if (typeof ctx.data === "undefined") {
15509
+ if (typeof ctx.data === 'undefined') {
15552
15510
  return { message: (_a = message !== null && message !== void 0 ? message : required_error) !== null && _a !== void 0 ? _a : ctx.defaultError };
15553
15511
  }
15554
- if (iss.code !== "invalid_type")
15512
+ if (iss.code !== 'invalid_type')
15555
15513
  return { message: ctx.defaultError };
15556
15514
  return { message: (_b = message !== null && message !== void 0 ? message : invalid_type_error) !== null && _b !== void 0 ? _b : ctx.defaultError };
15557
15515
  };
@@ -15601,7 +15559,9 @@ class McpServer {
15601
15559
  }
15602
15560
  });
15603
15561
  this.server.setRequestHandler(ListToolsRequestSchema, () => ({
15604
- tools: Object.entries(this._registeredTools).filter(([, tool]) => tool.enabled).map(([name, tool]) => {
15562
+ tools: Object.entries(this._registeredTools)
15563
+ .filter(([, tool]) => tool.enabled)
15564
+ .map(([name, tool]) => {
15605
15565
  const toolDefinition = {
15606
15566
  name,
15607
15567
  title: tool.title,
@@ -15609,16 +15569,20 @@ class McpServer {
15609
15569
  inputSchema: tool.inputSchema
15610
15570
  ? zodToJsonSchema(tool.inputSchema, {
15611
15571
  strictUnions: true,
15572
+ pipeStrategy: 'input'
15612
15573
  })
15613
15574
  : EMPTY_OBJECT_JSON_SCHEMA,
15614
15575
  annotations: tool.annotations,
15615
- _meta: tool._meta,
15576
+ _meta: tool._meta
15616
15577
  };
15617
15578
  if (tool.outputSchema) {
15618
- toolDefinition.outputSchema = zodToJsonSchema(tool.outputSchema, { strictUnions: true });
15579
+ toolDefinition.outputSchema = zodToJsonSchema(tool.outputSchema, {
15580
+ strictUnions: true,
15581
+ pipeStrategy: 'output'
15582
+ });
15619
15583
  }
15620
15584
  return toolDefinition;
15621
- }),
15585
+ })
15622
15586
  }));
15623
15587
  this.server.setRequestHandler(CallToolRequestSchema, async (request, extra) => {
15624
15588
  const tool = this._registeredTools[request.params.name];
@@ -15643,11 +15607,11 @@ class McpServer {
15643
15607
  result = {
15644
15608
  content: [
15645
15609
  {
15646
- type: "text",
15647
- text: error instanceof Error ? error.message : String(error),
15648
- },
15610
+ type: 'text',
15611
+ text: error instanceof Error ? error.message : String(error)
15612
+ }
15649
15613
  ],
15650
- isError: true,
15614
+ isError: true
15651
15615
  };
15652
15616
  }
15653
15617
  }
@@ -15660,11 +15624,11 @@ class McpServer {
15660
15624
  result = {
15661
15625
  content: [
15662
15626
  {
15663
- type: "text",
15664
- text: error instanceof Error ? error.message : String(error),
15665
- },
15627
+ type: 'text',
15628
+ text: error instanceof Error ? error.message : String(error)
15629
+ }
15666
15630
  ],
15667
- isError: true,
15631
+ isError: true
15668
15632
  };
15669
15633
  }
15670
15634
  }
@@ -15688,13 +15652,13 @@ class McpServer {
15688
15652
  }
15689
15653
  this.server.assertCanSetRequestHandler(CompleteRequestSchema.shape.method.value);
15690
15654
  this.server.registerCapabilities({
15691
- completions: {},
15655
+ completions: {}
15692
15656
  });
15693
15657
  this.server.setRequestHandler(CompleteRequestSchema, async (request) => {
15694
15658
  switch (request.params.ref.type) {
15695
- case "ref/prompt":
15659
+ case 'ref/prompt':
15696
15660
  return this.handlePromptCompletion(request, request.params.ref);
15697
- case "ref/resource":
15661
+ case 'ref/resource':
15698
15662
  return this.handleResourceCompletion(request, request.params.ref);
15699
15663
  default:
15700
15664
  throw new McpError(ErrorCode.InvalidParams, `Invalid completion reference: ${request.params.ref}`);
@@ -15722,7 +15686,7 @@ class McpServer {
15722
15686
  return createCompletionResult(suggestions);
15723
15687
  }
15724
15688
  async handleResourceCompletion(request, ref) {
15725
- const template = Object.values(this._registeredResourceTemplates).find((t) => t.resourceTemplate.uriTemplate.toString() === ref.uri);
15689
+ const template = Object.values(this._registeredResourceTemplates).find(t => t.resourceTemplate.uriTemplate.toString() === ref.uri);
15726
15690
  if (!template) {
15727
15691
  if (this._registeredResources[ref.uri]) {
15728
15692
  // Attempting to autocomplete a fixed resource URI is not an error in the spec (but probably should be).
@@ -15750,10 +15714,12 @@ class McpServer {
15750
15714
  }
15751
15715
  });
15752
15716
  this.server.setRequestHandler(ListResourcesRequestSchema, async (request, extra) => {
15753
- const resources = Object.entries(this._registeredResources).filter(([_, resource]) => resource.enabled).map(([uri, resource]) => ({
15717
+ const resources = Object.entries(this._registeredResources)
15718
+ .filter(([_, resource]) => resource.enabled)
15719
+ .map(([uri, resource]) => ({
15754
15720
  uri,
15755
15721
  name: resource.name,
15756
- ...resource.metadata,
15722
+ ...resource.metadata
15757
15723
  }));
15758
15724
  const templateResources = [];
15759
15725
  for (const template of Object.values(this._registeredResourceTemplates)) {
@@ -15765,7 +15731,7 @@ class McpServer {
15765
15731
  templateResources.push({
15766
15732
  ...template.metadata,
15767
15733
  // the defined resource metadata should override the template metadata if present
15768
- ...resource,
15734
+ ...resource
15769
15735
  });
15770
15736
  }
15771
15737
  }
@@ -15775,7 +15741,7 @@ class McpServer {
15775
15741
  const resourceTemplates = Object.entries(this._registeredResourceTemplates).map(([name, template]) => ({
15776
15742
  name,
15777
15743
  uriTemplate: template.resourceTemplate.uriTemplate.toString(),
15778
- ...template.metadata,
15744
+ ...template.metadata
15779
15745
  }));
15780
15746
  return { resourceTemplates };
15781
15747
  });
@@ -15813,16 +15779,16 @@ class McpServer {
15813
15779
  }
15814
15780
  });
15815
15781
  this.server.setRequestHandler(ListPromptsRequestSchema, () => ({
15816
- prompts: Object.entries(this._registeredPrompts).filter(([, prompt]) => prompt.enabled).map(([name, prompt]) => {
15782
+ prompts: Object.entries(this._registeredPrompts)
15783
+ .filter(([, prompt]) => prompt.enabled)
15784
+ .map(([name, prompt]) => {
15817
15785
  return {
15818
15786
  name,
15819
15787
  title: prompt.title,
15820
15788
  description: prompt.description,
15821
- arguments: prompt.argsSchema
15822
- ? promptArgumentsFromSchema(prompt.argsSchema)
15823
- : undefined,
15789
+ arguments: prompt.argsSchema ? promptArgumentsFromSchema(prompt.argsSchema) : undefined
15824
15790
  };
15825
- }),
15791
+ })
15826
15792
  }));
15827
15793
  this.server.setRequestHandler(GetPromptRequestSchema, async (request, extra) => {
15828
15794
  const prompt = this._registeredPrompts[request.params.name];
@@ -15851,11 +15817,11 @@ class McpServer {
15851
15817
  }
15852
15818
  resource(name, uriOrTemplate, ...rest) {
15853
15819
  let metadata;
15854
- if (typeof rest[0] === "object") {
15820
+ if (typeof rest[0] === 'object') {
15855
15821
  metadata = rest.shift();
15856
15822
  }
15857
15823
  const readCallback = rest[0];
15858
- if (typeof uriOrTemplate === "string") {
15824
+ if (typeof uriOrTemplate === 'string') {
15859
15825
  if (this._registeredResources[uriOrTemplate]) {
15860
15826
  throw new Error(`Resource ${uriOrTemplate} is already registered`);
15861
15827
  }
@@ -15875,7 +15841,7 @@ class McpServer {
15875
15841
  }
15876
15842
  }
15877
15843
  registerResource(name, uriOrTemplate, config, readCallback) {
15878
- if (typeof uriOrTemplate === "string") {
15844
+ if (typeof uriOrTemplate === 'string') {
15879
15845
  if (this._registeredResources[uriOrTemplate]) {
15880
15846
  throw new Error(`Resource ${uriOrTemplate} is already registered`);
15881
15847
  }
@@ -15904,24 +15870,24 @@ class McpServer {
15904
15870
  disable: () => registeredResource.update({ enabled: false }),
15905
15871
  enable: () => registeredResource.update({ enabled: true }),
15906
15872
  remove: () => registeredResource.update({ uri: null }),
15907
- update: (updates) => {
15908
- if (typeof updates.uri !== "undefined" && updates.uri !== uri) {
15873
+ update: updates => {
15874
+ if (typeof updates.uri !== 'undefined' && updates.uri !== uri) {
15909
15875
  delete this._registeredResources[uri];
15910
15876
  if (updates.uri)
15911
15877
  this._registeredResources[updates.uri] = registeredResource;
15912
15878
  }
15913
- if (typeof updates.name !== "undefined")
15879
+ if (typeof updates.name !== 'undefined')
15914
15880
  registeredResource.name = updates.name;
15915
- if (typeof updates.title !== "undefined")
15881
+ if (typeof updates.title !== 'undefined')
15916
15882
  registeredResource.title = updates.title;
15917
- if (typeof updates.metadata !== "undefined")
15883
+ if (typeof updates.metadata !== 'undefined')
15918
15884
  registeredResource.metadata = updates.metadata;
15919
- if (typeof updates.callback !== "undefined")
15885
+ if (typeof updates.callback !== 'undefined')
15920
15886
  registeredResource.readCallback = updates.callback;
15921
- if (typeof updates.enabled !== "undefined")
15887
+ if (typeof updates.enabled !== 'undefined')
15922
15888
  registeredResource.enabled = updates.enabled;
15923
15889
  this.sendResourceListChanged();
15924
- },
15890
+ }
15925
15891
  };
15926
15892
  this._registeredResources[uri] = registeredResource;
15927
15893
  return registeredResource;
@@ -15936,24 +15902,24 @@ class McpServer {
15936
15902
  disable: () => registeredResourceTemplate.update({ enabled: false }),
15937
15903
  enable: () => registeredResourceTemplate.update({ enabled: true }),
15938
15904
  remove: () => registeredResourceTemplate.update({ name: null }),
15939
- update: (updates) => {
15940
- if (typeof updates.name !== "undefined" && updates.name !== name) {
15905
+ update: updates => {
15906
+ if (typeof updates.name !== 'undefined' && updates.name !== name) {
15941
15907
  delete this._registeredResourceTemplates[name];
15942
15908
  if (updates.name)
15943
15909
  this._registeredResourceTemplates[updates.name] = registeredResourceTemplate;
15944
15910
  }
15945
- if (typeof updates.title !== "undefined")
15911
+ if (typeof updates.title !== 'undefined')
15946
15912
  registeredResourceTemplate.title = updates.title;
15947
- if (typeof updates.template !== "undefined")
15913
+ if (typeof updates.template !== 'undefined')
15948
15914
  registeredResourceTemplate.resourceTemplate = updates.template;
15949
- if (typeof updates.metadata !== "undefined")
15915
+ if (typeof updates.metadata !== 'undefined')
15950
15916
  registeredResourceTemplate.metadata = updates.metadata;
15951
- if (typeof updates.callback !== "undefined")
15917
+ if (typeof updates.callback !== 'undefined')
15952
15918
  registeredResourceTemplate.readCallback = updates.callback;
15953
- if (typeof updates.enabled !== "undefined")
15919
+ if (typeof updates.enabled !== 'undefined')
15954
15920
  registeredResourceTemplate.enabled = updates.enabled;
15955
15921
  this.sendResourceListChanged();
15956
- },
15922
+ }
15957
15923
  };
15958
15924
  this._registeredResourceTemplates[name] = registeredResourceTemplate;
15959
15925
  return registeredResourceTemplate;
@@ -15968,24 +15934,24 @@ class McpServer {
15968
15934
  disable: () => registeredPrompt.update({ enabled: false }),
15969
15935
  enable: () => registeredPrompt.update({ enabled: true }),
15970
15936
  remove: () => registeredPrompt.update({ name: null }),
15971
- update: (updates) => {
15972
- if (typeof updates.name !== "undefined" && updates.name !== name) {
15937
+ update: updates => {
15938
+ if (typeof updates.name !== 'undefined' && updates.name !== name) {
15973
15939
  delete this._registeredPrompts[name];
15974
15940
  if (updates.name)
15975
15941
  this._registeredPrompts[updates.name] = registeredPrompt;
15976
15942
  }
15977
- if (typeof updates.title !== "undefined")
15943
+ if (typeof updates.title !== 'undefined')
15978
15944
  registeredPrompt.title = updates.title;
15979
- if (typeof updates.description !== "undefined")
15945
+ if (typeof updates.description !== 'undefined')
15980
15946
  registeredPrompt.description = updates.description;
15981
- if (typeof updates.argsSchema !== "undefined")
15947
+ if (typeof updates.argsSchema !== 'undefined')
15982
15948
  registeredPrompt.argsSchema = objectType(updates.argsSchema);
15983
- if (typeof updates.callback !== "undefined")
15949
+ if (typeof updates.callback !== 'undefined')
15984
15950
  registeredPrompt.callback = updates.callback;
15985
- if (typeof updates.enabled !== "undefined")
15951
+ if (typeof updates.enabled !== 'undefined')
15986
15952
  registeredPrompt.enabled = updates.enabled;
15987
15953
  this.sendPromptListChanged();
15988
- },
15954
+ }
15989
15955
  };
15990
15956
  this._registeredPrompts[name] = registeredPrompt;
15991
15957
  return registeredPrompt;
@@ -16003,28 +15969,28 @@ class McpServer {
16003
15969
  disable: () => registeredTool.update({ enabled: false }),
16004
15970
  enable: () => registeredTool.update({ enabled: true }),
16005
15971
  remove: () => registeredTool.update({ name: null }),
16006
- update: (updates) => {
16007
- if (typeof updates.name !== "undefined" && updates.name !== name) {
15972
+ update: updates => {
15973
+ if (typeof updates.name !== 'undefined' && updates.name !== name) {
16008
15974
  delete this._registeredTools[name];
16009
15975
  if (updates.name)
16010
15976
  this._registeredTools[updates.name] = registeredTool;
16011
15977
  }
16012
- if (typeof updates.title !== "undefined")
15978
+ if (typeof updates.title !== 'undefined')
16013
15979
  registeredTool.title = updates.title;
16014
- if (typeof updates.description !== "undefined")
15980
+ if (typeof updates.description !== 'undefined')
16015
15981
  registeredTool.description = updates.description;
16016
- if (typeof updates.paramsSchema !== "undefined")
15982
+ if (typeof updates.paramsSchema !== 'undefined')
16017
15983
  registeredTool.inputSchema = objectType(updates.paramsSchema);
16018
- if (typeof updates.callback !== "undefined")
15984
+ if (typeof updates.callback !== 'undefined')
16019
15985
  registeredTool.callback = updates.callback;
16020
- if (typeof updates.annotations !== "undefined")
15986
+ if (typeof updates.annotations !== 'undefined')
16021
15987
  registeredTool.annotations = updates.annotations;
16022
- if (typeof updates._meta !== "undefined")
15988
+ if (typeof updates._meta !== 'undefined')
16023
15989
  registeredTool._meta = updates._meta;
16024
- if (typeof updates.enabled !== "undefined")
15990
+ if (typeof updates.enabled !== 'undefined')
16025
15991
  registeredTool.enabled = updates.enabled;
16026
15992
  this.sendToolListChanged();
16027
- },
15993
+ }
16028
15994
  };
16029
15995
  this._registeredTools[name] = registeredTool;
16030
15996
  this.setToolRequestHandlers();
@@ -16045,7 +16011,7 @@ class McpServer {
16045
16011
  // Tool properties are passed as separate arguments, with omissions allowed.
16046
16012
  // Support for this style is frozen as of protocol version 2025-03-26. Future additions
16047
16013
  // to tool definition should *NOT* be added.
16048
- if (typeof rest[0] === "string") {
16014
+ if (typeof rest[0] === 'string') {
16049
16015
  description = rest.shift();
16050
16016
  }
16051
16017
  // Handle the different overload combinations
@@ -16056,13 +16022,13 @@ class McpServer {
16056
16022
  // We have a params schema as the first arg
16057
16023
  inputSchema = rest.shift();
16058
16024
  // Check if the next arg is potentially annotations
16059
- if (rest.length > 1 && typeof rest[0] === "object" && rest[0] !== null && !(isZodRawShape(rest[0]))) {
16025
+ if (rest.length > 1 && typeof rest[0] === 'object' && rest[0] !== null && !isZodRawShape(rest[0])) {
16060
16026
  // Case: tool(name, paramsSchema, annotations, cb)
16061
16027
  // Or: tool(name, description, paramsSchema, annotations, cb)
16062
16028
  annotations = rest.shift();
16063
16029
  }
16064
16030
  }
16065
- else if (typeof firstArg === "object" && firstArg !== null) {
16031
+ else if (typeof firstArg === 'object' && firstArg !== null) {
16066
16032
  // Not a ZodRawShape, so must be annotations in this position
16067
16033
  // Case: tool(name, annotations, cb)
16068
16034
  // Or: tool(name, description, annotations, cb)
@@ -16087,7 +16053,7 @@ class McpServer {
16087
16053
  throw new Error(`Prompt ${name} is already registered`);
16088
16054
  }
16089
16055
  let description;
16090
- if (typeof rest[0] === "string") {
16056
+ if (typeof rest[0] === 'string') {
16091
16057
  description = rest.shift();
16092
16058
  }
16093
16059
  let argsSchema;
@@ -16156,12 +16122,12 @@ class McpServer {
16156
16122
  }
16157
16123
  }
16158
16124
  const EMPTY_OBJECT_JSON_SCHEMA = {
16159
- type: "object",
16160
- properties: {},
16125
+ type: 'object',
16126
+ properties: {}
16161
16127
  };
16162
16128
  // Helper to check if an object is a Zod schema (ZodRawShape)
16163
16129
  function isZodRawShape(obj) {
16164
- if (typeof obj !== "object" || obj === null)
16130
+ if (typeof obj !== 'object' || obj === null)
16165
16131
  return false;
16166
16132
  const isEmptyObject = Object.keys(obj).length === 0;
16167
16133
  // Check if object is empty or at least one property is a ZodType instance
@@ -16169,16 +16135,18 @@ function isZodRawShape(obj) {
16169
16135
  return isEmptyObject || Object.values(obj).some(isZodTypeLike);
16170
16136
  }
16171
16137
  function isZodTypeLike(value) {
16172
- return value !== null &&
16138
+ return (value !== null &&
16173
16139
  typeof value === 'object' &&
16174
- 'parse' in value && typeof value.parse === 'function' &&
16175
- 'safeParse' in value && typeof value.safeParse === 'function';
16140
+ 'parse' in value &&
16141
+ typeof value.parse === 'function' &&
16142
+ 'safeParse' in value &&
16143
+ typeof value.safeParse === 'function');
16176
16144
  }
16177
16145
  function promptArgumentsFromSchema(schema) {
16178
16146
  return Object.entries(schema.shape).map(([name, field]) => ({
16179
16147
  name,
16180
16148
  description: field.description,
16181
- required: !field.isOptional(),
16149
+ required: !field.isOptional()
16182
16150
  }));
16183
16151
  }
16184
16152
  function createCompletionResult(suggestions) {
@@ -16186,15 +16154,15 @@ function createCompletionResult(suggestions) {
16186
16154
  completion: {
16187
16155
  values: suggestions.slice(0, 100),
16188
16156
  total: suggestions.length,
16189
- hasMore: suggestions.length > 100,
16190
- },
16157
+ hasMore: suggestions.length > 100
16158
+ }
16191
16159
  };
16192
16160
  }
16193
16161
  const EMPTY_COMPLETION_RESULT = {
16194
16162
  completion: {
16195
16163
  values: [],
16196
- hasMore: false,
16197
- },
16164
+ hasMore: false
16165
+ }
16198
16166
  };
16199
16167
 
16200
16168
  async function safeMcpResponse(exec) {
@@ -31235,244 +31203,370 @@ class XmlNode{
31235
31203
  }
31236
31204
  }
31237
31205
 
31238
- //TODO: handle comments
31239
- function readDocType(xmlData, i){
31206
+ class DocTypeReader{
31207
+ constructor(processEntities){
31208
+ this.suppressValidationErr = !processEntities;
31209
+ }
31240
31210
 
31241
- const entities = {};
31242
- if( xmlData[i + 3] === 'O' &&
31243
- xmlData[i + 4] === 'C' &&
31244
- xmlData[i + 5] === 'T' &&
31245
- xmlData[i + 6] === 'Y' &&
31246
- xmlData[i + 7] === 'P' &&
31247
- xmlData[i + 8] === 'E')
31248
- {
31249
- i = i+9;
31250
- let angleBracketsCount = 1;
31251
- let hasBody = false, comment = false;
31252
- let exp = "";
31253
- for(;i<xmlData.length;i++){
31254
- if (xmlData[i] === '<' && !comment) { //Determine the tag type
31255
- if( hasBody && hasSeq(xmlData, "!ENTITY",i)){
31256
- i += 7;
31257
- let entityName, val;
31258
- [entityName, val,i] = readEntityExp(xmlData,i+1);
31259
- if(val.indexOf("&") === -1) //Parameter entities are not supported
31260
- entities[ entityName ] = {
31261
- regx : RegExp( `&${entityName};`,"g"),
31262
- val: val
31263
- };
31264
- }
31265
- else if( hasBody && hasSeq(xmlData, "!ELEMENT",i)) {
31266
- i += 8;//Not supported
31267
- const {index} = readElementExp(xmlData,i+1);
31268
- i = index;
31269
- }else if( hasBody && hasSeq(xmlData, "!ATTLIST",i)){
31270
- i += 8;//Not supported
31271
- // const {index} = readAttlistExp(xmlData,i+1);
31272
- // i = index;
31273
- }else if( hasBody && hasSeq(xmlData, "!NOTATION",i)) {
31274
- i += 9;//Not supported
31275
- const {index} = readNotationExp(xmlData,i+1);
31276
- i = index;
31277
- }else if( hasSeq(xmlData, "!--",i) ) comment = true;
31278
- else throw new Error(`Invalid DOCTYPE`);
31279
-
31280
- angleBracketsCount++;
31281
- exp = "";
31282
- } else if (xmlData[i] === '>') { //Read tag content
31283
- if(comment){
31284
- if( xmlData[i - 1] === "-" && xmlData[i - 2] === "-"){
31285
- comment = false;
31211
+ readDocType(xmlData, i){
31212
+
31213
+ const entities = {};
31214
+ if( xmlData[i + 3] === 'O' &&
31215
+ xmlData[i + 4] === 'C' &&
31216
+ xmlData[i + 5] === 'T' &&
31217
+ xmlData[i + 6] === 'Y' &&
31218
+ xmlData[i + 7] === 'P' &&
31219
+ xmlData[i + 8] === 'E')
31220
+ {
31221
+ i = i+9;
31222
+ let angleBracketsCount = 1;
31223
+ let hasBody = false, comment = false;
31224
+ let exp = "";
31225
+ for(;i<xmlData.length;i++){
31226
+ if (xmlData[i] === '<' && !comment) { //Determine the tag type
31227
+ if( hasBody && hasSeq(xmlData, "!ENTITY",i)){
31228
+ i += 7;
31229
+ let entityName, val;
31230
+ [entityName, val,i] = this.readEntityExp(xmlData,i+1,this.suppressValidationErr);
31231
+ if(val.indexOf("&") === -1) //Parameter entities are not supported
31232
+ entities[ entityName ] = {
31233
+ regx : RegExp( `&${entityName};`,"g"),
31234
+ val: val
31235
+ };
31236
+ }
31237
+ else if( hasBody && hasSeq(xmlData, "!ELEMENT",i)) {
31238
+ i += 8;//Not supported
31239
+ const {index} = this.readElementExp(xmlData,i+1);
31240
+ i = index;
31241
+ }else if( hasBody && hasSeq(xmlData, "!ATTLIST",i)){
31242
+ i += 8;//Not supported
31243
+ // const {index} = this.readAttlistExp(xmlData,i+1);
31244
+ // i = index;
31245
+ }else if( hasBody && hasSeq(xmlData, "!NOTATION",i)) {
31246
+ i += 9;//Not supported
31247
+ const {index} = this.readNotationExp(xmlData,i+1,this.suppressValidationErr);
31248
+ i = index;
31249
+ }else if( hasSeq(xmlData, "!--",i) ) comment = true;
31250
+ else throw new Error(`Invalid DOCTYPE`);
31251
+
31252
+ angleBracketsCount++;
31253
+ exp = "";
31254
+ } else if (xmlData[i] === '>') { //Read tag content
31255
+ if(comment){
31256
+ if( xmlData[i - 1] === "-" && xmlData[i - 2] === "-"){
31257
+ comment = false;
31258
+ angleBracketsCount--;
31259
+ }
31260
+ }else {
31286
31261
  angleBracketsCount--;
31287
31262
  }
31263
+ if (angleBracketsCount === 0) {
31264
+ break;
31265
+ }
31266
+ }else if( xmlData[i] === '['){
31267
+ hasBody = true;
31288
31268
  }else {
31289
- angleBracketsCount--;
31290
- }
31291
- if (angleBracketsCount === 0) {
31292
- break;
31269
+ exp += xmlData[i];
31293
31270
  }
31294
- }else if( xmlData[i] === '['){
31295
- hasBody = true;
31296
- }else {
31297
- exp += xmlData[i];
31298
31271
  }
31272
+ if(angleBracketsCount !== 0){
31273
+ throw new Error(`Unclosed DOCTYPE`);
31274
+ }
31275
+ }else {
31276
+ throw new Error(`Invalid Tag instead of DOCTYPE`);
31299
31277
  }
31300
- if(angleBracketsCount !== 0){
31301
- throw new Error(`Unclosed DOCTYPE`);
31302
- }
31303
- }else {
31304
- throw new Error(`Invalid Tag instead of DOCTYPE`);
31278
+ return {entities, i};
31305
31279
  }
31306
- return {entities, i};
31307
- }
31280
+ readEntityExp(xmlData, i) {
31281
+ //External entities are not supported
31282
+ // <!ENTITY ext SYSTEM "http://normal-website.com" >
31308
31283
 
31309
- const skipWhitespace = (data, index) => {
31310
- while (index < data.length && /\s/.test(data[index])) {
31311
- index++;
31312
- }
31313
- return index;
31314
- };
31284
+ //Parameter entities are not supported
31285
+ // <!ENTITY entityname "&anotherElement;">
31315
31286
 
31316
- function readEntityExp(xmlData, i) {
31317
- //External entities are not supported
31318
- // <!ENTITY ext SYSTEM "http://normal-website.com" >
31287
+ //Internal entities are supported
31288
+ // <!ENTITY entityname "replacement text">
31319
31289
 
31320
- //Parameter entities are not supported
31321
- // <!ENTITY entityname "&anotherElement;">
31290
+ // Skip leading whitespace after <!ENTITY
31291
+ i = skipWhitespace(xmlData, i);
31322
31292
 
31323
- //Internal entities are supported
31324
- // <!ENTITY entityname "replacement text">
31293
+ // Read entity name
31294
+ let entityName = "";
31295
+ while (i < xmlData.length && !/\s/.test(xmlData[i]) && xmlData[i] !== '"' && xmlData[i] !== "'") {
31296
+ entityName += xmlData[i];
31297
+ i++;
31298
+ }
31299
+ validateEntityName(entityName);
31325
31300
 
31326
- // Skip leading whitespace after <!ENTITY
31327
- i = skipWhitespace(xmlData, i);
31301
+ // Skip whitespace after entity name
31302
+ i = skipWhitespace(xmlData, i);
31328
31303
 
31329
- // Read entity name
31330
- let entityName = "";
31331
- while (i < xmlData.length && !/\s/.test(xmlData[i]) && xmlData[i] !== '"' && xmlData[i] !== "'") {
31332
- entityName += xmlData[i];
31333
- i++;
31304
+ // Check for unsupported constructs (external entities or parameter entities)
31305
+ if(!this.suppressValidationErr){
31306
+ if (xmlData.substring(i, i + 6).toUpperCase() === "SYSTEM") {
31307
+ throw new Error("External entities are not supported");
31308
+ }else if (xmlData[i] === "%") {
31309
+ throw new Error("Parameter entities are not supported");
31310
+ }
31311
+ }
31312
+
31313
+ // Read entity value (internal entity)
31314
+ let entityValue = "";
31315
+ [i, entityValue] = this.readIdentifierVal(xmlData, i, "entity");
31316
+ i--;
31317
+ return [entityName, entityValue, i ];
31334
31318
  }
31335
- validateEntityName(entityName);
31336
31319
 
31337
- // Skip whitespace after entity name
31338
- i = skipWhitespace(xmlData, i);
31320
+ readNotationExp(xmlData, i) {
31321
+ // Skip leading whitespace after <!NOTATION
31322
+ i = skipWhitespace(xmlData, i);
31339
31323
 
31340
- // Check for unsupported constructs (external entities or parameter entities)
31341
- if (xmlData.substring(i, i + 6).toUpperCase() === "SYSTEM") {
31342
- throw new Error("External entities are not supported");
31343
- }else if (xmlData[i] === "%") {
31344
- throw new Error("Parameter entities are not supported");
31324
+ // Read notation name
31325
+ let notationName = "";
31326
+ while (i < xmlData.length && !/\s/.test(xmlData[i])) {
31327
+ notationName += xmlData[i];
31328
+ i++;
31329
+ }
31330
+ !this.suppressValidationErr && validateEntityName(notationName);
31331
+
31332
+ // Skip whitespace after notation name
31333
+ i = skipWhitespace(xmlData, i);
31334
+
31335
+ // Check identifier type (SYSTEM or PUBLIC)
31336
+ const identifierType = xmlData.substring(i, i + 6).toUpperCase();
31337
+ if (!this.suppressValidationErr && identifierType !== "SYSTEM" && identifierType !== "PUBLIC") {
31338
+ throw new Error(`Expected SYSTEM or PUBLIC, found "${identifierType}"`);
31339
+ }
31340
+ i += identifierType.length;
31341
+
31342
+ // Skip whitespace after identifier type
31343
+ i = skipWhitespace(xmlData, i);
31344
+
31345
+ // Read public identifier (if PUBLIC)
31346
+ let publicIdentifier = null;
31347
+ let systemIdentifier = null;
31348
+
31349
+ if (identifierType === "PUBLIC") {
31350
+ [i, publicIdentifier ] = this.readIdentifierVal(xmlData, i, "publicIdentifier");
31351
+
31352
+ // Skip whitespace after public identifier
31353
+ i = skipWhitespace(xmlData, i);
31354
+
31355
+ // Optionally read system identifier
31356
+ if (xmlData[i] === '"' || xmlData[i] === "'") {
31357
+ [i, systemIdentifier ] = this.readIdentifierVal(xmlData, i,"systemIdentifier");
31358
+ }
31359
+ } else if (identifierType === "SYSTEM") {
31360
+ // Read system identifier (mandatory for SYSTEM)
31361
+ [i, systemIdentifier ] = this.readIdentifierVal(xmlData, i, "systemIdentifier");
31362
+
31363
+ if (!this.suppressValidationErr && !systemIdentifier) {
31364
+ throw new Error("Missing mandatory system identifier for SYSTEM notation");
31365
+ }
31366
+ }
31367
+
31368
+ return {notationName, publicIdentifier, systemIdentifier, index: --i};
31345
31369
  }
31346
31370
 
31347
- // Read entity value (internal entity)
31348
- let entityValue = "";
31349
- [i, entityValue] = readIdentifierVal(xmlData, i, "entity");
31350
- i--;
31351
- return [entityName, entityValue, i ];
31352
- }
31371
+ readIdentifierVal(xmlData, i, type) {
31372
+ let identifierVal = "";
31373
+ const startChar = xmlData[i];
31374
+ if (startChar !== '"' && startChar !== "'") {
31375
+ throw new Error(`Expected quoted string, found "${startChar}"`);
31376
+ }
31377
+ i++;
31353
31378
 
31354
- function readNotationExp(xmlData, i) {
31355
- // Skip leading whitespace after <!NOTATION
31356
- i = skipWhitespace(xmlData, i);
31379
+ while (i < xmlData.length && xmlData[i] !== startChar) {
31380
+ identifierVal += xmlData[i];
31381
+ i++;
31382
+ }
31357
31383
 
31358
- // Read notation name
31359
- let notationName = "";
31360
- while (i < xmlData.length && !/\s/.test(xmlData[i])) {
31361
- notationName += xmlData[i];
31384
+ if (xmlData[i] !== startChar) {
31385
+ throw new Error(`Unterminated ${type} value`);
31386
+ }
31362
31387
  i++;
31388
+ return [i, identifierVal];
31363
31389
  }
31364
- validateEntityName(notationName);
31365
31390
 
31366
- // Skip whitespace after notation name
31367
- i = skipWhitespace(xmlData, i);
31391
+ readElementExp(xmlData, i) {
31392
+ // <!ELEMENT br EMPTY>
31393
+ // <!ELEMENT div ANY>
31394
+ // <!ELEMENT title (#PCDATA)>
31395
+ // <!ELEMENT book (title, author+)>
31396
+ // <!ELEMENT name (content-model)>
31397
+
31398
+ // Skip leading whitespace after <!ELEMENT
31399
+ i = skipWhitespace(xmlData, i);
31400
+
31401
+ // Read element name
31402
+ let elementName = "";
31403
+ while (i < xmlData.length && !/\s/.test(xmlData[i])) {
31404
+ elementName += xmlData[i];
31405
+ i++;
31406
+ }
31407
+
31408
+ // Validate element name
31409
+ if (!this.suppressValidationErr && !isName(elementName)) {
31410
+ throw new Error(`Invalid element name: "${elementName}"`);
31411
+ }
31412
+
31413
+ // Skip whitespace after element name
31414
+ i = skipWhitespace(xmlData, i);
31415
+ let contentModel = "";
31416
+ // Expect '(' to start content model
31417
+ if(xmlData[i] === "E" && hasSeq(xmlData, "MPTY",i)) i+=4;
31418
+ else if(xmlData[i] === "A" && hasSeq(xmlData, "NY",i)) i+=2;
31419
+ else if (xmlData[i] === "(") {
31420
+ i++; // Move past '('
31421
+
31422
+ // Read content model
31423
+ while (i < xmlData.length && xmlData[i] !== ")") {
31424
+ contentModel += xmlData[i];
31425
+ i++;
31426
+ }
31427
+ if (xmlData[i] !== ")") {
31428
+ throw new Error("Unterminated content model");
31429
+ }
31368
31430
 
31369
- // Check identifier type (SYSTEM or PUBLIC)
31370
- const identifierType = xmlData.substring(i, i + 6).toUpperCase();
31371
- if (identifierType !== "SYSTEM" && identifierType !== "PUBLIC") {
31372
- throw new Error(`Expected SYSTEM or PUBLIC, found "${identifierType}"`);
31431
+ }else if(!this.suppressValidationErr){
31432
+ throw new Error(`Invalid Element Expression, found "${xmlData[i]}"`);
31433
+ }
31434
+
31435
+ return {
31436
+ elementName,
31437
+ contentModel: contentModel.trim(),
31438
+ index: i
31439
+ };
31373
31440
  }
31374
- i += identifierType.length;
31375
31441
 
31376
- // Skip whitespace after identifier type
31377
- i = skipWhitespace(xmlData, i);
31442
+ readAttlistExp(xmlData, i) {
31443
+ // Skip leading whitespace after <!ATTLIST
31444
+ i = skipWhitespace(xmlData, i);
31378
31445
 
31379
- // Read public identifier (if PUBLIC)
31380
- let publicIdentifier = null;
31381
- let systemIdentifier = null;
31446
+ // Read element name
31447
+ let elementName = "";
31448
+ while (i < xmlData.length && !/\s/.test(xmlData[i])) {
31449
+ elementName += xmlData[i];
31450
+ i++;
31451
+ }
31382
31452
 
31383
- if (identifierType === "PUBLIC") {
31384
- [i, publicIdentifier ] = readIdentifierVal(xmlData, i, "publicIdentifier");
31453
+ // Validate element name
31454
+ validateEntityName(elementName);
31385
31455
 
31386
- // Skip whitespace after public identifier
31456
+ // Skip whitespace after element name
31387
31457
  i = skipWhitespace(xmlData, i);
31388
31458
 
31389
- // Optionally read system identifier
31390
- if (xmlData[i] === '"' || xmlData[i] === "'") {
31391
- [i, systemIdentifier ] = readIdentifierVal(xmlData, i,"systemIdentifier");
31459
+ // Read attribute name
31460
+ let attributeName = "";
31461
+ while (i < xmlData.length && !/\s/.test(xmlData[i])) {
31462
+ attributeName += xmlData[i];
31463
+ i++;
31392
31464
  }
31393
- } else if (identifierType === "SYSTEM") {
31394
- // Read system identifier (mandatory for SYSTEM)
31395
- [i, systemIdentifier ] = readIdentifierVal(xmlData, i, "systemIdentifier");
31396
31465
 
31397
- if (!systemIdentifier) {
31398
- throw new Error("Missing mandatory system identifier for SYSTEM notation");
31466
+ // Validate attribute name
31467
+ if (!validateEntityName(attributeName)) {
31468
+ throw new Error(`Invalid attribute name: "${attributeName}"`);
31399
31469
  }
31400
- }
31401
-
31402
- return {notationName, publicIdentifier, systemIdentifier, index: --i};
31403
- }
31404
31470
 
31405
- function readIdentifierVal(xmlData, i, type) {
31406
- let identifierVal = "";
31407
- const startChar = xmlData[i];
31408
- if (startChar !== '"' && startChar !== "'") {
31409
- throw new Error(`Expected quoted string, found "${startChar}"`);
31410
- }
31411
- i++;
31471
+ // Skip whitespace after attribute name
31472
+ i = skipWhitespace(xmlData, i);
31412
31473
 
31413
- while (i < xmlData.length && xmlData[i] !== startChar) {
31414
- identifierVal += xmlData[i];
31415
- i++;
31416
- }
31474
+ // Read attribute type
31475
+ let attributeType = "";
31476
+ if (xmlData.substring(i, i + 8).toUpperCase() === "NOTATION") {
31477
+ attributeType = "NOTATION";
31478
+ i += 8; // Move past "NOTATION"
31417
31479
 
31418
- if (xmlData[i] !== startChar) {
31419
- throw new Error(`Unterminated ${type} value`);
31420
- }
31421
- i++;
31422
- return [i, identifierVal];
31423
- }
31480
+ // Skip whitespace after "NOTATION"
31481
+ i = skipWhitespace(xmlData, i);
31424
31482
 
31425
- function readElementExp(xmlData, i) {
31426
- // <!ELEMENT br EMPTY>
31427
- // <!ELEMENT div ANY>
31428
- // <!ELEMENT title (#PCDATA)>
31429
- // <!ELEMENT book (title, author+)>
31430
- // <!ELEMENT name (content-model)>
31431
-
31432
- // Skip leading whitespace after <!ELEMENT
31433
- i = skipWhitespace(xmlData, i);
31483
+ // Expect '(' to start the list of notations
31484
+ if (xmlData[i] !== "(") {
31485
+ throw new Error(`Expected '(', found "${xmlData[i]}"`);
31486
+ }
31487
+ i++; // Move past '('
31434
31488
 
31435
- // Read element name
31436
- let elementName = "";
31437
- while (i < xmlData.length && !/\s/.test(xmlData[i])) {
31438
- elementName += xmlData[i];
31439
- i++;
31440
- }
31489
+ // Read the list of allowed notations
31490
+ let allowedNotations = [];
31491
+ while (i < xmlData.length && xmlData[i] !== ")") {
31492
+ let notation = "";
31493
+ while (i < xmlData.length && xmlData[i] !== "|" && xmlData[i] !== ")") {
31494
+ notation += xmlData[i];
31495
+ i++;
31496
+ }
31441
31497
 
31442
- // Validate element name
31443
- if (!validateEntityName(elementName)) {
31444
- throw new Error(`Invalid element name: "${elementName}"`);
31445
- }
31498
+ // Validate notation name
31499
+ notation = notation.trim();
31500
+ if (!validateEntityName(notation)) {
31501
+ throw new Error(`Invalid notation name: "${notation}"`);
31502
+ }
31446
31503
 
31447
- // Skip whitespace after element name
31448
- i = skipWhitespace(xmlData, i);
31449
- let contentModel = "";
31450
- // Expect '(' to start content model
31451
- if(xmlData[i] === "E" && hasSeq(xmlData, "MPTY",i)) i+=4;
31452
- else if(xmlData[i] === "A" && hasSeq(xmlData, "NY",i)) i+=2;
31453
- else if (xmlData[i] === "(") {
31454
- i++; // Move past '('
31504
+ allowedNotations.push(notation);
31455
31505
 
31456
- // Read content model
31457
- while (i < xmlData.length && xmlData[i] !== ")") {
31458
- contentModel += xmlData[i];
31459
- i++;
31506
+ // Skip '|' separator or exit loop
31507
+ if (xmlData[i] === "|") {
31508
+ i++; // Move past '|'
31509
+ i = skipWhitespace(xmlData, i); // Skip optional whitespace after '|'
31510
+ }
31511
+ }
31512
+
31513
+ if (xmlData[i] !== ")") {
31514
+ throw new Error("Unterminated list of notations");
31515
+ }
31516
+ i++; // Move past ')'
31517
+
31518
+ // Store the allowed notations as part of the attribute type
31519
+ attributeType += " (" + allowedNotations.join("|") + ")";
31520
+ } else {
31521
+ // Handle simple types (e.g., CDATA, ID, IDREF, etc.)
31522
+ while (i < xmlData.length && !/\s/.test(xmlData[i])) {
31523
+ attributeType += xmlData[i];
31524
+ i++;
31525
+ }
31526
+
31527
+ // Validate simple attribute type
31528
+ const validTypes = ["CDATA", "ID", "IDREF", "IDREFS", "ENTITY", "ENTITIES", "NMTOKEN", "NMTOKENS"];
31529
+ if (!this.suppressValidationErr && !validTypes.includes(attributeType.toUpperCase())) {
31530
+ throw new Error(`Invalid attribute type: "${attributeType}"`);
31531
+ }
31460
31532
  }
31461
- if (xmlData[i] !== ")") {
31462
- throw new Error("Unterminated content model");
31533
+
31534
+ // Skip whitespace after attribute type
31535
+ i = skipWhitespace(xmlData, i);
31536
+
31537
+ // Read default value
31538
+ let defaultValue = "";
31539
+ if (xmlData.substring(i, i + 8).toUpperCase() === "#REQUIRED") {
31540
+ defaultValue = "#REQUIRED";
31541
+ i += 8;
31542
+ } else if (xmlData.substring(i, i + 7).toUpperCase() === "#IMPLIED") {
31543
+ defaultValue = "#IMPLIED";
31544
+ i += 7;
31545
+ } else {
31546
+ [i, defaultValue] = this.readIdentifierVal(xmlData, i, "ATTLIST");
31463
31547
  }
31464
31548
 
31465
- }else {
31466
- throw new Error(`Invalid Element Expression, found "${xmlData[i]}"`);
31549
+ return {
31550
+ elementName,
31551
+ attributeName,
31552
+ attributeType,
31553
+ defaultValue,
31554
+ index: i
31555
+ }
31467
31556
  }
31468
-
31469
- return {
31470
- elementName,
31471
- contentModel: contentModel.trim(),
31472
- index: i
31473
- };
31474
31557
  }
31475
31558
 
31559
+
31560
+
31561
+ const skipWhitespace = (data, index) => {
31562
+ while (index < data.length && /\s/.test(data[index])) {
31563
+ index++;
31564
+ }
31565
+ return index;
31566
+ };
31567
+
31568
+
31569
+
31476
31570
  function hasSeq(data, seq,i){
31477
31571
  for(let j=0;j<seq.length;j++){
31478
31572
  if(seq[j]!==data[i+j+1]) return false;
@@ -31482,7 +31576,7 @@ function hasSeq(data, seq,i){
31482
31576
 
31483
31577
  function validateEntityName(name){
31484
31578
  if (isName(name))
31485
- return name;
31579
+ return name;
31486
31580
  else
31487
31581
  throw new Error(`Invalid entity name ${name}`);
31488
31582
  }
@@ -31818,6 +31912,7 @@ const parseXml = function(xmlData) {
31818
31912
  let currentNode = xmlObj;
31819
31913
  let textData = "";
31820
31914
  let jPath = "";
31915
+ const docTypeReader = new DocTypeReader(this.options.processEntities);
31821
31916
  for(let i=0; i< xmlData.length; i++){//for each char in XML data
31822
31917
  const ch = xmlData[i];
31823
31918
  if(ch === '<'){
@@ -31889,7 +31984,7 @@ const parseXml = function(xmlData) {
31889
31984
  }
31890
31985
  i = endIndex;
31891
31986
  } else if( xmlData.substr(i + 1, 2) === '!D') {
31892
- const result = readDocType(xmlData, i);
31987
+ const result = docTypeReader.readDocType(xmlData, i);
31893
31988
  this.docTypeEntities = result.entities;
31894
31989
  i = result.i;
31895
31990
  }else if(xmlData.substr(i + 1, 2) === '![') {
@@ -32356,15 +32451,16 @@ class XMLParser{
32356
32451
  }
32357
32452
  /**
32358
32453
  * Parse XML dats to JS object
32359
- * @param {string|Buffer} xmlData
32454
+ * @param {string|Uint8Array} xmlData
32360
32455
  * @param {boolean|Object} validationOption
32361
32456
  */
32362
32457
  parse(xmlData,validationOption){
32363
- if(typeof xmlData === "string");else if( xmlData.toString){
32458
+ if(typeof xmlData !== "string" && xmlData.toString){
32364
32459
  xmlData = xmlData.toString();
32365
- }else {
32460
+ }else if(typeof xmlData !== "string"){
32366
32461
  throw new Error("XML data is accepted in String or Bytes[] form.")
32367
32462
  }
32463
+
32368
32464
  if( validationOption){
32369
32465
  if(validationOption === true) validationOption = {}; //validate with default options
32370
32466
 
@@ -35788,7 +35884,7 @@ function addRenderingByIdPowershellTool(server, config) {
35788
35884
  server.tool("presentation-add-rendering-by-id", "Adds a rendering to presentation of an item specified by item ID.", {
35789
35885
  itemId: stringType().describe("The ID of the item to add the rendering to."),
35790
35886
  renderingId: stringType().describe("The ID of the rendering to add."),
35791
- database: stringType().describe("The context database.").default("master").optional(),
35887
+ database: stringType().describe("The context database.").optional().default("master"),
35792
35888
  placeHolder: stringType().describe("The placeholder to add the rendering to.").optional(),
35793
35889
  dataSource: stringType().describe("The rendering data source.").optional(),
35794
35890
  finalLayout: booleanType()
@@ -35851,7 +35947,7 @@ function setRenderingByIdPowershellTool(server, config) {
35851
35947
  server.tool("presentation-set-rendering-by-id", "Updates rendering specified by item ID with new values.", {
35852
35948
  itemId: stringType().describe("The ID of the item holding the rendering."),
35853
35949
  uniqueId: stringType().describe("The unique ID of the rendering."),
35854
- database: stringType().describe("The context database.").default("master").optional(),
35950
+ database: stringType().describe("The context database.").optional().default("master"),
35855
35951
  placeholder: stringType().describe("New rendering placeholder value if specified.").optional(),
35856
35952
  dataSource: stringType().describe("New rendering data source if specified.").optional(),
35857
35953
  finalLayout: booleanType()
@@ -35888,7 +35984,7 @@ function switchRenderingByIdPowershellTool(server, config) {
35888
35984
  itemId: stringType().describe("The ID of the item holding the renderings."),
35889
35985
  oldRenderingId: stringType().describe("The ID of the rendering to switch."),
35890
35986
  newRenderingId: stringType().describe("The ID of the new rendering."),
35891
- database: stringType().describe("The context database.").default("master").optional(),
35987
+ database: stringType().describe("The context database.").optional().default("master"),
35892
35988
  finalLayout: booleanType()
35893
35989
  .describe("Specifies the layout to update the rendering. If 'true', the final layout is used, otherwise - shared layout.")
35894
35990
  .optional(),
@@ -35957,7 +36053,7 @@ function switchRenderingByUniqueIdPowershellTool(server, config) {
35957
36053
  itemId: stringType().describe("The ID of the item holding the rendering."),
35958
36054
  uniqueId: stringType().describe("The unique ID of the rendering to switch."),
35959
36055
  newRenderingId: stringType().describe("The ID of the new rendering."),
35960
- database: stringType().describe("The context database.").default("master").optional(),
36056
+ database: stringType().describe("The context database.").optional().default("master"),
35961
36057
  finalLayout: booleanType()
35962
36058
  .describe("Specifies the layout to update the rendering. If 'true', the final layout is used, otherwise - shared layout.")
35963
36059
  .optional(),
@@ -36027,7 +36123,7 @@ function addPlaceholderSettingByIdPowershellTool(server, config) {
36027
36123
  itemId: stringType().describe("The ID of the item to add the placeholder setting to."),
36028
36124
  placeholderSettingId: stringType().describe("The ID of the placeholder setting to add."),
36029
36125
  key: stringType().describe("The key of the placeholder setting to add."),
36030
- database: stringType().describe("The context database.").default("master").optional(),
36126
+ database: stringType().describe("The context database.").optional().default("master"),
36031
36127
  finalLayout: booleanType()
36032
36128
  .describe("Specifies layout to add the rendering placeholder setting to. If 'true', the final layout is used, otherwise - shared layout.")
36033
36129
  .optional(),
@@ -36391,18 +36487,19 @@ function formatDate(date) {
36391
36487
  function getLogsPowerShellTool(server, config) {
36392
36488
  server.tool(`logging-get-logs`, `Retrieves Sitecore logs from the log directory.`, {
36393
36489
  name: stringType()
36394
- .default("log")
36395
36490
  .optional()
36491
+ .default("log")
36396
36492
  .describe(`The name of the log file to retrieve. If not provided, defaults to log.*. Possible options: ${logFilePrefixes.join(", ")}.`),
36397
36493
  level: enumType(Object.values(LogLevel))
36494
+ .optional()
36398
36495
  .default(LogLevel.DEBUG)
36399
- .optional(),
36496
+ .describe("The level of the log to retrieve. Defaults to DEBUG."),
36400
36497
  date: stringType()
36401
36498
  .optional()
36402
36499
  .describe(`The date of the log file to retrieve. If not provided, defaults to today. Date format should be in ISO 8601 format (e.g., '2023-10-01T00:00:00Z'`),
36403
36500
  tail: numberType()
36404
- .default(500)
36405
36501
  .optional()
36502
+ .default(500)
36406
36503
  .describe("The number of lines to retrieve from the end of the log file. Defaults to 500."),
36407
36504
  }, async (params) => {
36408
36505
  const stringDate = formatDate(params.date);
@@ -49483,7 +49580,7 @@ function requireRawBody () {
49483
49580
  var rawBodyExports = requireRawBody();
49484
49581
  var getRawBody = /*@__PURE__*/getDefaultExportFromCjs(rawBodyExports);
49485
49582
 
49486
- const MAXIMUM_MESSAGE_SIZE$1 = "4mb";
49583
+ const MAXIMUM_MESSAGE_SIZE$1 = '4mb';
49487
49584
  /**
49488
49585
  * Server transport for SSE: this will send messages over an SSE connection and receive messages from HTTP POST requests.
49489
49586
  *
@@ -49531,12 +49628,12 @@ class SSEServerTransport {
49531
49628
  */
49532
49629
  async start() {
49533
49630
  if (this._sseResponse) {
49534
- throw new Error("SSEServerTransport already started! If using Server class, note that connect() calls start() automatically.");
49631
+ throw new Error('SSEServerTransport already started! If using Server class, note that connect() calls start() automatically.');
49535
49632
  }
49536
49633
  this.res.writeHead(200, {
49537
- "Content-Type": "text/event-stream",
49538
- "Cache-Control": "no-cache, no-transform",
49539
- Connection: "keep-alive",
49634
+ 'Content-Type': 'text/event-stream',
49635
+ 'Cache-Control': 'no-cache, no-transform',
49636
+ Connection: 'keep-alive'
49540
49637
  });
49541
49638
  // Send the endpoint event
49542
49639
  // Use a dummy base URL because this._endpoint is relative.
@@ -49548,7 +49645,7 @@ class SSEServerTransport {
49548
49645
  const relativeUrlWithSession = endpointUrl.pathname + endpointUrl.search + endpointUrl.hash;
49549
49646
  this.res.write(`event: endpoint\ndata: ${relativeUrlWithSession}\n\n`);
49550
49647
  this._sseResponse = this.res;
49551
- this.res.on("close", () => {
49648
+ this.res.on('close', () => {
49552
49649
  var _a;
49553
49650
  this._sseResponse = undefined;
49554
49651
  (_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this);
@@ -49562,7 +49659,7 @@ class SSEServerTransport {
49562
49659
  async handlePostMessage(req, res, parsedBody) {
49563
49660
  var _a, _b, _c, _d;
49564
49661
  if (!this._sseResponse) {
49565
- const message = "SSE connection not established";
49662
+ const message = 'SSE connection not established';
49566
49663
  res.writeHead(500).end(message);
49567
49664
  throw new Error(message);
49568
49665
  }
@@ -49577,14 +49674,15 @@ class SSEServerTransport {
49577
49674
  const requestInfo = { headers: req.headers };
49578
49675
  let body;
49579
49676
  try {
49580
- const ct = contentType.parse((_b = req.headers["content-type"]) !== null && _b !== void 0 ? _b : "");
49581
- if (ct.type !== "application/json") {
49677
+ const ct = contentType.parse((_b = req.headers['content-type']) !== null && _b !== void 0 ? _b : '');
49678
+ if (ct.type !== 'application/json') {
49582
49679
  throw new Error(`Unsupported content-type: ${ct.type}`);
49583
49680
  }
49584
- body = parsedBody !== null && parsedBody !== void 0 ? parsedBody : await getRawBody(req, {
49585
- limit: MAXIMUM_MESSAGE_SIZE$1,
49586
- encoding: (_c = ct.parameters.charset) !== null && _c !== void 0 ? _c : "utf-8",
49587
- });
49681
+ body =
49682
+ parsedBody !== null && parsedBody !== void 0 ? parsedBody : (await getRawBody(req, {
49683
+ limit: MAXIMUM_MESSAGE_SIZE$1,
49684
+ encoding: (_c = ct.parameters.charset) !== null && _c !== void 0 ? _c : 'utf-8'
49685
+ }));
49588
49686
  }
49589
49687
  catch (error) {
49590
49688
  res.writeHead(400).end(String(error));
@@ -49598,7 +49696,7 @@ class SSEServerTransport {
49598
49696
  res.writeHead(400).end(`Invalid message: ${body}`);
49599
49697
  return;
49600
49698
  }
49601
- res.writeHead(202).end("Accepted");
49699
+ res.writeHead(202).end('Accepted');
49602
49700
  }
49603
49701
  /**
49604
49702
  * Handle a client message, regardless of how it arrived. This can be used to inform the server of messages that arrive via a means different than HTTP POST.
@@ -49623,7 +49721,7 @@ class SSEServerTransport {
49623
49721
  }
49624
49722
  async send(message) {
49625
49723
  if (!this._sseResponse) {
49626
- throw new Error("Not connected");
49724
+ throw new Error('Not connected');
49627
49725
  }
49628
49726
  this._sseResponse.write(`event: message\ndata: ${JSON.stringify(message)}\n\n`);
49629
49727
  }
@@ -49682,7 +49780,7 @@ async function startSSE() {
49682
49780
  app.listen(3001);
49683
49781
  }
49684
49782
 
49685
- const MAXIMUM_MESSAGE_SIZE = "4mb";
49783
+ const MAXIMUM_MESSAGE_SIZE = '4mb';
49686
49784
  /**
49687
49785
  * Server transport for Streamable HTTP: this implements the MCP Streamable HTTP transport specification.
49688
49786
  * It supports both SSE streaming and direct HTTP responses.
@@ -49742,7 +49840,7 @@ class StreamableHTTPServerTransport {
49742
49840
  */
49743
49841
  async start() {
49744
49842
  if (this._started) {
49745
- throw new Error("Transport already started");
49843
+ throw new Error('Transport already started');
49746
49844
  }
49747
49845
  this._started = true;
49748
49846
  }
@@ -49780,7 +49878,7 @@ class StreamableHTTPServerTransport {
49780
49878
  const validationError = this.validateRequestHeaders(req);
49781
49879
  if (validationError) {
49782
49880
  res.writeHead(403).end(JSON.stringify({
49783
- jsonrpc: "2.0",
49881
+ jsonrpc: '2.0',
49784
49882
  error: {
49785
49883
  code: -32e3,
49786
49884
  message: validationError
@@ -49790,13 +49888,13 @@ class StreamableHTTPServerTransport {
49790
49888
  (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, new Error(validationError));
49791
49889
  return;
49792
49890
  }
49793
- if (req.method === "POST") {
49891
+ if (req.method === 'POST') {
49794
49892
  await this.handlePostRequest(req, res, parsedBody);
49795
49893
  }
49796
- else if (req.method === "GET") {
49894
+ else if (req.method === 'GET') {
49797
49895
  await this.handleGetRequest(req, res);
49798
49896
  }
49799
- else if (req.method === "DELETE") {
49897
+ else if (req.method === 'DELETE') {
49800
49898
  await this.handleDeleteRequest(req, res);
49801
49899
  }
49802
49900
  else {
@@ -49809,12 +49907,12 @@ class StreamableHTTPServerTransport {
49809
49907
  async handleGetRequest(req, res) {
49810
49908
  // The client MUST include an Accept header, listing text/event-stream as a supported content type.
49811
49909
  const acceptHeader = req.headers.accept;
49812
- if (!(acceptHeader === null || acceptHeader === void 0 ? void 0 : acceptHeader.includes("text/event-stream"))) {
49910
+ if (!(acceptHeader === null || acceptHeader === void 0 ? void 0 : acceptHeader.includes('text/event-stream'))) {
49813
49911
  res.writeHead(406).end(JSON.stringify({
49814
- jsonrpc: "2.0",
49912
+ jsonrpc: '2.0',
49815
49913
  error: {
49816
49914
  code: -32e3,
49817
- message: "Not Acceptable: Client must accept text/event-stream"
49915
+ message: 'Not Acceptable: Client must accept text/event-stream'
49818
49916
  },
49819
49917
  id: null
49820
49918
  }));
@@ -49840,22 +49938,22 @@ class StreamableHTTPServerTransport {
49840
49938
  // The server MUST either return Content-Type: text/event-stream in response to this HTTP GET,
49841
49939
  // or else return HTTP 405 Method Not Allowed
49842
49940
  const headers = {
49843
- "Content-Type": "text/event-stream",
49844
- "Cache-Control": "no-cache, no-transform",
49845
- Connection: "keep-alive",
49941
+ 'Content-Type': 'text/event-stream',
49942
+ 'Cache-Control': 'no-cache, no-transform',
49943
+ Connection: 'keep-alive'
49846
49944
  };
49847
49945
  // After initialization, always include the session ID if we have one
49848
49946
  if (this.sessionId !== undefined) {
49849
- headers["mcp-session-id"] = this.sessionId;
49947
+ headers['mcp-session-id'] = this.sessionId;
49850
49948
  }
49851
49949
  // Check if there's already an active standalone SSE stream for this session
49852
49950
  if (this._streamMapping.get(this._standaloneSseStreamId) !== undefined) {
49853
49951
  // Only one GET SSE stream is allowed per session
49854
49952
  res.writeHead(409).end(JSON.stringify({
49855
- jsonrpc: "2.0",
49953
+ jsonrpc: '2.0',
49856
49954
  error: {
49857
49955
  code: -32e3,
49858
- message: "Conflict: Only one SSE stream is allowed per session"
49956
+ message: 'Conflict: Only one SSE stream is allowed per session'
49859
49957
  },
49860
49958
  id: null
49861
49959
  }));
@@ -49867,9 +49965,14 @@ class StreamableHTTPServerTransport {
49867
49965
  // Assign the response to the standalone SSE stream
49868
49966
  this._streamMapping.set(this._standaloneSseStreamId, res);
49869
49967
  // Set up close handler for client disconnects
49870
- res.on("close", () => {
49968
+ res.on('close', () => {
49871
49969
  this._streamMapping.delete(this._standaloneSseStreamId);
49872
49970
  });
49971
+ // Add error handler for standalone SSE stream
49972
+ res.on('error', error => {
49973
+ var _a;
49974
+ (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error);
49975
+ });
49873
49976
  }
49874
49977
  /**
49875
49978
  * Replays events that would have been sent after the specified event ID
@@ -49882,24 +49985,29 @@ class StreamableHTTPServerTransport {
49882
49985
  }
49883
49986
  try {
49884
49987
  const headers = {
49885
- "Content-Type": "text/event-stream",
49886
- "Cache-Control": "no-cache, no-transform",
49887
- Connection: "keep-alive",
49988
+ 'Content-Type': 'text/event-stream',
49989
+ 'Cache-Control': 'no-cache, no-transform',
49990
+ Connection: 'keep-alive'
49888
49991
  };
49889
49992
  if (this.sessionId !== undefined) {
49890
- headers["mcp-session-id"] = this.sessionId;
49993
+ headers['mcp-session-id'] = this.sessionId;
49891
49994
  }
49892
49995
  res.writeHead(200, headers).flushHeaders();
49893
49996
  const streamId = await ((_a = this._eventStore) === null || _a === void 0 ? void 0 : _a.replayEventsAfter(lastEventId, {
49894
49997
  send: async (eventId, message) => {
49895
49998
  var _a;
49896
49999
  if (!this.writeSSEEvent(res, message, eventId)) {
49897
- (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, new Error("Failed replay events"));
50000
+ (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, new Error('Failed replay events'));
49898
50001
  res.end();
49899
50002
  }
49900
50003
  }
49901
50004
  }));
49902
50005
  this._streamMapping.set(streamId, res);
50006
+ // Add error handler for replay stream
50007
+ res.on('error', error => {
50008
+ var _a;
50009
+ (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error);
50010
+ });
49903
50011
  }
49904
50012
  catch (error) {
49905
50013
  (_b = this.onerror) === null || _b === void 0 ? void 0 : _b.call(this, error);
@@ -49922,12 +50030,12 @@ class StreamableHTTPServerTransport {
49922
50030
  */
49923
50031
  async handleUnsupportedRequest(res) {
49924
50032
  res.writeHead(405, {
49925
- "Allow": "GET, POST, DELETE"
50033
+ Allow: 'GET, POST, DELETE'
49926
50034
  }).end(JSON.stringify({
49927
- jsonrpc: "2.0",
50035
+ jsonrpc: '2.0',
49928
50036
  error: {
49929
50037
  code: -32e3,
49930
- message: "Method not allowed."
50038
+ message: 'Method not allowed.'
49931
50039
  },
49932
50040
  id: null
49933
50041
  }));
@@ -49941,24 +50049,24 @@ class StreamableHTTPServerTransport {
49941
50049
  // Validate the Accept header
49942
50050
  const acceptHeader = req.headers.accept;
49943
50051
  // The client MUST include an Accept header, listing both application/json and text/event-stream as supported content types.
49944
- if (!(acceptHeader === null || acceptHeader === void 0 ? void 0 : acceptHeader.includes("application/json")) || !acceptHeader.includes("text/event-stream")) {
50052
+ if (!(acceptHeader === null || acceptHeader === void 0 ? void 0 : acceptHeader.includes('application/json')) || !acceptHeader.includes('text/event-stream')) {
49945
50053
  res.writeHead(406).end(JSON.stringify({
49946
- jsonrpc: "2.0",
50054
+ jsonrpc: '2.0',
49947
50055
  error: {
49948
50056
  code: -32000,
49949
- message: "Not Acceptable: Client must accept both application/json and text/event-stream"
50057
+ message: 'Not Acceptable: Client must accept both application/json and text/event-stream'
49950
50058
  },
49951
50059
  id: null
49952
50060
  }));
49953
50061
  return;
49954
50062
  }
49955
- const ct = req.headers["content-type"];
49956
- if (!ct || !ct.includes("application/json")) {
50063
+ const ct = req.headers['content-type'];
50064
+ if (!ct || !ct.includes('application/json')) {
49957
50065
  res.writeHead(415).end(JSON.stringify({
49958
- jsonrpc: "2.0",
50066
+ jsonrpc: '2.0',
49959
50067
  error: {
49960
50068
  code: -32000,
49961
- message: "Unsupported Media Type: Content-Type must be application/json"
50069
+ message: 'Unsupported Media Type: Content-Type must be application/json'
49962
50070
  },
49963
50071
  id: null
49964
50072
  }));
@@ -49974,7 +50082,7 @@ class StreamableHTTPServerTransport {
49974
50082
  const parsedCt = contentType.parse(ct);
49975
50083
  const body = await getRawBody(req, {
49976
50084
  limit: MAXIMUM_MESSAGE_SIZE,
49977
- encoding: (_a = parsedCt.parameters.charset) !== null && _a !== void 0 ? _a : "utf-8",
50085
+ encoding: (_a = parsedCt.parameters.charset) !== null && _a !== void 0 ? _a : 'utf-8'
49978
50086
  });
49979
50087
  rawMessage = JSON.parse(body.toString());
49980
50088
  }
@@ -49994,10 +50102,10 @@ class StreamableHTTPServerTransport {
49994
50102
  // to avoid re-initialization.
49995
50103
  if (this._initialized && this.sessionId !== undefined) {
49996
50104
  res.writeHead(400).end(JSON.stringify({
49997
- jsonrpc: "2.0",
50105
+ jsonrpc: '2.0',
49998
50106
  error: {
49999
50107
  code: -32600,
50000
- message: "Invalid Request: Server already initialized"
50108
+ message: 'Invalid Request: Server already initialized'
50001
50109
  },
50002
50110
  id: null
50003
50111
  }));
@@ -50005,10 +50113,10 @@ class StreamableHTTPServerTransport {
50005
50113
  }
50006
50114
  if (messages.length > 1) {
50007
50115
  res.writeHead(400).end(JSON.stringify({
50008
- jsonrpc: "2.0",
50116
+ jsonrpc: '2.0',
50009
50117
  error: {
50010
50118
  code: -32600,
50011
- message: "Invalid Request: Only one initialization request is allowed"
50119
+ message: 'Invalid Request: Only one initialization request is allowed'
50012
50120
  },
50013
50121
  id: null
50014
50122
  }));
@@ -50024,7 +50132,7 @@ class StreamableHTTPServerTransport {
50024
50132
  }
50025
50133
  if (!isInitializationRequest) {
50026
50134
  // If an Mcp-Session-Id is returned by the server during initialization,
50027
- // clients using the Streamable HTTP transport MUST include it
50135
+ // clients using the Streamable HTTP transport MUST include it
50028
50136
  // in the Mcp-Session-Id header on all of their subsequent HTTP requests.
50029
50137
  if (!this.validateSession(req, res)) {
50030
50138
  return;
@@ -50050,13 +50158,13 @@ class StreamableHTTPServerTransport {
50050
50158
  const streamId = randomUUID();
50051
50159
  if (!this._enableJsonResponse) {
50052
50160
  const headers = {
50053
- "Content-Type": "text/event-stream",
50054
- "Cache-Control": "no-cache",
50055
- Connection: "keep-alive",
50161
+ 'Content-Type': 'text/event-stream',
50162
+ 'Cache-Control': 'no-cache',
50163
+ Connection: 'keep-alive'
50056
50164
  };
50057
50165
  // After initialization, always include the session ID if we have one
50058
50166
  if (this.sessionId !== undefined) {
50059
- headers["mcp-session-id"] = this.sessionId;
50167
+ headers['mcp-session-id'] = this.sessionId;
50060
50168
  }
50061
50169
  res.writeHead(200, headers);
50062
50170
  }
@@ -50069,9 +50177,14 @@ class StreamableHTTPServerTransport {
50069
50177
  }
50070
50178
  }
50071
50179
  // Set up close handler for client disconnects
50072
- res.on("close", () => {
50180
+ res.on('close', () => {
50073
50181
  this._streamMapping.delete(streamId);
50074
50182
  });
50183
+ // Add error handler for stream write errors
50184
+ res.on('error', error => {
50185
+ var _a;
50186
+ (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error);
50187
+ });
50075
50188
  // handle each message
50076
50189
  for (const message of messages) {
50077
50190
  (_d = this.onmessage) === null || _d === void 0 ? void 0 : _d.call(this, message, { authInfo, requestInfo });
@@ -50083,10 +50196,10 @@ class StreamableHTTPServerTransport {
50083
50196
  catch (error) {
50084
50197
  // return JSON-RPC formatted error
50085
50198
  res.writeHead(400).end(JSON.stringify({
50086
- jsonrpc: "2.0",
50199
+ jsonrpc: '2.0',
50087
50200
  error: {
50088
50201
  code: -32700,
50089
- message: "Parse error",
50202
+ message: 'Parse error',
50090
50203
  data: String(error)
50091
50204
  },
50092
50205
  id: null
@@ -50122,23 +50235,23 @@ class StreamableHTTPServerTransport {
50122
50235
  if (!this._initialized) {
50123
50236
  // If the server has not been initialized yet, reject all requests
50124
50237
  res.writeHead(400).end(JSON.stringify({
50125
- jsonrpc: "2.0",
50238
+ jsonrpc: '2.0',
50126
50239
  error: {
50127
50240
  code: -32e3,
50128
- message: "Bad Request: Server not initialized"
50241
+ message: 'Bad Request: Server not initialized'
50129
50242
  },
50130
50243
  id: null
50131
50244
  }));
50132
50245
  return false;
50133
50246
  }
50134
- const sessionId = req.headers["mcp-session-id"];
50247
+ const sessionId = req.headers['mcp-session-id'];
50135
50248
  if (!sessionId) {
50136
50249
  // Non-initialization requests without a session ID should return 400 Bad Request
50137
50250
  res.writeHead(400).end(JSON.stringify({
50138
- jsonrpc: "2.0",
50251
+ jsonrpc: '2.0',
50139
50252
  error: {
50140
50253
  code: -32e3,
50141
- message: "Bad Request: Mcp-Session-Id header is required"
50254
+ message: 'Bad Request: Mcp-Session-Id header is required'
50142
50255
  },
50143
50256
  id: null
50144
50257
  }));
@@ -50146,10 +50259,10 @@ class StreamableHTTPServerTransport {
50146
50259
  }
50147
50260
  else if (Array.isArray(sessionId)) {
50148
50261
  res.writeHead(400).end(JSON.stringify({
50149
- jsonrpc: "2.0",
50262
+ jsonrpc: '2.0',
50150
50263
  error: {
50151
50264
  code: -32e3,
50152
- message: "Bad Request: Mcp-Session-Id header must be a single value"
50265
+ message: 'Bad Request: Mcp-Session-Id header must be a single value'
50153
50266
  },
50154
50267
  id: null
50155
50268
  }));
@@ -50158,10 +50271,10 @@ class StreamableHTTPServerTransport {
50158
50271
  else if (sessionId !== this.sessionId) {
50159
50272
  // Reject requests with invalid session ID with 404 Not Found
50160
50273
  res.writeHead(404).end(JSON.stringify({
50161
- jsonrpc: "2.0",
50274
+ jsonrpc: '2.0',
50162
50275
  error: {
50163
50276
  code: -32001,
50164
- message: "Session not found"
50277
+ message: 'Session not found'
50165
50278
  },
50166
50279
  id: null
50167
50280
  }));
@@ -50171,16 +50284,16 @@ class StreamableHTTPServerTransport {
50171
50284
  }
50172
50285
  validateProtocolVersion(req, res) {
50173
50286
  var _a;
50174
- let protocolVersion = (_a = req.headers["mcp-protocol-version"]) !== null && _a !== void 0 ? _a : DEFAULT_NEGOTIATED_PROTOCOL_VERSION;
50287
+ let protocolVersion = (_a = req.headers['mcp-protocol-version']) !== null && _a !== void 0 ? _a : DEFAULT_NEGOTIATED_PROTOCOL_VERSION;
50175
50288
  if (Array.isArray(protocolVersion)) {
50176
50289
  protocolVersion = protocolVersion[protocolVersion.length - 1];
50177
50290
  }
50178
50291
  if (!SUPPORTED_PROTOCOL_VERSIONS.includes(protocolVersion)) {
50179
50292
  res.writeHead(400).end(JSON.stringify({
50180
- jsonrpc: "2.0",
50293
+ jsonrpc: '2.0',
50181
50294
  error: {
50182
50295
  code: -32e3,
50183
- message: `Bad Request: Unsupported protocol version (supported versions: ${SUPPORTED_PROTOCOL_VERSIONS.join(", ")})`
50296
+ message: `Bad Request: Unsupported protocol version (supported versions: ${SUPPORTED_PROTOCOL_VERSIONS.join(', ')})`
50184
50297
  },
50185
50298
  id: null
50186
50299
  }));
@@ -50191,7 +50304,7 @@ class StreamableHTTPServerTransport {
50191
50304
  async close() {
50192
50305
  var _a;
50193
50306
  // Close all SSE connections
50194
- this._streamMapping.forEach((response) => {
50307
+ this._streamMapping.forEach(response => {
50195
50308
  response.end();
50196
50309
  });
50197
50310
  this._streamMapping.clear();
@@ -50211,7 +50324,7 @@ class StreamableHTTPServerTransport {
50211
50324
  if (requestId === undefined) {
50212
50325
  // For standalone SSE streams, we can only send requests and notifications
50213
50326
  if (isJSONRPCResponse(message) || isJSONRPCError(message)) {
50214
- throw new Error("Cannot send a response on a standalone SSE stream unless resuming a previous client request");
50327
+ throw new Error('Cannot send a response on a standalone SSE stream unless resuming a previous client request');
50215
50328
  }
50216
50329
  const standaloneSse = this._streamMapping.get(this._standaloneSseStreamId);
50217
50330
  if (standaloneSse === undefined) {
@@ -50259,13 +50372,12 @@ class StreamableHTTPServerTransport {
50259
50372
  if (this._enableJsonResponse) {
50260
50373
  // All responses ready, send as JSON
50261
50374
  const headers = {
50262
- 'Content-Type': 'application/json',
50375
+ 'Content-Type': 'application/json'
50263
50376
  };
50264
50377
  if (this.sessionId !== undefined) {
50265
50378
  headers['mcp-session-id'] = this.sessionId;
50266
50379
  }
50267
- const responses = relatedIds
50268
- .map(id => this._requestResponseMap.get(id));
50380
+ const responses = relatedIds.map(id => this._requestResponseMap.get(id));
50269
50381
  response.writeHead(200, headers);
50270
50382
  if (responses.length === 1) {
50271
50383
  response.end(JSON.stringify(responses[0]));