1- from typing import Any , Generic , Literal , TypeVar
1+ from typing import Annotated , Any , Generic , Literal , TypeVar
22
33from pydantic import BaseModel , ConfigDict , Field , FileUrl , RootModel
44from pydantic .networks import AnyUrl
2525
2626ProgressToken = str | int
2727Cursor = str
28+ Role = Literal ["user" , "assistant" ]
29+ RequestId = str | int
2830
2931
3032class RequestParams (BaseModel ):
@@ -101,9 +103,6 @@ class PaginatedResult(Result):
101103 """
102104
103105
104- RequestId = str | int
105-
106-
107106class JSONRPCRequest (Request ):
108107 """A request that expects a response."""
109108
@@ -344,6 +343,12 @@ class ListResourcesRequest(PaginatedRequest):
344343 params : RequestParams | None = None
345344
346345
346+ class Annotations (BaseModel ):
347+ audience : list [Role ] | None = None
348+ priority : Annotated [float , Field (ge = 0.0 , le = 1.0 )] | None = None
349+ model_config = ConfigDict (extra = "allow" )
350+
351+
347352class Resource (BaseModel ):
348353 """A known resource that the server is capable of reading."""
349354
@@ -355,6 +360,14 @@ class Resource(BaseModel):
355360 """A description of what this resource represents."""
356361 mimeType : str | None = None
357362 """The MIME type of this resource, if known."""
363+ size : int | None = None
364+ """
365+ The size of the raw resource content, in bytes (i.e., before base64 encoding
366+ or any tokenization), if known.
367+
368+ This can be used by Hosts to display file sizes and estimate context window usage.
369+ """
370+ annotations : Annotations | None = None
358371 model_config = ConfigDict (extra = "allow" )
359372
360373
@@ -375,6 +388,7 @@ class ResourceTemplate(BaseModel):
375388 The MIME type for all resources that match this template. This should only be
376389 included if all resources matching this template have the same type.
377390 """
391+ annotations : Annotations | None = None
378392 model_config = ConfigDict (extra = "allow" )
379393
380394
@@ -578,6 +592,7 @@ class TextContent(BaseModel):
578592 type : Literal ["text" ]
579593 text : str
580594 """The text content of the message."""
595+ annotations : Annotations | None = None
581596 model_config = ConfigDict (extra = "allow" )
582597
583598
@@ -592,12 +607,10 @@ class ImageContent(BaseModel):
592607 The MIME type of the image. Different providers may support different
593608 image types.
594609 """
610+ annotations : Annotations | None = None
595611 model_config = ConfigDict (extra = "allow" )
596612
597613
598- Role = Literal ["user" , "assistant" ]
599-
600-
601614class SamplingMessage (BaseModel ):
602615 """Describes a message issued to or received from an LLM API."""
603616
@@ -616,6 +629,7 @@ class EmbeddedResource(BaseModel):
616629
617630 type : Literal ["resource" ]
618631 resource : TextResourceContents | BlobResourceContents
632+ annotations : Annotations | None = None
619633 model_config = ConfigDict (extra = "allow" )
620634
621635
@@ -977,6 +991,26 @@ class RootsListChangedNotification(Notification):
977991 params : NotificationParams | None = None
978992
979993
994+ class CancelledNotificationParams (NotificationParams ):
995+ """Parameters for cancellation notifications."""
996+
997+ requestId : RequestId
998+ """The ID of the request to cancel."""
999+ reason : str | None = None
1000+ """An optional string describing the reason for the cancellation."""
1001+ model_config = ConfigDict (extra = "allow" )
1002+
1003+
1004+ class CancelledNotification (Notification ):
1005+ """
1006+ This notification can be sent by either side to indicate that it is cancelling a
1007+ previously-issued request.
1008+ """
1009+
1010+ method : Literal ["notifications/cancelled" ]
1011+ params : CancelledNotificationParams
1012+
1013+
9801014class ClientRequest (
9811015 RootModel [
9821016 PingRequest
@@ -999,7 +1033,10 @@ class ClientRequest(
9991033
10001034class ClientNotification (
10011035 RootModel [
1002- ProgressNotification | InitializedNotification | RootsListChangedNotification
1036+ CancelledNotification
1037+ | ProgressNotification
1038+ | InitializedNotification
1039+ | RootsListChangedNotification
10031040 ]
10041041):
10051042 pass
@@ -1015,7 +1052,8 @@ class ServerRequest(RootModel[PingRequest | CreateMessageRequest | ListRootsRequ
10151052
10161053class ServerNotification (
10171054 RootModel [
1018- ProgressNotification
1055+ CancelledNotification
1056+ | ProgressNotification
10191057 | LoggingMessageNotification
10201058 | ResourceUpdatedNotification
10211059 | ResourceListChangedNotification
0 commit comments