zidane 5.1.2 → 5.1.7

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 (46) hide show
  1. package/dist/{agent-B0vrSTQ9.d.ts → agent-BEtOGMct.d.ts} +2 -2
  2. package/dist/{agent-B0vrSTQ9.d.ts.map → agent-BEtOGMct.d.ts.map} +1 -1
  3. package/dist/chat.d.ts +4 -4
  4. package/dist/chat.js +1 -1
  5. package/dist/contexts/docker.d.ts +1 -1
  6. package/dist/contexts.d.ts +2 -2
  7. package/dist/{index-DYcymRtr.d.ts → index-BiO_5Hm4.d.ts} +2 -2
  8. package/dist/{index-DYcymRtr.d.ts.map → index-BiO_5Hm4.d.ts.map} +1 -1
  9. package/dist/{index-CFxhms_B.d.ts → index-CYnIU6Pp.d.ts} +3 -3
  10. package/dist/{index-CFxhms_B.d.ts.map → index-CYnIU6Pp.d.ts.map} +1 -1
  11. package/dist/{index-X6Q9PN_A.d.ts → index-CsJOjP5T.d.ts} +3 -3
  12. package/dist/{index-X6Q9PN_A.d.ts.map → index-CsJOjP5T.d.ts.map} +1 -1
  13. package/dist/index.d.ts +5 -5
  14. package/dist/index.js +4 -4
  15. package/dist/{login-B7b7NNJQ.js → login-B3yZG4iI.js} +3 -3
  16. package/dist/{login-B7b7NNJQ.js.map → login-B3yZG4iI.js.map} +1 -1
  17. package/dist/{mcp-BgwK6ySj.js → mcp-8S8mSbr2.js} +29 -14
  18. package/dist/mcp-8S8mSbr2.js.map +1 -0
  19. package/dist/mcp.d.ts +1 -1
  20. package/dist/mcp.js +1 -1
  21. package/dist/{presets-CI8_fyvX.js → presets-B800CKGw.js} +2 -2
  22. package/dist/{presets-CI8_fyvX.js.map → presets-B800CKGw.js.map} +1 -1
  23. package/dist/presets.d.ts +2 -2
  24. package/dist/presets.js +1 -1
  25. package/dist/providers.d.ts +1 -1
  26. package/dist/session/sqlite.d.ts +1 -1
  27. package/dist/session.d.ts +1 -1
  28. package/dist/skills.d.ts +2 -2
  29. package/dist/stdio-loader-C48v4hPt.js +2120 -0
  30. package/dist/stdio-loader-C48v4hPt.js.map +1 -0
  31. package/dist/{tool-formatters-D7cN3T_W.d.ts → tool-formatters-Depi9Hwr.d.ts} +3 -3
  32. package/dist/{tool-formatters-D7cN3T_W.d.ts.map → tool-formatters-Depi9Hwr.d.ts.map} +1 -1
  33. package/dist/{tools-d1yeA6xK.js → tools-DngHXth6.js} +2 -2
  34. package/dist/{tools-d1yeA6xK.js.map → tools-DngHXth6.js.map} +1 -1
  35. package/dist/tools.d.ts +2 -2
  36. package/dist/tools.js +1 -1
  37. package/dist/tui.d.ts +2 -2
  38. package/dist/tui.js +5 -5
  39. package/dist/tui.js.map +1 -1
  40. package/dist/{turn-operations-2cgnXS2d.js → turn-operations-BF8_mSmx.js} +4 -4
  41. package/dist/{turn-operations-2cgnXS2d.js.map → turn-operations-BF8_mSmx.js.map} +1 -1
  42. package/dist/{types-OtrV6LJT.d.ts → types-Ce78ds4h.d.ts} +1 -1
  43. package/dist/{types-OtrV6LJT.d.ts.map → types-Ce78ds4h.d.ts.map} +1 -1
  44. package/dist/types.d.ts +4 -4
  45. package/package.json +1 -1
  46. package/dist/mcp-BgwK6ySj.js.map +0 -1
