mirror of
https://github.com/aljazceru/mcp-python-sdk.git
synced 2025-12-19 14:54:24 +01:00
Merge pull request #165 from modelcontextprotocol/davidsp/types-2024-11-05
feat: update types to 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 import BaseModel, ConfigDict, Field, FileUrl, RootModel
|
||||||
from pydantic.networks import AnyUrl
|
from pydantic.networks import AnyUrl
|
||||||
@@ -25,6 +25,8 @@ LATEST_PROTOCOL_VERSION = "2024-11-05"
|
|||||||
|
|
||||||
ProgressToken = str | int
|
ProgressToken = str | int
|
||||||
Cursor = str
|
Cursor = str
|
||||||
|
Role = Literal["user", "assistant"]
|
||||||
|
RequestId = str | int
|
||||||
|
|
||||||
|
|
||||||
class RequestParams(BaseModel):
|
class RequestParams(BaseModel):
|
||||||
@@ -101,9 +103,6 @@ class PaginatedResult(Result):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
RequestId = str | int
|
|
||||||
|
|
||||||
|
|
||||||
class JSONRPCRequest(Request):
|
class JSONRPCRequest(Request):
|
||||||
"""A request that expects a response."""
|
"""A request that expects a response."""
|
||||||
|
|
||||||
@@ -344,6 +343,12 @@ class ListResourcesRequest(PaginatedRequest):
|
|||||||
params: RequestParams | None = None
|
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):
|
class Resource(BaseModel):
|
||||||
"""A known resource that the server is capable of reading."""
|
"""A known resource that the server is capable of reading."""
|
||||||
|
|
||||||
@@ -355,6 +360,14 @@ class Resource(BaseModel):
|
|||||||
"""A description of what this resource represents."""
|
"""A description of what this resource represents."""
|
||||||
mimeType: str | None = None
|
mimeType: str | None = None
|
||||||
"""The MIME type of this resource, if known."""
|
"""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")
|
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
|
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.
|
included if all resources matching this template have the same type.
|
||||||
"""
|
"""
|
||||||
|
annotations: Annotations | None = None
|
||||||
model_config = ConfigDict(extra="allow")
|
model_config = ConfigDict(extra="allow")
|
||||||
|
|
||||||
|
|
||||||
@@ -578,6 +592,7 @@ class TextContent(BaseModel):
|
|||||||
type: Literal["text"]
|
type: Literal["text"]
|
||||||
text: str
|
text: str
|
||||||
"""The text content of the message."""
|
"""The text content of the message."""
|
||||||
|
annotations: Annotations | None = None
|
||||||
model_config = ConfigDict(extra="allow")
|
model_config = ConfigDict(extra="allow")
|
||||||
|
|
||||||
|
|
||||||
@@ -592,12 +607,10 @@ class ImageContent(BaseModel):
|
|||||||
The MIME type of the image. Different providers may support different
|
The MIME type of the image. Different providers may support different
|
||||||
image types.
|
image types.
|
||||||
"""
|
"""
|
||||||
|
annotations: Annotations | None = None
|
||||||
model_config = ConfigDict(extra="allow")
|
model_config = ConfigDict(extra="allow")
|
||||||
|
|
||||||
|
|
||||||
Role = Literal["user", "assistant"]
|
|
||||||
|
|
||||||
|
|
||||||
class SamplingMessage(BaseModel):
|
class SamplingMessage(BaseModel):
|
||||||
"""Describes a message issued to or received from an LLM API."""
|
"""Describes a message issued to or received from an LLM API."""
|
||||||
|
|
||||||
@@ -616,6 +629,7 @@ class EmbeddedResource(BaseModel):
|
|||||||
|
|
||||||
type: Literal["resource"]
|
type: Literal["resource"]
|
||||||
resource: TextResourceContents | BlobResourceContents
|
resource: TextResourceContents | BlobResourceContents
|
||||||
|
annotations: Annotations | None = None
|
||||||
model_config = ConfigDict(extra="allow")
|
model_config = ConfigDict(extra="allow")
|
||||||
|
|
||||||
|
|
||||||
@@ -977,6 +991,26 @@ class RootsListChangedNotification(Notification):
|
|||||||
params: NotificationParams | None = None
|
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(
|
class ClientRequest(
|
||||||
RootModel[
|
RootModel[
|
||||||
PingRequest
|
PingRequest
|
||||||
@@ -999,7 +1033,10 @@ class ClientRequest(
|
|||||||
|
|
||||||
class ClientNotification(
|
class ClientNotification(
|
||||||
RootModel[
|
RootModel[
|
||||||
ProgressNotification | InitializedNotification | RootsListChangedNotification
|
CancelledNotification
|
||||||
|
| ProgressNotification
|
||||||
|
| InitializedNotification
|
||||||
|
| RootsListChangedNotification
|
||||||
]
|
]
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
@@ -1015,7 +1052,8 @@ class ServerRequest(RootModel[PingRequest | CreateMessageRequest | ListRootsRequ
|
|||||||
|
|
||||||
class ServerNotification(
|
class ServerNotification(
|
||||||
RootModel[
|
RootModel[
|
||||||
ProgressNotification
|
CancelledNotification
|
||||||
|
| ProgressNotification
|
||||||
| LoggingMessageNotification
|
| LoggingMessageNotification
|
||||||
| ResourceUpdatedNotification
|
| ResourceUpdatedNotification
|
||||||
| ResourceListChangedNotification
|
| ResourceListChangedNotification
|
||||||
|
|||||||
Reference in New Issue
Block a user