pub struct Protocol {
pub cmd_tx: Option<Sender<TransportCommand>>,
pub event_rx: Option<Arc<Mutex<Receiver<TransportEvent>>>>,
pub options: ProtocolOptions,
pub request_message_id: Arc<RwLock<u64>>,
pub request_handlers: Arc<RwLock<HashMap<String, RequestHandlerFn>>>,
pub notification_handlers: Arc<RwLock<HashMap<String, Box<dyn Fn(JsonRpcNotification) -> Pin<Box<dyn Future<Output = Result<(), McpError>> + Send>> + Send + Sync>>>>,
pub response_handlers: Arc<RwLock<HashMap<u64, Box<dyn FnOnce(Result<JsonRpcResponse, McpError>) + Send + Sync>>>>,
pub progress_handlers: Arc<RwLock<HashMap<u64, ProgressCallback>>>,
}
Fields§
§cmd_tx: Option<Sender<TransportCommand>>
§event_rx: Option<Arc<Mutex<Receiver<TransportEvent>>>>
§options: ProtocolOptions
§request_message_id: Arc<RwLock<u64>>
§request_handlers: Arc<RwLock<HashMap<String, RequestHandlerFn>>>
§notification_handlers: Arc<RwLock<HashMap<String, Box<dyn Fn(JsonRpcNotification) -> Pin<Box<dyn Future<Output = Result<(), McpError>> + Send>> + Send + Sync>>>>
§response_handlers: Arc<RwLock<HashMap<u64, Box<dyn FnOnce(Result<JsonRpcResponse, McpError>) + Send + Sync>>>>
§progress_handlers: Arc<RwLock<HashMap<u64, ProgressCallback>>>
Implementations§
Source§impl Protocol
impl Protocol
pub fn builder(options: Option<ProtocolOptions>) -> ProtocolBuilder
pub async fn connect<T: Transport>( &mut self, transport: T, ) -> Result<ProtocolHandle, McpError>
pub fn clone(&self) -> Self
pub async fn request<Req, Resp>(
&self,
method: &str,
params: Option<Req>,
options: Option<RequestOptions>,
) -> Result<Resp, McpError>where
Req: Serialize,
Resp: for<'de> Deserialize<'de>,
pub async fn notification<N: Serialize>( &self, method: &str, params: Option<N>, ) -> Result<(), McpError>
pub async fn close(&mut self) -> Result<(), McpError>
pub async fn set_request_handler( &mut self, method: &str, handler: RequestHandlerFn, )
pub async fn set_notification_handler( &mut self, method: &str, handler: Box<dyn Fn(JsonRpcNotification) -> Pin<Box<dyn Future<Output = Result<(), McpError>> + Send>> + Send + Sync>, )
pub async fn send_notification( &self, notification: JsonRpcNotification, ) -> Result<(), McpError>
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