Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion crates/rmcp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ server-side-http = [
transport-worker = ["dep:tokio-stream"]

# SSE stream parsing utilities (used by streamable HTTP client for SSE-formatted responses)
client-side-sse = ["dep:sse-stream", "dep:http", "base64"]
client-side-sse = ["dep:sse-stream", "dep:http", "dep:bytes", "base64"]

# Streamable HTTP client
transport-streamable-http-client = ["client-side-sse", "transport-worker"]
Expand Down
54 changes: 54 additions & 0 deletions crates/rmcp/src/transport/common/auth/streamable_http_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,33 @@ where
.await
}

async fn get_stream_with_max_sse_event_size(
&self,
uri: std::sync::Arc<str>,
session_id: std::sync::Arc<str>,
last_event_id: Option<String>,
mut auth_token: Option<String>,
custom_headers: HashMap<HeaderName, HeaderValue>,
max_sse_event_size: usize,
) -> Result<
futures::stream::BoxStream<'static, Result<sse_stream::Sse, sse_stream::Error>>,
crate::transport::streamable_http_client::StreamableHttpError<Self::Error>,
> {
if auth_token.is_none() {
auth_token = Some(self.get_access_token().await?);
}
self.http_client

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My only Q would be whether we can apply the new defaults at the HTTP client level for all requests, instead of providing these methods for per request type limit setting. If not, feel free to go ahead as-is.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexhancock The value here is actually a single client-wide setting that gets threaded through each call. I see the method signature make it look like a per-request-type limit. I'll add some comment to clear that up.

@alexhancock alexhancock Jul 14, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My question was more why we needed the new wrapper methods, and why the limit couldn't be applied internally in self.http_client.get_stream_with_max_sse_event_size for example

Just not yet understanding

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexhancock The limit isn't stored on the client, so there's nothing for AuthClient to read internally. It lives on the transport config, and the clients are separate objects passed into with_client(client, config). One of them is reqwest::Client, which is a foreign type we can't add a field to, so the value has to come from the worker at call time.

Also, AuthClient isn't where the bounding can happen. The cap is applied at the raw byte layer, where response.bytes_stream() gets wrapped into an SseStream. That only happens in the leaf client (reqwest or unix socket). AuthClient just adds the auth token and forwards to the inner client, so all it can do is pass max_sse_event_size along.

So the value flows from the worker, through AuthClient, down to the client that actually reads the bytes. Dropping the parameter would mean storing the limit on the client, but because it's implemented on the foreign reqwest::Client that needs a wrapper type and removing the bare impl. I'd rather keep that as a separate follow-up.

.get_stream_with_max_sse_event_size(
uri,
session_id,
last_event_id,
auth_token,
custom_headers,
max_sse_event_size,
)
.await
}

async fn post_message(
&self,
uri: std::sync::Arc<str>,
Expand All @@ -65,4 +92,31 @@ where
.post_message(uri, message, session_id, auth_token, custom_headers)
.await
}

async fn post_message_with_max_sse_event_size(
&self,
uri: std::sync::Arc<str>,
message: crate::model::ClientJsonRpcMessage,
session_id: Option<std::sync::Arc<str>>,
mut auth_token: Option<String>,
custom_headers: HashMap<HeaderName, HeaderValue>,
max_sse_event_size: usize,
) -> Result<
crate::transport::streamable_http_client::StreamableHttpPostResponse,
StreamableHttpError<Self::Error>,
> {
if auth_token.is_none() {
auth_token = Some(self.get_access_token().await?);
}
self.http_client
.post_message_with_max_sse_event_size(
uri,
message,
session_id,
auth_token,
custom_headers,
max_sse_event_size,
)
.await
}
}
Loading