Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/mcp/common/modelContextProtocol.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
/* eslint-disable local/code-no-unexternalized-strings */
7
8
//#region proposals
9
/**
10
* MCP protocol proposals.
11
* - Proposals here MUST have an MCP PR linked to them
12
* - Proposals here are subject to change and SHALL be removed when
13
* the upstream MCP PR is merged or closed.
14
*/
15
export namespace MCP {
16
17
// Nothing, yet
18
19
}
20
21
//#endregion
22
23
/**
24
* Schema updated from the Model Context Protocol repository at
25
* https://github.com/modelcontextprotocol/specification/tree/main/schema
26
*
27
* ⚠️ Do not edit within `namespace` manually except to update schema versions ⚠️
28
*/
29
export namespace MCP {
30
/**
31
* Refers to any valid JSON-RPC object that can be decoded off the wire, or encoded to be sent.
32
*/
33
export type JSONRPCMessage =
34
| JSONRPCRequest
35
| JSONRPCNotification
36
| JSONRPCResponse
37
| JSONRPCError;
38
39
export const LATEST_PROTOCOL_VERSION = "2025-06-18";
40
export const JSONRPC_VERSION = "2.0";
41
42
/**
43
* A progress token, used to associate progress notifications with the original request.
44
*/
45
export type ProgressToken = string | number;
46
47
/**
48
* An opaque token used to represent a cursor for pagination.
49
*/
50
export type Cursor = string;
51
52
export interface Request {
53
method: string;
54
params?: {
55
/**
56
* See [specification/2025-06-18/basic/index#general-fields] for notes on _meta usage.
57
*/
58
_meta?: {
59
/**
60
* 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.
61
*/
62
progressToken?: ProgressToken;
63
[key: string]: unknown;
64
};
65
[key: string]: unknown;
66
};
67
}
68
69
export interface Notification {
70
method: string;
71
params?: {
72
/**
73
* See [specification/2025-06-18/basic/index#general-fields] for notes on _meta usage.
74
*/
75
_meta?: { [key: string]: unknown };
76
[key: string]: unknown;
77
};
78
}
79
80
export interface Result {
81
/**
82
* See [specification/2025-06-18/basic/index#general-fields] for notes on _meta usage.
83
*/
84
_meta?: { [key: string]: unknown };
85
[key: string]: unknown;
86
}
87
88
/**
89
* A uniquely identifying ID for a request in JSON-RPC.
90
*/
91
export type RequestId = string | number;
92
93
/**
94
* A request that expects a response.
95
*/
96
export interface JSONRPCRequest extends Request {
97
jsonrpc: typeof JSONRPC_VERSION;
98
id: RequestId;
99
}
100
101
/**
102
* A notification which does not expect a response.
103
*/
104
export interface JSONRPCNotification extends Notification {
105
jsonrpc: typeof JSONRPC_VERSION;
106
}
107
108
/**
109
* A successful (non-error) response to a request.
110
*/
111
export interface JSONRPCResponse {
112
jsonrpc: typeof JSONRPC_VERSION;
113
id: RequestId;
114
result: Result;
115
}
116
117
// Standard JSON-RPC error codes
118
export const PARSE_ERROR = -32700;
119
export const INVALID_REQUEST = -32600;
120
export const METHOD_NOT_FOUND = -32601;
121
export const INVALID_PARAMS = -32602;
122
export const INTERNAL_ERROR = -32603;
123
124
/**
125
* A response to a request that indicates an error occurred.
126
*/
127
export interface JSONRPCError {
128
jsonrpc: typeof JSONRPC_VERSION;
129
id: RequestId;
130
error: {
131
/**
132
* The error type that occurred.
133
*/
134
code: number;
135
/**
136
* A short description of the error. The message SHOULD be limited to a concise single sentence.
137
*/
138
message: string;
139
/**
140
* Additional information about the error. The value of this member is defined by the sender (e.g. detailed error information, nested errors etc.).
141
*/
142
data?: unknown;
143
};
144
}
145
146
/* Empty result */
147
/**
148
* A response that indicates success but carries no data.
149
*/
150
export type EmptyResult = Result;
151
152
/* Cancellation */
153
/**
154
* This notification can be sent by either side to indicate that it is cancelling a previously-issued request.
155
*
156
* 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.
157
*
158
* This notification indicates that the result will be unused, so any associated processing SHOULD cease.
159
*
160
* A client MUST NOT attempt to cancel its `initialize` request.
161
*/
162
export interface CancelledNotification extends Notification {
163
method: "notifications/cancelled";
164
params: {
165
/**
166
* The ID of the request to cancel.
167
*
168
* This MUST correspond to the ID of a request previously issued in the same direction.
169
*/
170
requestId: RequestId;
171
172
/**
173
* An optional string describing the reason for the cancellation. This MAY be logged or presented to the user.
174
*/
175
reason?: string;
176
};
177
}
178
179
/* Initialization */
180
/**
181
* This request is sent from the client to the server when it first connects, asking it to begin initialization.
182
*/
183
export interface InitializeRequest extends Request {
184
method: "initialize";
185
params: {
186
/**
187
* The latest version of the Model Context Protocol that the client supports. The client MAY decide to support older versions as well.
188
*/
189
protocolVersion: string;
190
capabilities: ClientCapabilities;
191
clientInfo: Implementation;
192
};
193
}
194
195
/**
196
* After receiving an initialize request from the client, the server sends this response.
197
*/
198
export interface InitializeResult extends Result {
199
/**
200
* 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.
201
*/
202
protocolVersion: string;
203
capabilities: ServerCapabilities;
204
serverInfo: Implementation;
205
206
/**
207
* Instructions describing how to use the server and its features.
208
*
209
* 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.
210
*/
211
instructions?: string;
212
}
213
214
/**
215
* This notification is sent from the client to the server after initialization has finished.
216
*/
217
export interface InitializedNotification extends Notification {
218
method: "notifications/initialized";
219
}
220
221
/**
222
* 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.
223
*/
224
export interface ClientCapabilities {
225
/**
226
* Experimental, non-standard capabilities that the client supports.
227
*/
228
experimental?: { [key: string]: object };
229
/**
230
* Present if the client supports listing roots.
231
*/
232
roots?: {
233
/**
234
* Whether the client supports notifications for changes to the roots list.
235
*/
236
listChanged?: boolean;
237
};
238
/**
239
* Present if the client supports sampling from an LLM.
240
*/
241
sampling?: object;
242
/**
243
* Present if the client supports elicitation from the server.
244
*/
245
elicitation?: object;
246
}
247
248
/**
249
* 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.
250
*/
251
export interface ServerCapabilities {
252
/**
253
* Experimental, non-standard capabilities that the server supports.
254
*/
255
experimental?: { [key: string]: object };
256
/**
257
* Present if the server supports sending log messages to the client.
258
*/
259
logging?: object;
260
/**
261
* Present if the server supports argument autocompletion suggestions.
262
*/
263
completions?: object;
264
/**
265
* Present if the server offers any prompt templates.
266
*/
267
prompts?: {
268
/**
269
* Whether this server supports notifications for changes to the prompt list.
270
*/
271
listChanged?: boolean;
272
};
273
/**
274
* Present if the server offers any resources to read.
275
*/
276
resources?: {
277
/**
278
* Whether this server supports subscribing to resource updates.
279
*/
280
subscribe?: boolean;
281
/**
282
* Whether this server supports notifications for changes to the resource list.
283
*/
284
listChanged?: boolean;
285
};
286
/**
287
* Present if the server offers any tools to call.
288
*/
289
tools?: {
290
/**
291
* Whether this server supports notifications for changes to the tool list.
292
*/
293
listChanged?: boolean;
294
};
295
}
296
297
/**
298
* Base interface for metadata with name (identifier) and title (display name) properties.
299
*/
300
export interface BaseMetadata {
301
/**
302
* Intended for programmatic or logical use, but used as a display name in past specs or fallback (if title isn't present).
303
*/
304
name: string;
305
306
/**
307
* Intended for UI and end-user contexts - optimized to be human-readable and easily understood,
308
* even by those unfamiliar with domain-specific terminology.
309
*
310
* If not provided, the name should be used for display (except for Tool,
311
* where `annotations.title` should be given precedence over using `name`,
312
* if present).
313
*/
314
title?: string;
315
}
316
317
/**
318
* Describes the name and version of an MCP implementation, with an optional title for UI representation.
319
*/
320
export interface Implementation extends BaseMetadata {
321
version: string;
322
}
323
324
/* Ping */
325
/**
326
* 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.
327
*/
328
export interface PingRequest extends Request {
329
method: "ping";
330
}
331
332
/* Progress notifications */
333
/**
334
* An out-of-band notification used to inform the receiver of a progress update for a long-running request.
335
*/
336
export interface ProgressNotification extends Notification {
337
method: "notifications/progress";
338
params: {
339
/**
340
* The progress token which was given in the initial request, used to associate this notification with the request that is proceeding.
341
*/
342
progressToken: ProgressToken;
343
/**
344
* The progress thus far. This should increase every time progress is made, even if the total is unknown.
345
*
346
* @TJS-type number
347
*/
348
progress: number;
349
/**
350
* Total number of items to process (or total progress required), if known.
351
*
352
* @TJS-type number
353
*/
354
total?: number;
355
/**
356
* An optional message describing the current progress.
357
*/
358
message?: string;
359
};
360
}
361
362
/* Pagination */
363
export interface PaginatedRequest extends Request {
364
params?: {
365
/**
366
* An opaque token representing the current pagination position.
367
* If provided, the server should return results starting after this cursor.
368
*/
369
cursor?: Cursor;
370
};
371
}
372
373
export interface PaginatedResult extends Result {
374
/**
375
* An opaque token representing the pagination position after the last returned result.
376
* If present, there may be more results available.
377
*/
378
nextCursor?: Cursor;
379
}
380
381
/* Resources */
382
/**
383
* Sent from the client to request a list of resources the server has.
384
*/
385
export interface ListResourcesRequest extends PaginatedRequest {
386
method: "resources/list";
387
}
388
389
/**
390
* The server's response to a resources/list request from the client.
391
*/
392
export interface ListResourcesResult extends PaginatedResult {
393
resources: Resource[];
394
}
395
396
/**
397
* Sent from the client to request a list of resource templates the server has.
398
*/
399
export interface ListResourceTemplatesRequest extends PaginatedRequest {
400
method: "resources/templates/list";
401
}
402
403
/**
404
* The server's response to a resources/templates/list request from the client.
405
*/
406
export interface ListResourceTemplatesResult extends PaginatedResult {
407
resourceTemplates: ResourceTemplate[];
408
}
409
410
/**
411
* Sent from the client to the server, to read a specific resource URI.
412
*/
413
export interface ReadResourceRequest extends Request {
414
method: "resources/read";
415
params: {
416
/**
417
* The URI of the resource to read. The URI can use any protocol; it is up to the server how to interpret it.
418
*
419
* @format uri
420
*/
421
uri: string;
422
};
423
}
424
425
/**
426
* The server's response to a resources/read request from the client.
427
*/
428
export interface ReadResourceResult extends Result {
429
contents: (TextResourceContents | BlobResourceContents)[];
430
}
431
432
/**
433
* 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.
434
*/
435
export interface ResourceListChangedNotification extends Notification {
436
method: "notifications/resources/list_changed";
437
}
438
439
/**
440
* Sent from the client to request resources/updated notifications from the server whenever a particular resource changes.
441
*/
442
export interface SubscribeRequest extends Request {
443
method: "resources/subscribe";
444
params: {
445
/**
446
* The URI of the resource to subscribe to. The URI can use any protocol; it is up to the server how to interpret it.
447
*
448
* @format uri
449
*/
450
uri: string;
451
};
452
}
453
454
/**
455
* Sent from the client to request cancellation of resources/updated notifications from the server. This should follow a previous resources/subscribe request.
456
*/
457
export interface UnsubscribeRequest extends Request {
458
method: "resources/unsubscribe";
459
params: {
460
/**
461
* The URI of the resource to unsubscribe from.
462
*
463
* @format uri
464
*/
465
uri: string;
466
};
467
}
468
469
/**
470
* 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.
471
*/
472
export interface ResourceUpdatedNotification extends Notification {
473
method: "notifications/resources/updated";
474
params: {
475
/**
476
* The URI of the resource that has been updated. This might be a sub-resource of the one that the client actually subscribed to.
477
*
478
* @format uri
479
*/
480
uri: string;
481
};
482
}
483
484
/**
485
* A known resource that the server is capable of reading.
486
*/
487
export interface Resource extends BaseMetadata {
488
/**
489
* The URI of this resource.
490
*
491
* @format uri
492
*/
493
uri: string;
494
495
/**
496
* A description of what this resource represents.
497
*
498
* 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.
499
*/
500
description?: string;
501
502
/**
503
* The MIME type of this resource, if known.
504
*/
505
mimeType?: string;
506
507
/**
508
* Optional annotations for the client.
509
*/
510
annotations?: Annotations;
511
512
/**
513
* The size of the raw resource content, in bytes (i.e., before base64 encoding or any tokenization), if known.
514
*
515
* This can be used by Hosts to display file sizes and estimate context window usage.
516
*/
517
size?: number;
518
519
/**
520
* See [specification/2025-06-18/basic/index#general-fields] for notes on _meta usage.
521
*/
522
_meta?: { [key: string]: unknown };
523
}
524
525
/**
526
* A template description for resources available on the server.
527
*/
528
export interface ResourceTemplate extends BaseMetadata {
529
/**
530
* A URI template (according to RFC 6570) that can be used to construct resource URIs.
531
*
532
* @format uri-template
533
*/
534
uriTemplate: string;
535
536
/**
537
* A description of what this template is for.
538
*
539
* 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.
540
*/
541
description?: string;
542
543
/**
544
* 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.
545
*/
546
mimeType?: string;
547
548
/**
549
* Optional annotations for the client.
550
*/
551
annotations?: Annotations;
552
553
/**
554
* See [specification/2025-06-18/basic/index#general-fields] for notes on _meta usage.
555
*/
556
_meta?: { [key: string]: unknown };
557
}
558
559
/**
560
* The contents of a specific resource or sub-resource.
561
*/
562
export interface ResourceContents {
563
/**
564
* The URI of this resource.
565
*
566
* @format uri
567
*/
568
uri: string;
569
/**
570
* The MIME type of this resource, if known.
571
*/
572
mimeType?: string;
573
574
/**
575
* See [specification/2025-06-18/basic/index#general-fields] for notes on _meta usage.
576
*/
577
_meta?: { [key: string]: unknown };
578
}
579
580
export interface TextResourceContents extends ResourceContents {
581
/**
582
* The text of the item. This must only be set if the item can actually be represented as text (not binary data).
583
*/
584
text: string;
585
}
586
587
export interface BlobResourceContents extends ResourceContents {
588
/**
589
* A base64-encoded string representing the binary data of the item.
590
*
591
* @format byte
592
*/
593
blob: string;
594
}
595
596
/* Prompts */
597
/**
598
* Sent from the client to request a list of prompts and prompt templates the server has.
599
*/
600
export interface ListPromptsRequest extends PaginatedRequest {
601
method: "prompts/list";
602
}
603
604
/**
605
* The server's response to a prompts/list request from the client.
606
*/
607
export interface ListPromptsResult extends PaginatedResult {
608
prompts: Prompt[];
609
}
610
611
/**
612
* Used by the client to get a prompt provided by the server.
613
*/
614
export interface GetPromptRequest extends Request {
615
method: "prompts/get";
616
params: {
617
/**
618
* The name of the prompt or prompt template.
619
*/
620
name: string;
621
/**
622
* Arguments to use for templating the prompt.
623
*/
624
arguments?: { [key: string]: string };
625
};
626
}
627
628
/**
629
* The server's response to a prompts/get request from the client.
630
*/
631
export interface GetPromptResult extends Result {
632
/**
633
* An optional description for the prompt.
634
*/
635
description?: string;
636
messages: PromptMessage[];
637
}
638
639
/**
640
* A prompt or prompt template that the server offers.
641
*/
642
export interface Prompt extends BaseMetadata {
643
/**
644
* An optional description of what this prompt provides
645
*/
646
description?: string;
647
/**
648
* A list of arguments to use for templating the prompt.
649
*/
650
arguments?: PromptArgument[];
651
652
/**
653
* See [specification/2025-06-18/basic/index#general-fields] for notes on _meta usage.
654
*/
655
_meta?: { [key: string]: unknown };
656
}
657
658
/**
659
* Describes an argument that a prompt can accept.
660
*/
661
export interface PromptArgument extends BaseMetadata {
662
/**
663
* A human-readable description of the argument.
664
*/
665
description?: string;
666
/**
667
* Whether this argument must be provided.
668
*/
669
required?: boolean;
670
}
671
672
/**
673
* The sender or recipient of messages and data in a conversation.
674
*/
675
export type Role = "user" | "assistant";
676
677
/**
678
* Describes a message returned as part of a prompt.
679
*
680
* This is similar to ` */
681
export interface PromptMessage {
682
role: Role;
683
content: ContentBlock;
684
}
685
686
/**
687
* A resource that the server is capable of reading, included in a prompt or tool call result.
688
*
689
* Note: resource links returned by tools are not guaranteed to appear in the results of `resources/list` requests.
690
*/
691
export interface ResourceLink extends Resource {
692
type: "resource_link";
693
}
694
695
/**
696
* The contents of a resource, embedded into a prompt or tool call result.
697
*
698
* It is up to the client how best to render embedded resources for the benefit
699
* of the LLM and/or the user.
700
*/
701
export interface EmbeddedResource {
702
type: "resource";
703
resource: TextResourceContents | BlobResourceContents;
704
705
/**
706
* Optional annotations for the client.
707
*/
708
annotations?: Annotations;
709
710
/**
711
* See [specification/2025-06-18/basic/index#general-fields] for notes on _meta usage.
712
*/
713
_meta?: { [key: string]: unknown };
714
}
715
/**
716
* 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.
717
*/
718
export interface PromptListChangedNotification extends Notification {
719
method: "notifications/prompts/list_changed";
720
}
721
722
/* Tools */
723
/**
724
* Sent from the client to request a list of tools the server has.
725
*/
726
export interface ListToolsRequest extends PaginatedRequest {
727
method: "tools/list";
728
}
729
730
/**
731
* The server's response to a tools/list request from the client.
732
*/
733
export interface ListToolsResult extends PaginatedResult {
734
tools: Tool[];
735
}
736
737
/**
738
* The server's response to a tool call.
739
*/
740
export interface CallToolResult extends Result {
741
/**
742
* A list of content objects that represent the unstructured result of the tool call.
743
*/
744
content: ContentBlock[];
745
746
/**
747
* An optional JSON object that represents the structured result of the tool call.
748
*/
749
structuredContent?: { [key: string]: unknown };
750
751
/**
752
* Whether the tool call ended in an error.
753
*
754
* If not set, this is assumed to be false (the call was successful).
755
*
756
* Any errors that originate from the tool SHOULD be reported inside the result
757
* object, with `isError` set to true, _not_ as an MCP protocol-level error
758
* response. Otherwise, the LLM would not be able to see that an error occurred
759
* and self-correct.
760
*
761
* However, any errors in _finding_ the tool, an error indicating that the
762
* server does not support tool calls, or any other exceptional conditions,
763
* should be reported as an MCP error response.
764
*/
765
isError?: boolean;
766
}
767
768
/**
769
* Used by the client to invoke a tool provided by the server.
770
*/
771
export interface CallToolRequest extends Request {
772
method: "tools/call";
773
params: {
774
name: string;
775
arguments?: { [key: string]: unknown };
776
};
777
}
778
779
/**
780
* 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.
781
*/
782
export interface ToolListChangedNotification extends Notification {
783
method: "notifications/tools/list_changed";
784
}
785
786
/**
787
* Additional properties describing a Tool to clients.
788
*
789
* NOTE: all properties in ToolAnnotations are **hints**.
790
* They are not guaranteed to provide a faithful description of
791
* tool behavior (including descriptive properties like `title`).
792
*
793
* Clients should never make tool use decisions based on ToolAnnotations
794
* received from untrusted servers.
795
*/
796
export interface ToolAnnotations {
797
/**
798
* A human-readable title for the tool.
799
*/
800
title?: string;
801
802
/**
803
* If true, the tool does not modify its environment.
804
*
805
* Default: false
806
*/
807
readOnlyHint?: boolean;
808
809
/**
810
* If true, the tool may perform destructive updates to its environment.
811
* If false, the tool performs only additive updates.
812
*
813
* (This property is meaningful only when `readOnlyHint == false`)
814
*
815
* Default: true
816
*/
817
destructiveHint?: boolean;
818
819
/**
820
* If true, calling the tool repeatedly with the same arguments
821
* will have no additional effect on the its environment.
822
*
823
* (This property is meaningful only when `readOnlyHint == false`)
824
*
825
* Default: false
826
*/
827
idempotentHint?: boolean;
828
829
/**
830
* If true, this tool may interact with an "open world" of external
831
* entities. If false, the tool's domain of interaction is closed.
832
* For example, the world of a web search tool is open, whereas that
833
* of a memory tool is not.
834
*
835
* Default: true
836
*/
837
openWorldHint?: boolean;
838
}
839
840
/**
841
* Definition for a tool the client can call.
842
*/
843
export interface Tool extends BaseMetadata {
844
/**
845
* A human-readable description of the tool.
846
*
847
* This can be used by clients to improve the LLM's understanding of available tools. It can be thought of like a "hint" to the model.
848
*/
849
description?: string;
850
851
/**
852
* A JSON Schema object defining the expected parameters for the tool.
853
*/
854
inputSchema: {
855
type: "object";
856
properties?: { [key: string]: object };
857
required?: string[];
858
};
859
860
/**
861
* An optional JSON Schema object defining the structure of the tool's output returned in
862
* the structuredContent field of a CallToolResult.
863
*/
864
outputSchema?: {
865
type: "object";
866
properties?: { [key: string]: object };
867
required?: string[];
868
};
869
870
/**
871
* Optional additional tool information.
872
*
873
* Display name precedence order is: title, annotations.title, then name.
874
*/
875
annotations?: ToolAnnotations;
876
877
/**
878
* See [specification/2025-06-18/basic/index#general-fields] for notes on _meta usage.
879
*/
880
_meta?: { [key: string]: unknown };
881
}
882
883
/* Logging */
884
/**
885
* A request from the client to the server, to enable or adjust logging.
886
*/
887
export interface SetLevelRequest extends Request {
888
method: "logging/setLevel";
889
params: {
890
/**
891
* 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/message.
892
*/
893
level: LoggingLevel;
894
};
895
}
896
897
/**
898
* 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.
899
*/
900
export interface LoggingMessageNotification extends Notification {
901
method: "notifications/message";
902
params: {
903
/**
904
* The severity of this log message.
905
*/
906
level: LoggingLevel;
907
/**
908
* An optional name of the logger issuing this message.
909
*/
910
logger?: string;
911
/**
912
* The data to be logged, such as a string message or an object. Any JSON serializable type is allowed here.
913
*/
914
data: unknown;
915
};
916
}
917
918
/**
919
* The severity of a log message.
920
*
921
* These map to syslog message severities, as specified in RFC-5424:
922
* https://datatracker.ietf.org/doc/html/rfc5424#section-6.2.1
923
*/
924
export type LoggingLevel =
925
| "debug"
926
| "info"
927
| "notice"
928
| "warning"
929
| "error"
930
| "critical"
931
| "alert"
932
| "emergency";
933
934
/* Sampling */
935
/**
936
* 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.
937
*/
938
export interface CreateMessageRequest extends Request {
939
method: "sampling/createMessage";
940
params: {
941
messages: SamplingMessage[];
942
/**
943
* The server's preferences for which model to select. The client MAY ignore these preferences.
944
*/
945
modelPreferences?: ModelPreferences;
946
/**
947
* An optional system prompt the server wants to use for sampling. The client MAY modify or omit this prompt.
948
*/
949
systemPrompt?: string;
950
/**
951
* A request to include context from one or more MCP servers (including the caller), to be attached to the prompt. The client MAY ignore this request.
952
*/
953
includeContext?: "none" | "thisServer" | "allServers";
954
/**
955
* @TJS-type number
956
*/
957
temperature?: number;
958
/**
959
* The maximum number of tokens to sample, as requested by the server. The client MAY choose to sample fewer tokens than requested.
960
*/
961
maxTokens: number;
962
stopSequences?: string[];
963
/**
964
* Optional metadata to pass through to the LLM provider. The format of this metadata is provider-specific.
965
*/
966
metadata?: object;
967
};
968
}
969
970
/**
971
* The client's response to a sampling/create_message request from the server. The client should inform the user before returning the sampled message, to allow them to inspect the response (human in the loop) and decide whether to allow the server to see it.
972
*/
973
export interface CreateMessageResult extends Result, SamplingMessage {
974
/**
975
* The name of the model that generated the message.
976
*/
977
model: string;
978
/**
979
* The reason why sampling stopped, if known.
980
*/
981
stopReason?: "endTurn" | "stopSequence" | "maxTokens" | string;
982
}
983
984
/**
985
* Describes a message issued to or received from an LLM API.
986
*/
987
export interface SamplingMessage {
988
role: Role;
989
content: TextContent | ImageContent | AudioContent;
990
}
991
992
/**
993
* Optional annotations for the client. The client can use annotations to inform how objects are used or displayed
994
*/
995
export interface Annotations {
996
/**
997
* Describes who the intended customer of this object or data is.
998
*
999
* It can include multiple entries to indicate content useful for multiple audiences (e.g., `["user", "assistant"]`).
1000
*/
1001
audience?: Role[];
1002
1003
/**
1004
* Describes how important this data is for operating the server.
1005
*
1006
* A value of 1 means "most important," and indicates that the data is
1007
* effectively required, while 0 means "least important," and indicates that
1008
* the data is entirely optional.
1009
*
1010
* @TJS-type number
1011
* @minimum 0
1012
* @maximum 1
1013
*/
1014
priority?: number;
1015
1016
/**
1017
* The moment the resource was last modified, as an ISO 8601 formatted string.
1018
*
1019
* Should be an ISO 8601 formatted string (e.g., "2025-01-12T15:00:58Z").
1020
*
1021
* Examples: last activity timestamp in an open file, timestamp when the resource
1022
* was attached, etc.
1023
*/
1024
lastModified?: string;
1025
}
1026
1027
/** */
1028
export type ContentBlock =
1029
| TextContent
1030
| ImageContent
1031
| AudioContent
1032
| ResourceLink
1033
| EmbeddedResource;
1034
1035
/**
1036
* Text provided to or from an LLM.
1037
*/
1038
export interface TextContent {
1039
type: "text";
1040
1041
/**
1042
* The text content of the message.
1043
*/
1044
text: string;
1045
1046
/**
1047
* Optional annotations for the client.
1048
*/
1049
annotations?: Annotations;
1050
1051
/**
1052
* See [specification/2025-06-18/basic/index#general-fields] for notes on _meta usage.
1053
*/
1054
_meta?: { [key: string]: unknown };
1055
}
1056
1057
/**
1058
* An image provided to or from an LLM.
1059
*/
1060
export interface ImageContent {
1061
type: "image";
1062
1063
/**
1064
* The base64-encoded image data.
1065
*
1066
* @format byte
1067
*/
1068
data: string;
1069
1070
/**
1071
* The MIME type of the image. Different providers may support different image types.
1072
*/
1073
mimeType: string;
1074
1075
/**
1076
* Optional annotations for the client.
1077
*/
1078
annotations?: Annotations;
1079
1080
/**
1081
* See [specification/2025-06-18/basic/index#general-fields] for notes on _meta usage.
1082
*/
1083
_meta?: { [key: string]: unknown };
1084
}
1085
1086
/**
1087
* Audio provided to or from an LLM.
1088
*/
1089
export interface AudioContent {
1090
type: "audio";
1091
1092
/**
1093
* The base64-encoded audio data.
1094
*
1095
* @format byte
1096
*/
1097
data: string;
1098
1099
/**
1100
* The MIME type of the audio. Different providers may support different audio types.
1101
*/
1102
mimeType: string;
1103
1104
/**
1105
* Optional annotations for the client.
1106
*/
1107
annotations?: Annotations;
1108
1109
/**
1110
* See [specification/2025-06-18/basic/index#general-fields] for notes on _meta usage.
1111
*/
1112
_meta?: { [key: string]: unknown };
1113
}
1114
1115
/**
1116
* The server's preferences for model selection, requested of the client during sampling.
1117
*
1118
* Because LLMs can vary along multiple dimensions, choosing the "best" model is
1119
* rarely straightforward. Different models excel in different areas-some are
1120
* faster but less capable, others are more capable but more expensive, and so
1121
* on. This interface allows servers to express their priorities across multiple
1122
* dimensions to help clients make an appropriate selection for their use case.
1123
*
1124
* These preferences are always advisory. The client MAY ignore them. It is also
1125
* up to the client to decide how to interpret these preferences and how to
1126
* balance them against other considerations.
1127
*/
1128
export interface ModelPreferences {
1129
/**
1130
* Optional hints to use for model selection.
1131
*
1132
* If multiple hints are specified, the client MUST evaluate them in order
1133
* (such that the first match is taken).
1134
*
1135
* The client SHOULD prioritize these hints over the numeric priorities, but
1136
* MAY still use the priorities to select from ambiguous matches.
1137
*/
1138
hints?: ModelHint[];
1139
1140
/**
1141
* How much to prioritize cost when selecting a model. A value of 0 means cost
1142
* is not important, while a value of 1 means cost is the most important
1143
* factor.
1144
*
1145
* @TJS-type number
1146
* @minimum 0
1147
* @maximum 1
1148
*/
1149
costPriority?: number;
1150
1151
/**
1152
* How much to prioritize sampling speed (latency) when selecting a model. A
1153
* value of 0 means speed is not important, while a value of 1 means speed is
1154
* the most important factor.
1155
*
1156
* @TJS-type number
1157
* @minimum 0
1158
* @maximum 1
1159
*/
1160
speedPriority?: number;
1161
1162
/**
1163
* How much to prioritize intelligence and capabilities when selecting a
1164
* model. A value of 0 means intelligence is not important, while a value of 1
1165
* means intelligence is the most important factor.
1166
*
1167
* @TJS-type number
1168
* @minimum 0
1169
* @maximum 1
1170
*/
1171
intelligencePriority?: number;
1172
}
1173
1174
/**
1175
* Hints to use for model selection.
1176
*
1177
* Keys not declared here are currently left unspecified by the spec and are up
1178
* to the client to interpret.
1179
*/
1180
export interface ModelHint {
1181
/**
1182
* A hint for a model name.
1183
*
1184
* The client SHOULD treat this as a substring of a model name; for example:
1185
* - `claude-3-5-sonnet` should match `claude-3-5-sonnet-20241022`
1186
* - `sonnet` should match `claude-3-5-sonnet-20241022`, `claude-3-sonnet-20240229`, etc.
1187
* - `claude` should match any Claude model
1188
*
1189
* The client MAY also map the string to a different provider's model name or a different model family, as long as it fills a similar niche; for example:
1190
* - `gemini-1.5-flash` could match `claude-3-haiku-20240307`
1191
*/
1192
name?: string;
1193
}
1194
1195
/* Autocomplete */
1196
/**
1197
* A request from the client to the server, to ask for completion options.
1198
*/
1199
export interface CompleteRequest extends Request {
1200
method: "completion/complete";
1201
params: {
1202
ref: PromptReference | ResourceTemplateReference;
1203
/**
1204
* The argument's information
1205
*/
1206
argument: {
1207
/**
1208
* The name of the argument
1209
*/
1210
name: string;
1211
/**
1212
* The value of the argument to use for completion matching.
1213
*/
1214
value: string;
1215
};
1216
1217
/**
1218
* Additional, optional context for completions
1219
*/
1220
context?: {
1221
/**
1222
* Previously-resolved variables in a URI template or prompt.
1223
*/
1224
arguments?: { [key: string]: string };
1225
};
1226
};
1227
}
1228
1229
/**
1230
* The server's response to a completion/complete request
1231
*/
1232
export interface CompleteResult extends Result {
1233
completion: {
1234
/**
1235
* An array of completion values. Must not exceed 100 items.
1236
*/
1237
values: string[];
1238
/**
1239
* The total number of completion options available. This can exceed the number of values actually sent in the response.
1240
*/
1241
total?: number;
1242
/**
1243
* Indicates whether there are additional completion options beyond those provided in the current response, even if the exact total is unknown.
1244
*/
1245
hasMore?: boolean;
1246
};
1247
}
1248
1249
/**
1250
* A reference to a resource or resource template definition.
1251
*/
1252
export interface ResourceTemplateReference {
1253
type: "ref/resource";
1254
/**
1255
* The URI or URI template of the resource.
1256
*
1257
* @format uri-template
1258
*/
1259
uri: string;
1260
}
1261
1262
/**
1263
* Identifies a prompt.
1264
*/
1265
export interface PromptReference extends BaseMetadata {
1266
type: "ref/prompt";
1267
}
1268
1269
/* Roots */
1270
/**
1271
* Sent from the server to request a list of root URIs from the client. Roots allow
1272
* servers to ask for specific directories or files to operate on. A common example
1273
* for roots is providing a set of repositories or directories a server should operate
1274
* on.
1275
*
1276
* This request is typically used when the server needs to understand the file system
1277
* structure or access specific locations that the client has permission to read from.
1278
*/
1279
export interface ListRootsRequest extends Request {
1280
method: "roots/list";
1281
}
1282
1283
/**
1284
* The client's response to a roots/list request from the server.
1285
* This result contains an array of Root objects, each representing a root directory
1286
* or file that the server can operate on.
1287
*/
1288
export interface ListRootsResult extends Result {
1289
roots: Root[];
1290
}
1291
1292
/**
1293
* Represents a root directory or file that the server can operate on.
1294
*/
1295
export interface Root {
1296
/**
1297
* The URI identifying the root. This *must* start with file:// for now.
1298
* This restriction may be relaxed in future versions of the protocol to allow
1299
* other URI schemes.
1300
*
1301
* @format uri
1302
*/
1303
uri: string;
1304
/**
1305
* An optional name for the root. This can be used to provide a human-readable
1306
* identifier for the root, which may be useful for display purposes or for
1307
* referencing the root in other parts of the application.
1308
*/
1309
name?: string;
1310
1311
/**
1312
* See [specification/2025-06-18/basic/index#general-fields] for notes on _meta usage.
1313
*/
1314
_meta?: { [key: string]: unknown };
1315
}
1316
1317
/**
1318
* A notification from the client to the server, informing it that the list of roots has changed.
1319
* This notification should be sent whenever the client adds, removes, or modifies any root.
1320
* The server should then request an updated list of roots using the ListRootsRequest.
1321
*/
1322
export interface RootsListChangedNotification extends Notification {
1323
method: "notifications/roots/list_changed";
1324
}
1325
1326
/**
1327
* A request from the server to elicit additional information from the user via the client.
1328
*/
1329
export interface ElicitRequest extends Request {
1330
method: "elicitation/create";
1331
params: {
1332
/**
1333
* The message to present to the user.
1334
*/
1335
message: string;
1336
/**
1337
* A restricted subset of JSON Schema.
1338
* Only top-level properties are allowed, without nesting.
1339
*/
1340
requestedSchema: {
1341
type: "object";
1342
properties: {
1343
[key: string]: PrimitiveSchemaDefinition;
1344
};
1345
required?: string[];
1346
};
1347
};
1348
}
1349
1350
/**
1351
* Restricted schema definitions that only allow primitive types
1352
* without nested objects or arrays.
1353
*/
1354
export type PrimitiveSchemaDefinition =
1355
| StringSchema
1356
| NumberSchema
1357
| BooleanSchema
1358
| EnumSchema;
1359
1360
export interface StringSchema {
1361
type: "string";
1362
title?: string;
1363
description?: string;
1364
minLength?: number;
1365
maxLength?: number;
1366
format?: "email" | "uri" | "date" | "date-time";
1367
}
1368
1369
export interface NumberSchema {
1370
type: "number" | "integer";
1371
title?: string;
1372
description?: string;
1373
minimum?: number;
1374
maximum?: number;
1375
}
1376
1377
export interface BooleanSchema {
1378
type: "boolean";
1379
title?: string;
1380
description?: string;
1381
default?: boolean;
1382
}
1383
1384
export interface EnumSchema {
1385
type: "string";
1386
title?: string;
1387
description?: string;
1388
enum: string[];
1389
enumNames?: string[]; // Display names for enum values
1390
}
1391
1392
/**
1393
* The client's response to an elicitation request.
1394
*/
1395
export interface ElicitResult extends Result {
1396
/**
1397
* The user action in response to the elicitation.
1398
* - "accept": User submitted the form/confirmed the action
1399
* - "decline": User explicitly declined the action
1400
* - "cancel": User dismissed without making an explicit choice
1401
*/
1402
action: "accept" | "decline" | "cancel";
1403
1404
/**
1405
* The submitted form data, only present when action is "accept".
1406
* Contains values matching the requested schema.
1407
*/
1408
content?: { [key: string]: string | number | boolean };
1409
}
1410
1411
/* Client messages */
1412
export type ClientRequest =
1413
| PingRequest
1414
| InitializeRequest
1415
| CompleteRequest
1416
| SetLevelRequest
1417
| GetPromptRequest
1418
| ListPromptsRequest
1419
| ListResourcesRequest
1420
| ListResourceTemplatesRequest
1421
| ReadResourceRequest
1422
| SubscribeRequest
1423
| UnsubscribeRequest
1424
| CallToolRequest
1425
| ListToolsRequest;
1426
1427
export type ClientNotification =
1428
| CancelledNotification
1429
| ProgressNotification
1430
| InitializedNotification
1431
| RootsListChangedNotification;
1432
1433
export type ClientResult =
1434
| EmptyResult
1435
| CreateMessageResult
1436
| ListRootsResult
1437
| ElicitResult;
1438
1439
/* Server messages */
1440
export type ServerRequest =
1441
| PingRequest
1442
| CreateMessageRequest
1443
| ListRootsRequest
1444
| ElicitRequest;
1445
1446
export type ServerNotification =
1447
| CancelledNotification
1448
| ProgressNotification
1449
| LoggingMessageNotification
1450
| ResourceUpdatedNotification
1451
| ResourceListChangedNotification
1452
| ToolListChangedNotification
1453
| PromptListChangedNotification;
1454
1455
export type ServerResult =
1456
| EmptyResult
1457
| InitializeResult
1458
| CompleteResult
1459
| GetPromptResult
1460
| ListPromptsResult
1461
| ListResourceTemplatesResult
1462
| ListResourcesResult
1463
| ReadResourceResult
1464
| CallToolResult
1465
| ListToolsResult;
1466
}
1467
1468