Recognize MCP tool hook configurations (#37363)

## What changed

- Parse `mcp_tool` hook handlers with a server, tool, JSON input, and optional timeout and status message.
- Return managed MCP tool hooks from `configRequirements/read` and include the handler in the generated protocol schemas.
- Skip MCP tool hooks during discovery with an explicit warning until execution is supported.

## Testing

- Cover MCP tool hook deserialization, including nested and null JSON input values.
- Extend the config requirements RPC test to verify the new handler shape.

GitOrigin-RevId: ff7e2d12b75b486c54d63469af547a29f9b31418
This commit is contained in:
Abhinav authored and copyberry committed 2026-08-07 03:30:29 +00:00
1 parent 5bdc889708
commit 81b9bc2109
14 files changed
+278 -10

No files matched your search

+40
View File
@@ -56,6 +56,46 @@ fn hooks_file_deserializes_existing_json_shape() {
);
}
#[test]
fn hooks_file_deserializes_mcp_tool_handler_with_json_inputs() {
let parsed: HooksFile = serde_json::from_value(serde_json::json!({
"hooks": {
"PostToolUse": [{
"matcher": "Write|Edit",
"hooks": [{
"type": "mcp_tool",
"server": "security",
"tool": "scan",
"input": {
"file_path": "${tool_input.file_path}",
"optional": null,
},
"timeout": 30,
"statusMessage": "Scanning file",
}],
}],
},
}))
.expect("MCP tool hooks should deserialize");
assert_eq!(
parsed.hooks.post_tool_use[0].hooks,
vec![HookHandlerConfig::McpTool {
server: "security".to_string(),
tool: "scan".to_string(),
input: serde_json::Map::from_iter([
(
"file_path".to_string(),
serde_json::Value::String("${tool_input.file_path}".to_string()),
),
("optional".to_string(), serde_json::Value::Null),
]),
timeout_sec: Some(30),
status_message: Some("Scanning file".to_string()),
}]
);
}
#[test]
fn hooks_file_rejects_events_outside_hooks_object() {
let error = serde_json::from_str::<HooksFile>(