pub struct McpMessage {
pub jsonrpc: String,
pub id: Option<Value>,
pub method: Option<String>,
pub params: Option<Value>,
pub result: Option<Value>,
pub error: Option<JsonRpcError>,
}Expand description
A parsed MCP message (JSON-RPC 2.0 envelope).
MCP uses JSON-RPC 2.0 over stdio or HTTP. Every message is one of:
- Request: has
method+params, hasid - Response: has
resultorerror, hasid - Notification: has
method+params, noid
Fields§
§jsonrpc: String§id: Option<Value>Request/response correlation ID. None for notifications.
method: Option<String>Method name (e.g. “tools/call”, “tools/list”, “initialize”).
params: Option<Value>Method parameters.
result: Option<Value>Success response payload.
error: Option<JsonRpcError>Error response payload.
Implementations§
Source§impl McpMessage
impl McpMessage
Sourcepub fn parse(raw: &str) -> Result<Self, Error>
pub fn parse(raw: &str) -> Result<Self, Error>
Parse a JSON-RPC message from a raw JSON string.
Sourcepub fn to_json(&self) -> Result<String, Error>
pub fn to_json(&self) -> Result<String, Error>
Serialize this message to a JSON string (no trailing newline).
Sourcepub fn is_request(&self) -> bool
pub fn is_request(&self) -> bool
True if this is a request (has method + id).
Sourcepub fn is_notification(&self) -> bool
pub fn is_notification(&self) -> bool
True if this is a notification (has method, no id).
Sourcepub fn is_response(&self) -> bool
pub fn is_response(&self) -> bool
True if this is a response (has result or error + id).
Trait Implementations§
Source§impl Clone for McpMessage
impl Clone for McpMessage
Source§fn clone(&self) -> McpMessage
fn clone(&self) -> McpMessage
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for McpMessage
impl Debug for McpMessage
Source§impl<'de> Deserialize<'de> for McpMessage
impl<'de> Deserialize<'de> for McpMessage
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>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for McpMessage
impl RefUnwindSafe for McpMessage
impl Send for McpMessage
impl Sync for McpMessage
impl Unpin for McpMessage
impl UnsafeUnpin for McpMessage
impl UnwindSafe for McpMessage
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more