Make MCP server contributions thread-scoped (#27670)

## Why

`selectedCapabilityRoots` belongs to one thread, but MCP contributors
previously received only the global Codex config. That left no clean way
for a selected executor capability to contribute MCP servers to its own
thread.

## What this PR does

- Gives MCP contributors a small context containing the config and, for
a running thread, its frozen host-seeded inputs.
- Uses the same thread inputs during startup, status queries, refreshes,
and skill dependency checks.
- Keeps threadless MCP operations and the existing hosted Apps behavior
unchanged.
- Adds coverage showing that two threads resolve independent
registrations and that later lifecycle mutations do not change the
frozen MCP inputs.

This PR does not discover plugin manifests, add MCP servers, or launch
anything new. It only establishes the thread-scoped registration
boundary.

## Follow-ups

- Resolve selected executor plugin roots through their owning
environment filesystem.
- Convert their stdio MCP declarations into environment-bound
registrations and add an executor MCP end-to-end test.

## Verification

- `just fmt`
- `cargo check --tests -p codex-protocol -p codex-extension-api -p
codex-mcp-extension -p codex-core -p codex-app-server`

Tests and Clippy were not run.
This commit is contained in:
jif authored and GitHub committed 2026-06-12 11:20:34 +02:00
1 parent bf667c7003
commit 693082f3c4
18 files changed
+298 -81

No files matched your search

+14 -3
View File
@@ -9,9 +9,11 @@ type ErasedData = Arc<dyn Any + Send + Sync>;
/// Typed values supplied before an [`ExtensionData`] scope is created.
///
/// Hosts consume this value once to seed a scope before lifecycle contributors
/// run. It does not install extensions or provide persistence.
#[derive(Debug, Default)]
/// Hosts may retain a clone when later operations must use the same initial
/// inputs. Cloning freezes the attachment map and shares each value by `Arc`;
/// values with interior mutability remain shared. This type does not install
/// extensions or provide persistence.
#[derive(Clone, Debug, Default)]
pub struct ExtensionDataInit {
entries: HashMap<TypeId, ErasedData>,
}
@@ -31,6 +33,15 @@ impl ExtensionDataInit {
.insert(TypeId::of::<T>(), Arc::new(value))
.map(downcast_data)
}
/// Returns a host-supplied initial attachment without creating a mutable scope.
pub fn get<T>(&self) -> Option<Arc<T>>
where
T: Any + Send + Sync,
{
let value = self.entries.get(&TypeId::of::<T>())?.clone();
Some(downcast_data(value))
}
}
/// Typed extension-owned data attached to one host object.