@@ -0,0 +1,2120 @@
1
+ import { spawn, spawnSync } from "node:child_process";
2
+ import process from "node:process";
3
+ import { PassThrough } from "node:stream";
4
+ import * as z from "zod/v4";
5
+ //#region build/cross-spawn-shim.mjs
6
+ /**
7
+ * Build-time replacement for the userland process-spawn helper that the
8
+ * MCP SDK's stdio transport depends on. Injected by tsdown via the
9
+ * rolldown alias plugin in `tsdown.config.ts`.
10
+ *
11
+ * Why this exists
12
+ *
13
+ * The upstream spawn helper is CJS and its first line dynamically resolves
14
+ * Node's process-spawn built-in via a bare specifier. When a downstream
15
+ * consumer re-bundles zidane as ESM (esbuild / Vite / tsup with
16
+ * `format: 'esm'` and Node built-ins not externalized), that bare
17
+ * resolution gets wrapped in esbuild's `__require` shim and throws at
18
+ * runtime — every stdio MCP server fails to launch.
19
+ *
20
+ * Aliasing the helper to this file at zidane's own build step replaces
21
+ * the offending bare resolution with explicit `node:`-prefixed imports.
22
+ * Downstream bundlers recognize the `node:` prefix as a Node built-in
23
+ * and externalize it automatically. The upstream MCP SDK is unmodified.
24
+ *
25
+ * Tradeoff
26
+ *
27
+ * The replaced helper does two extra things vs. raw spawn:
28
+ * 1. Windows `.cmd` / `.bat` / `.ps1` resolution via PATHEXT + cmd.exe
29
+ * shelling. Compensated below with `shell: true` on Win32, which
30
+ * routes through cmd.exe and handles the common `npx` / `pnpm` /
31
+ * `yarn` shims.
32
+ * 2. Synthesizes a clean ENOENT error event for missing commands.
33
+ * `node:child_process.spawn` already emits a perfectly usable
34
+ * `error` event with `code === 'ENOENT'`, which the MCP SDK's stdio
35
+ * transport forwards to `onerror`. Functionally equivalent.
36
+ *
37
+ * Net: zero behavioural change on POSIX, near-identical on Windows for
38
+ * MCP-style stdio invocations.
39
+ */
40
+ const IS_WIN32 = process.platform === "win32";
41
+ function withWin32Shell(options) {
42
+ if (!IS_WIN32) return options;
43
+ if (options && options.shell !== void 0) return options;
44
+ return {
45
+ ...options ?? {},
46
+ shell: true
47
+ };
48
+ }
49
+ function spawn$1(command, args, options) {
50
+ return spawn(command, args, withWin32Shell(options));
51
+ }
52
+ function spawnSync$1(command, args, options) {
53
+ return spawnSync(command, args, withWin32Shell(options));
54
+ }
55
+ spawn$1.spawn = spawn$1;
56
+ spawn$1.sync = spawnSync$1;
57
+ //#endregion
58
+ //#region node_modules/@modelcontextprotocol/sdk/dist/esm/types.js
59
+ const RELATED_TASK_META_KEY = "io.modelcontextprotocol/related-task";
60
+ /**
61
+ * Assert 'object' type schema.
62
+ *
63
+ * @internal
64
+ */
65
+ const AssertObjectSchema = z.custom((v) => v !== null && (typeof v === "object" || typeof v === "function"));
66
+ /**
67
+ * A progress token, used to associate progress notifications with the original request.
68
+ */
69
+ const ProgressTokenSchema = z.union([z.string(), z.number().int()]);
70
+ /**
71
+ * An opaque token used to represent a cursor for pagination.
72
+ */
73
+ const CursorSchema = z.string();
74
+ z.looseObject({
75
+ /**
76
+ * Requested duration in milliseconds to retain task from creation.
77
+ */
78
+ ttl: z.number().optional(),
79
+ /**
80
+ * Time in milliseconds to wait between task status requests.
81
+ */
82
+ pollInterval: z.number().optional()
83
+ });
84
+ const TaskMetadataSchema = z.object({ ttl: z.number().optional() });
85
+ /**
86
+ * Metadata for associating messages with a task.
87
+ * Include this in the `_meta` field under the key `io.modelcontextprotocol/related-task`.
88
+ */
89
+ const RelatedTaskMetadataSchema = z.object({ taskId: z.string() });
90
+ const RequestMetaSchema = z.looseObject({
91
+ /**
92
+ * 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.
93
+ */
94
+ progressToken: ProgressTokenSchema.optional(),
95
+ /**
96
+ * If specified, this request is related to the provided task.
97
+ */
98
+ [RELATED_TASK_META_KEY]: RelatedTaskMetadataSchema.optional()
99
+ });
100
+ /**
101
+ * Common params for any request.
102
+ */
103
+ const BaseRequestParamsSchema = z.object({
104
+ /**
105
+ * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage.
106
+ */
107
+ _meta: RequestMetaSchema.optional() });
108
+ /**
109
+ * Common params for any task-augmented request.
110
+ */
111
+ const TaskAugmentedRequestParamsSchema = BaseRequestParamsSchema.extend({
112
+ /**
113
+ * If specified, the caller is requesting task-augmented execution for this request.
114
+ * The request will return a CreateTaskResult immediately, and the actual result can be
115
+ * retrieved later via tasks/result.
116
+ *
117
+ * Task augmentation is subject to capability negotiation - receivers MUST declare support
118
+ * for task augmentation of specific request types in their capabilities.
119
+ */
120
+ task: TaskMetadataSchema.optional() });
121
+ const RequestSchema = z.object({
122
+ method: z.string(),
123
+ params: BaseRequestParamsSchema.loose().optional()
124
+ });
125
+ const NotificationsParamsSchema = z.object({
126
+ /**
127
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
128
+ * for notes on _meta usage.
129
+ */
130
+ _meta: RequestMetaSchema.optional() });
131
+ const NotificationSchema = z.object({
132
+ method: z.string(),
133
+ params: NotificationsParamsSchema.loose().optional()
134
+ });
135
+ const ResultSchema = z.looseObject({
136
+ /**
137
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
138
+ * for notes on _meta usage.
139
+ */
140
+ _meta: RequestMetaSchema.optional() });
141
+ /**
142
+ * A uniquely identifying ID for a request in JSON-RPC.
143
+ */
144
+ const RequestIdSchema = z.union([z.string(), z.number().int()]);
145
+ /**
146
+ * A request that expects a response.
147
+ */
148
+ const JSONRPCRequestSchema = z.object({
149
+ jsonrpc: z.literal("2.0"),
150
+ id: RequestIdSchema,
151
+ ...RequestSchema.shape
152
+ }).strict();
153
+ /**
154
+ * A notification which does not expect a response.
155
+ */
156
+ const JSONRPCNotificationSchema = z.object({
157
+ jsonrpc: z.literal("2.0"),
158
+ ...NotificationSchema.shape
159
+ }).strict();
160
+ /**
161
+ * A successful (non-error) response to a request.
162
+ */
163
+ const JSONRPCResultResponseSchema = z.object({
164
+ jsonrpc: z.literal("2.0"),
165
+ id: RequestIdSchema,
166
+ result: ResultSchema
167
+ }).strict();
168
+ /**
169
+ * Error codes defined by the JSON-RPC specification.
170
+ */
171
+ var ErrorCode;
172
+ (function(ErrorCode) {
173
+ ErrorCode[ErrorCode["ConnectionClosed"] = -32e3] = "ConnectionClosed";
174
+ ErrorCode[ErrorCode["RequestTimeout"] = -32001] = "RequestTimeout";
175
+ ErrorCode[ErrorCode["ParseError"] = -32700] = "ParseError";
176
+ ErrorCode[ErrorCode["InvalidRequest"] = -32600] = "InvalidRequest";
177
+ ErrorCode[ErrorCode["MethodNotFound"] = -32601] = "MethodNotFound";
178
+ ErrorCode[ErrorCode["InvalidParams"] = -32602] = "InvalidParams";
179
+ ErrorCode[ErrorCode["InternalError"] = -32603] = "InternalError";
180
+ ErrorCode[ErrorCode["UrlElicitationRequired"] = -32042] = "UrlElicitationRequired";
181
+ })(ErrorCode || (ErrorCode = {}));
182
+ /**
183
+ * A response to a request that indicates an error occurred.
184
+ */
185
+ const JSONRPCErrorResponseSchema = z.object({
186
+ jsonrpc: z.literal("2.0"),
187
+ id: RequestIdSchema.optional(),
188
+ error: z.object({
189
+ /**
190
+ * The error type that occurred.
191
+ */
192
+ code: z.number().int(),
193
+ /**
194
+ * A short description of the error. The message SHOULD be limited to a concise single sentence.
195
+ */
196
+ message: z.string(),
197
+ /**
198
+ * Additional information about the error. The value of this member is defined by the sender (e.g. detailed error information, nested errors etc.).
199
+ */
200
+ data: z.unknown().optional()
201
+ })
202
+ }).strict();
203
+ const JSONRPCMessageSchema = z.union([
204
+ JSONRPCRequestSchema,
205
+ JSONRPCNotificationSchema,
206
+ JSONRPCResultResponseSchema,
207
+ JSONRPCErrorResponseSchema
208
+ ]);
209
+ z.union([JSONRPCResultResponseSchema, JSONRPCErrorResponseSchema]);
210
+ /**
211
+ * A response that indicates success but carries no data.
212
+ */
213
+ const EmptyResultSchema = ResultSchema.strict();
214
+ const CancelledNotificationParamsSchema = NotificationsParamsSchema.extend({
215
+ /**
216
+ * The ID of the request to cancel.
217
+ *
218
+ * This MUST correspond to the ID of a request previously issued in the same direction.
219
+ */
220
+ requestId: RequestIdSchema.optional(),
221
+ /**
222
+ * An optional string describing the reason for the cancellation. This MAY be logged or presented to the user.
223
+ */
224
+ reason: z.string().optional()
225
+ });
226
+ /**
227
+ * This notification can be sent by either side to indicate that it is cancelling a previously-issued request.
228
+ *
229
+ * 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.
230
+ *
231
+ * This notification indicates that the result will be unused, so any associated processing SHOULD cease.
232
+ *
233
+ * A client MUST NOT attempt to cancel its `initialize` request.
234
+ */
235
+ const CancelledNotificationSchema = NotificationSchema.extend({
236
+ method: z.literal("notifications/cancelled"),
237
+ params: CancelledNotificationParamsSchema
238
+ });
239
+ /**
240
+ * Icon schema for use in tools, prompts, resources, and implementations.
241
+ */
242
+ const IconSchema = z.object({
243
+ /**
244
+ * URL or data URI for the icon.
245
+ */
246
+ src: z.string(),
247
+ /**
248
+ * Optional MIME type for the icon.
249
+ */
250
+ mimeType: z.string().optional(),
251
+ /**
252
+ * Optional array of strings that specify sizes at which the icon can be used.
253
+ * Each string should be in WxH format (e.g., `"48x48"`, `"96x96"`) or `"any"` for scalable formats like SVG.
254
+ *
255
+ * If not provided, the client should assume that the icon can be used at any size.
256
+ */
257
+ sizes: z.array(z.string()).optional(),
258
+ /**
259
+ * Optional specifier for the theme this icon is designed for. `light` indicates
260
+ * the icon is designed to be used with a light background, and `dark` indicates
261
+ * the icon is designed to be used with a dark background.
262
+ *
263
+ * If not provided, the client should assume the icon can be used with any theme.
264
+ */
265
+ theme: z.enum(["light", "dark"]).optional()
266
+ });
267
+ /**
268
+ * Base schema to add `icons` property.
269
+ *
270
+ */
271
+ const IconsSchema = z.object({
272
+ /**
273
+ * Optional set of sized icons that the client can display in a user interface.
274
+ *
275
+ * Clients that support rendering icons MUST support at least the following MIME types:
276
+ * - `image/png` - PNG images (safe, universal compatibility)
277
+ * - `image/jpeg` (and `image/jpg`) - JPEG images (safe, universal compatibility)
278
+ *
279
+ * Clients that support rendering icons SHOULD also support:
280
+ * - `image/svg+xml` - SVG images (scalable but requires security precautions)
281
+ * - `image/webp` - WebP images (modern, efficient format)
282
+ */
283
+ icons: z.array(IconSchema).optional() });
284
+ /**
285
+ * Base metadata interface for common properties across resources, tools, prompts, and implementations.
286
+ */
287
+ const BaseMetadataSchema = z.object({
288
+ /** Intended for programmatic or logical use, but used as a display name in past specs or fallback */
289
+ name: z.string(),
290
+ /**
291
+ * Intended for UI and end-user contexts — optimized to be human-readable and easily understood,
292
+ * even by those unfamiliar with domain-specific terminology.
293
+ *
294
+ * If not provided, the name should be used for display (except for Tool,
295
+ * where `annotations.title` should be given precedence over using `name`,
296
+ * if present).
297
+ */
298
+ title: z.string().optional()
299
+ });
300
+ /**
301
+ * Describes the name and version of an MCP implementation.
302
+ */
303
+ const ImplementationSchema = BaseMetadataSchema.extend({
304
+ ...BaseMetadataSchema.shape,
305
+ ...IconsSchema.shape,
306
+ version: z.string(),
307
+ /**
308
+ * An optional URL of the website for this implementation.
309
+ */
310
+ websiteUrl: z.string().optional(),
311
+ /**
312
+ * An optional human-readable description of what this implementation does.
313
+ *
314
+ * This can be used by clients or servers to provide context about their purpose
315
+ * and capabilities. For example, a server might describe the types of resources
316
+ * or tools it provides, while a client might describe its intended use case.
317
+ */
318
+ description: z.string().optional()
319
+ });
320
+ const FormElicitationCapabilitySchema = z.intersection(z.object({ applyDefaults: z.boolean().optional() }), z.record(z.string(), z.unknown()));
321
+ const ElicitationCapabilitySchema = z.preprocess((value) => {
322
+ if (value && typeof value === "object" && !Array.isArray(value)) {
323
+ if (Object.keys(value).length === 0) return { form: {} };
324
+ }
325
+ return value;
326
+ }, z.intersection(z.object({
327
+ form: FormElicitationCapabilitySchema.optional(),
328
+ url: AssertObjectSchema.optional()
329
+ }), z.record(z.string(), z.unknown()).optional()));
330
+ /**
331
+ * Task capabilities for clients, indicating which request types support task creation.
332
+ */
333
+ const ClientTasksCapabilitySchema = z.looseObject({
334
+ /**
335
+ * Present if the client supports listing tasks.
336
+ */
337
+ list: AssertObjectSchema.optional(),
338
+ /**
339
+ * Present if the client supports cancelling tasks.
340
+ */
341
+ cancel: AssertObjectSchema.optional(),
342
+ /**
343
+ * Capabilities for task creation on specific request types.
344
+ */
345
+ requests: z.looseObject({
346
+ /**
347
+ * Task support for sampling requests.
348
+ */
349
+ sampling: z.looseObject({ createMessage: AssertObjectSchema.optional() }).optional(),
350
+ /**
351
+ * Task support for elicitation requests.
352
+ */
353
+ elicitation: z.looseObject({ create: AssertObjectSchema.optional() }).optional()
354
+ }).optional()
355
+ });
356
+ /**
357
+ * Task capabilities for servers, indicating which request types support task creation.
358
+ */
359
+ const ServerTasksCapabilitySchema = z.looseObject({
360
+ /**
361
+ * Present if the server supports listing tasks.
362
+ */
363
+ list: AssertObjectSchema.optional(),
364
+ /**
365
+ * Present if the server supports cancelling tasks.
366
+ */
367
+ cancel: AssertObjectSchema.optional(),
368
+ /**
369
+ * Capabilities for task creation on specific request types.
370
+ */
371
+ requests: z.looseObject({
372
+ /**
373
+ * Task support for tool requests.
374
+ */
375
+ tools: z.looseObject({ call: AssertObjectSchema.optional() }).optional() }).optional()
376
+ });
377
+ /**
378
+ * 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.
379
+ */
380
+ const ClientCapabilitiesSchema = z.object({
381
+ /**
382
+ * Experimental, non-standard capabilities that the client supports.
383
+ */
384
+ experimental: z.record(z.string(), AssertObjectSchema).optional(),
385
+ /**
386
+ * Present if the client supports sampling from an LLM.
387
+ */
388
+ sampling: z.object({
389
+ /**
390
+ * Present if the client supports context inclusion via includeContext parameter.
391
+ * If not declared, servers SHOULD only use `includeContext: "none"` (or omit it).
392
+ */
393
+ context: AssertObjectSchema.optional(),
394
+ /**
395
+ * Present if the client supports tool use via tools and toolChoice parameters.
396
+ */
397
+ tools: AssertObjectSchema.optional()
398
+ }).optional(),
399
+ /**
400
+ * Present if the client supports eliciting user input.
401
+ */
402
+ elicitation: ElicitationCapabilitySchema.optional(),
403
+ /**
404
+ * Present if the client supports listing roots.
405
+ */
406
+ roots: z.object({
407
+ /**
408
+ * Whether the client supports issuing notifications for changes to the roots list.
409
+ */
410
+ listChanged: z.boolean().optional() }).optional(),
411
+ /**
412
+ * Present if the client supports task creation.
413
+ */
414
+ tasks: ClientTasksCapabilitySchema.optional(),
415
+ /**
416
+ * Extensions that the client supports. Keys are extension identifiers (vendor-prefix/extension-name).
417
+ */
418
+ extensions: z.record(z.string(), AssertObjectSchema).optional()
419
+ });
420
+ const InitializeRequestParamsSchema = BaseRequestParamsSchema.extend({
421
+ /**
422
+ * The latest version of the Model Context Protocol that the client supports. The client MAY decide to support older versions as well.
423
+ */
424
+ protocolVersion: z.string(),
425
+ capabilities: ClientCapabilitiesSchema,
426
+ clientInfo: ImplementationSchema
427
+ });
428
+ /**
429
+ * This request is sent from the client to the server when it first connects, asking it to begin initialization.
430
+ */
431
+ const InitializeRequestSchema = RequestSchema.extend({
432
+ method: z.literal("initialize"),
433
+ params: InitializeRequestParamsSchema
434
+ });
435
+ /**
436
+ * 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.
437
+ */
438
+ const ServerCapabilitiesSchema = z.object({
439
+ /**
440
+ * Experimental, non-standard capabilities that the server supports.
441
+ */
442
+ experimental: z.record(z.string(), AssertObjectSchema).optional(),
443
+ /**
444
+ * Present if the server supports sending log messages to the client.
445
+ */
446
+ logging: AssertObjectSchema.optional(),
447
+ /**
448
+ * Present if the server supports sending completions to the client.
449
+ */
450
+ completions: AssertObjectSchema.optional(),
451
+ /**
452
+ * Present if the server offers any prompt templates.
453
+ */
454
+ prompts: z.object({
455
+ /**
456
+ * Whether this server supports issuing notifications for changes to the prompt list.
457
+ */
458
+ listChanged: z.boolean().optional() }).optional(),
459
+ /**
460
+ * Present if the server offers any resources to read.
461
+ */
462
+ resources: z.object({
463
+ /**
464
+ * Whether this server supports clients subscribing to resource updates.
465
+ */
466
+ subscribe: z.boolean().optional(),
467
+ /**
468
+ * Whether this server supports issuing notifications for changes to the resource list.
469
+ */
470
+ listChanged: z.boolean().optional()
471
+ }).optional(),
472
+ /**
473
+ * Present if the server offers any tools to call.
474
+ */
475
+ tools: z.object({
476
+ /**
477
+ * Whether this server supports issuing notifications for changes to the tool list.
478
+ */
479
+ listChanged: z.boolean().optional() }).optional(),
480
+ /**
481
+ * Present if the server supports task creation.
482
+ */
483
+ tasks: ServerTasksCapabilitySchema.optional(),
484
+ /**
485
+ * Extensions that the server supports. Keys are extension identifiers (vendor-prefix/extension-name).
486
+ */
487
+ extensions: z.record(z.string(), AssertObjectSchema).optional()
488
+ });
489
+ /**
490
+ * After receiving an initialize request from the client, the server sends this response.
491
+ */
492
+ const InitializeResultSchema = ResultSchema.extend({
493
+ /**
494
+ * 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.
495
+ */
496
+ protocolVersion: z.string(),
497
+ capabilities: ServerCapabilitiesSchema,
498
+ serverInfo: ImplementationSchema,
499
+ /**
500
+ * Instructions describing how to use the server and its features.
501
+ *
502
+ * 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.
503
+ */
504
+ instructions: z.string().optional()
505
+ });
506
+ /**
507
+ * This notification is sent from the client to the server after initialization has finished.
508
+ */
509
+ const InitializedNotificationSchema = NotificationSchema.extend({
510
+ method: z.literal("notifications/initialized"),
511
+ params: NotificationsParamsSchema.optional()
512
+ });
513
+ /**
514
+ * 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.
515
+ */
516
+ const PingRequestSchema = RequestSchema.extend({
517
+ method: z.literal("ping"),
518
+ params: BaseRequestParamsSchema.optional()
519
+ });
520
+ const ProgressSchema = z.object({
521
+ /**
522
+ * The progress thus far. This should increase every time progress is made, even if the total is unknown.
523
+ */
524
+ progress: z.number(),
525
+ /**
526
+ * Total number of items to process (or total progress required), if known.
527
+ */
528
+ total: z.optional(z.number()),
529
+ /**
530
+ * An optional message describing the current progress.
531
+ */
532
+ message: z.optional(z.string())
533
+ });
534
+ const ProgressNotificationParamsSchema = z.object({
535
+ ...NotificationsParamsSchema.shape,
536
+ ...ProgressSchema.shape,
537
+ /**
538
+ * The progress token which was given in the initial request, used to associate this notification with the request that is proceeding.
539
+ */
540
+ progressToken: ProgressTokenSchema
541
+ });
542
+ /**
543
+ * An out-of-band notification used to inform the receiver of a progress update for a long-running request.
544
+ *
545
+ * @category notifications/progress
546
+ */
547
+ const ProgressNotificationSchema = NotificationSchema.extend({
548
+ method: z.literal("notifications/progress"),
549
+ params: ProgressNotificationParamsSchema
550
+ });
551
+ const PaginatedRequestParamsSchema = BaseRequestParamsSchema.extend({
552
+ /**
553
+ * An opaque token representing the current pagination position.
554
+ * If provided, the server should return results starting after this cursor.
555
+ */
556
+ cursor: CursorSchema.optional() });
557
+ const PaginatedRequestSchema = RequestSchema.extend({ params: PaginatedRequestParamsSchema.optional() });
558
+ const PaginatedResultSchema = ResultSchema.extend({
559
+ /**
560
+ * An opaque token representing the pagination position after the last returned result.
561
+ * If present, there may be more results available.
562
+ */
563
+ nextCursor: CursorSchema.optional() });
564
+ /**
565
+ * The status of a task.
566
+ * */
567
+ const TaskStatusSchema = z.enum([
568
+ "working",
569
+ "input_required",
570
+ "completed",
571
+ "failed",
572
+ "cancelled"
573
+ ]);
574
+ /**
575
+ * A pollable state object associated with a request.
576
+ */
577
+ const TaskSchema = z.object({
578
+ taskId: z.string(),
579
+ status: TaskStatusSchema,
580
+ /**
581
+ * Time in milliseconds to keep task results available after completion.
582
+ * If null, the task has unlimited lifetime until manually cleaned up.
583
+ */
584
+ ttl: z.union([z.number(), z.null()]),
585
+ /**
586
+ * ISO 8601 timestamp when the task was created.
587
+ */
588
+ createdAt: z.string(),
589
+ /**
590
+ * ISO 8601 timestamp when the task was last updated.
591
+ */
592
+ lastUpdatedAt: z.string(),
593
+ pollInterval: z.optional(z.number()),
594
+ /**
595
+ * Optional diagnostic message for failed tasks or other status information.
596
+ */
597
+ statusMessage: z.optional(z.string())
598
+ });
599
+ /**
600
+ * Result returned when a task is created, containing the task data wrapped in a task field.
601
+ */
602
+ const CreateTaskResultSchema = ResultSchema.extend({ task: TaskSchema });
603
+ /**
604
+ * Parameters for task status notification.
605
+ */
606
+ const TaskStatusNotificationParamsSchema = NotificationsParamsSchema.merge(TaskSchema);
607
+ /**
608
+ * A notification sent when a task's status changes.
609
+ */
610
+ const TaskStatusNotificationSchema = NotificationSchema.extend({
611
+ method: z.literal("notifications/tasks/status"),
612
+ params: TaskStatusNotificationParamsSchema
613
+ });
614
+ /**
615
+ * A request to get the state of a specific task.
616
+ */
617
+ const GetTaskRequestSchema = RequestSchema.extend({
618
+ method: z.literal("tasks/get"),
619
+ params: BaseRequestParamsSchema.extend({ taskId: z.string() })
620
+ });
621
+ /**
622
+ * The response to a tasks/get request.
623
+ */
624
+ const GetTaskResultSchema = ResultSchema.merge(TaskSchema);
625
+ /**
626
+ * A request to get the result of a specific task.
627
+ */
628
+ const GetTaskPayloadRequestSchema = RequestSchema.extend({
629
+ method: z.literal("tasks/result"),
630
+ params: BaseRequestParamsSchema.extend({ taskId: z.string() })
631
+ });
632
+ ResultSchema.loose();
633
+ /**
634
+ * A request to list tasks.
635
+ */
636
+ const ListTasksRequestSchema = PaginatedRequestSchema.extend({ method: z.literal("tasks/list") });
637
+ /**
638
+ * The response to a tasks/list request.
639
+ */
640
+ const ListTasksResultSchema = PaginatedResultSchema.extend({ tasks: z.array(TaskSchema) });
641
+ /**
642
+ * A request to cancel a specific task.
643
+ */
644
+ const CancelTaskRequestSchema = RequestSchema.extend({
645
+ method: z.literal("tasks/cancel"),
646
+ params: BaseRequestParamsSchema.extend({ taskId: z.string() })
647
+ });
648
+ ResultSchema.merge(TaskSchema);
649
+ /**
650
+ * The contents of a specific resource or sub-resource.
651
+ */
652
+ const ResourceContentsSchema = z.object({
653
+ /**
654
+ * The URI of this resource.
655
+ */
656
+ uri: z.string(),
657
+ /**
658
+ * The MIME type of this resource, if known.
659
+ */
660
+ mimeType: z.optional(z.string()),
661
+ /**
662
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
663
+ * for notes on _meta usage.
664
+ */
665
+ _meta: z.record(z.string(), z.unknown()).optional()
666
+ });
667
+ const TextResourceContentsSchema = ResourceContentsSchema.extend({
668
+ /**
669
+ * The text of the item. This must only be set if the item can actually be represented as text (not binary data).
670
+ */
671
+ text: z.string() });
672
+ /**
673
+ * A Zod schema for validating Base64 strings that is more performant and
674
+ * robust for very large inputs than the default regex-based check. It avoids
675
+ * stack overflows by using the native `atob` function for validation.
676
+ */
677
+ const Base64Schema = z.string().refine((val) => {
678
+ try {
679
+ atob(val);
680
+ return true;
681
+ } catch {
682
+ return false;
683
+ }
684
+ }, { message: "Invalid Base64 string" });
685
+ const BlobResourceContentsSchema = ResourceContentsSchema.extend({
686
+ /**
687
+ * A base64-encoded string representing the binary data of the item.
688
+ */
689
+ blob: Base64Schema });
690
+ /**
691
+ * The sender or recipient of messages and data in a conversation.
692
+ */
693
+ const RoleSchema = z.enum(["user", "assistant"]);
694
+ /**
695
+ * Optional annotations providing clients additional context about a resource.
696
+ */
697
+ const AnnotationsSchema = z.object({
698
+ /**
699
+ * Intended audience(s) for the resource.
700
+ */
701
+ audience: z.array(RoleSchema).optional(),
702
+ /**
703
+ * Importance hint for the resource, from 0 (least) to 1 (most).
704
+ */
705
+ priority: z.number().min(0).max(1).optional(),
706
+ /**
707
+ * ISO 8601 timestamp for the most recent modification.
708
+ */
709
+ lastModified: z.iso.datetime({ offset: true }).optional()
710
+ });
711
+ /**
712
+ * A known resource that the server is capable of reading.
713
+ */
714
+ const ResourceSchema = z.object({
715
+ ...BaseMetadataSchema.shape,
716
+ ...IconsSchema.shape,
717
+ /**
718
+ * The URI of this resource.
719
+ */
720
+ uri: z.string(),
721
+ /**
722
+ * A description of what this resource represents.
723
+ *
724
+ * 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.
725
+ */
726
+ description: z.optional(z.string()),
727
+ /**
728
+ * The MIME type of this resource, if known.
729
+ */
730
+ mimeType: z.optional(z.string()),
731
+ /**
732
+ * The size of the raw resource content, in bytes (i.e., before base64 encoding or any tokenization), if known.
733
+ *
734
+ * This can be used by Hosts to display file sizes and estimate context window usage.
735
+ */
736
+ size: z.optional(z.number()),
737
+ /**
738
+ * Optional annotations for the client.
739
+ */
740
+ annotations: AnnotationsSchema.optional(),
741
+ /**
742
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
743
+ * for notes on _meta usage.
744
+ */
745
+ _meta: z.optional(z.looseObject({}))
746
+ });
747
+ /**
748
+ * A template description for resources available on the server.
749
+ */
750
+ const ResourceTemplateSchema = z.object({
751
+ ...BaseMetadataSchema.shape,
752
+ ...IconsSchema.shape,
753
+ /**
754
+ * A URI template (according to RFC 6570) that can be used to construct resource URIs.
755
+ */
756
+ uriTemplate: z.string(),
757
+ /**
758
+ * A description of what this template is for.
759
+ *
760
+ * 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.
761
+ */
762
+ description: z.optional(z.string()),
763
+ /**
764
+ * 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.
765
+ */
766
+ mimeType: z.optional(z.string()),
767
+ /**
768
+ * Optional annotations for the client.
769
+ */
770
+ annotations: AnnotationsSchema.optional(),
771
+ /**
772
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
773
+ * for notes on _meta usage.
774
+ */
775
+ _meta: z.optional(z.looseObject({}))
776
+ });
777
+ /**
778
+ * Sent from the client to request a list of resources the server has.
779
+ */
780
+ const ListResourcesRequestSchema = PaginatedRequestSchema.extend({ method: z.literal("resources/list") });
781
+ /**
782
+ * The server's response to a resources/list request from the client.
783
+ */
784
+ const ListResourcesResultSchema = PaginatedResultSchema.extend({ resources: z.array(ResourceSchema) });
785
+ /**
786
+ * Sent from the client to request a list of resource templates the server has.
787
+ */
788
+ const ListResourceTemplatesRequestSchema = PaginatedRequestSchema.extend({ method: z.literal("resources/templates/list") });
789
+ /**
790
+ * The server's response to a resources/templates/list request from the client.
791
+ */
792
+ const ListResourceTemplatesResultSchema = PaginatedResultSchema.extend({ resourceTemplates: z.array(ResourceTemplateSchema) });
793
+ const ResourceRequestParamsSchema = BaseRequestParamsSchema.extend({
794
+ /**
795
+ * The URI of the resource to read. The URI can use any protocol; it is up to the server how to interpret it.
796
+ *
797
+ * @format uri
798
+ */
799
+ uri: z.string() });
800
+ /**
801
+ * Parameters for a `resources/read` request.
802
+ */
803
+ const ReadResourceRequestParamsSchema = ResourceRequestParamsSchema;
804
+ /**
805
+ * Sent from the client to the server, to read a specific resource URI.
806
+ */
807
+ const ReadResourceRequestSchema = RequestSchema.extend({
808
+ method: z.literal("resources/read"),
809
+ params: ReadResourceRequestParamsSchema
810
+ });
811
+ /**
812
+ * The server's response to a resources/read request from the client.
813
+ */
814
+ const ReadResourceResultSchema = ResultSchema.extend({ contents: z.array(z.union([TextResourceContentsSchema, BlobResourceContentsSchema])) });
815
+ /**
816
+ * 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.
817
+ */
818
+ const ResourceListChangedNotificationSchema = NotificationSchema.extend({
819
+ method: z.literal("notifications/resources/list_changed"),
820
+ params: NotificationsParamsSchema.optional()
821
+ });
822
+ const SubscribeRequestParamsSchema = ResourceRequestParamsSchema;
823
+ /**
824
+ * Sent from the client to request resources/updated notifications from the server whenever a particular resource changes.
825
+ */
826
+ const SubscribeRequestSchema = RequestSchema.extend({
827
+ method: z.literal("resources/subscribe"),
828
+ params: SubscribeRequestParamsSchema
829
+ });
830
+ const UnsubscribeRequestParamsSchema = ResourceRequestParamsSchema;
831
+ /**
832
+ * Sent from the client to request cancellation of resources/updated notifications from the server. This should follow a previous resources/subscribe request.
833
+ */
834
+ const UnsubscribeRequestSchema = RequestSchema.extend({
835
+ method: z.literal("resources/unsubscribe"),
836
+ params: UnsubscribeRequestParamsSchema
837
+ });
838
+ /**
839
+ * Parameters for a `notifications/resources/updated` notification.
840
+ */
841
+ const ResourceUpdatedNotificationParamsSchema = NotificationsParamsSchema.extend({
842
+ /**
843
+ * The URI of the resource that has been updated. This might be a sub-resource of the one that the client actually subscribed to.
844
+ */
845
+ uri: z.string() });
846
+ /**
847
+ * 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.
848
+ */
849
+ const ResourceUpdatedNotificationSchema = NotificationSchema.extend({
850
+ method: z.literal("notifications/resources/updated"),
851
+ params: ResourceUpdatedNotificationParamsSchema
852
+ });
853
+ /**
854
+ * Describes an argument that a prompt can accept.
855
+ */
856
+ const PromptArgumentSchema = z.object({
857
+ /**
858
+ * The name of the argument.
859
+ */
860
+ name: z.string(),
861
+ /**
862
+ * A human-readable description of the argument.
863
+ */
864
+ description: z.optional(z.string()),
865
+ /**
866
+ * Whether this argument must be provided.
867
+ */
868
+ required: z.optional(z.boolean())
869
+ });
870
+ /**
871
+ * A prompt or prompt template that the server offers.
872
+ */
873
+ const PromptSchema = z.object({
874
+ ...BaseMetadataSchema.shape,
875
+ ...IconsSchema.shape,
876
+ /**
877
+ * An optional description of what this prompt provides
878
+ */
879
+ description: z.optional(z.string()),
880
+ /**
881
+ * A list of arguments to use for templating the prompt.
882
+ */
883
+ arguments: z.optional(z.array(PromptArgumentSchema)),
884
+ /**
885
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
886
+ * for notes on _meta usage.
887
+ */
888
+ _meta: z.optional(z.looseObject({}))
889
+ });
890
+ /**
891
+ * Sent from the client to request a list of prompts and prompt templates the server has.
892
+ */
893
+ const ListPromptsRequestSchema = PaginatedRequestSchema.extend({ method: z.literal("prompts/list") });
894
+ /**
895
+ * The server's response to a prompts/list request from the client.
896
+ */
897
+ const ListPromptsResultSchema = PaginatedResultSchema.extend({ prompts: z.array(PromptSchema) });
898
+ /**
899
+ * Parameters for a `prompts/get` request.
900
+ */
901
+ const GetPromptRequestParamsSchema = BaseRequestParamsSchema.extend({
902
+ /**
903
+ * The name of the prompt or prompt template.
904
+ */
905
+ name: z.string(),
906
+ /**
907
+ * Arguments to use for templating the prompt.
908
+ */
909
+ arguments: z.record(z.string(), z.string()).optional()
910
+ });
911
+ /**
912
+ * Used by the client to get a prompt provided by the server.
913
+ */
914
+ const GetPromptRequestSchema = RequestSchema.extend({
915
+ method: z.literal("prompts/get"),
916
+ params: GetPromptRequestParamsSchema
917
+ });
918
+ /**
919
+ * Text provided to or from an LLM.
920
+ */
921
+ const TextContentSchema = z.object({
922
+ type: z.literal("text"),
923
+ /**
924
+ * The text content of the message.
925
+ */
926
+ text: z.string(),
927
+ /**
928
+ * Optional annotations for the client.
929
+ */
930
+ annotations: AnnotationsSchema.optional(),
931
+ /**
932
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
933
+ * for notes on _meta usage.
934
+ */
935
+ _meta: z.record(z.string(), z.unknown()).optional()
936
+ });
937
+ /**
938
+ * An image provided to or from an LLM.
939
+ */
940
+ const ImageContentSchema = z.object({
941
+ type: z.literal("image"),
942
+ /**
943
+ * The base64-encoded image data.
944
+ */
945
+ data: Base64Schema,
946
+ /**
947
+ * The MIME type of the image. Different providers may support different image types.
948
+ */
949
+ mimeType: z.string(),
950
+ /**
951
+ * Optional annotations for the client.
952
+ */
953
+ annotations: AnnotationsSchema.optional(),
954
+ /**
955
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
956
+ * for notes on _meta usage.
957
+ */
958
+ _meta: z.record(z.string(), z.unknown()).optional()
959
+ });
960
+ /**
961
+ * An Audio provided to or from an LLM.
962
+ */
963
+ const AudioContentSchema = z.object({
964
+ type: z.literal("audio"),
965
+ /**
966
+ * The base64-encoded audio data.
967
+ */
968
+ data: Base64Schema,
969
+ /**
970
+ * The MIME type of the audio. Different providers may support different audio types.
971
+ */
972
+ mimeType: z.string(),
973
+ /**
974
+ * Optional annotations for the client.
975
+ */
976
+ annotations: AnnotationsSchema.optional(),
977
+ /**
978
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
979
+ * for notes on _meta usage.
980
+ */
981
+ _meta: z.record(z.string(), z.unknown()).optional()
982
+ });
983
+ /**
984
+ * A tool call request from an assistant (LLM).
985
+ * Represents the assistant's request to use a tool.
986
+ */
987
+ const ToolUseContentSchema = z.object({
988
+ type: z.literal("tool_use"),
989
+ /**
990
+ * The name of the tool to invoke.
991
+ * Must match a tool name from the request's tools array.
992
+ */
993
+ name: z.string(),
994
+ /**
995
+ * Unique identifier for this tool call.
996
+ * Used to correlate with ToolResultContent in subsequent messages.
997
+ */
998
+ id: z.string(),
999
+ /**
1000
+ * Arguments to pass to the tool.
1001
+ * Must conform to the tool's inputSchema.
1002
+ */
1003
+ input: z.record(z.string(), z.unknown()),
1004
+ /**
1005
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
1006
+ * for notes on _meta usage.
1007
+ */
1008
+ _meta: z.record(z.string(), z.unknown()).optional()
1009
+ });
1010
+ /**
1011
+ * The contents of a resource, embedded into a prompt or tool call result.
1012
+ */
1013
+ const EmbeddedResourceSchema = z.object({
1014
+ type: z.literal("resource"),
1015
+ resource: z.union([TextResourceContentsSchema, BlobResourceContentsSchema]),
1016
+ /**
1017
+ * Optional annotations for the client.
1018
+ */
1019
+ annotations: AnnotationsSchema.optional(),
1020
+ /**
1021
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
1022
+ * for notes on _meta usage.
1023
+ */
1024
+ _meta: z.record(z.string(), z.unknown()).optional()
1025
+ });
1026
+ /**
1027
+ * A resource that the server is capable of reading, included in a prompt or tool call result.
1028
+ *
1029
+ * Note: resource links returned by tools are not guaranteed to appear in the results of `resources/list` requests.
1030
+ */
1031
+ const ResourceLinkSchema = ResourceSchema.extend({ type: z.literal("resource_link") });
1032
+ /**
1033
+ * A content block that can be used in prompts and tool results.
1034
+ */
1035
+ const ContentBlockSchema = z.union([
1036
+ TextContentSchema,
1037
+ ImageContentSchema,
1038
+ AudioContentSchema,
1039
+ ResourceLinkSchema,
1040
+ EmbeddedResourceSchema
1041
+ ]);
1042
+ /**
1043
+ * Describes a message returned as part of a prompt.
1044
+ */
1045
+ const PromptMessageSchema = z.object({
1046
+ role: RoleSchema,
1047
+ content: ContentBlockSchema
1048
+ });
1049
+ /**
1050
+ * The server's response to a prompts/get request from the client.
1051
+ */
1052
+ const GetPromptResultSchema = ResultSchema.extend({
1053
+ /**
1054
+ * An optional description for the prompt.
1055
+ */
1056
+ description: z.string().optional(),
1057
+ messages: z.array(PromptMessageSchema)
1058
+ });
1059
+ /**
1060
+ * An optional notification from the server to the client, informing it that the list of prompts it offers has changed. This may be issued by servers without any previous subscription from the client.
1061
+ */
1062
+ const PromptListChangedNotificationSchema = NotificationSchema.extend({
1063
+ method: z.literal("notifications/prompts/list_changed"),
1064
+ params: NotificationsParamsSchema.optional()
1065
+ });
1066
+ /**
1067
+ * Additional properties describing a Tool to clients.
1068
+ *
1069
+ * NOTE: all properties in ToolAnnotations are **hints**.
1070
+ * They are not guaranteed to provide a faithful description of
1071
+ * tool behavior (including descriptive properties like `title`).
1072
+ *
1073
+ * Clients should never make tool use decisions based on ToolAnnotations
1074
+ * received from untrusted servers.
1075
+ */
1076
+ const ToolAnnotationsSchema = z.object({
1077
+ /**
1078
+ * A human-readable title for the tool.
1079
+ */
1080
+ title: z.string().optional(),
1081
+ /**
1082
+ * If true, the tool does not modify its environment.
1083
+ *
1084
+ * Default: false
1085
+ */
1086
+ readOnlyHint: z.boolean().optional(),
1087
+ /**
1088
+ * If true, the tool may perform destructive updates to its environment.
1089
+ * If false, the tool performs only additive updates.
1090
+ *
1091
+ * (This property is meaningful only when `readOnlyHint == false`)
1092
+ *
1093
+ * Default: true
1094
+ */
1095
+ destructiveHint: z.boolean().optional(),
1096
+ /**
1097
+ * If true, calling the tool repeatedly with the same arguments
1098
+ * will have no additional effect on the its environment.
1099
+ *
1100
+ * (This property is meaningful only when `readOnlyHint == false`)
1101
+ *
1102
+ * Default: false
1103
+ */
1104
+ idempotentHint: z.boolean().optional(),
1105
+ /**
1106
+ * If true, this tool may interact with an "open world" of external
1107
+ * entities. If false, the tool's domain of interaction is closed.
1108
+ * For example, the world of a web search tool is open, whereas that
1109
+ * of a memory tool is not.
1110
+ *
1111
+ * Default: true
1112
+ */
1113
+ openWorldHint: z.boolean().optional()
1114
+ });
1115
+ /**
1116
+ * Execution-related properties for a tool.
1117
+ */
1118
+ const ToolExecutionSchema = z.object({
1119
+ /**
1120
+ * Indicates the tool's preference for task-augmented execution.
1121
+ * - "required": Clients MUST invoke the tool as a task
1122
+ * - "optional": Clients MAY invoke the tool as a task or normal request
1123
+ * - "forbidden": Clients MUST NOT attempt to invoke the tool as a task
1124
+ *
1125
+ * If not present, defaults to "forbidden".
1126
+ */
1127
+ taskSupport: z.enum([
1128
+ "required",
1129
+ "optional",
1130
+ "forbidden"
1131
+ ]).optional() });
1132
+ /**
1133
+ * Definition for a tool the client can call.
1134
+ */
1135
+ const ToolSchema = z.object({
1136
+ ...BaseMetadataSchema.shape,
1137
+ ...IconsSchema.shape,
1138
+ /**
1139
+ * A human-readable description of the tool.
1140
+ */
1141
+ description: z.string().optional(),
1142
+ /**
1143
+ * A JSON Schema 2020-12 object defining the expected parameters for the tool.
1144
+ * Must have type: 'object' at the root level per MCP spec.
1145
+ */
1146
+ inputSchema: z.object({
1147
+ type: z.literal("object"),
1148
+ properties: z.record(z.string(), AssertObjectSchema).optional(),
1149
+ required: z.array(z.string()).optional()
1150
+ }).catchall(z.unknown()),
1151
+ /**
1152
+ * An optional JSON Schema 2020-12 object defining the structure of the tool's output
1153
+ * returned in the structuredContent field of a CallToolResult.
1154
+ * Must have type: 'object' at the root level per MCP spec.
1155
+ */
1156
+ outputSchema: z.object({
1157
+ type: z.literal("object"),
1158
+ properties: z.record(z.string(), AssertObjectSchema).optional(),
1159
+ required: z.array(z.string()).optional()
1160
+ }).catchall(z.unknown()).optional(),
1161
+ /**
1162
+ * Optional additional tool information.
1163
+ */
1164
+ annotations: ToolAnnotationsSchema.optional(),
1165
+ /**
1166
+ * Execution-related properties for this tool.
1167
+ */
1168
+ execution: ToolExecutionSchema.optional(),
1169
+ /**
1170
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
1171
+ * for notes on _meta usage.
1172
+ */
1173
+ _meta: z.record(z.string(), z.unknown()).optional()
1174
+ });
1175
+ /**
1176
+ * Sent from the client to request a list of tools the server has.
1177
+ */
1178
+ const ListToolsRequestSchema = PaginatedRequestSchema.extend({ method: z.literal("tools/list") });
1179
+ /**
1180
+ * The server's response to a tools/list request from the client.
1181
+ */
1182
+ const ListToolsResultSchema = PaginatedResultSchema.extend({ tools: z.array(ToolSchema) });
1183
+ /**
1184
+ * The server's response to a tool call.
1185
+ */
1186
+ const CallToolResultSchema = ResultSchema.extend({
1187
+ /**
1188
+ * A list of content objects that represent the result of the tool call.
1189
+ *
1190
+ * If the Tool does not define an outputSchema, this field MUST be present in the result.
1191
+ * For backwards compatibility, this field is always present, but it may be empty.
1192
+ */
1193
+ content: z.array(ContentBlockSchema).default([]),
1194
+ /**
1195
+ * An object containing structured tool output.
1196
+ *
1197
+ * If the Tool defines an outputSchema, this field MUST be present in the result, and contain a JSON object that matches the schema.
1198
+ */
1199
+ structuredContent: z.record(z.string(), z.unknown()).optional(),
1200
+ /**
1201
+ * Whether the tool call ended in an error.
1202
+ *
1203
+ * If not set, this is assumed to be false (the call was successful).
1204
+ *
1205
+ * Any errors that originate from the tool SHOULD be reported inside the result
1206
+ * object, with `isError` set to true, _not_ as an MCP protocol-level error
1207
+ * response. Otherwise, the LLM would not be able to see that an error occurred
1208
+ * and self-correct.
1209
+ *
1210
+ * However, any errors in _finding_ the tool, an error indicating that the
1211
+ * server does not support tool calls, or any other exceptional conditions,
1212
+ * should be reported as an MCP error response.
1213
+ */
1214
+ isError: z.boolean().optional()
1215
+ });
1216
+ CallToolResultSchema.or(ResultSchema.extend({ toolResult: z.unknown() }));
1217
+ /**
1218
+ * Parameters for a `tools/call` request.
1219
+ */
1220
+ const CallToolRequestParamsSchema = TaskAugmentedRequestParamsSchema.extend({
1221
+ /**
1222
+ * The name of the tool to call.
1223
+ */
1224
+ name: z.string(),
1225
+ /**
1226
+ * Arguments to pass to the tool.
1227
+ */
1228
+ arguments: z.record(z.string(), z.unknown()).optional()
1229
+ });
1230
+ /**
1231
+ * Used by the client to invoke a tool provided by the server.
1232
+ */
1233
+ const CallToolRequestSchema = RequestSchema.extend({
1234
+ method: z.literal("tools/call"),
1235
+ params: CallToolRequestParamsSchema
1236
+ });
1237
+ /**
1238
+ * 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.
1239
+ */
1240
+ const ToolListChangedNotificationSchema = NotificationSchema.extend({
1241
+ method: z.literal("notifications/tools/list_changed"),
1242
+ params: NotificationsParamsSchema.optional()
1243
+ });
1244
+ z.object({
1245
+ /**
1246
+ * If true, the list will be refreshed automatically when a list changed notification is received.
1247
+ * The callback will be called with the updated list.
1248
+ *
1249
+ * If false, the callback will be called with null items, allowing manual refresh.
1250
+ *
1251
+ * @default true
1252
+ */
1253
+ autoRefresh: z.boolean().default(true),
1254
+ /**
1255
+ * Debounce time in milliseconds for list changed notification processing.
1256
+ *
1257
+ * Multiple notifications received within this timeframe will only trigger one refresh.
1258
+ * Set to 0 to disable debouncing.
1259
+ *
1260
+ * @default 300
1261
+ */
1262
+ debounceMs: z.number().int().nonnegative().default(300)
1263
+ });
1264
+ /**
1265
+ * The severity of a log message.
1266
+ */
1267
+ const LoggingLevelSchema = z.enum([
1268
+ "debug",
1269
+ "info",
1270
+ "notice",
1271
+ "warning",
1272
+ "error",
1273
+ "critical",
1274
+ "alert",
1275
+ "emergency"
1276
+ ]);
1277
+ /**
1278
+ * Parameters for a `logging/setLevel` request.
1279
+ */
1280
+ const SetLevelRequestParamsSchema = BaseRequestParamsSchema.extend({
1281
+ /**
1282
+ * 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.
1283
+ */
1284
+ level: LoggingLevelSchema });
1285
+ /**
1286
+ * A request from the client to the server, to enable or adjust logging.
1287
+ */
1288
+ const SetLevelRequestSchema = RequestSchema.extend({
1289
+ method: z.literal("logging/setLevel"),
1290
+ params: SetLevelRequestParamsSchema
1291
+ });
1292
+ /**
1293
+ * Parameters for a `notifications/message` notification.
1294
+ */
1295
+ const LoggingMessageNotificationParamsSchema = NotificationsParamsSchema.extend({
1296
+ /**
1297
+ * The severity of this log message.
1298
+ */
1299
+ level: LoggingLevelSchema,
1300
+ /**
1301
+ * An optional name of the logger issuing this message.
1302
+ */
1303
+ logger: z.string().optional(),
1304
+ /**
1305
+ * The data to be logged, such as a string message or an object. Any JSON serializable type is allowed here.
1306
+ */
1307
+ data: z.unknown()
1308
+ });
1309
+ /**
1310
+ * 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.
1311
+ */
1312
+ const LoggingMessageNotificationSchema = NotificationSchema.extend({
1313
+ method: z.literal("notifications/message"),
1314
+ params: LoggingMessageNotificationParamsSchema
1315
+ });
1316
+ /**
1317
+ * Hints to use for model selection.
1318
+ */
1319
+ const ModelHintSchema = z.object({
1320
+ /**
1321
+ * A hint for a model name.
1322
+ */
1323
+ name: z.string().optional() });
1324
+ /**
1325
+ * The server's preferences for model selection, requested of the client during sampling.
1326
+ */
1327
+ const ModelPreferencesSchema = z.object({
1328
+ /**
1329
+ * Optional hints to use for model selection.
1330
+ */
1331
+ hints: z.array(ModelHintSchema).optional(),
1332
+ /**
1333
+ * How much to prioritize cost when selecting a model.
1334
+ */
1335
+ costPriority: z.number().min(0).max(1).optional(),
1336
+ /**
1337
+ * How much to prioritize sampling speed (latency) when selecting a model.
1338
+ */
1339
+ speedPriority: z.number().min(0).max(1).optional(),
1340
+ /**
1341
+ * How much to prioritize intelligence and capabilities when selecting a model.
1342
+ */
1343
+ intelligencePriority: z.number().min(0).max(1).optional()
1344
+ });
1345
+ /**
1346
+ * Controls tool usage behavior in sampling requests.
1347
+ */
1348
+ const ToolChoiceSchema = z.object({
1349
+ /**
1350
+ * Controls when tools are used:
1351
+ * - "auto": Model decides whether to use tools (default)
1352
+ * - "required": Model MUST use at least one tool before completing
1353
+ * - "none": Model MUST NOT use any tools
1354
+ */
1355
+ mode: z.enum([
1356
+ "auto",
1357
+ "required",
1358
+ "none"
1359
+ ]).optional() });
1360
+ /**
1361
+ * The result of a tool execution, provided by the user (server).
1362
+ * Represents the outcome of invoking a tool requested via ToolUseContent.
1363
+ */
1364
+ const ToolResultContentSchema = z.object({
1365
+ type: z.literal("tool_result"),
1366
+ toolUseId: z.string().describe("The unique identifier for the corresponding tool call."),
1367
+ content: z.array(ContentBlockSchema).default([]),
1368
+ structuredContent: z.object({}).loose().optional(),
1369
+ isError: z.boolean().optional(),
1370
+ /**
1371
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
1372
+ * for notes on _meta usage.
1373
+ */
1374
+ _meta: z.record(z.string(), z.unknown()).optional()
1375
+ });
1376
+ /**
1377
+ * Basic content types for sampling responses (without tool use).
1378
+ * Used for backwards-compatible CreateMessageResult when tools are not used.
1379
+ */
1380
+ const SamplingContentSchema = z.discriminatedUnion("type", [
1381
+ TextContentSchema,
1382
+ ImageContentSchema,
1383
+ AudioContentSchema
1384
+ ]);
1385
+ /**
1386
+ * Content block types allowed in sampling messages.
1387
+ * This includes text, image, audio, tool use requests, and tool results.
1388
+ */
1389
+ const SamplingMessageContentBlockSchema = z.discriminatedUnion("type", [
1390
+ TextContentSchema,
1391
+ ImageContentSchema,
1392
+ AudioContentSchema,
1393
+ ToolUseContentSchema,
1394
+ ToolResultContentSchema
1395
+ ]);
1396
+ /**
1397
+ * Describes a message issued to or received from an LLM API.
1398
+ */
1399
+ const SamplingMessageSchema = z.object({
1400
+ role: RoleSchema,
1401
+ content: z.union([SamplingMessageContentBlockSchema, z.array(SamplingMessageContentBlockSchema)]),
1402
+ /**
1403
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
1404
+ * for notes on _meta usage.
1405
+ */
1406
+ _meta: z.record(z.string(), z.unknown()).optional()
1407
+ });
1408
+ /**
1409
+ * Parameters for a `sampling/createMessage` request.
1410
+ */
1411
+ const CreateMessageRequestParamsSchema = TaskAugmentedRequestParamsSchema.extend({
1412
+ messages: z.array(SamplingMessageSchema),
1413
+ /**
1414
+ * The server's preferences for which model to select. The client MAY modify or omit this request.
1415
+ */
1416
+ modelPreferences: ModelPreferencesSchema.optional(),
1417
+ /**
1418
+ * An optional system prompt the server wants to use for sampling. The client MAY modify or omit this prompt.
1419
+ */
1420
+ systemPrompt: z.string().optional(),
1421
+ /**
1422
+ * A request to include context from one or more MCP servers (including the caller), to be attached to the prompt.
1423
+ * The client MAY ignore this request.
1424
+ *
1425
+ * Default is "none". Values "thisServer" and "allServers" are soft-deprecated. Servers SHOULD only use these values if the client
1426
+ * declares ClientCapabilities.sampling.context. These values may be removed in future spec releases.
1427
+ */
1428
+ includeContext: z.enum([
1429
+ "none",
1430
+ "thisServer",
1431
+ "allServers"
1432
+ ]).optional(),
1433
+ temperature: z.number().optional(),
1434
+ /**
1435
+ * The requested maximum number of tokens to sample (to prevent runaway completions).
1436
+ *
1437
+ * The client MAY choose to sample fewer tokens than the requested maximum.
1438
+ */
1439
+ maxTokens: z.number().int(),
1440
+ stopSequences: z.array(z.string()).optional(),
1441
+ /**
1442
+ * Optional metadata to pass through to the LLM provider. The format of this metadata is provider-specific.
1443
+ */
1444
+ metadata: AssertObjectSchema.optional(),
1445
+ /**
1446
+ * Tools that the model may use during generation.
1447
+ * The client MUST return an error if this field is provided but ClientCapabilities.sampling.tools is not declared.
1448
+ */
1449
+ tools: z.array(ToolSchema).optional(),
1450
+ /**
1451
+ * Controls how the model uses tools.
1452
+ * The client MUST return an error if this field is provided but ClientCapabilities.sampling.tools is not declared.
1453
+ * Default is `{ mode: "auto" }`.
1454
+ */
1455
+ toolChoice: ToolChoiceSchema.optional()
1456
+ });
1457
+ /**
1458
+ * 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.
1459
+ */
1460
+ const CreateMessageRequestSchema = RequestSchema.extend({
1461
+ method: z.literal("sampling/createMessage"),
1462
+ params: CreateMessageRequestParamsSchema
1463
+ });
1464
+ /**
1465
+ * The client's response to a sampling/create_message request from the server.
1466
+ * This is the backwards-compatible version that returns single content (no arrays).
1467
+ * Used when the request does not include tools.
1468
+ */
1469
+ const CreateMessageResultSchema = ResultSchema.extend({
1470
+ /**
1471
+ * The name of the model that generated the message.
1472
+ */
1473
+ model: z.string(),
1474
+ /**
1475
+ * The reason why sampling stopped, if known.
1476
+ *
1477
+ * Standard values:
1478
+ * - "endTurn": Natural end of the assistant's turn
1479
+ * - "stopSequence": A stop sequence was encountered
1480
+ * - "maxTokens": Maximum token limit was reached
1481
+ *
1482
+ * This field is an open string to allow for provider-specific stop reasons.
1483
+ */
1484
+ stopReason: z.optional(z.enum([
1485
+ "endTurn",
1486
+ "stopSequence",
1487
+ "maxTokens"
1488
+ ]).or(z.string())),
1489
+ role: RoleSchema,
1490
+ /**
1491
+ * Response content. Single content block (text, image, or audio).
1492
+ */
1493
+ content: SamplingContentSchema
1494
+ });
1495
+ /**
1496
+ * The client's response to a sampling/create_message request when tools were provided.
1497
+ * This version supports array content for tool use flows.
1498
+ */
1499
+ const CreateMessageResultWithToolsSchema = ResultSchema.extend({
1500
+ /**
1501
+ * The name of the model that generated the message.
1502
+ */
1503
+ model: z.string(),
1504
+ /**
1505
+ * The reason why sampling stopped, if known.
1506
+ *
1507
+ * Standard values:
1508
+ * - "endTurn": Natural end of the assistant's turn
1509
+ * - "stopSequence": A stop sequence was encountered
1510
+ * - "maxTokens": Maximum token limit was reached
1511
+ * - "toolUse": The model wants to use one or more tools
1512
+ *
1513
+ * This field is an open string to allow for provider-specific stop reasons.
1514
+ */
1515
+ stopReason: z.optional(z.enum([
1516
+ "endTurn",
1517
+ "stopSequence",
1518
+ "maxTokens",
1519
+ "toolUse"
1520
+ ]).or(z.string())),
1521
+ role: RoleSchema,
1522
+ /**
1523
+ * Response content. May be a single block or array. May include ToolUseContent if stopReason is "toolUse".
1524
+ */
1525
+ content: z.union([SamplingMessageContentBlockSchema, z.array(SamplingMessageContentBlockSchema)])
1526
+ });
1527
+ /**
1528
+ * Primitive schema definition for boolean fields.
1529
+ */
1530
+ const BooleanSchemaSchema = z.object({
1531
+ type: z.literal("boolean"),
1532
+ title: z.string().optional(),
1533
+ description: z.string().optional(),
1534
+ default: z.boolean().optional()
1535
+ });
1536
+ /**
1537
+ * Primitive schema definition for string fields.
1538
+ */
1539
+ const StringSchemaSchema = z.object({
1540
+ type: z.literal("string"),
1541
+ title: z.string().optional(),
1542
+ description: z.string().optional(),
1543
+ minLength: z.number().optional(),
1544
+ maxLength: z.number().optional(),
1545
+ format: z.enum([
1546
+ "email",
1547
+ "uri",
1548
+ "date",
1549
+ "date-time"
1550
+ ]).optional(),
1551
+ default: z.string().optional()
1552
+ });
1553
+ /**
1554
+ * Primitive schema definition for number fields.
1555
+ */
1556
+ const NumberSchemaSchema = z.object({
1557
+ type: z.enum(["number", "integer"]),
1558
+ title: z.string().optional(),
1559
+ description: z.string().optional(),
1560
+ minimum: z.number().optional(),
1561
+ maximum: z.number().optional(),
1562
+ default: z.number().optional()
1563
+ });
1564
+ /**
1565
+ * Schema for single-selection enumeration without display titles for options.
1566
+ */
1567
+ const UntitledSingleSelectEnumSchemaSchema = z.object({
1568
+ type: z.literal("string"),
1569
+ title: z.string().optional(),
1570
+ description: z.string().optional(),
1571
+ enum: z.array(z.string()),
1572
+ default: z.string().optional()
1573
+ });
1574
+ /**
1575
+ * Schema for single-selection enumeration with display titles for each option.
1576
+ */
1577
+ const TitledSingleSelectEnumSchemaSchema = z.object({
1578
+ type: z.literal("string"),
1579
+ title: z.string().optional(),
1580
+ description: z.string().optional(),
1581
+ oneOf: z.array(z.object({
1582
+ const: z.string(),
1583
+ title: z.string()
1584
+ })),
1585
+ default: z.string().optional()
1586
+ });
1587
+ /**
1588
+ * Use TitledSingleSelectEnumSchema instead.
1589
+ * This interface will be removed in a future version.
1590
+ */
1591
+ const LegacyTitledEnumSchemaSchema = z.object({
1592
+ type: z.literal("string"),
1593
+ title: z.string().optional(),
1594
+ description: z.string().optional(),
1595
+ enum: z.array(z.string()),
1596
+ enumNames: z.array(z.string()).optional(),
1597
+ default: z.string().optional()
1598
+ });
1599
+ const SingleSelectEnumSchemaSchema = z.union([UntitledSingleSelectEnumSchemaSchema, TitledSingleSelectEnumSchemaSchema]);
1600
+ /**
1601
+ * Schema for multiple-selection enumeration without display titles for options.
1602
+ */
1603
+ const UntitledMultiSelectEnumSchemaSchema = z.object({
1604
+ type: z.literal("array"),
1605
+ title: z.string().optional(),
1606
+ description: z.string().optional(),
1607
+ minItems: z.number().optional(),
1608
+ maxItems: z.number().optional(),
1609
+ items: z.object({
1610
+ type: z.literal("string"),
1611
+ enum: z.array(z.string())
1612
+ }),
1613
+ default: z.array(z.string()).optional()
1614
+ });
1615
+ /**
1616
+ * Schema for multiple-selection enumeration with display titles for each option.
1617
+ */
1618
+ const TitledMultiSelectEnumSchemaSchema = z.object({
1619
+ type: z.literal("array"),
1620
+ title: z.string().optional(),
1621
+ description: z.string().optional(),
1622
+ minItems: z.number().optional(),
1623
+ maxItems: z.number().optional(),
1624
+ items: z.object({ anyOf: z.array(z.object({
1625
+ const: z.string(),
1626
+ title: z.string()
1627
+ })) }),
1628
+ default: z.array(z.string()).optional()
1629
+ });
1630
+ /**
1631
+ * Combined schema for multiple-selection enumeration
1632
+ */
1633
+ const MultiSelectEnumSchemaSchema = z.union([UntitledMultiSelectEnumSchemaSchema, TitledMultiSelectEnumSchemaSchema]);
1634
+ /**
1635
+ * Primitive schema definition for enum fields.
1636
+ */
1637
+ const EnumSchemaSchema = z.union([
1638
+ LegacyTitledEnumSchemaSchema,
1639
+ SingleSelectEnumSchemaSchema,
1640
+ MultiSelectEnumSchemaSchema
1641
+ ]);
1642
+ /**
1643
+ * Union of all primitive schema definitions.
1644
+ */
1645
+ const PrimitiveSchemaDefinitionSchema = z.union([
1646
+ EnumSchemaSchema,
1647
+ BooleanSchemaSchema,
1648
+ StringSchemaSchema,
1649
+ NumberSchemaSchema
1650
+ ]);
1651
+ /**
1652
+ * Parameters for an `elicitation/create` request for form-based elicitation.
1653
+ */
1654
+ const ElicitRequestFormParamsSchema = TaskAugmentedRequestParamsSchema.extend({
1655
+ /**
1656
+ * The elicitation mode.
1657
+ *
1658
+ * Optional for backward compatibility. Clients MUST treat missing mode as "form".
1659
+ */
1660
+ mode: z.literal("form").optional(),
1661
+ /**
1662
+ * The message to present to the user describing what information is being requested.
1663
+ */
1664
+ message: z.string(),
1665
+ /**
1666
+ * A restricted subset of JSON Schema.
1667
+ * Only top-level properties are allowed, without nesting.
1668
+ */
1669
+ requestedSchema: z.object({
1670
+ type: z.literal("object"),
1671
+ properties: z.record(z.string(), PrimitiveSchemaDefinitionSchema),
1672
+ required: z.array(z.string()).optional()
1673
+ })
1674
+ });
1675
+ /**
1676
+ * Parameters for an `elicitation/create` request for URL-based elicitation.
1677
+ */
1678
+ const ElicitRequestURLParamsSchema = TaskAugmentedRequestParamsSchema.extend({
1679
+ /**
1680
+ * The elicitation mode.
1681
+ */
1682
+ mode: z.literal("url"),
1683
+ /**
1684
+ * The message to present to the user explaining why the interaction is needed.
1685
+ */
1686
+ message: z.string(),
1687
+ /**
1688
+ * The ID of the elicitation, which must be unique within the context of the server.
1689
+ * The client MUST treat this ID as an opaque value.
1690
+ */
1691
+ elicitationId: z.string(),
1692
+ /**
1693
+ * The URL that the user should navigate to.
1694
+ */
1695
+ url: z.string().url()
1696
+ });
1697
+ /**
1698
+ * The parameters for a request to elicit additional information from the user via the client.
1699
+ */
1700
+ const ElicitRequestParamsSchema = z.union([ElicitRequestFormParamsSchema, ElicitRequestURLParamsSchema]);
1701
+ /**
1702
+ * A request from the server to elicit user input via the client.
1703
+ * The client should present the message and form fields to the user (form mode)
1704
+ * or navigate to a URL (URL mode).
1705
+ */
1706
+ const ElicitRequestSchema = RequestSchema.extend({
1707
+ method: z.literal("elicitation/create"),
1708
+ params: ElicitRequestParamsSchema
1709
+ });
1710
+ /**
1711
+ * Parameters for a `notifications/elicitation/complete` notification.
1712
+ *
1713
+ * @category notifications/elicitation/complete
1714
+ */
1715
+ const ElicitationCompleteNotificationParamsSchema = NotificationsParamsSchema.extend({
1716
+ /**
1717
+ * The ID of the elicitation that completed.
1718
+ */
1719
+ elicitationId: z.string() });
1720
+ /**
1721
+ * A notification from the server to the client, informing it of a completion of an out-of-band elicitation request.
1722
+ *
1723
+ * @category notifications/elicitation/complete
1724
+ */
1725
+ const ElicitationCompleteNotificationSchema = NotificationSchema.extend({
1726
+ method: z.literal("notifications/elicitation/complete"),
1727
+ params: ElicitationCompleteNotificationParamsSchema
1728
+ });
1729
+ /**
1730
+ * The client's response to an elicitation/create request from the server.
1731
+ */
1732
+ const ElicitResultSchema = ResultSchema.extend({
1733
+ /**
1734
+ * The user action in response to the elicitation.
1735
+ * - "accept": User submitted the form/confirmed the action
1736
+ * - "decline": User explicitly decline the action
1737
+ * - "cancel": User dismissed without making an explicit choice
1738
+ */
1739
+ action: z.enum([
1740
+ "accept",
1741
+ "decline",
1742
+ "cancel"
1743
+ ]),
1744
+ /**
1745
+ * The submitted form data, only present when action is "accept".
1746
+ * Contains values matching the requested schema.
1747
+ * Per MCP spec, content is "typically omitted" for decline/cancel actions.
1748
+ * We normalize null to undefined for leniency while maintaining type compatibility.
1749
+ */
1750
+ content: z.preprocess((val) => val === null ? void 0 : val, z.record(z.string(), z.union([
1751
+ z.string(),
1752
+ z.number(),
1753
+ z.boolean(),
1754
+ z.array(z.string())
1755
+ ])).optional())
1756
+ });
1757
+ /**
1758
+ * A reference to a resource or resource template definition.
1759
+ */
1760
+ const ResourceTemplateReferenceSchema = z.object({
1761
+ type: z.literal("ref/resource"),
1762
+ /**
1763
+ * The URI or URI template of the resource.
1764
+ */
1765
+ uri: z.string()
1766
+ });
1767
+ /**
1768
+ * Identifies a prompt.
1769
+ */
1770
+ const PromptReferenceSchema = z.object({
1771
+ type: z.literal("ref/prompt"),
1772
+ /**
1773
+ * The name of the prompt or prompt template
1774
+ */
1775
+ name: z.string()
1776
+ });
1777
+ /**
1778
+ * Parameters for a `completion/complete` request.
1779
+ */
1780
+ const CompleteRequestParamsSchema = BaseRequestParamsSchema.extend({
1781
+ ref: z.union([PromptReferenceSchema, ResourceTemplateReferenceSchema]),
1782
+ /**
1783
+ * The argument's information
1784
+ */
1785
+ argument: z.object({
1786
+ /**
1787
+ * The name of the argument
1788
+ */
1789
+ name: z.string(),
1790
+ /**
1791
+ * The value of the argument to use for completion matching.
1792
+ */
1793
+ value: z.string()
1794
+ }),
1795
+ context: z.object({
1796
+ /**
1797
+ * Previously-resolved variables in a URI template or prompt.
1798
+ */
1799
+ arguments: z.record(z.string(), z.string()).optional() }).optional()
1800
+ });
1801
+ /**
1802
+ * A request from the client to the server, to ask for completion options.
1803
+ */
1804
+ const CompleteRequestSchema = RequestSchema.extend({
1805
+ method: z.literal("completion/complete"),
1806
+ params: CompleteRequestParamsSchema
1807
+ });
1808
+ /**
1809
+ * The server's response to a completion/complete request
1810
+ */
1811
+ const CompleteResultSchema = ResultSchema.extend({ completion: z.looseObject({
1812
+ /**
1813
+ * An array of completion values. Must not exceed 100 items.
1814
+ */
1815
+ values: z.array(z.string()).max(100),
1816
+ /**
1817
+ * The total number of completion options available. This can exceed the number of values actually sent in the response.
1818
+ */
1819
+ total: z.optional(z.number().int()),
1820
+ /**
1821
+ * Indicates whether there are additional completion options beyond those provided in the current response, even if the exact total is unknown.
1822
+ */
1823
+ hasMore: z.optional(z.boolean())
1824
+ }) });
1825
+ /**
1826
+ * Represents a root directory or file that the server can operate on.
1827
+ */
1828
+ const RootSchema = z.object({
1829
+ /**
1830
+ * The URI identifying the root. This *must* start with file:// for now.
1831
+ */
1832
+ uri: z.string().startsWith("file://"),
1833
+ /**
1834
+ * An optional name for the root.
1835
+ */
1836
+ name: z.string().optional(),
1837
+ /**
1838
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
1839
+ * for notes on _meta usage.
1840
+ */
1841
+ _meta: z.record(z.string(), z.unknown()).optional()
1842
+ });
1843
+ /**
1844
+ * Sent from the server to request a list of root URIs from the client.
1845
+ */
1846
+ const ListRootsRequestSchema = RequestSchema.extend({
1847
+ method: z.literal("roots/list"),
1848
+ params: BaseRequestParamsSchema.optional()
1849
+ });
1850
+ /**
1851
+ * The client's response to a roots/list request from the server.
1852
+ */
1853
+ const ListRootsResultSchema = ResultSchema.extend({ roots: z.array(RootSchema) });
1854
+ /**
1855
+ * A notification from the client to the server, informing it that the list of roots has changed.
1856
+ */
1857
+ const RootsListChangedNotificationSchema = NotificationSchema.extend({
1858
+ method: z.literal("notifications/roots/list_changed"),
1859
+ params: NotificationsParamsSchema.optional()
1860
+ });
1861
+ z.union([
1862
+ PingRequestSchema,
1863
+ InitializeRequestSchema,
1864
+ CompleteRequestSchema,
1865
+ SetLevelRequestSchema,
1866
+ GetPromptRequestSchema,
1867
+ ListPromptsRequestSchema,
1868
+ ListResourcesRequestSchema,
1869
+ ListResourceTemplatesRequestSchema,
1870
+ ReadResourceRequestSchema,
1871
+ SubscribeRequestSchema,
1872
+ UnsubscribeRequestSchema,
1873
+ CallToolRequestSchema,
1874
+ ListToolsRequestSchema,
1875
+ GetTaskRequestSchema,
1876
+ GetTaskPayloadRequestSchema,
1877
+ ListTasksRequestSchema,
1878
+ CancelTaskRequestSchema
1879
+ ]);
1880
+ z.union([
1881
+ CancelledNotificationSchema,
1882
+ ProgressNotificationSchema,
1883
+ InitializedNotificationSchema,
1884
+ RootsListChangedNotificationSchema,
1885
+ TaskStatusNotificationSchema
1886
+ ]);
1887
+ z.union([
1888
+ EmptyResultSchema,
1889
+ CreateMessageResultSchema,
1890
+ CreateMessageResultWithToolsSchema,
1891
+ ElicitResultSchema,
1892
+ ListRootsResultSchema,
1893
+ GetTaskResultSchema,
1894
+ ListTasksResultSchema,
1895
+ CreateTaskResultSchema
1896
+ ]);
1897
+ z.union([
1898
+ PingRequestSchema,
1899
+ CreateMessageRequestSchema,
1900
+ ElicitRequestSchema,
1901
+ ListRootsRequestSchema,
1902
+ GetTaskRequestSchema,
1903
+ GetTaskPayloadRequestSchema,
1904
+ ListTasksRequestSchema,
1905
+ CancelTaskRequestSchema
1906
+ ]);
1907
+ z.union([
1908
+ CancelledNotificationSchema,
1909
+ ProgressNotificationSchema,
1910
+ LoggingMessageNotificationSchema,
1911
+ ResourceUpdatedNotificationSchema,
1912
+ ResourceListChangedNotificationSchema,
1913
+ ToolListChangedNotificationSchema,
1914
+ PromptListChangedNotificationSchema,
1915
+ TaskStatusNotificationSchema,
1916
+ ElicitationCompleteNotificationSchema
1917
+ ]);
1918
+ z.union([
1919
+ EmptyResultSchema,
1920
+ InitializeResultSchema,
1921
+ CompleteResultSchema,
1922
+ GetPromptResultSchema,
1923
+ ListPromptsResultSchema,
1924
+ ListResourcesResultSchema,
1925
+ ListResourceTemplatesResultSchema,
1926
+ ReadResourceResultSchema,
1927
+ CallToolResultSchema,
1928
+ ListToolsResultSchema,
1929
+ GetTaskResultSchema,
1930
+ ListTasksResultSchema,
1931
+ CreateTaskResultSchema
1932
+ ]);
1933
+ //#endregion
1934
+ //#region node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js
1935
+ /**
1936
+ * Buffers a continuous stdio stream into discrete JSON-RPC messages.
1937
+ */
1938
+ var ReadBuffer = class {
1939
+ append(chunk) {
1940
+ this._buffer = this._buffer ? Buffer.concat([this._buffer, chunk]) : chunk;
1941
+ }
1942
+ readMessage() {
1943
+ if (!this._buffer) return null;
1944
+ const index = this._buffer.indexOf("\n");
1945
+ if (index === -1) return null;
1946
+ const line = this._buffer.toString("utf8", 0, index).replace(/\r$/, "");
1947
+ this._buffer = this._buffer.subarray(index + 1);
1948
+ return deserializeMessage(line);
1949
+ }
1950
+ clear() {
1951
+ this._buffer = void 0;
1952
+ }
1953
+ };
1954
+ function deserializeMessage(line) {
1955
+ return JSONRPCMessageSchema.parse(JSON.parse(line));
1956
+ }
1957
+ function serializeMessage(message) {
1958
+ return JSON.stringify(message) + "\n";
1959
+ }
1960
+ //#endregion
1961
+ //#region node_modules/@modelcontextprotocol/sdk/dist/esm/client/stdio.js
1962
+ /**
1963
+ * Environment variables to inherit by default, if an environment is not explicitly given.
1964
+ */
1965
+ const DEFAULT_INHERITED_ENV_VARS = process.platform === "win32" ? [
1966
+ "APPDATA",
1967
+ "HOMEDRIVE",
1968
+ "HOMEPATH",
1969
+ "LOCALAPPDATA",
1970
+ "PATH",
1971
+ "PROCESSOR_ARCHITECTURE",
1972
+ "SYSTEMDRIVE",
1973
+ "SYSTEMROOT",
1974
+ "TEMP",
1975
+ "USERNAME",
1976
+ "USERPROFILE",
1977
+ "PROGRAMFILES"
1978
+ ] : [
1979
+ "HOME",
1980
+ "LOGNAME",
1981
+ "PATH",
1982
+ "SHELL",
1983
+ "TERM",
1984
+ "USER"
1985
+ ];
1986
+ /**
1987
+ * Returns a default environment object including only environment variables deemed safe to inherit.
1988
+ */
1989
+ function getDefaultEnvironment() {
1990
+ const env = {};
1991
+ for (const key of DEFAULT_INHERITED_ENV_VARS) {
1992
+ const value = process.env[key];
1993
+ if (value === void 0) continue;
1994
+ if (value.startsWith("()")) continue;
1995
+ env[key] = value;
1996
+ }
1997
+ return env;
1998
+ }
1999
+ /**
2000
+ * Client transport for stdio: this will connect to a server by spawning a process and communicating with it over stdin/stdout.
2001
+ *
2002
+ * This transport is only available in Node.js environments.
2003
+ */
2004
+ var StdioClientTransport = class {
2005
+ constructor(server) {
2006
+ this._readBuffer = new ReadBuffer();
2007
+ this._stderrStream = null;
2008
+ this._serverParams = server;
2009
+ if (server.stderr === "pipe" || server.stderr === "overlapped") this._stderrStream = new PassThrough();
2010
+ }
2011
+ /**
2012
+ * Starts the server process and prepares to communicate with it.
2013
+ */
2014
+ async start() {
2015
+ if (this._process) throw new Error("StdioClientTransport already started! If using Client class, note that connect() calls start() automatically.");
2016
+ return new Promise((resolve, reject) => {
2017
+ this._process = spawn$1(this._serverParams.command, this._serverParams.args ?? [], {
2018
+ env: {
2019
+ ...getDefaultEnvironment(),
2020
+ ...this._serverParams.env
2021
+ },
2022
+ stdio: [
2023
+ "pipe",
2024
+ "pipe",
2025
+ this._serverParams.stderr ?? "inherit"
2026
+ ],
2027
+ shell: false,
2028
+ windowsHide: process.platform === "win32",
2029
+ cwd: this._serverParams.cwd
2030
+ });
2031
+ this._process.on("error", (error) => {
2032
+ reject(error);
2033
+ this.onerror?.(error);
2034
+ });
2035
+ this._process.on("spawn", () => {
2036
+ resolve();
2037
+ });
2038
+ this._process.on("close", (_code) => {
2039
+ this._process = void 0;
2040
+ this.onclose?.();
2041
+ });
2042
+ this._process.stdin?.on("error", (error) => {
2043
+ this.onerror?.(error);
2044
+ });
2045
+ this._process.stdout?.on("data", (chunk) => {
2046
+ this._readBuffer.append(chunk);
2047
+ this.processReadBuffer();
2048
+ });
2049
+ this._process.stdout?.on("error", (error) => {
2050
+ this.onerror?.(error);
2051
+ });
2052
+ if (this._stderrStream && this._process.stderr) this._process.stderr.pipe(this._stderrStream);
2053
+ });
2054
+ }
2055
+ /**
2056
+ * The stderr stream of the child process, if `StdioServerParameters.stderr` was set to "pipe" or "overlapped".
2057
+ *
2058
+ * If stderr piping was requested, a PassThrough stream is returned _immediately_, allowing callers to
2059
+ * attach listeners before the start method is invoked. This prevents loss of any early
2060
+ * error output emitted by the child process.
2061
+ */
2062
+ get stderr() {
2063
+ if (this._stderrStream) return this._stderrStream;
2064
+ return this._process?.stderr ?? null;
2065
+ }
2066
+ /**
2067
+ * The child process pid spawned by this transport.
2068
+ *
2069
+ * This is only available after the transport has been started.
2070
+ */
2071
+ get pid() {
2072
+ return this._process?.pid ?? null;
2073
+ }
2074
+ processReadBuffer() {
2075
+ while (true) try {
2076
+ const message = this._readBuffer.readMessage();
2077
+ if (message === null) break;
2078
+ this.onmessage?.(message);
2079
+ } catch (error) {
2080
+ this.onerror?.(error);
2081
+ }
2082
+ }
2083
+ async close() {
2084
+ if (this._process) {
2085
+ const processToClose = this._process;
2086
+ this._process = void 0;
2087
+ const closePromise = new Promise((resolve) => {
2088
+ processToClose.once("close", () => {
2089
+ resolve();
2090
+ });
2091
+ });
2092
+ try {
2093
+ processToClose.stdin?.end();
2094
+ } catch {}
2095
+ await Promise.race([closePromise, new Promise((resolve) => setTimeout(resolve, 2e3).unref())]);
2096
+ if (processToClose.exitCode === null) {
2097
+ try {
2098
+ processToClose.kill("SIGTERM");
2099
+ } catch {}
2100
+ await Promise.race([closePromise, new Promise((resolve) => setTimeout(resolve, 2e3).unref())]);
2101
+ }
2102
+ if (processToClose.exitCode === null) try {
2103
+ processToClose.kill("SIGKILL");
2104
+ } catch {}
2105
+ }
2106
+ this._readBuffer.clear();
2107
+ }
2108
+ send(message) {
2109
+ return new Promise((resolve) => {
2110
+ if (!this._process?.stdin) throw new Error("Not connected");
2111
+ const json = serializeMessage(message);
2112
+ if (this._process.stdin.write(json)) resolve();
2113
+ else this._process.stdin.once("drain", resolve);
2114
+ });
2115
+ }
2116
+ };
2117
+ //#endregion
2118
+ export { StdioClientTransport, getDefaultEnvironment };
2119
+
2120
+ //# sourceMappingURL=stdio-loader-C48v4hPt.js.map