Add MCP tool handler support to the hooks engine (#38705)

## What changed

- Discover synchronous `mcp_tool` hook handlers and invoke their configured MCP server and tool through a supplied executor.
- Expand nested hook-event placeholders in MCP tool inputs while preserving JSON types, and process tool output through the existing hook output contract.
- Represent hook details as handler-specific metadata in `hooks/list`, including MCP server and tool fields, and show those details in the TUI hooks browser.
- Skip unsupported `SessionEnd` MCP hooks and runtimes without MCP invocation support with startup warnings.

## Testing

- Cover argument expansion, missing placeholders, MCP invocation and hook decisions, discovery warnings, `hooks/list` metadata, and TUI rendering.

GitOrigin-RevId: 295b845471fe92bd7ad7cd272fbcd2c3713912e0
This commit is contained in:
Abhinav authored and copyberry committed 2026-08-15 05:53:54 +00:00
1 parent 3685a61dad
commit 85fc4def35
33 files changed
+1351 -182

No files matched your search

+22
View File
@@ -0,0 +1,22 @@
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 {
pub server: String,
pub tool: String,
pub input: Map<String, Value>,
pub timeout: Duration,
}
/// Executes already-connected 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<String>>;
}