mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
857e731478
## Summary This PR removes the synthetic `HashMap<String, ToolInfo>` keys from MCP tool discovery. `McpConnectionManager::list_all_tools()` now returns normalized `Vec<ToolInfo>`, and downstream code derives identity from `ToolInfo::canonical_tool_name()`. The motivation is to keep model-visible tool identity on `ToolName`/`ToolInfo` instead of parallel string map keys, so future namespace changes do not have to preserve otherwise-unused lookup keys. ## Changes - Rename the MCP normalization path from `qualify_tools` to `normalize_tools_for_model` and return tool values directly. - Flow MCP tool lists through connectors, plugin injection, router/spec building, code mode, and tool search as vectors/slices. - Keep direct/deferred subtraction local to `mcp_tool_exposure`, using `ToolName` values. - Update tests to compare `ToolName` instances where MCP identity matters. ## Validation - `cargo test -p codex-mcp test_normalize_tools` - `cargo test -p codex-core mcp_tool_exposure` - `cargo test -p codex-core direct_mcp_tools_register_namespaced_handlers` - `cargo test -p codex-core search_tool_registers_namespaced_mcp_tool_aliases` - `just fix -p codex-mcp` - `just fix -p codex-core`
60 lines
2.2 KiB
Rust
60 lines
2.2 KiB
Rust
use std::collections::BTreeSet;
|
|
|
|
use codex_connectors::metadata::connector_display_label;
|
|
use codex_protocol::models::ResponseItem;
|
|
|
|
use crate::connectors;
|
|
use crate::context::ContextualUserFragment;
|
|
use crate::context::PluginInstructions;
|
|
use crate::plugins::PluginCapabilitySummary;
|
|
use crate::plugins::render_explicit_plugin_instructions;
|
|
use codex_mcp::CODEX_APPS_MCP_SERVER_NAME;
|
|
use codex_mcp::ToolInfo;
|
|
|
|
pub(crate) fn build_plugin_injections(
|
|
mentioned_plugins: &[PluginCapabilitySummary],
|
|
mcp_tools: &[ToolInfo],
|
|
available_connectors: &[connectors::AppInfo],
|
|
) -> Vec<ResponseItem> {
|
|
if mentioned_plugins.is_empty() {
|
|
return Vec::new();
|
|
}
|
|
|
|
// Turn each explicit plugin mention into a developer hint that points the
|
|
// model at the plugin's visible MCP servers, enabled apps, and skill prefix.
|
|
mentioned_plugins
|
|
.iter()
|
|
.filter_map(|plugin| {
|
|
let available_mcp_servers = mcp_tools
|
|
.iter()
|
|
.filter(|tool| {
|
|
tool.server_name != CODEX_APPS_MCP_SERVER_NAME
|
|
&& tool
|
|
.plugin_display_names
|
|
.iter()
|
|
.any(|plugin_name| plugin_name == &plugin.display_name)
|
|
})
|
|
.map(|tool| tool.server_name.clone())
|
|
.collect::<BTreeSet<String>>()
|
|
.into_iter()
|
|
.collect::<Vec<_>>();
|
|
let available_apps = available_connectors
|
|
.iter()
|
|
.filter(|connector| {
|
|
connector.is_enabled
|
|
&& connector
|
|
.plugin_display_names
|
|
.iter()
|
|
.any(|plugin_name| plugin_name == &plugin.display_name)
|
|
})
|
|
.map(connector_display_label)
|
|
.collect::<BTreeSet<String>>()
|
|
.into_iter()
|
|
.collect::<Vec<_>>();
|
|
render_explicit_plugin_instructions(plugin, &available_mcp_servers, &available_apps)
|
|
.map(PluginInstructions::new)
|
|
.map(ContextualUserFragment::into)
|
|
})
|
|
.collect()
|
|
}
|