Fired BEFORE the agent invokes a registered client tool. Listeners can veto
the dispatch by setting event.Cancel = true — AgentClientSession
short-circuits, the tool handler does NOT run, afterToolInvoked does NOT
fire, and the server receives a failure response carrying the optional
CancelReason.
Example: Confirm before a destructive tool runs
onBeforeToolInvoked(event: BeforeToolInvokedEventArgs) { if (event.ToolName === 'deleteRecord') { if (!confirm('Agent wants to delete a record. Allow?')) { event.Cancel = true; event.CancelReason = 'User declined deletion'; } } }
Fired BEFORE the agent invokes a registered client tool. Listeners can veto the dispatch by setting
event.Cancel = true—AgentClientSessionshort-circuits, the tool handler does NOT run,afterToolInvokeddoes NOT fire, and the server receives a failure response carrying the optionalCancelReason.Example: Confirm before a destructive tool runs