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
Higher priority runs first for Will/Stage; Did runs in reverse order
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 determines execution order. Higher priority runs first for Will/Stage hooks, and last for Did hooks.
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: High priority (90-100)
- Transformation: Medium priority (40-60)
- Logging/Metrics: Low priority (1-20)
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