Connect plugin MCP servers over launcher-provided Unix sockets (#64828)

## Why

A launcher that already hosts an MCP server needs a way for Codex to
use it without starting a separate subprocess for the plugin.

## What changed

The stdio app server accepts socket bindings from its immediate parent
on Unix. A binding applies to a local plugin's stdio MCP server only
when the plugin ID, server name, and binding ID match a single entry.
Codex uses the stdio wire protocol over the socket and retains the
original declaration for policy checks.

Before sending MCP traffic, Codex requires a user-owned socket
directory with mode `0700` and verifies the listener's PID and UID.

## Testing

Add tests for binding scope and ambiguous matches, and for rejecting
unexpected listener PIDs, insecure directory permissions, symlinked
socket directories, and relative socket paths.

GitOrigin-RevId: 3d669dd59a0812b04727e4a1e458774007f054ba
This commit is contained in:
Charlie Marsh
2026-11-30 23:34:32 +00:00
committed by copyberry
parent 515cfeceba
commit b0b5cfcab8
16 changed files with 441 additions and 9 deletions
+1
View File
@@ -2137,6 +2137,7 @@ impl Config {
}
McpConfig {
parent_bindings: Default::default(),
executor_discovery_v2: None,
client: McpClientConfig {
chatgpt_base_url: self.chatgpt_base_url.clone(),
+5
View File
@@ -32,6 +32,7 @@ use codex_mcp::McpEnvironmentAuthority;
use codex_mcp::McpPluginAttribution;
use codex_mcp::McpServerRegistration;
use codex_mcp::McpToolCatalogCache;
use codex_mcp::ParentMcpBindings;
use codex_mcp::ToolInfo;
use codex_mcp::codex_apps_mcp_server_config;
use codex_mcp::configured_mcp_servers;
@@ -112,6 +113,7 @@ enum OrderedMcpOverlay {
#[derive(Clone)]
pub struct McpManager {
pub(crate) parent_bindings: ParentMcpBindings,
connection_pool: codex_mcp::McpConnectionPool,
plugins_manager: Arc<PluginsManager>,
extensions: Arc<ExtensionRegistry<Config>>,
@@ -137,6 +139,7 @@ impl McpManager {
codex_apps_tools_cache: ConnectorRuntimeManager<ToolInfo>,
) -> Self {
Self {
parent_bindings: Default::default(),
connection_pool: codex_mcp::McpConnectionPool::default(),
plugins_manager,
extensions,
@@ -153,6 +156,7 @@ impl McpManager {
Arc::clone(&self.extensions),
ConnectorRuntimeManager::default(),
);
manager.parent_bindings = self.parent_bindings.clone();
manager.connection_pool = self.connection_pool.clone();
manager
}
@@ -537,6 +541,7 @@ impl McpManager {
!selected_plugins.is_empty() || !loaded_plugins.capability_summaries().is_empty();
let mut mcp_config = config
.to_mcp_config_with_loaded_plugins(&loaded_plugins, selected_plugin_registrations);
mcp_config.parent_bindings = self.parent_bindings.clone();
mcp_config.ema_state = Arc::clone(&self.ema_state);
let mut catalog = mcp_config.mcp_server_catalog.to_builder();
// Isolated sessions do not inherit the implicit Apps connection.
+10
View File
@@ -77,6 +77,7 @@ use codex_login::AuthManager;
use codex_login::CodexAuth;
use codex_login::default_client::CODEX_INTERNAL_ORIGINATOR_OVERRIDE_ENV_VAR;
use codex_login::default_client::originator;
use codex_mcp::ParentMcpBindings;
use codex_model_provider::ModelCatalogFactory;
use codex_model_provider::ProviderAuthContext;
use codex_model_provider_info::ModelProviderInfo;
@@ -787,6 +788,15 @@ impl ThreadManager {
self
}
/// Attach launcher endpoints before sharing the manager. Isolated sessions use their own manager.
pub fn with_parent_mcp_bindings(mut self, bindings: ParentMcpBindings) -> Self {
let Some(state) = Arc::get_mut(&mut self.state) else {
unreachable!("MCP bindings must be set before the thread manager is shared");
};
Arc::make_mut(&mut state.mcp_manager).parent_bindings = bindings;
self
}
/// Samples host metrics without creating a Codex thread or code-mode session.
/// Process-owned providers observe existing children; custom providers retain
/// their transport's connection policy.