@modelcontextprotocol/sdk 1.21.1 → 1.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/dist/cjs/client/auth.d.ts.map +1 -1
  2. package/dist/cjs/client/auth.js +2 -2
  3. package/dist/cjs/client/auth.js.map +1 -1
  4. package/dist/cjs/client/index.d.ts +747 -1432
  5. package/dist/cjs/client/index.d.ts.map +1 -1
  6. package/dist/cjs/client/index.js +74 -0
  7. package/dist/cjs/client/index.js.map +1 -1
  8. package/dist/cjs/examples/client/simpleStreamableHttp.js +1 -1
  9. package/dist/cjs/examples/client/simpleStreamableHttp.js.map +1 -1
  10. package/dist/cjs/examples/server/elicitationExample.js +2 -4
  11. package/dist/cjs/examples/server/elicitationExample.js.map +1 -1
  12. package/dist/cjs/server/index.d.ts +47 -47
  13. package/dist/cjs/server/index.js +3 -3
  14. package/dist/cjs/server/index.js.map +1 -1
  15. package/dist/cjs/server/mcp.d.ts +5 -5
  16. package/dist/cjs/server/mcp.d.ts.map +1 -1
  17. package/dist/cjs/server/mcp.js +23 -2
  18. package/dist/cjs/server/mcp.js.map +1 -1
  19. package/dist/cjs/shared/metadataUtils.d.ts +5 -1
  20. package/dist/cjs/shared/metadataUtils.d.ts.map +1 -1
  21. package/dist/cjs/shared/metadataUtils.js +2 -5
  22. package/dist/cjs/shared/metadataUtils.js.map +1 -1
  23. package/dist/cjs/shared/protocol.d.ts +2 -1
  24. package/dist/cjs/shared/protocol.d.ts.map +1 -1
  25. package/dist/cjs/shared/protocol.js +15 -6
  26. package/dist/cjs/shared/protocol.js.map +1 -1
  27. package/dist/cjs/shared/toolNameValidation.d.ts +31 -0
  28. package/dist/cjs/shared/toolNameValidation.d.ts.map +1 -0
  29. package/dist/cjs/shared/toolNameValidation.js +97 -0
  30. package/dist/cjs/shared/toolNameValidation.js.map +1 -0
  31. package/dist/cjs/shared/transport.d.ts +1 -1
  32. package/dist/cjs/shared/transport.d.ts.map +1 -1
  33. package/dist/cjs/spec.types.d.ts +459 -211
  34. package/dist/cjs/spec.types.d.ts.map +1 -1
  35. package/dist/cjs/spec.types.js +1 -2
  36. package/dist/cjs/spec.types.js.map +1 -1
  37. package/dist/cjs/types.d.ts +19117 -54214
  38. package/dist/cjs/types.d.ts.map +1 -1
  39. package/dist/cjs/types.js +440 -338
  40. package/dist/cjs/types.js.map +1 -1
  41. package/dist/esm/client/auth.d.ts.map +1 -1
  42. package/dist/esm/client/auth.js +2 -2
  43. package/dist/esm/client/auth.js.map +1 -1
  44. package/dist/esm/client/index.d.ts +747 -1432
  45. package/dist/esm/client/index.d.ts.map +1 -1
  46. package/dist/esm/client/index.js +75 -1
  47. package/dist/esm/client/index.js.map +1 -1
  48. package/dist/esm/examples/client/simpleStreamableHttp.js +1 -1
  49. package/dist/esm/examples/client/simpleStreamableHttp.js.map +1 -1
  50. package/dist/esm/examples/server/elicitationExample.js +2 -4
  51. package/dist/esm/examples/server/elicitationExample.js.map +1 -1
  52. package/dist/esm/server/index.d.ts +47 -47
  53. package/dist/esm/server/index.js +3 -3
  54. package/dist/esm/server/index.js.map +1 -1
  55. package/dist/esm/server/mcp.d.ts +5 -5
  56. package/dist/esm/server/mcp.d.ts.map +1 -1
  57. package/dist/esm/server/mcp.js +24 -3
  58. package/dist/esm/server/mcp.js.map +1 -1
  59. package/dist/esm/shared/metadataUtils.d.ts +5 -1
  60. package/dist/esm/shared/metadataUtils.d.ts.map +1 -1
  61. package/dist/esm/shared/metadataUtils.js +2 -5
  62. package/dist/esm/shared/metadataUtils.js.map +1 -1
  63. package/dist/esm/shared/protocol.d.ts +2 -1
  64. package/dist/esm/shared/protocol.d.ts.map +1 -1
  65. package/dist/esm/shared/protocol.js +15 -6
  66. package/dist/esm/shared/protocol.js.map +1 -1
  67. package/dist/esm/shared/toolNameValidation.d.ts +31 -0
  68. package/dist/esm/shared/toolNameValidation.d.ts.map +1 -0
  69. package/dist/esm/shared/toolNameValidation.js +92 -0
  70. package/dist/esm/shared/toolNameValidation.js.map +1 -0
  71. package/dist/esm/shared/transport.d.ts +1 -1
  72. package/dist/esm/shared/transport.d.ts.map +1 -1
  73. package/dist/esm/spec.types.d.ts +459 -211
  74. package/dist/esm/spec.types.d.ts.map +1 -1
  75. package/dist/esm/spec.types.js +1 -2
  76. package/dist/esm/spec.types.js.map +1 -1
  77. package/dist/esm/types.d.ts +19117 -54214
  78. package/dist/esm/types.d.ts.map +1 -1
  79. package/dist/esm/types.js +435 -335
  80. package/dist/esm/types.js.map +1 -1
  81. package/package.json +1 -1
package/dist/esm/types.js CHANGED
@@ -4,6 +4,12 @@ export const DEFAULT_NEGOTIATED_PROTOCOL_VERSION = '2025-03-26';
4
4
  export const SUPPORTED_PROTOCOL_VERSIONS = [LATEST_PROTOCOL_VERSION, '2025-03-26', '2024-11-05', '2024-10-07'];
5
5
  /* JSON-RPC types */
6
6
  export const JSONRPC_VERSION = '2.0';
7
+ /**
8
+ * Assert 'object' type schema.
9
+ *
10
+ * @internal
11
+ */
12
+ const AssertObjectSchema = z.custom((v) => v !== null && (typeof v === 'object' || typeof v === 'function'));
7
13
  /**
8
14
  * A progress token, used to associate progress notifications with the original request.
9
15
  */
@@ -17,30 +23,35 @@ const RequestMetaSchema = z
17
23
  /**
18
24
  * 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.
19
25
  */
20
- progressToken: z.optional(ProgressTokenSchema)
21
- })
22
- .passthrough();
23
- const BaseRequestParamsSchema = z
24
- .object({
25
- _meta: z.optional(RequestMetaSchema)
26
+ progressToken: ProgressTokenSchema.optional()
26
27
  })
28
+ /**
29
+ * Passthrough required here because we want to allow any additional fields to be added to the request meta.
30
+ */
27
31
  .passthrough();
32
+ /**
33
+ * Common params for any request.
34
+ */
35
+ const BaseRequestParamsSchema = z.object({
36
+ /**
37
+ * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage.
38
+ */
39
+ _meta: RequestMetaSchema.optional()
40
+ });
28
41
  export const RequestSchema = z.object({
29
42
  method: z.string(),
30
- params: z.optional(BaseRequestParamsSchema)
43
+ params: BaseRequestParamsSchema.passthrough().optional()
31
44
  });
