refactor: introduce MCPModel base class for protocol types (#1880)
Co-authored-by: Max Isbey <224885523+maxisbey@users.noreply.github.com>
This commit is contained in:
parent
b63776b14f
commit
68cbabb9d7
1 changed files with 71 additions and 187 deletions
258
src/mcp/types.py
258
src/mcp/types.py
|
|
@ -28,20 +28,24 @@ TASK_OPTIONAL: Final[Literal["optional"]] = "optional"
|
||||||
TASK_REQUIRED: Final[Literal["required"]] = "required"
|
TASK_REQUIRED: Final[Literal["required"]] = "required"
|
||||||
|
|
||||||
|
|
||||||
class TaskMetadata(BaseModel):
|
class MCPModel(BaseModel):
|
||||||
|
"""Base class for all MCP protocol types. Allows extra fields for forward compatibility."""
|
||||||
|
|
||||||
|
model_config = ConfigDict(extra="allow")
|
||||||
|
|
||||||
|
|
||||||
|
class TaskMetadata(MCPModel):
|
||||||
"""
|
"""
|
||||||
Metadata for augmenting a request with task execution.
|
Metadata for augmenting a request with task execution.
|
||||||
Include this in the `task` field of the request parameters.
|
Include this in the `task` field of the request parameters.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
ttl: Annotated[int, Field(strict=True)] | None = None
|
ttl: Annotated[int, Field(strict=True)] | None = None
|
||||||
"""Requested duration in milliseconds to retain task from creation."""
|
"""Requested duration in milliseconds to retain task from creation."""
|
||||||
|
|
||||||
|
|
||||||
class RequestParams(BaseModel):
|
class RequestParams(MCPModel):
|
||||||
class Meta(BaseModel):
|
class Meta(MCPModel):
|
||||||
progressToken: ProgressToken | None = None
|
progressToken: ProgressToken | None = None
|
||||||
"""
|
"""
|
||||||
If specified, the caller requests out-of-band progress notifications for
|
If specified, the caller requests out-of-band progress notifications for
|
||||||
|
|
@ -50,8 +54,6 @@ class RequestParams(BaseModel):
|
||||||
notifications. The receiver is not obligated to provide these notifications.
|
notifications. The receiver is not obligated to provide these notifications.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
task: TaskMetadata | None = None
|
task: TaskMetadata | None = None
|
||||||
"""
|
"""
|
||||||
If specified, the caller is requesting task-augmented execution for this request.
|
If specified, the caller is requesting task-augmented execution for this request.
|
||||||
|
|
@ -73,9 +75,9 @@ class PaginatedRequestParams(RequestParams):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
class NotificationParams(BaseModel):
|
class NotificationParams(MCPModel):
|
||||||
class Meta(BaseModel):
|
class Meta(MCPModel):
|
||||||
model_config = ConfigDict(extra="allow")
|
pass
|
||||||
|
|
||||||
meta: Meta | None = Field(alias="_meta", default=None)
|
meta: Meta | None = Field(alias="_meta", default=None)
|
||||||
"""
|
"""
|
||||||
|
|
@ -89,12 +91,11 @@ NotificationParamsT = TypeVar("NotificationParamsT", bound=NotificationParams |
|
||||||
MethodT = TypeVar("MethodT", bound=str)
|
MethodT = TypeVar("MethodT", bound=str)
|
||||||
|
|
||||||
|
|
||||||
class Request(BaseModel, Generic[RequestParamsT, MethodT]):
|
class Request(MCPModel, Generic[RequestParamsT, MethodT]):
|
||||||
"""Base class for JSON-RPC requests."""
|
"""Base class for JSON-RPC requests."""
|
||||||
|
|
||||||
method: MethodT
|
method: MethodT
|
||||||
params: RequestParamsT
|
params: RequestParamsT
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class PaginatedRequest(Request[PaginatedRequestParams | None, MethodT], Generic[MethodT]):
|
class PaginatedRequest(Request[PaginatedRequestParams | None, MethodT], Generic[MethodT]):
|
||||||
|
|
@ -104,15 +105,14 @@ class PaginatedRequest(Request[PaginatedRequestParams | None, MethodT], Generic[
|
||||||
params: PaginatedRequestParams | None = None
|
params: PaginatedRequestParams | None = None
|
||||||
|
|
||||||
|
|
||||||
class Notification(BaseModel, Generic[NotificationParamsT, MethodT]):
|
class Notification(MCPModel, Generic[NotificationParamsT, MethodT]):
|
||||||
"""Base class for JSON-RPC notifications."""
|
"""Base class for JSON-RPC notifications."""
|
||||||
|
|
||||||
method: MethodT
|
method: MethodT
|
||||||
params: NotificationParamsT
|
params: NotificationParamsT
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class Result(BaseModel):
|
class Result(MCPModel):
|
||||||
"""Base class for JSON-RPC results."""
|
"""Base class for JSON-RPC results."""
|
||||||
|
|
||||||
meta: dict[str, Any] | None = Field(alias="_meta", default=None)
|
meta: dict[str, Any] | None = Field(alias="_meta", default=None)
|
||||||
|
|
@ -120,7 +120,6 @@ class Result(BaseModel):
|
||||||
See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
||||||
for notes on _meta usage.
|
for notes on _meta usage.
|
||||||
"""
|
"""
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class PaginatedResult(Result):
|
class PaginatedResult(Result):
|
||||||
|
|
@ -147,13 +146,12 @@ class JSONRPCNotification(Notification[dict[str, Any] | None, str]):
|
||||||
params: dict[str, Any] | None = None
|
params: dict[str, Any] | None = None
|
||||||
|
|
||||||
|
|
||||||
class JSONRPCResponse(BaseModel):
|
class JSONRPCResponse(MCPModel):
|
||||||
"""A successful (non-error) response to a request."""
|
"""A successful (non-error) response to a request."""
|
||||||
|
|
||||||
jsonrpc: Literal["2.0"]
|
jsonrpc: Literal["2.0"]
|
||||||
id: RequestId
|
id: RequestId
|
||||||
result: dict[str, Any]
|
result: dict[str, Any]
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
# MCP-specific error codes in the range [-32000, -32099]
|
# MCP-specific error codes in the range [-32000, -32099]
|
||||||
|
|
@ -172,7 +170,7 @@ INVALID_PARAMS = -32602
|
||||||
INTERNAL_ERROR = -32603
|
INTERNAL_ERROR = -32603
|
||||||
|
|
||||||
|
|
||||||
class ErrorData(BaseModel):
|
class ErrorData(MCPModel):
|
||||||
"""Error information for JSON-RPC error responses."""
|
"""Error information for JSON-RPC error responses."""
|
||||||
|
|
||||||
code: int
|
code: int
|
||||||
|
|
@ -190,16 +188,13 @@ class ErrorData(BaseModel):
|
||||||
sender (e.g. detailed error information, nested errors etc.).
|
sender (e.g. detailed error information, nested errors etc.).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
class JSONRPCError(MCPModel):
|
||||||
class JSONRPCError(BaseModel):
|
|
||||||
"""A response to a request that indicates an error occurred."""
|
"""A response to a request that indicates an error occurred."""
|
||||||
|
|
||||||
jsonrpc: Literal["2.0"]
|
jsonrpc: Literal["2.0"]
|
||||||
id: str | int
|
id: str | int
|
||||||
error: ErrorData
|
error: ErrorData
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class JSONRPCMessage(RootModel[JSONRPCRequest | JSONRPCNotification | JSONRPCResponse | JSONRPCError]):
|
class JSONRPCMessage(RootModel[JSONRPCRequest | JSONRPCNotification | JSONRPCResponse | JSONRPCError]):
|
||||||
|
|
@ -210,7 +205,7 @@ class EmptyResult(Result):
|
||||||
"""A response that indicates success but carries no data."""
|
"""A response that indicates success but carries no data."""
|
||||||
|
|
||||||
|
|
||||||
class BaseMetadata(BaseModel):
|
class BaseMetadata(MCPModel):
|
||||||
"""Base class for entities with name and optional title fields."""
|
"""Base class for entities with name and optional title fields."""
|
||||||
|
|
||||||
name: str
|
name: str
|
||||||
|
|
@ -227,7 +222,7 @@ class BaseMetadata(BaseModel):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
class Icon(BaseModel):
|
class Icon(MCPModel):
|
||||||
"""An icon for display in user interfaces."""
|
"""An icon for display in user interfaces."""
|
||||||
|
|
||||||
src: str
|
src: str
|
||||||
|
|
@ -239,8 +234,6 @@ class Icon(BaseModel):
|
||||||
sizes: list[str] | None = None
|
sizes: list[str] | None = None
|
||||||
"""Optional list of strings specifying icon dimensions (e.g., ["48x48", "96x96"])."""
|
"""Optional list of strings specifying icon dimensions (e.g., ["48x48", "96x96"])."""
|
||||||
|
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class Implementation(BaseMetadata):
|
class Implementation(BaseMetadata):
|
||||||
"""Describes the name and version of an MCP implementation."""
|
"""Describes the name and version of an MCP implementation."""
|
||||||
|
|
@ -259,18 +252,15 @@ class Implementation(BaseMetadata):
|
||||||
icons: list[Icon] | None = None
|
icons: list[Icon] | None = None
|
||||||
"""An optional list of icons for this implementation."""
|
"""An optional list of icons for this implementation."""
|
||||||
|
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
class RootsCapability(MCPModel):
|
||||||
class RootsCapability(BaseModel):
|
|
||||||
"""Capability for root operations."""
|
"""Capability for root operations."""
|
||||||
|
|
||||||
listChanged: bool | None = None
|
listChanged: bool | None = None
|
||||||
"""Whether the client supports notifications for changes to the roots list."""
|
"""Whether the client supports notifications for changes to the roots list."""
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class SamplingContextCapability(BaseModel):
|
class SamplingContextCapability(MCPModel):
|
||||||
"""
|
"""
|
||||||
Capability for context inclusion during sampling.
|
Capability for context inclusion during sampling.
|
||||||
|
|
||||||
|
|
@ -278,10 +268,8 @@ class SamplingContextCapability(BaseModel):
|
||||||
SOFT-DEPRECATED: New implementations should use tools parameter instead.
|
SOFT-DEPRECATED: New implementations should use tools parameter instead.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
class SamplingToolsCapability(MCPModel):
|
||||||
class SamplingToolsCapability(BaseModel):
|
|
||||||
"""
|
"""
|
||||||
Capability indicating support for tool calling during sampling.
|
Capability indicating support for tool calling during sampling.
|
||||||
|
|
||||||
|
|
@ -289,22 +277,16 @@ class SamplingToolsCapability(BaseModel):
|
||||||
supports the tools and toolChoice parameters in sampling requests.
|
supports the tools and toolChoice parameters in sampling requests.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
class FormElicitationCapability(MCPModel):
|
||||||
class FormElicitationCapability(BaseModel):
|
|
||||||
"""Capability for form mode elicitation."""
|
"""Capability for form mode elicitation."""
|
||||||
|
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
class UrlElicitationCapability(MCPModel):
|
||||||
class UrlElicitationCapability(BaseModel):
|
|
||||||
"""Capability for URL mode elicitation."""
|
"""Capability for URL mode elicitation."""
|
||||||
|
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
class ElicitationCapability(MCPModel):
|
||||||
class ElicitationCapability(BaseModel):
|
|
||||||
"""Capability for elicitation operations.
|
"""Capability for elicitation operations.
|
||||||
|
|
||||||
Clients must support at least one mode (form or url).
|
Clients must support at least one mode (form or url).
|
||||||
|
|
@ -316,10 +298,8 @@ class ElicitationCapability(BaseModel):
|
||||||
url: UrlElicitationCapability | None = None
|
url: UrlElicitationCapability | None = None
|
||||||
"""Present if the client supports URL mode elicitation."""
|
"""Present if the client supports URL mode elicitation."""
|
||||||
|
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
class SamplingCapability(MCPModel):
|
||||||
class SamplingCapability(BaseModel):
|
|
||||||
"""
|
"""
|
||||||
Sampling capability structure, allowing fine-grained capability advertisement.
|
Sampling capability structure, allowing fine-grained capability advertisement.
|
||||||
"""
|
"""
|
||||||
|
|
@ -334,64 +314,47 @@ class SamplingCapability(BaseModel):
|
||||||
Present if the client supports tools and toolChoice parameters in sampling requests.
|
Present if the client supports tools and toolChoice parameters in sampling requests.
|
||||||
Presence indicates full tool calling support during sampling.
|
Presence indicates full tool calling support during sampling.
|
||||||
"""
|
"""
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class TasksListCapability(BaseModel):
|
class TasksListCapability(MCPModel):
|
||||||
"""Capability for tasks listing operations."""
|
"""Capability for tasks listing operations."""
|
||||||
|
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
class TasksCancelCapability(MCPModel):
|
||||||
class TasksCancelCapability(BaseModel):
|
|
||||||
"""Capability for tasks cancel operations."""
|
"""Capability for tasks cancel operations."""
|
||||||
|
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
class TasksCreateMessageCapability(MCPModel):
|
||||||
class TasksCreateMessageCapability(BaseModel):
|
|
||||||
"""Capability for tasks create messages."""
|
"""Capability for tasks create messages."""
|
||||||
|
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
class TasksSamplingCapability(MCPModel):
|
||||||
class TasksSamplingCapability(BaseModel):
|
|
||||||
"""Capability for tasks sampling operations."""
|
"""Capability for tasks sampling operations."""
|
||||||
|
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
createMessage: TasksCreateMessageCapability | None = None
|
createMessage: TasksCreateMessageCapability | None = None
|
||||||
|
|
||||||
|
|
||||||
class TasksCreateElicitationCapability(BaseModel):
|
class TasksCreateElicitationCapability(MCPModel):
|
||||||
"""Capability for tasks create elicitation operations."""
|
"""Capability for tasks create elicitation operations."""
|
||||||
|
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
class TasksElicitationCapability(MCPModel):
|
||||||
class TasksElicitationCapability(BaseModel):
|
|
||||||
"""Capability for tasks elicitation operations."""
|
"""Capability for tasks elicitation operations."""
|
||||||
|
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
create: TasksCreateElicitationCapability | None = None
|
create: TasksCreateElicitationCapability | None = None
|
||||||
|
|
||||||
|
|
||||||
class ClientTasksRequestsCapability(BaseModel):
|
class ClientTasksRequestsCapability(MCPModel):
|
||||||
"""Capability for tasks requests operations."""
|
"""Capability for tasks requests operations."""
|
||||||
|
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
sampling: TasksSamplingCapability | None = None
|
sampling: TasksSamplingCapability | None = None
|
||||||
|
|
||||||
elicitation: TasksElicitationCapability | None = None
|
elicitation: TasksElicitationCapability | None = None
|
||||||
|
|
||||||
|
|
||||||
class ClientTasksCapability(BaseModel):
|
class ClientTasksCapability(MCPModel):
|
||||||
"""Capability for client tasks operations."""
|
"""Capability for client tasks operations."""
|
||||||
|
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
list: TasksListCapability | None = None
|
list: TasksListCapability | None = None
|
||||||
"""Whether this client supports tasks/list."""
|
"""Whether this client supports tasks/list."""
|
||||||
|
|
||||||
|
|
@ -402,7 +365,7 @@ class ClientTasksCapability(BaseModel):
|
||||||
"""Specifies which request types can be augmented with tasks."""
|
"""Specifies which request types can be augmented with tasks."""
|
||||||
|
|
||||||
|
|
||||||
class ClientCapabilities(BaseModel):
|
class ClientCapabilities(MCPModel):
|
||||||
"""Capabilities a client may support."""
|
"""Capabilities a client may support."""
|
||||||
|
|
||||||
experimental: dict[str, dict[str, Any]] | None = None
|
experimental: dict[str, dict[str, Any]] | None = None
|
||||||
|
|
@ -419,79 +382,63 @@ class ClientCapabilities(BaseModel):
|
||||||
tasks: ClientTasksCapability | None = None
|
tasks: ClientTasksCapability | None = None
|
||||||
"""Present if the client supports task-augmented requests."""
|
"""Present if the client supports task-augmented requests."""
|
||||||
|
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
class PromptsCapability(MCPModel):
|
||||||
class PromptsCapability(BaseModel):
|
|
||||||
"""Capability for prompts operations."""
|
"""Capability for prompts operations."""
|
||||||
|
|
||||||
listChanged: bool | None = None
|
listChanged: bool | None = None
|
||||||
"""Whether this server supports notifications for changes to the prompt list."""
|
"""Whether this server supports notifications for changes to the prompt list."""
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class ResourcesCapability(BaseModel):
|
class ResourcesCapability(MCPModel):
|
||||||
"""Capability for resources operations."""
|
"""Capability for resources operations."""
|
||||||
|
|
||||||
subscribe: bool | None = None
|
subscribe: bool | None = None
|
||||||
"""Whether this server supports subscribing to resource updates."""
|
"""Whether this server supports subscribing to resource updates."""
|
||||||
listChanged: bool | None = None
|
listChanged: bool | None = None
|
||||||
"""Whether this server supports notifications for changes to the resource list."""
|
"""Whether this server supports notifications for changes to the resource list."""
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class ToolsCapability(BaseModel):
|
class ToolsCapability(MCPModel):
|
||||||
"""Capability for tools operations."""
|
"""Capability for tools operations."""
|
||||||
|
|
||||||
listChanged: bool | None = None
|
listChanged: bool | None = None
|
||||||
"""Whether this server supports notifications for changes to the tool list."""
|
"""Whether this server supports notifications for changes to the tool list."""
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class LoggingCapability(BaseModel):
|
class LoggingCapability(MCPModel):
|
||||||
"""Capability for logging operations."""
|
"""Capability for logging operations."""
|
||||||
|
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
class CompletionsCapability(MCPModel):
|
||||||
class CompletionsCapability(BaseModel):
|
|
||||||
"""Capability for completions operations."""
|
"""Capability for completions operations."""
|
||||||
|
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
class TasksCallCapability(MCPModel):
|
||||||
class TasksCallCapability(BaseModel):
|
|
||||||
"""Capability for tasks call operations."""
|
"""Capability for tasks call operations."""
|
||||||
|
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
class TasksToolsCapability(MCPModel):
|
||||||
class TasksToolsCapability(BaseModel):
|
|
||||||
"""Capability for tasks tools operations."""
|
"""Capability for tasks tools operations."""
|
||||||
|
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
call: TasksCallCapability | None = None
|
call: TasksCallCapability | None = None
|
||||||
|
|
||||||
|
|
||||||
class ServerTasksRequestsCapability(BaseModel):
|
class ServerTasksRequestsCapability(MCPModel):
|
||||||
"""Capability for tasks requests operations."""
|
"""Capability for tasks requests operations."""
|
||||||
|
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
tools: TasksToolsCapability | None = None
|
tools: TasksToolsCapability | None = None
|
||||||
|
|
||||||
|
|
||||||
class ServerTasksCapability(BaseModel):
|
class ServerTasksCapability(MCPModel):
|
||||||
"""Capability for server tasks operations."""
|
"""Capability for server tasks operations."""
|
||||||
|
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
list: TasksListCapability | None = None
|
list: TasksListCapability | None = None
|
||||||
cancel: TasksCancelCapability | None = None
|
cancel: TasksCancelCapability | None = None
|
||||||
requests: ServerTasksRequestsCapability | None = None
|
requests: ServerTasksRequestsCapability | None = None
|
||||||
|
|
||||||
|
|
||||||
class ServerCapabilities(BaseModel):
|
class ServerCapabilities(MCPModel):
|
||||||
"""Capabilities that a server may support."""
|
"""Capabilities that a server may support."""
|
||||||
|
|
||||||
experimental: dict[str, dict[str, Any]] | None = None
|
experimental: dict[str, dict[str, Any]] | None = None
|
||||||
|
|
@ -508,7 +455,6 @@ class ServerCapabilities(BaseModel):
|
||||||
"""Present if the server offers autocompletion suggestions for prompts and resources."""
|
"""Present if the server offers autocompletion suggestions for prompts and resources."""
|
||||||
tasks: ServerTasksCapability | None = None
|
tasks: ServerTasksCapability | None = None
|
||||||
"""Present if the server supports task-augmented requests."""
|
"""Present if the server supports task-augmented requests."""
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
TaskStatus = Literal["working", "input_required", "completed", "failed", "cancelled"]
|
TaskStatus = Literal["working", "input_required", "completed", "failed", "cancelled"]
|
||||||
|
|
@ -521,23 +467,20 @@ TASK_STATUS_FAILED: Final[Literal["failed"]] = "failed"
|
||||||
TASK_STATUS_CANCELLED: Final[Literal["cancelled"]] = "cancelled"
|
TASK_STATUS_CANCELLED: Final[Literal["cancelled"]] = "cancelled"
|
||||||
|
|
||||||
|
|
||||||
class RelatedTaskMetadata(BaseModel):
|
class RelatedTaskMetadata(MCPModel):
|
||||||
"""
|
"""
|
||||||
Metadata for associating messages with a task.
|
Metadata for associating messages with a task.
|
||||||
|
|
||||||
Include this in the `_meta` field under the key `io.modelcontextprotocol/related-task`.
|
Include this in the `_meta` field under the key `io.modelcontextprotocol/related-task`.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
taskId: str
|
taskId: str
|
||||||
"""The task identifier this message is associated with."""
|
"""The task identifier this message is associated with."""
|
||||||
|
|
||||||
|
|
||||||
class Task(BaseModel):
|
class Task(MCPModel):
|
||||||
"""Data associated with a task."""
|
"""Data associated with a task."""
|
||||||
|
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
taskId: str
|
taskId: str
|
||||||
"""The task identifier."""
|
"""The task identifier."""
|
||||||
|
|
||||||
|
|
@ -573,7 +516,6 @@ class CreateTaskResult(Result):
|
||||||
|
|
||||||
|
|
||||||
class GetTaskRequestParams(RequestParams):
|
class GetTaskRequestParams(RequestParams):
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
taskId: str
|
taskId: str
|
||||||
"""The task identifier to query."""
|
"""The task identifier to query."""
|
||||||
|
|
||||||
|
|
@ -591,8 +533,6 @@ class GetTaskResult(Result, Task):
|
||||||
|
|
||||||
|
|
||||||
class GetTaskPayloadRequestParams(RequestParams):
|
class GetTaskPayloadRequestParams(RequestParams):
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
taskId: str
|
taskId: str
|
||||||
"""The task identifier to retrieve results for."""
|
"""The task identifier to retrieve results for."""
|
||||||
|
|
||||||
|
|
@ -613,8 +553,6 @@ class GetTaskPayloadResult(Result):
|
||||||
|
|
||||||
|
|
||||||
class CancelTaskRequestParams(RequestParams):
|
class CancelTaskRequestParams(RequestParams):
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
taskId: str
|
taskId: str
|
||||||
"""The task identifier to cancel."""
|
"""The task identifier to cancel."""
|
||||||
|
|
||||||
|
|
@ -663,7 +601,6 @@ class InitializeRequestParams(RequestParams):
|
||||||
"""The latest version of the Model Context Protocol that the client supports."""
|
"""The latest version of the Model Context Protocol that the client supports."""
|
||||||
capabilities: ClientCapabilities
|
capabilities: ClientCapabilities
|
||||||
clientInfo: Implementation
|
clientInfo: Implementation
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class InitializeRequest(Request[InitializeRequestParams, Literal["initialize"]]):
|
class InitializeRequest(Request[InitializeRequestParams, Literal["initialize"]]):
|
||||||
|
|
@ -727,7 +664,6 @@ class ProgressNotificationParams(NotificationParams):
|
||||||
Message related to progress. This should provide relevant human readable
|
Message related to progress. This should provide relevant human readable
|
||||||
progress information.
|
progress information.
|
||||||
"""
|
"""
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class ProgressNotification(Notification[ProgressNotificationParams, Literal["notifications/progress"]]):
|
class ProgressNotification(Notification[ProgressNotificationParams, Literal["notifications/progress"]]):
|
||||||
|
|
@ -746,10 +682,9 @@ class ListResourcesRequest(PaginatedRequest[Literal["resources/list"]]):
|
||||||
method: Literal["resources/list"] = "resources/list"
|
method: Literal["resources/list"] = "resources/list"
|
||||||
|
|
||||||
|
|
||||||
class Annotations(BaseModel):
|
class Annotations(MCPModel):
|
||||||
audience: list[Role] | None = None
|
audience: list[Role] | None = None
|
||||||
priority: Annotated[float, Field(ge=0.0, le=1.0)] | None = None
|
priority: Annotated[float, Field(ge=0.0, le=1.0)] | None = None
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class Resource(BaseMetadata):
|
class Resource(BaseMetadata):
|
||||||
|
|
@ -776,7 +711,6 @@ class Resource(BaseMetadata):
|
||||||
See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
||||||
for notes on _meta usage.
|
for notes on _meta usage.
|
||||||
"""
|
"""
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class ResourceTemplate(BaseMetadata):
|
class ResourceTemplate(BaseMetadata):
|
||||||
|
|
@ -802,7 +736,6 @@ class ResourceTemplate(BaseMetadata):
|
||||||
See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
||||||
for notes on _meta usage.
|
for notes on _meta usage.
|
||||||
"""
|
"""
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class ListResourcesResult(PaginatedResult):
|
class ListResourcesResult(PaginatedResult):
|
||||||
|
|
@ -831,7 +764,6 @@ class ReadResourceRequestParams(RequestParams):
|
||||||
The URI of the resource to read. The URI can use any protocol; it is up to the
|
The URI of the resource to read. The URI can use any protocol; it is up to the
|
||||||
server how to interpret it.
|
server how to interpret it.
|
||||||
"""
|
"""
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class ReadResourceRequest(Request[ReadResourceRequestParams, Literal["resources/read"]]):
|
class ReadResourceRequest(Request[ReadResourceRequestParams, Literal["resources/read"]]):
|
||||||
|
|
@ -841,7 +773,7 @@ class ReadResourceRequest(Request[ReadResourceRequestParams, Literal["resources/
|
||||||
params: ReadResourceRequestParams
|
params: ReadResourceRequestParams
|
||||||
|
|
||||||
|
|
||||||
class ResourceContents(BaseModel):
|
class ResourceContents(MCPModel):
|
||||||
"""The contents of a specific resource or sub-resource."""
|
"""The contents of a specific resource or sub-resource."""
|
||||||
|
|
||||||
uri: str
|
uri: str
|
||||||
|
|
@ -853,7 +785,6 @@ class ResourceContents(BaseModel):
|
||||||
See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
||||||
for notes on _meta usage.
|
for notes on _meta usage.
|
||||||
"""
|
"""
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class TextResourceContents(ResourceContents):
|
class TextResourceContents(ResourceContents):
|
||||||
|
|
@ -899,7 +830,6 @@ class SubscribeRequestParams(RequestParams):
|
||||||
The URI of the resource to subscribe to. The URI can use any protocol; it is up to
|
The URI of the resource to subscribe to. The URI can use any protocol; it is up to
|
||||||
the server how to interpret it.
|
the server how to interpret it.
|
||||||
"""
|
"""
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class SubscribeRequest(Request[SubscribeRequestParams, Literal["resources/subscribe"]]):
|
class SubscribeRequest(Request[SubscribeRequestParams, Literal["resources/subscribe"]]):
|
||||||
|
|
@ -917,7 +847,6 @@ class UnsubscribeRequestParams(RequestParams):
|
||||||
|
|
||||||
uri: str
|
uri: str
|
||||||
"""The URI of the resource to unsubscribe from."""
|
"""The URI of the resource to unsubscribe from."""
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class UnsubscribeRequest(Request[UnsubscribeRequestParams, Literal["resources/unsubscribe"]]):
|
class UnsubscribeRequest(Request[UnsubscribeRequestParams, Literal["resources/unsubscribe"]]):
|
||||||
|
|
@ -938,7 +867,6 @@ class ResourceUpdatedNotificationParams(NotificationParams):
|
||||||
The URI of the resource that has been updated. This might be a sub-resource of the
|
The URI of the resource that has been updated. This might be a sub-resource of the
|
||||||
one that the client actually subscribed to.
|
one that the client actually subscribed to.
|
||||||
"""
|
"""
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class ResourceUpdatedNotification(
|
class ResourceUpdatedNotification(
|
||||||
|
|
@ -959,7 +887,7 @@ class ListPromptsRequest(PaginatedRequest[Literal["prompts/list"]]):
|
||||||
method: Literal["prompts/list"] = "prompts/list"
|
method: Literal["prompts/list"] = "prompts/list"
|
||||||
|
|
||||||
|
|
||||||
class PromptArgument(BaseModel):
|
class PromptArgument(MCPModel):
|
||||||
"""An argument for a prompt template."""
|
"""An argument for a prompt template."""
|
||||||
|
|
||||||
name: str
|
name: str
|
||||||
|
|
@ -968,7 +896,6 @@ class PromptArgument(BaseModel):
|
||||||
"""A human-readable description of the argument."""
|
"""A human-readable description of the argument."""
|
||||||
required: bool | None = None
|
required: bool | None = None
|
||||||
"""Whether this argument must be provided."""
|
"""Whether this argument must be provided."""
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class Prompt(BaseMetadata):
|
class Prompt(BaseMetadata):
|
||||||
|
|
@ -985,7 +912,6 @@ class Prompt(BaseMetadata):
|
||||||
See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
||||||
for notes on _meta usage.
|
for notes on _meta usage.
|
||||||
"""
|
"""
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class ListPromptsResult(PaginatedResult):
|
class ListPromptsResult(PaginatedResult):
|
||||||
|
|
@ -1001,7 +927,6 @@ class GetPromptRequestParams(RequestParams):
|
||||||
"""The name of the prompt or prompt template."""
|
"""The name of the prompt or prompt template."""
|
||||||
arguments: dict[str, str] | None = None
|
arguments: dict[str, str] | None = None
|
||||||
"""Arguments to use for templating the prompt."""
|
"""Arguments to use for templating the prompt."""
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class GetPromptRequest(Request[GetPromptRequestParams, Literal["prompts/get"]]):
|
class GetPromptRequest(Request[GetPromptRequestParams, Literal["prompts/get"]]):
|
||||||
|
|
@ -1011,7 +936,7 @@ class GetPromptRequest(Request[GetPromptRequestParams, Literal["prompts/get"]]):
|
||||||
params: GetPromptRequestParams
|
params: GetPromptRequestParams
|
||||||
|
|
||||||
|
|
||||||
class TextContent(BaseModel):
|
class TextContent(MCPModel):
|
||||||
"""Text content for a message."""
|
"""Text content for a message."""
|
||||||
|
|
||||||
type: Literal["text"]
|
type: Literal["text"]
|
||||||
|
|
@ -1023,10 +948,9 @@ class TextContent(BaseModel):
|
||||||
See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
||||||
for notes on _meta usage.
|
for notes on _meta usage.
|
||||||
"""
|
"""
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class ImageContent(BaseModel):
|
class ImageContent(MCPModel):
|
||||||
"""Image content for a message."""
|
"""Image content for a message."""
|
||||||
|
|
||||||
type: Literal["image"]
|
type: Literal["image"]
|
||||||
|
|
@ -1043,10 +967,9 @@ class ImageContent(BaseModel):
|
||||||
See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
||||||
for notes on _meta usage.
|
for notes on _meta usage.
|
||||||
"""
|
"""
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class AudioContent(BaseModel):
|
class AudioContent(MCPModel):
|
||||||
"""Audio content for a message."""
|
"""Audio content for a message."""
|
||||||
|
|
||||||
type: Literal["audio"]
|
type: Literal["audio"]
|
||||||
|
|
@ -1063,10 +986,9 @@ class AudioContent(BaseModel):
|
||||||
See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
||||||
for notes on _meta usage.
|
for notes on _meta usage.
|
||||||
"""
|
"""
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class ToolUseContent(BaseModel):
|
class ToolUseContent(MCPModel):
|
||||||
"""
|
"""
|
||||||
Content representing an assistant's request to invoke a tool.
|
Content representing an assistant's request to invoke a tool.
|
||||||
|
|
||||||
|
|
@ -1092,10 +1014,9 @@ class ToolUseContent(BaseModel):
|
||||||
See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
||||||
for notes on _meta usage.
|
for notes on _meta usage.
|
||||||
"""
|
"""
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class ToolResultContent(BaseModel):
|
class ToolResultContent(MCPModel):
|
||||||
"""
|
"""
|
||||||
Content representing the result of a tool execution.
|
Content representing the result of a tool execution.
|
||||||
|
|
||||||
|
|
@ -1128,7 +1049,6 @@ class ToolResultContent(BaseModel):
|
||||||
See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
||||||
for notes on _meta usage.
|
for notes on _meta usage.
|
||||||
"""
|
"""
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
SamplingMessageContentBlock: TypeAlias = TextContent | ImageContent | AudioContent | ToolUseContent | ToolResultContent
|
SamplingMessageContentBlock: TypeAlias = TextContent | ImageContent | AudioContent | ToolUseContent | ToolResultContent
|
||||||
|
|
@ -1139,7 +1059,7 @@ SamplingContent: TypeAlias = TextContent | ImageContent | AudioContent
|
||||||
Used for backwards-compatible CreateMessageResult when tools are not used."""
|
Used for backwards-compatible CreateMessageResult when tools are not used."""
|
||||||
|
|
||||||
|
|
||||||
class SamplingMessage(BaseModel):
|
class SamplingMessage(MCPModel):
|
||||||
"""Describes a message issued to or received from an LLM API."""
|
"""Describes a message issued to or received from an LLM API."""
|
||||||
|
|
||||||
role: Role
|
role: Role
|
||||||
|
|
@ -1153,7 +1073,6 @@ class SamplingMessage(BaseModel):
|
||||||
See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
||||||
for notes on _meta usage.
|
for notes on _meta usage.
|
||||||
"""
|
"""
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def content_as_list(self) -> list[SamplingMessageContentBlock]:
|
def content_as_list(self) -> list[SamplingMessageContentBlock]:
|
||||||
|
|
@ -1162,7 +1081,7 @@ class SamplingMessage(BaseModel):
|
||||||
return self.content if isinstance(self.content, list) else [self.content]
|
return self.content if isinstance(self.content, list) else [self.content]
|
||||||
|
|
||||||
|
|
||||||
class EmbeddedResource(BaseModel):
|
class EmbeddedResource(MCPModel):
|
||||||
"""
|
"""
|
||||||
The contents of a resource, embedded into a prompt or tool call result.
|
The contents of a resource, embedded into a prompt or tool call result.
|
||||||
|
|
||||||
|
|
@ -1178,7 +1097,6 @@ class EmbeddedResource(BaseModel):
|
||||||
See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
||||||
for notes on _meta usage.
|
for notes on _meta usage.
|
||||||
"""
|
"""
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class ResourceLink(Resource):
|
class ResourceLink(Resource):
|
||||||
|
|
@ -1195,12 +1113,11 @@ ContentBlock = TextContent | ImageContent | AudioContent | ResourceLink | Embedd
|
||||||
"""A content block that can be used in prompts and tool results."""
|
"""A content block that can be used in prompts and tool results."""
|
||||||
|
|
||||||
|
|
||||||
class PromptMessage(BaseModel):
|
class PromptMessage(MCPModel):
|
||||||
"""Describes a message returned as part of a prompt."""
|
"""Describes a message returned as part of a prompt."""
|
||||||
|
|
||||||
role: Role
|
role: Role
|
||||||
content: ContentBlock
|
content: ContentBlock
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class GetPromptResult(Result):
|
class GetPromptResult(Result):
|
||||||
|
|
@ -1229,7 +1146,7 @@ class ListToolsRequest(PaginatedRequest[Literal["tools/list"]]):
|
||||||
method: Literal["tools/list"] = "tools/list"
|
method: Literal["tools/list"] = "tools/list"
|
||||||
|
|
||||||
|
|
||||||
class ToolAnnotations(BaseModel):
|
class ToolAnnotations(MCPModel):
|
||||||
"""
|
"""
|
||||||
Additional properties describing a Tool to clients.
|
Additional properties describing a Tool to clients.
|
||||||
|
|
||||||
|
|
@ -1275,14 +1192,10 @@ class ToolAnnotations(BaseModel):
|
||||||
Default: true
|
Default: true
|
||||||
"""
|
"""
|
||||||
|
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
class ToolExecution(MCPModel):
|
||||||
class ToolExecution(BaseModel):
|
|
||||||
"""Execution-related properties for a tool."""
|
"""Execution-related properties for a tool."""
|
||||||
|
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
taskSupport: TaskExecutionMode | None = None
|
taskSupport: TaskExecutionMode | None = None
|
||||||
"""
|
"""
|
||||||
Indicates whether this tool supports task-augmented execution.
|
Indicates whether this tool supports task-augmented execution.
|
||||||
|
|
@ -1321,8 +1234,6 @@ class Tool(BaseMetadata):
|
||||||
|
|
||||||
execution: ToolExecution | None = None
|
execution: ToolExecution | None = None
|
||||||
|
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class ListToolsResult(PaginatedResult):
|
class ListToolsResult(PaginatedResult):
|
||||||
"""The server's response to a tools/list request from the client."""
|
"""The server's response to a tools/list request from the client."""
|
||||||
|
|
@ -1335,7 +1246,6 @@ class CallToolRequestParams(RequestParams):
|
||||||
|
|
||||||
name: str
|
name: str
|
||||||
arguments: dict[str, Any] | None = None
|
arguments: dict[str, Any] | None = None
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class CallToolRequest(Request[CallToolRequestParams, Literal["tools/call"]]):
|
class CallToolRequest(Request[CallToolRequestParams, Literal["tools/call"]]):
|
||||||
|
|
@ -1372,7 +1282,6 @@ class SetLevelRequestParams(RequestParams):
|
||||||
|
|
||||||
level: LoggingLevel
|
level: LoggingLevel
|
||||||
"""The level of logging that the client wants to receive from the server."""
|
"""The level of logging that the client wants to receive from the server."""
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class SetLevelRequest(Request[SetLevelRequestParams, Literal["logging/setLevel"]]):
|
class SetLevelRequest(Request[SetLevelRequestParams, Literal["logging/setLevel"]]):
|
||||||
|
|
@ -1394,7 +1303,6 @@ class LoggingMessageNotificationParams(NotificationParams):
|
||||||
The data to be logged, such as a string message or an object. Any JSON serializable
|
The data to be logged, such as a string message or an object. Any JSON serializable
|
||||||
type is allowed here.
|
type is allowed here.
|
||||||
"""
|
"""
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class LoggingMessageNotification(Notification[LoggingMessageNotificationParams, Literal["notifications/message"]]):
|
class LoggingMessageNotification(Notification[LoggingMessageNotificationParams, Literal["notifications/message"]]):
|
||||||
|
|
@ -1407,16 +1315,14 @@ class LoggingMessageNotification(Notification[LoggingMessageNotificationParams,
|
||||||
IncludeContext = Literal["none", "thisServer", "allServers"]
|
IncludeContext = Literal["none", "thisServer", "allServers"]
|
||||||
|
|
||||||
|
|
||||||
class ModelHint(BaseModel):
|
class ModelHint(MCPModel):
|
||||||
"""Hints to use for model selection."""
|
"""Hints to use for model selection."""
|
||||||
|
|
||||||
name: str | None = None
|
name: str | None = None
|
||||||
"""A hint for a model name."""
|
"""A hint for a model name."""
|
||||||
|
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
class ModelPreferences(MCPModel):
|
||||||
class ModelPreferences(BaseModel):
|
|
||||||
"""
|
"""
|
||||||
The server's preferences for model selection, requested by the client during
|
The server's preferences for model selection, requested by the client during
|
||||||
sampling.
|
sampling.
|
||||||
|
|
@ -1464,10 +1370,8 @@ class ModelPreferences(BaseModel):
|
||||||
means intelligence is the most important factor.
|
means intelligence is the most important factor.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
class ToolChoice(MCPModel):
|
||||||
class ToolChoice(BaseModel):
|
|
||||||
"""
|
"""
|
||||||
Controls tool usage behavior during sampling.
|
Controls tool usage behavior during sampling.
|
||||||
|
|
||||||
|
|
@ -1483,8 +1387,6 @@ class ToolChoice(BaseModel):
|
||||||
- "none": Model should not use tools
|
- "none": Model should not use tools
|
||||||
"""
|
"""
|
||||||
|
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class CreateMessageRequestParams(RequestParams):
|
class CreateMessageRequestParams(RequestParams):
|
||||||
"""Parameters for creating a message."""
|
"""Parameters for creating a message."""
|
||||||
|
|
@ -1518,7 +1420,6 @@ class CreateMessageRequestParams(RequestParams):
|
||||||
Controls tool usage behavior.
|
Controls tool usage behavior.
|
||||||
Requires clientCapabilities.sampling.tools and the tools parameter to be present.
|
Requires clientCapabilities.sampling.tools and the tools parameter to be present.
|
||||||
"""
|
"""
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class CreateMessageRequest(Request[CreateMessageRequestParams, Literal["sampling/createMessage"]]):
|
class CreateMessageRequest(Request[CreateMessageRequestParams, Literal["sampling/createMessage"]]):
|
||||||
|
|
@ -1576,40 +1477,36 @@ class CreateMessageResultWithTools(Result):
|
||||||
return self.content if isinstance(self.content, list) else [self.content]
|
return self.content if isinstance(self.content, list) else [self.content]
|
||||||
|
|
||||||
|
|
||||||
class ResourceTemplateReference(BaseModel):
|
class ResourceTemplateReference(MCPModel):
|
||||||
"""A reference to a resource or resource template definition."""
|
"""A reference to a resource or resource template definition."""
|
||||||
|
|
||||||
type: Literal["ref/resource"]
|
type: Literal["ref/resource"]
|
||||||
uri: str
|
uri: str
|
||||||
"""The URI or URI template of the resource."""
|
"""The URI or URI template of the resource."""
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class PromptReference(BaseModel):
|
class PromptReference(MCPModel):
|
||||||
"""Identifies a prompt."""
|
"""Identifies a prompt."""
|
||||||
|
|
||||||
type: Literal["ref/prompt"]
|
type: Literal["ref/prompt"]
|
||||||
name: str
|
name: str
|
||||||
"""The name of the prompt or prompt template"""
|
"""The name of the prompt or prompt template"""
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class CompletionArgument(BaseModel):
|
class CompletionArgument(MCPModel):
|
||||||
"""The argument's information for completion requests."""
|
"""The argument's information for completion requests."""
|
||||||
|
|
||||||
name: str
|
name: str
|
||||||
"""The name of the argument"""
|
"""The name of the argument"""
|
||||||
value: str
|
value: str
|
||||||
"""The value of the argument to use for completion matching."""
|
"""The value of the argument to use for completion matching."""
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class CompletionContext(BaseModel):
|
class CompletionContext(MCPModel):
|
||||||
"""Additional, optional context for completions."""
|
"""Additional, optional context for completions."""
|
||||||
|
|
||||||
arguments: dict[str, str] | None = None
|
arguments: dict[str, str] | None = None
|
||||||
"""Previously-resolved variables in a URI template or prompt."""
|
"""Previously-resolved variables in a URI template or prompt."""
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class CompleteRequestParams(RequestParams):
|
class CompleteRequestParams(RequestParams):
|
||||||
|
|
@ -1619,7 +1516,6 @@ class CompleteRequestParams(RequestParams):
|
||||||
argument: CompletionArgument
|
argument: CompletionArgument
|
||||||
context: CompletionContext | None = None
|
context: CompletionContext | None = None
|
||||||
"""Additional, optional context for completions"""
|
"""Additional, optional context for completions"""
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class CompleteRequest(Request[CompleteRequestParams, Literal["completion/complete"]]):
|
class CompleteRequest(Request[CompleteRequestParams, Literal["completion/complete"]]):
|
||||||
|
|
@ -1629,7 +1525,7 @@ class CompleteRequest(Request[CompleteRequestParams, Literal["completion/complet
|
||||||
params: CompleteRequestParams
|
params: CompleteRequestParams
|
||||||
|
|
||||||
|
|
||||||
class Completion(BaseModel):
|
class Completion(MCPModel):
|
||||||
"""Completion information."""
|
"""Completion information."""
|
||||||
|
|
||||||
values: list[str]
|
values: list[str]
|
||||||
|
|
@ -1644,7 +1540,6 @@ class Completion(BaseModel):
|
||||||
Indicates whether there are additional completion options beyond those provided in
|
Indicates whether there are additional completion options beyond those provided in
|
||||||
the current response, even if the exact total is unknown.
|
the current response, even if the exact total is unknown.
|
||||||
"""
|
"""
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class CompleteResult(Result):
|
class CompleteResult(Result):
|
||||||
|
|
@ -1668,7 +1563,7 @@ class ListRootsRequest(Request[RequestParams | None, Literal["roots/list"]]):
|
||||||
params: RequestParams | None = None
|
params: RequestParams | None = None
|
||||||
|
|
||||||
|
|
||||||
class Root(BaseModel):
|
class Root(MCPModel):
|
||||||
"""Represents a root directory or file that the server can operate on."""
|
"""Represents a root directory or file that the server can operate on."""
|
||||||
|
|
||||||
uri: FileUrl
|
uri: FileUrl
|
||||||
|
|
@ -1688,7 +1583,6 @@ class Root(BaseModel):
|
||||||
See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
||||||
for notes on _meta usage.
|
for notes on _meta usage.
|
||||||
"""
|
"""
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class ListRootsResult(Result):
|
class ListRootsResult(Result):
|
||||||
|
|
@ -1731,8 +1625,6 @@ class CancelledNotificationParams(NotificationParams):
|
||||||
reason: str | None = None
|
reason: str | None = None
|
||||||
"""An optional string describing the reason for the cancellation."""
|
"""An optional string describing the reason for the cancellation."""
|
||||||
|
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class CancelledNotification(Notification[CancelledNotificationParams, Literal["notifications/cancelled"]]):
|
class CancelledNotification(Notification[CancelledNotificationParams, Literal["notifications/cancelled"]]):
|
||||||
"""
|
"""
|
||||||
|
|
@ -1750,8 +1642,6 @@ class ElicitCompleteNotificationParams(NotificationParams):
|
||||||
elicitationId: str
|
elicitationId: str
|
||||||
"""The unique identifier of the elicitation that was completed."""
|
"""The unique identifier of the elicitation that was completed."""
|
||||||
|
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class ElicitCompleteNotification(
|
class ElicitCompleteNotification(
|
||||||
Notification[ElicitCompleteNotificationParams, Literal["notifications/elicitation/complete"]]
|
Notification[ElicitCompleteNotificationParams, Literal["notifications/elicitation/complete"]]
|
||||||
|
|
@ -1832,8 +1722,6 @@ class ElicitRequestFormParams(RequestParams):
|
||||||
Only top-level properties are allowed, without nesting.
|
Only top-level properties are allowed, without nesting.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
class ElicitRequestURLParams(RequestParams):
|
class ElicitRequestURLParams(RequestParams):
|
||||||
"""Parameters for URL mode elicitation requests.
|
"""Parameters for URL mode elicitation requests.
|
||||||
|
|
@ -1857,8 +1745,6 @@ class ElicitRequestURLParams(RequestParams):
|
||||||
The client MUST treat this ID as an opaque value.
|
The client MUST treat this ID as an opaque value.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
# Union type for elicitation request parameters
|
# Union type for elicitation request parameters
|
||||||
ElicitRequestParams: TypeAlias = ElicitRequestURLParams | ElicitRequestFormParams
|
ElicitRequestParams: TypeAlias = ElicitRequestURLParams | ElicitRequestFormParams
|
||||||
|
|
@ -1892,7 +1778,7 @@ class ElicitResult(Result):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
class ElicitationRequiredErrorData(BaseModel):
|
class ElicitationRequiredErrorData(MCPModel):
|
||||||
"""Error data for URLElicitationRequiredError.
|
"""Error data for URLElicitationRequiredError.
|
||||||
|
|
||||||
Servers return this when a request cannot be processed until one or more
|
Servers return this when a request cannot be processed until one or more
|
||||||
|
|
@ -1902,8 +1788,6 @@ class ElicitationRequiredErrorData(BaseModel):
|
||||||
elicitations: list[ElicitRequestURLParams]
|
elicitations: list[ElicitRequestURLParams]
|
||||||
"""List of URL mode elicitations that must be completed."""
|
"""List of URL mode elicitations that must be completed."""
|
||||||
|
|
||||||
model_config = ConfigDict(extra="allow")
|
|
||||||
|
|
||||||
|
|
||||||
ClientResultType: TypeAlias = (
|
ClientResultType: TypeAlias = (
|
||||||
EmptyResult
|
EmptyResult
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue