Skip to content

Commit

Permalink
Merge pull request #165 from modelcontextprotocol/davidsp/types-2024-…
Browse files Browse the repository at this point in the history
…11-05

feat: update types to 2024-11-05 schema
  • Loading branch information
dsp-ant authored Jan 24, 2025
2 parents c14ec2e + bd74227 commit ba25ad6
Showing 1 changed file with 47 additions and 9 deletions.
56 changes: 47 additions & 9 deletions src/mcp/types.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -25,6 +25,8 @@

ProgressToken = str | int
Cursor = str
Role = Literal["user", "assistant"]
RequestId = str | int


class RequestParams(BaseModel):
Expand Down Expand Up @@ -101,9 +103,6 @@ class PaginatedResult(Result):
"""


RequestId = str | int


class JSONRPCRequest(Request):
"""A request that expects a response."""

Expand Down Expand Up @@ -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."""

Expand All @@ -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")


Expand All @@ -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")


Expand Down Expand Up @@ -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")


Expand All @@ -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."""

Expand All @@ -616,6 +629,7 @@ class EmbeddedResource(BaseModel):

type: Literal["resource"]
resource: TextResourceContents | BlobResourceContents
annotations: Annotations | None = None
model_config = ConfigDict(extra="allow")


Expand Down Expand Up @@ -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
Expand All @@ -999,7 +1033,10 @@ class ClientRequest(

class ClientNotification(
RootModel[
ProgressNotification | InitializedNotification | RootsListChangedNotification
CancelledNotification
| ProgressNotification
| InitializedNotification
| RootsListChangedNotification
]
):
pass
Expand All @@ -1015,7 +1052,8 @@ class ServerRequest(RootModel[PingRequest | CreateMessageRequest | ListRootsRequ

class ServerNotification(
RootModel[
ProgressNotification
CancelledNotification
| ProgressNotification
| LoggingMessageNotification
| ResourceUpdatedNotification
| ResourceListChangedNotification
Expand Down

0 comments on commit ba25ad6

Please sign in to comment.