Give hosted Codex Apps an independent MCP protocol opt-in (#44318)

## Why

Hosted Codex Apps shared the `mcp_2026_07_28` protocol setting with other MCP servers, preventing independent protocol selection.

## What changed

- Add `features.codex_apps_mcp_2026_07_28`, disabled by default, for the host-owned HTTP `codex_apps` server. Enabling it attempts 2026-07-28 discovery with Legacy fallback.
- Keep other servers, including third-party registrations with Apps-like names or URLs and local stdio servers, governed by `mcp_2026_07_28`.
- Support the new flag through `experimentalFeature/enablement/set` and refresh protocol settings in existing sessions. Track protocol mode per server when deciding whether to reuse connections.

## Testing

Add coverage for independent feature and protocol selection, hosted event-stream protocol selection, standalone Legacy defaults and discovery fallback, and runtime enablement refreshing an existing app-server thread.

GitOrigin-RevId: 640e8e251f0c45e5f4829cc2b73c3082cf42f715
This commit is contained in:
thomas authored and copyberry committed 2026-09-09 22:22:08 +00:00
1 parent e1b23086ac
commit eb680c0558
18 files changed
+431 -19

No files matched your search

+16 -8
View File
@@ -160,6 +160,7 @@ impl Drop for McpServerConnection {
#[derive(Clone)]
struct McpServerView {
connection: Arc<McpServerConnection>,
protocol_mode: crate::McpProtocolMode,
metadata: McpServerMetadata,
tool_filter: ToolFilter,
tool_timeout: Option<Duration>,
@@ -186,7 +187,6 @@ pub(crate) struct McpConnectionSet {
servers: HashMap<String, McpServerView>,
pub(crate) event_stream_connection: Option<Arc<EventStreamConnectionSettings>>,
disabled_servers: Vec<String>,
protocol_mode: crate::McpProtocolMode,
required_servers: Vec<String>,
optional_startup_deadline: OnceLock<tokio::time::Instant>,
tool_plugin_provenance: Arc<ToolPluginProvenance>,
@@ -231,7 +231,8 @@ impl McpConnectionSet {
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 protocol_mode = config.protocol_mode;
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_provenance = crate::mcp::tool_plugin_provenance(&config);
let auth = auth.as_ref();
@@ -313,6 +314,15 @@ impl McpConnectionSet {
};
let metadata = McpServerMetadata::from(&server);
let configured_config = server.config().clone();
let protocol_mode = if is_host_owned_codex_apps
&& matches!(
&configured_config.transport,
McpServerTransportConfig::StreamableHttp { .. }
) {
host_owned_apps_protocol_mode
} else {
default_protocol_mode
};
let configured_tool_filter = ToolFilter::from_config(&configured_config);
let startup_timeout = configured_config
.startup_timeout_sec
@@ -445,13 +455,11 @@ impl McpConnectionSet {
&& !connection.client.cancel_token.is_cancelled()
&& previous_view.catalog_item_limit == catalog_item_limit
&& expected_protocol_mode.is_some()
&& reusable_previous
.is_some_and(|previous| previous.protocol_mode == protocol_mode);
&& previous_view.protocol_mode == protocol_mode;
let unchanged_auth_failure = if connection.identity.as_ref()
== Some(&connection_identity)
&& connection_identity.oauth_store_was_contended
&& reusable_previous
.is_some_and(|previous| previous.protocol_mode == protocol_mode)
&& previous_view.protocol_mode == protocol_mode
&& connection.client.startup_complete.load(Ordering::Acquire)
{
connection
@@ -480,6 +488,7 @@ impl McpConnectionSet {
server_name.clone(),
McpServerView {
connection,
protocol_mode,
metadata,
tool_filter: configured_tool_filter,
tool_timeout: configured_tool_timeout,
@@ -614,6 +623,7 @@ impl McpConnectionSet {
startup_trigger,
_diagnostics_guard: LIVE_CONNECTIONS.track(),
}),
protocol_mode,
metadata,
tool_filter: configured_tool_filter,
tool_timeout: configured_tool_timeout,
@@ -738,7 +748,6 @@ impl McpConnectionSet {
servers,
event_stream_connection,
disabled_servers,
protocol_mode,
required_servers,
optional_startup_deadline: OnceLock::new(),
tool_plugin_provenance,
@@ -797,7 +806,6 @@ impl McpConnectionSet {
servers: HashMap::new(),
event_stream_connection: None,
disabled_servers: Vec::new(),
protocol_mode: crate::McpProtocolMode::Legacy,
required_servers: Vec::new(),
optional_startup_deadline: OnceLock::new(),
tool_plugin_provenance: Arc::new(ToolPluginProvenance::default()),