Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions crates/rmcp/src/transport/sse_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,20 @@ impl<C: SseClient> SseClientTransport<C> {
config: SseClientConfig,
) -> Result<Self, SseTransportError<C::Error>> {
let mut sse_stream = client.get_stream(config.uri.clone(), None, None).await?;
// wait the endpoint event
let endpoint = loop {
let sse = sse_stream
.next()
.await
.ok_or(SseTransportError::UnexpectedEndOfStream)??;
let Some("endpoint") = sse.event.as_deref() else {
continue;
};
break sse.data.unwrap_or_default();
let endpoint = if let Some(endpoint) = config.use_endpoint.clone() {
endpoint
} else {
// wait the endpoint event
loop {
let sse = sse_stream
.next()
.await
.ok_or(SseTransportError::UnexpectedEndOfStream)??;
let Some("endpoint") = sse.event.as_deref() else {
continue;
};
break sse.data.unwrap_or_default();
}
};
let post_uri: Arc<str> = format!(
"{}/{}",
Expand Down Expand Up @@ -151,13 +155,16 @@ impl<C: SseClient> SseClientTransport<C> {
pub struct SseClientConfig {
pub uri: Arc<str>,
pub retry_policy: Arc<dyn SseRetryPolicy>,
/// if this is settled, the client will use this endpoint to send message and skip get the endpoint event
pub use_endpoint: Option<String>,
}

impl Default for SseClientConfig {
fn default() -> Self {
Self {
uri: "".into(),
retry_policy: Arc::new(super::common::client_side_sse::FixedInterval::default()),
use_endpoint: None,
}
}
}
Loading