mirror of
https://github.com/openai/codex.git
synced 2026-11-26 23:40:43 +00:00
## Why MCP hook results were flattened to text, so `SessionStart` hooks could not pass encrypted context to the model as encrypted tool output. ## What changed Recognize text blocks marked with `codex/encryptedContent` in synchronous MCP `SessionStart` hooks. Send them to the model as standalone `function_call_output` items with the originating tool name and namespace. Keep ciphertext out of hook previews and plaintext spill files. Reject empty encrypted blocks and cap the serialized encrypted output at 40,000 bytes per hook run. ## Testing Add a scenario that checks that ciphertext above the plaintext spill threshold reaches the first model request unchanged, appears once after a cold resume, and stays out of hook previews and spill files. Cover discarding encrypted context when hook output fails JSON parsing under both failure policies. GitOrigin-RevId: cbc11c6f7055cc131212c6e9ddd37a882ed61d38
35 lines
1.3 KiB
Rust
35 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 original response returned by an MCP hook and the callable namespace that supplied it.
|
|
pub struct HookMcpOutput {
|
|
pub result: codex_protocol::mcp::CallToolResult,
|
|
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 {
|
|
/// Preserves MCP content metadata so the hook runner can interpret the result.
|
|
fn execute(&self, call: HookMcpCall) -> BoxFuture<'_, anyhow::Result<HookMcpOutput>>;
|
|
}
|