pub struct Protocol { /* private fields */ }
Expand description
The core protocol handler for MCP.
The Protocol
struct manages the lifecycle of JSON-RPC requests and responses,
dispatches incoming requests to the appropriate handlers, and manages
pending requests and their responses.
Implementations§
Source§impl Protocol
impl Protocol
Sourcepub fn builder() -> ProtocolBuilder
pub fn builder() -> ProtocolBuilder
Sourcepub async fn handle_request(&self, request: JsonRpcRequest) -> JsonRpcResponse
pub async fn handle_request(&self, request: JsonRpcRequest) -> JsonRpcResponse
Sourcepub async fn handle_notification(&self, request: JsonRpcNotification)
pub async fn handle_notification(&self, request: JsonRpcNotification)
Handles an incoming JSON-RPC notification.
This method dispatches the notification to the appropriate handler based on the notification method.
§Arguments
request
- The incoming JSON-RPC notification
Sourcepub fn new_message_id(&self) -> u64
pub fn new_message_id(&self) -> u64
Sourcepub async fn create_request(&self) -> (u64, Receiver<JsonRpcResponse>)
pub async fn create_request(&self) -> (u64, Receiver<JsonRpcResponse>)
Creates a new request ID and channel for receiving the response.
§Returns
A tuple containing the request ID and a receiver for the response
Sourcepub async fn handle_response(&self, response: JsonRpcResponse)
pub async fn handle_response(&self, response: JsonRpcResponse)
Handles an incoming JSON-RPC response.
This method delivers the response to the appropriate waiting request, if any.
§Arguments
response
- The incoming JSON-RPC response
Sourcepub async fn cancel_response(&self, id: u64)
pub async fn cancel_response(&self, id: u64)
Cancels a pending request and sends an error response.
§Arguments
id
- The ID of the request to cancel
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Protocol
impl !RefUnwindSafe for Protocol
impl Send for Protocol
impl Sync for Protocol
impl Unpin for Protocol
impl !UnwindSafe for Protocol
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