pub struct JsonRpcResponse {
pub jsonrpc: String,
pub id: Value,
pub result: Option<Value>,
pub error: Option<JsonRpcError>,
}Expand description
JSON-RPC 2.0 response message.
Fields§
§jsonrpc: StringMust be “2.0”.
id: ValueMust match the request ID.
result: Option<Value>The result (present on success).
error: Option<JsonRpcError>The error (present on failure).
Implementations§
Source§impl JsonRpcResponse
impl JsonRpcResponse
Sourcepub fn error(id: Value, error: JsonRpcError) -> Self
pub fn error(id: Value, error: JsonRpcError) -> Self
Create an error response.
Sourcepub fn tool_error(id: Value, message: impl Into<String>) -> Self
pub fn tool_error(id: Value, message: impl Into<String>) -> Self
Create a tool error response (isError: true per MCP spec).
Use this for tool execution failures instead of error().
Sourcepub fn into_tool_error_if_needed(self) -> Self
pub fn into_tool_error_if_needed(self) -> Self
If this is a JSON-RPC error response, convert it to a tool error (isError: true) per MCP spec. Protocol errors pass through unchanged.
Trait Implementations§
Source§impl Clone for JsonRpcResponse
impl Clone for JsonRpcResponse
Source§fn clone(&self) -> JsonRpcResponse
fn clone(&self) -> JsonRpcResponse
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 JsonRpcResponse
impl Debug for JsonRpcResponse
Source§impl<'de> Deserialize<'de> for JsonRpcResponse
impl<'de> Deserialize<'de> for JsonRpcResponse
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 JsonRpcResponse
impl RefUnwindSafe for JsonRpcResponse
impl Send for JsonRpcResponse
impl Sync for JsonRpcResponse
impl Unpin for JsonRpcResponse
impl UnsafeUnpin for JsonRpcResponse
impl UnwindSafe for JsonRpcResponse
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