Skip to main content
Hooks allow you to intercept and modify tool execution at specific lifecycle stages. Use hooks to add cross-cutting concerns like validation, logging, auditing, rate limiting, and data transformation without modifying individual tools.

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

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 execution
  • metrics - Timing and performance data
  • logger - 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

Retrieves all hooks registered for a specific flow.

Example: Owner-Scoped Hook Filtering

The Hook Registry API is an advanced feature primarily intended for framework developers and complex plugin authors. Most users should use the decorator-based approach (@ToolHook, @HttpHook, etc.) instead.

Best Practices

Package related hooks into plugins to reuse across multiple apps:
  • Validation: High priority (90-100)
  • Transformation: Medium priority (40-60)
  • Logging/Metrics: Low priority (1-20)
This ensures validation runs before transformation, and logging captures everything.
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

Plugin Documentation

Learn more about FrontMCP plugins

Tool Documentation

Understand tool lifecycle and execution

Cache Plugin

See hooks in action with the Cache Plugin