tmcp 1.3.0 → 1.5.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tmcp",
3
- "version": "1.3.0",
3
+ "version": "1.5.0",
4
4
  "description": "The main tmcp library",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -34,6 +34,7 @@
34
34
  "devDependencies": {
35
35
  "@standard-schema/spec": "^1.0.0",
36
36
  "@types/json-schema": "^7.0.15",
37
+ "@types/node": "^24.0.13",
37
38
  "publint": "^0.3.12"
38
39
  },
39
40
  "scripts": {
package/src/index.d.ts CHANGED
@@ -1,3 +1,6 @@
1
+ /**
2
+ * @typedef {ClientCapabilitiesType} ClientCapabilities
3
+ */
1
4
  /**
2
5
  * @template {StandardSchemaV1} StandardSchema
3
6
  */
@@ -7,6 +10,28 @@ export class McpServer<StandardSchema extends StandardSchemaV1> {
7
10
  * @param {ServerOptions<StandardSchema>} options
8
11
  */
9
12
  constructor(server_info: ServerInfo, options: ServerOptions<StandardSchema>);
13
+ /**
14
+ * @type {Array<{uri: string, name?: string}>}
15
+ */
16
+ roots: Array<{
17
+ uri: string;
18
+ name?: string;
19
+ }>;
20
+ currentClientCapabilities(): {
21
+ roots?: {
22
+ listChanged?: boolean;
23
+ } & {
24
+ [key: string]: unknown;
25
+ };
26
+ sampling?: {} & {
27
+ [key: string]: unknown;
28
+ };
29
+ elicitation?: {} & {
30
+ [key: string]: unknown;
31
+ };
32
+ } & {
33
+ [key: string]: unknown;
34
+ };
10
35
  /**
11
36
  * @template {keyof McpEvents} TEvent
12
37
  * @param {TEvent} event
@@ -57,18 +82,36 @@ export class McpServer<StandardSchema extends StandardSchemaV1> {
57
82
  complete?: NoInfer<TVariables extends never ? never : Partial<Record<TVariables, Completion>>>;
58
83
  }, execute: (uri: string, params: Record<TVariables, string | string[]>) => Promise<ReadResourceResult> | ReadResourceResult): void;
59
84
  /**
60
- * @param {JSONRPCRequest} request
61
- * @returns {ReturnType<JSONRPCServer['receive']>}
85
+ * @param {JSONRPCResponse | JSONRPCRequest} message
86
+ * @param {string} [session_id]
87
+ * @returns {ReturnType<JSONRPCServer['receive']> | ReturnType<JSONRPCClient['receive'] | undefined>}
62
88
  */
63
- receive(request: JSONRPCRequest): ReturnType<JSONRPCServer["receive"]>;
89
+ receive(message: JSONRPCResponse | JSONRPCRequest, session_id?: string): ReturnType<JSONRPCServer["receive"]> | ReturnType<JSONRPCClient["receive"] | undefined>;
64
90
  /**
65
91
  * Send a notification for subscriptions
66
92
  * @param {SubscriptionsKeys} what
67
93
  * @param {string} id
68
94
  */
69
95
  changed(what: SubscriptionsKeys, id: string): void;
96
+ /**
97
+ * Refresh roots list from client
98
+ */
99
+ refreshRoots(): Promise<void>;
100
+ /**
101
+ * @template {StandardSchema} TSchema
102
+ * @param {TSchema} schema
103
+ * @returns {Promise<StandardSchemaV1.InferOutput<TSchema>>}
104
+ */
105
+ elicitation<TSchema extends StandardSchema>(schema: TSchema): Promise<StandardSchemaV1.InferOutput<TSchema>>;
106
+ /**
107
+ * Request language model sampling from the client
108
+ * @param {CreateMessageRequest} request
109
+ * @returns {Promise<CreateMessageResult>}
110
+ */
111
+ message(request: CreateMessageRequest): Promise<CreateMessageResult>;
70
112
  #private;
71
113
  }
114
+ export type ClientCapabilities = ClientCapabilitiesType;
72
115
  import type { StandardSchemaV1 } from "@standard-schema/spec";
73
116
  import type { McpEvents } from "./internal/internal.js";
74
117
  import type { CallToolResult } from "./validation/index.js";
@@ -76,8 +119,13 @@ import type { Completion } from "./internal/internal.js";
76
119
  import type { GetPromptResult } from "./validation/index.js";
77
120
  import type { ReadResourceResult } from "./validation/index.js";
78
121
  import type { ExtractURITemplateVariables } from "./internal/uri-template.js";
122
+ import type { JSONRPCResponse } from "./validation/index.js";
79
123
  import type { JSONRPCRequest } from "json-rpc-2.0";
80
124
  import { JSONRPCServer } from 'json-rpc-2.0';
125
+ import { JSONRPCClient } from 'json-rpc-2.0';
81
126
  import type { SubscriptionsKeys } from "./internal/internal.js";
127
+ import type { CreateMessageRequest } from "./validation/index.js";
128
+ import type { CreateMessageResult } from "./validation/index.js";
82
129
  import type { ServerInfo } from "./internal/internal.js";
83
130
  import type { ServerOptions } from "./internal/internal.js";
131
+ import type { ClientCapabilities as ClientCapabilitiesType } from "./validation/index.js";
package/src/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * @import { StandardSchemaV1 } from "@standard-schema/spec";
3
3
  * @import { JSONRPCRequest, JSONRPCParams } from "json-rpc-2.0";
4
4
  * @import { ExtractURITemplateVariables } from "./internal/uri-template.js";
5
- * @import { CallToolResult, ReadResourceResult, GetPromptResult, CompleteResult } from "./validation/index.js";
5
+ * @import { CallToolResult, ReadResourceResult, GetPromptResult, ClientCapabilities as ClientCapabilitiesType, JSONRPCRequest as JSONRPCRequestType, JSONRPCResponse, CreateMessageRequest, CreateMessageResult } from "./validation/index.js";
6
6
  * @import { Tool, Completion, Prompt, Resource, ServerOptions, ServerInfo, SubscriptionsKeys, McpEvents } from "./internal/internal.js";
7
7
  */
8
8
  import { JSONRPCServer, JSONRPCClient } from 'json-rpc-2.0';
@@ -12,16 +12,26 @@ import {
12
12
  ReadResourceResultSchema,
13
13
  GetPromptResultSchema,
14
14
  CompleteResultSchema,
15
+ InitializeRequestSchema,
16
+ JSONRPCRequestSchema,
17
+ JSONRPCResponseSchema,
18
+ CreateMessageRequestSchema,
19
+ CreateMessageResultSchema,
15
20
  } from './validation/index.js';
21
+ import { AsyncLocalStorage } from 'node:async_hooks';
16
22
  import * as v from 'valibot';
17
23
 
24
+ /**
25
+ * @typedef {ClientCapabilitiesType} ClientCapabilities
26
+ */
27
+
18
28
  /**
19
29
  * @template {StandardSchemaV1} StandardSchema
20
30
  */
21
31
  export class McpServer {
22
32
  #server = new JSONRPCServer();
23
33
  /**
24
- * @type {JSONRPCClient | undefined}
34
+ * @type {JSONRPCClient<Record<string, any> | undefined> | undefined}
25
35
  */
26
36
  #client;
27
37
  #options;
@@ -38,6 +48,10 @@ export class McpServer {
38
48
  */
39
49
  #resources = new Map();
40
50
  #templates = new UriTemplateMatcher();
51
+ /**
52
+ * @type {Array<{uri: string, name?: string}>}
53
+ */
54
+ roots = [];
41
55
  /**
42
56
  * @type {{ [ref: string]: Map<string, Partial<Record<string, Completion>>> }}
43
57
  */
@@ -49,24 +63,51 @@ export class McpServer {
49
63
  #event_target = new EventTarget();
50
64
 
51
65
  /**
52
- * @type {Record<SubscriptionsKeys, Set<string>>}
66
+ * @type {Record<SubscriptionsKeys, Map<string, Set<string | undefined>>>}
53
67
  */
54
68
  #subscriptions = {
55
69
  /**
56
- * @type {Set<string>}
70
+ * @type {Map<string, Set<string>>}
57
71
  */
58
- resource: new Set(),
72
+ resource: new Map(),
59
73
  };
60
74
 
75
+ /**
76
+ * @type {AsyncLocalStorage<string | undefined>}
77
+ */
78
+ #session_storage = new AsyncLocalStorage();
79
+
80
+ /**
81
+ * @type {Map<string|undefined, ClientCapabilities>}
82
+ */
83
+ #client_capabilities_map = new Map();
84
+
61
85
  /**
62
86
  * @param {ServerInfo} server_info
63
87
  * @param {ServerOptions<StandardSchema>} options
64
88
  */
65
89
  constructor(server_info, options) {
66
90
  this.#options = options;
67
- this.#server.addMethod('initialize', ({ protocolVersion }) => {
91
+ this.#server.addMethod('initialize', (initialize_request) => {
92
+ const validated_initialize = v.parse(
93
+ InitializeRequestSchema,
94
+ initialize_request,
95
+ );
96
+ this.#client_capabilities_map.set(
97
+ this.#session_id,
98
+ validated_initialize.capabilities,
99
+ );
100
+ this.#event_target.dispatchEvent(
101
+ new CustomEvent('initialize', {
102
+ detail: validated_initialize,
103
+ }),
104
+ );
105
+ // Trigger initial roots request if client supports it
106
+ if (validated_initialize.capabilities?.roots) {
107
+ this.#refresh_roots();
108
+ }
68
109
  return {
69
- protocolVersion,
110
+ protocolVersion: validated_initialize.protocolVersion,
70
111
  ...options,
71
112
  serverInfo: server_info,
72
113
  };
@@ -80,9 +121,34 @@ export class McpServer {
80
121
  this.#init_tools();
81
122
  this.#init_prompts();
82
123
  this.#init_resources();
124
+ this.#init_roots();
83
125
  this.#init_completion();
84
126
  }
85
127
 
128
+ get #session_id() {
129
+ return this.#session_storage.getStore();
130
+ }
131
+
132
+ get #client_capabilities() {
133
+ return this.#client_capabilities_map.get(this.#session_id);
134
+ }
135
+
136
+ currentClientCapabilities() {
137
+ return this.#client_capabilities;
138
+ }
139
+
140
+ #lazyily_create_client() {
141
+ if (!this.#client) {
142
+ this.#client = new JSONRPCClient((payload, context = {}) => {
143
+ this.#event_target.dispatchEvent(
144
+ new CustomEvent('send', {
145
+ detail: { request: payload, context },
146
+ }),
147
+ );
148
+ });
149
+ }
150
+ }
151
+
86
152
  /**
87
153
  * @template {keyof McpEvents} TEvent
88
154
  * @param {TEvent} event
@@ -90,12 +156,8 @@ export class McpServer {
90
156
  * @param {AddEventListenerOptions} [options]
91
157
  */
