|
|
|
|
@ -1,14 +1,6 @@
|
|
|
|
|
from collections.abc import Callable
|
|
|
|
|
from dataclasses import dataclass
|
|
|
|
|
from typing import (
|
|
|
|
|
Annotated,
|
|
|
|
|
Any,
|
|
|
|
|
Generic,
|
|
|
|
|
Literal,
|
|
|
|
|
Optional,
|
|
|
|
|
TypeAlias,
|
|
|
|
|
TypeVar,
|
|
|
|
|
)
|
|
|
|
|
from typing import Annotated, Any, Generic, Literal, Optional, TypeAlias, TypeVar
|
|
|
|
|
|
|
|
|
|
from pydantic import BaseModel, ConfigDict, Field, FileUrl, RootModel
|
|
|
|
|
from pydantic.networks import AnyUrl, UrlConstraints
|
|
|
|
|
@ -34,10 +26,11 @@ for reference.
|
|
|
|
|
LATEST_PROTOCOL_VERSION = "2025-03-26"
|
|
|
|
|
# Server support 2024-11-05 to allow claude to use.
|
|
|
|
|
SERVER_LATEST_PROTOCOL_VERSION = "2024-11-05"
|
|
|
|
|
DEFAULT_NEGOTIATED_VERSION = "2025-03-26"
|
|
|
|
|
ProgressToken = str | int
|
|
|
|
|
Cursor = str
|
|
|
|
|
Role = Literal["user", "assistant"]
|
|
|
|
|
RequestId = Annotated[int | str, Field(union_mode="left_to_right")]
|
|
|
|
|
RequestId = Annotated[int, Field(strict=True)] | str
|
|
|
|
|
AnyFunction: TypeAlias = Callable[..., Any]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -56,14 +49,22 @@ class RequestParams(BaseModel):
|
|
|
|
|
meta: Meta | None = Field(alias="_meta", default=None)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PaginatedRequestParams(RequestParams):
|
|
|
|
|
cursor: Cursor | None = None
|
|
|
|
|
"""
|
|
|
|
|
An opaque token representing the current pagination position.
|
|
|
|
|
If provided, the server should return results starting after this cursor.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class NotificationParams(BaseModel):
|
|
|
|
|
class Meta(BaseModel):
|
|
|
|
|
model_config = ConfigDict(extra="allow")
|
|
|
|
|
|
|
|
|
|
meta: Meta | None = Field(alias="_meta", default=None)
|
|
|
|
|
"""
|
|
|
|
|
This parameter name is reserved by MCP to allow clients and servers to attach
|
|
|
|
|
additional metadata to their notifications.
|
|
|
|
|
See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
|
|
|
for notes on _meta usage.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -80,12 +81,11 @@ class Request(BaseModel, Generic[RequestParamsT, MethodT]):
|
|
|
|
|
model_config = ConfigDict(extra="allow")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PaginatedRequest(Request[RequestParamsT, MethodT]):
|
|
|
|
|
cursor: Cursor | None = None
|
|
|
|
|
"""
|
|
|
|
|
An opaque token representing the current pagination position.
|
|
|
|
|
If provided, the server should return results starting after this cursor.
|
|
|
|
|
"""
|
|
|
|
|
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(BaseModel, Generic[NotificationParamsT, MethodT]):
|
|
|
|
|
@ -99,13 +99,12 @@ class Notification(BaseModel, Generic[NotificationParamsT, MethodT]):
|
|
|
|
|
class Result(BaseModel):
|
|
|
|
|
"""Base class for JSON-RPC results."""
|
|
|
|
|
|
|
|
|
|
model_config = ConfigDict(extra="allow")
|
|
|
|
|
|
|
|
|
|
meta: dict[str, Any] | None = Field(alias="_meta", default=None)
|
|
|
|
|
"""
|
|
|
|
|
This result property is reserved by the protocol to allow clients and servers to
|
|
|
|
|
attach additional metadata to their responses.
|
|
|
|
|
See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
|
|
|
for notes on _meta usage.
|
|
|
|
|
"""
|
|
|
|
|
model_config = ConfigDict(extra="allow")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PaginatedResult(Result):
|
|
|
|
|
@ -187,10 +186,26 @@ class EmptyResult(Result):
|
|
|
|
|
"""A response that indicates success but carries no data."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Implementation(BaseModel):
|
|
|
|
|
"""Describes the name and version of an MCP implementation."""
|
|
|
|
|
class BaseMetadata(BaseModel):
|
|
|
|
|
"""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 Implementation(BaseMetadata):
|
|
|
|
|
"""Describes the name and version of an MCP implementation."""
|
|
|
|
|
|
|
|
|
|
version: str
|
|
|
|
|
model_config = ConfigDict(extra="allow")
|
|
|
|
|
|
|
|
|
|
@ -204,7 +219,7 @@ class RootsCapability(BaseModel):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SamplingCapability(BaseModel):
|
|
|
|
|
"""Capability for logging operations."""
|
|
|
|
|
"""Capability for sampling operations."""
|
|
|
|
|
|
|
|
|
|
model_config = ConfigDict(extra="allow")
|
|
|
|
|
|
|
|
|
|
@ -253,6 +268,12 @@ class LoggingCapability(BaseModel):
|
|
|
|
|
model_config = ConfigDict(extra="allow")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CompletionsCapability(BaseModel):
|
|
|
|
|
"""Capability for completions operations."""
|
|
|
|
|
|
|
|
|
|
model_config = ConfigDict(extra="allow")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ServerCapabilities(BaseModel):
|
|
|
|
|
"""Capabilities that a server may support."""
|
|
|
|
|
|
|
|
|
|
@ -266,6 +287,8 @@ class ServerCapabilities(BaseModel):
|
|
|
|
|
"""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."""
|
|
|
|
|
model_config = ConfigDict(extra="allow")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -285,7 +308,7 @@ class InitializeRequest(Request[InitializeRequestParams, Literal["initialize"]])
|
|
|
|
|
to begin initialization.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
method: Literal["initialize"]
|
|
|
|
|
method: Literal["initialize"] = "initialize"
|
|
|
|
|
params: InitializeRequestParams
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -306,7 +329,7 @@ class InitializedNotification(Notification[NotificationParams | None, Literal["n
|
|
|
|
|
finished.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
method: Literal["notifications/initialized"]
|
|
|
|
|
method: Literal["notifications/initialized"] = "notifications/initialized"
|
|
|
|
|
params: NotificationParams | None = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -316,7 +339,7 @@ class PingRequest(Request[RequestParams | None, Literal["ping"]]):
|
|
|
|
|
still alive.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
method: Literal["ping"]
|
|
|
|
|
method: Literal["ping"] = "ping"
|
|
|
|
|
params: RequestParams | None = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -335,6 +358,11 @@ class ProgressNotificationParams(NotificationParams):
|
|
|
|
|
"""
|
|
|
|
|
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.
|
|
|
|
|
"""
|
|
|
|
|
model_config = ConfigDict(extra="allow")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -344,15 +372,14 @@ class ProgressNotification(Notification[ProgressNotificationParams, Literal["not
|
|
|
|
|
long-running request.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
method: Literal["notifications/progress"]
|
|
|
|
|
method: Literal["notifications/progress"] = "notifications/progress"
|
|
|
|
|
params: ProgressNotificationParams
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ListResourcesRequest(PaginatedRequest[RequestParams | None, Literal["resources/list"]]):
|
|
|
|
|
class ListResourcesRequest(PaginatedRequest[Literal["resources/list"]]):
|
|
|
|
|
"""Sent from the client to request a list of resources the server has."""
|
|
|
|
|
|
|
|
|
|
method: Literal["resources/list"]
|
|
|
|
|
params: RequestParams | None = None
|
|
|
|
|
method: Literal["resources/list"] = "resources/list"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Annotations(BaseModel):
|
|
|
|
|
@ -361,13 +388,11 @@ class Annotations(BaseModel):
|
|
|
|
|
model_config = ConfigDict(extra="allow")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Resource(BaseModel):
|
|
|
|
|
class Resource(BaseMetadata):
|
|
|
|
|
"""A known resource that the server is capable of reading."""
|
|
|
|
|
|
|
|
|
|
uri: Annotated[AnyUrl, UrlConstraints(host_required=False)]
|
|
|
|
|
"""The URI of this resource."""
|
|
|
|
|
name: str
|
|
|
|
|
"""A human-readable name for this resource."""
|
|
|
|
|
description: str | None = None
|
|
|
|
|
"""A description of what this resource represents."""
|
|
|
|
|
mimeType: str | None = None
|
|
|
|
|
@ -380,10 +405,15 @@ class Resource(BaseModel):
|
|
|
|
|
This can be used by Hosts to display file sizes and estimate context window usage.
|
|
|
|
|
"""
|
|
|
|
|
annotations: Annotations | None = None
|
|
|
|
|
meta: dict[str, Any] | 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.
|
|
|
|
|
"""
|
|
|
|
|
model_config = ConfigDict(extra="allow")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ResourceTemplate(BaseModel):
|
|
|
|
|
class ResourceTemplate(BaseMetadata):
|
|
|
|
|
"""A template description for resources available on the server."""
|
|
|
|
|
|
|
|
|
|
uriTemplate: str
|
|
|
|
|
@ -391,8 +421,6 @@ class ResourceTemplate(BaseModel):
|
|
|
|
|
A URI template (according to RFC 6570) that can be used to construct resource
|
|
|
|
|
URIs.
|
|
|
|
|
"""
|
|
|
|
|
name: str
|
|
|
|
|
"""A human-readable name for the type of resource this template refers to."""
|
|
|
|
|
description: str | None = None
|
|
|
|
|
"""A human-readable description of what this template is for."""
|
|
|
|
|
mimeType: str | None = None
|
|
|
|
|
@ -401,6 +429,11 @@ class ResourceTemplate(BaseModel):
|
|
|
|
|
included if all resources matching this template have the same type.
|
|
|
|
|
"""
|
|
|
|
|
annotations: Annotations | None = None
|
|
|
|
|
meta: dict[str, Any] | 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.
|
|
|
|
|
"""
|
|
|
|
|
model_config = ConfigDict(extra="allow")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -410,11 +443,10 @@ class ListResourcesResult(PaginatedResult):
|
|
|
|
|
resources: list[Resource]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ListResourceTemplatesRequest(PaginatedRequest[RequestParams | None, Literal["resources/templates/list"]]):
|
|
|
|
|
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"]
|
|
|
|
|
params: RequestParams | None = None
|
|
|
|
|
method: Literal["resources/templates/list"] = "resources/templates/list"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ListResourceTemplatesResult(PaginatedResult):
|
|
|
|
|
@ -437,7 +469,7 @@ class ReadResourceRequestParams(RequestParams):
|
|
|
|
|
class ReadResourceRequest(Request[ReadResourceRequestParams, Literal["resources/read"]]):
|
|
|
|
|
"""Sent from the client to the server, to read a specific resource URI."""
|
|
|
|
|
|
|
|
|
|
method: Literal["resources/read"]
|
|
|
|
|
method: Literal["resources/read"] = "resources/read"
|
|
|
|
|
params: ReadResourceRequestParams
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -448,6 +480,11 @@ class ResourceContents(BaseModel):
|
|
|
|
|
"""The URI of this resource."""
|
|
|
|
|
mimeType: str | None = None
|
|
|
|
|
"""The MIME type of this resource, if known."""
|
|
|
|
|
meta: dict[str, Any] | 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.
|
|
|
|
|
"""
|
|
|
|
|
model_config = ConfigDict(extra="allow")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -482,7 +519,7 @@ class ResourceListChangedNotification(
|
|
|
|
|
of resources it can read from has changed.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
method: Literal["notifications/resources/list_changed"]
|
|
|
|
|
method: Literal["notifications/resources/list_changed"] = "notifications/resources/list_changed"
|
|
|
|
|
params: NotificationParams | None = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -503,7 +540,7 @@ class SubscribeRequest(Request[SubscribeRequestParams, Literal["resources/subscr
|
|
|
|
|
whenever a particular resource changes.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
method: Literal["resources/subscribe"]
|
|
|
|
|
method: Literal["resources/subscribe"] = "resources/subscribe"
|
|
|
|
|
params: SubscribeRequestParams
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -521,7 +558,7 @@ class UnsubscribeRequest(Request[UnsubscribeRequestParams, Literal["resources/un
|
|
|
|
|
the server.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
method: Literal["resources/unsubscribe"]
|
|
|
|
|
method: Literal["resources/unsubscribe"] = "resources/unsubscribe"
|
|
|
|
|
params: UnsubscribeRequestParams
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -544,15 +581,14 @@ class ResourceUpdatedNotification(
|
|
|
|
|
changed and may need to be read again.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
method: Literal["notifications/resources/updated"]
|
|
|
|
|
method: Literal["notifications/resources/updated"] = "notifications/resources/updated"
|
|
|
|
|
params: ResourceUpdatedNotificationParams
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ListPromptsRequest(PaginatedRequest[RequestParams | None, Literal["prompts/list"]]):
|
|
|
|
|
class ListPromptsRequest(PaginatedRequest[Literal["prompts/list"]]):
|
|
|
|
|
"""Sent from the client to request a list of prompts and prompt templates."""
|
|
|
|
|
|
|
|
|
|
method: Literal["prompts/list"]
|
|
|
|
|
params: RequestParams | None = None
|
|
|
|
|
method: Literal["prompts/list"] = "prompts/list"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PromptArgument(BaseModel):
|
|
|
|
|
@ -567,15 +603,18 @@ class PromptArgument(BaseModel):
|
|
|
|
|
model_config = ConfigDict(extra="allow")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Prompt(BaseModel):
|
|
|
|
|
class Prompt(BaseMetadata):
|
|
|
|
|
"""A prompt or prompt template that the server offers."""
|
|
|
|
|
|
|
|
|
|
name: str
|
|
|
|
|
"""The name of the prompt or prompt template."""
|
|
|
|
|
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."""
|
|
|
|
|
meta: dict[str, Any] | 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.
|
|
|
|
|
"""
|
|
|
|
|
model_config = ConfigDict(extra="allow")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -598,7 +637,7 @@ class GetPromptRequestParams(RequestParams):
|
|
|
|
|
class GetPromptRequest(Request[GetPromptRequestParams, Literal["prompts/get"]]):
|
|
|
|
|
"""Used by the client to get a prompt provided by the server."""
|
|
|
|
|
|
|
|
|
|
method: Literal["prompts/get"]
|
|
|
|
|
method: Literal["prompts/get"] = "prompts/get"
|
|
|
|
|
params: GetPromptRequestParams
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -609,6 +648,11 @@ class TextContent(BaseModel):
|
|
|
|
|
text: str
|
|
|
|
|
"""The text content of the message."""
|
|
|
|
|
annotations: Annotations | None = None
|
|
|
|
|
meta: dict[str, Any] | 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.
|
|
|
|
|
"""
|
|
|
|
|
model_config = ConfigDict(extra="allow")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -624,6 +668,31 @@ class ImageContent(BaseModel):
|
|
|
|
|
image types.
|
|
|
|
|
"""
|
|
|
|
|
annotations: Annotations | None = None
|
|
|
|
|
meta: dict[str, Any] | 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.
|
|
|
|
|
"""
|
|
|
|
|
model_config = ConfigDict(extra="allow")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AudioContent(BaseModel):
|
|
|
|
|
"""Audio content for a message."""
|
|
|
|
|
|
|
|
|
|
type: Literal["audio"]
|
|
|
|
|
data: str
|
|
|
|
|
"""The base64-encoded audio data."""
|
|
|
|
|
mimeType: str
|
|
|
|
|
"""
|
|
|
|
|
The MIME type of the audio. Different providers may support different
|
|
|
|
|
audio types.
|
|
|
|
|
"""
|
|
|
|
|
annotations: Annotations | None = None
|
|
|
|
|
meta: dict[str, Any] | 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.
|
|
|
|
|
"""
|
|
|
|
|
model_config = ConfigDict(extra="allow")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -631,7 +700,7 @@ class SamplingMessage(BaseModel):
|
|
|
|
|
"""Describes a message issued to or received from an LLM API."""
|
|
|
|
|
|
|
|
|
|
role: Role
|
|
|
|
|
content: TextContent | ImageContent
|
|
|
|
|
content: TextContent | ImageContent | AudioContent
|
|
|
|
|
model_config = ConfigDict(extra="allow")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -646,14 +715,36 @@ class EmbeddedResource(BaseModel):
|
|
|
|
|
type: Literal["resource"]
|
|
|
|
|
resource: TextResourceContents | BlobResourceContents
|
|
|
|
|
annotations: Annotations | None = None
|
|
|
|
|
meta: dict[str, Any] | 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.
|
|
|
|
|
"""
|
|
|
|
|
model_config = ConfigDict(extra="allow")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ResourceLink(Resource):
|
|
|
|
|
"""
|
|
|
|
|
A resource that the server is capable of reading, included in a prompt or tool call result.
|
|
|
|
|
|
|
|
|
|
Note: resource links returned by tools are not guaranteed to appear in the results of `resources/list` requests.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
type: Literal["resource_link"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ContentBlock = TextContent | ImageContent | AudioContent | ResourceLink | EmbeddedResource
|
|
|
|
|
"""A content block that can be used in prompts and tool results."""
|
|
|
|
|
|
|
|
|
|
Content: TypeAlias = ContentBlock
|
|
|
|
|
# """DEPRECATED: Content is deprecated, you should use ContentBlock directly."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PromptMessage(BaseModel):
|
|
|
|
|
"""Describes a message returned as part of a prompt."""
|
|
|
|
|
|
|
|
|
|
role: Role
|
|
|
|
|
content: TextContent | ImageContent | EmbeddedResource
|
|
|
|
|
content: ContentBlock
|
|
|
|
|
model_config = ConfigDict(extra="allow")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -673,15 +764,14 @@ class PromptListChangedNotification(
|
|
|
|
|
of prompts it offers has changed.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
method: Literal["notifications/prompts/list_changed"]
|
|
|
|
|
method: Literal["notifications/prompts/list_changed"] = "notifications/prompts/list_changed"
|
|
|
|
|
params: NotificationParams | None = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ListToolsRequest(PaginatedRequest[RequestParams | None, Literal["tools/list"]]):
|
|
|
|
|
class ListToolsRequest(PaginatedRequest[Literal["tools/list"]]):
|
|
|
|
|
"""Sent from the client to request a list of tools the server has."""
|
|
|
|
|
|
|
|
|
|
method: Literal["tools/list"]
|
|
|
|
|
params: RequestParams | None = None
|
|
|
|
|
method: Literal["tools/list"] = "tools/list"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ToolAnnotations(BaseModel):
|
|
|
|
|
@ -732,17 +822,25 @@ class ToolAnnotations(BaseModel):
|
|
|
|
|
model_config = ConfigDict(extra="allow")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Tool(BaseModel):
|
|
|
|
|
class Tool(BaseMetadata):
|
|
|
|
|
"""Definition for a tool the client can call."""
|
|
|
|
|
|
|
|
|
|
name: str
|
|
|
|
|
"""The name of the tool."""
|
|
|
|
|
description: str | None = None
|
|
|
|
|
"""A human-readable description of the tool."""
|
|
|
|
|
inputSchema: dict[str, Any]
|
|
|
|
|
"""A JSON Schema object defining the expected parameters for the tool."""
|
|
|
|
|
outputSchema: dict[str, Any] | None = None
|
|
|
|
|
"""
|
|
|
|
|
An optional JSON Schema object defining the structure of the tool's output
|
|
|
|
|
returned in the structuredContent field of a CallToolResult.
|
|
|
|
|
"""
|
|
|
|
|
annotations: ToolAnnotations | None = None
|
|
|
|
|
"""Optional additional tool information."""
|
|
|
|
|
meta: dict[str, Any] | 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.
|
|
|
|
|
"""
|
|
|
|
|
model_config = ConfigDict(extra="allow")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -763,14 +861,16 @@ class CallToolRequestParams(RequestParams):
|
|
|
|
|
class CallToolRequest(Request[CallToolRequestParams, Literal["tools/call"]]):
|
|
|
|
|
"""Used by the client to invoke a tool provided by the server."""
|
|
|
|
|
|
|
|
|
|
method: Literal["tools/call"]
|
|
|
|
|
method: Literal["tools/call"] = "tools/call"
|
|
|
|
|
params: CallToolRequestParams
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CallToolResult(Result):
|
|
|
|
|
"""The server's response to a tool call."""
|
|
|
|
|
|
|
|
|
|
content: list[TextContent | ImageContent | EmbeddedResource]
|
|
|
|
|
content: list[ContentBlock]
|
|
|
|
|
structuredContent: dict[str, Any] | None = None
|
|
|
|
|
"""An optional JSON object that represents the structured result of the tool call."""
|
|
|
|
|
isError: bool = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -780,7 +880,7 @@ class ToolListChangedNotification(Notification[NotificationParams | None, Litera
|
|
|
|
|
of tools it offers has changed.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
method: Literal["notifications/tools/list_changed"]
|
|
|
|
|
method: Literal["notifications/tools/list_changed"] = "notifications/tools/list_changed"
|
|
|
|
|
params: NotificationParams | None = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -798,7 +898,7 @@ class SetLevelRequestParams(RequestParams):
|
|
|
|
|
class SetLevelRequest(Request[SetLevelRequestParams, Literal["logging/setLevel"]]):
|
|
|
|
|
"""A request from the client to the server, to enable or adjust logging."""
|
|
|
|
|
|
|
|
|
|
method: Literal["logging/setLevel"]
|
|
|
|
|
method: Literal["logging/setLevel"] = "logging/setLevel"
|
|
|
|
|
params: SetLevelRequestParams
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -809,7 +909,7 @@ class LoggingMessageNotificationParams(NotificationParams):
|
|
|
|
|
"""The severity of this log message."""
|
|
|
|
|
logger: str | None = None
|
|
|
|
|
"""An optional name of the logger issuing this message."""
|
|
|
|
|
data: Any = None
|
|
|
|
|
data: Any
|
|
|
|
|
"""
|
|
|
|
|
The data to be logged, such as a string message or an object. Any JSON serializable
|
|
|
|
|
type is allowed here.
|
|
|
|
|
@ -820,7 +920,7 @@ class LoggingMessageNotificationParams(NotificationParams):
|
|
|
|
|
class LoggingMessageNotification(Notification[LoggingMessageNotificationParams, Literal["notifications/message"]]):
|
|
|
|
|
"""Notification of a log message passed from server to client."""
|
|
|
|
|
|
|
|
|
|
method: Literal["notifications/message"]
|
|
|
|
|
method: Literal["notifications/message"] = "notifications/message"
|
|
|
|
|
params: LoggingMessageNotificationParams
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -915,7 +1015,7 @@ class CreateMessageRequestParams(RequestParams):
|
|
|
|
|
class CreateMessageRequest(Request[CreateMessageRequestParams, Literal["sampling/createMessage"]]):
|
|
|
|
|
"""A request from the server to sample an LLM via the client."""
|
|
|
|
|
|
|
|
|
|
method: Literal["sampling/createMessage"]
|
|
|
|
|
method: Literal["sampling/createMessage"] = "sampling/createMessage"
|
|
|
|
|
params: CreateMessageRequestParams
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -926,14 +1026,14 @@ class CreateMessageResult(Result):
|
|
|
|
|
"""The client's response to a sampling/create_message request from the server."""
|
|
|
|
|
|
|
|
|
|
role: Role
|
|
|
|
|
content: TextContent | ImageContent
|
|
|
|
|
content: TextContent | ImageContent | AudioContent
|
|
|
|
|
model: str
|
|
|
|
|
"""The name of the model that generated the message."""
|
|
|
|
|
stopReason: StopReason | None = None
|
|
|
|
|
"""The reason why sampling stopped, if known."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ResourceReference(BaseModel):
|
|
|
|
|
class ResourceTemplateReference(BaseModel):
|
|
|
|
|
"""A reference to a resource or resource template definition."""
|
|
|
|
|
|
|
|
|
|
type: Literal["ref/resource"]
|
|
|
|
|
@ -961,18 +1061,28 @@ class CompletionArgument(BaseModel):
|
|
|
|
|
model_config = ConfigDict(extra="allow")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CompletionContext(BaseModel):
|
|
|
|
|
"""Additional, optional context for completions."""
|
|
|
|
|
|
|
|
|
|
arguments: dict[str, str] | None = None
|
|
|
|
|
"""Previously-resolved variables in a URI template or prompt."""
|
|
|
|
|
model_config = ConfigDict(extra="allow")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CompleteRequestParams(RequestParams):
|
|
|
|
|
"""Parameters for completion requests."""
|
|
|
|
|
|
|
|
|
|
ref: ResourceReference | PromptReference
|
|
|
|
|
ref: ResourceTemplateReference | PromptReference
|
|
|
|
|
argument: CompletionArgument
|
|
|
|
|
context: CompletionContext | None = None
|
|
|
|
|
"""Additional, optional context for completions"""
|
|
|
|
|
model_config = ConfigDict(extra="allow")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CompleteRequest(Request[CompleteRequestParams, Literal["completion/complete"]]):
|
|
|
|
|
"""A request from the client to the server, to ask for completion options."""
|
|
|
|
|
|
|
|
|
|
method: Literal["completion/complete"]
|
|
|
|
|
method: Literal["completion/complete"] = "completion/complete"
|
|
|
|
|
params: CompleteRequestParams
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1011,7 +1121,7 @@ class ListRootsRequest(Request[RequestParams | None, Literal["roots/list"]]):
|
|
|
|
|
structure or access specific locations that the client has permission to read from.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
method: Literal["roots/list"]
|
|
|
|
|
method: Literal["roots/list"] = "roots/list"
|
|
|
|
|
params: RequestParams | None = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1030,6 +1140,11 @@ class Root(BaseModel):
|
|
|
|
|
identifier for the root, which may be useful for display purposes or for
|
|
|
|
|
referencing the root in other parts of the application.
|
|
|
|
|
"""
|
|
|
|
|
meta: dict[str, Any] | 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.
|
|
|
|
|
"""
|
|
|
|
|
model_config = ConfigDict(extra="allow")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1055,7 +1170,7 @@ class RootsListChangedNotification(
|
|
|
|
|
using the ListRootsRequest.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
method: Literal["notifications/roots/list_changed"]
|
|
|
|
|
method: Literal["notifications/roots/list_changed"] = "notifications/roots/list_changed"
|
|
|
|
|
params: NotificationParams | None = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1075,7 +1190,7 @@ class CancelledNotification(Notification[CancelledNotificationParams, Literal["n
|
|
|
|
|
previously-issued request.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
method: Literal["notifications/cancelled"]
|
|
|
|
|
method: Literal["notifications/cancelled"] = "notifications/cancelled"
|
|
|
|
|
params: CancelledNotificationParams
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|