This commit is contained in:
Matthew Zeng
2026-02-14 23:09:18 -08:00
parent 9ea4938ed0
commit c3011b865c
4 changed files with 87 additions and 47 deletions

View File

@@ -148,6 +148,7 @@ use crate::mcp::effective_mcp_servers;
use crate::mcp::maybe_prompt_and_install_mcp_dependencies;
use crate::mcp::with_codex_apps_mcp;
use crate::mcp_connection_manager::McpConnectionManager;
use crate::mcp_connection_manager::McpConnectionManagerInitializeParams;
use crate::mcp_connection_manager::codex_apps_tools_cache_key;
use crate::mcp_connection_manager::filter_codex_apps_mcp_tools_only;
use crate::mcp_connection_manager::filter_mcp_tools_by_name;
@@ -1381,13 +1382,15 @@ impl Session {
.await
.initialize(
&mcp_servers,
config.mcp_oauth_credentials_store_mode,
auth_statuses.clone(),
tx_event.clone(),
cancel_token,
sandbox_state,
config.codex_home.clone(),
codex_apps_tools_cache_key(auth),
McpConnectionManagerInitializeParams {
store_mode: config.mcp_oauth_credentials_store_mode,
auth_entries: auth_statuses.clone(),
tx_event: tx_event.clone(),
cancel_token,
initial_sandbox_state: sandbox_state,
codex_home: config.codex_home.clone(),
codex_apps_tools_cache_key: codex_apps_tools_cache_key(auth),
},
)
.await;
if !required_mcp_servers.is_empty() {
@@ -3001,13 +3004,15 @@ impl Session {
refreshed_manager
.initialize(
&mcp_servers,
store_mode,
auth_statuses,
self.get_tx_event(),
cancel_token,
sandbox_state,
config.codex_home.clone(),
codex_apps_tools_cache_key(auth.as_ref()),
McpConnectionManagerInitializeParams {
store_mode,
auth_entries: auth_statuses,
tx_event: self.get_tx_event(),
cancel_token,
initial_sandbox_state: sandbox_state,
codex_home: config.codex_home.clone(),
codex_apps_tools_cache_key: codex_apps_tools_cache_key(auth.as_ref()),
},
)
.await;

View File

@@ -23,6 +23,7 @@ use crate::mcp::CODEX_APPS_MCP_SERVER_NAME;
use crate::mcp::auth::compute_auth_statuses;
use crate::mcp::with_codex_apps_mcp;
use crate::mcp_connection_manager::McpConnectionManager;
use crate::mcp_connection_manager::McpConnectionManagerInitializeParams;
use crate::mcp_connection_manager::codex_apps_tools_cache_key;
use crate::token_data::TokenData;
@@ -135,13 +136,15 @@ pub async fn list_accessible_connectors_from_mcp_tools_with_options_and_status(
mcp_connection_manager
.initialize(
&mcp_servers,
config.mcp_oauth_credentials_store_mode,
auth_status_entries,
tx_event,
cancel_token.clone(),
sandbox_state,
config.codex_home.clone(),
codex_apps_tools_cache_key(auth.as_ref()),
McpConnectionManagerInitializeParams {
store_mode: config.mcp_oauth_credentials_store_mode,
auth_entries: auth_status_entries,
tx_event,
cancel_token: cancel_token.clone(),
initial_sandbox_state: sandbox_state,
codex_home: config.codex_home.clone(),
codex_apps_tools_cache_key: codex_apps_tools_cache_key(auth.as_ref()),
},
)
.await;

View File

@@ -24,6 +24,7 @@ use crate::config::types::McpServerTransportConfig;
use crate::features::Feature;
use crate::mcp::auth::compute_auth_statuses;
use crate::mcp_connection_manager::McpConnectionManager;
use crate::mcp_connection_manager::McpConnectionManagerInitializeParams;
use crate::mcp_connection_manager::SandboxState;
use crate::mcp_connection_manager::codex_apps_tools_cache_key;
@@ -208,13 +209,15 @@ pub async fn collect_mcp_snapshot(config: &Config) -> McpListToolsResponseEvent
mcp_connection_manager
.initialize(
&mcp_servers,
config.mcp_oauth_credentials_store_mode,
auth_status_entries.clone(),
tx_event,
cancel_token.clone(),
sandbox_state,
config.codex_home.clone(),
codex_apps_tools_cache_key(auth.as_ref()),
McpConnectionManagerInitializeParams {
store_mode: config.mcp_oauth_credentials_store_mode,
auth_entries: auth_status_entries.clone(),
tx_event,
cancel_token: cancel_token.clone(),
initial_sandbox_state: sandbox_state,
codex_home: config.codex_home.clone(),
codex_apps_tools_cache_key: codex_apps_tools_cache_key(auth.as_ref()),
},
)
.await;

View File

@@ -388,12 +388,16 @@ impl AsyncManagedClient {
match start_server_task(
server_name,
client,
config.startup_timeout_sec.or(Some(DEFAULT_STARTUP_TIMEOUT)),
config.tool_timeout_sec.unwrap_or(DEFAULT_TOOL_TIMEOUT),
startup_tool_filter,
tx_event,
elicitation_requests,
codex_apps_tools_cache_context,
StartServerTaskParams {
startup_timeout: config
.startup_timeout_sec
.or(Some(DEFAULT_STARTUP_TIMEOUT)),
tool_timeout: config.tool_timeout_sec.unwrap_or(DEFAULT_TOOL_TIMEOUT),
tool_filter: startup_tool_filter,
tx_event,
elicitation_requests,
codex_apps_tools_cache_context,
},
)
.or_cancel(&cancel_token)
.await
@@ -473,18 +477,31 @@ pub(crate) struct McpConnectionManager {
elicitation_requests: ElicitationRequestManager,
}
pub(crate) struct McpConnectionManagerInitializeParams {
pub(crate) store_mode: OAuthCredentialsStoreMode,
pub(crate) auth_entries: HashMap<String, McpAuthStatusEntry>,
pub(crate) tx_event: Sender<Event>,
pub(crate) cancel_token: CancellationToken,
pub(crate) initial_sandbox_state: SandboxState,
pub(crate) codex_home: PathBuf,
pub(crate) codex_apps_tools_cache_key: CodexAppsToolsCacheKey,
}
impl McpConnectionManager {
pub async fn initialize(
&mut self,
mcp_servers: &HashMap<String, McpServerConfig>,
store_mode: OAuthCredentialsStoreMode,
auth_entries: HashMap<String, McpAuthStatusEntry>,
tx_event: Sender<Event>,
cancel_token: CancellationToken,
initial_sandbox_state: SandboxState,
codex_home: PathBuf,
codex_apps_tools_cache_key: CodexAppsToolsCacheKey,
params: McpConnectionManagerInitializeParams,
) {
let McpConnectionManagerInitializeParams {
store_mode,
auth_entries,
tx_event,
cancel_token,
initial_sandbox_state,
codex_home,
codex_apps_tools_cache_key,
} = params;
if cancel_token.is_cancelled() {
return;
}
@@ -1125,13 +1142,16 @@ impl From<anyhow::Error> for StartupOutcomeError {
async fn start_server_task(
server_name: String,
client: Arc<RmcpClient>,
startup_timeout: Option<Duration>, // TODO: cancel_token should handle this.
tool_timeout: Duration,
tool_filter: ToolFilter,
tx_event: Sender<Event>,
elicitation_requests: ElicitationRequestManager,
codex_apps_tools_cache_context: Option<CodexAppsToolsCacheContext>,
params: StartServerTaskParams,
) -> Result<ManagedClient, StartupOutcomeError> {
let StartServerTaskParams {
startup_timeout,
tool_timeout,
tool_filter,
tx_event,
elicitation_requests,
codex_apps_tools_cache_context,
} = params;
let params = InitializeRequestParams {
meta: None,
capabilities: ClientCapabilities {
@@ -1210,6 +1230,15 @@ async fn start_server_task(
Ok(managed)
}
struct StartServerTaskParams {
startup_timeout: Option<Duration>, // TODO: cancel_token should handle this.
tool_timeout: Duration,
tool_filter: ToolFilter,
tx_event: Sender<Event>,
elicitation_requests: ElicitationRequestManager,
codex_apps_tools_cache_context: Option<CodexAppsToolsCacheContext>,
}
async fn make_rmcp_client(
server_name: &str,
transport: McpServerTransportConfig,