aKode fase 2b-2: rimosso login ChatGPT e tutti i sottosistemi solo-ChatGPT

- Login: resta solo chiave API (+ header, Bedrock). Rimossi OAuth/browser,
  device code, refresh/revoke su auth.openai.com, PAT, agent/workload identity,
  runtime agent instance, backend-client e openapi-models, workspace routing.
- Rimossi: generazione immagini (ext + skill imagegen), history notes, plugin
  remoti (catalogo, sync, share), cyber access program, daybreak, cloud config
  e requirements (config_server ora fail-closed), attestation, frozen cloud
  skills, EMA MCP auth, Codex Apps/connettori, ricerca ospitata, header/zstd/
  routing/cookie del backend Codex, fallback OPENAI_API_KEY del realtime.
- Messaggi d'errore senza link a chatgpt.com.
- Chiavi di config legacy accettate e ignorate; feature rimosse = Stage::Removed.
- Test: cancellati solo quelli del codice rimosso; test di sicurezza
  (sandbox estensioni, permessi, redazione, auth storage, requirements)
  adattati. Restano solo fallimenti d'ambiente (code-mode-host/V8, ~/.agents).
- Istruzioni di sistema invariate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
andrea.difonzo
2026-11-10 16:20:15 +01:00
parent 82347a58ed
commit 6089fbde91
1573 changed files with 10289 additions and 177679 deletions

View File

