-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Expand file tree
/
Copy path_types.py
More file actions
1778 lines (1229 loc) · 57.2 KB
/
_types.py
File metadata and controls
1778 lines (1229 loc) · 57.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from __future__ import annotations
from datetime import datetime
from typing import Annotated, Any, Final, Generic, Literal, TypeAlias, TypeVar
from pydantic import BaseModel, ConfigDict, Field, FileUrl, TypeAdapter
from pydantic.alias_generators import to_camel
from typing_extensions import NotRequired, TypedDict
from mcp.types.jsonrpc import RequestId
LATEST_PROTOCOL_VERSION = "2025-11-25"
"""The latest version of the Model Context Protocol.
You can find the latest specification at https://modelcontextprotocol.io/specification/latest.
"""
DEFAULT_NEGOTIATED_VERSION = "2025-03-26"
"""The default negotiated version of the Model Context Protocol when no version is specified.
We need this to satisfy the MCP specification, which requires the server to assume a specific version if none is
provided by the client.
See the "Protocol Version Header" at
https://modelcontextprotocol.io/specification/2025-11-25/basic/transports#protocol-version-header.
"""
ProgressToken = str | int
Role = Literal["user", "assistant"]
IconTheme = Literal["light", "dark"]
TaskExecutionMode = Literal["forbidden", "optional", "required"]
TASK_FORBIDDEN: Final[Literal["forbidden"]] = "forbidden"
TASK_OPTIONAL: Final[Literal["optional"]] = "optional"
TASK_REQUIRED: Final[Literal["required"]] = "required"
class MCPModel(BaseModel):
"""Base class for all MCP protocol types."""
model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True)
Meta: TypeAlias = dict[str, Any]
class RequestParamsMeta(TypedDict, extra_items=Any):
progress_token: NotRequired[ProgressToken]
"""
If specified, the caller requests 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.
"""
class TaskMetadata(MCPModel):
"""Metadata for augmenting a request with task execution.
Include this in the `task` field of the request parameters.
"""
ttl: Annotated[int, Field(strict=True)] | None = None
"""Requested duration in milliseconds to retain task from creation."""
class RequestParams(MCPModel):
task: TaskMetadata | None = None
"""
If specified, the caller is requesting task-augmented execution for this request.
The request will return a CreateTaskResult immediately, and the actual result can be
retrieved later via tasks/result.
Task augmentation is subject to capability negotiation - receivers MUST declare support
for task augmentation of specific request types in their capabilities.
"""
meta: RequestParamsMeta | None = Field(alias="_meta", default=None)
class PaginatedRequestParams(RequestParams):
cursor: str | None = None
"""An opaque token representing the current pagination position.
If provided, the server should return results starting after this cursor.
"""
class NotificationParams(MCPModel):
meta: Meta | None = Field(alias="_meta", default=None)
"""
See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
for notes on _meta usage.
"""
RequestParamsT = TypeVar("RequestParamsT", bound=RequestParams | dict[str, Any] | None)
NotificationParamsT = TypeVar("NotificationParamsT", bound=NotificationParams | dict[str, Any] | None)
MethodT = TypeVar("MethodT", bound=str)
class Request(MCPModel, Generic[RequestParamsT, MethodT]):
"""Base class for JSON-RPC requests."""
method: MethodT
params: RequestParamsT
class PaginatedRequest(Request[PaginatedRequestParams | None, MethodT], Generic[MethodT]):
"""Base class for paginated requests, matching the schema's PaginatedRequest interface."""
params: PaginatedRequestParams | None = None
class Notification(MCPModel, Generic[NotificationParamsT, MethodT]):
"""Base class for JSON-RPC notifications."""
method: MethodT
params: NotificationParamsT
class Result(MCPModel):
"""Base class for JSON-RPC results."""
meta: Meta | None = Field(alias="_meta", default=None)
"""
See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
for notes on _meta usage.
"""
class PaginatedResult(Result):
next_cursor: str | None = None
"""
An opaque token representing the pagination position after the last returned result.
If present, there may be more results available.
"""
class EmptyResult(Result):
"""A response that indicates success but carries no data."""
class BaseMetadata(MCPModel):
"""Base class for entities with name and optional title fields."""
name: str
"""The programmatic name of the entity."""
title: str | None = None
"""
Intended for UI and end-user contexts — optimized to be human-readable and easily understood,
even by those unfamiliar with domain-specific terminology.
If not provided, the name should be used for display (except for Tool,
where `annotations.title` should be given precedence over using `name`,
if present).
"""
class Icon(MCPModel):
"""An icon for display in user interfaces."""
src: str
"""URL or data URI for the icon."""
mime_type: str | None = None
"""Optional MIME type for the icon."""
sizes: list[str] | None = None
"""Optional list of strings specifying icon dimensions (e.g., ["48x48", "96x96"])."""
theme: IconTheme | None = None
"""Optional theme specifier.
`"light"` indicates the icon is designed for a light background, `"dark"` indicates the icon
is designed for a dark background.
See https://modelcontextprotocol.io/specification/2025-11-25/schema#icon for more details.
"""
class Implementation(BaseMetadata):
"""Describes the name and version of an MCP implementation."""
version: str
title: str | None = None
"""An optional human-readable title for this implementation."""
description: str | None = None
"""An optional human-readable description of what this implementation does."""
website_url: str | None = None
"""An optional URL of the website for this implementation."""
icons: list[Icon] | None = None
"""An optional list of icons for this implementation."""
class RootsCapability(MCPModel):
"""Capability for root operations."""
list_changed: bool | None = None
"""Whether the client supports notifications for changes to the roots list."""
class SamplingContextCapability(MCPModel):
"""Capability for context inclusion during sampling.
Indicates support for non-'none' values in the includeContext parameter.
SOFT-DEPRECATED: New implementations should use tools parameter instead.
"""
class SamplingToolsCapability(MCPModel):
"""Capability indicating support for tool calling during sampling.
When present in ClientCapabilities.sampling, indicates that the client
supports the tools and toolChoice parameters in sampling requests.
"""
class FormElicitationCapability(MCPModel):
"""Capability for form mode elicitation."""
class UrlElicitationCapability(MCPModel):
"""Capability for URL mode elicitation."""
class ElicitationCapability(MCPModel):
"""Capability for elicitation operations.
Clients must support at least one mode (form or url).
"""
form: FormElicitationCapability | None = None
"""Present if the client supports form mode elicitation."""
url: UrlElicitationCapability | None = None
"""Present if the client supports URL mode elicitation."""
class SamplingCapability(MCPModel):
"""Sampling capability structure, allowing fine-grained capability advertisement."""
context: SamplingContextCapability | None = None
"""
Present if the client supports non-'none' values for includeContext parameter.
SOFT-DEPRECATED: New implementations should use tools parameter instead.
"""
tools: SamplingToolsCapability | None = None
"""
Present if the client supports tools and toolChoice parameters in sampling requests.
Presence indicates full tool calling support during sampling.
"""
class TasksListCapability(MCPModel):
"""Capability for tasks listing operations."""
class TasksCancelCapability(MCPModel):
"""Capability for tasks cancel operations."""
class TasksCreateMessageCapability(MCPModel):
"""Capability for tasks create messages."""
class TasksSamplingCapability(MCPModel):
"""Capability for tasks sampling operations."""
create_message: TasksCreateMessageCapability | None = None
class TasksCreateElicitationCapability(MCPModel):
"""Capability for tasks create elicitation operations."""
class TasksElicitationCapability(MCPModel):
"""Capability for tasks elicitation operations."""
create: TasksCreateElicitationCapability | None = None
class ClientTasksRequestsCapability(MCPModel):
"""Capability for tasks requests operations."""
sampling: TasksSamplingCapability | None = None
elicitation: TasksElicitationCapability | None = None
class ClientTasksCapability(MCPModel):
"""Capability for client tasks operations."""
list: TasksListCapability | None = None
"""Whether this client supports tasks/list."""
cancel: TasksCancelCapability | None = None
"""Whether this client supports tasks/cancel."""
requests: ClientTasksRequestsCapability | None = None
"""Specifies which request types can be augmented with tasks."""
class ClientCapabilities(MCPModel):
"""Capabilities a client may support."""
experimental: dict[str, dict[str, Any]] | None = None
"""Experimental, non-standard capabilities that the client supports."""
sampling: SamplingCapability | None = None
"""
Present if the client supports sampling from an LLM.
Can contain fine-grained capabilities like context and tools support.
"""
elicitation: ElicitationCapability | None = None
"""Present if the client supports elicitation from the user."""
roots: RootsCapability | None = None
"""Present if the client supports listing roots."""
tasks: ClientTasksCapability | None = None
"""Present if the client supports task-augmented requests."""
class PromptsCapability(MCPModel):
"""Capability for prompts operations."""
list_changed: bool | None = None
"""Whether this server supports notifications for changes to the prompt list."""
class ResourcesCapability(MCPModel):
"""Capability for resources operations."""
subscribe: bool | None = None
"""Whether this server supports subscribing to resource updates."""
list_changed: bool | None = None
"""Whether this server supports notifications for changes to the resource list."""
class ToolsCapability(MCPModel):
"""Capability for tools operations."""
list_changed: bool | None = None
"""Whether this server supports notifications for changes to the tool list."""
class LoggingCapability(MCPModel):
"""Capability for logging operations."""
class CompletionsCapability(MCPModel):
"""Capability for completions operations."""
class TasksCallCapability(MCPModel):
"""Capability for tasks call operations."""
class TasksToolsCapability(MCPModel):
"""Capability for tasks tools operations."""
call: TasksCallCapability | None = None
class ServerTasksRequestsCapability(MCPModel):
"""Capability for tasks requests operations."""
tools: TasksToolsCapability | None = None
class ServerTasksCapability(MCPModel):
"""Capability for server tasks operations."""
list: TasksListCapability | None = None
cancel: TasksCancelCapability | None = None
requests: ServerTasksRequestsCapability | None = None
class ServerCapabilities(MCPModel):
"""Capabilities that a server may support."""
experimental: dict[str, dict[str, Any]] | None = None
"""Experimental, non-standard capabilities that the server supports."""
logging: LoggingCapability | None = None
"""Present if the server supports sending log messages to the client."""
prompts: PromptsCapability | None = None
"""Present if the server offers any prompt templates."""
resources: ResourcesCapability | None = None
"""Present if the server offers any resources to read."""
tools: ToolsCapability | None = None
"""Present if the server offers any tools to call."""
completions: CompletionsCapability | None = None
"""Present if the server offers autocompletion suggestions for prompts and resources."""
tasks: ServerTasksCapability | None = None
"""Present if the server supports task-augmented requests."""
TaskStatus = Literal["working", "input_required", "completed", "failed", "cancelled"]
# Task status constants
TASK_STATUS_WORKING: Final[Literal["working"]] = "working"
TASK_STATUS_INPUT_REQUIRED: Final[Literal["input_required"]] = "input_required"
TASK_STATUS_COMPLETED: Final[Literal["completed"]] = "completed"
TASK_STATUS_FAILED: Final[Literal["failed"]] = "failed"
TASK_STATUS_CANCELLED: Final[Literal["cancelled"]] = "cancelled"
class RelatedTaskMetadata(MCPModel):
"""Metadata for associating messages with a task.
Include this in the `_meta` field under the key `io.modelcontextprotocol/related-task`.
"""
task_id: str
"""The task identifier this message is associated with."""
class Task(MCPModel):
"""Data associated with a task."""
task_id: str
"""The task identifier."""
status: TaskStatus
"""Current task state."""
status_message: str | None = None
"""Optional human-readable message describing the current task state.
This can provide context for any status, including:
- Reasons for "cancelled" status
- Summaries for "completed" status
- Diagnostic information for "failed" status (e.g., error details, what went wrong)
"""
created_at: datetime # Pydantic will enforce ISO 8601 and re-serialize as a string later
"""ISO 8601 timestamp when the task was created."""
last_updated_at: datetime
"""ISO 8601 timestamp when the task was last updated."""
ttl: Annotated[int, Field(strict=True)] | None
"""Actual retention duration from creation in milliseconds, null for unlimited."""
poll_interval: Annotated[int, Field(strict=True)] | None = None
"""Suggested polling interval in milliseconds."""
class CreateTaskResult(Result):
"""A response to a task-augmented request."""
task: Task
class GetTaskRequestParams(RequestParams):
task_id: str
"""The task identifier to query."""
class GetTaskRequest(Request[GetTaskRequestParams, Literal["tasks/get"]]):
"""A request to retrieve the state of a task."""
method: Literal["tasks/get"] = "tasks/get"
params: GetTaskRequestParams
class GetTaskResult(Result, Task):
"""The response to a tasks/get request."""
class GetTaskPayloadRequestParams(RequestParams):
task_id: str
"""The task identifier to retrieve results for."""
class GetTaskPayloadRequest(Request[GetTaskPayloadRequestParams, Literal["tasks/result"]]):
"""A request to retrieve the result of a completed task."""
method: Literal["tasks/result"] = "tasks/result"
params: GetTaskPayloadRequestParams
class GetTaskPayloadResult(Result):
"""The response to a tasks/result request.
The structure matches the result type of the original request.
For example, a tools/call task would return the CallToolResult structure.
"""
model_config = ConfigDict(extra="allow", alias_generator=to_camel, populate_by_name=True)
class CancelTaskRequestParams(RequestParams):
task_id: str
"""The task identifier to cancel."""
class CancelTaskRequest(Request[CancelTaskRequestParams, Literal["tasks/cancel"]]):
"""A request to cancel a task."""
method: Literal["tasks/cancel"] = "tasks/cancel"
params: CancelTaskRequestParams
class CancelTaskResult(Result, Task):
"""The response to a tasks/cancel request."""
class ListTasksRequest(PaginatedRequest[Literal["tasks/list"]]):
"""A request to retrieve a list of tasks."""
method: Literal["tasks/list"] = "tasks/list"
class ListTasksResult(PaginatedResult):
"""The response to a tasks/list request."""
tasks: list[Task]
class TaskStatusNotificationParams(NotificationParams, Task):
"""Parameters for a `notifications/tasks/status` notification."""
class TaskStatusNotification(Notification[TaskStatusNotificationParams, Literal["notifications/tasks/status"]]):
"""An optional notification from the receiver to the requestor, informing them that a task's status has changed.
Receivers are not required to send these notifications.
"""
method: Literal["notifications/tasks/status"] = "notifications/tasks/status"
params: TaskStatusNotificationParams
class InitializeRequestParams(RequestParams):
"""Parameters for the initialize request."""
protocol_version: str | int
"""The latest version of the Model Context Protocol that the client supports."""
capabilities: ClientCapabilities
client_info: Implementation
class InitializeRequest(Request[InitializeRequestParams, Literal["initialize"]]):
"""This request is sent from the client to the server when it first connects, asking it
to begin initialization.
"""
method: Literal["initialize"] = "initialize"
params: InitializeRequestParams
class InitializeResult(Result):
"""After receiving an initialize request from the client, the server sends this."""
protocol_version: str | int
"""The version of the Model Context Protocol that the server wants to use."""
capabilities: ServerCapabilities
server_info: Implementation
instructions: str | None = None
"""Instructions describing how to use the server and its features."""
class InitializedNotification(Notification[NotificationParams | None, Literal["notifications/initialized"]]):
"""This notification is sent from the client to the server after initialization has
finished.
"""
method: Literal["notifications/initialized"] = "notifications/initialized"
params: NotificationParams | None = None
class PingRequest(Request[RequestParams | None, Literal["ping"]]):
"""A ping, issued by either the server or the client, to check that the other party is
still alive.
"""
method: Literal["ping"] = "ping"
params: RequestParams | None = None
class ProgressNotificationParams(NotificationParams):
"""Parameters for progress notifications."""
progress_token: ProgressToken
"""
The progress token which was given in the initial request, used to associate this
notification with the request that is proceeding.
"""
progress: float
"""
The progress thus far. This should increase every time progress is made, even if the
total is unknown.
"""
total: float | None = None
"""Total number of items to process (or total progress required), if known."""
message: str | None = None
"""Message related to progress.
This should provide relevant human-readable progress information.
"""
class ProgressNotification(Notification[ProgressNotificationParams, Literal["notifications/progress"]]):
"""An out-of-band notification used to inform the receiver of a progress update for a long-running request."""
method: Literal["notifications/progress"] = "notifications/progress"
params: ProgressNotificationParams
class ListResourcesRequest(PaginatedRequest[Literal["resources/list"]]):
"""Sent from the client to request a list of resources the server has."""
method: Literal["resources/list"] = "resources/list"
class Annotations(MCPModel):
audience: list[Role] | None = None
priority: Annotated[float, Field(ge=0.0, le=1.0)] | None = None
class Resource(BaseMetadata):
"""A known resource that the server is capable of reading."""
uri: str
"""The URI of this resource."""
description: str | None = None
"""A description of what this resource represents."""
mime_type: str | None = None
"""The MIME type of this resource, if known."""
size: int | None = None
"""The size of the raw resource content, in bytes (i.e., before base64 encoding or any tokenization), if known.
This can be used by Hosts to display file sizes and estimate context window usage.
"""
icons: list[Icon] | None = None
"""An optional list of icons for this resource."""
annotations: Annotations | None = None
meta: Meta | None = Field(alias="_meta", default=None)
"""
See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
for notes on _meta usage.
"""
class ResourceTemplate(BaseMetadata):
"""A template description for resources available on the server."""
uri_template: str
"""A URI template (according to RFC 6570) that can be used to construct resource URIs."""
description: str | None = None
"""A human-readable description of what this template is for."""
mime_type: str | None = None
"""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.
"""
icons: list[Icon] | None = None
"""An optional list of icons for this resource template."""
annotations: Annotations | None = None
meta: Meta | None = Field(alias="_meta", default=None)
"""
See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
for notes on _meta usage.
"""
class ListResourcesResult(PaginatedResult):
"""The server's response to a resources/list request from the client."""
resources: list[Resource]
class ListResourceTemplatesRequest(PaginatedRequest[Literal["resources/templates/list"]]):
"""Sent from the client to request a list of resource templates the server has."""
method: Literal["resources/templates/list"] = "resources/templates/list"
class ListResourceTemplatesResult(PaginatedResult):
"""The server's response to a resources/templates/list request from the client."""
resource_templates: list[ResourceTemplate]
class ReadResourceRequestParams(RequestParams):
"""Parameters for reading a resource."""
uri: str
"""
The URI of the resource to read. The URI can use any protocol; it is up to the
server how to interpret it.
"""
class ReadResourceRequest(Request[ReadResourceRequestParams, Literal["resources/read"]]):
"""Sent from the client to the server, to read a specific resource URI."""
method: Literal["resources/read"] = "resources/read"
params: ReadResourceRequestParams
class ResourceContents(MCPModel):
"""The contents of a specific resource or sub-resource."""
uri: str
"""The URI of this resource."""
mime_type: str | None = None
"""The MIME type of this resource, if known."""
meta: Meta | None = Field(alias="_meta", default=None)
"""
See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
for notes on _meta usage.
"""
class TextResourceContents(ResourceContents):
"""Text contents of a resource."""
text: str
"""
The text of the item. This must only be set if the item can actually be represented
as text (not binary data).
"""
class BlobResourceContents(ResourceContents):
"""Binary contents of a resource."""
blob: str
"""A base64-encoded string representing the binary data of the item."""
class ReadResourceResult(Result):
"""The server's response to a resources/read request from the client."""
contents: list[TextResourceContents | BlobResourceContents]
class ResourceListChangedNotification(
Notification[NotificationParams | None, Literal["notifications/resources/list_changed"]]
):
"""An optional notification from the server to the client, informing it that the list
of resources it can read from has changed.
"""
method: Literal["notifications/resources/list_changed"] = "notifications/resources/list_changed"
params: NotificationParams | None = None
class SubscribeRequestParams(RequestParams):
"""Parameters for subscribing to a resource."""
uri: str
"""
The URI of the resource to subscribe to. The URI can use any protocol; it is up to
the server how to interpret it.
"""
class SubscribeRequest(Request[SubscribeRequestParams, Literal["resources/subscribe"]]):
"""Sent from the client to request resources/updated notifications from the server
whenever a particular resource changes.
"""
method: Literal["resources/subscribe"] = "resources/subscribe"
params: SubscribeRequestParams
class UnsubscribeRequestParams(RequestParams):
"""Parameters for unsubscribing from a resource."""
uri: str
"""The URI of the resource to unsubscribe from."""
class UnsubscribeRequest(Request[UnsubscribeRequestParams, Literal["resources/unsubscribe"]]):
"""Sent from the client to request cancellation of resources/updated notifications from
the server.
"""
method: Literal["resources/unsubscribe"] = "resources/unsubscribe"
params: UnsubscribeRequestParams
class ResourceUpdatedNotificationParams(NotificationParams):
"""Parameters for resource update notifications."""
uri: str
"""
The URI of the resource that has been updated. This might be a sub-resource of the
one that the client actually subscribed to.
"""
class ResourceUpdatedNotification(
Notification[ResourceUpdatedNotificationParams, Literal["notifications/resources/updated"]]
):
"""A notification from the server to the client, informing it that a resource has
changed and may need to be read again.
"""
method: Literal["notifications/resources/updated"] = "notifications/resources/updated"
params: ResourceUpdatedNotificationParams
class ListPromptsRequest(PaginatedRequest[Literal["prompts/list"]]):
"""Sent from the client to request a list of prompts and prompt templates."""
method: Literal["prompts/list"] = "prompts/list"
class PromptArgument(MCPModel):
"""An argument for a prompt template."""
name: str
"""The name of the argument."""
description: str | None = None
"""A human-readable description of the argument."""
required: bool | None = None
"""Whether this argument must be provided."""
class Prompt(BaseMetadata):
"""A prompt or prompt template that the server offers."""
description: str | None = None
"""An optional description of what this prompt provides."""
arguments: list[PromptArgument] | None = None
"""A list of arguments to use for templating the prompt."""
icons: list[Icon] | None = None
"""An optional list of icons for this prompt."""
meta: Meta | None = Field(alias="_meta", default=None)
"""
See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
for notes on _meta usage.
"""
class ListPromptsResult(PaginatedResult):
"""The server's response to a prompts/list request from the client."""
prompts: list[Prompt]
class GetPromptRequestParams(RequestParams):
"""Parameters for getting a prompt."""
name: str
"""The name of the prompt or prompt template."""
arguments: dict[str, str] | None = None
"""Arguments to use for templating the prompt."""
class GetPromptRequest(Request[GetPromptRequestParams, Literal["prompts/get"]]):
"""Used by the client to get a prompt provided by the server."""
method: Literal["prompts/get"] = "prompts/get"
params: GetPromptRequestParams
class TextContent(MCPModel):
"""Text content for a message."""
type: Literal["text"] = "text"
text: str
"""The text content of the message."""
annotations: Annotations | None = None
meta: Meta | None = Field(alias="_meta", default=None)
"""
See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
for notes on _meta usage.
"""
class ImageContent(MCPModel):
"""Image content for a message."""
type: Literal["image"] = "image"
data: str
"""The base64-encoded image data."""
mime_type: str
"""
The MIME type of the image. Different providers may support different
image types.
"""
annotations: Annotations | None = None
meta: Meta | None = Field(alias="_meta", default=None)
"""
See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
for notes on _meta usage.
"""
class AudioContent(MCPModel):
"""Audio content for a message."""
type: Literal["audio"] = "audio"
data: str
"""The base64-encoded audio data."""
mime_type: str
"""
The MIME type of the audio. Different providers may support different
audio types.
"""
annotations: Annotations | None = None
meta: Meta | None = Field(alias="_meta", default=None)
"""
See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
for notes on _meta usage.
"""
class ToolUseContent(MCPModel):
"""Content representing an assistant's request to invoke a tool.
This content type appears in assistant messages when the LLM wants to call a tool
during sampling. The server should execute the tool and return a ToolResultContent
in the next user message.
"""
type: Literal["tool_use"] = "tool_use"
"""Discriminator for tool use content."""
name: str
"""The name of the tool to invoke. Must match a tool name from the request's tools array."""
id: str
"""Unique identifier for this tool call, used to correlate with ToolResultContent."""
input: dict[str, Any]
"""Arguments to pass to the tool. Must conform to the tool's inputSchema."""
meta: Meta | None = Field(alias="_meta", default=None)
"""
See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
for notes on _meta usage.
"""
class ToolResultContent(MCPModel):
"""Content representing the result of a tool execution.
This content type appears in user messages as a response to a ToolUseContent
from the assistant. It contains the output of executing the requested tool.
"""
type: Literal["tool_result"] = "tool_result"
"""Discriminator for tool result content."""
tool_use_id: str
"""The unique identifier that corresponds to the tool call's id field."""
content: list[ContentBlock] = []
"""
A list of content objects representing the tool result.
Defaults to empty list if not provided.
"""
structured_content: dict[str, Any] | None = None
"""
Optional structured tool output that matches the tool's outputSchema (if defined).
"""
is_error: bool | None = None
"""Whether the tool execution resulted in an error."""
meta: Meta | None = Field(alias="_meta", default=None)
"""
See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
for notes on _meta usage.
"""
SamplingMessageContentBlock: TypeAlias = TextContent | ImageContent | AudioContent | ToolUseContent | ToolResultContent
"""Content block types allowed in sampling messages."""
SamplingContent: TypeAlias = TextContent | ImageContent | AudioContent
"""Basic content types for sampling responses (without tool use).