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

@@ -0,0 +1,64 @@
//! Verifies the hosted Apps protocol choice in standalone Codex sessions.
use codex_features::Feature;
use codex_login::CodexAuth;
use codex_mcp::CODEX_APPS_MCP_SERVER_NAME;
use core_test_support::apps_test_server::AppsTestServer;
use core_test_support::responses;
use core_test_support::skip_if_no_network;
use core_test_support::test_codex::test_codex;
use core_test_support::wait_for_mcp_server;
use pretty_assertions::assert_eq;
use serde_json::Value;
use test_case::test_case;
#[derive(Clone, Copy)]
enum HostedProtocolSetting {
Default,
Enabled,
}
#[test_case(HostedProtocolSetting::Default, &["initialize", "notifications/initialized", "tools/list"]; "defaults_to_legacy")]
#[test_case(HostedProtocolSetting::Enabled, &["server/discover", "initialize", "notifications/initialized", "tools/list"]; "opt_in_discovers_and_falls_back_to_legacy")]
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn standalone_codex_apps_respects_protocol_setting(
setting: HostedProtocolSetting,
expected_methods: &[&str],
) -> anyhow::Result<()> {
skip_if_no_network!(Ok(()));
let server = responses::start_mock_server().await;
let apps_base_url = AppsTestServer::mount(&server).await?.chatgpt_base_url;
let fixture = test_codex()
.with_auth(CodexAuth::create_dummy_chatgpt_auth_for_testing())
.with_config(move |config| {
config
.features
.enable(Feature::Apps)
.expect("test config should allow Apps override");
if matches!(setting, HostedProtocolSetting::Enabled) {
config
.features
.enable(Feature::CodexAppsMcp20260728)
.expect("test config should allow Apps protocol override");
}
config.chatgpt_base_url = apps_base_url;
})
.build_with_auto_env(&server)
.await?;
wait_for_mcp_server(&fixture.codex, CODEX_APPS_MCP_SERVER_NAME).await?;
let methods = server
.received_requests()
.await
.expect("mock server should capture Apps MCP startup requests")
.into_iter()
.filter(|request| request.url.path() == "/api/codex/ps/mcp")
.filter_map(|request| {
let body: Value = serde_json::from_slice(&request.body).ok()?;
body.get("method")?.as_str().map(str::to_string)
})
.collect::<Vec<_>>();
assert_eq!(methods, expected_methods);
Ok(())
}
+1
View File
@@ -52,6 +52,7 @@ mod client_websockets;
mod cloud_config;
mod code_mode;
mod code_mode_elicitation;
mod codex_apps_protocol;
mod codex_delegate;
mod collaboration_instructions;
mod compact;