mirror of
https://github.com/openai/codex.git
synced 2026-11-17 22:59:25 +00:00
Add selected-plugin precedence and attribution to the MCP catalog (#27884)
## Why **In short:** this PR resolves already-discovered MCP registrations. It does not read selected plugins or discover their MCP servers. The resolved MCP catalog currently builds config and auto-discovered plugin registrations before runtime contributors are applied. A thread-selected plugin needs a distinct precedence tier in that same initial resolution pass: otherwise a disabled lower-precedence winner can leave stale name-level state behind, and the winning MCP tools cannot be attributed to the selected package reliably. This PR adds that catalog boundary before executor discovery is connected. ## What changed - Added an explicit selected-plugin registration tier between auto-discovered plugins and explicit config. - Collected selected-plugin contributions before the initial catalog build, while leaving compatibility and generic extension overlays in their existing runtime phase. - Retained the winning plugin ID and display name directly on plugin-owned catalog registrations. - Derived MCP tool provenance from the winning catalog entry instead of joining against local-only plugin summaries. - Retained the winning selected server's tool approval policy in the running connection manager, so a selected registration cannot inherit approval behavior from a losing local plugin. - Kept remembered approval session-scoped for selected plugins until there is an authority-aware persistence contract; Codex will not write approval back to an unrelated local plugin. - Preserved existing name-level disabled vetoes for discovered plugins and config, while keeping a selected package's own disabled registration scoped to that registration. - Preserved deterministic selection order and existing config, compatibility, and extension precedence. The resulting order is: ```text auto-discovered plugin < selected plugin < explicit config < compatibility registration < extension overlay ``` ## Behavior and scope This is a catalog and provenance change only. No production host contributes selected-plugin MCP registrations yet, so existing local MCP behavior remains unchanged. The stacked follow-up, #27870, installs the executor plugin provider that produces these registrations. App-server activation remains a separate final step. ## Verification Focused tests cover precedence, deterministic selected-plugin conflicts, disabled-veto behavior across catalog phases, managed requirements before selected-plugin resolution, winning-server approval policy, and attribution when local and selected packages share an ID or server name. CI owns execution of the test suite.
This commit is contained in:
16 files changed
+585
-89
No files matched your search
@@ -8,6 +8,7 @@ use codex_config::McpServerToolConfig;
|
||||
use codex_config::McpServerTransportConfig;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
use super::McpPluginAttribution;
|
||||
use super::McpServerConflict;
|
||||
use super::McpServerConflictAction;
|
||||
use super::McpServerRegistration;
|
||||
@@ -44,10 +45,16 @@ fn server(url: &str) -> McpServerConfig {
|
||||
}
|
||||
}
|
||||
|
||||
fn plugin(plugin_id: &str) -> McpPluginAttribution {
|
||||
McpPluginAttribution::new(plugin_id.to_string(), plugin_id.to_string())
|
||||
}
|
||||
|
||||
fn plugin_source(plugin_id: &str) -> McpServerSource {
|
||||
McpServerSource::Plugin {
|
||||
plugin_id: plugin_id.to_string(),
|
||||
}
|
||||
McpServerSource::Plugin(plugin(plugin_id))
|
||||
}
|
||||
|
||||
fn selected_plugin_source(plugin_id: &str) -> McpServerSource {
|
||||
McpServerSource::SelectedPlugin(plugin(plugin_id))
|
||||
}
|
||||
|
||||
fn compatibility_source(id: &str) -> McpServerSource {
|
||||
@@ -69,8 +76,8 @@ fn remove(source: McpServerSource) -> McpServerConflictAction {
|
||||
#[test]
|
||||
fn source_precedence_preserves_the_winning_registration() {
|
||||
let extension = server("https://extension.example/mcp");
|
||||
let mut plugin = server("https://plugin.example/mcp");
|
||||
plugin.enabled = false;
|
||||
let mut plugin_server = server("https://plugin.example/mcp");
|
||||
plugin_server.enabled = false;
|
||||
let mut builder = ResolvedMcpCatalog::builder();
|
||||
builder.register(McpServerRegistration::from_extension(
|
||||
"docs".to_string(),
|
||||
@@ -80,13 +87,13 @@ fn source_precedence_preserves_the_winning_registration() {
|
||||
));
|
||||
builder.register(McpServerRegistration::from_plugin(
|
||||
"docs".to_string(),
|
||||
"plugin@test".to_string(),
|
||||
plugin("plugin@test"),
|
||||
/*plugin_order*/ 0,
|
||||
plugin,
|
||||
plugin_server,
|
||||
));
|
||||
builder.register(McpServerRegistration::from_plugin(
|
||||
"docs".to_string(),
|
||||
"other-plugin@test".to_string(),
|
||||
plugin("other-plugin@test"),
|
||||
/*plugin_order*/ 1,
|
||||
server("https://other-plugin.example/mcp"),
|
||||
));
|
||||
@@ -110,7 +117,7 @@ fn source_precedence_preserves_the_winning_registration() {
|
||||
}
|
||||
);
|
||||
assert_eq!(resolved.config(), &extension);
|
||||
assert!(catalog.plugin_ids_by_server_name().is_empty());
|
||||
assert!(catalog.plugin_attributions_by_server_name().is_empty());
|
||||
assert_eq!(
|
||||
catalog.conflicts(),
|
||||
&[McpServerConflict {
|
||||
@@ -178,18 +185,50 @@ fn disabled_winner_remains_a_veto_when_the_catalog_is_extended() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn disabled_discovered_plugin_remains_a_veto_for_runtime_overlays() {
|
||||
let mut disabled = server("https://plugin.example/mcp");
|
||||
disabled.enabled = false;
|
||||
let mut expected = server("https://extension.example/mcp");
|
||||
expected.enabled = false;
|
||||
let mut builder = ResolvedMcpCatalog::builder();
|
||||
builder.register(McpServerRegistration::from_plugin(
|
||||
"docs".to_string(),
|
||||
plugin("plugin@test"),
|
||||
/*plugin_order*/ 0,
|
||||
disabled,
|
||||
));
|
||||
let mut builder = builder.build().to_builder();
|
||||
builder.register(McpServerRegistration::from_extension(
|
||||
"docs".to_string(),
|
||||
"hosted",
|
||||
/*contribution_order*/ 0,
|
||||
server("https://extension.example/mcp"),
|
||||
));
|
||||
|
||||
let resolved = builder.build();
|
||||
|
||||
assert_eq!(
|
||||
resolved.server("docs"),
|
||||
Some(&super::ResolvedMcpServer {
|
||||
source: extension_source("hosted"),
|
||||
config: expected,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn earlier_plugin_wins_with_an_explicit_conflict() {
|
||||
let mut builder = ResolvedMcpCatalog::builder();
|
||||
builder.register(McpServerRegistration::from_plugin(
|
||||
"docs".to_string(),
|
||||
"alpha@test".to_string(),
|
||||
plugin("alpha@test"),
|
||||
/*plugin_order*/ 0,
|
||||
server("https://alpha.example/mcp"),
|
||||
));
|
||||
builder.register(McpServerRegistration::from_plugin(
|
||||
"docs".to_string(),
|
||||
"beta@test".to_string(),
|
||||
plugin("beta@test"),
|
||||
/*plugin_order*/ 1,
|
||||
server("https://beta.example/mcp"),
|
||||
));
|
||||
@@ -197,8 +236,8 @@ fn earlier_plugin_wins_with_an_explicit_conflict() {
|
||||
let catalog = builder.build();
|
||||
|
||||
assert_eq!(
|
||||
catalog.plugin_ids_by_server_name(),
|
||||
HashMap::from([("docs".to_string(), "alpha@test".to_string())])
|
||||
catalog.plugin_attributions_by_server_name(),
|
||||
HashMap::from([("docs".to_string(), plugin("alpha@test"))])
|
||||
);
|
||||
assert_eq!(
|
||||
catalog.conflicts(),
|
||||
@@ -213,6 +252,105 @@ fn earlier_plugin_wins_with_an_explicit_conflict() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn selected_plugins_override_discovered_plugins_but_not_config() {
|
||||
let selected = server("https://selected-alpha.example/mcp");
|
||||
let mut discovered = server("https://local.example/mcp");
|
||||
discovered.enabled = false;
|
||||
discovered.default_tools_approval_mode = Some(AppToolApproval::Auto);
|
||||
let mut builder = ResolvedMcpCatalog::builder();
|
||||
builder.register(McpServerRegistration::from_plugin(
|
||||
"docs".to_string(),
|
||||
plugin("local@test"),
|
||||
/*plugin_order*/ 0,
|
||||
discovered,
|
||||
));
|
||||
builder.register(McpServerRegistration::from_selected_plugin(
|
||||
"docs".to_string(),
|
||||
plugin("selected-beta"),
|
||||
/*selection_order*/ 1,
|
||||
server("https://selected-beta.example/mcp"),
|
||||
));
|
||||
builder.register(McpServerRegistration::from_selected_plugin(
|
||||
"docs".to_string(),
|
||||
plugin("selected-alpha"),
|
||||
/*selection_order*/ 0,
|
||||
selected.clone(),
|
||||
));
|
||||
|
||||
let catalog = builder.build();
|
||||
|
||||
assert_eq!(
|
||||
catalog.server("docs"),
|
||||
Some(&super::ResolvedMcpServer {
|
||||
source: selected_plugin_source("selected-alpha"),
|
||||
config: selected,
|
||||
})
|
||||
);
|
||||
assert_eq!(
|
||||
catalog.plugin_attributions_by_server_name(),
|
||||
HashMap::from([("docs".to_string(), plugin("selected-alpha"))])
|
||||
);
|
||||
assert_eq!(
|
||||
catalog.conflicts(),
|
||||
&[McpServerConflict {
|
||||
name: "docs".to_string(),
|
||||
outcome: register(selected_plugin_source("selected-alpha")),
|
||||
contenders: vec![
|
||||
register(selected_plugin_source("selected-beta")),
|
||||
register(selected_plugin_source("selected-alpha")),
|
||||
],
|
||||
}]
|
||||
);
|
||||
|
||||
let mut builder = catalog.to_builder();
|
||||
let configured = server("https://config.example/mcp");
|
||||
builder.register(McpServerRegistration::from_config(
|
||||
"docs".to_string(),
|
||||
configured.clone(),
|
||||
));
|
||||
let catalog = builder.build();
|
||||
|
||||
assert_eq!(
|
||||
catalog.server("docs"),
|
||||
Some(&super::ResolvedMcpServer {
|
||||
source: McpServerSource::Config,
|
||||
config: configured,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn disabled_selected_plugin_does_not_veto_runtime_overlays() {
|
||||
let mut disabled = server("https://selected.example/mcp");
|
||||
disabled.enabled = false;
|
||||
let extension = server("https://extension.example/mcp");
|
||||
let mut builder = ResolvedMcpCatalog::builder();
|
||||
builder.register(McpServerRegistration::from_selected_plugin(
|
||||
"docs".to_string(),
|
||||
plugin("selected"),
|
||||
/*selection_order*/ 0,
|
||||
disabled,
|
||||
));
|
||||
let mut builder = builder.build().to_builder();
|
||||
builder.register(McpServerRegistration::from_extension(
|
||||
"docs".to_string(),
|
||||
"hosted",
|
||||
/*contribution_order*/ 0,
|
||||
extension.clone(),
|
||||
));
|
||||
|
||||
let resolved = builder.build();
|
||||
|
||||
assert_eq!(
|
||||
resolved.server("docs"),
|
||||
Some(&super::ResolvedMcpServer {
|
||||
source: extension_source("hosted"),
|
||||
config: extension,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn equal_precedence_uses_insertion_order_not_source_identity() {
|
||||
let mut builder = ResolvedMcpCatalog::builder();
|
||||
|
||||
Reference in new issue
Block a user