mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Route MCP OAuth through configured HTTP clients (#35806)
## What changed - Pass resolved, route-aware HTTP clients through MCP OAuth discovery and login so CLI commands, plugin installation, and skill dependency setup honor configured proxies and execution environments. - Apply per-plugin MCP server configuration and requirements before starting OAuth during installation, and skip disabled servers or servers assigned to unowned environments. - Preserve configured MCP server policies when merging remotely installed plugin metadata. ## Testing - Cover proxy-routed OAuth for `codex mcp add`, `codex mcp login`, plugin installation, and skill MCP dependencies. - Cover plugin-install OAuth filtering for disabled servers, plugin requirements, and unowned environments. GitOrigin-RevId: f84c88820e24a627faa78d6bed1b371682ecdc2f
This commit is contained in:
1 parent
8f00b9a04c
commit
9ea975a2dc
11 files changed
+947
-45
No files matched your search
@@ -1,5 +1,6 @@
|
||||
use std::collections::HashMap;
|
||||
use std::collections::HashSet;
|
||||
use std::sync::Arc;
|
||||
|
||||
use codex_config::ConfigEditsBuilder;
|
||||
use codex_config::McpServerConfig;
|
||||
@@ -11,6 +12,7 @@ use codex_protocol::request_user_input::RequestUserInputArgs;
|
||||
use codex_protocol::request_user_input::RequestUserInputQuestion;
|
||||
use codex_protocol::request_user_input::RequestUserInputQuestionOption;
|
||||
use codex_protocol::request_user_input::RequestUserInputResponse;
|
||||
use codex_rmcp_client::OAuthDiscoveryTimeout;
|
||||
use codex_rmcp_client::perform_oauth_login;
|
||||
use tokio_util::sync::CancellationToken;
|
||||
use tracing::warn;
|
||||
@@ -23,7 +25,7 @@ use codex_mcp::ElicitationReviewerHandle;
|
||||
use codex_mcp::McpOAuthLoginSupport;
|
||||
use codex_mcp::McpPermissionPromptAutoApproveContext;
|
||||
use codex_mcp::mcp_permission_prompt_is_auto_approved;
|
||||
use codex_mcp::oauth_login_support;
|
||||
use codex_mcp::oauth_login_support_with_http_client;
|
||||
use codex_mcp::resolve_oauth_scopes;
|
||||
use codex_mcp::should_retry_without_scopes;
|
||||
|
||||
@@ -132,8 +134,27 @@ pub(crate) async fn maybe_install_mcp_dependencies(
|
||||
return;
|
||||
}
|
||||
|
||||
let (_, runtime_context) = sess.runtime_mcp_config_and_context(config).await;
|
||||
for (name, server_config) in added {
|
||||
let oauth_config = match oauth_login_support(&server_config.transport).await {
|
||||
let http_client = match runtime_context.resolve_http_client(&name, &server_config) {
|
||||
Ok(http_client) => http_client,
|
||||
Err(err) => {
|
||||
warn!("failed to resolve MCP dependency runtime for {name}: {err}");
|
||||
continue;
|
||||
}
|
||||
};
|
||||
let discovery_timeout = if server_config.is_local_environment() {
|
||||
OAuthDiscoveryTimeout::LOCAL
|
||||
} else {
|
||||
OAuthDiscoveryTimeout::Requested
|
||||
};
|
||||
let login_support = oauth_login_support_with_http_client(
|
||||
&server_config.transport,
|
||||
Arc::clone(&http_client),
|
||||
discovery_timeout,
|
||||
)
|
||||
.await;
|
||||
let oauth_config = match login_support {
|
||||
McpOAuthLoginSupport::Supported(config) => config,
|
||||
McpOAuthLoginSupport::Unsupported => continue,
|
||||
McpOAuthLoginSupport::Unknown(err) => {
|
||||
@@ -160,6 +181,7 @@ pub(crate) async fn maybe_install_mcp_dependencies(
|
||||
server_config.oauth_resource.as_deref(),
|
||||
config.mcp_oauth_callback_port,
|
||||
config.mcp_oauth_callback_url.as_deref(),
|
||||
Arc::clone(&http_client),
|
||||
)
|
||||
.await;
|
||||
|
||||
@@ -177,6 +199,7 @@ pub(crate) async fn maybe_install_mcp_dependencies(
|
||||
server_config.oauth_resource.as_deref(),
|
||||
config.mcp_oauth_callback_port,
|
||||
config.mcp_oauth_callback_url.as_deref(),
|
||||
Arc::clone(&http_client),
|
||||
)
|
||||
.await
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user