tmcp 1.4.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 +1 -1
- package/src/index.d.ts +24 -3
- package/src/index.js +98 -7
- package/src/validation/index.d.ts +510 -0
- package/src/validation/index.js +177 -0
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -10,6 +10,13 @@ export class McpServer<StandardSchema extends StandardSchemaV1> {
|
|
|
10
10
|
* @param {ServerOptions<StandardSchema>} options
|
|
11
11
|
*/
|
|
12
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
|
+
}>;
|
|
13
20
|
currentClientCapabilities(): {
|
|
14
21
|
roots?: {
|
|
15
22
|
listChanged?: boolean;
|
|
@@ -75,23 +82,33 @@ export class McpServer<StandardSchema extends StandardSchemaV1> {
|
|
|
75
82
|
complete?: NoInfer<TVariables extends never ? never : Partial<Record<TVariables, Completion>>>;
|
|
76
83
|
}, execute: (uri: string, params: Record<TVariables, string | string[]>) => Promise<ReadResourceResult> | ReadResourceResult): void;
|
|
77
84
|
/**
|
|
78
|
-
* @param {JSONRPCRequest}
|
|
85
|
+
* @param {JSONRPCResponse | JSONRPCRequest} message
|
|
79
86
|
* @param {string} [session_id]
|
|
80
|
-
* @returns {ReturnType<JSONRPCServer['receive']>}
|
|
87
|
+
* @returns {ReturnType<JSONRPCServer['receive']> | ReturnType<JSONRPCClient['receive'] | undefined>}
|
|
81
88
|
*/
|
|
82
|
-
receive(
|
|
89
|
+
receive(message: JSONRPCResponse | JSONRPCRequest, session_id?: string): ReturnType<JSONRPCServer["receive"]> | ReturnType<JSONRPCClient["receive"] | undefined>;
|
|
83
90
|
/**
|
|
84
91
|
* Send a notification for subscriptions
|
|
85
92
|
* @param {SubscriptionsKeys} what
|
|
86
93
|
* @param {string} id
|
|
87
94
|
*/
|
|
88
95
|
changed(what: SubscriptionsKeys, id: string): void;
|
|
96
|
+
/**
|
|
97
|
+
* Refresh roots list from client
|
|
98
|
+
*/
|
|
99
|
+
refreshRoots(): Promise<void>;
|
|
89
100
|
/**
|
|
90
101
|
* @template {StandardSchema} TSchema
|
|
91
102
|
* @param {TSchema} schema
|
|
92
103
|
* @returns {Promise<StandardSchemaV1.InferOutput<TSchema>>}
|
|
93
104
|
*/
|
|
94
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>;
|
|
95
112
|
#private;
|
|
96
113
|
}
|
|
97
114
|
export type ClientCapabilities = ClientCapabilitiesType;
|
|
@@ -102,9 +119,13 @@ import type { Completion } from "./internal/internal.js";
|
|
|
102
119
|
import type { GetPromptResult } from "./validation/index.js";
|
|
103
120
|
import type { ReadResourceResult } from "./validation/index.js";
|
|
104
121
|
import type { ExtractURITemplateVariables } from "./internal/uri-template.js";
|
|
122
|
+
import type { JSONRPCResponse } from "./validation/index.js";
|
|
105
123
|
import type { JSONRPCRequest } from "json-rpc-2.0";
|
|
106
124
|
import { JSONRPCServer } from 'json-rpc-2.0';
|
|
125
|
+
import { JSONRPCClient } from 'json-rpc-2.0';
|
|
107
126
|
import type { SubscriptionsKeys } from "./internal/internal.js";
|
|
127
|
+
import type { CreateMessageRequest } from "./validation/index.js";
|
|
128
|
+
import type { CreateMessageResult } from "./validation/index.js";
|
|
108
129
|
import type { ServerInfo } from "./internal/internal.js";
|
|
109
130
|
import type { ServerOptions } from "./internal/internal.js";
|
|
110
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, ClientCapabilities as ClientCapabilitiesType } 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';
|
|
@@ -13,6 +13,10 @@ import {
|
|
|
13
13
|
GetPromptResultSchema,
|
|
14
14
|
CompleteResultSchema,
|
|
15
15
|
InitializeRequestSchema,
|
|
16
|
+
JSONRPCRequestSchema,
|
|
17
|
+
JSONRPCResponseSchema,
|
|
18
|
+
CreateMessageRequestSchema,
|
|
19
|
+
CreateMessageResultSchema,
|
|
16
20
|
} from './validation/index.js';
|
|
17
21
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
18
22
|
import * as v from 'valibot';
|
|
@@ -44,6 +48,10 @@ export class McpServer {
|
|
|
44
48
|
*/
|
|
45
49
|
#resources = new Map();
|
|
46
50
|
#templates = new UriTemplateMatcher();
|
|
51
|
+
/**
|
|
52
|
+
* @type {Array<{uri: string, name?: string}>}
|
|
53
|
+
*/
|
|
54
|
+
roots = [];
|
|
47
55
|
/**
|
|
48
56
|
* @type {{ [ref: string]: Map<string, Partial<Record<string, Completion>>> }}
|
|
49
57
|
*/
|
|
@@ -94,6 +102,10 @@ export class McpServer {
|
|
|
94
102
|
detail: validated_initialize,
|
|
95
103
|
}),
|
|
96
104
|
);
|
|
105
|
+
// Trigger initial roots request if client supports it
|
|
106
|
+
if (validated_initialize.capabilities?.roots) {
|
|
107
|
+
this.#refresh_roots();
|
|
108
|
+
}
|
|
97
109
|
return {
|
|
98
110
|
protocolVersion: validated_initialize.protocolVersion,
|
|
99
111
|
...options,
|
|
@@ -109,6 +121,7 @@ export class McpServer {
|
|
|
109
121
|
this.#init_tools();
|
|
110
122
|
this.#init_prompts();
|
|
111
123
|
this.#init_resources();
|
|
124
|
+
this.#init_roots();
|
|
112
125
|
this.#init_completion();
|
|
113
126
|
}
|
|
114
127
|
|
|
@@ -364,6 +377,37 @@ export class McpServer {
|
|
|
364
377
|
);
|
|
365
378
|
});
|
|
366
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
|
+
}
|
|
367
411
|
/**
|
|
368
412
|
*
|
|
369
413
|
*/
|
|
@@ -462,14 +506,27 @@ export class McpServer {
|
|
|
462
506
|
});
|
|
463
507
|
}
|
|
464
508
|
/**
|
|
465
|
-
* @param {JSONRPCRequest}
|
|
509
|
+
* @param {JSONRPCResponse | JSONRPCRequest} message
|
|
466
510
|
* @param {string} [session_id]
|
|
467
|
-
* @returns {ReturnType<JSONRPCServer['receive']>}
|
|
511
|
+
* @returns {ReturnType<JSONRPCServer['receive']> | ReturnType<JSONRPCClient['receive'] | undefined>}
|
|
468
512
|
*/
|
|
469
|
-
receive(
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
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),
|
|
473
530
|
);
|
|
474
531
|
}
|
|
475
532
|
|
|
@@ -496,6 +553,13 @@ export class McpServer {
|
|
|
496
553
|
}
|
|
497
554
|
}
|
|
498
555
|
|
|
556
|
+
/**
|
|
557
|
+
* Refresh roots list from client
|
|
558
|
+
*/
|
|
559
|
+
async refreshRoots() {
|
|
560
|
+
await this.#refresh_roots();
|
|
561
|
+
}
|
|
562
|
+
|
|
499
563
|
/**
|
|
500
564
|
* @template {StandardSchema} TSchema
|
|
501
565
|
* @param {TSchema} schema
|
|
@@ -526,4 +590,31 @@ export class McpServer {
|
|
|
526
590
|
}
|
|
527
591
|
return validated_result.value;
|
|
528
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);
|
|
619
|
+
}
|
|
529
620
|
}
|
|
@@ -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
|
*/
|
|
@@ -692,10 +1117,95 @@ export const InitializeRequestSchema: v.LooseObjectSchema<{
|
|
|
692
1117
|
readonly elicitation: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
|
|
693
1118
|
}, undefined>;
|
|
694
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>;
|
|
695
1198
|
export type ClientCapabilities = v.InferInput<typeof ClientCapabilitiesSchema>;
|
|
696
1199
|
export type InitializeRequest = v.InferInput<typeof InitializeRequestSchema>;
|
|
697
1200
|
export type CallToolResult = v.InferInput<typeof CallToolResultSchema>;
|
|
698
1201
|
export type ReadResourceResult = v.InferInput<typeof ReadResourceResultSchema>;
|
|
699
1202
|
export type GetPromptResult = v.InferInput<typeof GetPromptResultSchema>;
|
|
700
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>;
|
|
701
1211
|
import * as v from 'valibot';
|
package/src/validation/index.js
CHANGED
|
@@ -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
|
*/
|
|
@@ -269,3 +378,71 @@ export const InitializeRequestSchema = v.looseObject({
|
|
|
269
378
|
/**
|
|
270
379
|
* @typedef {v.InferInput<typeof CompleteResultSchema>} CompleteResult
|
|
271
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
|
+
*/
|