mirror of
https://github.com/openai/codex.git
synced 2026-11-26 23:40:43 +00:00
Connect Codex Desktop MCP over Unix sockets (#63497)
## Why An SSH forward can replace its Unix socket listener while the old keep-alive connection remains open. Reusing that connection can leave MCP requests waiting on the old listener. ## What changed Route `codex-desktop://<uuid>` endpoints to the corresponding Unix socket for local `codex_app` servers with explicit HTTP authorization. Allow `http_headers_helper` to supply supplemental headers while preserving the configured authorization. Socket requests bypass proxies, strip `Proxy-Authorization`, and disable redirects. Reuse pooled connections while the socket is unchanged and discard them when the listener is replaced or the socket disappears. ## Testing Add coverage for authenticated Desktop startup, rejection of helper-only authorization and other server names, and reconnection after socket replacement while the previous connection remains open. GitOrigin-RevId: a38e55d8cd726299506b487d1223fe64bd856e80
This commit is contained in:
@@ -1219,6 +1219,15 @@ pub fn apply_http_headers_helper(
|
||||
client: Arc<dyn HttpClient>,
|
||||
config: &codex_config::McpServerConfig,
|
||||
local_process_cwd: PathBuf,
|
||||
) -> Result<Arc<dyn HttpClient>, String> {
|
||||
apply_http_headers_helper_at(client, config, local_process_cwd, /*wire_url*/ None)
|
||||
}
|
||||
|
||||
pub(crate) fn apply_http_headers_helper_at(
|
||||
client: Arc<dyn HttpClient>,
|
||||
config: &codex_config::McpServerConfig,
|
||||
local_process_cwd: PathBuf,
|
||||
wire_url: Option<&str>,
|
||||
) -> Result<Arc<dyn HttpClient>, String> {
|
||||
if matches!(
|
||||
config.disabled_reason,
|
||||
@@ -1240,7 +1249,7 @@ pub fn apply_http_headers_helper(
|
||||
if !config.is_local_environment() {
|
||||
return Err("HTTP headers helpers can only run in the local environment".to_string());
|
||||
}
|
||||
with_http_headers_helper(client, url, command, local_process_cwd)
|
||||
with_http_headers_helper(client, wire_url.unwrap_or(url), command, local_process_cwd)
|
||||
.map_err(|error| error.to_string())
|
||||
}
|
||||
|
||||
@@ -1293,6 +1302,19 @@ impl McpRuntimeContext {
|
||||
Arc::clone(&self.local_http_client)
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
pub(crate) fn desktop_http_client(
|
||||
&self,
|
||||
id: uuid::Uuid,
|
||||
) -> std::io::Result<Arc<dyn HttpClient>> {
|
||||
let path =
|
||||
codex_uds::prepare_shared_daemon_socket_directory()?.join(format!("desktop-{id}.sock"));
|
||||
Ok(Arc::new(RouteAwareHttpClient::for_unix_socket(
|
||||
self.environment_manager.http_client_factory().clone(),
|
||||
path,
|
||||
)))
|
||||
}
|
||||
|
||||
pub(crate) fn resolve_server_environment(
|
||||
&self,
|
||||
server_name: &str,
|
||||
|
||||
Reference in New Issue
Block a user