92
158
  on(event, callback, options) {
93
- if (event === 'send' && !this.#client) {
94
- this.#client = new JSONRPCClient((payload) => {
95
- this.#event_target.dispatchEvent(
96
- new CustomEvent('send', { detail: payload }),
97
- );
98
- });
159
+ if (event === 'send') {
160
+ this.#lazyily_create_client();
99
161
  }
100
162
 
101
163
  this.#event_target.addEventListener(
@@ -110,9 +172,10 @@ export class McpServer {
110
172
  /**
111
173
  * @param {string} method
112
174
  * @param {JSONRPCParams} [params]
175
+ * @param {Record<string, any>} [extra]
113
176
  */
114
- #notify(method, params) {
115
- this.#client?.notify(method, params);
177
+ #notify(method, params, extra) {
178
+ this.#client?.notify(method, params, extra);
116
179
  }
117
180
 
118
181
  /**
@@ -243,7 +306,12 @@ export class McpServer {
243
306
 
244
307
  if (this.#options.capabilities?.resources?.subscribe) {
245
308
  this.#server.addMethod('resources/subscribe', async ({ uri }) => {
246
- this.#subscriptions.resource.add(uri);
309
+ let subscriptions = this.#subscriptions.resource.get(uri);
310
+ if (!subscriptions) {
311
+ subscriptions = new Set();
312
+ this.#subscriptions.resource.set(uri, subscriptions);
313
+ }
314
+ subscriptions.add(this.#session_id);
247
315
  return {};
248
316
  });
249
317
  }
@@ -309,6 +377,37 @@ export class McpServer {
309
377
  );
310
378
  });
311
379
  }
380
+ /**
381
+ *
382
+ */
383
+ #init_roots() {
384
+ this.#server.addMethod('notifications/roots/list_changed', () => {
385
+ this.#refresh_roots();
386
+ return null;
387
+ });
388
+ }
389
+
390
+ /**
391
+ * Request roots list from client
392
+ */
393
+ async #refresh_roots() {
394
+ if (!this.#client_capabilities?.roots) return;
395
+
396
+ this.#lazyily_create_client();
397
+ try {
398
+ const response = await this.#client?.request(
399
+ 'roots/list',
400
+ undefined,
401
+ {
402
+ sessions: [this.#session_id],
403
+ },
404
+ );
405
+ this.roots = response?.roots || [];
406
+ } catch {
407
+ // Client doesn't support roots or request failed
408
+ this.roots = [];
409
+ }
410
+ }
312
411
  /**
313
412
  *
314
413
  */
