Expose session sources to MCP contributors (#37167)

## What changed

- Add `session_source()` to `McpServerContributionContext` for thread-scoped MCP resolution.
- Propagate each thread's `SessionSource` through initial setup, per-step resolution, and runtime refreshes.

## Testing

- Verify global contexts omit the source while thread-scoped contexts retain it.
- Verify MCP contributors observe distinct sources for a root thread and its spawned subagent.

GitOrigin-RevId: 23da1509858e023fbd9e2d179034ddc83553f17b
This commit is contained in:
Rasmus Rygaard authored and copyberry committed 2026-08-05 21:45:33 +00:00
1 parent ad6e48ddd3
commit 15ea598c6e
9 files changed
+239 -24

No files matched your search

+11 -4
View File
@@ -26,6 +26,7 @@ use codex_mcp::configured_mcp_servers;
use codex_mcp::effective_mcp_servers;
use codex_plugin::AppConnectorId;
use codex_protocol::capabilities::SelectedCapabilityRoot;
use codex_protocol::protocol::SessionSource;
const LEGACY_CODEX_APPS_REGISTRATION_ID: &str = "legacy_codex_apps";
@@ -36,6 +37,11 @@ pub(crate) struct McpRuntimeProjection {
pub(crate) plugins_available: bool,
}
pub(crate) struct McpThreadIdentity<'a> {
pub(crate) session_source: &'a SessionSource,
pub(crate) originator: &'a str,
}
enum OrderedMcpOverlay {
Set {
contributor_id: &'static str,
@@ -109,7 +115,7 @@ impl McpManager {
config: &Config,
thread_init: &ExtensionDataInit,
thread_store: &ExtensionData,
originator: &str,
identity: McpThreadIdentity<'_>,
ready_selected_capability_roots: &[SelectedCapabilityRoot],
executor_capability_discovery: Option<&ExecutorCapabilityDiscoverySnapshot>,
) -> McpRuntimeProjection {
@@ -118,11 +124,12 @@ impl McpManager {
config,
thread_init,
thread_store,
originator,
identity.originator,
ready_selected_capability_roots,
executor_capability_discovery,
),
Some(originator),
)
.with_session_source(identity.session_source),
Some(identity.originator),
)
.await
}