From 92d92ecca318a12e0ca094fc23eace6200d3390c Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 13 May 2026 14:57:58 +0100 Subject: [PATCH] Remove Codex Apps MCP privilege --- notes/fresh-workspace-handoff.md | 9 + state/ledgers.msgpack | Bin 98439 -> 98810 bytes state/map.yaml | 30 +- vendor/codex/codex-rs/codex-mcp/src/lib.rs | 5 - .../codex/codex-rs/codex-mcp/src/mcp/mod.rs | 128 +-- .../codex-mcp/src/mcp_connection_manager.rs | 490 +-------- vendor/codex/codex-rs/core/src/connectors.rs | 31 - .../consequential_tool_message_templates.json | 962 ------------------ .../core/src/mcp_tool_approval_templates.rs | 356 +------ .../codex/codex-rs/core/src/mcp_tool_call.rs | 250 +---- .../codex-rs/core/src/mcp_tool_call_tests.rs | 221 +--- .../codex-rs/core/src/mcp_tool_exposure.rs | 49 +- .../core/src/mcp_tool_exposure_test.rs | 152 +-- vendor/codex/codex-rs/core/src/session/mcp.rs | 4 - vendor/codex/codex-rs/core/src/session/mod.rs | 1 - .../codex-rs/core/src/session/session.rs | 2 - .../codex/codex-rs/core/src/session/turn.rs | 2 - 17 files changed, 93 insertions(+), 2599 deletions(-) delete mode 100644 vendor/codex/codex-rs/core/src/consequential_tool_message_templates.json diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index 93b8ac30..0ab315ca 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -835,6 +835,15 @@ returns empty, app prompt instructions and app-rendering code were deleted, tiny default stub so legacy callers compile. User-declared MCP servers remain the only MCP authority; Codex Apps are not part of the OpenAI auth/model spine. +The Codex Apps MCP privilege layer has been cut below core too. MCP tool +exposure no longer separates Codex Apps from ordinary MCP tools, core MCP tool +calls no longer consult app policy, forward `_codex_apps` metadata, emit app +invocation telemetry, render bundled app approval templates, or persist +approvals under `[apps.*]`, and `codex-mcp` no longer injects `codex_apps`, +exports `with_codex_apps_mcp`, keeps a ChatGPT-auth-keyed app tool cache, or +normalizes app callable names/namespaces/titles. MCP remains JSON-RPC at the +edge; only user-declared MCP servers are runtime MCP authority. + The Phase 6 freshness slice is landed. It exposes read-only `thread/epiphany/freshness` from live retrieval summaries plus graph frontier/churn state and, for loaded threads, watcher-backed invalidation diff --git a/state/ledgers.msgpack b/state/ledgers.msgpack index a0093df10d7ca0341467c05d8433eb5e2c09c806..091213f689bfae153393b9b56178ff795332c113 100644 GIT binary patch delta 369 zcmYjNy-EW?5N1X40=~e2*vMTjxg-{66|S)nEUXj>>)yny?%giCn?sw#kiu3F^d0O3 z#U@3b%gR~S!g9WE=KGnaRp)2jdEVbyZ9fiP8Dr}W``$42wRqbu*xv4FSmZC`_hgxs za}TAi@E*p-I5;iOz*yNzg*OOOt7{P2VkW{$S_@M^qk+%8CY+!N4_C6eMd77x5}+Bp z)(Qj{GmJA~R<~S%$J!|F(M8%+}t>HbI%G!FQwTG)6{-<~@wt_b@VUtrKh5Vq{=srfXoTYiJx|Xl!L@YGrC1 F1puKk4)p*4 diff --git a/state/map.yaml b/state/map.yaml index 5a51bf4c..bda5a3e0 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -282,20 +282,18 @@ rejected_paths: current_status: summary: The Codex starvation pass has five typing receipts, thirty-eight processor/foundation cuts, a real physical extraction in `epiphany-codex-bridge`, a root `epiphany-state-model` crate for durable Epiphany state, a source-grounded Codex auth spine inventory, the native `epiphany-openai-adapter` document boundary, a buildable Codex auth/model wrapper in `epiphany-openai-codex-spine`, the first native runtime caller in `epiphany-openai-runtime`, native heartbeat launch planning/job opening in `epiphany-core`, native state-update contract/validation/application in `epiphany-core`, native exact retrieval path matching in `epiphany-core`, and the route-facing mutation/view/coordinator projection services in `epiphany-codex-bridge`. `codex-protocol` no longer defines the durable `Epiphany*` state structs; it re-exports the native model for legacy rollout/API compatibility while `epiphany-core` imports the native model directly. `epiphany-core` now has no direct vendored Codex dependency: pressure derivation accepts native `EpiphanyTokenUsageSnapshot`, Codex rollout replay moved to `codex-core::epiphany_rollout`, and exact retrieval search uses Epiphany-owned workspace walking/path scoring instead of `codex-file-search`. The bridge owns Codex-facing Epiphany adapters for scene, jobs, context/planning/graph query, retrieval/indexing projection, result projection, runtime-spine result adaptation, launch/prompt doctrine, mutation document mechanics, mutation service update/promote/role-accept/reorient-accept/role-launch/reorient-launch/job-launch/job-interrupt application, live-state projection, pressure/pre-compaction rendering, freshness/reorientation projection, CRRC/coordinator/role-board projection, watcher invalidation adaptation, full `thread/epiphany/view` response construction, freshness/context/graph-query response construction, role/reorient result response construction, distill/propose patch-response construction, coordinator status/view construction, and acceptance/evidence signal helpers. Vendored app-server no longer retains root Epiphany modules; `codex_message_processor.rs` still contains route dispatch, JSON-RPC response shaping, watcher registration/snapshotting calls, and notification emission, but its root no longer imports the evacuated Epiphany policy/protocol registry or owns the watcher invalidation manager. Codex product surfaces for apps, skills, plugins, marketplace, and external agent config import are now inert in the app-server compatibility path: list routes return empty lists, mutation/detail/import routes report disabled, `externalAgentConfig/detect` returns no import candidates, helper/import modules and stale implementation-shape tests were deleted, runtime feature enablement no longer supports `apps` or `plugins`, config writes no longer emit plugin-toggle analytics, plugin/skill cache invalidation on config writes is gone, plugin startup warmups and app-list refreshes were removed, and app-server no longer directly depends on `codex-plugin`, `codex-chatgpt`, or `codex-core-plugins`. `Config::to_mcp_config` now keeps user-declared MCP servers but no longer accepts `PluginsManager`, folds plugin MCP servers into the runtime, enables Codex apps, enables skill MCP dependency install, or advertises plugin capability summaries; `TurnContext::apps_enabled()` now returns false so model turns cannot awaken Codex Apps through ChatGPT auth or feature flags; session startup and per-turn context no longer load skills, turns receive an empty `SkillLoadOutcome`, internal `Op::ListSkills` returns empty compatibility entries without loading config layers, plugin roots, skill files, or conversion helpers, the Codex skill watcher has been collapsed to a no-op marker with no file watcher, skill-root registration, cache-clear task, or `SkillsUpdateAvailable` session listener, model turns no longer run skill mention collection, skill env-var prompts, skill MCP dependency installation, skill instruction injection, or implicit skill invocation analytics from shell tools, and the turn prompt/router path no longer loads plugin/app capability summaries, injects available-skill/available-plugin/plugin instruction fragments, parses plugin/app mentions, records app/plugin invocation telemetry, or filters MCP tools through Codex app connectors. `codex_message_processor.rs` is about 9,637 lines; root `message_processor.rs` is about 1,292 lines after the external-agent/config-product cuts; `epiphany_read_routes.rs` is about 579 lines after the full view and read-response extractions; `epiphany_mutation_routes.rs` is about 694 lines after route-load/notification helper cuts and product-surface starvation; `epiphany_state_helpers.rs` is down to a 19-line rollout-state loader; and `codex_thread.rs` is about 1,425 lines after state-update law moved native. `epiphany-openai-adapter` defines CultCache `DatabaseEntry` request/event/receipt/auth-status documents with no Codex app-server or generic JSON dependency. `epiphany-openai-codex-spine` owns all direct Codex auth/model-transport imports for the native OpenAI path: it exposes `default_codex_home` and `auth_manager`, projects `AuthManager` / `CodexAuth` into typed `EpiphanyOpenAiAdapterStatus`, maps typed `EpiphanyOpenAiModelRequest` into Codex API `ResponsesApiRequest`, resolves auth/provider through keeper Codex crates, opens HTTP Responses streams through `codex-api`, maps deltas / completion into typed stream events and receipts, and no longer directly depends on `codex-app-server-protocol` just to name auth mode. `epiphany-openai-runtime` no longer depends directly on `codex-login`; it writes OpenAI status/request/stream-event/receipt records plus runtime sessions/jobs/results/events into `epiphany-core::runtime_spine_cache`, can emit the assistant text artifact for legacy result consumers, is now the default executor for startup-only repo birth specialists, and now has `run-worker` to load a durable `EpiphanyRuntimeWorkerLaunchRequest`, call the typed OpenAI runtime through the spine, persist typed `EpiphanyRuntimeRoleWorkerResult` / `EpiphanyRuntimeReorientWorkerResult` documents, and complete the original heartbeat/specialist runtime job without Codex worker execution; `codex exec` survives only as explicit fallback in repo-birth startup. `epiphany-mvp-coordinator` now invokes `epiphany-openai-runtime run-worker` for launched runtime job ids and no longer creates a second coordinator-owned shadow runtime job/result as a compensator. `epiphany-core::plan_runtime_spine_heartbeat_launch` validates launch contracts/conflicts and projects durable job bindings/runtime links; `epiphany-core::open_runtime_spine_heartbeat_job` owns the initialize-runtime/ensure-session/create-job sequence and now persists `EpiphanyRuntimeWorkerLaunchRequest` CultCache records keyed by runtime job id, with indexed kind/contract fields plus MessagePack-encoded typed launch documents instead of discarding work intent after queue receipt creation; `roleResult` and `reorientResult` now prefer typed worker result documents and fall back only to generic job summaries for older receipts; `epiphany-core::EpiphanyStateUpdate`, `epiphany_state_update_validation_errors`, and `apply_epiphany_state_update` own state-update document shape and mutation law while `codex-core` calls them for compatibility. Vendored `CodexThread::epiphany_launch_job` is now mostly revision check, persistence validation, launch request handoff, and rollout/session writeback for the compatibility route. Vendored `codex-core` no longer has `epiphany_distillation`, `epiphany_promotion`, `epiphany_proposal`, or `epiphany_retrieval` husk modules; it re-exports native surfaces from `epiphany-core` directly, and now owns only the real Codex rollout adapter because it is a host seam. `epiphany-runtime-spine` advertises OpenAI adapter status/model-request/stream-event/receipt CultNet schemas and mutation contracts, so the native caller now has a real storage route instead of only JSON-RPC. MCP itself is correctly JSON at its protocol edge; the target is typed Epiphany intent/result/receipt wrappers around MCP, not replacing MCP JSON. The current OpenAI spine still pulls `codex-api` and a large transport dependency stack, so its next cut is dependency starvation after richer live callers move. latest_cut: > - The Codex tool-suggestion marketplace path is cold: `tool_suggest` is no - longer exposed in model-turn tool config, its core handler and - discoverable-plugin scan were deleted, MCP startup/refresh uses empty plugin - provenance, session/thread state no longer carries `PluginsManager`, and - the explicit connector-selection cache was removed because it only served - app/plugin suggestion bookkeeping. The core plugin husk was then deleted: - `codex-core` no longer exports `plugins` or depends on `codex-core-plugins` - / `codex-plugin`, the core plugin manager and marketplace add/remove/sync - modules/tests are gone, CLI marketplace commands are disabled compatibility - shells, MCP CLI setup no longer creates plugin managers, ChatGPT connector - listing no longer merges plugin-provided apps, and TUI plugin mentions no - longer scan core plugins. Codex Apps are now a tiny compatibility stub in - core: connector listing returns empty, app prompt instructions/rendering are - deleted, `TurnContext::apps_enabled()` is gone, refresh no longer auto-adds - `codex_apps` as an MCP server, and only user-declared MCP servers remain as - runtime MCP authority. + Codex Apps no longer have privileged MCP/runtime treatment in the keeper + path. MCP exposure is now uniform: small tool sets are direct, large or + always-defer sets go through `tool_search`, and no server name gets an app + exemption. Core MCP tool calls no longer consult app tool policy, block via + app config, track app invocation analytics, forward `_codex_apps` metadata, + render bundled Codex app approval templates, persist approvals under + `[apps.*]`, or decorate approval elicitation metadata with connector-source + fields. The 962-line consequential app-template JSON relic was deleted. + `codex-mcp` no longer auto-injects `codex_apps`, exports + `with_codex_apps_mcp`, keeps a ChatGPT-auth-keyed Codex Apps tool cache, + exposes `hard_refresh_codex_apps_tools_cache`, filters non-app MCP tools, + normalizes app callable names/namespaces/titles, or masks app file params at + app-specific return boundaries. MCP remains JSON-RPC at the edge; user + declared MCP servers are the only runtime MCP authority. next_action: Continue starving coordinator/runtime execution and operator surfaces off app-server JSON-RPC and out of `codex_message_processor.rs`; keep the vestigial Codex organ narrowed to subscription auth/model transport. diff --git a/vendor/codex/codex-rs/codex-mcp/src/lib.rs b/vendor/codex/codex-rs/codex-mcp/src/lib.rs index 8b77086e..8c83cb63 100644 --- a/vendor/codex/codex-rs/codex-mcp/src/lib.rs +++ b/vendor/codex/codex-rs/codex-mcp/src/lib.rs @@ -2,7 +2,6 @@ pub(crate) mod mcp; pub(crate) mod mcp_connection_manager; pub(crate) mod mcp_tool_names; -pub use mcp::CODEX_APPS_MCP_SERVER_NAME; pub use mcp::McpAuthStatusEntry; pub use mcp::McpConfig; pub use mcp::McpManager; @@ -34,14 +33,10 @@ pub use mcp::resolve_oauth_scopes; pub use mcp::should_retry_without_scopes; pub use mcp::split_qualified_tool_name; pub use mcp::tool_plugin_provenance; -pub use mcp::with_codex_apps_mcp; -pub use mcp_connection_manager::CodexAppsToolsCacheKey; pub use mcp_connection_manager::DEFAULT_STARTUP_TIMEOUT; pub use mcp_connection_manager::MCP_SANDBOX_STATE_META_CAPABILITY; pub use mcp_connection_manager::McpConnectionManager; pub use mcp_connection_manager::McpRuntimeEnvironment; pub use mcp_connection_manager::SandboxState; pub use mcp_connection_manager::ToolInfo; -pub use mcp_connection_manager::codex_apps_tools_cache_key; pub use mcp_connection_manager::declared_openai_file_input_param_names; -pub use mcp_connection_manager::filter_non_codex_apps_mcp_tools_only; diff --git a/vendor/codex/codex-rs/codex-mcp/src/mcp/mod.rs b/vendor/codex/codex-rs/codex-mcp/src/mcp/mod.rs index 97053cbe..c6f97c71 100644 --- a/vendor/codex/codex-rs/codex-mcp/src/mcp/mod.rs +++ b/vendor/codex/codex-rs/codex-mcp/src/mcp/mod.rs @@ -14,14 +14,11 @@ pub use skill_dependencies::canonical_mcp_server_key; pub use skill_dependencies::collect_missing_mcp_dependencies; use std::collections::HashMap; -use std::env; use std::path::PathBuf; -use std::time::Duration; use async_channel::unbounded; use codex_config::Constrained; use codex_config::McpServerConfig; -use codex_config::McpServerTransportConfig; use codex_config::types::OAuthCredentialsStoreMode; use codex_login::CodexAuth; use codex_plugin::PluginCapabilitySummary; @@ -38,14 +35,10 @@ use serde_json::Value; use crate::mcp_connection_manager::McpConnectionManager; use crate::mcp_connection_manager::McpRuntimeEnvironment; -use crate::mcp_connection_manager::codex_apps_tools_cache_key; pub type McpManager = McpConnectionManager; const MCP_TOOL_NAME_PREFIX: &str = "mcp"; const MCP_TOOL_NAME_DELIMITER: &str = "__"; -pub const CODEX_APPS_MCP_SERVER_NAME: &str = "codex_apps"; -const CODEX_CONNECTORS_TOKEN_ENV_VAR: &str = "CODEX_CONNECTORS_TOKEN"; - #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] pub enum McpSnapshotDetail { #[default] @@ -105,7 +98,7 @@ pub fn mcp_permission_prompt_is_auto_approved( /// approval/sandbox policy, locate OAuth state, and merge plugin-provided MCP /// servers. Request-scoped or auth-scoped state should not be stored here; /// thread those values explicitly into runtime entry points such as -/// [`with_codex_apps_mcp`] and [`collect_mcp_snapshot`] so config objects do +/// [`effective_mcp_servers`] and [`collect_mcp_snapshot`] so config objects do /// not go stale when auth changes. #[derive(Debug, Clone)] pub struct McpConfig { @@ -196,124 +189,15 @@ impl ToolPluginProvenance { } } -fn codex_apps_mcp_bearer_token_env_var() -> Option { - match env::var(CODEX_CONNECTORS_TOKEN_ENV_VAR) { - Ok(value) if !value.trim().is_empty() => Some(CODEX_CONNECTORS_TOKEN_ENV_VAR.to_string()), - Ok(_) => None, - Err(env::VarError::NotPresent) => None, - Err(env::VarError::NotUnicode(_)) => Some(CODEX_CONNECTORS_TOKEN_ENV_VAR.to_string()), - } -} - -fn codex_apps_mcp_bearer_token(auth: Option<&CodexAuth>) -> Option { - let token = auth.and_then(|auth| auth.get_token().ok())?; - let token = token.trim(); - if token.is_empty() { - None - } else { - Some(token.to_string()) - } -} - -fn codex_apps_mcp_http_headers(auth: Option<&CodexAuth>) -> Option> { - let mut headers = HashMap::new(); - if let Some(token) = codex_apps_mcp_bearer_token(auth) { - headers.insert("Authorization".to_string(), format!("Bearer {token}")); - } - if let Some(account_id) = auth.and_then(CodexAuth::get_account_id) { - headers.insert("ChatGPT-Account-ID".to_string(), account_id); - } - if headers.is_empty() { - None - } else { - Some(headers) - } -} - -fn normalize_codex_apps_base_url(base_url: &str) -> String { - let mut base_url = base_url.trim_end_matches('/').to_string(); - if (base_url.starts_with("https://chatgpt.com") - || base_url.starts_with("https://chat.openai.com")) - && !base_url.contains("/backend-api") - { - base_url = format!("{base_url}/backend-api"); - } - base_url -} - -fn codex_apps_mcp_url_for_base_url(base_url: &str) -> String { - let base_url = normalize_codex_apps_base_url(base_url); - if base_url.contains("/backend-api") { - format!("{base_url}/wham/apps") - } else if base_url.contains("/api/codex") { - format!("{base_url}/apps") - } else { - format!("{base_url}/api/codex/apps") - } -} - -pub(crate) fn codex_apps_mcp_url(config: &McpConfig) -> String { - codex_apps_mcp_url_for_base_url(&config.chatgpt_base_url) -} - -fn codex_apps_mcp_server_config(config: &McpConfig, auth: Option<&CodexAuth>) -> McpServerConfig { - let bearer_token_env_var = codex_apps_mcp_bearer_token_env_var(); - let http_headers = if bearer_token_env_var.is_some() { - None - } else { - codex_apps_mcp_http_headers(auth) - }; - let url = codex_apps_mcp_url(config); - - McpServerConfig { - transport: McpServerTransportConfig::StreamableHttp { - url, - bearer_token_env_var, - http_headers, - env_http_headers: None, - }, - experimental_environment: None, - enabled: true, - required: false, - supports_parallel_tool_calls: false, - disabled_reason: None, - startup_timeout_sec: Some(Duration::from_secs(30)), - tool_timeout_sec: None, - default_tools_approval_mode: None, - enabled_tools: None, - disabled_tools: None, - scopes: None, - oauth_resource: None, - tools: HashMap::new(), - } -} - -pub fn with_codex_apps_mcp( - mut servers: HashMap, - auth: Option<&CodexAuth>, - config: &McpConfig, -) -> HashMap { - if config.apps_enabled && auth.is_some_and(CodexAuth::is_chatgpt_auth) { - servers.insert( - CODEX_APPS_MCP_SERVER_NAME.to_string(), - codex_apps_mcp_server_config(config, auth), - ); - } else { - servers.remove(CODEX_APPS_MCP_SERVER_NAME); - } - servers -} - pub fn configured_mcp_servers(config: &McpConfig) -> HashMap { config.configured_mcp_servers.clone() } pub fn effective_mcp_servers( config: &McpConfig, - auth: Option<&CodexAuth>, + _auth: Option<&CodexAuth>, ) -> HashMap { - let servers = configured_mcp_servers(config); - with_codex_apps_mcp(servers, auth, config) + configured_mcp_servers(config) } pub fn tool_plugin_provenance(config: &McpConfig) -> ToolPluginProvenance { @@ -342,8 +226,6 @@ pub async fn read_mcp_resource( tx_event, SandboxPolicy::new_read_only_policy(), runtime_environment, - config.codex_home.clone(), - codex_apps_tools_cache_key(auth), tool_plugin_provenance(config), ) .await; @@ -410,8 +292,6 @@ pub async fn collect_mcp_snapshot_with_detail( tx_event, SandboxPolicy::new_read_only_policy(), runtime_environment, - config.codex_home.clone(), - codex_apps_tools_cache_key(auth), tool_plugin_provenance, ) .await; @@ -485,8 +365,6 @@ pub async fn collect_mcp_server_status_snapshot_with_detail( tx_event, SandboxPolicy::new_read_only_policy(), runtime_environment, - config.codex_home.clone(), - codex_apps_tools_cache_key(auth), tool_plugin_provenance, ) .await; diff --git a/vendor/codex/codex-rs/codex-mcp/src/mcp_connection_manager.rs b/vendor/codex/codex-rs/codex-mcp/src/mcp_connection_manager.rs index 18c15cff..c271a1a8 100644 --- a/vendor/codex/codex-rs/codex-mcp/src/mcp_connection_manager.rs +++ b/vendor/codex/codex-rs/codex-mcp/src/mcp_connection_manager.rs @@ -14,13 +14,10 @@ use std::ffi::OsString; use std::path::PathBuf; use std::sync::Arc; use std::sync::Mutex as StdMutex; -use std::sync::atomic::AtomicBool; -use std::sync::atomic::Ordering; use std::time::Duration; use std::time::Instant; use crate::McpAuthStatusEntry; -use crate::mcp::CODEX_APPS_MCP_SERVER_NAME; use crate::mcp::McpConfig; use crate::mcp::ToolPluginProvenance; use crate::mcp::configured_mcp_servers; @@ -81,8 +78,6 @@ use serde::Deserialize; use serde::Serialize; use serde_json::Map; use serde_json::Value as JsonValue; -use sha1::Digest; -use sha1::Sha1; use tokio::sync::Mutex; use tokio::sync::oneshot; use tokio::task::JoinSet; @@ -94,8 +89,6 @@ use url::Url; use codex_config::McpServerConfig; use codex_config::McpServerTransportConfig; use codex_login::CodexAuth; -use codex_utils_plugins::mcp_connector::is_connector_id_allowed; -use codex_utils_plugins::mcp_connector::sanitize_name; /// Delimiter used to separate MCP tool-name parts. const MCP_TOOL_NAME_DELIMITER: &str = "__"; @@ -106,37 +99,8 @@ pub const DEFAULT_STARTUP_TIMEOUT: Duration = Duration::from_secs(30); /// Default timeout for individual tool calls. const DEFAULT_TOOL_TIMEOUT: Duration = Duration::from_secs(120); -const CODEX_APPS_TOOLS_CACHE_SCHEMA_VERSION: u8 = 2; -const CODEX_APPS_TOOLS_CACHE_DIR: &str = "cache/codex_apps_tools"; const MCP_TOOLS_LIST_DURATION_METRIC: &str = "codex.mcp.tools.list.duration_ms"; const MCP_TOOLS_FETCH_UNCACHED_DURATION_METRIC: &str = "codex.mcp.tools.fetch_uncached.duration_ms"; -const MCP_TOOLS_CACHE_WRITE_DURATION_METRIC: &str = "codex.mcp.tools.cache_write.duration_ms"; - -fn sha1_hex(s: &str) -> String { - let mut hasher = Sha1::new(); - hasher.update(s.as_bytes()); - let sha1 = hasher.finalize(); - format!("{sha1:x}") -} - -pub fn codex_apps_tools_cache_key(auth: Option<&CodexAuth>) -> CodexAppsToolsCacheKey { - let token_data = auth.and_then(|auth| auth.get_token_data().ok()); - let account_id = token_data - .as_ref() - .and_then(|token_data| token_data.account_id.clone()); - let chatgpt_user_id = token_data - .as_ref() - .and_then(|token_data| token_data.id_token.chatgpt_user_id.clone()); - let is_workspace_account = token_data - .as_ref() - .is_some_and(|token_data| token_data.id_token.is_workspace_account()); - - CodexAppsToolsCacheKey { - account_id, - chatgpt_user_id, - is_workspace_account, - } -} #[derive(Debug, Clone, Serialize, Deserialize)] pub struct ToolInfo { @@ -185,105 +149,6 @@ pub fn declared_openai_file_input_param_names( .collect() } -/// Returns the model-visible view of a tool while preserving the raw metadata -/// used by execution. Keep cache entries raw and call this at manager return -/// boundaries. -fn tool_with_model_visible_input_schema(tool: &Tool) -> Tool { - let file_params = declared_openai_file_input_param_names(tool.meta.as_deref()); - if file_params.is_empty() { - return tool.clone(); - } - - let mut tool = tool.clone(); - let mut input_schema = JsonValue::Object(tool.input_schema.as_ref().clone()); - mask_input_schema_for_file_path_params(&mut input_schema, &file_params); - if let JsonValue::Object(input_schema) = input_schema { - tool.input_schema = Arc::new(input_schema); - } - tool -} - -fn mask_input_schema_for_file_path_params(input_schema: &mut JsonValue, file_params: &[String]) { - let Some(properties) = input_schema - .as_object_mut() - .and_then(|schema| schema.get_mut("properties")) - .and_then(JsonValue::as_object_mut) - else { - return; - }; - - for field_name in file_params { - let Some(property_schema) = properties.get_mut(field_name) else { - continue; - }; - mask_input_property_schema(property_schema); - } -} - -fn mask_input_property_schema(schema: &mut JsonValue) { - let Some(object) = schema.as_object_mut() else { - return; - }; - - let mut description = object - .get("description") - .and_then(JsonValue::as_str) - .map(str::to_string) - .unwrap_or_default(); - let guidance = "This parameter expects an absolute local file path. If you want to upload a file, provide the absolute path to that file here."; - if description.is_empty() { - description = guidance.to_string(); - } else if !description.contains(guidance) { - description = format!("{description} {guidance}"); - } - - let is_array = object.get("type").and_then(JsonValue::as_str) == Some("array") - || object.get("items").is_some(); - object.clear(); - object.insert("description".to_string(), JsonValue::String(description)); - if is_array { - object.insert("type".to_string(), JsonValue::String("array".to_string())); - object.insert("items".to_string(), serde_json::json!({ "type": "string" })); - } else { - object.insert("type".to_string(), JsonValue::String("string".to_string())); - } -} - -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct CodexAppsToolsCacheKey { - account_id: Option, - chatgpt_user_id: Option, - is_workspace_account: bool, -} - -#[derive(Clone)] -struct CodexAppsToolsCacheContext { - codex_home: PathBuf, - user_key: CodexAppsToolsCacheKey, -} - -impl CodexAppsToolsCacheContext { - fn cache_path(&self) -> PathBuf { - let user_key_json = serde_json::to_string(&self.user_key).unwrap_or_default(); - let user_key_hash = sha1_hex(&user_key_json); - self.codex_home - .join(CODEX_APPS_TOOLS_CACHE_DIR) - .join(format!("{user_key_hash}.json")) - } -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -struct CodexAppsToolsDiskCache { - schema_version: u8, - tools: Vec, -} - -enum CachedCodexAppsToolsLoad { - Hit(Vec), - Missing, - Invalid, -} - type ResponderMap = HashMap<(String, RequestId), oneshot::Sender>; fn elicitation_is_rejected_by_policy(approval_policy: AskForApproval) -> bool { @@ -442,34 +307,11 @@ struct ManagedClient { tools: Vec, tool_filter: ToolFilter, tool_timeout: Option, - server_instructions: Option, server_supports_sandbox_state_meta_capability: bool, - codex_apps_tools_cache_context: Option, } impl ManagedClient { fn listed_tools(&self) -> Vec { - let total_start = Instant::now(); - if let Some(cache_context) = self.codex_apps_tools_cache_context.as_ref() - && let CachedCodexAppsToolsLoad::Hit(tools) = - load_cached_codex_apps_tools(cache_context) - { - emit_duration( - MCP_TOOLS_LIST_DURATION_METRIC, - total_start.elapsed(), - &[("cache", "hit")], - ); - return filter_tools(tools, &self.tool_filter); - } - - if self.codex_apps_tools_cache_context.is_some() { - emit_duration( - MCP_TOOLS_LIST_DURATION_METRIC, - total_start.elapsed(), - &[("cache", "miss")], - ); - } - self.tools.clone() } } @@ -477,8 +319,6 @@ impl ManagedClient { #[derive(Clone)] struct AsyncManagedClient { client: Shared>>, - startup_snapshot: Option>, - startup_complete: Arc, tool_plugin_provenance: Arc, } @@ -493,19 +333,11 @@ impl AsyncManagedClient { cancel_token: CancellationToken, tx_event: Sender, elicitation_requests: ElicitationRequestManager, - codex_apps_tools_cache_context: Option, tool_plugin_provenance: Arc, runtime_environment: McpRuntimeEnvironment, ) -> Self { let tool_filter = ToolFilter::from_config(&config); - let startup_snapshot = load_startup_cached_codex_apps_tools_snapshot( - &server_name, - codex_apps_tools_cache_context.as_ref(), - ) - .map(|tools| filter_tools(tools, &tool_filter)); let startup_tool_filter = tool_filter; - let startup_complete = Arc::new(AtomicBool::new(false)); - let startup_complete_for_fut = Arc::clone(&startup_complete); let fut = async move { let outcome = async { if let Err(error) = validate_mcp_server_name(&server_name) { @@ -532,7 +364,6 @@ impl AsyncManagedClient { tool_filter: startup_tool_filter, tx_event, elicitation_requests, - codex_apps_tools_cache_context, }, ) .or_cancel(&cancel_token) @@ -544,21 +375,12 @@ impl AsyncManagedClient { } .await; - startup_complete_for_fut.store(true, Ordering::Release); outcome }; let client = fut.boxed().shared(); - if startup_snapshot.is_some() { - let startup_task = client.clone(); - tokio::spawn(async move { - let _ = startup_task.await; - }); - } Self { client, - startup_snapshot, - startup_complete, tool_plugin_provenance, } } @@ -567,21 +389,10 @@ impl AsyncManagedClient { self.client.clone().await } - fn startup_snapshot_while_initializing(&self) -> Option> { - if !self.startup_complete.load(Ordering::Acquire) { - return self.startup_snapshot.clone(); - } - None - } - async fn listed_tools(&self) -> Option> { let annotate_tools = |tools: Vec| { let mut tools = tools; for tool in &mut tools { - if tool.server_name == CODEX_APPS_MCP_SERVER_NAME { - tool.tool = tool_with_model_visible_input_schema(&tool.tool); - } - let plugin_names = match tool.connector_id.as_deref() { Some(connector_id) => self .tool_plugin_provenance @@ -626,14 +437,9 @@ impl AsyncManagedClient { tools }; - // Keep cache payloads raw; plugin provenance is resolved per-session at read time. - let tools = if let Some(startup_tools) = self.startup_snapshot_while_initializing() { - Some(startup_tools) - } else { - match self.client().await { - Ok(client) => Some(client.listed_tools()), - Err(_) => self.startup_snapshot.clone(), - } + let tools = match self.client().await { + Ok(client) => Some(client.listed_tools()), + Err(_) => None, }; tools.map(annotate_tools) } @@ -752,8 +558,6 @@ impl McpConnectionManager { tx_event: Sender, initial_sandbox_policy: SandboxPolicy, runtime_environment: McpRuntimeEnvironment, - codex_home: PathBuf, - codex_apps_tools_cache_key: CodexAppsToolsCacheKey, tool_plugin_provenance: ToolPluginProvenance, ) -> (Self, CancellationToken) { let cancel_token = CancellationToken::new(); @@ -779,14 +583,6 @@ impl McpConnectionManager { }, ) .await; - let codex_apps_tools_cache_context = if server_name == CODEX_APPS_MCP_SERVER_NAME { - Some(CodexAppsToolsCacheContext { - codex_home: codex_home.clone(), - user_key: codex_apps_tools_cache_key.clone(), - }) - } else { - None - }; let async_managed_client = AsyncManagedClient::new( server_name.clone(), cfg, @@ -794,7 +590,6 @@ impl McpConnectionManager { cancel_token.clone(), tx_event.clone(), elicitation_requests.clone(), - codex_apps_tools_cache_context, Arc::clone(&tool_plugin_provenance), runtime_environment.clone(), ); @@ -933,57 +728,6 @@ impl McpConnectionManager { qualify_tools(tools) } - /// Force-refresh codex apps tools by bypassing the in-process cache. - /// - /// On success, the refreshed tools replace the cache contents and the - /// latest filtered tool map is returned directly to the caller. On - /// failure, the existing cache remains unchanged. - pub async fn hard_refresh_codex_apps_tools_cache(&self) -> Result> { - let managed_client = self - .clients - .get(CODEX_APPS_MCP_SERVER_NAME) - .ok_or_else(|| anyhow!("unknown MCP server '{CODEX_APPS_MCP_SERVER_NAME}'"))? - .client() - .await - .context("failed to get client")?; - - let list_start = Instant::now(); - let fetch_start = Instant::now(); - let tools = list_tools_for_client_uncached( - CODEX_APPS_MCP_SERVER_NAME, - &managed_client.client, - managed_client.tool_timeout, - managed_client.server_instructions.as_deref(), - ) - .await - .with_context(|| { - format!("failed to refresh tools for MCP server '{CODEX_APPS_MCP_SERVER_NAME}'") - })?; - emit_duration( - MCP_TOOLS_FETCH_UNCACHED_DURATION_METRIC, - fetch_start.elapsed(), - &[], - ); - - write_cached_codex_apps_tools_if_needed( - CODEX_APPS_MCP_SERVER_NAME, - managed_client.codex_apps_tools_cache_context.as_ref(), - &tools, - ); - emit_duration( - MCP_TOOLS_LIST_DURATION_METRIC, - list_start.elapsed(), - &[("cache", "miss")], - ); - let tools = filter_tools(tools, &managed_client.tool_filter) - .into_iter() - .map(|mut tool| { - tool.tool = tool_with_model_visible_input_schema(&tool.tool); - tool - }); - Ok(qualify_tools(tools)) - } - /// Returns a single map that contains all resources. Each key is the /// server name and the value is a vector of resources. pub async fn list_all_resources(&self) -> HashMap> { @@ -1280,96 +1024,6 @@ fn filter_tools(tools: Vec, filter: &ToolFilter) -> Vec { .collect() } -pub fn filter_non_codex_apps_mcp_tools_only( - mcp_tools: &HashMap, -) -> HashMap { - mcp_tools - .iter() - .filter(|(_, tool)| tool.server_name != CODEX_APPS_MCP_SERVER_NAME) - .map(|(name, tool)| (name.clone(), tool.clone())) - .collect() -} - -fn normalize_codex_apps_tool_title( - server_name: &str, - connector_name: Option<&str>, - value: &str, -) -> String { - if server_name != CODEX_APPS_MCP_SERVER_NAME { - return value.to_string(); - } - - let Some(connector_name) = connector_name - .map(str::trim) - .filter(|name| !name.is_empty()) - else { - return value.to_string(); - }; - - let prefix = format!("{connector_name}_"); - if let Some(stripped) = value.strip_prefix(&prefix) - && !stripped.is_empty() - { - return stripped.to_string(); - } - - value.to_string() -} - -fn normalize_codex_apps_callable_name( - server_name: &str, - tool_name: &str, - connector_id: Option<&str>, - connector_name: Option<&str>, -) -> String { - if server_name != CODEX_APPS_MCP_SERVER_NAME { - return tool_name.to_string(); - } - - let tool_name = sanitize_name(tool_name); - - if let Some(connector_name) = connector_name - .map(str::trim) - .map(sanitize_name) - .filter(|name| !name.is_empty()) - && let Some(stripped) = tool_name.strip_prefix(&connector_name) - && !stripped.is_empty() - { - return stripped.to_string(); - } - - if let Some(connector_id) = connector_id - .map(str::trim) - .map(sanitize_name) - .filter(|name| !name.is_empty()) - && let Some(stripped) = tool_name.strip_prefix(&connector_id) - && !stripped.is_empty() - { - return stripped.to_string(); - } - - tool_name -} - -fn normalize_codex_apps_callable_namespace( - server_name: &str, - connector_name: Option<&str>, -) -> String { - if server_name == CODEX_APPS_MCP_SERVER_NAME - && let Some(connector_name) = connector_name - { - format!( - "mcp{}{}{}{}", - MCP_TOOL_NAME_DELIMITER, - server_name, - MCP_TOOL_NAME_DELIMITER, - sanitize_name(connector_name) - ) - } else { - format!("mcp{MCP_TOOL_NAME_DELIMITER}{server_name}{MCP_TOOL_NAME_DELIMITER}") - } -} - fn resolve_bearer_token( server_name: &str, bearer_token_env_var: Option<&str>, @@ -1437,7 +1091,6 @@ async fn start_server_task( tool_filter, tx_event, elicitation_requests, - codex_apps_tools_cache_context, } = params; let elicitation = elicitation_capability_for_server(&server_name); let params = InitializeRequestParams { @@ -1489,18 +1142,7 @@ async fn start_server_task( fetch_start.elapsed(), &[], ); - write_cached_codex_apps_tools_if_needed( - &server_name, - codex_apps_tools_cache_context.as_ref(), - &tools, - ); - if server_name == CODEX_APPS_MCP_SERVER_NAME { - emit_duration( - MCP_TOOLS_LIST_DURATION_METRIC, - list_start.elapsed(), - &[("cache", "miss")], - ); - } + emit_duration(MCP_TOOLS_LIST_DURATION_METRIC, list_start.elapsed(), &[]); let tools = filter_tools(tools, &tool_filter); let managed = ManagedClient { @@ -1508,9 +1150,7 @@ async fn start_server_task( tools, tool_timeout: Some(tool_timeout), tool_filter, - server_instructions: initialize_result.instructions, server_supports_sandbox_state_meta_capability, - codex_apps_tools_cache_context, }; Ok(managed) @@ -1522,7 +1162,6 @@ struct StartServerTaskParams { tool_filter: ToolFilter, tx_event: Sender, elicitation_requests: ElicitationRequestManager, - codex_apps_tools_cache_context: Option, } async fn make_rmcp_client( @@ -1616,101 +1255,6 @@ async fn make_rmcp_client( } } -fn write_cached_codex_apps_tools_if_needed( - server_name: &str, - cache_context: Option<&CodexAppsToolsCacheContext>, - tools: &[ToolInfo], -) { - if server_name != CODEX_APPS_MCP_SERVER_NAME { - return; - } - - if let Some(cache_context) = cache_context { - let cache_write_start = Instant::now(); - write_cached_codex_apps_tools(cache_context, tools); - emit_duration( - MCP_TOOLS_CACHE_WRITE_DURATION_METRIC, - cache_write_start.elapsed(), - &[], - ); - } -} - -fn load_startup_cached_codex_apps_tools_snapshot( - server_name: &str, - cache_context: Option<&CodexAppsToolsCacheContext>, -) -> Option> { - if server_name != CODEX_APPS_MCP_SERVER_NAME { - return None; - } - - let cache_context = cache_context?; - - match load_cached_codex_apps_tools(cache_context) { - CachedCodexAppsToolsLoad::Hit(tools) => Some(tools), - CachedCodexAppsToolsLoad::Missing | CachedCodexAppsToolsLoad::Invalid => None, - } -} - -#[cfg(test)] -fn read_cached_codex_apps_tools( - cache_context: &CodexAppsToolsCacheContext, -) -> Option> { - match load_cached_codex_apps_tools(cache_context) { - CachedCodexAppsToolsLoad::Hit(tools) => Some(tools), - CachedCodexAppsToolsLoad::Missing | CachedCodexAppsToolsLoad::Invalid => None, - } -} - -fn load_cached_codex_apps_tools( - cache_context: &CodexAppsToolsCacheContext, -) -> CachedCodexAppsToolsLoad { - let cache_path = cache_context.cache_path(); - let bytes = match std::fs::read(cache_path) { - Ok(bytes) => bytes, - Err(err) if err.kind() == std::io::ErrorKind::NotFound => { - return CachedCodexAppsToolsLoad::Missing; - } - Err(_) => return CachedCodexAppsToolsLoad::Invalid, - }; - let cache: CodexAppsToolsDiskCache = match serde_json::from_slice(&bytes) { - Ok(cache) => cache, - Err(_) => return CachedCodexAppsToolsLoad::Invalid, - }; - if cache.schema_version != CODEX_APPS_TOOLS_CACHE_SCHEMA_VERSION { - return CachedCodexAppsToolsLoad::Invalid; - } - CachedCodexAppsToolsLoad::Hit(filter_disallowed_codex_apps_tools(cache.tools)) -} - -fn write_cached_codex_apps_tools(cache_context: &CodexAppsToolsCacheContext, tools: &[ToolInfo]) { - let cache_path = cache_context.cache_path(); - if let Some(parent) = cache_path.parent() - && std::fs::create_dir_all(parent).is_err() - { - return; - } - let tools = filter_disallowed_codex_apps_tools(tools.to_vec()); - let Ok(bytes) = serde_json::to_vec_pretty(&CodexAppsToolsDiskCache { - schema_version: CODEX_APPS_TOOLS_CACHE_SCHEMA_VERSION, - tools, - }) else { - return; - }; - let _ = std::fs::write(cache_path, bytes); -} - -fn filter_disallowed_codex_apps_tools(tools: Vec) -> Vec { - tools - .into_iter() - .filter(|tool| { - tool.connector_id - .as_deref() - .is_none_or(is_connector_id_allowed) - }) - .collect() -} - fn emit_duration(metric: &str, duration: Duration, tags: &[(&str, &str)]) { if let Some(metrics) = codex_otel::global() { let _ = metrics.record_duration(metric, duration, tags); @@ -1740,32 +1284,17 @@ async fn list_tools_for_client_uncached( .tools .into_iter() .map(|tool| { - let callable_name = normalize_codex_apps_callable_name( - server_name, - &tool.tool.name, - tool.connector_id.as_deref(), - tool.connector_name.as_deref(), - ); - let callable_namespace = normalize_codex_apps_callable_namespace( - server_name, - tool.connector_name.as_deref(), - ); + let callable_name = tool.tool.name.to_string(); + let callable_namespace = + format!("mcp{MCP_TOOL_NAME_DELIMITER}{server_name}{MCP_TOOL_NAME_DELIMITER}"); let connector_name = tool.connector_name; let connector_description = tool.connector_description; - let mut tool_def = tool.tool; - if let Some(title) = tool_def.title.as_deref() { - let normalized_title = - normalize_codex_apps_tool_title(server_name, connector_name.as_deref(), title); - if tool_def.title.as_deref() != Some(normalized_title.as_str()) { - tool_def.title = Some(normalized_title); - } - } ToolInfo { server_name: server_name.to_owned(), callable_name, callable_namespace, server_instructions: server_instructions.map(str::to_string), - tool: tool_def, + tool: tool.tool, connector_id: tool.connector_id, connector_name, plugin_display_names: Vec::new(), @@ -1773,9 +1302,6 @@ async fn list_tools_for_client_uncached( } }) .collect(); - if server_name == CODEX_APPS_MCP_SERVER_NAME { - return Ok(filter_disallowed_codex_apps_tools(tools)); - } Ok(tools) } diff --git a/vendor/codex/codex-rs/core/src/connectors.rs b/vendor/codex/codex-rs/core/src/connectors.rs index 2a73bdd5..ce1819b3 100644 --- a/vendor/codex/codex-rs/core/src/connectors.rs +++ b/vendor/codex/codex-rs/core/src/connectors.rs @@ -1,27 +1,10 @@ pub use codex_app_server_protocol::AppBranding; pub use codex_app_server_protocol::AppInfo; pub use codex_app_server_protocol::AppMetadata; -use codex_config::types::AppToolApproval; use codex_mcp::ToolInfo; -use rmcp::model::ToolAnnotations; use crate::config::Config; -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub(crate) struct AppToolPolicy { - pub enabled: bool, - pub approval: AppToolApproval, -} - -impl Default for AppToolPolicy { - fn default() -> Self { - Self { - enabled: true, - approval: AppToolApproval::Auto, - } - } -} - #[derive(Debug, Clone)] pub struct AccessibleConnectorsStatus { pub connectors: Vec, @@ -77,17 +60,3 @@ pub fn accessible_connectors_from_mcp_tools( pub fn with_app_enabled_state(connectors: Vec, _config: &Config) -> Vec { connectors } - -pub(crate) fn app_tool_policy( - _config: &Config, - _connector_id: Option<&str>, - _tool_name: &str, - _tool_title: Option<&str>, - _annotations: Option<&ToolAnnotations>, -) -> AppToolPolicy { - AppToolPolicy::default() -} - -pub(crate) fn codex_app_tool_is_enabled(_config: &Config, _tool_info: &ToolInfo) -> bool { - true -} diff --git a/vendor/codex/codex-rs/core/src/consequential_tool_message_templates.json b/vendor/codex/codex-rs/core/src/consequential_tool_message_templates.json deleted file mode 100644 index 83e11c79..00000000 --- a/vendor/codex/codex-rs/core/src/consequential_tool_message_templates.json +++ /dev/null @@ -1,962 +0,0 @@ -{ - "schema_version": 4, - "templates": [ - { - "source_tool_index": 0, - "connector_id": "connector_76869538009648d5b282a4bb21c3d157", - "server_name": "codex_apps", - "tool_title": "add_comment_to_issue", - "template_params": [ - { - "name": "pr_number", - "label": "Pull request" - }, - { - "name": "repo_full_name", - "label": "Repository" - }, - { - "name": "comment", - "label": "Comment" - } - ], - "template": "Allow {connector_name} to add a comment to a pull request?" - }, - { - "source_tool_index": 1, - "connector_id": "connector_76869538009648d5b282a4bb21c3d157", - "server_name": "codex_apps", - "tool_title": "add_reaction_to_issue_comment", - "template_params": [ - { - "name": "reaction", - "label": "Reaction" - }, - { - "name": "comment_id", - "label": "Comment" - }, - { - "name": "repo_full_name", - "label": "Repository" - } - ], - "template": "Allow {connector_name} to add a reaction to an issue comment?" - }, - { - "source_tool_index": 2, - "connector_id": "connector_76869538009648d5b282a4bb21c3d157", - "server_name": "codex_apps", - "tool_title": "add_reaction_to_pr", - "template_params": [ - { - "name": "reaction", - "label": "Reaction" - }, - { - "name": "pr_number", - "label": "Pull request" - }, - { - "name": "repo_full_name", - "label": "Repository" - } - ], - "template": "Allow {connector_name} to add a reaction to a pull request?" - }, - { - "source_tool_index": 3, - "connector_id": "connector_76869538009648d5b282a4bb21c3d157", - "server_name": "codex_apps", - "tool_title": "add_reaction_to_pr_review_comment", - "template_params": [ - { - "name": "reaction", - "label": "Reaction" - }, - { - "name": "comment_id", - "label": "Comment" - }, - { - "name": "repo_full_name", - "label": "Repository" - } - ], - "template": "Allow {connector_name} to add a reaction to a pull request review comment?" - }, - { - "source_tool_index": 4, - "connector_id": "connector_76869538009648d5b282a4bb21c3d157", - "server_name": "codex_apps", - "tool_title": "add_review_to_pr", - "template_params": [ - { - "name": "action", - "label": "Action" - }, - { - "name": "pr_number", - "label": "Pull request" - }, - { - "name": "review", - "label": "Review" - } - ], - "template": "Allow {connector_name} to submit a pull request review?" - }, - { - "source_tool_index": 5, - "connector_id": "connector_76869538009648d5b282a4bb21c3d157", - "server_name": "codex_apps", - "tool_title": "create_blob", - "template_params": [ - { - "name": "repository_full_name", - "label": "Repository" - }, - { - "name": "content", - "label": "Content" - } - ], - "template": "Allow {connector_name} to create a Git blob?" - }, - { - "source_tool_index": 6, - "connector_id": "connector_76869538009648d5b282a4bb21c3d157", - "server_name": "codex_apps", - "tool_title": "create_branch", - "template_params": [ - { - "name": "branch_name", - "label": "Branch" - }, - { - "name": "repository_full_name", - "label": "Repository" - } - ], - "template": "Allow {connector_name} to create a branch?" - }, - { - "source_tool_index": 7, - "connector_id": "connector_76869538009648d5b282a4bb21c3d157", - "server_name": "codex_apps", - "tool_title": "create_commit", - "template_params": [ - { - "name": "repository_full_name", - "label": "Repository" - }, - { - "name": "message", - "label": "Message" - } - ], - "template": "Allow {connector_name} to create a commit?" - }, - { - "source_tool_index": 8, - "connector_id": "connector_76869538009648d5b282a4bb21c3d157", - "server_name": "codex_apps", - "tool_title": "create_pull_request", - "template_params": [ - { - "name": "title", - "label": "Title" - }, - { - "name": "head_branch", - "label": "Head branch" - }, - { - "name": "base_branch", - "label": "Base branch" - } - ], - "template": "Allow {connector_name} to create a pull request?" - }, - { - "source_tool_index": 9, - "connector_id": "connector_76869538009648d5b282a4bb21c3d157", - "server_name": "codex_apps", - "tool_title": "create_tree", - "template_params": [ - { - "name": "repository_full_name", - "label": "Repository" - }, - { - "name": "tree_elements", - "label": "Changes" - } - ], - "template": "Allow {connector_name} to create a Git tree?" - }, - { - "source_tool_index": 10, - "connector_id": "connector_76869538009648d5b282a4bb21c3d157", - "server_name": "codex_apps", - "tool_title": "enable_auto_merge", - "template_params": [ - { - "name": "pr_number", - "label": "Pull request" - }, - { - "name": "repository_full_name", - "label": "Repository" - } - ], - "template": "Allow {connector_name} to enable pull request auto-merge?" - }, - { - "source_tool_index": 11, - "connector_id": "connector_76869538009648d5b282a4bb21c3d157", - "server_name": "codex_apps", - "tool_title": "label_pr", - "template_params": [ - { - "name": "label", - "label": "Label" - }, - { - "name": "pr_number", - "label": "Pull request" - }, - { - "name": "repository_full_name", - "label": "Repository" - } - ], - "template": "Allow {connector_name} to add a label to a pull request?" - }, - { - "source_tool_index": 12, - "connector_id": "connector_76869538009648d5b282a4bb21c3d157", - "server_name": "codex_apps", - "tool_title": "remove_reaction_from_issue_comment", - "template_params": [ - { - "name": "reaction_id", - "label": "Reaction" - }, - { - "name": "comment_id", - "label": "Comment" - }, - { - "name": "repo_full_name", - "label": "Repository" - } - ], - "template": "Allow {connector_name} to remove a reaction from an issue comment?" - }, - { - "source_tool_index": 13, - "connector_id": "connector_76869538009648d5b282a4bb21c3d157", - "server_name": "codex_apps", - "tool_title": "remove_reaction_from_pr", - "template_params": [ - { - "name": "reaction_id", - "label": "Reaction" - }, - { - "name": "pr_number", - "label": "Pull request" - }, - { - "name": "repo_full_name", - "label": "Repository" - } - ], - "template": "Allow {connector_name} to remove a reaction from a pull request?" - }, - { - "source_tool_index": 14, - "connector_id": "connector_76869538009648d5b282a4bb21c3d157", - "server_name": "codex_apps", - "tool_title": "remove_reaction_from_pr_review_comment", - "template_params": [ - { - "name": "reaction_id", - "label": "Reaction" - }, - { - "name": "comment_id", - "label": "Comment" - }, - { - "name": "repo_full_name", - "label": "Repository" - } - ], - "template": "Allow {connector_name} to remove a reaction from a pull request review comment?" - }, - { - "source_tool_index": 15, - "connector_id": "connector_76869538009648d5b282a4bb21c3d157", - "server_name": "codex_apps", - "tool_title": "reply_to_review_comment", - "template_params": [ - { - "name": "pr_number", - "label": "Pull request" - }, - { - "name": "repo_full_name", - "label": "Repository" - }, - { - "name": "comment", - "label": "Comment" - } - ], - "template": "Allow {connector_name} to reply to a pull request review comment?" - }, - { - "source_tool_index": 16, - "connector_id": "connector_76869538009648d5b282a4bb21c3d157", - "server_name": "codex_apps", - "tool_title": "update_issue_comment", - "template_params": [ - { - "name": "comment_id", - "label": "Comment ID" - }, - { - "name": "repo_full_name", - "label": "Repository" - }, - { - "name": "comment", - "label": "Comment" - } - ], - "template": "Allow {connector_name} to update an issue comment?" - }, - { - "source_tool_index": 17, - "connector_id": "connector_76869538009648d5b282a4bb21c3d157", - "server_name": "codex_apps", - "tool_title": "update_ref", - "template_params": [ - { - "name": "branch_name", - "label": "Branch" - }, - { - "name": "repository_full_name", - "label": "Repository" - }, - { - "name": "sha", - "label": "Commit" - } - ], - "template": "Allow {connector_name} to update a branch reference?" - }, - { - "source_tool_index": 18, - "connector_id": "connector_76869538009648d5b282a4bb21c3d157", - "server_name": "codex_apps", - "tool_title": "update_review_comment", - "template_params": [ - { - "name": "comment_id", - "label": "Comment ID" - }, - { - "name": "repo_full_name", - "label": "Repository" - }, - { - "name": "comment", - "label": "Comment" - } - ], - "template": "Allow {connector_name} to update a pull request review comment?" - }, - { - "source_tool_index": 19, - "connector_id": "connector_947e0d954944416db111db556030eea6", - "server_name": "codex_apps", - "tool_title": "create_event", - "template_params": [ - { - "name": "title", - "label": "Title" - }, - { - "name": "start_time", - "label": "Start" - }, - { - "name": "attendees", - "label": "Attendees" - } - ], - "template": "Allow {connector_name} to create an event?" - }, - { - "source_tool_index": 20, - "connector_id": "connector_947e0d954944416db111db556030eea6", - "server_name": "codex_apps", - "tool_title": "delete_event", - "template_params": [ - { - "name": "event_id", - "label": "Event" - } - ], - "template": "Allow {connector_name} to delete an event?" - }, - { - "source_tool_index": 21, - "connector_id": "connector_947e0d954944416db111db556030eea6", - "server_name": "codex_apps", - "tool_title": "respond_event", - "template_params": [ - { - "name": "response_status", - "label": "Response Status" - }, - { - "name": "event_id", - "label": "Event" - } - ], - "template": "Allow {connector_name} to respond to an event?" - }, - { - "source_tool_index": 22, - "connector_id": "connector_947e0d954944416db111db556030eea6", - "server_name": "codex_apps", - "tool_title": "update_event", - "template_params": [ - { - "name": "event_id", - "label": "Event" - } - ], - "template": "Allow {connector_name} to update an event?" - }, - { - "source_tool_index": 23, - "connector_id": "connector_9d7cfa34e6654a5f98d3387af34b2e1c", - "server_name": "codex_apps", - "tool_title": "batch_update", - "template_params": [ - { - "name": "spreadsheet_url", - "label": "Spreadsheet" - }, - { - "name": "requests", - "label": "Changes" - } - ], - "template": "Allow {connector_name} to apply spreadsheet updates?" - }, - { - "source_tool_index": 24, - "connector_id": "connector_9d7cfa34e6654a5f98d3387af34b2e1c", - "server_name": "codex_apps", - "tool_title": "create_spreadsheet", - "template_params": [ - { - "name": "title", - "label": "Title" - } - ], - "template": "Allow {connector_name} to create a spreadsheet?" - }, - { - "source_tool_index": 25, - "connector_id": "connector_9d7cfa34e6654a5f98d3387af34b2e1c", - "server_name": "codex_apps", - "tool_title": "duplicate_sheet_in_new_file", - "template_params": [ - { - "name": "source_sheet_name", - "label": "Source Sheet Name" - }, - { - "name": "spreadsheet_url", - "label": "Spreadsheet" - }, - { - "name": "new_file_name", - "label": "New File Name" - } - ], - "template": "Allow {connector_name} to copy a sheet into a new spreadsheet?" - }, - { - "source_tool_index": 26, - "connector_id": "connector_6f1ec045b8fa4ced8738e32c7f74514b", - "server_name": "codex_apps", - "tool_title": "batch_update", - "template_params": [ - { - "name": "presentation_url", - "label": "Presentation" - }, - { - "name": "requests", - "label": "Changes" - } - ], - "template": "Allow {connector_name} to apply presentation updates?" - }, - { - "source_tool_index": 27, - "connector_id": "connector_6f1ec045b8fa4ced8738e32c7f74514b", - "server_name": "codex_apps", - "tool_title": "create_presentation", - "template_params": [ - { - "name": "title", - "label": "Title" - } - ], - "template": "Allow {connector_name} to create a presentation?" - }, - { - "source_tool_index": 28, - "connector_id": "connector_4964e3b22e3e427e9b4ae1acf2c1fa34", - "server_name": "codex_apps", - "tool_title": "batch_update", - "template_params": [ - { - "name": "document_url", - "label": "Document" - }, - { - "name": "requests", - "label": "Changes" - } - ], - "template": "Allow {connector_name} to apply document updates?" - }, - { - "source_tool_index": 29, - "connector_id": "connector_4964e3b22e3e427e9b4ae1acf2c1fa34", - "server_name": "codex_apps", - "tool_title": "create_document", - "template_params": [ - { - "name": "title", - "label": "Title" - } - ], - "template": "Allow {connector_name} to create a document?" - }, - { - "source_tool_index": 30, - "connector_id": "connector_5f3c8c41a1e54ad7a76272c89e2554fa", - "server_name": "codex_apps", - "tool_title": "copy_document", - "template_params": [ - { - "name": "url", - "label": "URL" - } - ], - "template": "Allow {connector_name} to copy a file?" - }, - { - "source_tool_index": 31, - "connector_id": "connector_5f3c8c41a1e54ad7a76272c89e2554fa", - "server_name": "codex_apps", - "tool_title": "share_document", - "template_params": [ - { - "name": "url", - "label": "URL" - }, - { - "name": "permission", - "label": "Permission" - } - ], - "template": "Allow {connector_name} to change file sharing?" - }, - { - "source_tool_index": 32, - "connector_id": "asdk_app_69a1d78e929881919bba0dbda1f6436d", - "server_name": "codex_apps", - "tool_title": "slack_send_message", - "template_params": [ - { - "name": "channel_id", - "label": "Conversation" - }, - { - "name": "message", - "label": "Message" - } - ], - "template": "Allow {connector_name} to send a message?" - }, - { - "source_tool_index": 33, - "connector_id": "asdk_app_69a1d78e929881919bba0dbda1f6436d", - "server_name": "codex_apps", - "tool_title": "slack_schedule_message", - "template_params": [ - { - "name": "channel_id", - "label": "Conversation" - }, - { - "name": "post_at", - "label": "Send at" - }, - { - "name": "message", - "label": "Message" - } - ], - "template": "Allow {connector_name} to schedule a message?" - }, - { - "source_tool_index": 34, - "connector_id": "asdk_app_69a1d78e929881919bba0dbda1f6436d", - "server_name": "codex_apps", - "tool_title": "slack_create_canvas", - "template_params": [ - { - "name": "title", - "label": "Title" - }, - { - "name": "content", - "label": "Content" - } - ], - "template": "Allow {connector_name} to create a canvas?" - }, - { - "source_tool_index": 35, - "connector_id": "asdk_app_69a1d78e929881919bba0dbda1f6436d", - "server_name": "codex_apps", - "tool_title": "slack_send_message_draft", - "template_params": [ - { - "name": "channel_id", - "label": "Conversation" - }, - { - "name": "message", - "label": "Message" - } - ], - "template": "Allow {connector_name} to create a message draft?" - }, - { - "source_tool_index": 36, - "connector_id": "connector_686fad9b54914a35b75be6d06a0f6f31", - "server_name": "codex_apps", - "tool_title": "add_comment_to_issue", - "template_params": [ - { - "name": "issue_id", - "label": "Issue" - }, - { - "name": "body", - "label": "Body" - } - ], - "template": "Allow {connector_name} to add a comment to an issue?" - }, - { - "source_tool_index": 37, - "connector_id": "connector_686fad9b54914a35b75be6d06a0f6f31", - "server_name": "codex_apps", - "tool_title": "add_label_to_issue", - "template_params": [ - { - "name": "label_id", - "label": "Label" - }, - { - "name": "issue_id", - "label": "Issue" - } - ], - "template": "Allow {connector_name} to add a label to an issue?" - }, - { - "source_tool_index": 38, - "connector_id": "connector_686fad9b54914a35b75be6d06a0f6f31", - "server_name": "codex_apps", - "tool_title": "add_url_attachment_to_issue", - "template_params": [ - { - "name": "url", - "label": "URL" - }, - { - "name": "issue_id", - "label": "Issue" - }, - { - "name": "title", - "label": "Title" - } - ], - "template": "Allow {connector_name} to attach a link to an issue?" - }, - { - "source_tool_index": 39, - "connector_id": "connector_686fad9b54914a35b75be6d06a0f6f31", - "server_name": "codex_apps", - "tool_title": "assign_issue", - "template_params": [ - { - "name": "issue_id", - "label": "Issue" - }, - { - "name": "user_id", - "label": "User" - } - ], - "template": "Allow {connector_name} to assign an issue?" - }, - { - "source_tool_index": 40, - "connector_id": "connector_686fad9b54914a35b75be6d06a0f6f31", - "server_name": "codex_apps", - "tool_title": "create_issue", - "template_params": [ - { - "name": "title", - "label": "Title" - }, - { - "name": "team_id", - "label": "Team" - } - ], - "template": "Allow {connector_name} to create an issue?" - }, - { - "source_tool_index": 41, - "connector_id": "connector_686fad9b54914a35b75be6d06a0f6f31", - "server_name": "codex_apps", - "tool_title": "create_label", - "template_params": [ - { - "name": "label_name", - "label": "Label Name" - } - ], - "template": "Allow {connector_name} to create a label?" - }, - { - "source_tool_index": 42, - "connector_id": "connector_686fad9b54914a35b75be6d06a0f6f31", - "server_name": "codex_apps", - "tool_title": "create_project", - "template_params": [ - { - "name": "name", - "label": "Name" - }, - { - "name": "team_id", - "label": "Team" - } - ], - "template": "Allow {connector_name} to create a project?" - }, - { - "source_tool_index": 43, - "connector_id": "connector_686fad9b54914a35b75be6d06a0f6f31", - "server_name": "codex_apps", - "tool_title": "remove_label_from_issue", - "template_params": [ - { - "name": "label_id", - "label": "Label" - }, - { - "name": "issue_id", - "label": "Issue" - } - ], - "template": "Allow {connector_name} to remove a label from an issue?" - }, - { - "source_tool_index": 44, - "connector_id": "connector_686fad9b54914a35b75be6d06a0f6f31", - "server_name": "codex_apps", - "tool_title": "resolve_comment", - "template_params": [ - { - "name": "comment_id", - "label": "Comment" - } - ], - "template": "Allow {connector_name} to resolve a comment?" - }, - { - "source_tool_index": 45, - "connector_id": "connector_686fad9b54914a35b75be6d06a0f6f31", - "server_name": "codex_apps", - "tool_title": "set_issue_state", - "template_params": [ - { - "name": "issue_id", - "label": "Issue" - }, - { - "name": "state_id", - "label": "State" - } - ], - "template": "Allow {connector_name} to change issue state?" - }, - { - "source_tool_index": 46, - "connector_id": "connector_686fad9b54914a35b75be6d06a0f6f31", - "server_name": "codex_apps", - "tool_title": "unassign_issue", - "template_params": [ - { - "name": "issue_id", - "label": "Issue" - } - ], - "template": "Allow {connector_name} to unassign an issue?" - }, - { - "source_tool_index": 47, - "connector_id": "connector_686fad9b54914a35b75be6d06a0f6f31", - "server_name": "codex_apps", - "tool_title": "update_issue", - "template_params": [ - { - "name": "issue_id", - "label": "Issue" - }, - { - "name": "issue_update", - "label": "Changes" - } - ], - "template": "Allow {connector_name} to update an issue?" - }, - { - "source_tool_index": 48, - "connector_id": "connector_686fad9b54914a35b75be6d06a0f6f31", - "server_name": "codex_apps", - "tool_title": "update_project", - "template_params": [ - { - "name": "project_id", - "label": "Project" - }, - { - "name": "update_fields", - "label": "Changes" - } - ], - "template": "Allow {connector_name} to update a project?" - }, - { - "source_tool_index": 49, - "connector_id": "connector_2128aebfecb84f64a069897515042a44", - "server_name": "codex_apps", - "tool_title": "apply_labels_to_emails", - "template_params": [], - "template": "Allow {connector_name} to apply label changes to messages?" - }, - { - "source_tool_index": 50, - "connector_id": "connector_2128aebfecb84f64a069897515042a44", - "server_name": "codex_apps", - "tool_title": "batch_modify_email", - "template_params": [], - "template": "Allow {connector_name} to update message labels?" - }, - { - "source_tool_index": 51, - "connector_id": "connector_2128aebfecb84f64a069897515042a44", - "server_name": "codex_apps", - "tool_title": "bulk_label_matching_emails", - "template_params": [ - { - "name": "label_name", - "label": "Label Name" - }, - { - "name": "query", - "label": "Query" - } - ], - "template": "Allow {connector_name} to label matching messages?" - }, - { - "source_tool_index": 52, - "connector_id": "connector_2128aebfecb84f64a069897515042a44", - "server_name": "codex_apps", - "tool_title": "create_draft", - "template_params": [ - { - "name": "to", - "label": "To" - }, - { - "name": "subject", - "label": "Subject" - }, - { - "name": "body", - "label": "Body" - } - ], - "template": "Allow {connector_name} to create an email draft?" - }, - { - "source_tool_index": 53, - "connector_id": "connector_2128aebfecb84f64a069897515042a44", - "server_name": "codex_apps", - "tool_title": "create_label", - "template_params": [ - { - "name": "name", - "label": "Name" - } - ], - "template": "Allow {connector_name} to create a label?" - }, - { - "source_tool_index": 54, - "connector_id": "connector_2128aebfecb84f64a069897515042a44", - "server_name": "codex_apps", - "tool_title": "send_email", - "template_params": [ - { - "name": "to", - "label": "To" - }, - { - "name": "subject", - "label": "Subject" - }, - { - "name": "body", - "label": "Body" - } - ], - "template": "Allow {connector_name} to send an email?" - } - ] -} diff --git a/vendor/codex/codex-rs/core/src/mcp_tool_approval_templates.rs b/vendor/codex/codex-rs/core/src/mcp_tool_approval_templates.rs index 66002ab5..9dcb9fdd 100644 --- a/vendor/codex/codex-rs/core/src/mcp_tool_approval_templates.rs +++ b/vendor/codex/codex-rs/core/src/mcp_tool_approval_templates.rs @@ -1,18 +1,5 @@ -use std::collections::HashSet; -use std::sync::LazyLock; - -use serde::Deserialize; use serde::Serialize; -use serde_json::Map; use serde_json::Value; -use tracing::warn; - -const CONSEQUENTIAL_TOOL_MESSAGE_TEMPLATES_SCHEMA_VERSION: u8 = 4; -const CONNECTOR_NAME_TEMPLATE_VAR: &str = "{connector_name}"; - -static CONSEQUENTIAL_TOOL_MESSAGE_TEMPLATES: LazyLock< - Option>, -> = LazyLock::new(load_consequential_tool_message_templates); #[derive(Clone, Debug, PartialEq)] pub(crate) struct RenderedMcpToolApprovalTemplate { @@ -29,343 +16,12 @@ pub(crate) struct RenderedMcpToolApprovalParam { pub(crate) display_name: String, } -#[derive(Debug, Deserialize)] -struct ConsequentialToolMessageTemplatesFile { - schema_version: u8, - templates: Vec, -} - -#[derive(Clone, Debug, Deserialize, PartialEq, Eq)] -struct ConsequentialToolMessageTemplate { - connector_id: String, - server_name: String, - tool_title: String, - template: String, - template_params: Vec, -} - -#[derive(Clone, Debug, Deserialize, PartialEq, Eq)] -struct ConsequentialToolTemplateParam { - name: String, - label: String, -} - pub(crate) fn render_mcp_tool_approval_template( - server_name: &str, - connector_id: Option<&str>, - connector_name: Option<&str>, - tool_title: Option<&str>, - tool_params: Option<&Value>, + _server_name: &str, + _connector_id: Option<&str>, + _connector_name: Option<&str>, + _tool_title: Option<&str>, + _tool_params: Option<&Value>, ) -> Option { - let templates = CONSEQUENTIAL_TOOL_MESSAGE_TEMPLATES.as_ref()?; - render_mcp_tool_approval_template_from_templates( - templates, - server_name, - connector_id, - connector_name, - tool_title, - tool_params, - ) -} - -fn load_consequential_tool_message_templates() -> Option> { - let templates = match serde_json::from_str::( - include_str!("consequential_tool_message_templates.json"), - ) { - Ok(templates) => templates, - Err(err) => { - warn!(error = %err, "failed to parse consequential tool approval templates"); - return None; - } - }; - - if templates.schema_version != CONSEQUENTIAL_TOOL_MESSAGE_TEMPLATES_SCHEMA_VERSION { - warn!( - found_schema_version = templates.schema_version, - expected_schema_version = CONSEQUENTIAL_TOOL_MESSAGE_TEMPLATES_SCHEMA_VERSION, - "unexpected consequential tool approval templates schema version" - ); - return None; - } - - Some(templates.templates) -} - -fn render_mcp_tool_approval_template_from_templates( - templates: &[ConsequentialToolMessageTemplate], - server_name: &str, - connector_id: Option<&str>, - connector_name: Option<&str>, - tool_title: Option<&str>, - tool_params: Option<&Value>, -) -> Option { - let connector_id = connector_id?; - let tool_title = tool_title.map(str::trim).filter(|name| !name.is_empty())?; - let template = templates.iter().find(|template| { - template.server_name == server_name - && template.connector_id == connector_id - && template.tool_title == tool_title - })?; - let elicitation_message = render_question_template(&template.template, connector_name)?; - let (tool_params, tool_params_display) = match tool_params { - Some(Value::Object(tool_params)) => { - render_tool_params(tool_params, &template.template_params)? - } - Some(_) => return None, - None => (None, Vec::new()), - }; - - Some(RenderedMcpToolApprovalTemplate { - question: elicitation_message.clone(), - elicitation_message, - tool_params, - tool_params_display, - }) -} - -fn render_question_template(template: &str, connector_name: Option<&str>) -> Option { - let template = template.trim(); - if template.is_empty() { - return None; - } - - if template.contains(CONNECTOR_NAME_TEMPLATE_VAR) { - let connector_name = connector_name - .map(str::trim) - .filter(|name| !name.is_empty())?; - return Some(template.replace(CONNECTOR_NAME_TEMPLATE_VAR, connector_name)); - } - - Some(template.to_string()) -} - -fn render_tool_params( - tool_params: &Map, - template_params: &[ConsequentialToolTemplateParam], -) -> Option<(Option, Vec)> { - let mut display_params = Vec::new(); - let mut display_names = HashSet::new(); - let mut handled_names = HashSet::new(); - - for template_param in template_params { - let label = template_param.label.trim(); - if label.is_empty() { - return None; - } - let Some(value) = tool_params.get(&template_param.name) else { - continue; - }; - if !display_names.insert(label.to_string()) { - return None; - } - display_params.push(RenderedMcpToolApprovalParam { - name: template_param.name.clone(), - value: value.clone(), - display_name: label.to_string(), - }); - handled_names.insert(template_param.name.as_str()); - } - - let mut remaining_params = tool_params - .iter() - .filter(|(name, _)| !handled_names.contains(name.as_str())) - .collect::>(); - remaining_params.sort_by(|(left_name, _), (right_name, _)| left_name.cmp(right_name)); - - for (name, value) in remaining_params { - if handled_names.contains(name.as_str()) { - continue; - } - if !display_names.insert(name.clone()) { - return None; - } - display_params.push(RenderedMcpToolApprovalParam { - name: name.clone(), - value: value.clone(), - display_name: name.clone(), - }); - } - - Some((Some(Value::Object(tool_params.clone())), display_params)) -} - -#[cfg(test)] -mod tests { - use pretty_assertions::assert_eq; - use serde_json::json; - - use super::*; - - #[test] - fn renders_exact_match_with_readable_param_labels() { - let templates = vec![ConsequentialToolMessageTemplate { - connector_id: "calendar".to_string(), - server_name: "codex_apps".to_string(), - tool_title: "create_event".to_string(), - template: "Allow {connector_name} to create an event?".to_string(), - template_params: vec![ - ConsequentialToolTemplateParam { - name: "calendar_id".to_string(), - label: "Calendar".to_string(), - }, - ConsequentialToolTemplateParam { - name: "title".to_string(), - label: "Title".to_string(), - }, - ], - }]; - - let rendered = render_mcp_tool_approval_template_from_templates( - &templates, - "codex_apps", - Some("calendar"), - Some("Calendar"), - Some("create_event"), - Some(&json!({ - "title": "Roadmap review", - "calendar_id": "primary", - "timezone": "UTC", - })), - ); - - assert_eq!( - rendered, - Some(RenderedMcpToolApprovalTemplate { - question: "Allow Calendar to create an event?".to_string(), - elicitation_message: "Allow Calendar to create an event?".to_string(), - tool_params: Some(json!({ - "title": "Roadmap review", - "calendar_id": "primary", - "timezone": "UTC", - })), - tool_params_display: vec![ - RenderedMcpToolApprovalParam { - name: "calendar_id".to_string(), - value: json!("primary"), - display_name: "Calendar".to_string(), - }, - RenderedMcpToolApprovalParam { - name: "title".to_string(), - value: json!("Roadmap review"), - display_name: "Title".to_string(), - }, - RenderedMcpToolApprovalParam { - name: "timezone".to_string(), - value: json!("UTC"), - display_name: "timezone".to_string(), - }, - ], - }) - ); - } - - #[test] - fn returns_none_when_no_exact_match_exists() { - let templates = vec![ConsequentialToolMessageTemplate { - connector_id: "calendar".to_string(), - server_name: "codex_apps".to_string(), - tool_title: "create_event".to_string(), - template: "Allow {connector_name} to create an event?".to_string(), - template_params: Vec::new(), - }]; - - assert_eq!( - render_mcp_tool_approval_template_from_templates( - &templates, - "codex_apps", - Some("calendar"), - Some("Calendar"), - Some("delete_event"), - Some(&json!({})), - ), - None - ); - } - - #[test] - fn returns_none_when_relabeling_would_collide() { - let templates = vec![ConsequentialToolMessageTemplate { - connector_id: "calendar".to_string(), - server_name: "codex_apps".to_string(), - tool_title: "create_event".to_string(), - template: "Allow {connector_name} to create an event?".to_string(), - template_params: vec![ConsequentialToolTemplateParam { - name: "calendar_id".to_string(), - label: "timezone".to_string(), - }], - }]; - - assert_eq!( - render_mcp_tool_approval_template_from_templates( - &templates, - "codex_apps", - Some("calendar"), - Some("Calendar"), - Some("create_event"), - Some(&json!({ - "calendar_id": "primary", - "timezone": "UTC", - })), - ), - None - ); - } - - #[test] - fn bundled_templates_load() { - assert_eq!(CONSEQUENTIAL_TOOL_MESSAGE_TEMPLATES.is_some(), true); - } - - #[test] - fn renders_literal_template_without_connector_substitution() { - let templates = vec![ConsequentialToolMessageTemplate { - connector_id: "github".to_string(), - server_name: "codex_apps".to_string(), - tool_title: "add_comment".to_string(), - template: "Allow GitHub to add a comment to a pull request?".to_string(), - template_params: Vec::new(), - }]; - - let rendered = render_mcp_tool_approval_template_from_templates( - &templates, - "codex_apps", - Some("github"), - /*connector_name*/ None, - Some("add_comment"), - Some(&json!({})), - ); - - assert_eq!( - rendered, - Some(RenderedMcpToolApprovalTemplate { - question: "Allow GitHub to add a comment to a pull request?".to_string(), - elicitation_message: "Allow GitHub to add a comment to a pull request?".to_string(), - tool_params: Some(json!({})), - tool_params_display: Vec::new(), - }) - ); - } - - #[test] - fn returns_none_when_connector_placeholder_has_no_value() { - let templates = vec![ConsequentialToolMessageTemplate { - connector_id: "calendar".to_string(), - server_name: "codex_apps".to_string(), - tool_title: "create_event".to_string(), - template: "Allow {connector_name} to create an event?".to_string(), - template_params: Vec::new(), - }]; - - assert_eq!( - render_mcp_tool_approval_template_from_templates( - &templates, - "codex_apps", - Some("calendar"), - /*connector_name*/ None, - Some("create_event"), - Some(&json!({})), - ), - None - ); - } + None } diff --git a/vendor/codex/codex-rs/core/src/mcp_tool_call.rs b/vendor/codex/codex-rs/core/src/mcp_tool_call.rs index 5028ba97..bb522fb7 100644 --- a/vendor/codex/codex-rs/core/src/mcp_tool_call.rs +++ b/vendor/codex/codex-rs/core/src/mcp_tool_call.rs @@ -16,7 +16,6 @@ use crate::config::Config; use crate::config::edit::ConfigEdit; use crate::config::edit::ConfigEditsBuilder; use crate::config::load_global_mcp_servers; -use crate::connectors; use crate::guardian::GuardianApprovalRequest; use crate::guardian::GuardianMcpAnnotations; use crate::guardian::guardian_approval_request_to_json; @@ -30,12 +29,8 @@ use crate::mcp_tool_approval_templates::RenderedMcpToolApprovalParam; use crate::mcp_tool_approval_templates::render_mcp_tool_approval_template; use crate::session::session::Session; use crate::session::turn_context::TurnContext; -use codex_analytics::AppInvocation; -use codex_analytics::InvocationType; -use codex_analytics::build_track_events_context; use codex_config::types::AppToolApproval; use codex_features::Feature; -use codex_mcp::CODEX_APPS_MCP_SERVER_NAME; use codex_mcp::SandboxState; use codex_mcp::declared_openai_file_input_param_names; use codex_mcp::mcp_permission_prompt_is_auto_approved; @@ -104,48 +99,7 @@ pub(crate) async fn handle_mcp_tool_call( let mcp_app_resource_uri = metadata .as_ref() .and_then(|metadata| metadata.mcp_app_resource_uri.clone()); - let app_tool_policy = if server == CODEX_APPS_MCP_SERVER_NAME { - connectors::app_tool_policy( - &turn_context.config, - metadata - .as_ref() - .and_then(|metadata| metadata.connector_id.as_deref()), - &tool_name, - metadata - .as_ref() - .and_then(|metadata| metadata.tool_title.as_deref()), - metadata - .as_ref() - .and_then(|metadata| metadata.annotations.as_ref()), - ) - } else { - connectors::AppToolPolicy::default() - }; - let approval_mode = if server == CODEX_APPS_MCP_SERVER_NAME { - app_tool_policy.approval - } else { - custom_mcp_tool_approval_mode(turn_context.as_ref(), &server, &tool_name) - }; - - if server == CODEX_APPS_MCP_SERVER_NAME && !app_tool_policy.enabled { - let result = notify_mcp_tool_call_skip( - sess.as_ref(), - turn_context.as_ref(), - &call_id, - invocation, - mcp_app_resource_uri.clone(), - "MCP tool call blocked by app configuration".to_string(), - /*already_started*/ false, - ) - .await; - let status = if result.is_ok() { "ok" } else { "error" }; - turn_context.session_telemetry.counter( - MCP_CALL_COUNT_METRIC, - /*inc*/ 1, - &[("status", status)], - ); - return CallToolResult::from_result(result); - } + let approval_mode = custom_mcp_tool_approval_mode(turn_context.as_ref(), &server, &tool_name); let request_meta = build_mcp_tool_call_request_meta(turn_context.as_ref(), &server, metadata.as_ref()); let connector_id = metadata @@ -228,13 +182,6 @@ pub(crate) async fn handle_mcp_tool_call( tool_call_end_event.clone(), ) .await; - maybe_track_codex_app_used( - sess.as_ref(), - turn_context.as_ref(), - &server, - &tool_name, - ) - .await; (result, Some(duration)) } McpToolApprovalDecision::Decline { message } => { @@ -345,7 +292,6 @@ pub(crate) async fn handle_mcp_tool_call( tool_call_end_event.clone(), ) .await; - maybe_track_codex_app_used(sess.as_ref(), turn_context.as_ref(), &server, &tool_name).await; let status = if result.is_ok() { "ok" } else { "error" }; emit_mcp_call_metrics( @@ -593,41 +539,6 @@ async fn notify_mcp_tool_call_event(sess: &Session, turn_context: &TurnContext, sess.send_event(turn_context, event).await; } -struct McpAppUsageMetadata { - connector_id: Option, - app_name: Option, -} - -async fn maybe_track_codex_app_used( - sess: &Session, - turn_context: &TurnContext, - server: &str, - tool_name: &str, -) { - if server != CODEX_APPS_MCP_SERVER_NAME { - return; - } - let metadata = lookup_mcp_app_usage_metadata(sess, server, tool_name).await; - let (connector_id, app_name) = metadata - .map(|metadata| (metadata.connector_id, metadata.app_name)) - .unwrap_or((None, None)); - let invocation_type = InvocationType::Implicit; - - let tracking = build_track_events_context( - turn_context.model_info.slug.clone(), - sess.conversation_id.to_string(), - turn_context.sub_id.clone(), - ); - sess.services.analytics_events_client.track_app_used( - tracking, - AppInvocation { - connector_id, - app_name, - invocation_type: Some(invocation_type), - }, - ); -} - #[derive(Debug, Clone, PartialEq, Eq)] enum McpToolApprovalDecision { Accept, @@ -646,11 +557,9 @@ pub(crate) struct McpToolApprovalMetadata { tool_title: Option, tool_description: Option, mcp_app_resource_uri: Option, - codex_apps_meta: Option>, openai_file_input_params: Option>, } -const MCP_TOOL_CODEX_APPS_META_KEY: &str = "_codex_apps"; const MCP_TOOL_OPENAI_OUTPUT_TEMPLATE_META_KEY: &str = "openai/outputTemplate"; const MCP_TOOL_UI_RESOURCE_URI_META_KEY: &str = "ui/resourceUri"; const MCP_TOOL_THREAD_ID_META_KEY: &str = "threadId"; @@ -683,8 +592,8 @@ fn custom_mcp_tool_approval_mode( fn build_mcp_tool_call_request_meta( turn_context: &TurnContext, - server: &str, - metadata: Option<&McpToolApprovalMetadata>, + _server: &str, + _metadata: Option<&McpToolApprovalMetadata>, ) -> Option { let mut request_meta = serde_json::Map::new(); @@ -695,16 +604,6 @@ fn build_mcp_tool_call_request_meta( ); } - if server == CODEX_APPS_MCP_SERVER_NAME - && let Some(codex_apps_meta) = - metadata.and_then(|metadata| metadata.codex_apps_meta.clone()) - { - request_meta.insert( - MCP_TOOL_CODEX_APPS_META_KEY.to_string(), - serde_json::Value::Object(codex_apps_meta), - ); - } - (!request_meta.is_empty()).then_some(serde_json::Value::Object(request_meta)) } @@ -763,11 +662,6 @@ const MCP_TOOL_APPROVAL_KIND_MCP_TOOL_CALL: &str = "mcp_tool_call"; const MCP_TOOL_APPROVAL_PERSIST_KEY: &str = "persist"; const MCP_TOOL_APPROVAL_PERSIST_SESSION: &str = "session"; const MCP_TOOL_APPROVAL_PERSIST_ALWAYS: &str = "always"; -const MCP_TOOL_APPROVAL_SOURCE_KEY: &str = "source"; -const MCP_TOOL_APPROVAL_SOURCE_CONNECTOR: &str = "connector"; -const MCP_TOOL_APPROVAL_CONNECTOR_ID_KEY: &str = "connector_id"; -const MCP_TOOL_APPROVAL_CONNECTOR_NAME_KEY: &str = "connector_name"; -const MCP_TOOL_APPROVAL_CONNECTOR_DESCRIPTION_KEY: &str = "connector_description"; const MCP_TOOL_APPROVAL_TOOL_TITLE_KEY: &str = "tool_title"; const MCP_TOOL_APPROVAL_TOOL_DESCRIPTION_KEY: &str = "tool_description"; const MCP_TOOL_APPROVAL_TOOL_PARAMS_KEY: &str = "tool_params"; @@ -1013,9 +907,6 @@ fn session_mcp_tool_approval_key( } let connector_id = metadata.and_then(|metadata| metadata.connector_id.clone()); - if invocation.server == CODEX_APPS_MCP_SERVER_NAME && connector_id.is_none() { - return None; - } Some(McpToolApprovalKey { server: invocation.server.clone(), @@ -1095,7 +986,7 @@ fn mcp_tool_approval_callsite_mode( )] pub(crate) async fn lookup_mcp_tool_metadata( sess: &Session, - turn_context: &TurnContext, + _turn_context: &TurnContext, server: &str, tool_name: &str, ) -> Option { @@ -1109,45 +1000,15 @@ pub(crate) async fn lookup_mcp_tool_metadata( let tool_info = tools .into_values() .find(|tool_info| tool_info.server_name == server && tool_info.tool.name == tool_name)?; - let connector_description = if server == CODEX_APPS_MCP_SERVER_NAME { - let connectors = match connectors::list_cached_accessible_connectors_from_mcp_tools( - turn_context.config.as_ref(), - ) - .await - { - Some(connectors) => Some(connectors), - None => { - connectors::list_accessible_connectors_from_mcp_tools(turn_context.config.as_ref()) - .await - .ok() - } - }; - connectors.and_then(|connectors| { - let connector_id = tool_info.connector_id.as_deref()?; - connectors - .into_iter() - .find(|connector| connector.id == connector_id) - .and_then(|connector| connector.description) - }) - } else { - None - }; Some(McpToolApprovalMetadata { annotations: tool_info.tool.annotations, connector_id: tool_info.connector_id, connector_name: tool_info.connector_name, - connector_description, + connector_description: tool_info.connector_description, tool_title: tool_info.tool.title, tool_description: tool_info.tool.description.map(std::borrow::Cow::into_owned), mcp_app_resource_uri: get_mcp_app_resource_uri(tool_info.tool.meta.as_deref()), - codex_apps_meta: tool_info - .tool - .meta - .as_ref() - .and_then(|meta| meta.get(MCP_TOOL_CODEX_APPS_META_KEY)) - .and_then(serde_json::Value::as_object) - .cloned(), openai_file_input_params: Some(declared_openai_file_input_param_names( tool_info.tool.meta.as_deref(), )) @@ -1175,35 +1036,6 @@ fn get_mcp_app_resource_uri( }) } -#[expect( - clippy::await_holding_invalid_type, - reason = "MCP app metadata reads through the session-owned manager guard" -)] -async fn lookup_mcp_app_usage_metadata( - sess: &Session, - server: &str, - tool_name: &str, -) -> Option { - let tools = sess - .services - .mcp_connection_manager - .read() - .await - .list_all_tools() - .await; - - tools.into_values().find_map(|tool_info| { - if tool_info.server_name == server && tool_info.tool.name == tool_name { - Some(McpAppUsageMetadata { - connector_id: tool_info.connector_id, - app_name: tool_info.connector_name, - }) - } else { - None - } - }) -} - fn build_mcp_tool_approval_question( question_id: String, server: &str, @@ -1242,7 +1074,7 @@ fn build_mcp_tool_approval_question( RequestUserInputQuestion { id: question_id, - header: "Approve app tool call?".to_string(), + header: "Approve MCP tool call?".to_string(), question, is_other: false, is_secret: false, @@ -1259,13 +1091,7 @@ fn build_mcp_tool_approval_fallback_message( .map(str::trim) .filter(|name| !name.is_empty()) .map(ToString::to_string) - .unwrap_or_else(|| { - if server == CODEX_APPS_MCP_SERVER_NAME { - "this app".to_string() - } else { - format!("the {server} MCP server") - } - }); + .unwrap_or_else(|| format!("the {server} MCP server")); format!("Allow {actor} to run tool \"{tool_name}\"?") } @@ -1321,7 +1147,7 @@ fn build_mcp_tool_approval_elicitation_request( } fn build_mcp_tool_approval_elicitation_meta( - server: &str, + _server: &str, metadata: Option<&McpToolApprovalMetadata>, tool_params: Option<&serde_json::Value>, tool_params_display: Option<&[RenderedMcpToolApprovalParam]>, @@ -1372,34 +1198,6 @@ fn build_mcp_tool_approval_elicitation_meta( serde_json::Value::String(tool_description.clone()), ); } - if server == CODEX_APPS_MCP_SERVER_NAME - && (metadata.connector_id.is_some() - || metadata.connector_name.is_some() - || metadata.connector_description.is_some()) - { - meta.insert( - MCP_TOOL_APPROVAL_SOURCE_KEY.to_string(), - serde_json::Value::String(MCP_TOOL_APPROVAL_SOURCE_CONNECTOR.to_string()), - ); - if let Some(connector_id) = metadata.connector_id.as_deref() { - meta.insert( - MCP_TOOL_APPROVAL_CONNECTOR_ID_KEY.to_string(), - serde_json::Value::String(connector_id.to_string()), - ); - } - if let Some(connector_name) = metadata.connector_name.as_ref() { - meta.insert( - MCP_TOOL_APPROVAL_CONNECTOR_NAME_KEY.to_string(), - serde_json::Value::String(connector_name.clone()), - ); - } - if let Some(connector_description) = metadata.connector_description.as_ref() { - meta.insert( - MCP_TOOL_APPROVAL_CONNECTOR_DESCRIPTION_KEY.to_string(), - serde_json::Value::String(connector_description.clone()), - ); - } - } } if let Some(tool_params) = tool_params { meta.insert( @@ -1600,16 +1398,8 @@ async fn maybe_persist_mcp_tool_approval( ) { let tool_name = key.tool_name.clone(); - let persist_result = if key.server == CODEX_APPS_MCP_SERVER_NAME { - let Some(connector_id) = key.connector_id.clone() else { - remember_mcp_tool_approval(sess, key).await; - return; - }; - persist_codex_app_tool_approval(&turn_context.config.codex_home, &connector_id, &tool_name) - .await - } else { - persist_custom_mcp_tool_approval(&turn_context.config, &key.server, &tool_name).await - }; + let persist_result = + persist_custom_mcp_tool_approval(&turn_context.config, &key.server, &tool_name).await; if let Err(err) = persist_result { error!( @@ -1626,26 +1416,6 @@ async fn maybe_persist_mcp_tool_approval( remember_mcp_tool_approval(sess, key).await; } -async fn persist_codex_app_tool_approval( - codex_home: &AbsolutePathBuf, - connector_id: &str, - tool_name: &str, -) -> anyhow::Result<()> { - ConfigEditsBuilder::new(codex_home) - .with_edits([ConfigEdit::SetPath { - segments: vec![ - "apps".to_string(), - connector_id.to_string(), - "tools".to_string(), - tool_name.to_string(), - "approval_mode".to_string(), - ], - value: value("approve"), - }]) - .apply() - .await -} - async fn persist_custom_mcp_tool_approval( config: &Config, server: &str, diff --git a/vendor/codex/codex-rs/core/src/mcp_tool_call_tests.rs b/vendor/codex/codex-rs/core/src/mcp_tool_call_tests.rs index ed355c47..655eea16 100644 --- a/vendor/codex/codex-rs/core/src/mcp_tool_call_tests.rs +++ b/vendor/codex/codex-rs/core/src/mcp_tool_call_tests.rs @@ -5,17 +5,12 @@ use crate::session::tests::make_session_and_context_with_rx; use crate::state::ActiveTurn; use codex_config::CONFIG_TOML_FILE; use codex_config::config_toml::ConfigToml; -use codex_config::types::AppConfig; -use codex_config::types::AppToolConfig; -use codex_config::types::AppToolsConfig; use codex_config::types::ApprovalsReviewer; -use codex_config::types::AppsConfigToml; use codex_config::types::McpServerConfig; use codex_config::types::McpServerToolConfig; use codex_model_provider::create_model_provider; use codex_protocol::protocol::AskForApproval; use codex_protocol::protocol::SandboxPolicy; -use core_test_support::PathExt; use core_test_support::responses::ev_assistant_message; use core_test_support::responses::ev_completed; use core_test_support::responses::ev_response_created; @@ -61,7 +56,6 @@ fn approval_metadata( tool_title: tool_title.map(str::to_string), tool_description: tool_description.map(str::to_string), mcp_app_resource_uri: None, - codex_apps_meta: None, openai_file_input_params: None, } } @@ -223,7 +217,7 @@ async fn approval_elicitation_request_uses_message_override_and_preserves_tool_p let (session, turn_context) = make_session_and_context().await; let question = build_mcp_tool_approval_question( "q".to_string(), - CODEX_APPS_MCP_SERVER_NAME, + "custom_server", "create_event", Some("Calendar"), prompt_options( @@ -236,7 +230,7 @@ async fn approval_elicitation_request_uses_message_override_and_preserves_tool_p &session, &turn_context, McpToolApprovalElicitationRequest { - server: CODEX_APPS_MCP_SERVER_NAME, + server: "custom_server", metadata: Some(&approval_metadata( Some("calendar"), Some("Calendar"), @@ -273,7 +267,7 @@ async fn approval_elicitation_request_uses_message_override_and_preserves_tool_p McpServerElicitationRequestParams { thread_id: session.conversation_id.to_string(), turn_id: Some(turn_context.sub_id), - server_name: CODEX_APPS_MCP_SERVER_NAME.to_string(), + server_name: "custom_server".to_string(), request: McpServerElicitationRequest::Form { meta: Some(serde_json::json!({ MCP_TOOL_APPROVAL_KIND_KEY: MCP_TOOL_APPROVAL_KIND_MCP_TOOL_CALL, @@ -281,10 +275,6 @@ async fn approval_elicitation_request_uses_message_override_and_preserves_tool_p MCP_TOOL_APPROVAL_PERSIST_SESSION, MCP_TOOL_APPROVAL_PERSIST_ALWAYS, ], - MCP_TOOL_APPROVAL_SOURCE_KEY: MCP_TOOL_APPROVAL_SOURCE_CONNECTOR, - MCP_TOOL_APPROVAL_CONNECTOR_ID_KEY: "calendar", - MCP_TOOL_APPROVAL_CONNECTOR_NAME_KEY: "Calendar", - MCP_TOOL_APPROVAL_CONNECTOR_DESCRIPTION_KEY: "Manage events and schedules.", MCP_TOOL_APPROVAL_TOOL_TITLE_KEY: "Create Event", MCP_TOOL_APPROVAL_TOOL_DESCRIPTION_KEY: "Create a calendar event.", MCP_TOOL_APPROVAL_TOOL_PARAMS_KEY: { @@ -329,7 +319,7 @@ fn custom_mcp_tool_question_mentions_server_name() { /*question_override*/ None, ); - assert_eq!(question.header, "Approve app tool call?"); + assert_eq!(question.header, "Approve MCP tool call?"); assert_eq!( question.question, "Allow the custom_server MCP server to run tool \"run_action\"?" @@ -345,29 +335,10 @@ fn custom_mcp_tool_question_mentions_server_name() { } #[test] -fn codex_apps_tool_question_uses_fallback_app_label() { +fn trusted_mcp_tool_question_offers_always_allow() { let question = build_mcp_tool_approval_question( "q".to_string(), - CODEX_APPS_MCP_SERVER_NAME, - "run_action", - /*connector_name*/ None, - prompt_options( - /*allow_session_remember*/ true, /*allow_persistent_approval*/ true, - ), - /*question_override*/ None, - ); - - assert_eq!( - question.question, - "Allow this app to run tool \"run_action\"?" - ); -} - -#[test] -fn trusted_codex_apps_tool_question_offers_always_allow() { - let question = build_mcp_tool_approval_question( - "q".to_string(), - CODEX_APPS_MCP_SERVER_NAME, + "custom_server", "run_action", Some("Calendar"), prompt_options( @@ -400,16 +371,16 @@ fn trusted_codex_apps_tool_question_offers_always_allow() { } #[test] -fn codex_apps_tool_question_without_elicitation_omits_always_allow() { +fn trusted_mcp_tool_question_without_elicitation_omits_always_allow() { let session_key = McpToolApprovalKey { - server: CODEX_APPS_MCP_SERVER_NAME.to_string(), + server: "custom_server".to_string(), connector_id: Some("calendar".to_string()), tool_name: "run_action".to_string(), }; let persistent_key = session_key.clone(); let question = build_mcp_tool_approval_question( "q".to_string(), - CODEX_APPS_MCP_SERVER_NAME, + "custom_server", "run_action", Some("Calendar"), mcp_tool_approval_prompt_options( @@ -492,9 +463,9 @@ fn custom_servers_support_session_and_persistent_approval() { } #[test] -fn codex_apps_connectors_support_persistent_approval() { +fn connector_metadata_can_scope_persistent_approval() { let invocation = McpInvocation { - server: CODEX_APPS_MCP_SERVER_NAME.to_string(), + server: "custom_server".to_string(), tool: "calendar/list_events".to_string(), arguments: None, }; @@ -506,7 +477,7 @@ fn codex_apps_connectors_support_persistent_approval() { /*tool_description*/ None, ); let expected = McpToolApprovalKey { - server: CODEX_APPS_MCP_SERVER_NAME.to_string(), + server: "custom_server".to_string(), connector_id: Some("calendar".to_string()), tool_name: "calendar/list_events".to_string(), }; @@ -603,54 +574,6 @@ async fn mcp_tool_call_request_meta_includes_turn_metadata_for_custom_server() { ); } -#[tokio::test] -async fn codex_apps_tool_call_request_meta_includes_turn_metadata_and_codex_apps_meta() { - let (_, turn_context) = make_session_and_context().await; - let expected_turn_metadata = serde_json::from_str::( - &turn_context - .turn_metadata_state - .current_header_value() - .expect("turn metadata header"), - ) - .expect("turn metadata json"); - let metadata = McpToolApprovalMetadata { - annotations: None, - connector_id: Some("calendar".to_string()), - connector_name: Some("Calendar".to_string()), - connector_description: Some("Manage events".to_string()), - tool_title: Some("Create Event".to_string()), - tool_description: Some("Create a calendar event.".to_string()), - mcp_app_resource_uri: None, - codex_apps_meta: Some( - serde_json::json!({ - "resource_uri": "connector://calendar/tools/calendar_create_event", - "contains_mcp_source": true, - "connector_id": "calendar", - }) - .as_object() - .cloned() - .expect("_codex_apps metadata should be an object"), - ), - openai_file_input_params: None, - }; - - assert_eq!( - build_mcp_tool_call_request_meta( - &turn_context, - CODEX_APPS_MCP_SERVER_NAME, - Some(&metadata), - ), - Some(serde_json::json!({ - crate::X_CODEX_TURN_METADATA_HEADER: expected_turn_metadata, - MCP_TOOL_CODEX_APPS_META_KEY: { - "resource_uri": "connector://calendar/tools/calendar_create_event", - "contains_mcp_source": true, - "connector_id": "calendar", - }, - })) - ); -} - #[test] fn mcp_tool_call_thread_id_meta_is_added_to_request_meta() { assert_eq!( @@ -755,7 +678,7 @@ fn approval_elicitation_meta_merges_session_and_always_persist_for_custom_server #[test] fn guardian_mcp_review_request_includes_invocation_metadata() { let invocation = McpInvocation { - server: CODEX_APPS_MCP_SERVER_NAME.to_string(), + server: "custom_server".to_string(), tool: "browser_navigate".to_string(), arguments: Some(serde_json::json!({ "url": "https://example.com", @@ -778,7 +701,7 @@ fn guardian_mcp_review_request_includes_invocation_metadata() { request, GuardianApprovalRequest::McpToolCall { id: "call-1".to_string(), - server: CODEX_APPS_MCP_SERVER_NAME.to_string(), + server: "custom_server".to_string(), tool_name: "browser_navigate".to_string(), arguments: Some(serde_json::json!({ "url": "https://example.com", @@ -808,7 +731,6 @@ fn guardian_mcp_review_request_includes_annotations_when_present() { tool_title: None, tool_description: None, mcp_app_resource_uri: None, - codex_apps_meta: None, openai_file_input_params: None, }; @@ -838,7 +760,7 @@ fn guardian_mcp_review_request_includes_annotations_when_present() { #[test] fn prepare_arc_request_action_serializes_mcp_tool_call_shape() { let invocation = McpInvocation { - server: CODEX_APPS_MCP_SERVER_NAME.to_string(), + server: "custom_server".to_string(), tool: "browser_navigate".to_string(), arguments: Some(serde_json::json!({ "url": "https://example.com", @@ -860,7 +782,7 @@ fn prepare_arc_request_action_serializes_mcp_tool_call_shape() { action, serde_json::json!({ "tool": "mcp_tool_call", - "server": CODEX_APPS_MCP_SERVER_NAME, + "server": "custom_server", "tool_name": "browser_navigate", "arguments": { "url": "https://example.com", @@ -932,10 +854,10 @@ async fn guardian_review_decision_maps_to_mcp_tool_decision() { } #[test] -fn approval_elicitation_meta_includes_connector_source_for_codex_apps() { +fn approval_elicitation_meta_includes_tool_details_for_mcp_server() { assert_eq!( build_mcp_tool_approval_elicitation_meta( - CODEX_APPS_MCP_SERVER_NAME, + "custom_server", Some(&approval_metadata( Some("calendar"), Some("Calendar"), @@ -953,10 +875,6 @@ fn approval_elicitation_meta_includes_connector_source_for_codex_apps() { ), Some(serde_json::json!({ MCP_TOOL_APPROVAL_KIND_KEY: MCP_TOOL_APPROVAL_KIND_MCP_TOOL_CALL, - MCP_TOOL_APPROVAL_SOURCE_KEY: MCP_TOOL_APPROVAL_SOURCE_CONNECTOR, - MCP_TOOL_APPROVAL_CONNECTOR_ID_KEY: "calendar", - MCP_TOOL_APPROVAL_CONNECTOR_NAME_KEY: "Calendar", - MCP_TOOL_APPROVAL_CONNECTOR_DESCRIPTION_KEY: "Manage events and schedules.", MCP_TOOL_APPROVAL_TOOL_TITLE_KEY: "Run Action", MCP_TOOL_APPROVAL_TOOL_DESCRIPTION_KEY: "Runs the selected action.", MCP_TOOL_APPROVAL_TOOL_PARAMS_KEY: { @@ -967,10 +885,10 @@ fn approval_elicitation_meta_includes_connector_source_for_codex_apps() { } #[test] -fn approval_elicitation_meta_merges_session_and_always_persist_with_connector_source() { +fn approval_elicitation_meta_merges_session_and_always_persist() { assert_eq!( build_mcp_tool_approval_elicitation_meta( - CODEX_APPS_MCP_SERVER_NAME, + "custom_server", Some(&approval_metadata( Some("calendar"), Some("Calendar"), @@ -992,10 +910,6 @@ fn approval_elicitation_meta_merges_session_and_always_persist_with_connector_so MCP_TOOL_APPROVAL_PERSIST_SESSION, MCP_TOOL_APPROVAL_PERSIST_ALWAYS, ], - MCP_TOOL_APPROVAL_SOURCE_KEY: MCP_TOOL_APPROVAL_SOURCE_CONNECTOR, - MCP_TOOL_APPROVAL_CONNECTOR_ID_KEY: "calendar", - MCP_TOOL_APPROVAL_CONNECTOR_NAME_KEY: "Calendar", - MCP_TOOL_APPROVAL_CONNECTOR_DESCRIPTION_KEY: "Manage events and schedules.", MCP_TOOL_APPROVAL_TOOL_TITLE_KEY: "Run Action", MCP_TOOL_APPROVAL_TOOL_DESCRIPTION_KEY: "Runs the selected action.", MCP_TOOL_APPROVAL_TOOL_PARAMS_KEY: { @@ -1102,45 +1016,6 @@ fn accepted_elicitation_without_content_defaults_to_accept() { assert_eq!(response, McpToolApprovalDecision::Accept); } -#[tokio::test] -async fn persist_codex_app_tool_approval_writes_tool_override() { - let tmp = tempdir().expect("tempdir"); - - persist_codex_app_tool_approval(&tmp.path().abs(), "calendar", "calendar/list_events") - .await - .expect("persist approval"); - - let contents = std::fs::read_to_string(tmp.path().join(CONFIG_TOML_FILE)).expect("read config"); - let parsed: ConfigToml = toml::from_str(&contents).expect("parse config"); - - assert_eq!( - parsed.apps, - Some(AppsConfigToml { - default: None, - apps: HashMap::from([( - "calendar".to_string(), - AppConfig { - enabled: true, - destructive_enabled: None, - open_world_enabled: None, - default_tools_approval_mode: None, - default_tools_enabled: None, - tools: Some(AppToolsConfig { - tools: HashMap::from([( - "calendar/list_events".to_string(), - AppToolConfig { - enabled: None, - approval_mode: Some(AppToolApproval::Approve), - }, - )]), - }), - }, - )]), - }) - ); - assert!(contents.contains("[apps.calendar.tools.\"calendar/list_events\"]")); -} - #[tokio::test] async fn persist_custom_mcp_tool_approval_writes_tool_override() { let tmp = tempdir().expect("tempdir"); @@ -1213,45 +1088,6 @@ approval_mode = "prompt" ); } -#[tokio::test] -async fn maybe_persist_mcp_tool_approval_reloads_session_config() { - let (session, turn_context) = make_session_and_context().await; - let codex_home = session.codex_home().await; - std::fs::create_dir_all(&codex_home).expect("create codex home"); - let key = McpToolApprovalKey { - server: CODEX_APPS_MCP_SERVER_NAME.to_string(), - connector_id: Some("calendar".to_string()), - tool_name: "calendar/list_events".to_string(), - }; - - maybe_persist_mcp_tool_approval(&session, &turn_context, key.clone()).await; - - let config = session.get_config().await; - let apps_toml = config - .config_layer_stack - .effective_config() - .as_table() - .and_then(|table| table.get("apps")) - .cloned() - .expect("apps table"); - let apps = AppsConfigToml::deserialize(apps_toml).expect("deserialize apps config"); - let tool = apps - .apps - .get("calendar") - .and_then(|app| app.tools.as_ref()) - .and_then(|tools| tools.tools.get("calendar/list_events")) - .expect("calendar/list_events tool config exists"); - - assert_eq!( - tool, - &AppToolConfig { - enabled: None, - approval_mode: Some(AppToolApproval::Approve), - } - ); - assert_eq!(mcp_tool_approval_is_remembered(&session, &key).await, true); -} - #[tokio::test] async fn maybe_persist_mcp_tool_approval_reloads_session_config_for_custom_server() { let (session, turn_context) = make_session_and_context().await; @@ -1372,7 +1208,6 @@ async fn approve_mode_skips_when_annotations_do_not_require_approval() { tool_title: Some("Read Only Tool".to_string()), tool_description: None, mcp_app_resource_uri: None, - codex_apps_meta: None, openai_file_input_params: None, }; @@ -1444,7 +1279,6 @@ async fn guardian_mode_skips_auto_when_annotations_do_not_require_approval() { tool_title: Some("Read Only Tool".to_string()), tool_description: None, mcp_app_resource_uri: None, - codex_apps_meta: None, openai_file_input_params: None, }; @@ -1519,7 +1353,6 @@ async fn guardian_mode_mcp_denial_returns_rationale_message() { tool_title: Some("Dangerous Tool".to_string()), tool_description: Some("Reads calendar data.".to_string()), mcp_app_resource_uri: None, - codex_apps_meta: None, openai_file_input_params: None, }; @@ -1571,7 +1404,6 @@ async fn prompt_mode_waits_for_approval_when_annotations_do_not_require_approval tool_title: Some("Read Only Tool".to_string()), tool_description: None, mcp_app_resource_uri: None, - codex_apps_meta: None, openai_file_input_params: None, }; @@ -1637,7 +1469,7 @@ async fn approve_mode_blocks_when_arc_returns_interrupt_for_model() { let session = Arc::new(session); let turn_context = Arc::new(turn_context); let invocation = McpInvocation { - server: CODEX_APPS_MCP_SERVER_NAME.to_string(), + server: "custom_server".to_string(), tool: "dangerous_tool".to_string(), arguments: Some(serde_json::json!({ "id": 1 })), }; @@ -1649,7 +1481,6 @@ async fn approve_mode_blocks_when_arc_returns_interrupt_for_model() { tool_title: Some("Dangerous Tool".to_string()), tool_description: Some("Performs a risky action.".to_string()), mcp_app_resource_uri: None, - codex_apps_meta: None, openai_file_input_params: None, }; @@ -1720,7 +1551,6 @@ async fn custom_approve_mode_blocks_when_arc_returns_interrupt_for_model() { tool_title: Some("Dangerous Tool".to_string()), tool_description: Some("Performs a risky action.".to_string()), mcp_app_resource_uri: None, - codex_apps_meta: None, openai_file_input_params: None, }; @@ -1779,7 +1609,7 @@ async fn approve_mode_blocks_when_arc_returns_interrupt_without_annotations() { let session = Arc::new(session); let turn_context = Arc::new(turn_context); let invocation = McpInvocation { - server: CODEX_APPS_MCP_SERVER_NAME.to_string(), + server: "custom_server".to_string(), tool: "dangerous_tool".to_string(), arguments: Some(serde_json::json!({ "id": 1 })), }; @@ -1791,7 +1621,6 @@ async fn approve_mode_blocks_when_arc_returns_interrupt_without_annotations() { tool_title: Some("Dangerous Tool".to_string()), tool_description: Some("Performs a risky action.".to_string()), mcp_app_resource_uri: None, - codex_apps_meta: None, openai_file_input_params: None, }; @@ -1858,7 +1687,7 @@ async fn full_access_mode_skips_arc_monitor_for_all_approval_modes() { let session = Arc::new(session); let turn_context = Arc::new(turn_context); let invocation = McpInvocation { - server: CODEX_APPS_MCP_SERVER_NAME.to_string(), + server: "custom_server".to_string(), tool: "dangerous_tool".to_string(), arguments: Some(serde_json::json!({ "id": 1 })), }; @@ -1870,7 +1699,6 @@ async fn full_access_mode_skips_arc_monitor_for_all_approval_modes() { tool_title: Some("Dangerous Tool".to_string()), tool_description: Some("Performs a risky action.".to_string()), mcp_app_resource_uri: None, - codex_apps_meta: None, openai_file_input_params: None, }; @@ -1964,7 +1792,7 @@ async fn approve_mode_routes_arc_ask_user_to_guardian_when_guardian_reviewer_is_ let session = Arc::new(session); let turn_context = Arc::new(turn_context); let invocation = McpInvocation { - server: CODEX_APPS_MCP_SERVER_NAME.to_string(), + server: "custom_server".to_string(), tool: "dangerous_tool".to_string(), arguments: Some(serde_json::json!({ "id": 1 })), }; @@ -1976,7 +1804,6 @@ async fn approve_mode_routes_arc_ask_user_to_guardian_when_guardian_reviewer_is_ tool_title: Some("Dangerous Tool".to_string()), tool_description: Some("Performs a risky action.".to_string()), mcp_app_resource_uri: None, - codex_apps_meta: None, openai_file_input_params: None, }; diff --git a/vendor/codex/codex-rs/core/src/mcp_tool_exposure.rs b/vendor/codex/codex-rs/core/src/mcp_tool_exposure.rs index 3917a1d5..f4eeb612 100644 --- a/vendor/codex/codex-rs/core/src/mcp_tool_exposure.rs +++ b/vendor/codex/codex-rs/core/src/mcp_tool_exposure.rs @@ -1,14 +1,10 @@ use std::collections::HashMap; -use std::collections::HashSet; use codex_features::Feature; -use codex_mcp::CODEX_APPS_MCP_SERVER_NAME; use codex_mcp::ToolInfo as McpToolInfo; -use codex_mcp::filter_non_codex_apps_mcp_tools_only; use codex_tools::ToolsConfig; use crate::config::Config; -use crate::connectors; pub(crate) const DIRECT_MCP_TOOL_EXPOSURE_THRESHOLD: usize = 100; @@ -19,20 +15,10 @@ pub(crate) struct McpToolExposure { pub(crate) fn build_mcp_tool_exposure( all_mcp_tools: &HashMap, - connectors: Option<&[connectors::AppInfo]>, - explicitly_enabled_connectors: &[connectors::AppInfo], config: &Config, tools_config: &ToolsConfig, ) -> McpToolExposure { - let mut deferred_tools = filter_non_codex_apps_mcp_tools_only(all_mcp_tools); - if let Some(connectors) = connectors { - deferred_tools.extend(filter_codex_apps_mcp_tools( - all_mcp_tools, - connectors, - config, - )); - } - + let deferred_tools = all_mcp_tools.clone(); let should_defer = tools_config.search_tool && (config .features @@ -46,43 +32,12 @@ pub(crate) fn build_mcp_tool_exposure( }; } - let direct_tools = - filter_codex_apps_mcp_tools(all_mcp_tools, explicitly_enabled_connectors, config); - for direct_tool_name in direct_tools.keys() { - deferred_tools.remove(direct_tool_name); - } - McpToolExposure { - direct_tools, + direct_tools: HashMap::new(), deferred_tools: (!deferred_tools.is_empty()).then_some(deferred_tools), } } -fn filter_codex_apps_mcp_tools( - mcp_tools: &HashMap, - connectors: &[connectors::AppInfo], - config: &Config, -) -> HashMap { - let allowed: HashSet<&str> = connectors - .iter() - .map(|connector| connector.id.as_str()) - .collect(); - - mcp_tools - .iter() - .filter(|(_, tool)| { - if tool.server_name != CODEX_APPS_MCP_SERVER_NAME { - return false; - } - let Some(connector_id) = tool.connector_id.as_deref() else { - return false; - }; - allowed.contains(connector_id) && connectors::codex_app_tool_is_enabled(config, tool) - }) - .map(|(name, tool)| (name.clone(), tool.clone())) - .collect() -} - #[cfg(test)] #[path = "mcp_tool_exposure_test.rs"] mod tests; diff --git a/vendor/codex/codex-rs/core/src/mcp_tool_exposure_test.rs b/vendor/codex/codex-rs/core/src/mcp_tool_exposure_test.rs index 3372291d..28a54e4d 100644 --- a/vendor/codex/codex-rs/core/src/mcp_tool_exposure_test.rs +++ b/vendor/codex/codex-rs/core/src/mcp_tool_exposure_test.rs @@ -1,10 +1,8 @@ use std::collections::HashMap; use std::sync::Arc; -use codex_connectors::metadata::sanitize_name; use codex_features::Feature; use codex_features::Features; -use codex_mcp::CODEX_APPS_MCP_SERVER_NAME; use codex_mcp::ToolInfo; use codex_models_manager::manager::ModelsManager; use codex_protocol::config_types::WebSearchMode; @@ -19,45 +17,12 @@ use rmcp::model::Tool; use super::*; use crate::config::test_config; -use crate::connectors::AppInfo; - -fn make_connector(id: &str, name: &str) -> AppInfo { - AppInfo { - id: id.to_string(), - name: name.to_string(), - description: None, - logo_url: None, - logo_url_dark: None, - distribution_channel: None, - branding: None, - app_metadata: None, - labels: None, - install_url: None, - is_accessible: true, - is_enabled: true, - plugin_display_names: Vec::new(), - } -} - -fn make_mcp_tool( - server_name: &str, - tool_name: &str, - connector_id: Option<&str>, - connector_name: Option<&str>, -) -> ToolInfo { - let tool_namespace = if server_name == CODEX_APPS_MCP_SERVER_NAME { - connector_name - .map(sanitize_name) - .map(|connector_name| format!("mcp__{server_name}__{connector_name}")) - .unwrap_or_else(|| server_name.to_string()) - } else { - format!("mcp__{server_name}__") - }; +fn make_mcp_tool(server_name: &str, tool_name: &str) -> ToolInfo { ToolInfo { server_name: server_name.to_string(), callable_name: tool_name.to_string(), - callable_namespace: tool_namespace, + callable_namespace: format!("mcp__{server_name}__"), server_instructions: None, tool: Tool { name: tool_name.to_string().into(), @@ -70,8 +35,8 @@ fn make_mcp_tool( icons: None, meta: None, }, - connector_id: connector_id.map(str::to_string), - connector_name: connector_name.map(str::to_string), + connector_id: None, + connector_name: None, plugin_display_names: Vec::new(), connector_description: None, } @@ -83,9 +48,7 @@ fn numbered_mcp_tools(count: usize) -> HashMap { let tool_name = format!("tool_{index}"); ( format!("mcp__rmcp__{tool_name}"), - make_mcp_tool( - "rmcp", &tool_name, /*connector_id*/ None, /*connector_name*/ None, - ), + make_mcp_tool("rmcp", &tool_name), ) }) .collect() @@ -114,18 +77,12 @@ async fn tools_config_for_mcp_tool_exposure(search_tool: bool) -> ToolsConfig { } #[tokio::test] -async fn directly_exposes_small_effective_tool_sets() { +async fn directly_exposes_small_mcp_tool_sets() { let config = test_config().await; let tools_config = tools_config_for_mcp_tool_exposure(/*search_tool*/ true).await; let mcp_tools = numbered_mcp_tools(DIRECT_MCP_TOOL_EXPOSURE_THRESHOLD - 1); - let exposure = build_mcp_tool_exposure( - &mcp_tools, - /*connectors*/ None, - &[], - &config, - &tools_config, - ); + let exposure = build_mcp_tool_exposure(&mcp_tools, &config, &tools_config); let mut direct_tool_names: Vec<_> = exposure.direct_tools.keys().cloned().collect(); direct_tool_names.sort(); @@ -136,18 +93,12 @@ async fn directly_exposes_small_effective_tool_sets() { } #[tokio::test] -async fn searches_large_effective_tool_sets() { +async fn searches_large_mcp_tool_sets() { let config = test_config().await; let tools_config = tools_config_for_mcp_tool_exposure(/*search_tool*/ true).await; let mcp_tools = numbered_mcp_tools(DIRECT_MCP_TOOL_EXPOSURE_THRESHOLD); - let exposure = build_mcp_tool_exposure( - &mcp_tools, - /*connectors*/ None, - &[], - &config, - &tools_config, - ); + let exposure = build_mcp_tool_exposure(&mcp_tools, &config, &tools_config); assert!(exposure.direct_tools.is_empty()); let deferred_tools = exposure @@ -162,55 +113,7 @@ async fn searches_large_effective_tool_sets() { } #[tokio::test] -async fn directly_exposes_explicit_apps_without_deferred_overlap() { - let config = test_config().await; - let tools_config = tools_config_for_mcp_tool_exposure(/*search_tool*/ true).await; - let mut mcp_tools = numbered_mcp_tools(DIRECT_MCP_TOOL_EXPOSURE_THRESHOLD - 1); - mcp_tools.extend([( - "mcp__codex_apps__calendar_create_event".to_string(), - make_mcp_tool( - CODEX_APPS_MCP_SERVER_NAME, - "calendar_create_event", - Some("calendar"), - Some("Calendar"), - ), - )]); - let connectors = vec![make_connector("calendar", "Calendar")]; - - let exposure = build_mcp_tool_exposure( - &mcp_tools, - Some(connectors.as_slice()), - connectors.as_slice(), - &config, - &tools_config, - ); - - let mut tool_names: Vec = exposure.direct_tools.into_keys().collect(); - tool_names.sort(); - assert_eq!( - tool_names, - vec!["mcp__codex_apps__calendar_create_event".to_string()] - ); - assert_eq!( - exposure.deferred_tools.as_ref().map(HashMap::len), - Some(DIRECT_MCP_TOOL_EXPOSURE_THRESHOLD - 1) - ); - let deferred_tools = exposure - .deferred_tools - .as_ref() - .expect("large tool sets should be discoverable through tool_search"); - assert!( - tool_names - .iter() - .all(|direct_tool_name| !deferred_tools.contains_key(direct_tool_name)), - "direct tools should not also be deferred: {tool_names:?}" - ); - assert!(!deferred_tools.contains_key("mcp__codex_apps__calendar_create_event")); - assert!(deferred_tools.contains_key("mcp__rmcp__tool_0")); -} - -#[tokio::test] -async fn always_defer_feature_preserves_explicit_apps() { +async fn always_defer_feature_defers_all_mcp_tools_uniformly() { let mut config = test_config().await; config .features @@ -218,42 +121,21 @@ async fn always_defer_feature_preserves_explicit_apps() { .expect("test config should allow feature update"); let tools_config = tools_config_for_mcp_tool_exposure(/*search_tool*/ true).await; let mcp_tools = HashMap::from([ + ("mcp__rmcp__tool".to_string(), make_mcp_tool("rmcp", "tool")), ( - "mcp__rmcp__tool".to_string(), - make_mcp_tool( - "rmcp", "tool", /*connector_id*/ None, /*connector_name*/ None, - ), - ), - ( - "mcp__codex_apps__calendar_create_event".to_string(), - make_mcp_tool( - CODEX_APPS_MCP_SERVER_NAME, - "calendar_create_event", - Some("calendar"), - Some("Calendar"), - ), + "mcp__custom__calendar_create_event".to_string(), + make_mcp_tool("custom", "calendar_create_event"), ), ]); - let connectors = vec![make_connector("calendar", "Calendar")]; - let exposure = build_mcp_tool_exposure( - &mcp_tools, - Some(connectors.as_slice()), - connectors.as_slice(), - &config, - &tools_config, - ); + let exposure = build_mcp_tool_exposure(&mcp_tools, &config, &tools_config); - let mut direct_tool_names: Vec = exposure.direct_tools.into_keys().collect(); - direct_tool_names.sort(); - assert_eq!( - direct_tool_names, - vec!["mcp__codex_apps__calendar_create_event".to_string()] - ); + assert!(exposure.direct_tools.is_empty()); let deferred_tools = exposure .deferred_tools .as_ref() .expect("MCP tools should be discoverable through tool_search"); + assert_eq!(deferred_tools.len(), 2); assert!(deferred_tools.contains_key("mcp__rmcp__tool")); - assert!(!deferred_tools.contains_key("mcp__codex_apps__calendar_create_event")); + assert!(deferred_tools.contains_key("mcp__custom__calendar_create_event")); } diff --git a/vendor/codex/codex-rs/core/src/session/mcp.rs b/vendor/codex/codex-rs/core/src/session/mcp.rs index c3f81913..9b98cc4f 100644 --- a/vendor/codex/codex-rs/core/src/session/mcp.rs +++ b/vendor/codex/codex-rs/core/src/session/mcp.rs @@ -208,8 +208,6 @@ impl Session { mcp_servers: HashMap, store_mode: OAuthCredentialsStoreMode, ) { - let auth = self.services.auth_manager.auth().await; - let config = self.get_config().await; let auth_statuses = compute_auth_statuses(mcp_servers.iter(), store_mode).await; { let mut guard = self.services.mcp_startup_cancellation_token.lock().await; @@ -231,8 +229,6 @@ impl Session { .unwrap_or_else(|| self.services.environment_manager.local_environment()), turn_context.cwd.to_path_buf(), ), - config.codex_home.to_path_buf(), - codex_apps_tools_cache_key(auth.as_ref()), ToolPluginProvenance::default(), ) .await; diff --git a/vendor/codex/codex-rs/core/src/session/mod.rs b/vendor/codex/codex-rs/core/src/session/mod.rs index 34094cb2..c25777a8 100644 --- a/vendor/codex/codex-rs/core/src/session/mod.rs +++ b/vendor/codex/codex-rs/core/src/session/mod.rs @@ -57,7 +57,6 @@ use codex_mcp::McpConnectionManager; use codex_mcp::McpRuntimeEnvironment; use codex_mcp::ToolInfo; use codex_mcp::ToolPluginProvenance; -use codex_mcp::codex_apps_tools_cache_key; #[cfg(test)] use codex_models_manager::collaboration_mode_presets::CollaborationModesConfig; use codex_models_manager::manager::ModelsManager; diff --git a/vendor/codex/codex-rs/core/src/session/session.rs b/vendor/codex/codex-rs/core/src/session/session.rs index a9bdeea7..ca628413 100644 --- a/vendor/codex/codex-rs/core/src/session/session.rs +++ b/vendor/codex/codex-rs/core/src/session/session.rs @@ -850,8 +850,6 @@ impl Session { .unwrap_or_else(|| sess.services.environment_manager.local_environment()), session_configuration.cwd.to_path_buf(), ), - config.codex_home.to_path_buf(), - codex_apps_tools_cache_key(auth), ToolPluginProvenance::default(), ) .instrument(info_span!( diff --git a/vendor/codex/codex-rs/core/src/session/turn.rs b/vendor/codex/codex-rs/core/src/session/turn.rs index 1470bca9..0fcffa08 100644 --- a/vendor/codex/codex-rs/core/src/session/turn.rs +++ b/vendor/codex/codex-rs/core/src/session/turn.rs @@ -868,8 +868,6 @@ pub(crate) async fn built_tools( drop(mcp_connection_manager); let mcp_tool_exposure = build_mcp_tool_exposure( &all_mcp_tools, - None, - &[], &turn_context.config, &turn_context.tools_config, );