Skip to content

Commit 923145a

Browse files
authored
fix(oauth): pass bearer token to all streamable http requests (#476)
* fix(oauth): attach bearer token to all streaming http requests * fix(typo): fix an unrelated typo There was an errant typo in the CHANGELOG that is breaking CI
1 parent 34f4823 commit 923145a

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

crates/rmcp/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515

1616
### Fixed
1717

18-
- *(oauth)* support suffixed and preffixed well-knonw paths ([#459](https://github.com/modelcontextprotocol/rust-sdk/pull/459))
18+
- *(oauth)* support suffixed and prefixed well-known paths ([#459](https://github.com/modelcontextprotocol/rust-sdk/pull/459))
1919
- generate default schema for tools with no params ([#446](https://github.com/modelcontextprotocol/rust-sdk/pull/446))
2020

2121
### Other

crates/rmcp/src/transport/streamable_http_client.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ struct StreamableHttpClientReconnect<C> {
173173
pub client: C,
174174
pub session_id: Arc<str>,
175175
pub uri: Arc<str>,
176+
pub auth_header: Option<String>,
176177
}
177178

178179
impl<C: StreamableHttpClient> SseStreamReconnect for StreamableHttpClientReconnect<C> {
@@ -182,10 +183,11 @@ impl<C: StreamableHttpClient> SseStreamReconnect for StreamableHttpClientReconne
182183
let client = self.client.clone();
183184
let uri = self.uri.clone();
184185
let session_id = self.session_id.clone();
186+
let auth_header = self.auth_header.clone();
185187
let last_event_id = last_event_id.map(|s| s.to_owned());
186188
Box::pin(async move {
187189
client
188-
.get_stream(uri, session_id, last_event_id, None)
190+
.get_stream(uri, session_id, last_event_id, auth_header)
189191
.await
190192
})
191193
}
@@ -324,10 +326,12 @@ impl<C: StreamableHttpClient> Worker for StreamableHttpClientWorker<C> {
324326
let client = self.client.clone();
325327
let session_id = session_id.clone();
326328
let url = config.uri.clone();
329+
let auth_header = config.auth_header.clone();
327330
tokio::spawn(async move {
328331
ct.cancelled().await;
329-
let delete_session_result =
330-
client.delete_session(url, session_id.clone(), None).await;
332+
let delete_session_result = client
333+
.delete_session(url, session_id.clone(), auth_header.clone())
334+
.await;
331335
match delete_session_result {
332336
Ok(_) => {
333337
tracing::info!(session_id = session_id.as_ref(), "delete session success")
@@ -376,7 +380,12 @@ impl<C: StreamableHttpClient> Worker for StreamableHttpClientWorker<C> {
376380
if let Some(session_id) = &session_id {
377381
match self
378382
.client
379-
.get_stream(config.uri.clone(), session_id.clone(), None, None)
383+
.get_stream(
384+
config.uri.clone(),
385+
session_id.clone(),
386+
None,
387+
config.auth_header.clone(),
388+
)
380389
.await
381390
{
382391
Ok(stream) => {
@@ -386,6 +395,7 @@ impl<C: StreamableHttpClient> Worker for StreamableHttpClientWorker<C> {
386395
client: self.client.clone(),
387396
session_id: session_id.clone(),
388397
uri: config.uri.clone(),
398+
auth_header: config.auth_header.clone(),
389399
},
390400
self.config.retry_config.clone(),
391401
);
@@ -468,6 +478,7 @@ impl<C: StreamableHttpClient> Worker for StreamableHttpClientWorker<C> {
468478
client: self.client.clone(),
469479
session_id: session_id.clone(),
470480
uri: config.uri.clone(),
481+
auth_header: config.auth_header.clone(),
471482
},
472483
self.config.retry_config.clone(),
473484
);
@@ -704,7 +715,7 @@ impl StreamableHttpClientTransportConfig {
704715
///
705716
/// # Arguments
706717
///
707-
/// * `value` - The value to set
718+
/// * `value` - A bearer token without the `Bearer ` prefix
708719
pub fn auth_header<T: Into<String>>(mut self, value: T) -> Self {
709720
// set our authorization header
710721
self.auth_header = Some(value.into());

0 commit comments

Comments
 (0)