mirror of
https://github.com/openai/codex.git
synced 2026-11-23 07:17:11 +00:00
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:
1 parent
544007d006
commit
89a3b89c4c
9 files changed
+541
-49
No files matched your search
@@ -16,6 +16,8 @@ use rmcp::transport::auth::OAuthHttpClientFuture;
|
||||
use rmcp::transport::auth::OAuthHttpRedirectPolicy;
|
||||
use rmcp::transport::auth::OAuthHttpRequest;
|
||||
|
||||
use crate::auth_status::OAuthDiscoveryTimeout;
|
||||
|
||||
const MAX_OAUTH_HTTP_RESPONSE_BODY_BYTES: usize = 1024 * 1024;
|
||||
static NEXT_OAUTH_REQUEST_ID: AtomicU64 = AtomicU64::new(0);
|
||||
|
||||
@@ -23,6 +25,7 @@ static NEXT_OAUTH_REQUEST_ID: AtomicU64 = AtomicU64::new(0);
|
||||
pub(crate) struct OAuthHttpClientAdapter {
|
||||
http_client: Arc<dyn HttpClient>,
|
||||
default_headers: HeaderMap,
|
||||
timeout: OAuthDiscoveryTimeout,
|
||||
}
|
||||
|
||||
impl OAuthHttpClientAdapter {
|
||||
@@ -30,6 +33,19 @@ impl OAuthHttpClientAdapter {
|
||||
Self {
|
||||
http_client,
|
||||
default_headers,
|
||||
timeout: OAuthDiscoveryTimeout::Requested,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn new_with_max_timeout(
|
||||
http_client: Arc<dyn HttpClient>,
|
||||
default_headers: HeaderMap,
|
||||
max_timeout: Duration,
|
||||
) -> Self {
|
||||
Self {
|
||||
http_client,
|
||||
default_headers,
|
||||
timeout: OAuthDiscoveryTimeout::Capped(max_timeout),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,6 +82,12 @@ impl OAuthHttpClientAdapter {
|
||||
})
|
||||
})
|
||||
.collect::<Result<Vec<_>, OAuthHttpClientError>>()?;
|
||||
let timeout = match self.timeout {
|
||||
OAuthDiscoveryTimeout::Requested => timeout,
|
||||
OAuthDiscoveryTimeout::Capped(max_timeout) => {
|
||||
Some(timeout.map_or(max_timeout, |timeout| timeout.min(max_timeout)))
|
||||
}
|
||||
};
|
||||
let timeout_ms = timeout.map(|timeout| {
|
||||
u64::try_from(timeout.as_millis())
|
||||
.unwrap_or(u64::MAX)
|
||||
|
||||
Reference in new issue
Block a user