@@ -407,11 +506,28 @@ export class McpServer {
407
506
  });
408
507
  }
409
508
  /**
410
- * @param {JSONRPCRequest} request
411
- * @returns {ReturnType<JSONRPCServer['receive']>}
509
+ * @param {JSONRPCResponse | JSONRPCRequest} message
510
+ * @param {string} [session_id]
511
+ * @returns {ReturnType<JSONRPCServer['receive']> | ReturnType<JSONRPCClient['receive'] | undefined>}
412
512
  */
413
- receive(request) {
414
- return this.#server.receive(request);
513
+ receive(message, session_id) {
514
+ // Validate the message first
515
+ const validated_message = v.safeParse(JSONRPCRequestSchema, message);
516
+
517
+ // Check if it's a request or response
518
+ if (validated_message.success) {
519
+ return this.#session_storage.run(
520
+ session_id,
521
+ async () =>
522
+ await this.#server.receive(validated_message.output),
523
+ );
524
+ }
525
+ // It's a response - handle with client
526
+ const validated_response = v.parse(JSONRPCResponseSchema, message);
527
+ this.#lazyily_create_client();
528
+ return this.#session_storage.run(session_id, async () =>
529
+ this.#client?.receive(validated_response),
530
+ );
415
531
  }
416
532
 
