mirror of
https://github.com/aljazceru/mcp-python-sdk.git
synced 2025-12-19 14:54:24 +01:00
fix: update types to reflext 2024-11-05 schema
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from typing import Any, Generic, Literal, TypeVar
|
||||
from typing import Annotated, Any, Generic, Literal, TypeVar
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field, FileUrl, RootModel
|
||||
from pydantic.networks import AnyUrl
|
||||
@@ -25,6 +25,8 @@ LATEST_PROTOCOL_VERSION = "2024-11-05"
|
||||
|
||||
ProgressToken = str | int
|
||||
Cursor = str
|
||||
Role = Literal["user", "assistant"]
|
||||
RequestId = str | int
|
||||
|
||||
|
||||
class RequestParams(BaseModel):
|
||||
@@ -101,9 +103,6 @@ class PaginatedResult(Result):
|
||||
"""
|
||||
|
||||
|
||||
RequestId = str | int
|
||||
|
||||
|
||||
class JSONRPCRequest(Request):
|
||||
"""A request that expects a response."""
|
||||
|
||||
@@ -344,6 +343,12 @@ class ListResourcesRequest(PaginatedRequest):
|
||||
params: RequestParams | None = None
|
||||
|
||||
|
||||
class Annotations(BaseModel):
|
||||
audience: list[Role] | None = None
|
||||
priority: Annotated[float, Field(ge=0.0, le=1.0)] | None = None
|
||||
model_config = ConfigDict(extra="allow")
|
||||
|
||||
|
||||
class Resource(BaseModel):
|
||||
"""A known resource that the server is capable of reading."""
|
||||
|
||||
@@ -355,6 +360,14 @@ class Resource(BaseModel):
|
||||
"""A description of what this resource represents."""
|
||||
mimeType: 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.
|
||||
"""
|
||||
annotations: Annotations | None = None
|
||||
model_config = ConfigDict(extra="allow")
|
||||
|
||||
|
||||
@@ -375,6 +388,7 @@ class ResourceTemplate(BaseModel):
|
||||
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.
|
||||
"""
|
||||
annotations: Annotations | None = None
|
||||
model_config = ConfigDict(extra="allow")
|
||||
|
||||
|
||||
@@ -578,6 +592,7 @@ class TextContent(BaseModel):
|
||||
type: Literal["text"]
|
||||
text: str
|
||||
"""The text content of the message."""
|
||||
annotations: Annotations | None = None
|
||||
model_config = ConfigDict(extra="allow")
|
||||
|
||||
|
||||
@@ -592,12 +607,10 @@ class ImageContent(BaseModel):
|
||||
The MIME type of the image. Different providers may support different
|
||||
image types.
|
||||
"""
|
||||
annotations: Annotations | None = None
|
||||
model_config = ConfigDict(extra="allow")
|
||||
|
||||
|
||||
Role = Literal["user", "assistant"]
|
||||
|
||||
|
||||
class SamplingMessage(BaseModel):
|
||||
"""Describes a message issued to or received from an LLM API."""
|
||||
|
||||
@@ -616,6 +629,7 @@ class EmbeddedResource(BaseModel):
|
||||
|
||||
type: Literal["resource"]
|
||||
resource: TextResourceContents | BlobResourceContents
|
||||
annotations: Annotations | None = None
|
||||
model_config = ConfigDict(extra="allow")
|
||||
|
||||
|
||||
@@ -977,6 +991,26 @@ class RootsListChangedNotification(Notification):
|
||||
params: NotificationParams | None = None
|
||||
|
||||
|
||||
class CancelledNotificationParams(NotificationParams):
|
||||
"""Parameters for cancellation notifications."""
|
||||
|
||||
requestId: RequestId
|
||||
"""The ID of the request to cancel."""
|
||||
reason: str | None = None
|
||||
"""An optional string describing the reason for the cancellation."""
|
||||
model_config = ConfigDict(extra="allow")
|
||||
|
||||
|
||||
class CancelledNotification(Notification):
|
||||
"""
|
||||
This notification can be sent by either side to indicate that it is cancelling a
|
||||
previously-issued request.
|
||||
"""
|
||||
|
||||
method: Literal["notifications/cancelled"]
|
||||
params: CancelledNotificationParams
|
||||
|
||||
|
||||
class ClientRequest(
|
||||
RootModel[
|
||||
PingRequest
|
||||
@@ -999,7 +1033,10 @@ class ClientRequest(
|
||||
|
||||
class ClientNotification(
|
||||
RootModel[
|
||||
ProgressNotification | InitializedNotification | RootsListChangedNotification
|
||||
CancelledNotification
|
||||
| ProgressNotification
|
||||
| InitializedNotification
|
||||
| RootsListChangedNotification
|
||||
]
|
||||
):
|
||||
pass
|
||||
@@ -1015,7 +1052,8 @@ class ServerRequest(RootModel[PingRequest | CreateMessageRequest | ListRootsRequ
|
||||
|
||||
class ServerNotification(
|
||||
RootModel[
|
||||
ProgressNotification
|
||||
CancelledNotification
|
||||
| ProgressNotification
|
||||
| LoggingMessageNotification
|
||||
| ResourceUpdatedNotification
|
||||
| ResourceListChangedNotification
|
||||
|
||||
Reference in New Issue
Block a user