mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Build MCP tool runtimes before router planning (#33149)
## What changed - Convert filtered MCP tool metadata into `CoreToolRuntime` instances before constructing the tool router. - Pass those runtimes through the shared tool-planning path instead of maintaining separate direct and deferred MCP tool lists. - Preserve MCP visibility, app policy filtering, and direct versus deferred exposure behavior. GitOrigin-RevId: 67f7fbeecc2992318c859e038cd97938833911db
This commit is contained in:
1 parent
eb80df0317
commit
1447cee36b
9 files changed
+141
-190
No files matched your search
@@ -1,47 +1,58 @@
|
||||
use std::collections::HashSet;
|
||||
use std::sync::Arc;
|
||||
|
||||
use codex_connectors::AppToolPolicyEvaluator;
|
||||
use codex_connectors::AppToolPolicyInput;
|
||||
use codex_mcp::CODEX_APPS_MCP_SERVER_NAME;
|
||||
use codex_mcp::ToolInfo as McpToolInfo;
|
||||
use codex_mcp::tool_is_model_visible;
|
||||
use codex_tools::ToolExposure;
|
||||
use tracing::instrument;
|
||||
use tracing::warn;
|
||||
|
||||
use crate::config::Config;
|
||||
use crate::connectors;
|
||||
|
||||
pub(crate) struct McpToolExposure {
|
||||
pub(crate) direct_tools: Vec<McpToolInfo>,
|
||||
pub(crate) deferred_tools: Option<Vec<McpToolInfo>>,
|
||||
}
|
||||
use crate::tools::handlers::McpHandler;
|
||||
use crate::tools::registry::CoreToolRuntime;
|
||||
use crate::tools::registry::override_tool_exposure;
|
||||
|
||||
#[instrument(level = "trace", skip_all)]
|
||||
pub(crate) fn build_mcp_tool_exposure(
|
||||
pub(crate) fn build_mcp_tool_runtimes(
|
||||
all_mcp_tools: &[McpToolInfo],
|
||||
connectors: Option<&[connectors::AppInfo]>,
|
||||
config: &Config,
|
||||
search_tool_enabled: bool,
|
||||
) -> McpToolExposure {
|
||||
let mut deferred_tools = filter_non_codex_apps_mcp_tools_only(all_mcp_tools);
|
||||
) -> Vec<Arc<dyn CoreToolRuntime>> {
|
||||
let mut exposed_tools = filter_non_codex_apps_mcp_tools_only(all_mcp_tools);
|
||||
if let Some(connectors) = connectors {
|
||||
deferred_tools.extend(filter_codex_apps_mcp_tools(
|
||||
exposed_tools.extend(filter_codex_apps_mcp_tools(
|
||||
all_mcp_tools,
|
||||
connectors,
|
||||
config,
|
||||
));
|
||||
}
|
||||
|
||||
if !search_tool_enabled {
|
||||
return McpToolExposure {
|
||||
direct_tools: deferred_tools,
|
||||
deferred_tools: None,
|
||||
};
|
||||
}
|
||||
|
||||
McpToolExposure {
|
||||
direct_tools: Vec::new(),
|
||||
deferred_tools: (!deferred_tools.is_empty()).then_some(deferred_tools),
|
||||
}
|
||||
let exposure = if search_tool_enabled {
|
||||
ToolExposure::Deferred
|
||||
} else {
|
||||
ToolExposure::Direct
|
||||
};
|
||||
exposed_tools
|
||||
.into_iter()
|
||||
.filter_map(|tool| {
|
||||
let tool_name = tool.canonical_tool_name();
|
||||
match McpHandler::new(tool) {
|
||||
Ok(handler) => {
|
||||
let handler: Arc<dyn CoreToolRuntime> = Arc::new(handler);
|
||||
Some(override_tool_exposure(handler, exposure))
|
||||
}
|
||||
Err(err) => {
|
||||
warn!("Skipping MCP tool `{tool_name}`: failed to build tool spec: {err}");
|
||||
None
|
||||
}
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn filter_non_codex_apps_mcp_tools_only(mcp_tools: &[McpToolInfo]) -> Vec<McpToolInfo> {
|
||||
|
||||
Reference in new issue
Block a user