Repository navigation
Expand file tree
/
Copy pathschemas.ts
More file actions
2460 lines (2273 loc) · 83.9 KB
/
Copy pathschemas.ts
File metadata and controls
2460 lines (2273 loc) · 83.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import * as z from 'zod/v4';
import { JSONRPC_VERSION, RELATED_TASK_META_KEY, SERVER_INFO_META_KEY, SUBSCRIPTION_ID_META_KEY } from './constants';
import type { JSONArray, JSONObject, JSONValue } from './types';
export const JSONValueSchema: z.ZodType<JSONValue, JSONValue> = z.lazy(() =>
z.union([z.string(), z.number(), z.boolean(), z.null(), z.record(z.string(), JSONValueSchema), z.array(JSONValueSchema)])
);
export const JSONObjectSchema: z.ZodType<JSONObject, JSONObject> = z.record(z.string(), JSONValueSchema);
export const JSONArraySchema: z.ZodType<JSONArray, JSONArray> = z.array(JSONValueSchema);
/**
* A progress token, used to associate progress notifications with the original request.
*/
export const ProgressTokenSchema = z.union([z.string(), z.number().int()]);
/**
* An opaque token used to represent a cursor for pagination.
*/
export const CursorSchema = z.string();
/** @deprecated 2025-11-25 wire vocabulary with no SDK runtime; kept importable for interoperability only. */
export const TaskMetadataSchema = z.object({
ttl: z.number().optional()
});
/**
* Metadata for associating messages with a task.
* Include this in the `_meta` field under the key `io.modelcontextprotocol/related-task`.
*
* @deprecated 2025-11-25 wire vocabulary with no SDK runtime; kept importable for interoperability only.
*/
export const RelatedTaskMetadataSchema = z.object({
taskId: z.string()
});
export const RequestMetaSchema = z.looseObject({
/**
* 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.
*/
progressToken: ProgressTokenSchema.optional(),
/**
* If specified, this request is related to the provided task.
*/
[RELATED_TASK_META_KEY]: RelatedTaskMetadataSchema.optional()
});
/**
* Common params for any request.
*/
export const BaseRequestParamsSchema = z.object({
/**
* See [General fields: `_meta`](https://modelcontextprotocol.io/specification/2026-07-28/basic/index#meta) for notes on `_meta` usage.
*/
_meta: RequestMetaSchema.optional()
});
/**
* Common params for any task-augmented request.
*
* @deprecated 2025-11-25 wire vocabulary with no SDK runtime; kept importable for interoperability only.
*/
export const TaskAugmentedRequestParamsSchema = BaseRequestParamsSchema.extend({
/**
* If specified, the caller is requesting task-augmented execution for this request.
* The request will return a `CreateTaskResult` immediately, and the actual result can be
* retrieved later via `tasks/result`.
*
* Task augmentation is subject to capability negotiation - receivers MUST declare support
* for task augmentation of specific request types in their capabilities.
*/
task: TaskMetadataSchema.optional()
});
export const RequestSchema = z.object({
method: z.string(),
params: BaseRequestParamsSchema.loose().optional()
});
export const NotificationsParamsSchema = z.object({
/**
* See [MCP specification](https://modelcontextprotocol.io/specification/2026-07-28/basic/index#general-fields)
* for notes on `_meta` usage.
*/
_meta: RequestMetaSchema.optional()
});
export const NotificationSchema = z.object({
method: z.string(),
params: NotificationsParamsSchema.loose().optional()
});
/**
* The contents of a result's `_meta` field (the 2026-07-28 `ResultMetaObject`).
* Loose — implementation-specific keys pass through.
*
* The serverInfo key identifies the server software producing the response
* (servers SHOULD include it on every response; the value is self-reported
* and intended for display, logging, and debugging). The getter defers the
* `ImplementationSchema` reference, which is declared later in this file.
*/
export const ResultMetaObjectSchema = z.looseObject({
get [SERVER_INFO_META_KEY]() {
// Malformed drops to absent, matching the wire layer: the value "is
// not verified by the protocol" and clients "SHOULD NOT use it to
// change their behavior". Load-bearing beyond leniency — this schema
// sits inside JSONRPCResultResponseSchema, whose guard classifies
// every inbound message, so a strict key here would drop whole
// responses over a bad display-only stamp.
// eslint-disable-next-line unicorn/prefer-top-level-await -- Zod `.catch()`, not a Promise
return ImplementationSchema.optional().catch(undefined);
}
});
export const ResultSchema = z.looseObject({
/**
* See [MCP specification](https://modelcontextprotocol.io/specification/2026-07-28/basic/index#general-fields)
* for notes on `_meta` usage.
*/
_meta: ResultMetaObjectSchema.optional()
// `resultType` is wire-only vocabulary (protocol revision 2026-07-28) and
// is deliberately NOT modeled here: the neutral result schemas carry no
// slot for it. It exists only inside the 2026-era wire codec, which
// consumes it on decode and stamps it on encode. (Q1 increment 2 - the
// former optional member here was the masking surface that let modern
// vocabulary leak through every legacy-leg parse.)
});
/**
* A uniquely identifying ID for a request in JSON-RPC.
*/
export const RequestIdSchema = z.union([z.string(), z.number().int()]);
/**
* A request that expects a response.
*/
export const JSONRPCRequestSchema = z
.object({
jsonrpc: z.literal(JSONRPC_VERSION),
id: RequestIdSchema,
...RequestSchema.shape
})
.strict();
/**
* A notification which does not expect a response.
*/
export const JSONRPCNotificationSchema = z
.object({
jsonrpc: z.literal(JSONRPC_VERSION),
...NotificationSchema.shape
})
.strict();
/**
* A successful (non-error) response to a request.
*/
export const JSONRPCResultResponseSchema = z
.object({
jsonrpc: z.literal(JSONRPC_VERSION),
id: RequestIdSchema,
result: ResultSchema
})
.strict();
/**
* A response to a request that indicates an error occurred.
*/
export const JSONRPCErrorResponseSchema = z
.object({
jsonrpc: z.literal(JSONRPC_VERSION),
id: RequestIdSchema.optional(),
error: z.object({
/**
* The error type that occurred.
*/
code: z.number().int(),
/**
* A short description of the error. The message SHOULD be limited to a concise single sentence.
*/
message: z.string(),
/**
* Additional information about the error. The value of this member is defined by the sender (e.g. detailed error information, nested errors etc.).
*/
data: z.unknown().optional()
})
})
.strict();
export const JSONRPCMessageSchema = z.union([
JSONRPCRequestSchema,
JSONRPCNotificationSchema,
JSONRPCResultResponseSchema,
JSONRPCErrorResponseSchema
]);
export const JSONRPCResponseSchema = z.union([JSONRPCResultResponseSchema, JSONRPCErrorResponseSchema]);
/* Empty result */
/**
* A response that indicates success but carries no data.
*/
export const EmptyResultSchema = ResultSchema.strict();
export const CancelledNotificationParamsSchema = NotificationsParamsSchema.extend({
/**
* The ID of the request to cancel.
*
* This MUST correspond to the ID of a request previously issued in the same direction.
*/
requestId: RequestIdSchema.optional(),
/**
* An optional string describing the reason for the cancellation. This MAY be logged or presented to the user.
*/
reason: z.string().optional()
});
/* Cancellation */
/**
* This notification can be sent by either side to indicate that it is cancelling a previously-issued request.
*
* The request SHOULD still be in-flight, but due to communication latency, it is always possible that this notification MAY arrive after the request has already finished.
*
* This notification indicates that the result will be unused, so any associated processing SHOULD cease.
*
* A client MUST NOT attempt to cancel its {@linkcode InitializeRequest | initialize} request.
*/
export const CancelledNotificationSchema = NotificationSchema.extend({
method: z.literal('notifications/cancelled'),
params: CancelledNotificationParamsSchema
});
/* Base Metadata */
/**
* Icon schema for use in {@link Tool | tools}, {@link Prompt | prompts}, {@link Resource | resources}, and {@link Implementation | implementations}.
*/
export const IconSchema = z.object({
/**
* URL or data URI for the icon.
*/
src: z.string(),
/**
* Optional MIME type for the icon.
*/
mimeType: z.string().optional(),
/**
* Optional array of strings that specify sizes at which the icon can be used.
* Each string should be in WxH format (e.g., `"48x48"`, `"96x96"`) or `"any"` for scalable formats like SVG.
*
* If not provided, the client should assume that the icon can be used at any size.
*/
sizes: z.array(z.string()).optional(),
/**
* Optional specifier for the theme this icon is designed for. `light` indicates
* the icon is designed to be used with a light background, and `dark` indicates
* the icon is designed to be used with a dark background.
*
* If not provided, the client should assume the icon can be used with any theme.
*/
theme: z.enum(['light', 'dark']).optional()
});
/**
* Base schema to add `icons` property.
*
*/
export const IconsSchema = z.object({
/**
* Optional set of sized icons that the client can display in a user interface.
*
* Clients that support rendering icons MUST support at least the following MIME types:
* - `image/png` - PNG images (safe, universal compatibility)
* - `image/jpeg` (and `image/jpg`) - JPEG images (safe, universal compatibility)
*
* Clients that support rendering icons SHOULD also support:
* - `image/svg+xml` - SVG images (scalable but requires security precautions)
* - `image/webp` - WebP images (modern, efficient format)
*/
icons: z.array(IconSchema).optional()
});
/**
* Base metadata interface for common properties across {@link Resource | resources}, {@link Tool | tools}, {@link Prompt | prompts}, and {@link Implementation | implementations}.
*/
export const BaseMetadataSchema = z.object({
/** Intended for programmatic or logical use, but used as a display name in past specs or fallback */
name: z.string(),
/**
* Intended for UI and end-user contexts — optimized to be human-readable and easily understood,
* even by those unfamiliar with domain-specific terminology.
*
* If not provided, the `name` should be used for display (except for `Tool`,
* where `annotations.title` should be given precedence over using `name`,
* if present).
*/
title: z.string().optional()
});
/* Initialization */
/**
* Describes the name and version of an MCP implementation.
*/
export const ImplementationSchema = BaseMetadataSchema.extend({
...BaseMetadataSchema.shape,
...IconsSchema.shape,
version: z.string(),
/**
* An optional URL of the website for this implementation.
*/
websiteUrl: z.string().optional(),
/**
* An optional human-readable description of what this implementation does.
*
* This can be used by clients or servers to provide context about their purpose
* and capabilities. For example, a server might describe the types of resources
* or tools it provides, while a client might describe its intended use case.
*/
description: z.string().optional()
});
const FormElicitationCapabilitySchema = z.intersection(
z.object({
applyDefaults: z.boolean().optional()
}),
JSONObjectSchema
);
const ElicitationCapabilitySchema = z.preprocess(
value => {
if (value && typeof value === 'object' && !Array.isArray(value) && Object.keys(value as Record<string, unknown>).length === 0) {
return { form: {} };
}
return value;
},
z.intersection(
z.object({
form: FormElicitationCapabilitySchema.optional(),
url: JSONObjectSchema.optional()
}),
JSONObjectSchema.optional()
)
);
/**
* Task capabilities for clients, indicating which request types support task creation.
*
* @deprecated 2025-11-25 wire vocabulary with no SDK runtime; kept importable for interoperability only.
*/
export const ClientTasksCapabilitySchema = z.looseObject({
/**
* Present if the client supports listing tasks.
*/
list: JSONObjectSchema.optional(),
/**
* Present if the client supports cancelling tasks.
*/
cancel: JSONObjectSchema.optional(),
/**
* Capabilities for task creation on specific request types.
*/
requests: z
.looseObject({
/**
* Task support for sampling requests.
*/
sampling: z
.looseObject({
createMessage: JSONObjectSchema.optional()
})
.optional(),
/**
* Task support for elicitation requests.
*/
elicitation: z
.looseObject({
create: JSONObjectSchema.optional()
})
.optional()
})
.optional()
});
/**
* Task capabilities for servers, indicating which request types support task creation.
*
* @deprecated 2025-11-25 wire vocabulary with no SDK runtime; kept importable for interoperability only.
*/
export const ServerTasksCapabilitySchema = z.looseObject({
/**
* Present if the server supports listing tasks.
*/
list: JSONObjectSchema.optional(),
/**
* Present if the server supports cancelling tasks.
*/
cancel: JSONObjectSchema.optional(),
/**
* Capabilities for task creation on specific request types.
*/
requests: z
.looseObject({
/**
* Task support for tool requests.
*/
tools: z
.looseObject({
call: JSONObjectSchema.optional()
})
.optional()
})
.optional()
});
/**
* 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.
*/
export const ClientCapabilitiesSchema = z.object({
/**
* Experimental, non-standard capabilities that the client supports.
*/
experimental: z.record(z.string(), JSONObjectSchema).optional(),
/**
* Present if the client supports sampling from an LLM.
*
* @deprecated Deprecated as of protocol version 2026-07-28 (SEP-2577); remains
* in the specification for at least twelve months. Migrate to calling LLM
* provider APIs directly.
*/
sampling: z
.object({
/**
* Present if the client supports context inclusion via `includeContext` parameter.
* If not declared, servers SHOULD only use `includeContext: "none"` (or omit it).
*/
context: JSONObjectSchema.optional(),
/**
* Present if the client supports tool use via `tools` and `toolChoice` parameters.
*/
tools: JSONObjectSchema.optional()
})
.optional(),
/**
* Present if the client supports eliciting user input.
*/
elicitation: ElicitationCapabilitySchema.optional(),
/**
* Present if the client supports listing roots.
*
* @deprecated Deprecated as of protocol version 2026-07-28 (SEP-2577); remains
* in the specification for at least twelve months. Migrate to passing paths via
* tool parameters, resource URIs, or configuration.
*/
roots: z
.object({
/**
* Whether the client supports issuing notifications for changes to the roots list.
*/
listChanged: z.boolean().optional()
})
.optional(),
/**
* Present if the client supports task creation.
*
* @deprecated 2025-11-25 wire vocabulary with no SDK runtime; parsed for interoperability only — servers built on this SDK never advertise it.
*/
tasks: ClientTasksCapabilitySchema.optional(),
/**
* Extensions that the client supports. Keys are extension identifiers (vendor-prefix/extension-name).
*/
extensions: z.record(z.string(), JSONObjectSchema).optional()
});
export const InitializeRequestParamsSchema = BaseRequestParamsSchema.extend({
/**
* The latest version of the Model Context Protocol that the client supports. The client MAY decide to support older versions as well.
*/
protocolVersion: z.string(),
capabilities: ClientCapabilitiesSchema,
clientInfo: ImplementationSchema
});
/**
* This request is sent from the client to the server when it first connects, asking it to begin initialization.
*/
export const InitializeRequestSchema = RequestSchema.extend({
method: z.literal('initialize'),
params: InitializeRequestParamsSchema
});
/**
* Capabilities that a server may support. Known capabilities are defined here, in this schema, but this is not a closed set: any server can define its own, additional capabilities.
*/
export const ServerCapabilitiesSchema = z.object({
/**
* Experimental, non-standard capabilities that the server supports.
*/
experimental: z.record(z.string(), JSONObjectSchema).optional(),
/**
* Present if the server supports sending log messages to the client.
*
* @deprecated Deprecated as of protocol version 2026-07-28 (SEP-2577); remains
* in the specification for at least twelve months. Migrate to stderr logging
* (STDIO servers) or OpenTelemetry.
*/
logging: JSONObjectSchema.optional(),
/**
* Present if the server supports sending completions to the client.
*/
completions: JSONObjectSchema.optional(),
/**
* Present if the server offers any prompt templates.
*/
prompts: z
.object({
/**
* Whether this server supports issuing notifications for changes to the prompt list.
*/
listChanged: z.boolean().optional()
})
.optional(),
/**
* Present if the server offers any resources to read.
*/
resources: z
.object({
/**
* Whether this server supports clients subscribing to resource updates.
*/
subscribe: z.boolean().optional(),
/**
* Whether this server supports issuing notifications for changes to the resource list.
*/
listChanged: z.boolean().optional()
})
.optional(),
/**
* Present if the server offers any tools to call.
*/
tools: z
.object({
/**
* Whether this server supports issuing notifications for changes to the tool list.
*/
listChanged: z.boolean().optional()
})
.optional(),
/**
* Present if the server supports task creation.
*
* @deprecated 2025-11-25 wire vocabulary with no SDK runtime; parsed for interoperability only — servers built on this SDK never advertise it.
*/
tasks: ServerTasksCapabilitySchema.optional(),
/**
* Extensions that the server supports. Keys are extension identifiers (vendor-prefix/extension-name).
*/
extensions: z.record(z.string(), JSONObjectSchema).optional()
});
/**
* After receiving an initialize request from the client, the server sends this response.
*/
export const InitializeResultSchema = ResultSchema.extend({
/**
* 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.
*/
protocolVersion: z.string(),
capabilities: ServerCapabilitiesSchema,
serverInfo: ImplementationSchema,
/**
* Instructions describing how to use the server and its features.
*
* 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.
*/
instructions: z.string().optional()
});
/**
* This notification is sent from the client to the server after initialization has finished.
*/
export const InitializedNotificationSchema = NotificationSchema.extend({
method: z.literal('notifications/initialized'),
params: NotificationsParamsSchema.optional()
});
/* Discovery */
/**
* A request from the client asking the server to advertise its supported protocol
* versions, capabilities, and other metadata (protocol revision 2026-07-28). Servers
* MUST implement `server/discover`. Clients MAY call it but are not required to —
* version negotiation can also happen inline via the per-request `_meta` envelope.
*/
export const DiscoverRequestSchema = RequestSchema.extend({
method: z.literal('server/discover'),
params: BaseRequestParamsSchema.optional()
});
/**
* The result returned by the server for a `server/discover` request.
*/
export const DiscoverResultSchema = ResultSchema.extend({
/**
* MCP protocol versions this server supports. The client should choose a
* version from this list for use in subsequent requests.
*/
supportedVersions: z.array(z.string()),
/**
* The capabilities of the server.
*/
capabilities: ServerCapabilitiesSchema,
/**
* Instructions describing how to use the server and its features.
*
* 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.
*
* Server identity is not a body field: it travels in
* `_meta['io.modelcontextprotocol/serverInfo']` (spec PR #3002).
*/
instructions: z.string().optional()
});
/* Ping */
/**
* 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.
*/
export const PingRequestSchema = RequestSchema.extend({
method: z.literal('ping'),
params: BaseRequestParamsSchema.optional()
});
/* Progress notifications */
export const ProgressSchema = z.object({
/**
* The progress thus far. This should increase every time progress is made, even if the total is unknown.
*/
progress: z.number(),
/**
* Total number of items to process (or total progress required), if known.
*/
total: z.optional(z.number()),
/**
* An optional message describing the current progress.
*/
message: z.optional(z.string())
});
export const ProgressNotificationParamsSchema = z.object({
...NotificationsParamsSchema.shape,
...ProgressSchema.shape,
/**
* The progress token which was given in the initial request, used to associate this notification with the request that is proceeding.
*/
progressToken: ProgressTokenSchema
});
/**
* An out-of-band notification used to inform the receiver of a progress update for a long-running request.
*
* @category notifications/progress
*/
export const ProgressNotificationSchema = NotificationSchema.extend({
method: z.literal('notifications/progress'),
params: ProgressNotificationParamsSchema
});
export const PaginatedRequestParamsSchema = BaseRequestParamsSchema.extend({
/**
* An opaque token representing the current pagination position.
* If provided, the server should return results starting after this cursor.
*/
cursor: CursorSchema.optional()
});
/* Pagination */
export const PaginatedRequestSchema = RequestSchema.extend({
params: PaginatedRequestParamsSchema.optional()
});
export const PaginatedResultSchema = ResultSchema.extend({
/**
* An opaque token representing the pagination position after the last returned result.
* If present, there may be more results available.
*/
nextCursor: CursorSchema.optional()
});
/* Resources */
/**
* The contents of a specific resource or sub-resource.
*/
export const ResourceContentsSchema = z.object({
/**
* The URI of this resource.
*/
uri: z.string(),
/**
* The MIME type of this resource, if known.
*/
mimeType: z.optional(z.string()),
/**
* See [MCP specification](https://modelcontextprotocol.io/specification/2026-07-28/basic/index#general-fields)
* for notes on `_meta` usage.
*/
_meta: z.record(z.string(), z.unknown()).optional()
});
export const TextResourceContentsSchema = ResourceContentsSchema.extend({
/**
* The text of the item. This must only be set if the item can actually be represented as text (not binary data).
*/
text: z.string()
});
/**
* A Zod schema for validating Base64 strings that is more performant and
* robust for very large inputs than the default regex-based check. It avoids
* stack overflows by using the native `atob` function for validation.
*/
const Base64Schema = z.string().refine(
val => {
try {
// atob throws a DOMException if the string contains characters
// that are not part of the Base64 character set.
atob(val);
return true;
} catch {
return false;
}
},
{ message: 'Invalid Base64 string' }
);
export const BlobResourceContentsSchema = ResourceContentsSchema.extend({
/**
* A base64-encoded string representing the binary data of the item.
*/
blob: Base64Schema
});
/**
* The sender or recipient of messages and data in a conversation.
*/
export const RoleSchema = z.enum(['user', 'assistant']);
/**
* Optional annotations providing clients additional context about a resource.
*/
export const AnnotationsSchema = z.object({
/**
* Intended audience(s) for the resource.
*/
audience: z.array(RoleSchema).optional(),
/**
* Importance hint for the resource, from 0 (least) to 1 (most).
*/
priority: z.number().min(0).max(1).optional(),
/**
* ISO 8601 timestamp for the most recent modification.
*/
lastModified: z.iso.datetime({ offset: true }).optional()
});
/**
* A known resource that the server is capable of reading.
*/
export const ResourceSchema = z.object({
...BaseMetadataSchema.shape,
...IconsSchema.shape,
/**
* The URI of this resource.
*/
uri: z.string(),
/**
* A description of what this resource represents.
*
* 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.
*/
description: z.optional(z.string()),
/**
* The MIME type of this resource, if known.
*/
mimeType: z.optional(z.string()),
/**
* The size of the raw resource content, in bytes (i.e., before base64 encoding or any tokenization), if known.
*
* This can be used by Hosts to display file sizes and estimate context window usage.
*/
size: z.optional(z.number()),
/**
* Optional annotations for the client.
*/
annotations: AnnotationsSchema.optional(),
/**
* See [MCP specification](https://modelcontextprotocol.io/specification/2026-07-28/basic/index#general-fields)
* for notes on `_meta` usage.
*/
_meta: z.optional(z.looseObject({}))
});
/**
* A template description for resources available on the server.
*/
export const ResourceTemplateSchema = z.object({
...BaseMetadataSchema.shape,
...IconsSchema.shape,
/**
* A URI template (according to RFC 6570) that can be used to construct resource URIs.
*/
uriTemplate: z.string(),
/**
* A description of what this template is for.
*
* 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.
*/
description: z.optional(z.string()),
/**
* 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.
*/
mimeType: z.optional(z.string()),
/**
* Optional annotations for the client.
*/
annotations: AnnotationsSchema.optional(),
/**
* See [MCP specification](https://modelcontextprotocol.io/specification/2026-07-28/basic/index#general-fields)
* for notes on `_meta` usage.
*/
_meta: z.optional(z.looseObject({}))
});
/**
* Sent from the client to request a list of resources the server has.
*/
export const ListResourcesRequestSchema = PaginatedRequestSchema.extend({
method: z.literal('resources/list')
});
/**
* The server's response to a {@linkcode ListResourcesRequest | resources/list} request from the client.
*/
export const ListResourcesResultSchema = PaginatedResultSchema.extend({
resources: z.array(ResourceSchema)
});
/**
* Sent from the client to request a list of resource templates the server has.
*/
export const ListResourceTemplatesRequestSchema = PaginatedRequestSchema.extend({
method: z.literal('resources/templates/list')
});
/**
* The server's response to a {@linkcode ListResourceTemplatesRequest | resources/templates/list} request from the client.
*/
export const ListResourceTemplatesResultSchema = PaginatedResultSchema.extend({
resourceTemplates: z.array(ResourceTemplateSchema)
});
export const ResourceRequestParamsSchema = BaseRequestParamsSchema.extend({
/**
* The URI of the resource to read. The URI can use any protocol; it is up to the server how to interpret it.
*
* @format uri
*/
uri: z.string()
});
/**
* Parameters for a {@linkcode ReadResourceRequest | resources/read} request.
*/
export const ReadResourceRequestParamsSchema = ResourceRequestParamsSchema;
/**
* Sent from the client to the server, to read a specific resource URI.
*/
export const ReadResourceRequestSchema = RequestSchema.extend({
method: z.literal('resources/read'),
params: ReadResourceRequestParamsSchema
});
/**
* The server's response to a {@linkcode ReadResourceRequest | resources/read} request from the client.
*/
export const ReadResourceResultSchema = ResultSchema.extend({
contents: z.array(z.union([TextResourceContentsSchema, BlobResourceContentsSchema]))
});
/**
* 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.
*/
export const ResourceListChangedNotificationSchema = NotificationSchema.extend({
method: z.literal('notifications/resources/list_changed'),
params: NotificationsParamsSchema.optional()
});
export const SubscribeRequestParamsSchema = ResourceRequestParamsSchema;
/**
* Sent from the client to request `resources/updated` notifications from the server whenever a particular resource changes.
*/
export const SubscribeRequestSchema = RequestSchema.extend({
method: z.literal('resources/subscribe'),
params: SubscribeRequestParamsSchema
});
export const UnsubscribeRequestParamsSchema = ResourceRequestParamsSchema;
/**
* Sent from the client to request cancellation of {@linkcode ResourceUpdatedNotification | resources/updated} notifications from the server. This should follow a previous {@linkcode SubscribeRequest | resources/subscribe} request.
*/
export const UnsubscribeRequestSchema = RequestSchema.extend({
method: z.literal('resources/unsubscribe'),
params: UnsubscribeRequestParamsSchema
});
/* Subscriptions (protocol revision 2026-07-28) */
/**
* The set of notification types a client opts in to on a `subscriptions/listen`
* request. Each type is opt-in; the server MUST NOT send a notification type
* the client has not explicitly requested here.
*/
export const SubscriptionFilterSchema = z.object({
/**
* If true, receive `notifications/tools/list_changed`.
*/
toolsListChanged: z.boolean().optional(),
/**
* If true, receive `notifications/prompts/list_changed`.
*/
promptsListChanged: z.boolean().optional(),
/**
* If true, receive `notifications/resources/list_changed`.
*/
resourcesListChanged: z.boolean().optional(),
/**
* Subscribe to `notifications/resources/updated` for these resource URIs.
* Replaces the former `resources/subscribe` RPC on the 2026-07-28 revision.
*/
resourceSubscriptions: z.array(z.string()).optional()
});
export const SubscriptionsListenRequestParamsSchema = BaseRequestParamsSchema.extend({
/**
* The notifications the client opts in to on this stream. The server MUST
* NOT send notification types the client has not explicitly requested.
*/
notifications: SubscriptionFilterSchema
});
/**
* Sent from the client to open a long-lived channel for receiving notifications
* outside the context of a specific request (protocol revision 2026-07-28).
* Replaces the previous HTTP GET endpoint and `resources/subscribe`.
*/
export const SubscriptionsListenRequestSchema = RequestSchema.extend({
method: z.literal('subscriptions/listen'),
params: SubscriptionsListenRequestParamsSchema
});
export const SubscriptionsAcknowledgedNotificationParamsSchema = NotificationsParamsSchema.extend({
/**
* The subset of requested notification types the server agreed to honor.
*/
notifications: SubscriptionFilterSchema
});
/**
* Sent by the server as the first message on a `subscriptions/listen` stream
* to acknowledge that the subscription has been established and report which
* notification types it agreed to honor (protocol revision 2026-07-28).
*/
export const SubscriptionsAcknowledgedNotificationSchema = NotificationSchema.extend({
method: z.literal('notifications/subscriptions/acknowledged'),
params: SubscriptionsAcknowledgedNotificationParamsSchema
});
/**
* `_meta` for a {@linkcode SubscriptionsListenResult}: the listen request's
* JSON-RPC ID under the canonical subscription-id key (mirroring the same key
* on every notification delivered on the stream). Extends
* {@linkcode ResultMetaObjectSchema}, so the optional serverInfo key is typed
* here too.
*/
export const SubscriptionsListenResultMetaSchema = ResultMetaObjectSchema.extend({
[SUBSCRIPTION_ID_META_KEY]: RequestIdSchema
});
/**
* The response to a `subscriptions/listen` request, signalling that the
* subscription has ended gracefully (for example, during server shutdown).
* Because the listen stream is long-lived, this result is sent only when the
* server tears the subscription down; an abrupt transport close carries no
* response. The result body is otherwise empty.
*/