417
533
  /**
@@ -423,10 +539,82 @@ export class McpServer {
423
539
  if (this.#subscriptions[what].has(id)) {
424
540
  const resource = this.#resources.get(id);
425
541
  if (!resource) return;
426
- this.#notify(`notifications/resources/updated`, {
427
- uri: id,
428
- title: resource.name,
429
- });
542
+ const sessions = this.#subscriptions[what].get(id);
543
+ this.#notify(
544
+ `notifications/resources/updated`,
545
+ {
546
+ uri: id,
547
+ title: resource.name,
548
+ },
549
+ {
550
+ sessions: sessions ? [...sessions] : undefined,
551
+ },
552
+ );
553
+ }
554
+ }
555
+
556
+ /**
557
+ * Refresh roots list from client
558
+ */
559
+ async refreshRoots() {
560
+ await this.#refresh_roots();
561
+ }
562
+
563
+ /**
564
+ * @template {StandardSchema} TSchema
565
+ * @param {TSchema} schema
566
+ * @returns {Promise<StandardSchemaV1.InferOutput<TSchema>>}
567
+ */
568
+ async elicitation(schema) {
569
+ if (!this.#client_capabilities?.elicitation)
570
+ throw new Error("Client doesn't support elicitation");
571
+
572
+ this.#lazyily_create_client();
573
+ let validated_result = schema['~standard'].validate(
574
+ await this.#client?.request(
575
+ 'elicitation/create',
576
+ {
577
+ params: await this.#options.adapter.toJsonSchema(schema),
578
+ },
579
+ {
580
+ sessions: [this.#session_id],
581
+ },
582
+ ),
583
+ );
584
+ if (validated_result instanceof Promise)
585
+ validated_result = await validated_result;
586
+ if (validated_result.issues) {
587
+ throw new Error(
588
+ `Invalid elicitation result: ${JSON.stringify(validated_result.issues)}`,
589
+ );
430
590
  }
591
+ return validated_result.value;
592
+ }
593
+
594
+ /**
595
+ * Request language model sampling from the client
596
+ * @param {CreateMessageRequest} request
597
+ * @returns {Promise<CreateMessageResult>}
598
+ */
599
+ async message(request) {
600
+ if (!this.#client_capabilities?.sampling)
601
+ throw new Error("Client doesn't support sampling");
602
+
603
+ this.#lazyily_create_client();
604
+
605
+ // Validate the request
606
+ const validated_request = v.parse(CreateMessageRequestSchema, request);
607
+
608
+ // Make the request to the client
609
+ const response = await this.#client?.request(
610
+ 'sampling/createMessage',
611
+ validated_request,
612
+ {
613
+ sessions: [this.#session_id],
614
+ },
615
+ );
616
+
617
+ // Validate and return the response
618
+ return v.parse(CreateMessageResultSchema, response);
431
619
  }
432
620
  }
@@ -6,6 +6,7 @@ import {
6
6
  CallToolResult,
7
7
  ReadResourceResult,
8
8
  CompleteResult,
9
+ InitializeRequest,
9
10
  } from '../validation/index.js';
10
11
 
11
12
  export type Tool<TSchema extends StandardSchemaV1 = StandardSchemaV1<any>> = {
@@ -67,5 +68,11 @@ export type ServerInfo = {
67
68
  export type SubscriptionsKeys = 'resource';
68
69
 
69
70
  export type McpEvents = {
70
- send: (message: JSONRPCRequest) => void;
71
+ send: (message: {
72
+ request: JSONRPCRequest;
73
+ context: {
74
+ sessions?: string[] | undefined;
75
+ };
76
+ }) => void;
77
+ initialize: (initialize_request: InitializeRequest) => void;
71
78
  };
@@ -382,6 +382,431 @@ export const PromptMessageSchema: v.LooseObjectSchema<{
382
382
  readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
383
383
  }, undefined>], undefined>;
384
384
  }, undefined>;
385
+ /**
386
+ * A model hint for sampling requests.
387
+ */
388
+ export const ModelHintSchema: v.LooseObjectSchema<{
389
+ /**
390
+ * Optional name of the model.
391
+ */
392
+ readonly name: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
393
+ }, undefined>;
394
+ /**
395
+ * A sampling message used in sampling requests.
396
+ */
397
+ export const SamplingMessageSchema: v.LooseObjectSchema<{
398
+ readonly role: v.PicklistSchema<["user", "assistant"], undefined>;
399
+ readonly content: v.UnionSchema<[v.LooseObjectSchema<{
400
+ readonly type: v.LiteralSchema<"text", undefined>;
401
+ /**
402
+ * The text content of the message.
403
+ */
404
+ readonly text: v.StringSchema<undefined>;
405
+ /**
406
+ * See [MCP specification] for notes on _meta usage.
407
+ */
408
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
409
+ }, undefined>, v.LooseObjectSchema<{
410
+ readonly type: v.LiteralSchema<"image", undefined>;
411
+ /**
412
+ * The base64-encoded image data.
413
+ */
414
+ readonly data: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.Base64Action<string, undefined>]>;
415
+ /**
416
+ * The MIME type of the image. Different providers may support different image types.
417
+ */
418
+ readonly mimeType: v.StringSchema<undefined>;
419
+ /**
420
+ * See [MCP specification] for notes on _meta usage.
421
+ */
422
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
423
+ }, undefined>, v.LooseObjectSchema<{
424
+ readonly type: v.LiteralSchema<"audio", undefined>;
425
+ /**
426
+ * The base64-encoded audio data.
427
+ */
428
+ readonly data: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.Base64Action<string, undefined>]>;
429
+ /**
430
+ * The MIME type of the audio. Different providers may support different audio types.
431
+ */
432
+ readonly mimeType: v.StringSchema<undefined>;
433
+ /**
434
+ * See [MCP specification] for notes on _meta usage.
435
+ */
436
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
437
+ }, undefined>, v.LooseObjectSchema<{
438
+ /** Intended for programmatic or logical use, but used as a display name in past specs or fallback */
439
+ readonly name: v.StringSchema<undefined>;
440
+ readonly title: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
441
+ /**
442
+ * The URI of this resource.
443
+ */
444
+ readonly uri: v.StringSchema<undefined>;
445
+ /**
446
+ * A description of what this resource represents.
447
+ */
448
+ readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
449
+ /**
450
+ * The MIME type of this resource, if known.
451
+ */
452
+ readonly mimeType: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
453
+ readonly type: v.LiteralSchema<"resource_link", undefined>;
454
+ /**
455
+ * See [MCP specification] for notes on _meta usage.
456
+ */
457
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
458
+ }, undefined>, v.LooseObjectSchema<{
459
+ readonly type: v.LiteralSchema<"resource", undefined>;
460
+ readonly resource: v.UnionSchema<[v.LooseObjectSchema<{
461
+ /**
462
+ * The URI of this resource.
463
+ */
464
+ readonly uri: v.StringSchema<undefined>;
465
+ /**
466
+ * The MIME type of this resource, if known.
467
+ */
468
+ readonly mimeType: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
469
+ /**
470
+ * The text of the item. This must only be set if the item can actually be represented as text (not binary data).
471
+ */
472
+ readonly text: v.StringSchema<undefined>;
473
+ /**
474
+ * See [MCP specification] for notes on _meta usage.
475
+ */
476
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
477
+ }, undefined>, v.LooseObjectSchema<{
478
+ /**
479
+ * The URI of this resource.
480
+ */
481
+ readonly uri: v.StringSchema<undefined>;
482
+ /**
483
+ * The MIME type of this resource, if known.
484
+ */
485
+ readonly mimeType: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
486
+ /**
487
+ * A base64-encoded string representing the binary data of the item.
488
+ */
489
+ readonly blob: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.Base64Action<string, undefined>]>;
490
+ /**
491
+ * See [MCP specification] for notes on _meta usage.
492
+ */
493
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
494
+ }, undefined>], undefined>;
495
+ /**
496
+ * See [MCP specification] for notes on _meta usage.
497
+ */
498
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
499
+ }, undefined>], undefined>;
500
+ }, undefined>;
501
+ /**
502
+ * Model preferences for sampling requests.
503
+ */
504
+ export const ModelPreferencesSchema: v.LooseObjectSchema<{
505
+ /**
506
+ * Optional hints for which model to use, in order of preference.
507
+ */
508
+ readonly hints: v.OptionalSchema<v.ArraySchema<v.LooseObjectSchema<{
509
+ /**
510
+ * Optional name of the model.
511
+ */
512
+ readonly name: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
513
+ }, undefined>, undefined>, undefined>;
514
+ /**
515
+ * Priority for cost considerations (0-1, where 1 is highest priority).
516
+ */
517
+ readonly costPriority: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
518
+ /**
519
+ * Priority for speed considerations (0-1, where 1 is highest priority).
520
+ */
521
+ readonly speedPriority: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
522
+ /**
523
+ * Priority for intelligence considerations (0-1, where 1 is highest priority).
524
+ */
525
+ readonly intelligencePriority: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
526
+ }, undefined>;
527
+ /**
528
+ * Request for sampling/createMessage.
529
+ */
530
+ export const CreateMessageRequestSchema: v.LooseObjectSchema<{
531
+ /**
532
+ * The messages to be processed.
533
+ */
534
+ readonly messages: v.ArraySchema<v.LooseObjectSchema<{
535
+ readonly role: v.PicklistSchema<["user", "assistant"], undefined>;
536
+ readonly content: v.UnionSchema<[v.LooseObjectSchema<{
537
+ readonly type: v.LiteralSchema<"text", undefined>;
538
+ /**
539
+ * The text content of the message.
540
+ */
541
+ readonly text: v.StringSchema<undefined>;
542
+ /**
543
+ * See [MCP specification] for notes on _meta usage.
544
+ */
545
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
546
+ }, undefined>, v.LooseObjectSchema<{
547
+ readonly type: v.LiteralSchema<"image", undefined>;
548
+ /**
549
+ * The base64-encoded image data.
550
+ */
551
+ readonly data: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.Base64Action<string, undefined>]>;
552
+ /**
553
+ * The MIME type of the image. Different providers may support different image types.
554
+ */
555
+ readonly mimeType: v.StringSchema<undefined>;
556
+ /**
557
+ * See [MCP specification] for notes on _meta usage.
558
+ */
559
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
560
+ }, undefined>, v.LooseObjectSchema<{
561
+ readonly type: v.LiteralSchema<"audio", undefined>;
562
+ /**
563
+ * The base64-encoded audio data.
564
+ */
565
+ readonly data: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.Base64Action<string, undefined>]>;
566
+ /**
567
+ * The MIME type of the audio. Different providers may support different audio types.
568
+ */
569
+ readonly mimeType: v.StringSchema<undefined>;
570
+ /**
571
+ * See [MCP specification] for notes on _meta usage.
572
+ */
573
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
574
+ }, undefined>, v.LooseObjectSchema<{
575
+ /** Intended for programmatic or logical use, but used as a display name in past specs or fallback */
576
+ readonly name: v.StringSchema<undefined>;
577
+ readonly title: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
578
+ /**
579
+ * The URI of this resource.
580
+ */
581
+ readonly uri: v.StringSchema<undefined>;
582
+ /**
583
+ * A description of what this resource represents.
584
+ */
585
+ readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
586
+ /**
587
+ * The MIME type of this resource, if known.
588
+ */
589
+ readonly mimeType: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
590
+ readonly type: v.LiteralSchema<"resource_link", undefined>;
591
+ /**
592
+ * See [MCP specification] for notes on _meta usage.
593
+ */
594
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
595
+ }, undefined>, v.LooseObjectSchema<{
596
+ readonly type: v.LiteralSchema<"resource", undefined>;
597
+ readonly resource: v.UnionSchema<[v.LooseObjectSchema<{
598
+ /**
599
+ * The URI of this resource.
600
+ */
601
+ readonly uri: v.StringSchema<undefined>;
602
+ /**
603
+ * The MIME type of this resource, if known.
604
+ */
605
+ readonly mimeType: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
606
+ /**
607
+ * The text of the item. This must only be set if the item can actually be represented as text (not binary data).
608
+ */
609
+ readonly text: v.StringSchema<undefined>;
610
+ /**
611
+ * See [MCP specification] for notes on _meta usage.
612
+ */
613
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
614
+ }, undefined>, v.LooseObjectSchema<{
615
+ /**
616
+ * The URI of this resource.
617
+ */
618
+ readonly uri: v.StringSchema<undefined>;
619
+ /**
620
+ * The MIME type of this resource, if known.
621
+ */
622
+ readonly mimeType: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
623
+ /**
624
+ * A base64-encoded string representing the binary data of the item.
625
+ */
626
+ readonly blob: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.Base64Action<string, undefined>]>;
627
+ /**
628
+ * See [MCP specification] for notes on _meta usage.
629
+ */
630
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
631
+ }, undefined>], undefined>;
632
+ /**
633
+ * See [MCP specification] for notes on _meta usage.
634
+ */
635
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
636
+ }, undefined>], undefined>;
637
+ }, undefined>, undefined>;
638
+ /**
639
+ * Optional system prompt to provide context.
640
+ */
641
+ readonly systemPrompt: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
642
+ /**
643
+ * Optional context inclusion preference.
644
+ */
645
+ readonly includeContext: v.OptionalSchema<v.PicklistSchema<["none", "thisServer", "allServers"], undefined>, undefined>;
646
+ /**
647
+ * Optional temperature for generation.
648
+ */
649
+ readonly temperature: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
650
+ /**
651
+ * Maximum number of tokens to generate.
652
+ */
653
+ readonly maxTokens: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>;
654
+ /**
655
+ * Optional stop sequences.
656
+ */
657
+ readonly stopSequences: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
658
+ /**
659
+ * Optional metadata for the request.
660
+ */
661
+ readonly metadata: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
662
+ /**
663
+ * Optional model preferences for the request.
664
+ */
665
+ readonly modelPreferences: v.OptionalSchema<v.LooseObjectSchema<{
666
+ /**
667
+ * Optional hints for which model to use, in order of preference.
668
+ */
669
+ readonly hints: v.OptionalSchema<v.ArraySchema<v.LooseObjectSchema<{
670
+ /**
671
+ * Optional name of the model.
672
+ */
673
+ readonly name: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
674
+ }, undefined>, undefined>, undefined>;
675
+ /**
676
+ * Priority for cost considerations (0-1, where 1 is highest priority).
677
+ */
678
+ readonly costPriority: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
679
+ /**
680
+ * Priority for speed considerations (0-1, where 1 is highest priority).
681
+ */
682
+ readonly speedPriority: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
683
+ /**
684
+ * Priority for intelligence considerations (0-1, where 1 is highest priority).
685
+ */
686
+ readonly intelligencePriority: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
687
+ }, undefined>, undefined>;
688
+ }, undefined>;
689
+ /**
690
+ * Response for sampling/createMessage.
691
+ */
692
+ export const CreateMessageResultSchema: v.LooseObjectSchema<{
693
+ /**
694
+ * The model that generated the message.
695
+ */
696
+ readonly model: v.StringSchema<undefined>;
697
+ /**
698
+ * Optional stop reason.
699
+ */
700
+ readonly stopReason: v.OptionalSchema<v.UnionSchema<[v.LiteralSchema<"endTurn", undefined>, v.LiteralSchema<"stopSequence", undefined>, v.LiteralSchema<"maxTokens", undefined>, v.StringSchema<undefined>], undefined>, undefined>;
701
+ /**
702
+ * The role of the generated message.
703
+ */
704
+ readonly role: v.PicklistSchema<["user", "assistant"], undefined>;
705
+ /**
706
+ * The content of the generated message.
707
+ */
708
+ readonly content: v.UnionSchema<[v.LooseObjectSchema<{
709
+ readonly type: v.LiteralSchema<"text", undefined>;
710
+ /**
711
+ * The text content of the message.
712
+ */
713
+ readonly text: v.StringSchema<undefined>;
714
+ /**
715
+ * See [MCP specification] for notes on _meta usage.
716
+ */
717
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
718
+ }, undefined>, v.LooseObjectSchema<{
719
+ readonly type: v.LiteralSchema<"image", undefined>;
720
+ /**
721
+ * The base64-encoded image data.
722
+ */
723
+ readonly data: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.Base64Action<string, undefined>]>;
724
+ /**
725
+ * The MIME type of the image. Different providers may support different image types.
726
+ */
727
+ readonly mimeType: v.StringSchema<undefined>;
728
+ /**
729
+ * See [MCP specification] for notes on _meta usage.
730
+ */
731
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
732
+ }, undefined>, v.LooseObjectSchema<{
733
+ readonly type: v.LiteralSchema<"audio", undefined>;
734
+ /**
735
+ * The base64-encoded audio data.
736
+ */
737
+ readonly data: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.Base64Action<string, undefined>]>;
738
+ /**
739
+ * The MIME type of the audio. Different providers may support different audio types.
740
+ */
741
+ readonly mimeType: v.StringSchema<undefined>;
742
+ /**
743
+ * See [MCP specification] for notes on _meta usage.
744
+ */
745
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
746
+ }, undefined>, v.LooseObjectSchema<{
747
+ /** Intended for programmatic or logical use, but used as a display name in past specs or fallback */
748
+ readonly name: v.StringSchema<undefined>;
749
+ readonly title: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
750
+ /**
751
+ * The URI of this resource.
752
+ */
753
+ readonly uri: v.StringSchema<undefined>;
754
+ /**
755
+ * A description of what this resource represents.
756
+ */
757
+ readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
758
+ /**
759
+ * The MIME type of this resource, if known.
760
+ */
761
+ readonly mimeType: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
762
+ readonly type: v.LiteralSchema<"resource_link", undefined>;
763
+ /**
764
+ * See [MCP specification] for notes on _meta usage.
765
+ */
766
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
767
+ }, undefined>, v.LooseObjectSchema<{
768
+ readonly type: v.LiteralSchema<"resource", undefined>;
769
+ readonly resource: v.UnionSchema<[v.LooseObjectSchema<{
770
+ /**
771
+ * The URI of this resource.
772
+ */
773
+ readonly uri: v.StringSchema<undefined>;
774
+ /**
775
+ * The MIME type of this resource, if known.
776
+ */
777
+ readonly mimeType: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
778
+ /**
779
+ * The text of the item. This must only be set if the item can actually be represented as text (not binary data).
780
+ */
781
+ readonly text: v.StringSchema<undefined>;
782
+ /**
783
+ * See [MCP specification] for notes on _meta usage.
784
+ */
785
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
786
+ }, undefined>, v.LooseObjectSchema<{
787
+ /**
788
+ * The URI of this resource.
789
+ */
790
+ readonly uri: v.StringSchema<undefined>;
791
+ /**
792
+ * The MIME type of this resource, if known.
793
+ */
794
+ readonly mimeType: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
795
+ /**
796
+ * A base64-encoded string representing the binary data of the item.
797
+ */
798
+ readonly blob: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.Base64Action<string, undefined>]>;
799
+ /**
800
+ * See [MCP specification] for notes on _meta usage.
801
+ */
802
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
803
+ }, undefined>], undefined>;
804
+ /**
805
+ * See [MCP specification] for notes on _meta usage.
806
+ */
807
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
808
+ }, undefined>], undefined>;
809
+ }, undefined>;
385
810
  /**
386
811
  * The server's response to a tool call.
387
812
  */
