Files
codex/codex-rs/core-plugins/src/app_mcp_routing.rs
T
thomas c465563aa9 Enable app routing for remote curated Agent Plugins (#55667)
## Why

Agent Plugin manifests previously skipped app declarations, including service-generated declarations installed with remote curated plugins. This prevented those plugins from using app routing and suppressing matching direct MCP connections.

## What changed

- Recognize app declarations for Agent Plugins from `openai-curated-remote` across loading, capability summaries, plugin details, tool suggestions, and install authentication.
- Apply app routing to suppress same-name MCP servers when an app route is available. Keep unrelated MCP servers available and preserve direct MCP access in API-key mode.
- Keep app declarations inactive for Agent Plugins from other marketplaces.

## Testing

Add coverage for marketplace and authentication routing, service-generated app declarations during installation with both manifest formats, and app tools reaching turns. Verify that disabling Apps does not restore matching direct MCP connections.

GitOrigin-RevId: 791739569f0e01c898040bc2d028cf517f767e00
2026-10-20 20:27:32 +00:00

43 lines
1.3 KiB
Rust

use crate::manifest::PluginManifestFormat;
use crate::remote::REMOTE_GLOBAL_MARKETPLACE_NAME;
use codex_plugin::AppDeclaration;
use codex_plugin::PluginId;
use codex_protocol::auth::AuthMode;
use std::collections::HashMap;
use std::collections::HashSet;
pub fn apps_route_available(auth_mode: Option<AuthMode>) -> bool {
auth_mode.is_some_and(AuthMode::uses_codex_backend)
}
pub(crate) fn plugin_supports_apps(format: PluginManifestFormat, plugin_id: &PluginId) -> bool {
// The remote curated installer overwrites app declarations with plugin-service metadata.
// Keep portable app declarations inactive for other Agent Plugins.
format == PluginManifestFormat::Legacy
|| plugin_id.marketplace_name == REMOTE_GLOBAL_MARKETPLACE_NAME
}
pub(crate) fn apply_app_mcp_routing_policy<M>(
apps: &mut Vec<AppDeclaration>,
mcp_servers: &mut HashMap<String, M>,
auth_mode: Option<AuthMode>,
plugin_active: bool,
) {
if !apps_route_available(auth_mode) {
apps.clear();
return;
}
if plugin_active && !apps.is_empty() {
let app_declaration_names = apps
.iter()
.map(|app| app.name.as_str())
.collect::<HashSet<_>>();
mcp_servers.retain(|name, _| !app_declaration_names.contains(name.as_str()));
}
}
#[cfg(test)]
#[path = "app_mcp_routing_tests.rs"]
mod tests;