Route MCP auth discovery through runtime HTTP clients (#35239)

## Why

MCP authentication checks need to use the same HTTP routing as the MCP
transport so servers reached through configured proxies can be discovered
reliably.

## What changed

- Resolve OAuth discovery and authentication status through each server's
  runtime HTTP client for both local and managed environments.
- Keep local discovery capped at five seconds while allowing explicit login
  requests to retain their requested timeout.
- Resolve refreshed MCP configuration and its runtime context from the same
  snapshot.

## Testing

- Cover OAuth discovery through an environment proxy and macOS system proxy
  resolution.
- Cover proxied MCP startup and runtime refresh with updated authorization
  headers.
- Verify capped and preserved OAuth discovery timeout policies.

GitOrigin-RevId: 461fb1d4786e547df8b1e6b2215a8ac40438a3aa
This commit is contained in:
Celia Chen authored and copyberry committed 2026-07-24 20:04:23 +00:00
1 parent 544007d006
commit 89a3b89c4c
9 files changed
+541 -49

No files matched your search

@@ -172,8 +172,12 @@ impl McpRequestProcessor {
})?;
let discovered_scopes = if scopes.is_none() && server.scopes.is_none() {
discover_supported_scopes_with_http_client(&server.transport, Arc::clone(&http_client))
.await
discover_supported_scopes_with_http_client(
&server.transport,
Arc::clone(&http_client),
codex_rmcp_client::OAuthDiscoveryTimeout::Requested,
)
.await
} else {
None
};
@@ -250,11 +254,7 @@ impl McpRequestProcessor {
let mcp_manager = self.thread_manager.mcp_manager();
let auth = self.auth_manager.auth().await;
let (mcp_config, runtime_context) = match thread {
Some(thread) => {
let mcp_config = thread.runtime_mcp_config(&config).await;
let (_, runtime_context) = thread.current_mcp_config_and_runtime_context().await;
(mcp_config, runtime_context)
}
Some(thread) => thread.runtime_mcp_config_and_context(&config).await,
None => {
let mcp_config = mcp_manager.runtime_config(&config).await;
let runtime_context = McpRuntimeContext::new(