WIP fase 2b-2: rimosso login ChatGPT/OAuth/device code, agent/workload identity, backend-client; resta solo chiave API (test non tutti verdi)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
andrea.difonzo
2026-11-10 06:00:44 +01:00
parent 82347a58ed
commit 231e8cd136
661 changed files with 4924 additions and 64817 deletions

View File

@@ -22,7 +22,6 @@ 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;
@@ -65,8 +64,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;
@@ -94,6 +91,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 {
@@ -344,7 +344,6 @@ 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 {
@@ -360,7 +359,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,
@@ -378,7 +376,6 @@ impl McpConnectionSet {
client_mcp_extensions,
auth,
auth_manager,
runtime_auth,
elicitation_reviewer,
elicitation_lifecycle,
} = input;
@@ -442,17 +439,6 @@ 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())
@@ -463,8 +449,6 @@ impl McpConnectionSet {
&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
@@ -546,17 +530,6 @@ impl McpConnectionSet {
&& 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();
@@ -572,7 +545,6 @@ impl McpConnectionSet {
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,
@@ -585,34 +557,8 @@ impl McpConnectionSet {
.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(&server_name);
let protocol_mode = if discover_local_stdio {
McpProtocolMode::DiscoverLocalStdio
} else {
@@ -626,7 +572,6 @@ impl McpConnectionSet {
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,
@@ -642,9 +587,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(),
@@ -888,7 +830,6 @@ 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(),
@@ -929,7 +870,6 @@ impl McpConnectionSet {
tool_catalog_cache_context,
runtime_context.clone(),
resolved_environment,
runtime_auth_provider,
client_elicitation_capability.clone(),
client_mcp_extensions.clone(),
auth_manager
@@ -1015,7 +955,6 @@ impl McpConnectionSet {
let auth_state = match &outcome {
Err(error)
if error.is_authentication_required()
&& !has_runtime_auth
&& !matches!(configured_config.auth, McpServerAuth::EmaAuth) =>
{
match &configured_config.transport {
@@ -1112,7 +1051,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 {
@@ -1189,7 +1127,6 @@ impl McpConnectionSet {
prefix_mcp_tool_names,
non_prefixed_mcp_tool_servers: Vec::new(),
elicitation_requests: ElicitationRequestManager::default(),
trusted_access: None,
}
}