Skip to content

Commit 021a431

Browse files
authored
chore: upgrade reqwest to 0.13.2 (#669)
1 parent 0b53bfd commit 021a431

6 files changed

Lines changed: 47 additions & 13 deletions

File tree

crates/rmcp/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ tokio-util = { version = "0.7" }
2626
pin-project-lite = "0.2"
2727
pastey = { version = "0.2.0", optional = true }
2828
# oauth2 support
29-
oauth2 = { version = "5.0", optional = true, default-features = false, features = ["reqwest"] }
29+
oauth2 = { version = "5.0", optional = true, default-features = false }
3030

3131
# for auto generate schema
3232
schemars = { version = "1.0", optional = true, features = ["chrono04"] }
@@ -35,7 +35,7 @@ schemars = { version = "1.0", optional = true, features = ["chrono04"] }
3535
base64 = { version = "0.22", optional = true }
3636

3737
# for HTTP client
38-
reqwest = { version = "0.12", default-features = false, features = [
38+
reqwest = { version = "0.13.2", default-features = false, features = [
3939
"json",
4040
"stream",
4141
], optional = true }
@@ -84,9 +84,9 @@ elicitation = ["dep:url"]
8484
# reqwest http client
8585
__reqwest = ["dep:reqwest"]
8686

87-
reqwest = ["__reqwest", "reqwest?/rustls-tls"]
87+
reqwest = ["__reqwest", "reqwest?/rustls"]
8888

89-
reqwest-tls-no-provider = ["__reqwest", "reqwest?/rustls-tls-no-provider"]
89+
reqwest-tls-no-provider = ["__reqwest", "reqwest?/rustls-no-provider"]
9090

9191
reqwest-native-tls = ["__reqwest", "reqwest?/native-tls"]
9292

crates/rmcp/src/transport/auth.rs

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ use std::{collections::HashMap, sync::Arc, time::Duration};
22

33
use async_trait::async_trait;
44
use oauth2::{
5-
AuthType, AuthUrl, AuthorizationCode, ClientId, ClientSecret, CsrfToken, EmptyExtraTokenFields,
6-
PkceCodeChallenge, PkceCodeVerifier, RedirectUrl, RefreshToken, RequestTokenError, Scope,
7-
StandardTokenResponse, TokenResponse, TokenUrl,
5+
AsyncHttpClient, AuthType, AuthUrl, AuthorizationCode, ClientId, ClientSecret, CsrfToken,
6+
EmptyExtraTokenFields, HttpClientError, HttpRequest, HttpResponse, PkceCodeChallenge,
7+
PkceCodeVerifier, RedirectUrl, RefreshToken, RequestTokenError, Scope, StandardTokenResponse,
8+
TokenResponse, TokenUrl,
89
basic::{BasicClient, BasicTokenType},
910
};
1011
use reqwest::{
@@ -18,6 +19,39 @@ use tracing::{debug, error, warn};
1819

1920
use crate::transport::common::http_header::HEADER_MCP_PROTOCOL_VERSION;
2021

22+
/// Owned wrapper around [`reqwest::Client`] that implements [`AsyncHttpClient`] for oauth2.
23+
struct OAuthReqwestClient(HttpClient);
24+
25+
impl<'c> AsyncHttpClient<'c> for OAuthReqwestClient {
26+
type Error = HttpClientError<reqwest::Error>;
27+
28+
type Future = std::pin::Pin<
29+
Box<dyn std::future::Future<Output = Result<HttpResponse, Self::Error>> + Send + Sync + 'c>,
30+
>;
31+
32+
fn call(&'c self, request: HttpRequest) -> Self::Future {
33+
Box::pin(async move {
34+
let response = self
35+
.0
36+
.execute(request.try_into().map_err(Box::new)?)
37+
.await
38+
.map_err(Box::new)?;
39+
40+
let mut builder = oauth2::http::Response::builder()
41+
.status(response.status())
42+
.version(response.version());
43+
44+
for (name, value) in response.headers().iter() {
45+
builder = builder.header(name, value);
46+
}
47+
48+
builder
49+
.body(response.bytes().await.map_err(Box::new)?.to_vec())
50+
.map_err(HttpClientError::Http)
51+
})
52+
}
53+
}
54+
2155
const DEFAULT_EXCHANGE_URL: &str = "http://localhost";
2256

2357
/// Stored credentials for OAuth2 authorization
@@ -872,7 +906,7 @@ impl AuthorizationManager {
872906
.exchange_code(AuthorizationCode::new(code.to_string()))
873907
.set_pkce_verifier(pkce_verifier)
874908
.add_extra_param("resource", self.base_url.to_string())
875-
.request_async(&http_client)
909+
.request_async(&OAuthReqwestClient(http_client))
876910
.await
877911
{
878912
Ok(token) => token,
@@ -961,7 +995,7 @@ impl AuthorizationManager {
961995

962996
let token_result = oauth_client
963997
.exchange_refresh_token(&RefreshToken::new(refresh_token.secret().to_string()))
964-
.request_async(&self.http_client)
998+
.request_async(&OAuthReqwestClient(self.http_client.clone()))
965999
.await
9661000
.map_err(|e| AuthError::TokenRefreshFailed(e.to_string()))?;
9671001

examples/clients/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ anyhow = "1.0"
2626
url = "2.4"
2727
tower = "0.5"
2828
axum = "0.8"
29-
reqwest = "0.12"
29+
reqwest = "0.13.2"
3030
clap = { version = "4.0", features = ["derive"] }
3131

3232
[[example]]

examples/servers/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ futures = "0.3"
3535
rand = { version = "0.10", features = ["std"] }
3636
axum = { version = "0.8", features = ["macros"] }
3737
schemars = "1.0"
38-
reqwest = { version = "0.12", features = ["json"] }
38+
reqwest = { version = "0.13.2", features = ["json"] }
3939
chrono = "0.4"
4040
uuid = { version = "1.6", features = ["v4", "serde"] }
4141
serde_urlencoded = "0.7"

examples/simple-chat-client/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ publish = false
88
tokio = { version = "1", features = ["full"] }
99
serde = { version = "1.0", features = ["derive"] }
1010
serde_json = "1.0"
11-
reqwest = { version = "0.12", features = ["json"] }
11+
reqwest = { version = "0.13.2", features = ["json"] }
1212
anyhow = "1.0"
1313
thiserror = "2.0"
1414
async-trait = "0.1"

examples/transport/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ schemars = { version = "1.0", optional = true }
4141
hyper = { version = "1", features = ["client", "server", "http1"] }
4242
hyper-util = { version = "0.1", features = ["tokio"] }
4343
tokio-tungstenite = "0.28.0"
44-
reqwest = { version = "0.12" }
44+
reqwest = { version = "0.13.2" }
4545
pin-project-lite = "0.2"
4646

4747
[[example]]

0 commit comments

Comments
 (0)