@@ -675,8 +1100,112 @@ export const CompleteResultSchema: v.LooseObjectSchema<{
675
1100
  }, undefined>;
676
1101
  readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
677
1102
  }, undefined>;
1103
+ export const ClientCapabilitiesSchema: v.LooseObjectSchema<{
1104
+ readonly roots: v.OptionalSchema<v.LooseObjectSchema<{
1105
+ readonly listChanged: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
1106
+ }, undefined>, undefined>;
1107
+ readonly sampling: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
1108
+ readonly elicitation: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
1109
+ }, undefined>;
1110
+ export const InitializeRequestSchema: v.LooseObjectSchema<{
1111
+ readonly protocolVersion: v.StringSchema<undefined>;
1112
+ readonly capabilities: v.LooseObjectSchema<{
1113
+ readonly roots: v.OptionalSchema<v.LooseObjectSchema<{
1114
+ readonly listChanged: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
1115
+ }, undefined>, undefined>;
1116
+ readonly sampling: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
1117
+ readonly elicitation: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
1118
+ }, undefined>;
1119
+ }, undefined>;
1120
+ /**
1121
+ * @typedef {v.InferInput<typeof ClientCapabilitiesSchema>} ClientCapabilities
1122
+ */
1123
+ /**
1124
+ * @typedef {v.InferInput<typeof InitializeRequestSchema>} InitializeRequest
1125
+ */
1126
+ /**
1127
+ * @typedef {v.InferInput<typeof CallToolResultSchema>} CallToolResult
1128
+ */
1129
+ /**
1130
+ * @typedef {v.InferInput<typeof ReadResourceResultSchema>} ReadResourceResult
1131
+ */
1132
+ /**
1133
+ * @typedef {v.InferInput<typeof GetPromptResultSchema>} GetPromptResult
1134
+ */
1135
+ /**
1136
+ * @typedef {v.InferInput<typeof CompleteResultSchema>} CompleteResult
1137
+ */
1138
+ /**
1139
+ * @typedef {v.InferInput<typeof CreateMessageRequestSchema>} CreateMessageRequest
1140
+ */
1141
+ /**
1142
+ * @typedef {v.InferInput<typeof CreateMessageResultSchema>} CreateMessageResult
1143
+ */
1144
+ /**
1145
+ * @typedef {v.InferInput<typeof ModelPreferencesSchema>} ModelPreferences
1146
+ */
1147
+ /**
1148
+ * @typedef {v.InferInput<typeof SamplingMessageSchema>} SamplingMessage
1149
+ */
1150
+ /**
1151
+ * @typedef {v.InferInput<typeof ModelHintSchema>} ModelHint
1152
+ */
1153
+ /**
1154
+ * JSON-RPC 2.0 Request
1155
+ */
1156
+ export const JSONRPCRequestSchema: v.LooseObjectSchema<{
1157
+ readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
1158
+ readonly method: v.StringSchema<undefined>;
1159
+ readonly params: v.OptionalSchema<v.UnionSchema<[v.ArraySchema<v.UnknownSchema, undefined>, v.LooseObjectSchema<{}, undefined>], undefined>, undefined>;
1160
+ readonly id: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.NullSchema<undefined>], undefined>, undefined>;
1161
+ }, undefined>;
1162
+ /**
1163
+ * JSON-RPC 2.0 Response Success
1164
+ */
1165
+ export const JSONRPCResponseSuccessSchema: v.LooseObjectSchema<{
1166
+ readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
1167
+ readonly result: v.UnknownSchema;
1168
+ readonly id: v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.NullSchema<undefined>], undefined>;
1169
+ }, undefined>;
1170
+ /**
1171
+ * JSON-RPC 2.0 Response Error
1172
+ */
1173
+ export const JSONRPCResponseErrorSchema: v.LooseObjectSchema<{
1174
+ readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
1175
+ readonly error: v.LooseObjectSchema<{
1176
+ readonly code: v.NumberSchema<undefined>;
1177
+ readonly message: v.StringSchema<undefined>;
1178
+ readonly data: v.OptionalSchema<v.UnknownSchema, undefined>;
1179
+ }, undefined>;
1180
+ readonly id: v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.NullSchema<undefined>], undefined>;
1181
+ }, undefined>;
1182
+ /**
1183
+ * JSON-RPC 2.0 Response (Success or Error)
1184
+ */
1185
+ export const JSONRPCResponseSchema: v.UnionSchema<[v.LooseObjectSchema<{
1186
+ readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
1187
+ readonly result: v.UnknownSchema;
1188
+ readonly id: v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.NullSchema<undefined>], undefined>;
1189
+ }, undefined>, v.LooseObjectSchema<{
1190
+ readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
1191
+ readonly error: v.LooseObjectSchema<{
1192
+ readonly code: v.NumberSchema<undefined>;
1193
+ readonly message: v.StringSchema<undefined>;
1194
+ readonly data: v.OptionalSchema<v.UnknownSchema, undefined>;
1195
+ }, undefined>;
1196
+ readonly id: v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.NullSchema<undefined>], undefined>;
1197
+ }, undefined>], undefined>;
1198
+ export type ClientCapabilities = v.InferInput<typeof ClientCapabilitiesSchema>;
1199
+ export type InitializeRequest = v.InferInput<typeof InitializeRequestSchema>;
678
1200
  export type CallToolResult = v.InferInput<typeof CallToolResultSchema>;
679
1201
  export type ReadResourceResult = v.InferInput<typeof ReadResourceResultSchema>;
680
1202
  export type GetPromptResult = v.InferInput<typeof GetPromptResultSchema>;
681
1203
  export type CompleteResult = v.InferInput<typeof CompleteResultSchema>;
1204
+ export type CreateMessageRequest = v.InferInput<typeof CreateMessageRequestSchema>;
1205
+ export type CreateMessageResult = v.InferInput<typeof CreateMessageResultSchema>;
1206
+ export type ModelPreferences = v.InferInput<typeof ModelPreferencesSchema>;
1207
+ export type SamplingMessage = v.InferInput<typeof SamplingMessageSchema>;
1208
+ export type ModelHint = v.InferInput<typeof ModelHintSchema>;
1209
+ export type JSONRPCRequest = v.InferInput<typeof JSONRPCRequestSchema>;
1210
+ export type JSONRPCResponse = v.InferInput<typeof JSONRPCResponseSchema>;
682
1211
  import * as v from 'valibot';
@@ -167,6 +167,115 @@ export const PromptMessageSchema = v.looseObject({
167
167
  content: ContentBlockSchema,
168
168
  });
169
169
 
170
+ /**
171
+ * A model hint for sampling requests.
172
+ */
173
+ export const ModelHintSchema = v.looseObject({
174
+ /**
175
+ * Optional name of the model.
176
+ */
177
+ name: v.optional(v.string()),
178
+ });
179
+
180
+ /**
181
+ * A sampling message used in sampling requests.
182
+ */
183
+ export const SamplingMessageSchema = v.looseObject({
184
+ role: v.picklist(['user', 'assistant']),
185
+ content: ContentBlockSchema,
186
+ });
187
+
188
+ /**
189
+ * Model preferences for sampling requests.
190
+ */
191
+ export const ModelPreferencesSchema = v.looseObject({
192
+ /**
193
+ * Optional hints for which model to use, in order of preference.
194
+ */
195
+ hints: v.optional(v.array(ModelHintSchema)),
196
+ /**
197
+ * Priority for cost considerations (0-1, where 1 is highest priority).
198
+ */
199
+ costPriority: v.optional(v.number()),
200
+ /**
201
+ * Priority for speed considerations (0-1, where 1 is highest priority).
202
+ */
203
+ speedPriority: v.optional(v.number()),
204
+ /**
205
+ * Priority for intelligence considerations (0-1, where 1 is highest priority).
206
+ */
207
+ intelligencePriority: v.optional(v.number()),
208
+ });
209
+
210
+ /**
211
+ * Request for sampling/createMessage.
212
+ */
213
+ export const CreateMessageRequestSchema = v.looseObject({
214
+ /**
215
+ * The messages to be processed.
216
+ */
217
+ messages: v.array(SamplingMessageSchema),
218
+ /**
219
+ * Optional system prompt to provide context.
220
+ */
221
+ systemPrompt: v.optional(v.string()),
222
+ /**
223
+ * Optional context inclusion preference.
224
+ */
225
+ includeContext: v.optional(
226
+ v.picklist(['none', 'thisServer', 'allServers']),
227
+ ),
228
+ /**
229
+ * Optional temperature for generation.
230
+ */
231
+ temperature: v.optional(v.number()),
232
+ /**
233
+ * Maximum number of tokens to generate.
234
+ */
235
+ maxTokens: v.pipe(v.number(), v.integer(), v.minValue(1)),
236
+ /**
237
+ * Optional stop sequences.
238
+ */
239
+ stopSequences: v.optional(v.array(v.string())),
240
+ /**
241
+ * Optional metadata for the request.
242
+ */
243
+ metadata: v.optional(v.looseObject({})),
244
+ /**
245
+ * Optional model preferences for the request.
246
+ */
247
+ modelPreferences: v.optional(ModelPreferencesSchema),
248
+ });
249
+
250
+ /**
251
+ * Response for sampling/createMessage.
252
+ */
253
+ export const CreateMessageResultSchema = v.looseObject({
254
+ /**
255
+ * The model that generated the message.
256
+ */
257
+ model: v.string(),
258
+ /**
259
+ * Optional stop reason.
260
+ */
261
+ stopReason: v.optional(
262
+ v.union([
263
+ v.literal('endTurn'),
264
+ v.literal('stopSequence'),
265
+ v.literal('maxTokens'),
266
+ v.string(),
267
+ ]),
268
+ ),
269
+ /**
270
+ * The role of the generated message.
271
+ */
272
+ role: v.picklist(['user', 'assistant']),
273
+ /**
274
+ * The content of the generated message.
275
+ */
276
+ content: ContentBlockSchema,
277
+ });
278
+
170
279
  /**
171
280
  * The server's response to a tool call.
172
281
  */
