Skip to main content
Unified events provide targeted observation without wrapping every request. They are best for focused events like auditing a single server, capturing diagnostics for specific tools, and observing session lifecycle. If you need to enforce policy for all tool calls, use Middleware.

When to use hooks

  • You only care about a single server or a small subset of tools.
  • You want audit logs without changing the control flow.
  • You want lightweight metrics without blocking requests.

Tool success event

Filtered event

Server-scoped event

Available filters

  • server: match the upstream server name.
  • tool: match the original tool name.
  • proxyTool: match the prefixed tool name.
Hooks run before middleware and can return a tool result to short-circuit the call. Legacy proxy.on("call", ...) hooks are still supported for compatibility. Use middleware or tool routes for runtime control, and use tool:start, tool:success, tool:error, tool:after, tools:list:after, session:start, and session:end for observation.

Use hooks for audits

Use hooks for metrics

Combine hooks with middleware

Hooks can collect data while middleware enforces policy. This lets you capture metrics without blocking the request.

Debugging hooks

If a hook is not firing, verify the filter values and check the proxyToolName from logs. Most issues are due to mismatched prefixes.

Best practices

  • Use hooks for observation, middleware for control.
  • Keep hook handlers fast and non-blocking.
  • Prefer proxyTool filtering for clarity.
  • Avoid mutations in hooks; keep them side-effect free when possible.