@@ -22,15 +22,12 @@ mod status;
#[path = "connection_manager/tool_catalog.rs"]
mod tool_catalog;
use startup::chatgpt_auth_provider_for_server;
use startup::emit_update;
use startup::mcp_init_error_display;
use startup::mcp_startup_failure_reason;
use startup::should_share_codex_apps_tools_cache;
pub(crate) use tool_catalog::BindingCatalogRevision;
pub use tool_catalog::tool_is_model_visible;
use codex_config::McpServerAuth;
use std::cell::LazyCell;
use std::collections::HashMap;
use std::sync::Arc;
@@ -45,17 +42,13 @@ use crate::connection_pool::ConnectionKey;
use crate::connection_pool::ConnectionSharing;
use crate::elicitation::ElicitationRequestManager;
use crate::elicitation::ElicitationRequestRouter;
use crate::event_stream::EventStreamConnectionSettings;
use crate::mcp::CODEX_APPS_MCP_SERVER_NAME;
use crate::mcp::ToolPluginContext;
use crate::pagination::MAX_CODEX_APPS_TOOL_CATALOG_ITEMS;
use crate::pagination::MAX_MCP_CATALOG_ITEMS;
use crate::rmcp_client::AsyncManagedClient;
use crate::rmcp_client::DEFAULT_STARTUP_TIMEOUT;
use crate::rmcp_client::DEFAULT_TOOL_TIMEOUT;
use crate::rmcp_client::ManagedClient;
use crate::rmcp_client::StartupOutcomeError;
use crate::rmcp_client::prepare_codex_apps_tools_for_model;
use crate::rmcp_client::prepare_regular_mcp_tools_for_model;
use crate::runtime::McpPublicationGate;
use crate::runtime::McpRuntimeInput;
@@ -65,8 +58,6 @@ use crate::server::McpServerMetadata;
use crate::tools::ToolFilter;
use crate::tools::ToolInfo;
use crate::tools::filter_tools;
use crate::trusted_access::ENTITLEMENT_CONTEXT_KEY;
use crate::trusted_access::TrustedAccessContext;
use anyhow::Context;
use anyhow::Result;
use anyhow::anyhow;
@@ -77,8 +68,6 @@ use codex_diagnostics::Gauge;
use codex_diagnostics::GaugeGuard;
use codex_otel::auth_storage::AuthStorageOriginator;
use codex_protocol::mcp::CallToolResult;
use codex_protocol::mcp::ClientMcpExtensions;
use codex_protocol::mcp::ENTERPRISE_MANAGED_AUTHORIZATION_EXTENSION_ID;
use codex_protocol::mcp::McpServerInfo;
use codex_protocol::protocol::Event;
use codex_protocol::protocol::EventMsg;
@@ -94,6 +83,9 @@ use tokio::sync::watch;
use tokio::task::JoinSet;
use tracing::warn;
/// Host-owned entitlement metadata that direct callers may never supply.
const ENTITLEMENT_CONTEXT_KEY: &str = "openai/entitlementContext";
static LIVE_CONNECTIONS: Gauge = Gauge::new("mcp.connections.live");
pub(crate) struct McpServerConnection {
@@ -103,9 +95,6 @@ pub(crate) struct McpServerConnection {
// Startup-only budget; changing it must not replace a ready connection.
startup_timeout: Duration,
startup_trigger: Option<watch::Sender<bool>>,
// Only the initial host-owned Apps attempt publishes here. A retry uses normal readiness.
initialized_apps:
Option<watch::Receiver<Option<std::sync::Weak<codex_rmcp_client::RmcpClient>>>>,
_diagnostics_guard: GaugeGuard,
}
@@ -203,18 +192,7 @@ impl McpServerConnection {
}
async fn client_for_call(&self) -> Result<ManagedClient, StartupOutcomeError> {
let result = self.client().await;
if matches!(result, Err(StartupOutcomeError::Failed { .. }))
&& !self.client.cancel_token.is_cancelled()
&& let Some(reconnect) = &self.client.startup_reconnect
{
if let Some(attempt) = reconnect.reconnect_in_background() {
return attempt.await;
}
// Recovery may have finished between reading the client and joining it.
return self.client().await;
}
result
self.client().await
}
async fn shutdown(&self) {
@@ -267,18 +245,17 @@ impl McpServerView {
}
fn accepts_cached_tools(&self, tools: &[ToolInfo]) -> bool {
self.connection.client.is_codex_apps_mcp_server
|| match self.startup_readiness {
McpStartupReadiness::Connection => !tools.is_empty(),
McpStartupReadiness::Catalog => tools.iter().any(|tool| {
self.tool_filter.allows(&tool.tool.name)
&& (self.connection.startup_is_dormant() || tool_is_model_visible(tool))
}),
}
match self.startup_readiness {
McpStartupReadiness::Connection => !tools.is_empty(),
McpStartupReadiness::Catalog => tools.iter().any(|tool| {
self.tool_filter.allows(&tool.tool.name)
&& (self.connection.startup_is_dormant() || tool_is_model_visible(tool))
}),
}
}
async fn refresh_notified_catalog(&self, server_name: &str, client: &ManagedClient) {
if !self.refresh_tool_list || self.connection.client.is_codex_apps_mcp_server {
if !self.refresh_tool_list {
return;
}
let timeout = self.refresh_timeout;
@@ -287,8 +264,6 @@ impl McpServerView {
.refresh_after_notifications(&client.client.tool_list_revision(), timeout, || async {
let relist = crate::rmcp_client::list_tools_for_client_uncached(
server_name,
/*is_codex_apps_mcp_server*/ false,
"list_changed",
&client.client,
Some(timeout),
self.catalog_item_limit,
@@ -317,11 +292,7 @@ impl McpServerView {
self.connection.client.listed_catalog().await?
};
let tools = filter_tools(tools, &self.tool_filter);
let tools = if self.connection.client.is_codex_apps_mcp_server {
prepare_codex_apps_tools_for_model(tools, tool_plugin_context)
} else {
prepare_regular_mcp_tools_for_model(tools, tool_plugin_context)
};
let tools = prepare_regular_mcp_tools_for_model(tools, tool_plugin_context);
Ok((tools, meta))
}
}
@@ -336,7 +307,6 @@ pub(crate) struct McpConnectionSet {
config: Option<Arc<crate::McpConfig>>,
network_policy_metadata: Option<Arc<dyn NetworkPolicyMetadataProvider>>,
servers: HashMap<String, McpServerView>,
pub(crate) event_stream_connection: Option<Arc<EventStreamConnectionSettings>>,
disabled_servers: Vec<String>,
required_servers: Vec<String>,
optional_startup_deadline: OnceLock<tokio::time::Instant>,
@@ -344,15 +314,13 @@ pub(crate) struct McpConnectionSet {
prefix_mcp_tool_names: bool,
non_prefixed_mcp_tool_servers: Vec<String>,
elicitation_requests: ElicitationRequestManager,
pub(crate) trusted_access: Option<TrustedAccessContext>,
}
impl McpConnectionSet {
/// Creates an MCP connection manager. Threadless callers can pass no `tx_event`; startup
/// notifications are then skipped and interactive elicitations are declined.
pub async fn new(
ema_auth: Option<crate::ema_auth::EmaAuthContext>,
existing_ema: Option<&Self>,
predecessor: Option<&Self>,
previous: Option<PreviousMcpConnections<'_>>,
publication_gate: McpPublicationGate,
input: McpRuntimeInput,
@@ -360,7 +328,6 @@ impl McpConnectionSet {
) -> Self {
let same_owner = previous.as_ref().is_some_and(|state| state.same_owner);
let previous = previous.map(|state| state.connections);
let trusted_access = TrustedAccessContext::from_runtime(&input);
let McpRuntimeInput {
startup_policy,
config,
@@ -372,29 +339,23 @@ impl McpConnectionSet {
tx_event,
startup_cancellation_token,
runtime_context,
codex_apps_tools_cache,
tool_catalog_cache,
codex_apps_tools_cache_key,
client_mcp_extensions,
auth,
auth_manager,
runtime_auth,
elicitation_reviewer,
elicitation_lifecycle,
} = input;
let store_mode = config.mcp_oauth_credentials_store_mode;
let keyring_backend_kind = config.auth_keyring_backend_kind;
let oauth_refresh_mode = config.oauth_refresh_mode;
let codex_home = config.codex_home.clone();
let prefix_mcp_tool_names = config.prefix_mcp_tool_names;
let non_prefixed_mcp_tool_servers = config.non_prefixed_mcp_tool_servers.clone();
let default_protocol_mode = config.protocol_mode;
let host_owned_apps_protocol_mode = config.host_owned_apps_protocol_mode;
let client_elicitation_capability = config.client_elicitation_capability.clone();
let tool_plugin_context = crate::mcp::tool_plugin_context(&config);
let auth = auth.as_ref();
let mut servers = HashMap::new();
let mut event_stream_connection = None;
let disabled_servers = mcp_servers
.iter()
.filter(|(_, server)| !server.enabled())
@@ -410,18 +371,7 @@ impl McpConnectionSet {
let mut eager_starts = Vec::new();
let mut eager_workers = Vec::new();
let mut deferred_workers = Vec::new();
// Retained EMA clients keep callbacks attached to this manager even when
// an explicit reconnect replaces the ordinary clients.
let elicitation_previous = previous
.or_else(|| {
existing_ema.filter(|previous| {
previous
.servers
.values()
.any(|view| view.connection.client.ema_authority.is_some())
})
})
.filter(|previous| {
let elicitation_previous = previous.filter(|previous| {
!previous.servers.is_empty()
&& previous.elicitation_requests.update(
Arc::clone(&config),
@@ -442,35 +392,14 @@ impl McpConnectionSet {
};
let tool_plugin_context = Arc::new(tool_plugin_context);
let startup_submit_id = submit_id;
let static_chatgpt_auth_provider = auth
.filter(|auth| auth.uses_codex_backend())
.map(codex_model_provider::auth_provider_from_auth);
let codex_apps_auth_provider = auth_manager.as_ref().and_then(|auth_manager| {
auth.filter(|auth| auth.uses_codex_backend()).map(|auth| {
codex_model_provider::auth_provider_from_auth_manager(
Arc::clone(auth_manager),
auth,
)
})
});
for (server_name, server) in mcp_servers
.into_iter()
.filter(|(_, server)| server.enabled())
{
let server = server.with_read_only_mcp_tools(config.requires_read_only_mcp_tools);
let registration = config.mcp_server_catalog.server(&server_name);
let client_mcp_extensions = crate::client_capabilities::server_mcp_extensions(
&client_mcp_extensions,
&server_name,
registration,
network_policy_metadata.is_some(),
&config.chatgpt_base_url,
);
let is_host_owned_codex_apps = registration.is_some_and(|server| {
server
.source()
.is_host_owned_apps(&server_name, server.config())
});
let client_mcp_extensions =
crate::client_capabilities::server_mcp_extensions(&client_mcp_extensions);
let host_plugin_root = registration.and_then(|server| match server.source() {
McpServerSource::Plugin(plugin) => plugin.host_root(),
McpServerSource::SelectedPlugin(_)
@@ -478,11 +407,7 @@ impl McpConnectionSet {
| McpServerSource::Compatibility { .. }
| McpServerSource::Extension { .. } => None,
});
let catalog_item_limit = if is_host_owned_codex_apps {
MAX_CODEX_APPS_TOOL_CATALOG_ITEMS
} else {
MAX_MCP_CATALOG_ITEMS
};
let catalog_item_limit = MAX_MCP_CATALOG_ITEMS;
let metadata = McpServerMetadata::from(&server);
let configured_config = server.config().clone();
let protocol_mode = if matches!(
@@ -491,34 +416,10 @@ impl McpConnectionSet {
) {
registration
.and_then(crate::ResolvedMcpServer::protocol_mode)
.unwrap_or(if is_host_owned_codex_apps {
host_owned_apps_protocol_mode
} else {
default_protocol_mode
})
.unwrap_or(default_protocol_mode)
} else {
default_protocol_mode
};
let uses_ema_auth =
config.xaa_enabled && matches!(configured_config.auth, McpServerAuth::EmaAuth);
let protocol_mode = if uses_ema_auth {
McpProtocolMode::V20260728
} else {
protocol_mode
};
let client_mcp_extensions = if uses_ema_auth {
ClientMcpExtensions::new(
client_mcp_extensions
.iter()
.map(|(id, settings)| (id.to_string(), settings.clone()))
.chain(std::iter::once((
ENTERPRISE_MANAGED_AUTHORIZATION_EXTENSION_ID.to_string(),
serde_json::json!({}),
))),
)
} else {
client_mcp_extensions
};
let configured_tool_filter = ToolFilter::from_config(&configured_config);
let startup_timeout = configured_config
.startup_timeout_sec
@@ -530,109 +431,13 @@ impl McpConnectionSet {
);
let resolved_environment =
runtime_context.resolve_server_environment(&server_name, &configured_config);
// For built-in Codex Apps, `CODEX_CONNECTORS_TOKEN` is a debug
// override: it supplies runtime auth but bypasses the shared tools
// cache.
let uses_env_bearer_token = match &configured_config.transport {
McpServerTransportConfig::StreamableHttp {
bearer_token_env_var,
..
} => bearer_token_env_var.is_some(),
McpServerTransportConfig::Stdio { .. } => false,
};
// Filtered catalogs must not read or populate an unrestricted shared cache.
let eligible_for_apps_cache = is_host_owned_codex_apps
&& !server.requires_read_only_mcp_tools()
&& should_share_codex_apps_tools_cache(&server_name, uses_env_bearer_token);
let shares_codex_apps_tools_cache =
eligible_for_apps_cache && codex_apps_tools_cache.shares_snapshot();
let openai_runtime = runtime_auth.as_ref().filter(|_| {
!uses_env_bearer_token
&& configured_config.is_local_environment()
&& matches!(configured_config.auth, codex_config::McpServerAuth::ChatGpt)
&& auth.is_some_and(codex_login::CodexAuth::uses_codex_backend)
&& matches!(&configured_config.transport,
McpServerTransportConfig::StreamableHttp { url, .. }
if codex_http_client::classify_openai_api_url(url)
!= codex_http_client::OpenAiDestination::Other)
});
let runtime_auth_mode = openai_runtime.map(|(_, mode)| *mode);
let codex_apps_tools_cache_context = shares_codex_apps_tools_cache.then(|| {
// Only equivalent discovery inputs may share executable Apps tools.
let mut transport = configured_config.transport.clone();
if let McpServerTransportConfig::StreamableHttp {
http_headers: Some(headers),
..
} = &mut transport
{
// mcp_server_config_for_url in codex-rs/codex-mcp/src/mcp/mod.rs
// adds thread attribution that threadless discovery does not carry.
headers.retain(|name, _| !name.eq_ignore_ascii_case("originator"));
}
let mut scope = serde_json::json!([
transport,
&configured_config.auth,
runtime_auth_mode,
protocol_mode.preferred_protocol_version().as_str(),
catalog_item_limit,
&client_elicitation_capability,
client_mcp_extensions
.iter()
.collect::<std::collections::BTreeMap<_, _>>(),
]);
scope.sort_all_objects();
codex_apps_tools_cache
.context(codex_home.clone(), codex_apps_tools_cache_key.clone())
.with_live_scope(scope.to_string())
});
// The reserved Codex Apps registration follows the shared
// AuthManager across refreshes. In the hosted-plugin path, this
// is the ChatGPT /ps/mcp connection. User-configured MCP
// registrations keep their existing configured auth path.
let chatgpt_auth_provider = if server_name == CODEX_APPS_MCP_SERVER_NAME {
codex_apps_auth_provider
.clone()
.or_else(|| static_chatgpt_auth_provider.clone())
} else {
static_chatgpt_auth_provider.clone()
};
// If Codex Apps has an env bearer token, that is its auth path. Do
// not also attach the ambient CodexAuth provider.
let runtime_auth_provider =
if server_name == CODEX_APPS_MCP_SERVER_NAME && uses_env_bearer_token {
None
} else {
chatgpt_auth_provider_for_server(&server, chatgpt_auth_provider).map(
|provider| match (openai_runtime, auth) {
(Some(runtime), Some(auth)) => {
crate::auth::McpAuthProvider::runtime(runtime.clone(), auth.clone())
}
_ => crate::auth::McpAuthProvider::Credentials(provider),
},
)
};
let discover_local_stdio = config.discover_local_stdio
&& server.can_discover_local_stdio(&server_name, runtime_auth_provider.as_ref());
let discover_local_stdio =
config.discover_local_stdio && server.can_discover_local_stdio();
let protocol_mode = if discover_local_stdio {
McpProtocolMode::DiscoverLocalStdio
} else {
protocol_mode
};
if is_host_owned_codex_apps {
event_stream_connection = Some(Arc::new(EventStreamConnectionSettings {
server: server.clone(),
store_mode,
keyring_backend_kind,
oauth_refresh_mode,
runtime_context: runtime_context.clone(),
resolved_environment: resolved_environment.clone(),
auth_provider: runtime_auth_provider.clone(),
auth_manager: auth_manager.clone(),
auth: auth.cloned(),
protocol_mode,
client_mcp_extensions: client_mcp_extensions.clone(),
}));
}
let connection_identity = McpServerConnectionIdentity::new(
&server_name,
&server,
@@ -642,11 +447,6 @@ impl McpConnectionSet {
oauth_refresh_mode,
&resolved_environment,
&runtime_context,
runtime_auth_provider.as_ref(),
runtime_auth_mode,
auth,
eligible_for_apps_cache
.then(|| (codex_home.clone(), codex_apps_tools_cache_key.clone())),
client_elicitation_capability.clone(),
client_mcp_extensions.clone(),
previous
@@ -658,10 +458,7 @@ impl McpConnectionSet {
McpServerTransportConfig::Stdio { .. } => server.stdio_protocol_mode(protocol_mode),
};
let mut tool_catalog_cache_context = LazyCell::new(|| {
if server_name == CODEX_APPS_MCP_SERVER_NAME
|| server.requires_read_only_mcp_tools()
|| matches!(configured_config.auth, McpServerAuth::EmaAuth)
{
if server.requires_read_only_mcp_tools() {
return None;
}
let environment = resolved_environment.as_ref().ok()?;
@@ -710,62 +507,6 @@ impl McpConnectionSet {
&& protocol_mode != McpProtocolMode::Legacy
&& (auth.is_none() || auth_manager.is_some())
});
if matches!(configured_config.auth, McpServerAuth::EmaAuth) && existing_ema.is_some() {
if let Some(previous_view) = existing_ema
.filter(|_| elicitation_previous.is_some())
.and_then(|previous| previous.servers.get(&server_name))
{
let connection = &previous_view.connection;
let authority_is_current = || {
connection
.client
.ema_authority
.as_ref()
.is_some_and(|authority| authority.check_new_request().is_ok())
};
let same_identity = connection.identity.as_ref() == Some(&connection_identity)
&& previous_view.catalog_item_limit == catalog_item_limit
&& previous_view.protocol_mode == protocol_mode;
let pending = same_identity
&& !connection.client.startup_complete.load(Ordering::Acquire)
&& connection.startup_timeout == startup_timeout
&& !connection.startup_is_dormant()
&& !connection.client.cancel_token.is_cancelled();
let ready = same_identity
&& !pending
&& connection
.reusable_client(&connection_identity)
.await
.is_some_and(|client| {
expected_protocol_mode == Some(client.client.protocol_mode())
});
if authority_is_current() && (pending || ready) {
servers.insert(
server_name.clone(),
McpServerView {
connection: Arc::clone(connection),
protocol_mode,
startup_readiness: configured_config.startup_readiness,
refresh_tool_list: config.mcp_tool_list_changed,
refresh_timeout: startup_timeout,
metadata,
tool_filter: configured_tool_filter,
tool_timeout: configured_tool_timeout,
catalog_item_limit,
},
);
if pending {
let client = connection.client.clone();
eager_workers
.push(async move { (server_name, client.client().await) }.boxed());
} else {
reused_ready.push(server_name);
}
}
}
// Post-start publications may only retain the original EMA connection.
continue;
}
let mut legacy_to_upgrade = None;
if let Some(previous_view) =
reusable_previous.and_then(|previous| previous.servers.get(&server_name))
@@ -888,14 +629,12 @@ impl McpConnectionSet {
}
let cancel_token = startup_cancellation_token.child_token();
let tool_catalog_cache_context = tool_catalog_cache_context.take();
let has_runtime_auth = runtime_auth_provider.is_some();
let connection_pool = connection_pool.map(|pool| {
(
pool.clone(),
ConnectionKey {
server_name: server_name.clone(),
identity: connection_identity.clone(),
account: codex_apps_tools_cache_key.clone(),
auth_state: auth_manager.as_ref().map(|manager| {
(
Arc::clone(manager),
@@ -907,17 +646,8 @@ impl McpConnectionSet {
},
)
});
let (publish_apps, initialized_apps) =
if is_host_owned_codex_apps && config.apps_early_resource_discovery {
let (tx, rx) = watch::channel(None);
(Some(tx), Some(rx))
} else {
(None, None)
};
let mut async_managed_client = AsyncManagedClient::new(
ema_auth.clone(),
server_name.clone(),
startup_submit_id.clone(),
server,
store_mode,
keyring_backend_kind,
@@ -925,11 +655,9 @@ impl McpConnectionSet {
cancel_token.clone(),
tx_event.clone(),
elicitation_requests.clone(),
codex_apps_tools_cache_context,
tool_catalog_cache_context,
runtime_context.clone(),
resolved_environment,
runtime_auth_provider,
client_elicitation_capability.clone(),
client_mcp_extensions.clone(),
auth_manager
@@ -945,10 +673,9 @@ impl McpConnectionSet {
defer_startup,
catalog_item_limit,
connection_pool,
publish_apps,
);
// A forced reconnect must also wait for the previously published helper to exit.
if let Some(previous) = existing_ema.and_then(|set| set.servers.get(&server_name)) {
if let Some(previous) = predecessor.and_then(|set| set.servers.get(&server_name)) {
async_managed_client.wait_for_failed_predecessor(&previous.connection.client);
}
let legacy_fallback = legacy_to_upgrade
@@ -968,7 +695,6 @@ impl McpConnectionSet {
legacy_fallback,
startup_timeout,
startup_trigger,
initialized_apps,
_diagnostics_guard: LIVE_CONNECTIONS.track(),
}),
protocol_mode,
@@ -1013,10 +739,7 @@ impl McpConnectionSet {
}
if let Some(tx_event) = tx_event.as_ref() {
let auth_state = match &outcome {
Err(error)
if error.is_authentication_required()
&& !has_runtime_auth
&& !matches!(configured_config.auth, McpServerAuth::EmaAuth) =>
Err(error) if error.is_authentication_required() =>
{
match &configured_config.transport {
McpServerTransportConfig::StreamableHttp {
@@ -1086,10 +809,6 @@ impl McpConnectionSet {
outcome = Err(StartupOutcomeError::Cancelled);
}
if matches!(&outcome, Err(StartupOutcomeError::Failed { .. })) {
async_managed_client.reconnect_failed_startup().await;
}
(server_name, outcome)
};
let startup = AuthStorageOriginator::current().scope(startup);
@@ -1104,7 +823,6 @@ impl McpConnectionSet {
config: Some(config),
network_policy_metadata,
servers,
event_stream_connection,
disabled_servers,
required_servers,
optional_startup_deadline: OnceLock::new(),
@@ -1112,7 +830,6 @@ impl McpConnectionSet {
prefix_mcp_tool_names,
non_prefixed_mcp_tool_servers,
elicitation_requests: elicitation_requests.clone(),
trusted_access,
};
tokio::spawn(async move {
if !publication_gate.wait().await {
@@ -1181,7 +898,6 @@ impl McpConnectionSet {
config: None,
network_policy_metadata: None,
servers: HashMap::new(),
event_stream_connection: None,
disabled_servers: Vec::new(),
required_servers: Vec::new(),
optional_startup_deadline: OnceLock::new(),
@@ -1189,7 +905,6 @@ impl McpConnectionSet {
prefix_mcp_tool_names,
non_prefixed_mcp_tool_servers: Vec::new(),
elicitation_requests: ElicitationRequestManager::default(),
trusted_access: None,
}
}
@@ -1450,30 +1165,15 @@ impl McpConnectionSet {
}
/// Returns presentation metadata from the current connection.
/// Codex Apps metadata may come from its existing cache; regular MCP server information is
/// connection-specific, so pending regular clients are awaited.
/// Server information is connection-specific, so pending clients are awaited.
pub(crate) async fn list_available_server_infos(
&self,
include_server: impl Fn(&str) -> bool,
) -> HashMap<String, McpServerInfo> {
let mut server_infos = HashMap::new();
for (server_name, view) in self.servers.iter().filter(|(name, _)| include_server(name)) {
let client = &view.connection.client;
if !client.startup_complete.load(Ordering::Acquire)
&& let Some(server_info) = client.cached_server_info.clone()
{
server_infos.insert(server_name.clone(), server_info);
continue;
}
match view.connection.client().await {
Ok(managed_client) => {
server_infos.insert(server_name.clone(), managed_client.server_info);
}
Err(_) => {
if let Some(server_info) = client.cached_server_info.clone() {
server_infos.insert(server_name.clone(), server_info);
}
}
if let Ok(managed_client) = view.connection.client().await {
server_infos.insert(server_name.clone(), managed_client.server_info);
}
}
server_infos