Skip to content

protocol

Class info

Classes

Name Children Inherits
AgentNotification
aclientp.schema.v2.protocol
A notification the agent sends to the client.
    AgentRequest
    aclientp.schema.v2.protocol
    A request the agent sends to the client (a :data:`ClientMethod`).
      CancelRequestNotification
      aclientp.schema.v2.protocol
      Parameters of ``$/cancel_request``: cancel an ongoing request.
        ClientNotification
        aclientp.schema.v2.protocol
        A notification the client sends to the agent.
          ClientRequest
          aclientp.schema.v2.protocol
          A request the client sends to the agent (an :data:`AgentMethod`).
            ErrorResponse
            aclientp.schema.v2.protocol
            A failed JSON-RPC response.
              InitializeProxyRequest
              aclientp.schema.v2.protocol
              **UNSTABLE**: Parameters of ``proxy/initialize``, sent instead of ``initialize``.
                InitializeProxyResponse
                aclientp.schema.v2.protocol
                **UNSTABLE**: Response to ``proxy/initialize``; the same as an ``initialize`` response.
                  ProxyNotification
                  aclientp.schema.v2.protocol
                  **UNSTABLE**: A notification to a proxy in a proxy chain.
                    ProxyRequest
                    aclientp.schema.v2.protocol
                    **UNSTABLE**: A request to a proxy in a proxy chain (a :data:`ProxyMethod`).
                      ProxySuccessorNotification
                      aclientp.schema.v2.protocol
                      **UNSTABLE**: Parameters of a ``proxy/successor`` notification: a wrapped notification.
                        ProxySuccessorRequest
                        aclientp.schema.v2.protocol
                        **UNSTABLE**: Parameters of a ``proxy/successor`` request: a wrapped request.
                          RequestTypes
                          aclientp.schema.v2.protocol
                          Validators of a request method's parameters and result.
                            ResultResponse
                            aclientp.schema.v2.protocol
                            A successful JSON-RPC response.

                              🛈 DocStrings

                              v2 JSON-RPC layer: methods, message envelopes, cancellation and proxies.

                              Envelopes keep params / result untyped: the method selects their type, and many parameter types share fields (e.g. sessionId), so they cannot be told apart by shape. Parse them by method with the *_REQUESTS / *_NOTIFICATIONS tables, e.g. AGENT_REQUESTS[request.method].params.validate_python(request.params).

                              v2 does not use JSON-RPC batches: each transport message is a single request, notification or response, and receivers reject an array with -32600.

                              AGENT_NOTIFICATIONS module-attribute

                              AGENT_NOTIFICATIONS: dict[str, TypeAdapter[Any]] = {
                                  "session/cancel": TypeAdapter(CancelSessionNotification),
                                  "mcp/message": TypeAdapter(MessageMcpNotification),
                              }
                              

                              Notifications the agent handles.

                              AGENT_REQUESTS module-attribute

                              AGENT_REQUESTS: dict[str, RequestTypes] = {
                                  "initialize": RequestTypes.of(InitializeRequest, InitializeResponse),
                                  "auth/login": RequestTypes.of(LoginAuthRequest, LoginAuthResponse),
                                  "auth/logout": RequestTypes.of(LogoutAuthRequest, LogoutAuthResponse),
                                  "auth/status": RequestTypes.of(AuthStatusRequest, AuthStatusResponse),
                                  "providers/list": RequestTypes.of(ListProvidersRequest, ListProvidersResponse),
                                  "providers/set": RequestTypes.of(SetProviderRequest, SetProviderResponse),
                                  "providers/disable": RequestTypes.of(DisableProviderRequest, DisableProviderResponse),
                                  "session/new": RequestTypes.of(NewSessionRequest, NewSessionResponse),
                                  "session/resume": RequestTypes.of(ResumeSessionRequest, ResumeSessionResponse),
                                  "session/fork": RequestTypes.of(ForkSessionRequest, ForkSessionResponse),
                                  "session/close": RequestTypes.of(CloseSessionRequest, CloseSessionResponse),
                                  "session/list": RequestTypes.of(ListSessionsRequest, ListSessionsResponse),
                                  "session/delete": RequestTypes.of(DeleteSessionRequest, DeleteSessionResponse),
                                  "session/archive": RequestTypes.of(ArchiveSessionRequest, ArchiveSessionResponse),
                                  "session/unarchive": RequestTypes.of(UnarchiveSessionRequest, UnarchiveSessionResponse),
                                  "session/status": RequestTypes.of(SessionStatusRequest, SessionStatusResponse),
                                  "session/options": RequestTypes.of(SessionOptionsRequest, SessionOptionsResponse),
                                  "session/set_title": RequestTypes.of(SetSessionTitleRequest, SetSessionTitleResponse),
                                  "session/set_config_option": RequestTypes.of(
                                      SetSessionConfigOptionRequest, SetSessionConfigOptionResponse
                                  ),
                                  "session/prompt": RequestTypes.of(PromptRequest, PromptResponse),
                                  "tool_call/cancel": RequestTypes.of(CancelToolCallRequest, CancelToolCallResponse),
                                  "terminal/cancel": RequestTypes.of(CancelTerminalRequest, CancelTerminalResponse),
                                  "mcp/message": RequestTypes.of(MessageMcpRequest, MessageMcpResponse),
                              }
                              

                              Requests the agent handles.

                              AgentMethod module-attribute

                              AgentMethod = Literal[
                                  "auth/login",
                                  "auth/logout",
                                  "auth/status",
                                  "initialize",
                                  "mcp/message",
                                  "providers/disable",
                                  "providers/list",
                                  "providers/set",
                                  "session/archive",
                                  "session/cancel",
                                  "session/close",
                                  "session/delete",
                                  "session/fork",
                                  "session/list",
                                  "session/new",
                                  "session/options",
                                  "session/prompt",
                                  "session/resume",
                                  "session/set_config_option",
                                  "session/set_title",
                                  "session/status",
                                  "session/unarchive",
                                  "terminal/cancel",
                                  "tool_call/cancel",
                              ]
                              

                              Methods handled by the agent (session/cancel is a notification).

                              AgentResponse module-attribute

                              AgentResponse = ResultResponse | ErrorResponse
                              

                              A response the agent sends to a client request.

                              CLIENT_NOTIFICATIONS module-attribute

                              CLIENT_NOTIFICATIONS: dict[str, TypeAdapter[Any]] = {
                                  "session/update": TypeAdapter(UpdateSessionNotification),
                                  "elicitation/complete": TypeAdapter(CompleteElicitationNotification),
                                  "auth/status_update": TypeAdapter(AuthStatusUpdateNotification),
                                  "mcp/message": TypeAdapter(MessageMcpNotification),
                              }
                              

                              Notifications the client handles.

                              CLIENT_REQUESTS module-attribute

                              CLIENT_REQUESTS: dict[str, RequestTypes] = {
                                  "session/request_permission": RequestTypes.of(
                                      RequestPermissionRequest, RequestPermissionResponse
                                  ),
                                  "elicitation/create": RequestTypes.of(CreateElicitationRequest, CreateElicitationResponse),
                                  "mcp/message": RequestTypes.of(MessageMcpRequest, MessageMcpResponse),
                              }
                              

                              Requests the client handles.

                              ClientMethod module-attribute

                              ClientMethod = Literal[
                                  "auth/status_update",
                                  "elicitation/complete",
                                  "elicitation/create",
                                  "mcp/message",
                                  "session/request_permission",
                                  "session/update",
                              ]
                              

                              Methods handled by the client.

                              ClientResponse module-attribute

                              ClientResponse = ResultResponse | ErrorResponse
                              

                              A response the client sends to an agent request.

                              PROTOCOL_NOTIFICATIONS module-attribute

                              PROTOCOL_NOTIFICATIONS: dict[str, TypeAdapter[Any]] = {
                                  "$/cancel_request": TypeAdapter(CancelRequestNotification)
                              }
                              

                              Notifications either side handles.

                              PROXY_NOTIFICATIONS module-attribute

                              PROXY_NOTIFICATIONS: dict[str, TypeAdapter[Any]] = {
                                  "proxy/successor": TypeAdapter(ProxySuccessorNotification)
                              }
                              

                              UNSTABLE: Notifications a proxy handles.

                              PROXY_REQUESTS module-attribute

                              PROXY_REQUESTS: dict[str, RequestTypes] = {
                                  "proxy/initialize": RequestTypes.of(InitializeProxyRequest, InitializeProxyResponse),
                                  "proxy/successor": RequestTypes.of(ProxySuccessorRequest, ProxySuccessorResponse),
                              }
                              

                              UNSTABLE: Requests a proxy handles.

                              ProtocolMethod module-attribute

                              ProtocolMethod = Literal['$/cancel_request']
                              

                              Methods either side may send.

                              ProxyMethod module-attribute

                              ProxyMethod = Literal['proxy/initialize', 'proxy/successor']
                              

                              UNSTABLE: Methods handled by proxies in a proxy chain.

                              ProxyResponse module-attribute

                              ProxyResponse = ResultResponse | ErrorResponse
                              

                              UNSTABLE: A response of a proxy.

                              ProxySuccessorResponse module-attribute

                              ProxySuccessorResponse = Any
                              

                              UNSTABLE: Result of proxy/successor: the wrapped request's result, unchanged.

                              AgentNotification

                              Bases: _Notification

                              A notification the agent sends to the client.

                              Source code in src/aclientp/schema/v2/protocol.py
                              class AgentNotification(_Notification):
                                  """A notification the agent sends to the client."""
                              

                              AgentRequest

                              Bases: _Request

                              A request the agent sends to the client (a :data:ClientMethod).

                              Source code in src/aclientp/schema/v2/protocol.py
                              class AgentRequest(_Request):
                                  """A request the agent sends to the client (a :data:`ClientMethod`)."""
                              

                              CancelRequestNotification

                              Bases: AnnotatedObject

                              Parameters of $/cancel_request: cancel an ongoing request.

                              The request must be one the sender of the notification issued.

                              Source code in src/aclientp/schema/v2/protocol.py
                              class CancelRequestNotification(AnnotatedObject):
                                  """Parameters of ``$/cancel_request``: cancel an ongoing request.
                              
                                  The request must be one the sender of the notification issued.
                                  """
                              
                                  request_id: RequestId
                                  """The request to cancel."""
                              

                              request_id instance-attribute

                              request_id: RequestId
                              

                              The request to cancel.

                              ClientNotification

                              Bases: _Notification

                              A notification the client sends to the agent.

                              Source code in src/aclientp/schema/v2/protocol.py
                              class ClientNotification(_Notification):
                                  """A notification the client sends to the agent."""
                              

                              ClientRequest

                              Bases: _Request

                              A request the client sends to the agent (an :data:AgentMethod).

                              Source code in src/aclientp/schema/v2/protocol.py
                              class ClientRequest(_Request):
                                  """A request the client sends to the agent (an :data:`AgentMethod`)."""
                              

                              ErrorResponse

                              Bases: _Message

                              A failed JSON-RPC response.

                              Source code in src/aclientp/schema/v2/protocol.py
                              class ErrorResponse(_Message):
                                  """A failed JSON-RPC response."""
                              
                                  id: RequestId | None
                                  """The ID of the request answered; ``None`` if it could not be determined."""
                              
                                  error: Error
                                  """The error."""
                              

                              error instance-attribute

                              error: Error
                              

                              The error.

                              id instance-attribute

                              id: RequestId | None
                              

                              The ID of the request answered; None if it could not be determined.

                              InitializeProxyRequest

                              Bases: InitializeRequest

                              UNSTABLE: Parameters of proxy/initialize, sent instead of initialize.

                              A conductor sends it to every component that has a successor.

                              Source code in src/aclientp/schema/v2/protocol.py
                              class InitializeProxyRequest(InitializeRequest):
                                  """**UNSTABLE**: Parameters of ``proxy/initialize``, sent instead of ``initialize``.
                              
                                  A conductor sends it to every component that has a successor.
                                  """
                              

                              InitializeProxyResponse

                              Bases: InitializeResponse

                              UNSTABLE: Response to proxy/initialize; the same as an initialize response.

                              Source code in src/aclientp/schema/v2/protocol.py
                              class InitializeProxyResponse(InitializeResponse):
                                  """**UNSTABLE**: Response to ``proxy/initialize``; the same as an ``initialize`` response."""
                              

                              ProxyNotification

                              Bases: _Notification

                              UNSTABLE: A notification to a proxy in a proxy chain.

                              Source code in src/aclientp/schema/v2/protocol.py
                              class ProxyNotification(_Notification):
                                  """**UNSTABLE**: A notification to a proxy in a proxy chain."""
                              

                              ProxyRequest

                              Bases: _Request

                              UNSTABLE: A request to a proxy in a proxy chain (a :data:ProxyMethod).

                              Source code in src/aclientp/schema/v2/protocol.py
                              class ProxyRequest(_Request):
                                  """**UNSTABLE**: A request to a proxy in a proxy chain (a :data:`ProxyMethod`)."""
                              

                              ProxySuccessorNotification

                              Bases: AnnotatedObject

                              UNSTABLE: Parameters of a proxy/successor notification: a wrapped notification.

                              Source code in src/aclientp/schema/v2/protocol.py
                              class ProxySuccessorNotification(AnnotatedObject):
                                  """**UNSTABLE**: Parameters of a ``proxy/successor`` notification: a wrapped notification."""
                              
                                  method: str
                                  """Method of the wrapped notification."""
                              
                                  params: Any | MISSING = MISSING
                                  """Params of the wrapped notification, forwarded unchanged."""
                              

                              method instance-attribute

                              method: str
                              

                              Method of the wrapped notification.

                              params class-attribute instance-attribute

                              params: Any | MISSING = MISSING
                              

                              Params of the wrapped notification, forwarded unchanged.

                              ProxySuccessorRequest

                              Bases: AnnotatedObject

                              UNSTABLE: Parameters of a proxy/successor request: a wrapped request.

                              Source code in src/aclientp/schema/v2/protocol.py
                              class ProxySuccessorRequest(AnnotatedObject):
                                  """**UNSTABLE**: Parameters of a ``proxy/successor`` request: a wrapped request."""
                              
                                  method: str
                                  """Method of the wrapped request."""
                              
                                  params: Any | MISSING = MISSING
                                  """Params of the wrapped request, forwarded unchanged."""
                              

                              method instance-attribute

                              method: str
                              

                              Method of the wrapped request.

                              params class-attribute instance-attribute

                              params: Any | MISSING = MISSING
                              

                              Params of the wrapped request, forwarded unchanged.

                              RequestTypes dataclass

                              Validators of a request method's parameters and result.

                              Source code in src/aclientp/schema/v2/protocol.py
                              @dataclass(frozen=True)
                              class RequestTypes:
                                  """Validators of a request method's parameters and result."""
                              
                                  params: TypeAdapter[Any]
                                  """Parses and validates the ``params`` of the request."""
                              
                                  result: TypeAdapter[Any]
                                  """Parses and validates the ``result`` of the response."""
                              
                                  @classmethod
                                  def of(cls, params: Any, result: Any) -> RequestTypes:
                                      """Build the validators from parameter and result types."""
                                      return cls(TypeAdapter(params), TypeAdapter(result))
                              

                              params instance-attribute

                              params: TypeAdapter[Any]
                              

                              Parses and validates the params of the request.

                              result instance-attribute

                              result: TypeAdapter[Any]
                              

                              Parses and validates the result of the response.

                              of classmethod

                              of(params: Any, result: Any) -> RequestTypes
                              

                              Build the validators from parameter and result types.

                              Source code in src/aclientp/schema/v2/protocol.py
                              @classmethod
                              def of(cls, params: Any, result: Any) -> RequestTypes:
                                  """Build the validators from parameter and result types."""
                                  return cls(TypeAdapter(params), TypeAdapter(result))
                              

                              ResultResponse

                              Bases: _Message

                              A successful JSON-RPC response.

                              Source code in src/aclientp/schema/v2/protocol.py
                              class ResultResponse(_Message):
                                  """A successful JSON-RPC response."""
                              
                                  id: RequestId
                                  """The ID of the request answered."""
                              
                                  result: Any
                                  """The method-specific result; parse it with the method tables."""
                              

                              id instance-attribute

                              The ID of the request answered.

                              result instance-attribute

                              result: Any
                              

                              The method-specific result; parse it with the method tables.