Core Concepts
Flows
Named execution pipelines with defined stages (e.g.,
tools:call-tool, http:request)Hook Types
Will (before), Did (after), Around (wrap), Stage (replace)
Priority
Within a stage, a lower priority runs first, for Will, Did and Stage hooks alike
Context
Shared state object passed through all stages, allowing data flow between hooks
Hook Types
- Will (Before)
- Did (After)
- Around (Wrap)
- Stage (Replace)
Runs before a stage executes. Use for:
- Input validation
- Pre-processing
- Short-circuiting execution
- Setting up context
Available Flows
FrontMCP provides pre-defined hooks for common flows:You can also create custom flows using
FlowHooksOf('custom-flow-name') for application-specific pipelines.Complete Examples
Example 1: Request Validation & Auditing
Example 2: Error Handling & Retries
Example 3: Data Transformation Pipeline
Priority System
Priority sets the order within a stage: a lower priority runs first, for Will, Did and Stage hooks alike. Hooks with the same priority run in the order they were registered.
-1000). To run a Did hook after everything else, give it a very high one (1000).
Flow Context
The flow context (FlowCtxOf<'flow-name'>) contains:
state- Shared state between hooks (tool, toolContext, request, response, etc.)error- Any error that occurred during executionmetrics- Timing and performance datalogger- Logger instance for this flow
Hook Registry API
For advanced use cases, you can programmatically access and manage hooks using the Hook Registry API. This is useful when building custom flow orchestration or when you need to dynamically query which hooks are registered.Accessing the Hook Registry
Registry Methods
- getFlowHooks
- getFlowHooksForOwner
- getFlowStageHooks
- getClsHooks
Retrieves all hooks registered for a specific flow.
Example: Owner-Scoped Hook Filtering
Best Practices
1. Use Plugins for Reusable Hooks
1. Use Plugins for Reusable Hooks
Package related hooks into plugins to reuse across multiple apps:
2. Set Appropriate Priorities
2. Set Appropriate Priorities
- Validation: Low priority (1-20)
- Transformation: Medium priority (40-60)
- Logging/Metrics (Did hooks): High priority (90-100)
3. Handle Errors Gracefully
3. Handle Errors Gracefully
4. Use Context for Data Sharing
4. Use Context for Data Sharing
5. Avoid Heavy Computation in Hooks
5. Avoid Heavy Computation in Hooks
Hooks run for every tool execution. Keep them fast:
- Use caching for expensive operations
- Delegate heavy work to background jobs
- Consider async/non-blocking operations
Links & Resources
Plugin Documentation
Learn more about FrontMCP plugins
Tool Documentation
Understand tool lifecycle and execution
Cache Plugin
See hooks in action with the Cache Plugin