pub struct Protocol<T: Transport> { /* private fields */ }
Expand description
The main protocol implementation for handling MCP messages
Manages bidirectional communication between client and server, handling requests, notifications, and their respective responses.
Implementations§
Source§impl<T: Transport> Protocol<T>
impl<T: Transport> Protocol<T>
Sourcepub fn builder(transport: T) -> ProtocolBuilder<T>
pub fn builder(transport: T) -> ProtocolBuilder<T>
Creates a new protocol builder with the given transport
§Arguments
transport
- The transport layer to use for communication
Sourcepub async fn notify(
&self,
method: &str,
params: Option<Value>,
) -> Result<(), TransportError>
pub async fn notify( &self, method: &str, params: Option<Value>, ) -> Result<(), TransportError>
Sends a notification to the remote endpoint
§Arguments
method
- The notification method nameparams
- Optional parameters for the notification
Sourcepub async fn request(
&self,
method: &str,
params: Option<Value>,
options: RequestOptions,
) -> Result<JsonRpcResponse, TransportError>
pub async fn request( &self, method: &str, params: Option<Value>, options: RequestOptions, ) -> Result<JsonRpcResponse, TransportError>
Sourcepub async fn listen(&self) -> Result<(), TransportError>
pub async fn listen(&self) -> Result<(), TransportError>
Listen for and handle incoming JSON-RPC messages
This method runs indefinitely, processing incoming messages and routing them to the appropriate handlers.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Protocol<T>
impl<T> !RefUnwindSafe for Protocol<T>
impl<T> Send for Protocol<T>
impl<T> Sync for Protocol<T>
impl<T> Unpin for Protocol<T>
impl<T> !UnwindSafe for Protocol<T>
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<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more