Add rustls fallback for local MCP HTTP requests (#38436)

## Why

Local MCP requests can fail when the platform TLS backend cannot negotiate a
protocol version with an HTTPS endpoint.

## What changed

- Retry replayable local MCP requests once with rustls after a recognized TLS
  protocol-version negotiation failure. Keep certificate, timeout, and unrelated
  connection failures on the existing error path.
- Remember successful fallback per HTTPS origin and outbound route, while keeping
  the platform TLS backend as the default for other destinations.
- Share the fallback-enabled client across local MCP resolution, CLI login, and
  OAuth discovery while preserving remote environment HTTP clients.

## Testing

Added coverage for platform-specific error detection, request replay, cached
fallback reuse and isolation, non-replayable requests, redirects, and remote MCP
client selection.

GitOrigin-RevId: 39a2d96fdb2ea0e51df14f652ba2a953d24e69a1
This commit is contained in:
Celia Chen
2026-08-13 21:13:07 +00:00
committed by copyberry
parent 93327c852a
commit b87327f4e5
10 changed files with 1204 additions and 30 deletions
+6 -4
View File
@@ -446,8 +446,9 @@ async fn run_add(config_overrides: &CliConfigOverrides, add_args: AddArgs) -> Re
// `mcp add` assigns new servers to the local environment, so its immediate
// OAuth discovery uses the local route-aware HTTP client.
let http_client: Arc<dyn HttpClient> =
Arc::new(RouteAwareHttpClient::new(config.http_client_factory()));
let http_client: Arc<dyn HttpClient> = Arc::new(
RouteAwareHttpClient::new(config.http_client_factory()).with_tls_backend_fallback(),
);
let login_support = oauth_login_support(
&transport,
Arc::clone(&http_client),
@@ -560,8 +561,9 @@ async fn run_login(config: &Config, login_args: LoginArgs) -> Result<()> {
// Standalone `mcp login` runs OAuth from the local CLI process; execution
// environment routing belongs to app-server and session MCP flows.
let http_client: Arc<dyn HttpClient> =
Arc::new(RouteAwareHttpClient::new(config.http_client_factory()));
let http_client: Arc<dyn HttpClient> = Arc::new(
RouteAwareHttpClient::new(config.http_client_factory()).with_tls_backend_fallback(),
);
let http_client = apply_http_headers_helper(http_client, server, config.cwd.to_path_buf())
.map_err(anyhow::Error::msg)?;
let explicit_scopes = (!scopes.is_empty()).then_some(scopes);