32
- const BaseNotificationParamsSchema = z
33
- .object({
45
+ const NotificationsParamsSchema = z.object({
34
46
  /**
35
47
  * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
36
48
  * for notes on _meta usage.
37
49
  */
38
- _meta: z.optional(z.object({}).passthrough())
39
- })
40
- .passthrough();
50
+ _meta: z.record(z.string(), z.unknown()).optional()
51
+ });
41
52
  export const NotificationSchema = z.object({
42
53
  method: z.string(),
43
- params: z.optional(BaseNotificationParamsSchema)
54
+ params: NotificationsParamsSchema.passthrough().optional()
44
55
  });
45
56
  export const ResultSchema = z
46
57
  .object({
@@ -48,8 +59,11 @@ export const ResultSchema = z
48
59
  * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
49
60
  * for notes on _meta usage.
50
61
  */
51
- _meta: z.optional(z.object({}).passthrough())
62
+ _meta: z.record(z.string(), z.unknown()).optional()
52
63
  })
64
+ /**
65
+ * Passthrough required here because we want to allow any additional fields to be added to the result.
66
+ */
53
67
  .passthrough();
54
68
  /**
55
69
  * A uniquely identifying ID for a request in JSON-RPC.
@@ -132,6 +146,18 @@ export const JSONRPCMessageSchema = z.union([JSONRPCRequestSchema, JSONRPCNotifi
132
146
  * A response that indicates success but carries no data.
133
147
  */
134
148
  export const EmptyResultSchema = ResultSchema.strict();
149
+ export const CancelledNotificationParamsSchema = NotificationsParamsSchema.extend({
150
+ /**
151
+ * The ID of the request to cancel.
152
+ *
153
+ * This MUST correspond to the ID of a request previously issued in the same direction.
154
+ */
155
+ requestId: RequestIdSchema,
156
+ /**
157
+ * An optional string describing the reason for the cancellation. This MAY be logged or presented to the user.
158
+ */
159
+ reason: z.string().optional()
160
+ });
135
161
  /* Cancellation */
136
162
  /**
137
163
  * This notification can be sent by either side to indicate that it is cancelling a previously-issued request.
@@ -144,25 +170,13 @@ export const EmptyResultSchema = ResultSchema.strict();
144
170
  */
145
171
  export const CancelledNotificationSchema = NotificationSchema.extend({
146
172
  method: z.literal('notifications/cancelled'),
147
- params: BaseNotificationParamsSchema.extend({
148
- /**
149
- * The ID of the request to cancel.
150
- *
151
- * This MUST correspond to the ID of a request previously issued in the same direction.
152
- */
153
- requestId: RequestIdSchema,
154
- /**
155
- * An optional string describing the reason for the cancellation. This MAY be logged or presented to the user.
156
- */
157
- reason: z.string().optional()
158
- })
173
+ params: CancelledNotificationParamsSchema
159
174
  });
160
175
  /* Base Metadata */
161
176
  /**
162
177
  * Icon schema for use in tools, prompts, resources, and implementations.
163
178
  */
164
- export const IconSchema = z
165
- .object({
179
+ export const IconSchema = z.object({
166
180
  /**
167
181
  * URL or data URI for the icon.
168
182
  */
@@ -170,22 +184,20 @@ export const IconSchema = z
170
184
  /**
171
185
  * Optional MIME type for the icon.
172
186
  */
173
- mimeType: z.optional(z.string()),
187
+ mimeType: z.string().optional(),
174
188
  /**
175
189
  * Optional array of strings that specify sizes at which the icon can be used.
176
190
  * Each string should be in WxH format (e.g., `"48x48"`, `"96x96"`) or `"any"` for scalable formats like SVG.
177
191
  *
178
192
  * If not provided, the client should assume that the icon can be used at any size.
179
193
  */
180
- sizes: z.optional(z.array(z.string()))
181
- })
182
- .passthrough();
194
+ sizes: z.array(z.string()).optional()
195
+ });
183
196
  /**
184
197
  * Base schema to add `icons` property.
185
198
  *
186
199
  */
187
- export const IconsSchema = z
188
- .object({
200
+ export const IconsSchema = z.object({
189
201
  /**
190
202
  * Optional set of sized icons that the client can display in a user interface.
191
203
  *
@@ -198,13 +210,11 @@ export const IconsSchema = z
198
210
  * - `image/webp` - WebP images (modern, efficient format)
199
211
  */
200
212
  icons: z.array(IconSchema).optional()
201
- })
202
- .passthrough();
213
+ });
203
214
  /**
204
215
  * Base metadata interface for common properties across resources, tools, prompts, and implementations.
205
216
  */
206
- export const BaseMetadataSchema = z
207
- .object({
217
+ export const BaseMetadataSchema = z.object({
208
218
  /** Intended for programmatic or logical use, but used as a display name in past specs or fallback */
209
219
  name: z.string(),
210
220
  /**
@@ -215,9 +225,8 @@ export const BaseMetadataSchema = z
215
225
  * where `annotations.title` should be given precedence over using `name`,
216
226
  * if present).
217
227
  */
218
- title: z.optional(z.string())
219
- })
220
- .passthrough();
228
+ title: z.string().optional()
229
+ });
221
230
  /* Initialization */
222
231
  /**
223
232
  * Describes the name and version of an MCP implementation.
@@ -227,109 +236,111 @@ export const ImplementationSchema = BaseMetadataSchema.extend({
227
236
  /**
228
237
  * An optional URL of the website for this implementation.
229
238
  */
230
- websiteUrl: z.optional(z.string())
239
+ websiteUrl: z.string().optional()
231
240
  }).merge(IconsSchema);
232
241
  /**
233
242
  * 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.
234
243
  */
235
- export const ClientCapabilitiesSchema = z
236
- .object({
244
+ export const ClientCapabilitiesSchema = z.object({
237
245
  /**
238
246
  * Experimental, non-standard capabilities that the client supports.
239
247
  */
240
- experimental: z.optional(z.object({}).passthrough()),
248
+ experimental: z.record(z.string(), AssertObjectSchema).optional(),
241
249
  /**
242
250
  * Present if the client supports sampling from an LLM.
243
251
  */
244
- sampling: z.optional(z.object({}).passthrough()),
252
+ sampling: AssertObjectSchema.optional(),
245
253
  /**
246
254
  * Present if the client supports eliciting user input.
247
255
  */
248
- elicitation: z.optional(z.object({}).passthrough()),
256
+ elicitation: z.intersection(z
257
+ .object({
258
+ /**
259
+ * Whether the client should apply defaults to the user input.
260
+ */
261
+ applyDefaults: z.boolean().optional()
262
+ })
263
+ .optional(), z.record(z.string(), z.unknown()).optional()),
249
264
  /**
250
265
  * Present if the client supports listing roots.
251
266
  */
252
- roots: z.optional(z
267
+ roots: z
253
268
  .object({
254
269
  /**
255
270
  * Whether the client supports issuing notifications for changes to the roots list.
256
271
  */
257
- listChanged: z.optional(z.boolean())
272
+ listChanged: z.boolean().optional()
258
273
  })
259
- .passthrough())
260
- })
261
- .passthrough();
274
+ .optional()
275
+ });
276
+ export const InitializeRequestParamsSchema = BaseRequestParamsSchema.extend({
277
+ /**
278
+ * The latest version of the Model Context Protocol that the client supports. The client MAY decide to support older versions as well.
279
+ */
280
+ protocolVersion: z.string(),
281
+ capabilities: ClientCapabilitiesSchema,
282
+ clientInfo: ImplementationSchema
283
+ });
262
284
  /**
263
285
  * This request is sent from the client to the server when it first connects, asking it to begin initialization.
264
286
  */
