pub enum ServeStream {
Unix(UnixStream),
Http(Box<dyn Write + Send>),
}Expand description
The served-MCP transport, type-erased to one concrete enum so the connection
registry (SharedWriter, Subscriber) stays monomorphic across transports
while the same connection code serves each. The socket variants are
Read + Write with a try_clone (their write half is
shared with the threads that push NDJSON notifications). The Http
variant is a write-only SSE sink: an HTTP subscription stream’s write half,
so an HTTP subscriber registers in the SAME SubRegistry and the embedder’s
existing notify_* calls reach it transparently — the framing (NDJSON vs SSE
data: events) is chosen per-variant in write_notification.
Variants§
Unix(UnixStream)
A unix-domain-socket peer.
Http(Box<dyn Write + Send>)
The write half of an HTTP subscription (SSE) stream — a push-only sink.
Never read from, never a reply channel; notifications are framed as SSE
data: events. Boxed so it spans plain TCP and (feature tls) TLS.
Implementations§
Source§impl ServeStream
impl ServeStream
Sourcepub fn try_clone(&self) -> Result<ServeStream>
pub fn try_clone(&self) -> Result<ServeStream>
Clone the handle (a second fd onto the same connection) for the shared write
half. Mirrors UnixStream::try_clone. The Http sink
is single-owner (its SharedWriter is built directly from the stream half),
so it is never cloned — attempting to is an error.
Sourcepub fn set_write_timeout(&self, dur: Option<Duration>) -> Result<()>
pub fn set_write_timeout(&self, dur: Option<Duration>) -> Result<()>
Bound a stalled-but-alive peer so it can’t pin the writer Mutex forever. The HTTP sink sets its timeout on the underlying stream before boxing.
Sourcepub fn write_notification(&mut self, note: &Notification) -> Result<()>
pub fn write_notification(&mut self, note: &Notification) -> Result<()>
Push one notification, framed for this transport: NDJSON (one JSON object +
\n) on the socket variants, an SSE data: event on Http.
This is the single seam the notify_* push helpers write through.
Sourcepub fn write_response(&mut self, resp: &Response) -> Result<()>
pub fn write_response(&mut self, resp: &Response) -> Result<()>
Write one JSON-RPC RESPONSE frame with per-transport framing — the
server-streaming twin of [write_notification]: an HTTP (SSE) sink gets
a data: event, a socket peer gets an NDJSON line. Streaming method
handlers (A2A StreamResponse frames) push through this so one handler
serves every transport.
Trait Implementations§
Source§impl Read for ServeStream
impl Read for ServeStream
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>
read_buf)Source§fn read_buf_exact(
&mut self,
cursor: BorrowedCursor<'_, u8>,
) -> Result<(), Error>
fn read_buf_exact( &mut self, cursor: BorrowedCursor<'_, u8>, ) -> Result<(), Error>
read_buf)cursor. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read. Read more1.0.0 · Source§fn chain<R>(self, next: R) -> Chain<Self, R> ⓘ
fn chain<R>(self, next: R) -> Chain<Self, R> ⓘ
1.0.0 · Source§fn take(self, limit: u64) -> Take<Self> ⓘwhere
Self: Sized,
fn take(self, limit: u64) -> Take<Self> ⓘwhere
Self: Sized,
limit bytes from it. Read moreSource§fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>where
Self: Sized,
fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>where
Self: Sized,
read_array)Source§impl Write for ServeStream
impl Write for ServeStream
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored)