pub enum ServerMessage {
Request(ServerJsonrpcRequest),
Notification(ServerJsonrpcNotification),
Response(ServerJsonrpcResponse),
Error(JsonrpcErrorResponse),
}Expand description
“Similar to JsonrpcMessage, but with the variants restricted to client-side messages.” ServerMessage represents a message sent by an MCP Server and received by an MCP Client.
Variants§
Request(ServerJsonrpcRequest)
Notification(ServerJsonrpcNotification)
Response(ServerJsonrpcResponse)
Error(JsonrpcErrorResponse)
Implementations§
Source§impl ServerMessage
impl ServerMessage
Sourcepub fn as_response(self) -> Result<ServerJsonrpcResponse, RpcError>
pub fn as_response(self) -> Result<ServerJsonrpcResponse, RpcError>
Converts the current message into a ServerJsonrpcResponse if it’s of the correct type.
This function checks if the current message is of type Response. If so, it returns the
ServerJsonrpcResponse 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(ServerJsonrpcResponse)if the message is a validResponse.Err(RpcError)if the message type is invalid
Sourcepub fn as_request(self) -> Result<ServerJsonrpcRequest, RpcError>
pub fn as_request(self) -> Result<ServerJsonrpcRequest, RpcError>
Converts the current message into a ServerJsonrpcRequest if it’s of the correct type.
This function checks if the current message is of type Request. If so, it returns the
ServerJsonrpcRequest 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(ServerJsonrpcRequest)if the message is a validRequest.Err(RpcError)if the message type is invalid
Sourcepub fn as_notification(self) -> Result<ServerJsonrpcNotification, RpcError>
pub fn as_notification(self) -> Result<ServerJsonrpcNotification, RpcError>
Converts the current message into a ServerJsonrpcNotification if it’s of the correct type.
This function checks if the current message is of type Notification. If so, it returns the
ServerJsonrpcNotification 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(ServerJsonrpcNotification)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
Trait Implementations§
Source§impl Clone for ServerMessage
impl Clone for ServerMessage
Source§fn clone(&self) -> ServerMessage
fn clone(&self) -> ServerMessage
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ServerMessage
impl Debug for ServerMessage
Source§impl<'de> Deserialize<'de> for ServerMessage
impl<'de> Deserialize<'de> for ServerMessage
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 ServerMessage
impl Display for ServerMessage
Source§impl From<ServerJsonrpcNotification> for ServerMessage
impl From<ServerJsonrpcNotification> for ServerMessage
Source§fn from(value: ServerJsonrpcNotification) -> Self
fn from(value: ServerJsonrpcNotification) -> Self
Source§impl From<ServerJsonrpcRequest> for ServerMessage
impl From<ServerJsonrpcRequest> for ServerMessage
Source§fn from(value: ServerJsonrpcRequest) -> Self
fn from(value: ServerJsonrpcRequest) -> Self
Source§impl From<ServerJsonrpcResponse> for ServerMessage
impl From<ServerJsonrpcResponse> for ServerMessage
Source§fn from(value: ServerJsonrpcResponse) -> Self
fn from(value: ServerJsonrpcResponse) -> Self
Source§impl From<ServerMessage> for ServerMessages
impl From<ServerMessage> for ServerMessages
Source§fn from(value: ServerMessage) -> Self
fn from(value: ServerMessage) -> Self
Source§impl FromMessage<MessageFromServer> for ServerMessage
impl FromMessage<MessageFromServer> for ServerMessage
fn from_message( message: MessageFromServer, request_id: Option<RequestId>, ) -> Result<Self, RpcError>
Source§impl FromStr for ServerMessage
impl FromStr for ServerMessage
Source§impl McpMessage for ServerMessage
impl McpMessage for ServerMessage
Source§fn message_type(&self) -> MessageTypes
fn message_type(&self) -> MessageTypes
Determines the type of the message and returns the corresponding MessageTypes variant.
fn is_response(&self) -> bool
fn is_request(&self) -> bool
fn is_notification(&self) -> bool
fn is_error(&self) -> bool
Source§impl RpcMessage for ServerMessage
impl RpcMessage for ServerMessage
Auto Trait Implementations§
impl Freeze for ServerMessage
impl RefUnwindSafe for ServerMessage
impl Send for ServerMessage
impl Sync for ServerMessage
impl Unpin for ServerMessage
impl UnwindSafe for ServerMessage
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)