Hook Types
FlowHooksOf
Create typed hook decorators for a specific flow:Available Flows
@Will (Before Hook)
Execute before a flow stage:Priority
Lower priority values execute first:Filter
Conditionally execute hooks:@Did (After Hook)
Execute after a flow stage:@Around (Wrapper Hook)
Wrap stage execution for full control. The stage’s Will hooks run first,next() runs the stage itself, and its Did hooks run after the Around hook returns. An Around hook that does not call next() skips the stage. With several Around hooks on one stage, each next() runs the next one, and the innermost runs the stage. For tools:call-tool, the tool’s result is ctx.state.required.toolContext.output.
@Stage (Custom Stage)
Define custom flow stages:Hook Options
tools/call, resources/read, prompts/get and
completion/complete, only for that app’s entries. With appliesTo: 'uncovered-apps' it also runs for the entries of
any app that has no instance of the same hook (same class and method) of its own or from a server-level plugin. Use it
for gates that an entry’s metadata asks for, so the entry is not left ungated when the plugin sits on another app.
Registering Hooks
In Apps
In Plugins
On an Entry Class
A hook declared on a@Tool, @Resource, @Prompt or @Agent class runs only for that entry, on the instance created for each call:
tools:call-tool, resources:read-resource, prompts:get-prompt, completion:complete), including the ones its adapters and plugins provide, such as the tools an OpenAPI adapter generates. Plugins registered on the server (@FrontMcp({ plugins })) apply to every app. Resources and prompts the server serves outside every app, such as the SEP-2640 skill:// resources, run every app’s hooks.
Hook Context
Hooks receive flow context with access to:Error Handling
A hook that throws stops the flow, and the error reaches the client like an error from the stage itself. An Around hook sees a failing stage as a rejectednext(). It can rethrow, retry by calling next() again, or catch the rejection and return normally. Returning normally handles the failure: the stage counts as successful, so set the output the stage would have produced first. An Around hook skipped by its filter still runs the stage:
Full Example
Related
HookRegistry
Hook registry API
Flow Types
Flow type definitions
@Plugin
Create plugins
Customize Flows
Flow customization guide