pub enum RpcOutcome {
Single(JsonRpcResponse),
Batch(Vec<JsonRpcResponse>),
}Expand description
A dispatched JSON-RPC result, ready to be inspected or rendered.
Returned by McpServer::handle_message. A None from that method means
there is nothing to send (a notification, or a batch of only
notifications); a Some is either a Single response
object or a Batch array.
RpcOutcome implements Serialize and
Display, both rendering a Single as a JSON object
and a Batch as a JSON array. Use
to_wire (or .to_string()) for a String, or
write_json to append directly to a byte buffer — each
serializes in a single pass with no intermediate serde_json::Value.
Variants§
Single(JsonRpcResponse)
A single JSON-RPC response object.
Batch(Vec<JsonRpcResponse>)
A JSON-RPC batch response array (always non-empty).
Implementations§
Source§impl RpcOutcome
impl RpcOutcome
Sourcepub fn to_wire(&self) -> String
pub fn to_wire(&self) -> String
Render this outcome to a single JSON wire string.
§Panics
Panics only if a well-formed MCP response fails to serialize, which would indicate a bug in this crate.
Sourcepub fn write_json(&self, buf: &mut Vec<u8>)
pub fn write_json(&self, buf: &mut Vec<u8>)
Render this outcome’s JSON wire form by appending it to buf.
Lets callers reuse a single buffer across many responses, avoiding a fresh allocation per message.
§Panics
Panics only if a well-formed MCP response fails to serialize, which would indicate a bug in this crate.
Sourcepub fn into_responses(self) -> Vec<JsonRpcResponse>
pub fn into_responses(self) -> Vec<JsonRpcResponse>
Trait Implementations§
Source§impl Clone for RpcOutcome
impl Clone for RpcOutcome
Source§fn clone(&self) -> RpcOutcome
fn clone(&self) -> RpcOutcome
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more