Skip to content

Commit 35282ee

Browse files
authored
feat: sse client optionally skip the endpoint event (#187)
1 parent c1e282e commit 35282ee

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

crates/rmcp/src/transport/sse_client.rs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,20 @@ impl<C: SseClient> SseClientTransport<C> {
113113
config: SseClientConfig,
114114
) -> Result<Self, SseTransportError<C::Error>> {
115115
let mut sse_stream = client.get_stream(config.uri.clone(), None, None).await?;
116-
// wait the endpoint event
117-
let endpoint = loop {
118-
let sse = sse_stream
119-
.next()
120-
.await
121-
.ok_or(SseTransportError::UnexpectedEndOfStream)??;
122-
let Some("endpoint") = sse.event.as_deref() else {
123-
continue;
124-
};
125-
break sse.data.unwrap_or_default();
116+
let endpoint = if let Some(endpoint) = config.use_endpoint.clone() {
117+
endpoint
118+
} else {
119+
// wait the endpoint event
120+
loop {
121+
let sse = sse_stream
122+
.next()
123+
.await
124+
.ok_or(SseTransportError::UnexpectedEndOfStream)??;
125+
let Some("endpoint") = sse.event.as_deref() else {
126+
continue;
127+
};
128+
break sse.data.unwrap_or_default();
129+
}
126130
};
127131
let post_uri: Arc<str> = format!(
128132
"{}/{}",
@@ -151,13 +155,16 @@ impl<C: SseClient> SseClientTransport<C> {
151155
pub struct SseClientConfig {
152156
pub uri: Arc<str>,
153157
pub retry_policy: Arc<dyn SseRetryPolicy>,
158+
/// if this is settled, the client will use this endpoint to send message and skip get the endpoint event
159+
pub use_endpoint: Option<String>,
154160
}
155161

156162
impl Default for SseClientConfig {
157163
fn default() -> Self {
158164
Self {
159165
uri: "".into(),
160166
retry_policy: Arc::new(super::common::client_side_sse::FixedInterval::default()),
167+
use_endpoint: None,
161168
}
162169
}
163170
}

0 commit comments

Comments
 (0)