Skip to content

Commit 531b6d8

Browse files
acarl005oz-agent
andcommitted
Fix CI failures: type alignment, non-exhaustive match, formatting
- Simplify Transport enum to use Option<reqwest::Client> instead of AuthClient wrapper - Fix error_to_user_message to add wildcard arm for non-exhaustive RmcpError - Remove duplicate function signature line - Run cargo fmt Co-Authored-By: Oz <oz-agent@warp.dev>
1 parent d1a2244 commit 531b6d8

3 files changed

Lines changed: 35 additions & 26 deletions

File tree

app/src/ai/mcp/http_client.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{borrow::Cow, collections::HashMap, sync::Arc};
22

3-
use futures::{StreamExt, stream::BoxStream};
4-
use http::{HeaderName, HeaderValue, header::WWW_AUTHENTICATE};
3+
use futures::{stream::BoxStream, StreamExt};
4+
use http::{header::WWW_AUTHENTICATE, HeaderName, HeaderValue};
55
use reqwest::header::{HeaderMap, ACCEPT};
66
use rmcp::{
77
model::{ClientJsonRpcMessage, JsonRpcMessage, ServerJsonRpcMessage},
@@ -65,7 +65,9 @@ fn apply_custom_headers(
6565
for (name, value) in custom_headers {
6666
let name_lower = name.as_str().to_lowercase();
6767
if RESERVED_HEADERS.contains(&name_lower.as_str()) {
68-
return Err(StreamableHttpError::ReservedHeaderConflict(name.to_string()));
68+
return Err(StreamableHttpError::ReservedHeaderConflict(
69+
name.to_string(),
70+
));
6971
}
7072
builder = builder.header(name, value);
7173
}
@@ -107,7 +109,8 @@ impl StreamableHttpClient for McpHttpClient {
107109
auth_token: Option<String>,
108110
custom_headers: HashMap<HeaderName, HeaderValue>,
109111
) -> Result<BoxStream<'static, Result<Sse, SseError>>, StreamableHttpError<Self::Error>> {
110-
let mut request_builder = self.0
112+
let mut request_builder = self
113+
.0
111114
.get(uri.as_ref())
112115
.header(ACCEPT, [EVENT_STREAM_MIME_TYPE, JSON_MIME_TYPE].join(", "))
113116
.header(HEADER_SESSION_ID, session_id.as_ref());
@@ -181,7 +184,8 @@ impl StreamableHttpClient for McpHttpClient {
181184
auth_token: Option<String>,
182185
custom_headers: HashMap<HeaderName, HeaderValue>,
183186
) -> Result<StreamableHttpPostResponse, StreamableHttpError<Self::Error>> {
184-
let mut request = self.0
187+
let mut request = self
188+
.0
185189
.post(uri.as_ref())
186190
.header(ACCEPT, [EVENT_STREAM_MIME_TYPE, JSON_MIME_TYPE].join(", "));
187191
if let Some(auth_header) = auth_token {
@@ -207,9 +211,9 @@ impl StreamableHttpClient for McpHttpClient {
207211
))
208212
})?
209213
.to_string();
210-
return Err(StreamableHttpError::AuthRequired(
211-
AuthRequiredError::new(header),
212-
));
214+
return Err(StreamableHttpError::AuthRequired(AuthRequiredError::new(
215+
header,
216+
)));
213217
}
214218
}
215219
if response.status() == reqwest::StatusCode::FORBIDDEN {

app/src/ai/mcp/templatable_manager/native.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ fn error_to_user_message(error: &rmcp::RmcpError) -> String {
157157
}
158158
_ => format!("Service error: {}", err),
159159
},
160+
_ => format!("Error: {}", error),
160161
}
161162
}
162163

