Files
codex/codex-rs/hooks/src/mcp.rs
T
jif f993175205 Add policy-checked dispatch for bundled App hooks (#62080)
## What changed

Carry an expected connector identity on hook MCP calls and add a bundled App dispatch path that requires the host Apps server, a matching connector, and current policy permitting execution without user approval.

Prepare hook calls from the current Apps client catalog, including app-only tools, without exposing those tools to the model or starting unrelated required servers. Refresh session MCP state before preparation and recheck admission before dispatch so configuration changes and logout invalidate stale calls. Never retry a dispatched call.

## Testing

Add coverage for refreshed approval and enablement policies, connector mismatches, app-only tool visibility, preparation without unrelated server startup, and admission invalidation on refresh or logout.

GitOrigin-RevId: 965dd7f79baa40d1be0e158e47b2679d8ba98fe5
2026-11-17 16:56:34 +00:00

36 lines
1.3 KiB
Rust

use std::time::Duration;
use futures::future::BoxFuture;
use serde_json::Map;
use serde_json::Value;
/// One MCP tool call requested by a configured hook handler.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct HookMcpCall {
/// A bundled REPL cleanup may skip a private local transport whose startup was never requested.
pub skip_dormant_repl_cleanup: bool,
/// Exact bundled App identity; executors must enforce live connector and approval policy.
pub expected_app_connector_id: Option<&'static str>,
pub server: String,
pub tool: String,
pub environment_id: Option<String>,
pub metadata: Option<Map<String, Value>>,
pub input: Map<String, Value>,
pub timeout: Duration,
}
/// The MCP hook's text, structured result, and originating callable namespace.
pub struct HookMcpOutput {
pub text: String,
pub structured_content: Option<serde_json::Value>,
pub source_tool_namespace: Option<String>,
}
/// Executes MCP tools on behalf of hooks without coupling this crate to core.
///
/// Implementations own server readiness, policy enforcement, timeout handling, and elicitation.
pub trait HookMcpExecutor: Send + Sync {
/// Returns text that is interpreted using ordinary command-hook output semantics.
fn execute(&self, call: HookMcpCall) -> BoxFuture<'_, anyhow::Result<HookMcpOutput>>;
}