265
287
  export const InitializeRequestSchema = RequestSchema.extend({
266
288
  method: z.literal('initialize'),
267
- params: BaseRequestParamsSchema.extend({
268
- /**
269
- * The latest version of the Model Context Protocol that the client supports. The client MAY decide to support older versions as well.
270
- */
271
- protocolVersion: z.string(),
272
- capabilities: ClientCapabilitiesSchema,
273
- clientInfo: ImplementationSchema
274
- })
289
+ params: InitializeRequestParamsSchema
275
290
  });
276
291
  export const isInitializeRequest = (value) => InitializeRequestSchema.safeParse(value).success;
277
292
  /**
278
293
  * 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.
279
294
  */
280
- export const ServerCapabilitiesSchema = z
281
- .object({
295
+ export const ServerCapabilitiesSchema = z.object({
282
296
  /**
283
297
  * Experimental, non-standard capabilities that the server supports.
284
298
  */
285
- experimental: z.optional(z.object({}).passthrough()),
299
+ experimental: z.record(z.string(), AssertObjectSchema).optional(),
286
300
  /**
287
301
  * Present if the server supports sending log messages to the client.
288
302
  */
289
- logging: z.optional(z.object({}).passthrough()),
303
+ logging: AssertObjectSchema.optional(),
290
304
  /**
291
305
  * Present if the server supports sending completions to the client.
292
306
  */
293
- completions: z.optional(z.object({}).passthrough()),
307
+ completions: AssertObjectSchema.optional(),
294
308
  /**
295
309
  * Present if the server offers any prompt templates.
296
310
  */
297
- prompts: z.optional(z
298
- .object({
311
+ prompts: z.optional(z.object({
299
312
  /**
300
313
  * Whether this server supports issuing notifications for changes to the prompt list.
301
314
  */
302
315
  listChanged: z.optional(z.boolean())
303
- })
304
- .passthrough()),
316
+ })),
305
317
  /**
306
318
  * Present if the server offers any resources to read.
307
319
  */
308
- resources: z.optional(z
320
+ resources: z
309
321
  .object({
310
322
  /**
311
323
  * Whether this server supports clients subscribing to resource updates.
312
324
  */
313
- subscribe: z.optional(z.boolean()),
325
+ subscribe: z.boolean().optional(),
314
326
  /**
315
327
  * Whether this server supports issuing notifications for changes to the resource list.
316
328
  */
317
- listChanged: z.optional(z.boolean())
329
+ listChanged: z.boolean().optional()
318
330
  })
319
- .passthrough()),
331
+ .optional(),
320
332
  /**
321
333
  * Present if the server offers any tools to call.
322
334
  */
323
- tools: z.optional(z
335
+ tools: z
324
336
  .object({
325
337
  /**
326
338
  * Whether this server supports issuing notifications for changes to the tool list.
327
339
  */
328
- listChanged: z.optional(z.boolean())
340
+ listChanged: z.boolean().optional()
329
341
  })
330
- .passthrough())
331
- })
332
- .passthrough();
342
+ .optional()
343
+ });
333
344
  /**
334
345
  * After receiving an initialize request from the client, the server sends this response.
335
346
  */
@@ -345,7 +356,7 @@ export const InitializeResultSchema = ResultSchema.extend({
345
356
  *
346
357
  * 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.
347
358
  */
348
- instructions: z.optional(z.string())
359
+ instructions: z.string().optional()
349
360
  });
350
361
  /**
351
362
  * This notification is sent from the client to the server after initialization has finished.
@@ -362,8 +373,7 @@ export const PingRequestSchema = RequestSchema.extend({
362
373
  method: z.literal('ping')
363
374
  });
364
375
  /* Progress notifications */
365
- export const ProgressSchema = z
366
- .object({
376
+ export const ProgressSchema = z.object({
367
377
  /**
368
378
  * The progress thus far. This should increase every time progress is made, even if the total is unknown.
369
379
  */
@@ -376,29 +386,32 @@ export const ProgressSchema = z
376
386
  * An optional message describing the current progress.
377
387
  */
378
388
  message: z.optional(z.string())
379
- })
380
- .passthrough();
389
+ });
390
+ export const ProgressNotificationParamsSchema = NotificationsParamsSchema.merge(ProgressSchema).extend({
391
+ /**
392
+ * The progress token which was given in the initial request, used to associate this notification with the request that is proceeding.
393
+ */
394
+ progressToken: ProgressTokenSchema
395
+ });
381
396
  /**
382
397
  * An out-of-band notification used to inform the receiver of a progress update for a long-running request.
398
+ *
399
+ * @category notifications/progress
383
400
  */
384
401
  export const ProgressNotificationSchema = NotificationSchema.extend({
385
402
  method: z.literal('notifications/progress'),
386
- params: BaseNotificationParamsSchema.merge(ProgressSchema).extend({
387
- /**
388
- * The progress token which was given in the initial request, used to associate this notification with the request that is proceeding.
389
- */
390
- progressToken: ProgressTokenSchema
391
- })
403
+ params: ProgressNotificationParamsSchema
404
+ });
405
+ export const PaginatedRequestParamsSchema = BaseRequestParamsSchema.extend({
406
+ /**
407
+ * An opaque token representing the current pagination position.
408
+ * If provided, the server should return results starting after this cursor.
409
+ */
410
+ cursor: CursorSchema.optional()
392
411
  });
393
412
  /* Pagination */
394
413
  export const PaginatedRequestSchema = RequestSchema.extend({
395
- params: BaseRequestParamsSchema.extend({
396
- /**
397
- * An opaque token representing the current pagination position.
398
- * If provided, the server should return results starting after this cursor.
399
- */
400
- cursor: z.optional(CursorSchema)
401
- }).optional()
414
+ params: PaginatedRequestParamsSchema.optional()
402
415
  });