@@ -1852,7 +1853,7 @@ async fn spawn_server(
18521853

18531854
logger.log("[info] MCP: Using Streaming HTTP transport".to_string());
18541855
let transport = rmcp::transport::StreamableHttpClientTransport::with_client(
1855-
crate::ai::mcp::http_client::McpHttpClient(client.http_client),
1856+
crate::ai::mcp::http_client::McpHttpClient(client),
18561857
rmcp::transport::streamable_http_client::StreamableHttpClientTransportConfig::with_uri(
18571858
sse_server.url.clone(),
18581859
),
@@ -1869,7 +1870,9 @@ async fn spawn_server(
18691870
let client = if headers.is_empty() {
18701871
crate::ai::mcp::http_client::McpHttpClient::default()
18711872
} else {
1872-
crate::ai::mcp::http_client::McpHttpClient(build_client_with_headers(&headers)?)
1873+
crate::ai::mcp::http_client::McpHttpClient(build_client_with_headers(
1874+
&headers,
1875+
)?)
18731876
};
18741877
rmcp::transport::StreamableHttpClientTransport::with_client(
18751878
client,
@@ -1890,7 +1893,9 @@ async fn spawn_server(
18901893
let client = if headers.is_empty() {
18911894
crate::ai::mcp::http_client::McpHttpClient::default()
18921895
} else {
1893-
crate::ai::mcp::http_client::McpHttpClient(build_client_with_headers(&headers)?)
1896+
crate::ai::mcp::http_client::McpHttpClient(build_client_with_headers(
1897+
&headers,
1898+
)?)
18941899
};
18951900
rmcp::transport::StreamableHttpClientTransport::with_client(
18961901
client,
@@ -1955,7 +1960,7 @@ async fn spawn_server(
19551960
/// The transport to use for MCP.
19561961
enum Transport {
19571962
/// The HTTP transport, with an optional authenticated client.
1958-
Http(Option<rmcp::transport::auth::AuthClient<crate::ai::mcp::http_client::McpHttpClient>>),
1963+
Http(Option<reqwest::Client>),
19591964
/// Legacy SSE transport (server responded with 404 to HTTP transport check).
19601965
LegacySse,
19611966
}
@@ -1991,18 +1996,15 @@ async fn determine_transport(
19911996
let spawner = auth_context.spawner.clone();
19921997
// Go through the OAuth flow to get an authenticated client.
19931998
// This will first attempt to use cached credentials before starting interactive OAuth.
1994-
let (client, did_require_login) = oauth::make_authenticated_client(url, auth_context)
1995-
.boxed()
1996-
.await
1997-
.map_err(rmcp::RmcpError::transport_creation::<ReqwestHttpTransport>)?;
1998-
let mcp_client = rmcp::transport::auth::AuthClient::new(
1999-
crate::ai::mcp::http_client::McpHttpClient(client.http_client),
2000-
client.auth_manager.lock().await.clone(),
2001-
);
2002-
let transport = match send_initialize_request(url, headers, Some(&mcp_client)).await? {
2003-
StatusCode::OK => Ok(Transport::Http(Some(client))),
1999+
let (auth_client, did_require_login) =
2000+
oauth::make_authenticated_client(url, auth_context)
2001+
.boxed()
2002+
.await
2003+
.map_err(rmcp::RmcpError::transport_creation::<ReqwestHttpTransport>)?;
2004+
let transport = match send_initialize_request(url, headers, Some(&auth_client)).await? {
2005+
StatusCode::OK => Ok(Transport::Http(Some(auth_client.http_client.clone()))),
20042006
StatusCode::NOT_FOUND | StatusCode::METHOD_NOT_ALLOWED => {
2005-
Ok(Transport::Http(Some(client)))
2007+
Ok(Transport::Http(Some(auth_client.http_client.clone())))
20062008
}
20072009
other => Err(unexpected_error(other)),
20082010
};
@@ -2034,7 +2036,7 @@ async fn determine_transport(
20342036
async fn send_initialize_request(
20352037
url: &str,
20362038
headers: &std::collections::HashMap<String, String>,
2037-
auth_client: Option<&rmcp::transport::auth::AuthClient<crate::ai::mcp::http_client::McpHttpClient>>,
2039+
auth_client: Option<&rmcp::transport::auth::AuthClient<reqwest::Client>>,
20382040
) -> Result<reqwest::StatusCode, rmcp::RmcpError> {
20392041
use rmcp::transport::common::http_header::{EVENT_STREAM_MIME_TYPE, JSON_MIME_TYPE};
20402042

app/src/ai/mcp/templatable_manager/oauth.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ pub async fn make_authenticated_client(
240240
// If this is a client for which we have a known client secret,
241241
// update our client config accordingly.
242242
if let Some(client_secret) = &client_secret {
243-
auth_manager.configure_client(
243+
auth_manager.configure_client(
244244
OAuthClientConfig::new(credentials.client_id.clone(), redirect_uri.clone())
245245
.with_client_secret(client_secret.clone()),
246246
)?;
@@ -319,7 +319,10 @@ pub async fn make_authenticated_client(
319319
// For apps for which we have static client IDs (e.g. GitHub), we manually override scopes.
320320
let mut scopes: &[&str] = &[];
321321

322-
let config = match auth_manager.register_client("Warp", &redirect_uri, scopes).await {
322+
let config = match auth_manager
323+
.register_client("Warp", &redirect_uri, scopes)
324+
.await
325+
{
323326
Ok(config) => config,
324327
Err(err @ AuthError::RegistrationFailed(_)) => {
325328
// If we failed dynamic registration, check to see if this is an auth

0 commit comments

Comments
 (0)