pub struct JsonRpcResponse {
pub jsonrpc: String,
pub id: RequestId,
pub result: Option<Value>,
pub error: Option<JsonRpcError>,
}Expand description
JSON-RPC 2.0 response message.
Represents a response from server to client for a previous request. Can contain either a successful result or an error.
Fields§
§jsonrpc: StringJSON-RPC version (always “2.0”)
id: RequestIdID from the corresponding request
result: Option<Value>Success result (mutually exclusive with error)
error: Option<JsonRpcError>Error result (mutually exclusive with result)
Implementations§
Source§impl JsonRpcResponse
impl JsonRpcResponse
Sourcepub fn success(id: impl Into<RequestId>, result: Value) -> Self
pub fn success(id: impl Into<RequestId>, result: Value) -> Self
Create a successful response with the given result.
§Examples
use mcp_probe_core::messages::core::JsonRpcResponse;
use serde_json::json;
let response = JsonRpcResponse::success("1", json!({"status": "ok"}));Sourcepub fn error(id: impl Into<RequestId>, error: JsonRpcError) -> Self
pub fn error(id: impl Into<RequestId>, error: JsonRpcError) -> Self
Create an error response with the given error.
§Examples
use mcp_probe_core::messages::core::{JsonRpcResponse, JsonRpcError};
let response = JsonRpcResponse::error(
"1",
JsonRpcError::method_not_found("unknown_method"),
);Sourcepub fn is_success(&self) -> bool
pub fn is_success(&self) -> bool
Check if this response represents a success.
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§const fn clone_from(&mut self, source: &Self)
const 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
Source§impl From<JsonRpcResponse> for JsonRpcMessage
impl From<JsonRpcResponse> for JsonRpcMessage
Source§fn from(resp: JsonRpcResponse) -> Self
fn from(resp: JsonRpcResponse) -> Self
Converts to this type from the input type.
Source§impl PartialEq for JsonRpcResponse
impl PartialEq for JsonRpcResponse
Source§impl Serialize for JsonRpcResponse
impl Serialize for JsonRpcResponse
impl Eq for JsonRpcResponse
impl StructuralPartialEq for JsonRpcResponse
Auto Trait Implementations§
impl Freeze for JsonRpcResponse
impl RefUnwindSafe for JsonRpcResponse
impl Send for JsonRpcResponse
impl Sync for JsonRpcResponse
impl Unpin 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.