403
416
  export const PaginatedResultSchema = ResultSchema.extend({
404
417
  /**
@@ -411,8 +424,7 @@ export const PaginatedResultSchema = ResultSchema.extend({
411
424
  /**
412
425
  * The contents of a specific resource or sub-resource.
413
426
  */
414
- export const ResourceContentsSchema = z
415
- .object({
427
+ export const ResourceContentsSchema = z.object({
416
428
  /**
417
429
  * The URI of this resource.
418
430
  */
@@ -425,9 +437,8 @@ export const ResourceContentsSchema = z
425
437
  * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
426
438
  * for notes on _meta usage.
427
439
  */
428
- _meta: z.optional(z.object({}).passthrough())
429
- })
430
- .passthrough();
440
+ _meta: z.record(z.string(), z.unknown()).optional()
441
+ });
431
442
  export const TextResourceContentsSchema = ResourceContentsSchema.extend({
432
443
  /**
433
444
  * The text of the item. This must only be set if the item can actually be represented as text (not binary data).
@@ -528,17 +539,24 @@ export const ListResourceTemplatesRequestSchema = PaginatedRequestSchema.extend(
528
539
  export const ListResourceTemplatesResultSchema = PaginatedResultSchema.extend({
529
540
  resourceTemplates: z.array(ResourceTemplateSchema)
530
541
  });
542
+ export const ResourceRequestParamsSchema = BaseRequestParamsSchema.extend({
543
+ /**
544
+ * The URI of the resource to read. The URI can use any protocol; it is up to the server how to interpret it.
545
+ *
546
+ * @format uri
547
+ */
548
+ uri: z.string()
549
+ });
550
+ /**
551
+ * Parameters for a `resources/read` request.
552
+ */
553
+ export const ReadResourceRequestParamsSchema = ResourceRequestParamsSchema;
531
554
  /**
532
555
  * Sent from the client to the server, to read a specific resource URI.
533
556
  */
534
557
  export const ReadResourceRequestSchema = RequestSchema.extend({
535
558
  method: z.literal('resources/read'),
536
- params: BaseRequestParamsSchema.extend({
537
- /**
538
- * The URI of the resource to read. The URI can use any protocol; it is up to the server how to interpret it.
539
- */
540
- uri: z.string()
541
- })
559
+ params: ReadResourceRequestParamsSchema
542
560
  });
543
561
  /**
544
562
  * The server's response to a resources/read request from the client.
@@ -552,48 +570,43 @@ export const ReadResourceResultSchema = ResultSchema.extend({
552
570
  export const ResourceListChangedNotificationSchema = NotificationSchema.extend({
553
571
  method: z.literal('notifications/resources/list_changed')
554
572
  });
573
+ export const SubscribeRequestParamsSchema = ResourceRequestParamsSchema;
555
574
  /**
556
575
  * Sent from the client to request resources/updated notifications from the server whenever a particular resource changes.
557
576
  */
558
577
  export const SubscribeRequestSchema = RequestSchema.extend({
559
578
  method: z.literal('resources/subscribe'),
560
- params: BaseRequestParamsSchema.extend({
561
- /**
562
- * The URI of the resource to subscribe to. The URI can use any protocol; it is up to the server how to interpret it.
563
- */
564
- uri: z.string()
565
- })
579
+ params: SubscribeRequestParamsSchema
566
580
  });
581
+ export const UnsubscribeRequestParamsSchema = ResourceRequestParamsSchema;
567
582
  /**
568
583
  * Sent from the client to request cancellation of resources/updated notifications from the server. This should follow a previous resources/subscribe request.
569
584
  */
570
585
  export const UnsubscribeRequestSchema = RequestSchema.extend({
571
586
  method: z.literal('resources/unsubscribe'),
572
- params: BaseRequestParamsSchema.extend({
573
- /**
574
- * The URI of the resource to unsubscribe from.
575
- */
576
- uri: z.string()
577
- })
587
+ params: UnsubscribeRequestParamsSchema
588
+ });
589
+ /**
590
+ * Parameters for a `notifications/resources/updated` notification.
591
+ */
592
+ export const ResourceUpdatedNotificationParamsSchema = NotificationsParamsSchema.extend({
593
+ /**
594
+ * The URI of the resource that has been updated. This might be a sub-resource of the one that the client actually subscribed to.
595
+ */
596
+ uri: z.string()
578
597
  });
579
598
  /**
580
599
  * A notification from the server to the client, informing it that a resource has changed and may need to be read again. This should only be sent if the client previously sent a resources/subscribe request.
581
600
  */
582
601
  export const ResourceUpdatedNotificationSchema = NotificationSchema.extend({
583
602
  method: z.literal('notifications/resources/updated'),
584
- params: BaseNotificationParamsSchema.extend({
585
- /**
586
- * The URI of the resource that has been updated. This might be a sub-resource of the one that the client actually subscribed to.
587
- */
588
- uri: z.string()
589
- })
603
+ params: ResourceUpdatedNotificationParamsSchema
590
604
  });
591
605
  /* Prompts */
592
606
  /**
593
607
  * Describes an argument that a prompt can accept.
594
608
  */
595
- export const PromptArgumentSchema = z
596
- .object({
609
+ export const PromptArgumentSchema = z.object({
597
610
  /**
598
611
  * The name of the argument.
599
612
  */
@@ -606,8 +619,7 @@ export const PromptArgumentSchema = z
606
619
  * Whether this argument must be provided.
607
620
  */
608
621
  required: z.optional(z.boolean())
609
- })
610
- .passthrough();
622
+ });
611
623
  /**
612
624
  * A prompt or prompt template that the server offers.
613
625
  */
@@ -638,27 +650,30 @@ export const ListPromptsRequestSchema = PaginatedRequestSchema.extend({
638
650
  export const ListPromptsResultSchema = PaginatedResultSchema.extend({
639
651
  prompts: z.array(PromptSchema)
640
652
  });
653
+ /**
654
+ * Parameters for a `prompts/get` request.
655
+ */
656
+ export const GetPromptRequestParamsSchema = BaseRequestParamsSchema.extend({
657
+ /**
658
+ * The name of the prompt or prompt template.
659
+ */
660
+ name: z.string(),
661
+ /**
662
+ * Arguments to use for templating the prompt.
663
+ */
664
+ arguments: z.record(z.string(), z.string()).optional()
665
+ });
641
666
  /**
642
667
  * Used by the client to get a prompt provided by the server.
643
668
  */
644
669
  export const GetPromptRequestSchema = RequestSchema.extend({
645
670
  method: z.literal('prompts/get'),
646
- params: BaseRequestParamsSchema.extend({
647
- /**
648
- * The name of the prompt or prompt template.
649
- */
650
- name: z.string(),
651
- /**
652
- * Arguments to use for templating the prompt.
653
- */
654
- arguments: z.optional(z.record(z.string()))
655
- })
671
+ params: GetPromptRequestParamsSchema
656
672
  });
657
673
  /**
658
674
  * Text provided to or from an LLM.
659
675
  */
660
- export const TextContentSchema = z
661
- .object({
676
+ export const TextContentSchema = z.object({
662
677
  type: z.literal('text'),
663
678
  /**
664
679
  * The text content of the message.
@@ -668,14 +683,12 @@ export const TextContentSchema = z
668
683
  * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
669
684
  * for notes on _meta usage.
670
685
  */
671
- _meta: z.optional(z.object({}).passthrough())
672
- })
673
- .passthrough();
686
+ _meta: z.record(z.string(), z.unknown()).optional()
687
+ });
674
688
  /**
675
689
  * An image provided to or from an LLM.
676
690
  */
677
- export const ImageContentSchema = z
678
- .object({
691
+ export const ImageContentSchema = z.object({
679
692
  type: z.literal('image'),
680
693
  /**
681
694
  * The base64-encoded image data.
@@ -689,14 +702,12 @@ export const ImageContentSchema = z
689
702
  * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
690
703
  * for notes on _meta usage.
691
704
  */
692
- _meta: z.optional(z.object({}).passthrough())
693
- })
694
- .passthrough();
705
+ _meta: z.record(z.string(), z.unknown()).optional()
706
+ });
695
707
  /**
696
708
  * An Audio provided to or from an LLM.
697
709
  */
698
- export const AudioContentSchema = z
699
- .object({
710
+ export const AudioContentSchema = z.object({
700
711
  type: z.literal('audio'),
701
712
  /**
702
713
  * The base64-encoded audio data.
@@ -710,23 +721,20 @@ export const AudioContentSchema = z
710
721
  * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
711
722
  * for notes on _meta usage.
712
723
  */
713
- _meta: z.optional(z.object({}).passthrough())
714
- })
715
- .passthrough();
724
+ _meta: z.record(z.string(), z.unknown()).optional()
725
+ });
716
726
  /**
717
727
  * The contents of a resource, embedded into a prompt or tool call result.
718
728
  */
719
- export const EmbeddedResourceSchema = z
720
- .object({
729
+ export const EmbeddedResourceSchema = z.object({
721
730
  type: z.literal('resource'),
722
731
  resource: z.union([TextResourceContentsSchema, BlobResourceContentsSchema]),
723
732
  /**
724
733
  * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
725
734
  * for notes on _meta usage.
726
735
  */
727
- _meta: z.optional(z.object({}).passthrough())
728
- })
729
- .passthrough();
736
+ _meta: z.record(z.string(), z.unknown()).optional()
737
+ });
730
738
  /**
731
739
  * A resource that the server is capable of reading, included in a prompt or tool call result.
732
740
  *
@@ -748,12 +756,10 @@ export const ContentBlockSchema = z.union([
748
756
  /**
749
757
  * Describes a message returned as part of a prompt.
750
758
  */
751
- export const PromptMessageSchema = z
752
- .object({
759
+ export const PromptMessageSchema = z.object({
753
760
  role: z.enum(['user', 'assistant']),
754
761
  content: ContentBlockSchema
755
- })
756
- .passthrough();
762
+ });
757
763
  /**
758
764
  * The server's response to a prompts/get request from the client.
759
765
  */
@@ -781,18 +787,17 @@ export const PromptListChangedNotificationSchema = NotificationSchema.extend({
781
787
  * Clients should never make tool use decisions based on ToolAnnotations
782
788
  * received from untrusted servers.
783
789
  */
784
- export const ToolAnnotationsSchema = z
785
- .object({
790
+ export const ToolAnnotationsSchema = z.object({
786
791
  /**
787
792
  * A human-readable title for the tool.
788
793
  */
789
- title: z.optional(z.string()),
794
+ title: z.string().optional(),
790
795
  /**
791
796
  * If true, the tool does not modify its environment.
792
797
  *
793
798
  * Default: false
794
799
  */
795
- readOnlyHint: z.optional(z.boolean()),
800
+ readOnlyHint: z.boolean().optional(),
796
801
  /**
797
802
  * If true, the tool may perform destructive updates to its environment.
798
803
  * If false, the tool performs only additive updates.
@@ -801,7 +806,7 @@ export const ToolAnnotationsSchema = z
801
806
  *
802
807
  * Default: true
803
808
  */
804
- destructiveHint: z.optional(z.boolean()),
809
+ destructiveHint: z.boolean().optional(),
805
810
  /**
806
811
  * If true, calling the tool repeatedly with the same arguments
807
812
  * will have no additional effect on the its environment.
@@ -810,7 +815,7 @@ export const ToolAnnotationsSchema = z
810
815
  *
811
816
  * Default: false
812
817
  */
813
- idempotentHint: z.optional(z.boolean()),
818
+ idempotentHint: z.boolean().optional(),
814
819
  /**
815
820
  * If true, this tool may interact with an "open world" of external
816
821
  * entities. If false, the tool's domain of interaction is closed.
@@ -819,9 +824,8 @@ export const ToolAnnotationsSchema = z
819
824
  *
820
825
  * Default: true
821
826
  */
822
- openWorldHint: z.optional(z.boolean())
823
- })
824
- .passthrough();
827
+ openWorldHint: z.boolean().optional()
828
+ });
825
829
  /**
826
830
  * Definition for a tool the client can call.
827
831
  */
@@ -829,28 +833,30 @@ export const ToolSchema = BaseMetadataSchema.extend({
829
833
  /**
830
834
  * A human-readable description of the tool.
831
835
  */
832
- description: z.optional(z.string()),
836
+ description: z.string().optional(),
833
837
  /**
834
838
  * A JSON Schema object defining the expected parameters for the tool.
835
839
  */
836
- inputSchema: z
837
- .object({
840
+ inputSchema: z.object({
838
841
  type: z.literal('object'),
839
- properties: z.optional(z.object({}).passthrough()),
842
+ properties: z.record(z.string(), AssertObjectSchema).optional(),
840
843
  required: z.optional(z.array(z.string()))
841
- })
842
- .passthrough(),
844
+ }),
843
845
  /**
844
846
  * An optional JSON Schema object defining the structure of the tool's output returned in
845
847
  * the structuredContent field of a CallToolResult.
846
848
  */
847
- outputSchema: z.optional(z
849
+ outputSchema: z
848
850
  .object({
849
851
  type: z.literal('object'),
850
- properties: z.optional(z.object({}).passthrough()),
851
- required: z.optional(z.array(z.string()))
852
+ properties: z.record(z.string(), AssertObjectSchema).optional(),
853
+ required: z.optional(z.array(z.string())),
854
+ /**
855
+ * Not in the MCP specification, but added to support the Ajv validator while removing .passthrough() which previously allowed additionalProperties to be passed through.
856
+ */
857
+ additionalProperties: z.optional(z.boolean())
852
858
  })
853
- .passthrough()),
859
+ .optional(),
854
860
  /**
855
861
  * Optional additional tool information.
856
862
  */
@@ -859,7 +865,7 @@ export const ToolSchema = BaseMetadataSchema.extend({
859
865
  * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
860
866
  * for notes on _meta usage.
861
867
  */
862
- _meta: z.optional(z.object({}).passthrough())
868
+ _meta: z.record(z.string(), z.unknown()).optional()
863
869
  }).merge(IconsSchema);
864
870
  /**
865
871
  * Sent from the client to request a list of tools the server has.
@@ -889,7 +895,7 @@ export const CallToolResultSchema = ResultSchema.extend({
889
895
  *
890
896
  * If the Tool defines an outputSchema, this field MUST be present in the result, and contain a JSON object that matches the schema.
891
897
  */
892
- structuredContent: z.object({}).passthrough().optional(),
898
+ structuredContent: z.record(z.string(), z.unknown()).optional(),
893
899
  /**
894
900
  * Whether the tool call ended in an error.
895
901
  *
@@ -912,15 +918,25 @@ export const CallToolResultSchema = ResultSchema.extend({
912
918
  export const CompatibilityCallToolResultSchema = CallToolResultSchema.or(ResultSchema.extend({
913
919
  toolResult: z.unknown()
914
920
  }));
921
+ /**
922
+ * Parameters for a `tools/call` request.
923
+ */
924
+ export const CallToolRequestParamsSchema = BaseRequestParamsSchema.extend({
925
+ /**
926
+ * The name of the tool to call.
927
+ */
928
+ name: z.string(),
929
+ /**
930
+ * Arguments to pass to the tool.
931
+ */
932
+ arguments: z.optional(z.record(z.string(), z.unknown()))
933
+ });
915
934
  /**
916
935
  * Used by the client to invoke a tool provided by the server.
917
936
  */
918
937
  export const CallToolRequestSchema = RequestSchema.extend({
919
938
  method: z.literal('tools/call'),
920
- params: BaseRequestParamsSchema.extend({
921
- name: z.string(),
922
- arguments: z.optional(z.record(z.unknown()))
923
- })
939
+ params: CallToolRequestParamsSchema
924
940
  });
925
941
  /**
926
942
  * An optional notification from the server to the client, informing it that the list of tools it offers has changed. This may be issued by servers without any previous subscription from the client.
@@ -933,55 +949,60 @@ export const ToolListChangedNotificationSchema = NotificationSchema.extend({
933
949
  * The severity of a log message.
934
950
  */
935
951
  export const LoggingLevelSchema = z.enum(['debug', 'info', 'notice', 'warning', 'error', 'critical', 'alert', 'emergency']);
952
+ /**
953
+ * Parameters for a `logging/setLevel` request.
954
+ */
955
+ export const SetLevelRequestParamsSchema = BaseRequestParamsSchema.extend({
956
+ /**
957
+ * 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.
958
+ */
959
+ level: LoggingLevelSchema
960
+ });
936
961
  /**
937
962
  * A request from the client to the server, to enable or adjust logging.
938
963
  */
939
964
  export const SetLevelRequestSchema = RequestSchema.extend({
940
965
  method: z.literal('logging/setLevel'),
941
- params: BaseRequestParamsSchema.extend({
942
- /**
943
- * 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.
944
- */
945
- level: LoggingLevelSchema
946
- })
966
+ params: SetLevelRequestParamsSchema
967
+ });
968
+ /**
969
+ * Parameters for a `notifications/message` notification.
970
+ */
971
+ export const LoggingMessageNotificationParamsSchema = NotificationsParamsSchema.extend({
972
+ /**
973
+ * The severity of this log message.
974
+ */
975
+ level: LoggingLevelSchema,
976
+ /**
977
+ * An optional name of the logger issuing this message.
978
+ */
979
+ logger: z.string().optional(),
980
+ /**
981
+ * The data to be logged, such as a string message or an object. Any JSON serializable type is allowed here.
982
+ */
983
+ data: z.unknown()
947
984
  });
948
985
  /**
949
986
  * Notification of a log message passed from server to client. If no logging/setLevel request has been sent from the client, the server MAY decide which messages to send automatically.
950
987
  */
951
988
  export const LoggingMessageNotificationSchema = NotificationSchema.extend({
952
989
  method: z.literal('notifications/message'),
953
- params: BaseNotificationParamsSchema.extend({
954
- /**
955
- * The severity of this log message.
956
- */
957
- level: LoggingLevelSchema,
958
- /**
959
- * An optional name of the logger issuing this message.
960
- */
961
- logger: z.optional(z.string()),
962
- /**
963
- * The data to be logged, such as a string message or an object. Any JSON serializable type is allowed here.
964
- */
965
- data: z.unknown()
966
- })
990
+ params: LoggingMessageNotificationParamsSchema
967
991
  });
968
992
  /* Sampling */
969
993
  /**
970
994
  * Hints to use for model selection.
971
995
  */
972
- export const ModelHintSchema = z
973
- .object({
996
+ export const ModelHintSchema = z.object({
974
997
  /**
975
998
  * A hint for a model name.
976
999
  */
977
1000
  name: z.string().optional()
978
- })
979
- .passthrough();
1001
+ });
980
1002
  /**
981
1003
  * The server's preferences for model selection, requested of the client during sampling.
982
1004
  */
983
- export const ModelPreferencesSchema = z
984
- .object({
1005
+ export const ModelPreferencesSchema = z.object({
985
1006
  /**
986
1007
  * Optional hints to use for model selection.
987
1008
  */
@@ -998,47 +1019,50 @@ export const ModelPreferencesSchema = z
998
1019
  * How much to prioritize intelligence and capabilities when selecting a model.
999
1020
  */
1000
1021
  intelligencePriority: z.optional(z.number().min(0).max(1))
1001
- })
1002
- .passthrough();
1022
+ });
1003
1023
  /**
1004
1024
  * Describes a message issued to or received from an LLM API.
1005
1025
  */
1006
- export const SamplingMessageSchema = z
1007
- .object({
1026
+ export const SamplingMessageSchema = z.object({
1008
1027
  role: z.enum(['user', 'assistant']),
1009
1028
  content: z.union([TextContentSchema, ImageContentSchema, AudioContentSchema])
1010
- })
1011
- .passthrough();
1029
+ });
1030
+ /**
1031
+ * Parameters for a `sampling/createMessage` request.
1032
+ */
1033
+ export const CreateMessageRequestParamsSchema = BaseRequestParamsSchema.extend({
1034
+ messages: z.array(SamplingMessageSchema),
1035
+ /**
1036
+ * The server's preferences for which model to select. The client MAY modify or omit this request.
1037
+ */
1038
+ modelPreferences: ModelPreferencesSchema.optional(),
1039
+ /**
1040
+ * An optional system prompt the server wants to use for sampling. The client MAY modify or omit this prompt.
1041
+ */
1042
+ systemPrompt: z.string().optional(),
1043
+ /**
1044
+ * A request to include context from one or more MCP servers (including the caller), to be attached to the prompt. The client MAY ignore this request.
1045
+ */
1046
+ includeContext: z.enum(['none', 'thisServer', 'allServers']).optional(),
1047
+ temperature: z.number().optional(),
1048
+ /**
1049
+ * The requested maximum number of tokens to sample (to prevent runaway completions).
1050
+ *
1051
+ * The client MAY choose to sample fewer tokens than the requested maximum.
1052
+ */
1053
+ maxTokens: z.number().int(),
1054
+ stopSequences: z.array(z.string()).optional(),
1055
+ /**
1056
+ * Optional metadata to pass through to the LLM provider. The format of this metadata is provider-specific.
1057
+ */
1058
+ metadata: AssertObjectSchema.optional()
1059
+ });
1012
1060
  /**
1013
1061
  * A request from the server to sample an LLM via the client. The client has full discretion over which model to select. The client should also inform the user before beginning sampling, to allow them to inspect the request (human in the loop) and decide whether to approve it.
1014
1062
  */
1015
1063
  export const CreateMessageRequestSchema = RequestSchema.extend({
1016
1064
  method: z.literal('sampling/createMessage'),
1017
- params: BaseRequestParamsSchema.extend({
1018
- messages: z.array(SamplingMessageSchema),
1019
- /**
1020
- * An optional system prompt the server wants to use for sampling. The client MAY modify or omit this prompt.
1021
- */
1022
- systemPrompt: z.optional(z.string()),
1023
- /**
1024
- * A request to include context from one or more MCP servers (including the caller), to be attached to the prompt. The client MAY ignore this request.
1025
- */
1026
- includeContext: z.optional(z.enum(['none', 'thisServer', 'allServers'])),
1027
- temperature: z.optional(z.number()),
1028
- /**
1029
- * The maximum number of tokens to sample, as requested by the server. The client MAY choose to sample fewer tokens than requested.
1030
- */
1031
- maxTokens: z.number().int(),
1032
- stopSequences: z.optional(z.array(z.string())),
1033
- /**
1034
- * Optional metadata to pass through to the LLM provider. The format of this metadata is provider-specific.
1035
- */
1036
- metadata: z.optional(z.object({}).passthrough()),
1037
- /**
1038
- * The server's preferences for which model to select.
1039
- */
1040
- modelPreferences: z.optional(ModelPreferencesSchema)
1041
- })
1065
+ params: CreateMessageRequestParamsSchema
1042
1066
  });
1043
1067
  /**
1044
1068
  * The client's response to a sampling/create_message request from the server. The client should inform the user before returning the sampled message, to allow them to inspect the response (human in the loop) and decide whether to allow the server to see it.
@@ -1059,104 +1083,170 @@ export const CreateMessageResultSchema = ResultSchema.extend({
1059
1083
  /**
1060
1084
  * Primitive schema definition for boolean fields.
1061
1085
  */
1062
- export const BooleanSchemaSchema = z
1063
- .object({
1086
+ export const BooleanSchemaSchema = z.object({
1064
1087
  type: z.literal('boolean'),
1065
- title: z.optional(z.string()),
1066
- description: z.optional(z.string()),
1067
- default: z.optional(z.boolean())
1068
- })
1069
- .passthrough();
1088
+ title: z.string().optional(),
1089
+ description: z.string().optional(),
1090
+ default: z.boolean().optional()
1091
+ });
1070
1092
  /**
1071
1093
  * Primitive schema definition for string fields.
1072
1094
  */
1073
- export const StringSchemaSchema = z
1074
- .object({
1095
+ export const StringSchemaSchema = z.object({
1075
1096
  type: z.literal('string'),
1076
- title: z.optional(z.string()),
1077
- description: z.optional(z.string()),
1078
- minLength: z.optional(z.number()),
1079
- maxLength: z.optional(z.number()),
1080
- format: z.optional(z.enum(['email', 'uri', 'date', 'date-time']))
1081
- })
1082
- .passthrough();
1097
+ title: z.string().optional(),
1098
+ description: z.string().optional(),
1099
+ minLength: z.number().optional(),
1100
+ maxLength: z.number().optional(),
1101
+ format: z.enum(['email', 'uri', 'date', 'date-time']).optional(),
1102
+ default: z.string().optional()
1103
+ });
1083
1104
  /**
1084
1105
  * Primitive schema definition for number fields.
1085
1106
  */
1086
- export const NumberSchemaSchema = z
1087
- .object({
1107
+ export const NumberSchemaSchema = z.object({
1088
1108
  type: z.enum(['number', 'integer']),
1089
- title: z.optional(z.string()),
1090
- description: z.optional(z.string()),
1091
- minimum: z.optional(z.number()),
1092
- maximum: z.optional(z.number())
1093
- })
1094
- .passthrough();
1109
+ title: z.string().optional(),
1110
+ description: z.string().optional(),
1111
+ minimum: z.number().optional(),
1112
+ maximum: z.number().optional(),
1113
+ default: z.number().optional()
1114
+ });
1095
1115
  /**
1096
- * Primitive schema definition for enum fields.
1116
+ * Schema for single-selection enumeration without display titles for options.
1097
1117
  */
1098
- export const EnumSchemaSchema = z
1099
- .object({
1118
+ export const UntitledSingleSelectEnumSchemaSchema = z.object({
1100
1119
  type: z.literal('string'),
1101
- title: z.optional(z.string()),
1102
- description: z.optional(z.string()),
1120
+ title: z.string().optional(),
1121
+ description: z.string().optional(),
1103
1122
  enum: z.array(z.string()),
1104
- enumNames: z.optional(z.array(z.string()))
1105
- })
1106
- .passthrough();
1123
+ default: z.string().optional()
1124
+ });
1125
+ /**
1126
+ * Schema for single-selection enumeration with display titles for each option.
1127
+ */
1128
+ export const TitledSingleSelectEnumSchemaSchema = z.object({
1129
+ type: z.literal('string'),
1130
+ title: z.string().optional(),
1131
+ description: z.string().optional(),
1132
+ oneOf: z.array(z.object({
1133
+ const: z.string(),
1134
+ title: z.string()
1135
+ })),
1136
+ default: z.string().optional()
1137
+ });
1138
+ /**
1139
+ * Use TitledSingleSelectEnumSchema instead.
1140
+ * This interface will be removed in a future version.
1141
+ */
1142
+ export const LegacyTitledEnumSchemaSchema = z.object({
1143
+ type: z.literal('string'),
1144
+ title: z.string().optional(),
1145
+ description: z.string().optional(),
1146
+ enum: z.array(z.string()),
1147
+ enumNames: z.array(z.string()).optional(),
1148
+ default: z.string().optional()
1149
+ });
1150
+ // Combined single selection enumeration
1151
+ export const SingleSelectEnumSchemaSchema = z.union([UntitledSingleSelectEnumSchemaSchema, TitledSingleSelectEnumSchemaSchema]);
1152
+ /**
1153
+ * Schema for multiple-selection enumeration without display titles for options.
1154
+ */
1155
+ export const UntitledMultiSelectEnumSchemaSchema = z.object({
1156
+ type: z.literal('array'),
1157
+ title: z.string().optional(),
1158
+ description: z.string().optional(),
1159
+ minItems: z.number().optional(),
1160
+ maxItems: z.number().optional(),
1161
+ items: z.object({
1162
+ type: z.literal('string'),
1163
+ enum: z.array(z.string())
1164
+ }),
1165
+ default: z.array(z.string()).optional()
1166
+ });
1167
+ /**
1168
+ * Schema for multiple-selection enumeration with display titles for each option.
1169
+ */
1170
+ export const TitledMultiSelectEnumSchemaSchema = z.object({
1171
+ type: z.literal('array'),
1172
+ title: z.string().optional(),
1173
+ description: z.string().optional(),
1174
+ minItems: z.number().optional(),
1175
+ maxItems: z.number().optional(),
1176
+ items: z.object({
1177
+ anyOf: z.array(z.object({
1178
+ const: z.string(),
1179
+ title: z.string()
1180
+ }))
1181
+ }),
1182
+ default: z.array(z.string()).optional()
1183
+ });
1184
+ /**
1185
+ * Combined schema for multiple-selection enumeration
1186
+ */
1187
+ export const MultiSelectEnumSchemaSchema = z.union([UntitledMultiSelectEnumSchemaSchema, TitledMultiSelectEnumSchemaSchema]);
1188
+ /**
1189
+ * Primitive schema definition for enum fields.
1190
+ */
1191
+ export const EnumSchemaSchema = z.union([LegacyTitledEnumSchemaSchema, SingleSelectEnumSchemaSchema, MultiSelectEnumSchemaSchema]);
1107
1192
  /**
1108
1193
  * Union of all primitive schema definitions.
1109
1194
  */
1110
- export const PrimitiveSchemaDefinitionSchema = z.union([BooleanSchemaSchema, StringSchemaSchema, NumberSchemaSchema, EnumSchemaSchema]);
1195
+ export const PrimitiveSchemaDefinitionSchema = z.union([EnumSchemaSchema, BooleanSchemaSchema, StringSchemaSchema, NumberSchemaSchema]);
1196
+ /**
1197
+ * Parameters for an `elicitation/create` request.
1198
+ */
1199
+ export const ElicitRequestParamsSchema = BaseRequestParamsSchema.extend({
1200
+ /**
1201
+ * The message to present to the user.
1202
+ */
1203
+ message: z.string(),
1204
+ /**
1205
+ * A restricted subset of JSON Schema.
1206
+ * Only top-level properties are allowed, without nesting.
1207
+ */
1208
+ requestedSchema: z.object({
1209
+ type: z.literal('object'),
1210
+ properties: z.record(z.string(), PrimitiveSchemaDefinitionSchema),
1211
+ required: z.array(z.string()).optional()
1212
+ })
1213
+ });
1111
1214
  /**
1112
1215
  * A request from the server to elicit user input via the client.
1113
1216
  * The client should present the message and form fields to the user.
1114
1217
  */
1115
1218
  export const ElicitRequestSchema = RequestSchema.extend({
1116
1219
  method: z.literal('elicitation/create'),
1117
- params: BaseRequestParamsSchema.extend({
1118
- /**
1119
- * The message to present to the user.
1120
- */
1121
- message: z.string(),
1122
- /**
1123
- * The schema for the requested user input.
1124
- */
1125
- requestedSchema: z
1126
- .object({
1127
- type: z.literal('object'),
1128
- properties: z.record(z.string(), PrimitiveSchemaDefinitionSchema),
1129
- required: z.optional(z.array(z.string()))
1130
- })
1131
- .passthrough()
1132
- })
1220
+ params: ElicitRequestParamsSchema
1133
1221
  });
1134
1222
  /**
1135
1223
  * The client's response to an elicitation/create request from the server.
1136
1224
  */
1137
1225
  export const ElicitResultSchema = ResultSchema.extend({
1138
1226
  /**
1139
- * The user's response action.
1227
+ * The user action in response to the elicitation.
1228
+ * - "accept": User submitted the form/confirmed the action
1229
+ * - "decline": User explicitly decline the action
1230
+ * - "cancel": User dismissed without making an explicit choice
1140
1231
  */
1141
1232
  action: z.enum(['accept', 'decline', 'cancel']),
1142
1233
  /**
1143
- * The collected user input content (only present if action is "accept").
1234
+ * The submitted form data, only present when action is "accept".
1235
+ * Contains values matching the requested schema.
1144
1236
  */
1145
- content: z.optional(z.record(z.string(), z.unknown()))
1237
+ content: z.record(z.union([z.string(), z.number(), z.boolean(), z.array(z.string())])).optional()
1146
1238
  });
1147
1239
  /* Autocomplete */
1148
1240
  /**
1149
1241
  * A reference to a resource or resource template definition.
1150
1242
  */
1151
- export const ResourceTemplateReferenceSchema = z
1152
- .object({
1243
+ export const ResourceTemplateReferenceSchema = z.object({
1153
1244
  type: z.literal('ref/resource'),
1154
1245
  /**
1155
1246
  * The URI or URI template of the resource.
1156
1247
  */
1157
1248
  uri: z.string()
1158
- })
1159
- .passthrough();
1249
+ });
1160
1250
  /**
1161
1251
  * @deprecated Use ResourceTemplateReferenceSchema instead
1162
1252
  */
@@ -1164,45 +1254,57 @@ export const ResourceReferenceSchema = ResourceTemplateReferenceSchema;
1164
1254
  /**
1165
1255
  * Identifies a prompt.
1166
1256
  */
1167
- export const PromptReferenceSchema = z
1168
- .object({
1257
+ export const PromptReferenceSchema = z.object({
1169
1258
  type: z.literal('ref/prompt'),
1170
1259
  /**
1171
1260
  * The name of the prompt or prompt template
1172
1261
  */
1173
1262
  name: z.string()
1174
- })
1175
- .passthrough();
1263
+ });
1176
1264
  /**
1177
- * A request from the client to the server, to ask for completion options.
1265
+ * Parameters for a `completion/complete` request.
1178
1266
  */
1179
- export const CompleteRequestSchema = RequestSchema.extend({
1180
- method: z.literal('completion/complete'),
1181
- params: BaseRequestParamsSchema.extend({
1182
- ref: z.union([PromptReferenceSchema, ResourceTemplateReferenceSchema]),
1267
+ export const CompleteRequestParamsSchema = BaseRequestParamsSchema.extend({
1268
+ ref: z.union([PromptReferenceSchema, ResourceTemplateReferenceSchema]),
1269
+ /**
1270
+ * The argument's information
1271
+ */
1272
+ argument: z.object({
1183
1273
  /**
1184
- * The argument's information
1274
+ * The name of the argument
1185
1275
  */
1186
- argument: z
1187
- .object({
1188
- /**
1189
- * The name of the argument
1190
- */
1191
- name: z.string(),
1192
- /**
1193
- * The value of the argument to use for completion matching.
1194
- */
1195
- value: z.string()
1196
- })
1197
- .passthrough(),
1198
- context: z.optional(z.object({
1199
- /**
1200
- * Previously-resolved variables in a URI template or prompt.
1201
- */
1202
- arguments: z.optional(z.record(z.string(), z.string()))
1203
- }))
1276
+ name: z.string(),
1277
+ /**
1278
+ * The value of the argument to use for completion matching.
1279
+ */
1280
+ value: z.string()
1281
+ }),
1282
+ context: z
1283
+ .object({
1284
+ /**
1285
+ * Previously-resolved variables in a URI template or prompt.
1286
+ */
1287
+ arguments: z.record(z.string(), z.string()).optional()
1204
1288
  })
1289
+ .optional()
1290
+ });
1291
+ /**
1292
+ * A request from the client to the server, to ask for completion options.
1293
+ */
1294
+ export const CompleteRequestSchema = RequestSchema.extend({
1295
+ method: z.literal('completion/complete'),
1296
+ params: CompleteRequestParamsSchema
1205
1297
  });
1298
+ export function assertCompleteRequestPrompt(request) {
1299
+ if (request.params.ref.type !== 'ref/prompt') {
1300
+ throw new TypeError(`Expected CompleteRequestPrompt, but got ${request.params.ref.type}`);
1301
+ }
1302
+ }
1303
+ export function assertCompleteRequestResourceTemplate(request) {
1304
+ if (request.params.ref.type !== 'ref/resource') {
1305
+ throw new TypeError(`Expected CompleteRequestResourceTemplate, but got ${request.params.ref.type}`);
1306
+ }
1307
+ }
1206
1308
  /**
1207
1309
  * The server's response to a completion/complete request
1208
1310
  */
@@ -1228,8 +1330,7 @@ export const CompleteResultSchema = ResultSchema.extend({
1228
1330
  /**
1229
1331
  * Represents a root directory or file that the server can operate on.
1230
1332
  */
1231
- export const RootSchema = z
1232
- .object({
1333
+ export const RootSchema = z.object({
1233
1334
  /**
1234
1335
  * The URI identifying the root. This *must* start with file:// for now.
1235
1336
  */
@@ -1237,14 +1338,13 @@ export const RootSchema = z
1237
1338
  /**
1238
1339
  * An optional name for the root.
1239
1340
  */
1240
- name: z.optional(z.string()),
1341
+ name: z.string().optional(),
1241
1342
  /**
1242
1343
  * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
1243
1344
  * for notes on _meta usage.
1244
1345
  */
1245
- _meta: z.optional(z.object({}).passthrough())
1246
- })
1247
- .passthrough();
1346
+ _meta: z.record(z.string(), z.unknown()).optional()
1347
+ });
1248
1348
  /**
1249
1349
  * Sent from the server to request a list of root URIs from the client.
1250
1350
  */