pub enum ClientMessage {
Request(ClientJsonrpcRequest),
Notification(ClientJsonrpcNotification),
Response(ClientJsonrpcResponse),
Error(JsonrpcErrorResponse),
}Expand description
“Similar to JsonrpcMessage, but with the variants restricted to client-side messages.” ClientMessage represents a message sent by an MCP Client and received by an MCP Server.
Variants§
Request(ClientJsonrpcRequest)
Notification(ClientJsonrpcNotification)
Response(ClientJsonrpcResponse)
Error(JsonrpcErrorResponse)
Implementations§
Source§impl ClientMessage
impl ClientMessage
Sourcepub fn as_response(self) -> Result<ClientJsonrpcResponse, RpcError>
pub fn as_response(self) -> Result<ClientJsonrpcResponse, RpcError>
Converts the current message into a ClientJsonrpcResponse if it’s of the correct type.
This function checks if the current message is of type Response. If so, it returns the
ClientJsonrpcResponse wrapped in a Result::Ok. If the message is not a Response,
it returns an error with a descriptive message indicating the mismatch in expected message types.
§Returns
Ok(ClientJsonrpcResponse)if the message is a validResponse.Err(RpcError)if the message type is invalid
Sourcepub fn as_request(self) -> Result<ClientJsonrpcRequest, RpcError>
pub fn as_request(self) -> Result<ClientJsonrpcRequest, RpcError>
Converts the current message into a ClientJsonrpcRequest if it’s of the correct type.
This function checks if the current message is of type Request. If so, it returns the
ClientJsonrpcRequest wrapped in a Result::Ok. If the message is not a Request,
it returns an error with a descriptive message indicating the mismatch in expected message types.
§Returns
Ok(ClientJsonrpcRequest)if the message is a validRequest.Err(RpcError)if the message type is invalid
Sourcepub fn as_notification(self) -> Result<ClientJsonrpcNotification, RpcError>
pub fn as_notification(self) -> Result<ClientJsonrpcNotification, RpcError>
Converts the current message into a ClientJsonrpcNotification if it’s of the correct type.
This function checks if the current message is of type Notification. If so, it returns the
ClientJsonrpcNotification wrapped in a Result::Ok. If the message is not a Notification,
it returns an error with a descriptive message indicating the mismatch in expected message types.
§Returns
Ok(ClientJsonrpcNotification)if the message is a validNotification.Err(RpcError)if the message type is invalid
Sourcepub fn as_error(self) -> Result<JsonrpcErrorResponse, RpcError>
pub fn as_error(self) -> Result<JsonrpcErrorResponse, RpcError>
Converts the current message into a JsonrpcErrorResponse if it’s of the correct type.
This function checks if the current message is of type Error. If so, it returns the
JsonrpcErrorResponse wrapped in a Result::Ok. If the message is not a Error,
it returns an error with a descriptive message indicating the mismatch in expected message types.
§Returns
Ok(JsonrpcErrorResponse)if the message is a validError.Err(RpcError)if the message type is invalid
Sourcepub fn is_initialize_request(&self) -> bool
pub fn is_initialize_request(&self) -> bool
Returns true if message is an InitializeRequest.
Sourcepub fn is_initialized_notification(&self) -> bool
pub fn is_initialized_notification(&self) -> bool
Returns true if the message is an InitializedNotification
Trait Implementations§
Source§impl Clone for ClientMessage
impl Clone for ClientMessage
Source§fn clone(&self) -> ClientMessage
fn clone(&self) -> ClientMessage
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ClientMessage
impl Debug for ClientMessage
Source§impl<'de> Deserialize<'de> for ClientMessage
impl<'de> Deserialize<'de> for ClientMessage
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for ClientMessage
impl Display for ClientMessage
Source§impl From<ClientJsonrpcNotification> for ClientMessage
impl From<ClientJsonrpcNotification> for ClientMessage
Source§fn from(value: ClientJsonrpcNotification) -> Self
fn from(value: ClientJsonrpcNotification) -> Self
Source§impl From<ClientJsonrpcRequest> for ClientMessage
impl From<ClientJsonrpcRequest> for ClientMessage
Source§fn from(value: ClientJsonrpcRequest) -> Self
fn from(value: ClientJsonrpcRequest) -> Self
Source§impl From<ClientJsonrpcResponse> for ClientMessage
impl From<ClientJsonrpcResponse> for ClientMessage
Source§fn from(value: ClientJsonrpcResponse) -> Self
fn from(value: ClientJsonrpcResponse) -> Self
Source§impl From<ClientMessage> for ClientMessages
impl From<ClientMessage> for ClientMessages
Source§fn from(value: ClientMessage) -> Self
fn from(value: ClientMessage) -> Self
Source§impl FromMessage<MessageFromClient> for ClientMessage
impl FromMessage<MessageFromClient> for ClientMessage
fn from_message( message: MessageFromClient, request_id: Option<RequestId>, ) -> Result<Self, RpcError>
Source§impl FromStr for ClientMessage
impl FromStr for ClientMessage
Source§impl McpMessage for ClientMessage
impl McpMessage for ClientMessage
Source§fn message_type(&self) -> MessageTypes
fn message_type(&self) -> MessageTypes
Determines the type of the message and returns the corresponding MessageTypes variant.