feat(rmcp): add authorization header support for the streamable http client (#390)
This allows the streamable http client to send an authorization header when making requests. Closes #387
This commit is contained in:
parent
357671cc5c
commit
6853143684
2 changed files with 37 additions and 3 deletions
|
|
@ -160,8 +160,18 @@ impl StreamableHttpClientTransport<reqwest::Client> {
|
||||||
reqwest::Client::default(),
|
reqwest::Client::default(),
|
||||||
StreamableHttpClientTransportConfig {
|
StreamableHttpClientTransportConfig {
|
||||||
uri: uri.into(),
|
uri: uri.into(),
|
||||||
|
auth_header: None,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Build this transport form a config
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
///
|
||||||
|
/// * `config` - The config to use with this transport
|
||||||
|
pub fn from_config(config: StreamableHttpClientTransportConfig) -> Self {
|
||||||
|
StreamableHttpClientTransport::with_client(reqwest::Client::default(), config)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -277,7 +277,12 @@ impl<C: StreamableHttpClient> Worker for StreamableHttpClientWorker<C> {
|
||||||
let _ = responder.send(Ok(()));
|
let _ = responder.send(Ok(()));
|
||||||
let (message, session_id) = self
|
let (message, session_id) = self
|
||||||
.client
|
.client
|
||||||
.post_message(config.uri.clone(), initialize_request, None, None)
|
.post_message(
|
||||||
|
config.uri.clone(),
|
||||||
|
initialize_request,
|
||||||
|
None,
|
||||||
|
self.config.auth_header,
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
.map_err(WorkerQuitReason::fatal_context("send initialize request"))?
|
.map_err(WorkerQuitReason::fatal_context("send initialize request"))?
|
||||||
.expect_initialized::<C::Error>()
|
.expect_initialized::<C::Error>()
|
||||||
|
|
@ -334,7 +339,7 @@ impl<C: StreamableHttpClient> Worker for StreamableHttpClientWorker<C> {
|
||||||
config.uri.clone(),
|
config.uri.clone(),
|
||||||
initialized_notification.message,
|
initialized_notification.message,
|
||||||
session_id.clone(),
|
session_id.clone(),
|
||||||
None,
|
config.auth_header.clone(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.map_err(WorkerQuitReason::fatal_context(
|
.map_err(WorkerQuitReason::fatal_context(
|
||||||
|
|
@ -421,7 +426,12 @@ impl<C: StreamableHttpClient> Worker for StreamableHttpClientWorker<C> {
|
||||||
let WorkerSendRequest { message, responder } = send_request;
|
let WorkerSendRequest { message, responder } = send_request;
|
||||||
let response = self
|
let response = self
|
||||||
.client
|
.client
|
||||||
.post_message(config.uri.clone(), message, session_id.clone(), None)
|
.post_message(
|
||||||
|
config.uri.clone(),
|
||||||
|
message,
|
||||||
|
session_id.clone(),
|
||||||
|
config.auth_header.clone(),
|
||||||
|
)
|
||||||
.await;
|
.await;
|
||||||
let send_result = match response {
|
let send_result = match response {
|
||||||
Err(e) => Err(e),
|
Err(e) => Err(e),
|
||||||
|
|
@ -661,6 +671,8 @@ pub struct StreamableHttpClientTransportConfig {
|
||||||
pub channel_buffer_capacity: usize,
|
pub channel_buffer_capacity: usize,
|
||||||
/// if true, the transport will not require a session to be established
|
/// if true, the transport will not require a session to be established
|
||||||
pub allow_stateless: bool,
|
pub allow_stateless: bool,
|
||||||
|
/// The value to send in the authorization header
|
||||||
|
pub auth_header: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StreamableHttpClientTransportConfig {
|
impl StreamableHttpClientTransportConfig {
|
||||||
|
|
@ -670,6 +682,17 @@ impl StreamableHttpClientTransportConfig {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set the authorization header to send with requests
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
///
|
||||||
|
/// * `value` - The value to set
|
||||||
|
pub fn auth_header<T: Into<String>>(mut self, value: T) -> Self {
|
||||||
|
// set our authorization header
|
||||||
|
self.auth_header = Some(value.into());
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for StreamableHttpClientTransportConfig {
|
impl Default for StreamableHttpClientTransportConfig {
|
||||||
|
|
@ -679,6 +702,7 @@ impl Default for StreamableHttpClientTransportConfig {
|
||||||
retry_config: Arc::new(ExponentialBackoff::default()),
|
retry_config: Arc::new(ExponentialBackoff::default()),
|
||||||
channel_buffer_capacity: 16,
|
channel_buffer_capacity: 16,
|
||||||
allow_stateless: true,
|
allow_stateless: true,
|
||||||
|
auth_header: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue