@@ -14,15 +14,17 @@ export const RequestSchema = z.object({
14
14
z
15
15
. object ( {
16
16
_meta : z . optional (
17
- z . object ( {
18
- /**
19
- * 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.
20
- */
21
- progressToken : z . optional ( ProgressTokenSchema ) ,
22
- } ) ,
17
+ z
18
+ . object ( {
19
+ /**
20
+ * 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.
21
+ */
22
+ progressToken : z . optional ( ProgressTokenSchema ) ,
23
+ } )
24
+ . passthrough ( ) ,
23
25
) ,
24
26
} )
25
- . catchall ( z . unknown ( ) ) ,
27
+ . passthrough ( ) ,
26
28
) ,
27
29
} ) ;
28
30
@@ -34,9 +36,9 @@ export const NotificationSchema = z.object({
34
36
/**
35
37
* This parameter name is reserved by MCP to allow clients and servers to attach additional metadata to their notifications.
36
38
*/
37
- _meta : z . optional ( z . record ( z . unknown ( ) ) ) ,
39
+ _meta : z . optional ( z . object ( { } ) . passthrough ( ) ) ,
38
40
} )
39
- . catchall ( z . unknown ( ) ) ,
41
+ . passthrough ( ) ,
40
42
) ,
41
43
} ) ;
42
44
@@ -45,9 +47,9 @@ export const ResultSchema = z
45
47
/**
46
48
* This result property is reserved by the protocol to allow clients and servers to attach additional metadata to their responses.
47
49
*/
48
- _meta : z . optional ( z . record ( z . unknown ( ) ) ) ,
50
+ _meta : z . optional ( z . object ( { } ) . passthrough ( ) ) ,
49
51
} )
50
- . catchall ( z . unknown ( ) ) ;
52
+ . passthrough ( ) ;
51
53
52
54
/**
53
55
* A uniquely identifying ID for a request in JSON-RPC.
@@ -60,23 +62,25 @@ export const RequestIdSchema = z.union([z.string(), z.number().int()]);
60
62
export const JSONRPCRequestSchema = RequestSchema . extend ( {
61
63
jsonrpc : z . literal ( JSONRPC_VERSION ) ,
62
64
id : RequestIdSchema ,
63
- } ) ;
65
+ } ) . strict ( ) ;
64
66
65
67
/**
66
68
* A notification which does not expect a response.
67
69
*/
68
70
export const JSONRPCNotificationSchema = NotificationSchema . extend ( {
69
71
jsonrpc : z . literal ( JSONRPC_VERSION ) ,
70
- } ) ;
72
+ } ) . strict ( ) ;
71
73
72
74
/**
73
75
* A successful (non-error) response to a request.
74
76
*/
75
- export const JSONRPCResponseSchema = z . object ( {
76
- jsonrpc : z . literal ( JSONRPC_VERSION ) ,
77
- id : RequestIdSchema ,
78
- result : ResultSchema ,
79
- } ) ;
77
+ export const JSONRPCResponseSchema = z
78
+ . object ( {
79
+ jsonrpc : z . literal ( JSONRPC_VERSION ) ,
80
+ id : RequestIdSchema ,
81
+ result : ResultSchema ,
82
+ } )
83
+ . strict ( ) ;
80
84
81
85
// Standard JSON-RPC error codes
82
86
export const PARSE_ERROR = - 32700 ;
@@ -88,24 +92,26 @@ export const INTERNAL_ERROR = -32603;
88
92
/**
89
93
* A response to a request that indicates an error occurred.
90
94
*/
91
- export const JSONRPCErrorSchema = z . object ( {
92
- jsonrpc : z . literal ( JSONRPC_VERSION ) ,
93
- id : RequestIdSchema ,
94
- error : z . object ( {
95
- /**
96
- * The error type that occurred.
97
- */
98
- code : z . number ( ) . int ( ) ,
99
- /**
100
- * A short description of the error. The message SHOULD be limited to a concise single sentence.
101
- */
102
- message : z . string ( ) ,
103
- /**
104
- * Additional information about the error. The value of this member is defined by the sender (e.g. detailed error information, nested errors etc.).
105
- */
106
- data : z . optional ( z . unknown ( ) ) ,
107
- } ) ,
108
- } ) ;
95
+ export const JSONRPCErrorSchema = z
96
+ . object ( {
97
+ jsonrpc : z . literal ( JSONRPC_VERSION ) ,
98
+ id : RequestIdSchema ,
99
+ error : z . object ( {
100
+ /**
101
+ * The error type that occurred.
102
+ */
103
+ code : z . number ( ) . int ( ) ,
104
+ /**
105
+ * A short description of the error. The message SHOULD be limited to a concise single sentence.
106
+ */
107
+ message : z . string ( ) ,
108
+ /**
109
+ * Additional information about the error. The value of this member is defined by the sender (e.g. detailed error information, nested errors etc.).
110
+ */
111
+ data : z . optional ( z . unknown ( ) ) ,
112
+ } ) ,
113
+ } )
114
+ . strict ( ) ;
109
115
110
116
export const JSONRPCMessageSchema = z . union ( [
111
117
JSONRPCRequestSchema ,
@@ -118,7 +124,7 @@ export const JSONRPCMessageSchema = z.union([
118
124
/**
119
125
* A response that indicates success but carries no data.
120
126
*/
121
- export const EmptyResultSchema = ResultSchema ;
127
+ export const EmptyResultSchema = ResultSchema . strict ( ) ;
122
128
123
129
/* Initialization */
124
130
export const PROTOCOL_VERSION = 1 ;
@@ -141,10 +147,8 @@ export const ImageContentSchema = z.object({
141
147
type : z . literal ( "image" ) ,
142
148
/**
143
149
* The base64-encoded image data.
144
- *
145
- * @format byte
146
150
*/
147
- data : z . string ( ) ,
151
+ data : z . string ( ) . base64 ( ) ,
148
152
/**
149
153
* The MIME type of the image. Different providers may support different image types.
150
154
*/
@@ -174,11 +178,11 @@ export const ClientCapabilitiesSchema = z.object({
174
178
/**
175
179
* Experimental, non-standard capabilities that the client supports.
176
180
*/
177
- experimental : z . optional ( z . record ( z . object ( { } ) ) ) ,
181
+ experimental : z . optional ( z . object ( { } ) . passthrough ( ) ) ,
178
182
/**
179
183
* Present if the client supports sampling from an LLM.
180
184
*/
181
- sampling : z . optional ( z . object ( { } ) ) ,
185
+ sampling : z . optional ( z . object ( { } ) . passthrough ( ) ) ,
182
186
} ) ;
183
187
184
188
/**
@@ -203,30 +207,32 @@ export const ServerCapabilitiesSchema = z.object({
203
207
/**
204
208
* Experimental, non-standard capabilities that the server supports.
205
209
*/
206
- experimental : z . optional ( z . record ( z . object ( { } ) ) ) ,
210
+ experimental : z . optional ( z . object ( { } ) . passthrough ( ) ) ,
207
211
/**
208
212
* Present if the server supports sending log messages to the client.
209
213
*/
210
- logging : z . optional ( z . object ( { } ) ) ,
214
+ logging : z . optional ( z . object ( { } ) . passthrough ( ) ) ,
211
215
/**
212
216
* Present if the server offers any prompt templates.
213
217
*/
214
- prompts : z . optional ( z . object ( { } ) ) ,
218
+ prompts : z . optional ( z . object ( { } ) . passthrough ( ) ) ,
215
219
/**
216
220
* Present if the server offers any resources to read.
217
221
*/
218
222
resources : z . optional (
219
- z . object ( {
220
- /**
221
- * Whether this server supports subscribing to resource updates.
222
- */
223
- subscribe : z . optional ( z . boolean ( ) ) ,
224
- } ) ,
223
+ z
224
+ . object ( {
225
+ /**
226
+ * Whether this server supports subscribing to resource updates.
227
+ */
228
+ subscribe : z . optional ( z . boolean ( ) ) ,
229
+ } )
230
+ . passthrough ( ) ,
225
231
) ,
226
232
/**
227
233
* Present if the server offers any tools to call.
228
234
*/
229
- tools : z . optional ( z . object ( { } ) ) ,
235
+ tools : z . optional ( z . object ( { } ) . passthrough ( ) ) ,
230
236
} ) ;
231
237
232
238
/**
@@ -303,10 +309,8 @@ export const TextResourceContentsSchema = ResourceContentsSchema.extend({
303
309
export const BlobResourceContentsSchema = ResourceContentsSchema . extend ( {
304
310
/**
305
311
* A base64-encoded string representing the binary data of the item.
306
- *
307
- * @format byte
308
312
*/
309
- blob : z . string ( ) ,
313
+ blob : z . string ( ) . base64 ( ) ,
310
314
} ) ;
311
315
312
316
/**
@@ -344,8 +348,6 @@ export const ResourceSchema = z.object({
344
348
export const ResourceTemplateSchema = z . object ( {
345
349
/**
346
350
* A URI template (according to RFC 6570) that can be used to construct resource URIs.
347
- *
348
- * @format uri-template
349
351
*/
350
352
uriTemplate : z . string ( ) ,
351
353
@@ -549,7 +551,7 @@ export const ToolSchema = z.object({
549
551
*/
550
552
inputSchema : z . object ( {
551
553
type : z . literal ( "object" ) ,
552
- properties : z . optional ( z . record ( z . object ( { } ) ) ) ,
554
+ properties : z . optional ( z . object ( { } ) . passthrough ( ) ) ,
553
555
} ) ,
554
556
} ) ;
555
557
@@ -657,7 +659,7 @@ export const CreateMessageRequestSchema = RequestSchema.extend({
657
659
/**
658
660
* Optional metadata to pass through to the LLM provider. The format of this metadata is provider-specific.
659
661
*/
660
- metadata : z . optional ( z . object ( { } ) ) ,
662
+ metadata : z . optional ( z . object ( { } ) . passthrough ( ) ) ,
661
663
} ) ,
662
664
} ) ;
663
665
@@ -674,7 +676,10 @@ export const CreateMessageResultSchema = ResultSchema.extend({
674
676
*/
675
677
stopReason : z . enum ( [ "endTurn" , "stopSequence" , "maxTokens" ] ) ,
676
678
role : z . enum ( [ "user" , "assistant" ] ) ,
677
- content : z . union ( [ TextContentSchema , ImageContentSchema ] ) ,
679
+ content : z . discriminatedUnion ( "type" , [
680
+ TextContentSchema ,
681
+ ImageContentSchema ,
682
+ ] ) ,
678
683
} ) ;
679
684
680
685
/* Autocomplete */
@@ -685,8 +690,6 @@ export const ResourceReferenceSchema = z.object({
685
690
type : z . literal ( "ref/resource" ) ,
686
691
/**
687
692
* The URI or URI template of the resource.
688
- *
689
- * @format uri-template
690
693
*/
691
694
uri : z . string ( ) ,
692
695
} ) ;
0 commit comments