dahrk-node 0.1.20 → 0.1.21

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.
@@ -0,0 +1,1568 @@
1
+ #!/usr/bin/env node
2
+
3
+ // ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.29.0_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/types.js
4
+ import * as z from "zod/v4";
5
+ var LATEST_PROTOCOL_VERSION = "2025-11-25";
6
+ var SUPPORTED_PROTOCOL_VERSIONS = [LATEST_PROTOCOL_VERSION, "2025-06-18", "2025-03-26", "2024-11-05", "2024-10-07"];
7
+ var RELATED_TASK_META_KEY = "io.modelcontextprotocol/related-task";
8
+ var JSONRPC_VERSION = "2.0";
9
+ var AssertObjectSchema = z.custom((v) => v !== null && (typeof v === "object" || typeof v === "function"));
10
+ var ProgressTokenSchema = z.union([z.string(), z.number().int()]);
11
+ var CursorSchema = z.string();
12
+ var TaskCreationParamsSchema = z.looseObject({
13
+ /**
14
+ * Requested duration in milliseconds to retain task from creation.
15
+ */
16
+ ttl: z.number().optional(),
17
+ /**
18
+ * Time in milliseconds to wait between task status requests.
19
+ */
20
+ pollInterval: z.number().optional()
21
+ });
22
+ var TaskMetadataSchema = z.object({
23
+ ttl: z.number().optional()
24
+ });
25
+ var RelatedTaskMetadataSchema = z.object({
26
+ taskId: z.string()
27
+ });
28
+ var RequestMetaSchema = z.looseObject({
29
+ /**
30
+ * 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.
31
+ */
32
+ progressToken: ProgressTokenSchema.optional(),
33
+ /**
34
+ * If specified, this request is related to the provided task.
35
+ */
36
+ [RELATED_TASK_META_KEY]: RelatedTaskMetadataSchema.optional()
37
+ });
38
+ var BaseRequestParamsSchema = z.object({
39
+ /**
40
+ * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage.
41
+ */
42
+ _meta: RequestMetaSchema.optional()
43
+ });
44
+ var TaskAugmentedRequestParamsSchema = BaseRequestParamsSchema.extend({
45
+ /**
46
+ * If specified, the caller is requesting task-augmented execution for this request.
47
+ * The request will return a CreateTaskResult immediately, and the actual result can be
48
+ * retrieved later via tasks/result.
49
+ *
50
+ * Task augmentation is subject to capability negotiation - receivers MUST declare support
51
+ * for task augmentation of specific request types in their capabilities.
52
+ */
53
+ task: TaskMetadataSchema.optional()
54
+ });
55
+ var isTaskAugmentedRequestParams = (value) => TaskAugmentedRequestParamsSchema.safeParse(value).success;
56
+ var RequestSchema = z.object({
57
+ method: z.string(),
58
+ params: BaseRequestParamsSchema.loose().optional()
59
+ });
60
+ var NotificationsParamsSchema = z.object({
61
+ /**
62
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
63
+ * for notes on _meta usage.
64
+ */
65
+ _meta: RequestMetaSchema.optional()
66
+ });
67
+ var NotificationSchema = z.object({
68
+ method: z.string(),
69
+ params: NotificationsParamsSchema.loose().optional()
70
+ });
71
+ var ResultSchema = z.looseObject({
72
+ /**
73
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
74
+ * for notes on _meta usage.
75
+ */
76
+ _meta: RequestMetaSchema.optional()
77
+ });
78
+ var RequestIdSchema = z.union([z.string(), z.number().int()]);
79
+ var JSONRPCRequestSchema = z.object({
80
+ jsonrpc: z.literal(JSONRPC_VERSION),
81
+ id: RequestIdSchema,
82
+ ...RequestSchema.shape
83
+ }).strict();
84
+ var isJSONRPCRequest = (value) => JSONRPCRequestSchema.safeParse(value).success;
85
+ var JSONRPCNotificationSchema = z.object({
86
+ jsonrpc: z.literal(JSONRPC_VERSION),
87
+ ...NotificationSchema.shape
88
+ }).strict();
89
+ var isJSONRPCNotification = (value) => JSONRPCNotificationSchema.safeParse(value).success;
90
+ var JSONRPCResultResponseSchema = z.object({
91
+ jsonrpc: z.literal(JSONRPC_VERSION),
92
+ id: RequestIdSchema,
93
+ result: ResultSchema
94
+ }).strict();
95
+ var isJSONRPCResultResponse = (value) => JSONRPCResultResponseSchema.safeParse(value).success;
96
+ var ErrorCode;
97
+ (function(ErrorCode2) {
98
+ ErrorCode2[ErrorCode2["ConnectionClosed"] = -32e3] = "ConnectionClosed";
99
+ ErrorCode2[ErrorCode2["RequestTimeout"] = -32001] = "RequestTimeout";
100
+ ErrorCode2[ErrorCode2["ParseError"] = -32700] = "ParseError";
101
+ ErrorCode2[ErrorCode2["InvalidRequest"] = -32600] = "InvalidRequest";
102
+ ErrorCode2[ErrorCode2["MethodNotFound"] = -32601] = "MethodNotFound";
103
+ ErrorCode2[ErrorCode2["InvalidParams"] = -32602] = "InvalidParams";
104
+ ErrorCode2[ErrorCode2["InternalError"] = -32603] = "InternalError";
105
+ ErrorCode2[ErrorCode2["UrlElicitationRequired"] = -32042] = "UrlElicitationRequired";
106
+ })(ErrorCode || (ErrorCode = {}));
107
+ var JSONRPCErrorResponseSchema = z.object({
108
+ jsonrpc: z.literal(JSONRPC_VERSION),
109
+ id: RequestIdSchema.optional(),
110
+ error: z.object({
111
+ /**
112
+ * The error type that occurred.
113
+ */
114
+ code: z.number().int(),
115
+ /**
116
+ * A short description of the error. The message SHOULD be limited to a concise single sentence.
117
+ */
118
+ message: z.string(),
119
+ /**
120
+ * Additional information about the error. The value of this member is defined by the sender (e.g. detailed error information, nested errors etc.).
121
+ */
122
+ data: z.unknown().optional()
123
+ })
124
+ }).strict();
125
+ var isJSONRPCErrorResponse = (value) => JSONRPCErrorResponseSchema.safeParse(value).success;
126
+ var JSONRPCMessageSchema = z.union([
127
+ JSONRPCRequestSchema,
128
+ JSONRPCNotificationSchema,
129
+ JSONRPCResultResponseSchema,
130
+ JSONRPCErrorResponseSchema
131
+ ]);
132
+ var JSONRPCResponseSchema = z.union([JSONRPCResultResponseSchema, JSONRPCErrorResponseSchema]);
133
+ var EmptyResultSchema = ResultSchema.strict();
134
+ var CancelledNotificationParamsSchema = NotificationsParamsSchema.extend({
135
+ /**
136
+ * The ID of the request to cancel.
137
+ *
138
+ * This MUST correspond to the ID of a request previously issued in the same direction.
139
+ */
140
+ requestId: RequestIdSchema.optional(),
141
+ /**
142
+ * An optional string describing the reason for the cancellation. This MAY be logged or presented to the user.
143
+ */
144
+ reason: z.string().optional()
145
+ });
146
+ var CancelledNotificationSchema = NotificationSchema.extend({
147
+ method: z.literal("notifications/cancelled"),
148
+ params: CancelledNotificationParamsSchema
149
+ });
150
+ var IconSchema = z.object({
151
+ /**
152
+ * URL or data URI for the icon.
153
+ */
154
+ src: z.string(),
155
+ /**
156
+ * Optional MIME type for the icon.
157
+ */
158
+ mimeType: z.string().optional(),
159
+ /**
160
+ * Optional array of strings that specify sizes at which the icon can be used.
161
+ * Each string should be in WxH format (e.g., `"48x48"`, `"96x96"`) or `"any"` for scalable formats like SVG.
162
+ *
163
+ * If not provided, the client should assume that the icon can be used at any size.
164
+ */
165
+ sizes: z.array(z.string()).optional(),
166
+ /**
167
+ * Optional specifier for the theme this icon is designed for. `light` indicates
168
+ * the icon is designed to be used with a light background, and `dark` indicates
169
+ * the icon is designed to be used with a dark background.
170
+ *
171
+ * If not provided, the client should assume the icon can be used with any theme.
172
+ */
173
+ theme: z.enum(["light", "dark"]).optional()
174
+ });
175
+ var IconsSchema = z.object({
176
+ /**
177
+ * Optional set of sized icons that the client can display in a user interface.
178
+ *
179
+ * Clients that support rendering icons MUST support at least the following MIME types:
180
+ * - `image/png` - PNG images (safe, universal compatibility)
181
+ * - `image/jpeg` (and `image/jpg`) - JPEG images (safe, universal compatibility)
182
+ *
183
+ * Clients that support rendering icons SHOULD also support:
184
+ * - `image/svg+xml` - SVG images (scalable but requires security precautions)
185
+ * - `image/webp` - WebP images (modern, efficient format)
186
+ */
187
+ icons: z.array(IconSchema).optional()
188
+ });
189
+ var BaseMetadataSchema = z.object({
190
+ /** Intended for programmatic or logical use, but used as a display name in past specs or fallback */
191
+ name: z.string(),
192
+ /**
193
+ * Intended for UI and end-user contexts — optimized to be human-readable and easily understood,
194
+ * even by those unfamiliar with domain-specific terminology.
195
+ *
196
+ * If not provided, the name should be used for display (except for Tool,
197
+ * where `annotations.title` should be given precedence over using `name`,
198
+ * if present).
199
+ */
200
+ title: z.string().optional()
201
+ });
202
+ var ImplementationSchema = BaseMetadataSchema.extend({
203
+ ...BaseMetadataSchema.shape,
204
+ ...IconsSchema.shape,
205
+ version: z.string(),
206
+ /**
207
+ * An optional URL of the website for this implementation.
208
+ */
209
+ websiteUrl: z.string().optional(),
210
+ /**
211
+ * An optional human-readable description of what this implementation does.
212
+ *
213
+ * This can be used by clients or servers to provide context about their purpose
214
+ * and capabilities. For example, a server might describe the types of resources
215
+ * or tools it provides, while a client might describe its intended use case.
216
+ */
217
+ description: z.string().optional()
218
+ });
219
+ var FormElicitationCapabilitySchema = z.intersection(z.object({
220
+ applyDefaults: z.boolean().optional()
221
+ }), z.record(z.string(), z.unknown()));
222
+ var ElicitationCapabilitySchema = z.preprocess((value) => {
223
+ if (value && typeof value === "object" && !Array.isArray(value)) {
224
+ if (Object.keys(value).length === 0) {
225
+ return { form: {} };
226
+ }
227
+ }
228
+ return value;
229
+ }, z.intersection(z.object({
230
+ form: FormElicitationCapabilitySchema.optional(),
231
+ url: AssertObjectSchema.optional()
232
+ }), z.record(z.string(), z.unknown()).optional()));
233
+ var ClientTasksCapabilitySchema = z.looseObject({
234
+ /**
235
+ * Present if the client supports listing tasks.
236
+ */
237
+ list: AssertObjectSchema.optional(),
238
+ /**
239
+ * Present if the client supports cancelling tasks.
240
+ */
241
+ cancel: AssertObjectSchema.optional(),
242
+ /**
243
+ * Capabilities for task creation on specific request types.
244
+ */
245
+ requests: z.looseObject({
246
+ /**
247
+ * Task support for sampling requests.
248
+ */
249
+ sampling: z.looseObject({
250
+ createMessage: AssertObjectSchema.optional()
251
+ }).optional(),
252
+ /**
253
+ * Task support for elicitation requests.
254
+ */
255
+ elicitation: z.looseObject({
256
+ create: AssertObjectSchema.optional()
257
+ }).optional()
258
+ }).optional()
259
+ });
260
+ var ServerTasksCapabilitySchema = z.looseObject({
261
+ /**
262
+ * Present if the server supports listing tasks.
263
+ */
264
+ list: AssertObjectSchema.optional(),
265
+ /**
266
+ * Present if the server supports cancelling tasks.
267
+ */
268
+ cancel: AssertObjectSchema.optional(),
269
+ /**
270
+ * Capabilities for task creation on specific request types.
271
+ */
272
+ requests: z.looseObject({
273
+ /**
274
+ * Task support for tool requests.
275
+ */
276
+ tools: z.looseObject({
277
+ call: AssertObjectSchema.optional()
278
+ }).optional()
279
+ }).optional()
280
+ });
281
+ var ClientCapabilitiesSchema = z.object({
282
+ /**
283
+ * Experimental, non-standard capabilities that the client supports.
284
+ */
285
+ experimental: z.record(z.string(), AssertObjectSchema).optional(),
286
+ /**
287
+ * Present if the client supports sampling from an LLM.
288
+ */
289
+ sampling: z.object({
290
+ /**
291
+ * Present if the client supports context inclusion via includeContext parameter.
292
+ * If not declared, servers SHOULD only use `includeContext: "none"` (or omit it).
293
+ */
294
+ context: AssertObjectSchema.optional(),
295
+ /**
296
+ * Present if the client supports tool use via tools and toolChoice parameters.
297
+ */
298
+ tools: AssertObjectSchema.optional()
299
+ }).optional(),
300
+ /**
301
+ * Present if the client supports eliciting user input.
302
+ */
303
+ elicitation: ElicitationCapabilitySchema.optional(),
304
+ /**
305
+ * Present if the client supports listing roots.
306
+ */
307
+ roots: z.object({
308
+ /**
309
+ * Whether the client supports issuing notifications for changes to the roots list.
310
+ */
311
+ listChanged: z.boolean().optional()
312
+ }).optional(),
313
+ /**
314
+ * Present if the client supports task creation.
315
+ */
316
+ tasks: ClientTasksCapabilitySchema.optional(),
317
+ /**
318
+ * Extensions that the client supports. Keys are extension identifiers (vendor-prefix/extension-name).
319
+ */
320
+ extensions: z.record(z.string(), AssertObjectSchema).optional()
321
+ });
322
+ var InitializeRequestParamsSchema = BaseRequestParamsSchema.extend({
323
+ /**
324
+ * The latest version of the Model Context Protocol that the client supports. The client MAY decide to support older versions as well.
325
+ */
326
+ protocolVersion: z.string(),
327
+ capabilities: ClientCapabilitiesSchema,
328
+ clientInfo: ImplementationSchema
329
+ });
330
+ var InitializeRequestSchema = RequestSchema.extend({
331
+ method: z.literal("initialize"),
332
+ params: InitializeRequestParamsSchema
333
+ });
334
+ var ServerCapabilitiesSchema = z.object({
335
+ /**
336
+ * Experimental, non-standard capabilities that the server supports.
337
+ */
338
+ experimental: z.record(z.string(), AssertObjectSchema).optional(),
339
+ /**
340
+ * Present if the server supports sending log messages to the client.
341
+ */
342
+ logging: AssertObjectSchema.optional(),
343
+ /**
344
+ * Present if the server supports sending completions to the client.
345
+ */
346
+ completions: AssertObjectSchema.optional(),
347
+ /**
348
+ * Present if the server offers any prompt templates.
349
+ */
350
+ prompts: z.object({
351
+ /**
352
+ * Whether this server supports issuing notifications for changes to the prompt list.
353
+ */
354
+ listChanged: z.boolean().optional()
355
+ }).optional(),
356
+ /**
357
+ * Present if the server offers any resources to read.
358
+ */
359
+ resources: z.object({
360
+ /**
361
+ * Whether this server supports clients subscribing to resource updates.
362
+ */
363
+ subscribe: z.boolean().optional(),
364
+ /**
365
+ * Whether this server supports issuing notifications for changes to the resource list.
366
+ */
367
+ listChanged: z.boolean().optional()
368
+ }).optional(),
369
+ /**
370
+ * Present if the server offers any tools to call.
371
+ */
372
+ tools: z.object({
373
+ /**
374
+ * Whether this server supports issuing notifications for changes to the tool list.
375
+ */
376
+ listChanged: z.boolean().optional()
377
+ }).optional(),
378
+ /**
379
+ * Present if the server supports task creation.
380
+ */
381
+ tasks: ServerTasksCapabilitySchema.optional(),
382
+ /**
383
+ * Extensions that the server supports. Keys are extension identifiers (vendor-prefix/extension-name).
384
+ */
385
+ extensions: z.record(z.string(), AssertObjectSchema).optional()
386
+ });
387
+ var InitializeResultSchema = ResultSchema.extend({
388
+ /**
389
+ * The version of the Model Context Protocol that the server wants to use. This may not match the version that the client requested. If the client cannot support this version, it MUST disconnect.
390
+ */
391
+ protocolVersion: z.string(),
392
+ capabilities: ServerCapabilitiesSchema,
393
+ serverInfo: ImplementationSchema,
394
+ /**
395
+ * Instructions describing how to use the server and its features.
396
+ *
397
+ * 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.
398
+ */
399
+ instructions: z.string().optional()
400
+ });
401
+ var InitializedNotificationSchema = NotificationSchema.extend({
402
+ method: z.literal("notifications/initialized"),
403
+ params: NotificationsParamsSchema.optional()
404
+ });
405
+ var isInitializedNotification = (value) => InitializedNotificationSchema.safeParse(value).success;
406
+ var PingRequestSchema = RequestSchema.extend({
407
+ method: z.literal("ping"),
408
+ params: BaseRequestParamsSchema.optional()
409
+ });
410
+ var ProgressSchema = z.object({
411
+ /**
412
+ * The progress thus far. This should increase every time progress is made, even if the total is unknown.
413
+ */
414
+ progress: z.number(),
415
+ /**
416
+ * Total number of items to process (or total progress required), if known.
417
+ */
418
+ total: z.optional(z.number()),
419
+ /**
420
+ * An optional message describing the current progress.
421
+ */
422
+ message: z.optional(z.string())
423
+ });
424
+ var ProgressNotificationParamsSchema = z.object({
425
+ ...NotificationsParamsSchema.shape,
426
+ ...ProgressSchema.shape,
427
+ /**
428
+ * The progress token which was given in the initial request, used to associate this notification with the request that is proceeding.
429
+ */
430
+ progressToken: ProgressTokenSchema
431
+ });
432
+ var ProgressNotificationSchema = NotificationSchema.extend({
433
+ method: z.literal("notifications/progress"),
434
+ params: ProgressNotificationParamsSchema
435
+ });
436
+ var PaginatedRequestParamsSchema = BaseRequestParamsSchema.extend({
437
+ /**
438
+ * An opaque token representing the current pagination position.
439
+ * If provided, the server should return results starting after this cursor.
440
+ */
441
+ cursor: CursorSchema.optional()
442
+ });
443
+ var PaginatedRequestSchema = RequestSchema.extend({
444
+ params: PaginatedRequestParamsSchema.optional()
445
+ });
446
+ var PaginatedResultSchema = ResultSchema.extend({
447
+ /**
448
+ * An opaque token representing the pagination position after the last returned result.
449
+ * If present, there may be more results available.
450
+ */
451
+ nextCursor: CursorSchema.optional()
452
+ });
453
+ var TaskStatusSchema = z.enum(["working", "input_required", "completed", "failed", "cancelled"]);
454
+ var TaskSchema = z.object({
455
+ taskId: z.string(),
456
+ status: TaskStatusSchema,
457
+ /**
458
+ * Time in milliseconds to keep task results available after completion.
459
+ * If null, the task has unlimited lifetime until manually cleaned up.
460
+ */
461
+ ttl: z.union([z.number(), z.null()]),
462
+ /**
463
+ * ISO 8601 timestamp when the task was created.
464
+ */
465
+ createdAt: z.string(),
466
+ /**
467
+ * ISO 8601 timestamp when the task was last updated.
468
+ */
469
+ lastUpdatedAt: z.string(),
470
+ pollInterval: z.optional(z.number()),
471
+ /**
472
+ * Optional diagnostic message for failed tasks or other status information.
473
+ */
474
+ statusMessage: z.optional(z.string())
475
+ });
476
+ var CreateTaskResultSchema = ResultSchema.extend({
477
+ task: TaskSchema
478
+ });
479
+ var TaskStatusNotificationParamsSchema = NotificationsParamsSchema.merge(TaskSchema);
480
+ var TaskStatusNotificationSchema = NotificationSchema.extend({
481
+ method: z.literal("notifications/tasks/status"),
482
+ params: TaskStatusNotificationParamsSchema
483
+ });
484
+ var GetTaskRequestSchema = RequestSchema.extend({
485
+ method: z.literal("tasks/get"),
486
+ params: BaseRequestParamsSchema.extend({
487
+ taskId: z.string()
488
+ })
489
+ });
490
+ var GetTaskResultSchema = ResultSchema.merge(TaskSchema);
491
+ var GetTaskPayloadRequestSchema = RequestSchema.extend({
492
+ method: z.literal("tasks/result"),
493
+ params: BaseRequestParamsSchema.extend({
494
+ taskId: z.string()
495
+ })
496
+ });
497
+ var GetTaskPayloadResultSchema = ResultSchema.loose();
498
+ var ListTasksRequestSchema = PaginatedRequestSchema.extend({
499
+ method: z.literal("tasks/list")
500
+ });
501
+ var ListTasksResultSchema = PaginatedResultSchema.extend({
502
+ tasks: z.array(TaskSchema)
503
+ });
504
+ var CancelTaskRequestSchema = RequestSchema.extend({
505
+ method: z.literal("tasks/cancel"),
506
+ params: BaseRequestParamsSchema.extend({
507
+ taskId: z.string()
508
+ })
509
+ });
510
+ var CancelTaskResultSchema = ResultSchema.merge(TaskSchema);
511
+ var ResourceContentsSchema = z.object({
512
+ /**
513
+ * The URI of this resource.
514
+ */
515
+ uri: z.string(),
516
+ /**
517
+ * The MIME type of this resource, if known.
518
+ */
519
+ mimeType: z.optional(z.string()),
520
+ /**
521
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
522
+ * for notes on _meta usage.
523
+ */
524
+ _meta: z.record(z.string(), z.unknown()).optional()
525
+ });
526
+ var TextResourceContentsSchema = ResourceContentsSchema.extend({
527
+ /**
528
+ * The text of the item. This must only be set if the item can actually be represented as text (not binary data).
529
+ */
530
+ text: z.string()
531
+ });
532
+ var Base64Schema = z.string().refine((val) => {
533
+ try {
534
+ atob(val);
535
+ return true;
536
+ } catch {
537
+ return false;
538
+ }
539
+ }, { message: "Invalid Base64 string" });
540
+ var BlobResourceContentsSchema = ResourceContentsSchema.extend({
541
+ /**
542
+ * A base64-encoded string representing the binary data of the item.
543
+ */
544
+ blob: Base64Schema
545
+ });
546
+ var RoleSchema = z.enum(["user", "assistant"]);
547
+ var AnnotationsSchema = z.object({
548
+ /**
549
+ * Intended audience(s) for the resource.
550
+ */
551
+ audience: z.array(RoleSchema).optional(),
552
+ /**
553
+ * Importance hint for the resource, from 0 (least) to 1 (most).
554
+ */
555
+ priority: z.number().min(0).max(1).optional(),
556
+ /**
557
+ * ISO 8601 timestamp for the most recent modification.
558
+ */
559
+ lastModified: z.iso.datetime({ offset: true }).optional()
560
+ });
561
+ var ResourceSchema = z.object({
562
+ ...BaseMetadataSchema.shape,
563
+ ...IconsSchema.shape,
564
+ /**
565
+ * The URI of this resource.
566
+ */
567
+ uri: z.string(),
568
+ /**
569
+ * A description of what this resource represents.
570
+ *
571
+ * This can be used by clients to improve the LLM's understanding of available resources. It can be thought of like a "hint" to the model.
572
+ */
573
+ description: z.optional(z.string()),
574
+ /**
575
+ * The MIME type of this resource, if known.
576
+ */
577
+ mimeType: z.optional(z.string()),
578
+ /**
579
+ * The size of the raw resource content, in bytes (i.e., before base64 encoding or any tokenization), if known.
580
+ *
581
+ * This can be used by Hosts to display file sizes and estimate context window usage.
582
+ */
583
+ size: z.optional(z.number()),
584
+ /**
585
+ * Optional annotations for the client.
586
+ */
587
+ annotations: AnnotationsSchema.optional(),
588
+ /**
589
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
590
+ * for notes on _meta usage.
591
+ */
592
+ _meta: z.optional(z.looseObject({}))
593
+ });
594
+ var ResourceTemplateSchema = z.object({
595
+ ...BaseMetadataSchema.shape,
596
+ ...IconsSchema.shape,
597
+ /**
598
+ * A URI template (according to RFC 6570) that can be used to construct resource URIs.
599
+ */
600
+ uriTemplate: z.string(),
601
+ /**
602
+ * A description of what this template is for.
603
+ *
604
+ * This can be used by clients to improve the LLM's understanding of available resources. It can be thought of like a "hint" to the model.
605
+ */
606
+ description: z.optional(z.string()),
607
+ /**
608
+ * The MIME type for all resources that match this template. This should only be included if all resources matching this template have the same type.
609
+ */
610
+ mimeType: z.optional(z.string()),
611
+ /**
612
+ * Optional annotations for the client.
613
+ */
614
+ annotations: AnnotationsSchema.optional(),
615
+ /**
616
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
617
+ * for notes on _meta usage.
618
+ */
619
+ _meta: z.optional(z.looseObject({}))
620
+ });
621
+ var ListResourcesRequestSchema = PaginatedRequestSchema.extend({
622
+ method: z.literal("resources/list")
623
+ });
624
+ var ListResourcesResultSchema = PaginatedResultSchema.extend({
625
+ resources: z.array(ResourceSchema)
626
+ });
627
+ var ListResourceTemplatesRequestSchema = PaginatedRequestSchema.extend({
628
+ method: z.literal("resources/templates/list")
629
+ });
630
+ var ListResourceTemplatesResultSchema = PaginatedResultSchema.extend({
631
+ resourceTemplates: z.array(ResourceTemplateSchema)
632
+ });
633
+ var ResourceRequestParamsSchema = BaseRequestParamsSchema.extend({
634
+ /**
635
+ * The URI of the resource to read. The URI can use any protocol; it is up to the server how to interpret it.
636
+ *
637
+ * @format uri
638
+ */
639
+ uri: z.string()
640
+ });
641
+ var ReadResourceRequestParamsSchema = ResourceRequestParamsSchema;
642
+ var ReadResourceRequestSchema = RequestSchema.extend({
643
+ method: z.literal("resources/read"),
644
+ params: ReadResourceRequestParamsSchema
645
+ });
646
+ var ReadResourceResultSchema = ResultSchema.extend({
647
+ contents: z.array(z.union([TextResourceContentsSchema, BlobResourceContentsSchema]))
648
+ });
649
+ var ResourceListChangedNotificationSchema = NotificationSchema.extend({
650
+ method: z.literal("notifications/resources/list_changed"),
651
+ params: NotificationsParamsSchema.optional()
652
+ });
653
+ var SubscribeRequestParamsSchema = ResourceRequestParamsSchema;
654
+ var SubscribeRequestSchema = RequestSchema.extend({
655
+ method: z.literal("resources/subscribe"),
656
+ params: SubscribeRequestParamsSchema
657
+ });
658
+ var UnsubscribeRequestParamsSchema = ResourceRequestParamsSchema;
659
+ var UnsubscribeRequestSchema = RequestSchema.extend({
660
+ method: z.literal("resources/unsubscribe"),
661
+ params: UnsubscribeRequestParamsSchema
662
+ });
663
+ var ResourceUpdatedNotificationParamsSchema = NotificationsParamsSchema.extend({
664
+ /**
665
+ * The URI of the resource that has been updated. This might be a sub-resource of the one that the client actually subscribed to.
666
+ */
667
+ uri: z.string()
668
+ });
669
+ var ResourceUpdatedNotificationSchema = NotificationSchema.extend({
670
+ method: z.literal("notifications/resources/updated"),
671
+ params: ResourceUpdatedNotificationParamsSchema
672
+ });
673
+ var PromptArgumentSchema = z.object({
674
+ /**
675
+ * The name of the argument.
676
+ */
677
+ name: z.string(),
678
+ /**
679
+ * A human-readable description of the argument.
680
+ */
681
+ description: z.optional(z.string()),
682
+ /**
683
+ * Whether this argument must be provided.
684
+ */
685
+ required: z.optional(z.boolean())
686
+ });
687
+ var PromptSchema = z.object({
688
+ ...BaseMetadataSchema.shape,
689
+ ...IconsSchema.shape,
690
+ /**
691
+ * An optional description of what this prompt provides
692
+ */
693
+ description: z.optional(z.string()),
694
+ /**
695
+ * A list of arguments to use for templating the prompt.
696
+ */
697
+ arguments: z.optional(z.array(PromptArgumentSchema)),
698
+ /**
699
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
700
+ * for notes on _meta usage.
701
+ */
702
+ _meta: z.optional(z.looseObject({}))
703
+ });
704
+ var ListPromptsRequestSchema = PaginatedRequestSchema.extend({
705
+ method: z.literal("prompts/list")
706
+ });
707
+ var ListPromptsResultSchema = PaginatedResultSchema.extend({
708
+ prompts: z.array(PromptSchema)
709
+ });
710
+ var GetPromptRequestParamsSchema = BaseRequestParamsSchema.extend({
711
+ /**
712
+ * The name of the prompt or prompt template.
713
+ */
714
+ name: z.string(),
715
+ /**
716
+ * Arguments to use for templating the prompt.
717
+ */
718
+ arguments: z.record(z.string(), z.string()).optional()
719
+ });
720
+ var GetPromptRequestSchema = RequestSchema.extend({
721
+ method: z.literal("prompts/get"),
722
+ params: GetPromptRequestParamsSchema
723
+ });
724
+ var TextContentSchema = z.object({
725
+ type: z.literal("text"),
726
+ /**
727
+ * The text content of the message.
728
+ */
729
+ text: z.string(),
730
+ /**
731
+ * Optional annotations for the client.
732
+ */
733
+ annotations: AnnotationsSchema.optional(),
734
+ /**
735
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
736
+ * for notes on _meta usage.
737
+ */
738
+ _meta: z.record(z.string(), z.unknown()).optional()
739
+ });
740
+ var ImageContentSchema = z.object({
741
+ type: z.literal("image"),
742
+ /**
743
+ * The base64-encoded image data.
744
+ */
745
+ data: Base64Schema,
746
+ /**
747
+ * The MIME type of the image. Different providers may support different image types.
748
+ */
749
+ mimeType: z.string(),
750
+ /**
751
+ * Optional annotations for the client.
752
+ */
753
+ annotations: AnnotationsSchema.optional(),
754
+ /**
755
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
756
+ * for notes on _meta usage.
757
+ */
758
+ _meta: z.record(z.string(), z.unknown()).optional()
759
+ });
760
+ var AudioContentSchema = z.object({
761
+ type: z.literal("audio"),
762
+ /**
763
+ * The base64-encoded audio data.
764
+ */
765
+ data: Base64Schema,
766
+ /**
767
+ * The MIME type of the audio. Different providers may support different audio types.
768
+ */
769
+ mimeType: z.string(),
770
+ /**
771
+ * Optional annotations for the client.
772
+ */
773
+ annotations: AnnotationsSchema.optional(),
774
+ /**
775
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
776
+ * for notes on _meta usage.
777
+ */
778
+ _meta: z.record(z.string(), z.unknown()).optional()
779
+ });
780
+ var ToolUseContentSchema = z.object({
781
+ type: z.literal("tool_use"),
782
+ /**
783
+ * The name of the tool to invoke.
784
+ * Must match a tool name from the request's tools array.
785
+ */
786
+ name: z.string(),
787
+ /**
788
+ * Unique identifier for this tool call.
789
+ * Used to correlate with ToolResultContent in subsequent messages.
790
+ */
791
+ id: z.string(),
792
+ /**
793
+ * Arguments to pass to the tool.
794
+ * Must conform to the tool's inputSchema.
795
+ */
796
+ input: z.record(z.string(), z.unknown()),
797
+ /**
798
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
799
+ * for notes on _meta usage.
800
+ */
801
+ _meta: z.record(z.string(), z.unknown()).optional()
802
+ });
803
+ var EmbeddedResourceSchema = z.object({
804
+ type: z.literal("resource"),
805
+ resource: z.union([TextResourceContentsSchema, BlobResourceContentsSchema]),
806
+ /**
807
+ * Optional annotations for the client.
808
+ */
809
+ annotations: AnnotationsSchema.optional(),
810
+ /**
811
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
812
+ * for notes on _meta usage.
813
+ */
814
+ _meta: z.record(z.string(), z.unknown()).optional()
815
+ });
816
+ var ResourceLinkSchema = ResourceSchema.extend({
817
+ type: z.literal("resource_link")
818
+ });
819
+ var ContentBlockSchema = z.union([
820
+ TextContentSchema,
821
+ ImageContentSchema,
822
+ AudioContentSchema,
823
+ ResourceLinkSchema,
824
+ EmbeddedResourceSchema
825
+ ]);
826
+ var PromptMessageSchema = z.object({
827
+ role: RoleSchema,
828
+ content: ContentBlockSchema
829
+ });
830
+ var GetPromptResultSchema = ResultSchema.extend({
831
+ /**
832
+ * An optional description for the prompt.
833
+ */
834
+ description: z.string().optional(),
835
+ messages: z.array(PromptMessageSchema)
836
+ });
837
+ var PromptListChangedNotificationSchema = NotificationSchema.extend({
838
+ method: z.literal("notifications/prompts/list_changed"),
839
+ params: NotificationsParamsSchema.optional()
840
+ });
841
+ var ToolAnnotationsSchema = z.object({
842
+ /**
843
+ * A human-readable title for the tool.
844
+ */
845
+ title: z.string().optional(),
846
+ /**
847
+ * If true, the tool does not modify its environment.
848
+ *
849
+ * Default: false
850
+ */
851
+ readOnlyHint: z.boolean().optional(),
852
+ /**
853
+ * If true, the tool may perform destructive updates to its environment.
854
+ * If false, the tool performs only additive updates.
855
+ *
856
+ * (This property is meaningful only when `readOnlyHint == false`)
857
+ *
858
+ * Default: true
859
+ */
860
+ destructiveHint: z.boolean().optional(),
861
+ /**
862
+ * If true, calling the tool repeatedly with the same arguments
863
+ * will have no additional effect on the its environment.
864
+ *
865
+ * (This property is meaningful only when `readOnlyHint == false`)
866
+ *
867
+ * Default: false
868
+ */
869
+ idempotentHint: z.boolean().optional(),
870
+ /**
871
+ * If true, this tool may interact with an "open world" of external
872
+ * entities. If false, the tool's domain of interaction is closed.
873
+ * For example, the world of a web search tool is open, whereas that
874
+ * of a memory tool is not.
875
+ *
876
+ * Default: true
877
+ */
878
+ openWorldHint: z.boolean().optional()
879
+ });
880
+ var ToolExecutionSchema = z.object({
881
+ /**
882
+ * Indicates the tool's preference for task-augmented execution.
883
+ * - "required": Clients MUST invoke the tool as a task
884
+ * - "optional": Clients MAY invoke the tool as a task or normal request
885
+ * - "forbidden": Clients MUST NOT attempt to invoke the tool as a task
886
+ *
887
+ * If not present, defaults to "forbidden".
888
+ */
889
+ taskSupport: z.enum(["required", "optional", "forbidden"]).optional()
890
+ });
891
+ var ToolSchema = z.object({
892
+ ...BaseMetadataSchema.shape,
893
+ ...IconsSchema.shape,
894
+ /**
895
+ * A human-readable description of the tool.
896
+ */
897
+ description: z.string().optional(),
898
+ /**
899
+ * A JSON Schema 2020-12 object defining the expected parameters for the tool.
900
+ * Must have type: 'object' at the root level per MCP spec.
901
+ */
902
+ inputSchema: z.object({
903
+ type: z.literal("object"),
904
+ properties: z.record(z.string(), AssertObjectSchema).optional(),
905
+ required: z.array(z.string()).optional()
906
+ }).catchall(z.unknown()),
907
+ /**
908
+ * An optional JSON Schema 2020-12 object defining the structure of the tool's output
909
+ * returned in the structuredContent field of a CallToolResult.
910
+ * Must have type: 'object' at the root level per MCP spec.
911
+ */
912
+ outputSchema: z.object({
913
+ type: z.literal("object"),
914
+ properties: z.record(z.string(), AssertObjectSchema).optional(),
915
+ required: z.array(z.string()).optional()
916
+ }).catchall(z.unknown()).optional(),
917
+ /**
918
+ * Optional additional tool information.
919
+ */
920
+ annotations: ToolAnnotationsSchema.optional(),
921
+ /**
922
+ * Execution-related properties for this tool.
923
+ */
924
+ execution: ToolExecutionSchema.optional(),
925
+ /**
926
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
927
+ * for notes on _meta usage.
928
+ */
929
+ _meta: z.record(z.string(), z.unknown()).optional()
930
+ });
931
+ var ListToolsRequestSchema = PaginatedRequestSchema.extend({
932
+ method: z.literal("tools/list")
933
+ });
934
+ var ListToolsResultSchema = PaginatedResultSchema.extend({
935
+ tools: z.array(ToolSchema)
936
+ });
937
+ var CallToolResultSchema = ResultSchema.extend({
938
+ /**
939
+ * A list of content objects that represent the result of the tool call.
940
+ *
941
+ * If the Tool does not define an outputSchema, this field MUST be present in the result.
942
+ * For backwards compatibility, this field is always present, but it may be empty.
943
+ */
944
+ content: z.array(ContentBlockSchema).default([]),
945
+ /**
946
+ * An object containing structured tool output.
947
+ *
948
+ * If the Tool defines an outputSchema, this field MUST be present in the result, and contain a JSON object that matches the schema.
949
+ */
950
+ structuredContent: z.record(z.string(), z.unknown()).optional(),
951
+ /**
952
+ * Whether the tool call ended in an error.
953
+ *
954
+ * If not set, this is assumed to be false (the call was successful).
955
+ *
956
+ * Any errors that originate from the tool SHOULD be reported inside the result
957
+ * object, with `isError` set to true, _not_ as an MCP protocol-level error
958
+ * response. Otherwise, the LLM would not be able to see that an error occurred
959
+ * and self-correct.
960
+ *
961
+ * However, any errors in _finding_ the tool, an error indicating that the
962
+ * server does not support tool calls, or any other exceptional conditions,
963
+ * should be reported as an MCP error response.
964
+ */
965
+ isError: z.boolean().optional()
966
+ });
967
+ var CompatibilityCallToolResultSchema = CallToolResultSchema.or(ResultSchema.extend({
968
+ toolResult: z.unknown()
969
+ }));
970
+ var CallToolRequestParamsSchema = TaskAugmentedRequestParamsSchema.extend({
971
+ /**
972
+ * The name of the tool to call.
973
+ */
974
+ name: z.string(),
975
+ /**
976
+ * Arguments to pass to the tool.
977
+ */
978
+ arguments: z.record(z.string(), z.unknown()).optional()
979
+ });
980
+ var CallToolRequestSchema = RequestSchema.extend({
981
+ method: z.literal("tools/call"),
982
+ params: CallToolRequestParamsSchema
983
+ });
984
+ var ToolListChangedNotificationSchema = NotificationSchema.extend({
985
+ method: z.literal("notifications/tools/list_changed"),
986
+ params: NotificationsParamsSchema.optional()
987
+ });
988
+ var ListChangedOptionsBaseSchema = z.object({
989
+ /**
990
+ * If true, the list will be refreshed automatically when a list changed notification is received.
991
+ * The callback will be called with the updated list.
992
+ *
993
+ * If false, the callback will be called with null items, allowing manual refresh.
994
+ *
995
+ * @default true
996
+ */
997
+ autoRefresh: z.boolean().default(true),
998
+ /**
999
+ * Debounce time in milliseconds for list changed notification processing.
1000
+ *
1001
+ * Multiple notifications received within this timeframe will only trigger one refresh.
1002
+ * Set to 0 to disable debouncing.
1003
+ *
1004
+ * @default 300
1005
+ */
1006
+ debounceMs: z.number().int().nonnegative().default(300)
1007
+ });
1008
+ var LoggingLevelSchema = z.enum(["debug", "info", "notice", "warning", "error", "critical", "alert", "emergency"]);
1009
+ var SetLevelRequestParamsSchema = BaseRequestParamsSchema.extend({
1010
+ /**
1011
+ * 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.
1012
+ */
1013
+ level: LoggingLevelSchema
1014
+ });
1015
+ var SetLevelRequestSchema = RequestSchema.extend({
1016
+ method: z.literal("logging/setLevel"),
1017
+ params: SetLevelRequestParamsSchema
1018
+ });
1019
+ var LoggingMessageNotificationParamsSchema = NotificationsParamsSchema.extend({
1020
+ /**
1021
+ * The severity of this log message.
1022
+ */
1023
+ level: LoggingLevelSchema,
1024
+ /**
1025
+ * An optional name of the logger issuing this message.
1026
+ */
1027
+ logger: z.string().optional(),
1028
+ /**
1029
+ * The data to be logged, such as a string message or an object. Any JSON serializable type is allowed here.
1030
+ */
1031
+ data: z.unknown()
1032
+ });
1033
+ var LoggingMessageNotificationSchema = NotificationSchema.extend({
1034
+ method: z.literal("notifications/message"),
1035
+ params: LoggingMessageNotificationParamsSchema
1036
+ });
1037
+ var ModelHintSchema = z.object({
1038
+ /**
1039
+ * A hint for a model name.
1040
+ */
1041
+ name: z.string().optional()
1042
+ });
1043
+ var ModelPreferencesSchema = z.object({
1044
+ /**
1045
+ * Optional hints to use for model selection.
1046
+ */
1047
+ hints: z.array(ModelHintSchema).optional(),
1048
+ /**
1049
+ * How much to prioritize cost when selecting a model.
1050
+ */
1051
+ costPriority: z.number().min(0).max(1).optional(),
1052
+ /**
1053
+ * How much to prioritize sampling speed (latency) when selecting a model.
1054
+ */
1055
+ speedPriority: z.number().min(0).max(1).optional(),
1056
+ /**
1057
+ * How much to prioritize intelligence and capabilities when selecting a model.
1058
+ */
1059
+ intelligencePriority: z.number().min(0).max(1).optional()
1060
+ });
1061
+ var ToolChoiceSchema = z.object({
1062
+ /**
1063
+ * Controls when tools are used:
1064
+ * - "auto": Model decides whether to use tools (default)
1065
+ * - "required": Model MUST use at least one tool before completing
1066
+ * - "none": Model MUST NOT use any tools
1067
+ */
1068
+ mode: z.enum(["auto", "required", "none"]).optional()
1069
+ });
1070
+ var ToolResultContentSchema = z.object({
1071
+ type: z.literal("tool_result"),
1072
+ toolUseId: z.string().describe("The unique identifier for the corresponding tool call."),
1073
+ content: z.array(ContentBlockSchema).default([]),
1074
+ structuredContent: z.object({}).loose().optional(),
1075
+ isError: z.boolean().optional(),
1076
+ /**
1077
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
1078
+ * for notes on _meta usage.
1079
+ */
1080
+ _meta: z.record(z.string(), z.unknown()).optional()
1081
+ });
1082
+ var SamplingContentSchema = z.discriminatedUnion("type", [TextContentSchema, ImageContentSchema, AudioContentSchema]);
1083
+ var SamplingMessageContentBlockSchema = z.discriminatedUnion("type", [
1084
+ TextContentSchema,
1085
+ ImageContentSchema,
1086
+ AudioContentSchema,
1087
+ ToolUseContentSchema,
1088
+ ToolResultContentSchema
1089
+ ]);
1090
+ var SamplingMessageSchema = z.object({
1091
+ role: RoleSchema,
1092
+ content: z.union([SamplingMessageContentBlockSchema, z.array(SamplingMessageContentBlockSchema)]),
1093
+ /**
1094
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
1095
+ * for notes on _meta usage.
1096
+ */
1097
+ _meta: z.record(z.string(), z.unknown()).optional()
1098
+ });
1099
+ var CreateMessageRequestParamsSchema = TaskAugmentedRequestParamsSchema.extend({
1100
+ messages: z.array(SamplingMessageSchema),
1101
+ /**
1102
+ * The server's preferences for which model to select. The client MAY modify or omit this request.
1103
+ */
1104
+ modelPreferences: ModelPreferencesSchema.optional(),
1105
+ /**
1106
+ * An optional system prompt the server wants to use for sampling. The client MAY modify or omit this prompt.
1107
+ */
1108
+ systemPrompt: z.string().optional(),
1109
+ /**
1110
+ * A request to include context from one or more MCP servers (including the caller), to be attached to the prompt.
1111
+ * The client MAY ignore this request.
1112
+ *
1113
+ * Default is "none". Values "thisServer" and "allServers" are soft-deprecated. Servers SHOULD only use these values if the client
1114
+ * declares ClientCapabilities.sampling.context. These values may be removed in future spec releases.
1115
+ */
1116
+ includeContext: z.enum(["none", "thisServer", "allServers"]).optional(),
1117
+ temperature: z.number().optional(),
1118
+ /**
1119
+ * The requested maximum number of tokens to sample (to prevent runaway completions).
1120
+ *
1121
+ * The client MAY choose to sample fewer tokens than the requested maximum.
1122
+ */
1123
+ maxTokens: z.number().int(),
1124
+ stopSequences: z.array(z.string()).optional(),
1125
+ /**
1126
+ * Optional metadata to pass through to the LLM provider. The format of this metadata is provider-specific.
1127
+ */
1128
+ metadata: AssertObjectSchema.optional(),
1129
+ /**
1130
+ * Tools that the model may use during generation.
1131
+ * The client MUST return an error if this field is provided but ClientCapabilities.sampling.tools is not declared.
1132
+ */
1133
+ tools: z.array(ToolSchema).optional(),
1134
+ /**
1135
+ * Controls how the model uses tools.
1136
+ * The client MUST return an error if this field is provided but ClientCapabilities.sampling.tools is not declared.
1137
+ * Default is `{ mode: "auto" }`.
1138
+ */
1139
+ toolChoice: ToolChoiceSchema.optional()
1140
+ });
1141
+ var CreateMessageRequestSchema = RequestSchema.extend({
1142
+ method: z.literal("sampling/createMessage"),
1143
+ params: CreateMessageRequestParamsSchema
1144
+ });
1145
+ var CreateMessageResultSchema = ResultSchema.extend({
1146
+ /**
1147
+ * The name of the model that generated the message.
1148
+ */
1149
+ model: z.string(),
1150
+ /**
1151
+ * The reason why sampling stopped, if known.
1152
+ *
1153
+ * Standard values:
1154
+ * - "endTurn": Natural end of the assistant's turn
1155
+ * - "stopSequence": A stop sequence was encountered
1156
+ * - "maxTokens": Maximum token limit was reached
1157
+ *
1158
+ * This field is an open string to allow for provider-specific stop reasons.
1159
+ */
1160
+ stopReason: z.optional(z.enum(["endTurn", "stopSequence", "maxTokens"]).or(z.string())),
1161
+ role: RoleSchema,
1162
+ /**
1163
+ * Response content. Single content block (text, image, or audio).
1164
+ */
1165
+ content: SamplingContentSchema
1166
+ });
1167
+ var CreateMessageResultWithToolsSchema = ResultSchema.extend({
1168
+ /**
1169
+ * The name of the model that generated the message.
1170
+ */
1171
+ model: z.string(),
1172
+ /**
1173
+ * The reason why sampling stopped, if known.
1174
+ *
1175
+ * Standard values:
1176
+ * - "endTurn": Natural end of the assistant's turn
1177
+ * - "stopSequence": A stop sequence was encountered
1178
+ * - "maxTokens": Maximum token limit was reached
1179
+ * - "toolUse": The model wants to use one or more tools
1180
+ *
1181
+ * This field is an open string to allow for provider-specific stop reasons.
1182
+ */
1183
+ stopReason: z.optional(z.enum(["endTurn", "stopSequence", "maxTokens", "toolUse"]).or(z.string())),
1184
+ role: RoleSchema,
1185
+ /**
1186
+ * Response content. May be a single block or array. May include ToolUseContent if stopReason is "toolUse".
1187
+ */
1188
+ content: z.union([SamplingMessageContentBlockSchema, z.array(SamplingMessageContentBlockSchema)])
1189
+ });
1190
+ var BooleanSchemaSchema = z.object({
1191
+ type: z.literal("boolean"),
1192
+ title: z.string().optional(),
1193
+ description: z.string().optional(),
1194
+ default: z.boolean().optional()
1195
+ });
1196
+ var StringSchemaSchema = z.object({
1197
+ type: z.literal("string"),
1198
+ title: z.string().optional(),
1199
+ description: z.string().optional(),
1200
+ minLength: z.number().optional(),
1201
+ maxLength: z.number().optional(),
1202
+ format: z.enum(["email", "uri", "date", "date-time"]).optional(),
1203
+ default: z.string().optional()
1204
+ });
1205
+ var NumberSchemaSchema = z.object({
1206
+ type: z.enum(["number", "integer"]),
1207
+ title: z.string().optional(),
1208
+ description: z.string().optional(),
1209
+ minimum: z.number().optional(),
1210
+ maximum: z.number().optional(),
1211
+ default: z.number().optional()
1212
+ });
1213
+ var UntitledSingleSelectEnumSchemaSchema = z.object({
1214
+ type: z.literal("string"),
1215
+ title: z.string().optional(),
1216
+ description: z.string().optional(),
1217
+ enum: z.array(z.string()),
1218
+ default: z.string().optional()
1219
+ });
1220
+ var TitledSingleSelectEnumSchemaSchema = z.object({
1221
+ type: z.literal("string"),
1222
+ title: z.string().optional(),
1223
+ description: z.string().optional(),
1224
+ oneOf: z.array(z.object({
1225
+ const: z.string(),
1226
+ title: z.string()
1227
+ })),
1228
+ default: z.string().optional()
1229
+ });
1230
+ var LegacyTitledEnumSchemaSchema = z.object({
1231
+ type: z.literal("string"),
1232
+ title: z.string().optional(),
1233
+ description: z.string().optional(),
1234
+ enum: z.array(z.string()),
1235
+ enumNames: z.array(z.string()).optional(),
1236
+ default: z.string().optional()
1237
+ });
1238
+ var SingleSelectEnumSchemaSchema = z.union([UntitledSingleSelectEnumSchemaSchema, TitledSingleSelectEnumSchemaSchema]);
1239
+ var UntitledMultiSelectEnumSchemaSchema = z.object({
1240
+ type: z.literal("array"),
1241
+ title: z.string().optional(),
1242
+ description: z.string().optional(),
1243
+ minItems: z.number().optional(),
1244
+ maxItems: z.number().optional(),
1245
+ items: z.object({
1246
+ type: z.literal("string"),
1247
+ enum: z.array(z.string())
1248
+ }),
1249
+ default: z.array(z.string()).optional()
1250
+ });
1251
+ var TitledMultiSelectEnumSchemaSchema = z.object({
1252
+ type: z.literal("array"),
1253
+ title: z.string().optional(),
1254
+ description: z.string().optional(),
1255
+ minItems: z.number().optional(),
1256
+ maxItems: z.number().optional(),
1257
+ items: z.object({
1258
+ anyOf: z.array(z.object({
1259
+ const: z.string(),
1260
+ title: z.string()
1261
+ }))
1262
+ }),
1263
+ default: z.array(z.string()).optional()
1264
+ });
1265
+ var MultiSelectEnumSchemaSchema = z.union([UntitledMultiSelectEnumSchemaSchema, TitledMultiSelectEnumSchemaSchema]);
1266
+ var EnumSchemaSchema = z.union([LegacyTitledEnumSchemaSchema, SingleSelectEnumSchemaSchema, MultiSelectEnumSchemaSchema]);
1267
+ var PrimitiveSchemaDefinitionSchema = z.union([EnumSchemaSchema, BooleanSchemaSchema, StringSchemaSchema, NumberSchemaSchema]);
1268
+ var ElicitRequestFormParamsSchema = TaskAugmentedRequestParamsSchema.extend({
1269
+ /**
1270
+ * The elicitation mode.
1271
+ *
1272
+ * Optional for backward compatibility. Clients MUST treat missing mode as "form".
1273
+ */
1274
+ mode: z.literal("form").optional(),
1275
+ /**
1276
+ * The message to present to the user describing what information is being requested.
1277
+ */
1278
+ message: z.string(),
1279
+ /**
1280
+ * A restricted subset of JSON Schema.
1281
+ * Only top-level properties are allowed, without nesting.
1282
+ */
1283
+ requestedSchema: z.object({
1284
+ type: z.literal("object"),
1285
+ properties: z.record(z.string(), PrimitiveSchemaDefinitionSchema),
1286
+ required: z.array(z.string()).optional()
1287
+ })
1288
+ });
1289
+ var ElicitRequestURLParamsSchema = TaskAugmentedRequestParamsSchema.extend({
1290
+ /**
1291
+ * The elicitation mode.
1292
+ */
1293
+ mode: z.literal("url"),
1294
+ /**
1295
+ * The message to present to the user explaining why the interaction is needed.
1296
+ */
1297
+ message: z.string(),
1298
+ /**
1299
+ * The ID of the elicitation, which must be unique within the context of the server.
1300
+ * The client MUST treat this ID as an opaque value.
1301
+ */
1302
+ elicitationId: z.string(),
1303
+ /**
1304
+ * The URL that the user should navigate to.
1305
+ */
1306
+ url: z.string().url()
1307
+ });
1308
+ var ElicitRequestParamsSchema = z.union([ElicitRequestFormParamsSchema, ElicitRequestURLParamsSchema]);
1309
+ var ElicitRequestSchema = RequestSchema.extend({
1310
+ method: z.literal("elicitation/create"),
1311
+ params: ElicitRequestParamsSchema
1312
+ });
1313
+ var ElicitationCompleteNotificationParamsSchema = NotificationsParamsSchema.extend({
1314
+ /**
1315
+ * The ID of the elicitation that completed.
1316
+ */
1317
+ elicitationId: z.string()
1318
+ });
1319
+ var ElicitationCompleteNotificationSchema = NotificationSchema.extend({
1320
+ method: z.literal("notifications/elicitation/complete"),
1321
+ params: ElicitationCompleteNotificationParamsSchema
1322
+ });
1323
+ var ElicitResultSchema = ResultSchema.extend({
1324
+ /**
1325
+ * The user action in response to the elicitation.
1326
+ * - "accept": User submitted the form/confirmed the action
1327
+ * - "decline": User explicitly decline the action
1328
+ * - "cancel": User dismissed without making an explicit choice
1329
+ */
1330
+ action: z.enum(["accept", "decline", "cancel"]),
1331
+ /**
1332
+ * The submitted form data, only present when action is "accept".
1333
+ * Contains values matching the requested schema.
1334
+ * Per MCP spec, content is "typically omitted" for decline/cancel actions.
1335
+ * We normalize null to undefined for leniency while maintaining type compatibility.
1336
+ */
1337
+ content: z.preprocess((val) => val === null ? void 0 : val, z.record(z.string(), z.union([z.string(), z.number(), z.boolean(), z.array(z.string())])).optional())
1338
+ });
1339
+ var ResourceTemplateReferenceSchema = z.object({
1340
+ type: z.literal("ref/resource"),
1341
+ /**
1342
+ * The URI or URI template of the resource.
1343
+ */
1344
+ uri: z.string()
1345
+ });
1346
+ var PromptReferenceSchema = z.object({
1347
+ type: z.literal("ref/prompt"),
1348
+ /**
1349
+ * The name of the prompt or prompt template
1350
+ */
1351
+ name: z.string()
1352
+ });
1353
+ var CompleteRequestParamsSchema = BaseRequestParamsSchema.extend({
1354
+ ref: z.union([PromptReferenceSchema, ResourceTemplateReferenceSchema]),
1355
+ /**
1356
+ * The argument's information
1357
+ */
1358
+ argument: z.object({
1359
+ /**
1360
+ * The name of the argument
1361
+ */
1362
+ name: z.string(),
1363
+ /**
1364
+ * The value of the argument to use for completion matching.
1365
+ */
1366
+ value: z.string()
1367
+ }),
1368
+ context: z.object({
1369
+ /**
1370
+ * Previously-resolved variables in a URI template or prompt.
1371
+ */
1372
+ arguments: z.record(z.string(), z.string()).optional()
1373
+ }).optional()
1374
+ });
1375
+ var CompleteRequestSchema = RequestSchema.extend({
1376
+ method: z.literal("completion/complete"),
1377
+ params: CompleteRequestParamsSchema
1378
+ });
1379
+ var CompleteResultSchema = ResultSchema.extend({
1380
+ completion: z.looseObject({
1381
+ /**
1382
+ * An array of completion values. Must not exceed 100 items.
1383
+ */
1384
+ values: z.array(z.string()).max(100),
1385
+ /**
1386
+ * The total number of completion options available. This can exceed the number of values actually sent in the response.
1387
+ */
1388
+ total: z.optional(z.number().int()),
1389
+ /**
1390
+ * Indicates whether there are additional completion options beyond those provided in the current response, even if the exact total is unknown.
1391
+ */
1392
+ hasMore: z.optional(z.boolean())
1393
+ })
1394
+ });
1395
+ var RootSchema = z.object({
1396
+ /**
1397
+ * The URI identifying the root. This *must* start with file:// for now.
1398
+ */
1399
+ uri: z.string().startsWith("file://"),
1400
+ /**
1401
+ * An optional name for the root.
1402
+ */
1403
+ name: z.string().optional(),
1404
+ /**
1405
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
1406
+ * for notes on _meta usage.
1407
+ */
1408
+ _meta: z.record(z.string(), z.unknown()).optional()
1409
+ });
1410
+ var ListRootsRequestSchema = RequestSchema.extend({
1411
+ method: z.literal("roots/list"),
1412
+ params: BaseRequestParamsSchema.optional()
1413
+ });
1414
+ var ListRootsResultSchema = ResultSchema.extend({
1415
+ roots: z.array(RootSchema)
1416
+ });
1417
+ var RootsListChangedNotificationSchema = NotificationSchema.extend({
1418
+ method: z.literal("notifications/roots/list_changed"),
1419
+ params: NotificationsParamsSchema.optional()
1420
+ });
1421
+ var ClientRequestSchema = z.union([
1422
+ PingRequestSchema,
1423
+ InitializeRequestSchema,
1424
+ CompleteRequestSchema,
1425
+ SetLevelRequestSchema,
1426
+ GetPromptRequestSchema,
1427
+ ListPromptsRequestSchema,
1428
+ ListResourcesRequestSchema,
1429
+ ListResourceTemplatesRequestSchema,
1430
+ ReadResourceRequestSchema,
1431
+ SubscribeRequestSchema,
1432
+ UnsubscribeRequestSchema,
1433
+ CallToolRequestSchema,
1434
+ ListToolsRequestSchema,
1435
+ GetTaskRequestSchema,
1436
+ GetTaskPayloadRequestSchema,
1437
+ ListTasksRequestSchema,
1438
+ CancelTaskRequestSchema
1439
+ ]);
1440
+ var ClientNotificationSchema = z.union([
1441
+ CancelledNotificationSchema,
1442
+ ProgressNotificationSchema,
1443
+ InitializedNotificationSchema,
1444
+ RootsListChangedNotificationSchema,
1445
+ TaskStatusNotificationSchema
1446
+ ]);
1447
+ var ClientResultSchema = z.union([
1448
+ EmptyResultSchema,
1449
+ CreateMessageResultSchema,
1450
+ CreateMessageResultWithToolsSchema,
1451
+ ElicitResultSchema,
1452
+ ListRootsResultSchema,
1453
+ GetTaskResultSchema,
1454
+ ListTasksResultSchema,
1455
+ CreateTaskResultSchema
1456
+ ]);
1457
+ var ServerRequestSchema = z.union([
1458
+ PingRequestSchema,
1459
+ CreateMessageRequestSchema,
1460
+ ElicitRequestSchema,
1461
+ ListRootsRequestSchema,
1462
+ GetTaskRequestSchema,
1463
+ GetTaskPayloadRequestSchema,
1464
+ ListTasksRequestSchema,
1465
+ CancelTaskRequestSchema
1466
+ ]);
1467
+ var ServerNotificationSchema = z.union([
1468
+ CancelledNotificationSchema,
1469
+ ProgressNotificationSchema,
1470
+ LoggingMessageNotificationSchema,
1471
+ ResourceUpdatedNotificationSchema,
1472
+ ResourceListChangedNotificationSchema,
1473
+ ToolListChangedNotificationSchema,
1474
+ PromptListChangedNotificationSchema,
1475
+ TaskStatusNotificationSchema,
1476
+ ElicitationCompleteNotificationSchema
1477
+ ]);
1478
+ var ServerResultSchema = z.union([
1479
+ EmptyResultSchema,
1480
+ InitializeResultSchema,
1481
+ CompleteResultSchema,
1482
+ GetPromptResultSchema,
1483
+ ListPromptsResultSchema,
1484
+ ListResourcesResultSchema,
1485
+ ListResourceTemplatesResultSchema,
1486
+ ReadResourceResultSchema,
1487
+ CallToolResultSchema,
1488
+ ListToolsResultSchema,
1489
+ GetTaskResultSchema,
1490
+ ListTasksResultSchema,
1491
+ CreateTaskResultSchema
1492
+ ]);
1493
+ var McpError = class _McpError extends Error {
1494
+ constructor(code, message, data) {
1495
+ super(`MCP error ${code}: ${message}`);
1496
+ this.code = code;
1497
+ this.data = data;
1498
+ this.name = "McpError";
1499
+ }
1500
+ /**
1501
+ * Factory method to create the appropriate error type based on the error code and data
1502
+ */
1503
+ static fromError(code, message, data) {
1504
+ if (code === ErrorCode.UrlElicitationRequired && data) {
1505
+ const errorData = data;
1506
+ if (errorData.elicitations) {
1507
+ return new UrlElicitationRequiredError(errorData.elicitations, message);
1508
+ }
1509
+ }
1510
+ return new _McpError(code, message, data);
1511
+ }
1512
+ };
1513
+ var UrlElicitationRequiredError = class extends McpError {
1514
+ constructor(elicitations, message = `URL elicitation${elicitations.length > 1 ? "s" : ""} required`) {
1515
+ super(ErrorCode.UrlElicitationRequired, message, {
1516
+ elicitations
1517
+ });
1518
+ }
1519
+ get elicitations() {
1520
+ return this.data?.elicitations ?? [];
1521
+ }
1522
+ };
1523
+
1524
+ export {
1525
+ LATEST_PROTOCOL_VERSION,
1526
+ SUPPORTED_PROTOCOL_VERSIONS,
1527
+ RELATED_TASK_META_KEY,
1528
+ isTaskAugmentedRequestParams,
1529
+ isJSONRPCRequest,
1530
+ isJSONRPCNotification,
1531
+ isJSONRPCResultResponse,
1532
+ ErrorCode,
1533
+ isJSONRPCErrorResponse,
1534
+ JSONRPCMessageSchema,
1535
+ EmptyResultSchema,
1536
+ CancelledNotificationSchema,
1537
+ InitializeResultSchema,
1538
+ isInitializedNotification,
1539
+ PingRequestSchema,
1540
+ ProgressNotificationSchema,
1541
+ CreateTaskResultSchema,
1542
+ TaskStatusNotificationSchema,
1543
+ GetTaskRequestSchema,
1544
+ GetTaskResultSchema,
1545
+ GetTaskPayloadRequestSchema,
1546
+ ListTasksRequestSchema,
1547
+ ListTasksResultSchema,
1548
+ CancelTaskRequestSchema,
1549
+ CancelTaskResultSchema,
1550
+ ListResourcesResultSchema,
1551
+ ListResourceTemplatesResultSchema,
1552
+ ReadResourceResultSchema,
1553
+ ResourceListChangedNotificationSchema,
1554
+ ListPromptsResultSchema,
1555
+ GetPromptResultSchema,
1556
+ PromptListChangedNotificationSchema,
1557
+ ListToolsResultSchema,
1558
+ CallToolResultSchema,
1559
+ ToolListChangedNotificationSchema,
1560
+ ListChangedOptionsBaseSchema,
1561
+ CreateMessageRequestSchema,
1562
+ CreateMessageResultSchema,
1563
+ CreateMessageResultWithToolsSchema,
1564
+ ElicitRequestSchema,
1565
+ ElicitResultSchema,
1566
+ CompleteResultSchema,
1567
+ McpError
1568
+ };