@@ -231,6 +340,29 @@ export const CompleteResultSchema = v.looseObject({
231
340
  _meta: v.optional(v.looseObject({})),
232
341
  });
233
342
 
343
+ export const ClientCapabilitiesSchema = v.looseObject({
344
+ roots: v.optional(
345
+ v.looseObject({
346
+ listChanged: v.optional(v.boolean()),
347
+ }),
348
+ ),
349
+ sampling: v.optional(v.looseObject({})),
350
+ elicitation: v.optional(v.looseObject({})),
351
+ });
352
+
353
+ export const InitializeRequestSchema = v.looseObject({
354
+ protocolVersion: v.string(),
355
+ capabilities: ClientCapabilitiesSchema,
356
+ });
357
+
358
+ /**
359
+ * @typedef {v.InferInput<typeof ClientCapabilitiesSchema>} ClientCapabilities
360
+ */
361
+
362
+ /**
363
+ * @typedef {v.InferInput<typeof InitializeRequestSchema>} InitializeRequest
364
+ */
365
+
234
366
  /**
235
367
  * @typedef {v.InferInput<typeof CallToolResultSchema>} CallToolResult
236
368
  */
@@ -246,3 +378,71 @@ export const CompleteResultSchema = v.looseObject({
246
378
  /**
247
379
  * @typedef {v.InferInput<typeof CompleteResultSchema>} CompleteResult
248
380
  */
381
+
382
+ /**
383
+ * @typedef {v.InferInput<typeof CreateMessageRequestSchema>} CreateMessageRequest
384
+ */
385
+
386
+ /**
387
+ * @typedef {v.InferInput<typeof CreateMessageResultSchema>} CreateMessageResult
388
+ */
389
+
390
+ /**
391
+ * @typedef {v.InferInput<typeof ModelPreferencesSchema>} ModelPreferences
392
+ */
393
+
394
+ /**
395
+ * @typedef {v.InferInput<typeof SamplingMessageSchema>} SamplingMessage
396
+ */
397
+
398
+ /**
399
+ * @typedef {v.InferInput<typeof ModelHintSchema>} ModelHint
400
+ */
401
+
402
+ /**
403
+ * JSON-RPC 2.0 Request
404
+ */
405
+ export const JSONRPCRequestSchema = v.looseObject({
406
+ jsonrpc: v.literal('2.0'),
407
+ method: v.string(),
408
+ params: v.optional(v.union([v.array(v.unknown()), v.looseObject({})])),
409
+ id: v.optional(v.union([v.string(), v.number(), v.null()])),
410
+ });
411
+
412
+ /**
413
+ * JSON-RPC 2.0 Response Success
414
+ */
415
+ export const JSONRPCResponseSuccessSchema = v.looseObject({
416
+ jsonrpc: v.literal('2.0'),
417
+ result: v.unknown(),
418
+ id: v.union([v.string(), v.number(), v.null()]),
419
+ });
420
+
421
+ /**
422
+ * JSON-RPC 2.0 Response Error
423
+ */
424
+ export const JSONRPCResponseErrorSchema = v.looseObject({
425
+ jsonrpc: v.literal('2.0'),
426
+ error: v.looseObject({
427
+ code: v.number(),
428
+ message: v.string(),
429
+ data: v.optional(v.unknown()),
430
+ }),
431
+ id: v.union([v.string(), v.number(), v.null()]),
432
+ });
433
+
434
+ /**
435
+ * JSON-RPC 2.0 Response (Success or Error)
436
+ */
437
+ export const JSONRPCResponseSchema = v.union([
438
+ JSONRPCResponseSuccessSchema,
439
+ JSONRPCResponseErrorSchema,
440
+ ]);
441
+
442
+ /**
443
+ * @typedef {v.InferInput<typeof JSONRPCRequestSchema>} JSONRPCRequest
444
+ */
445
+
446
+ /**
447
+ * @typedef {v.InferInput<typeof JSONRPCResponseSchema>} JSONRPCResponse
448
+ */