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.
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 theproxyToolName 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
proxyToolfiltering for clarity. - Avoid mutations in hooks; keep them side-effect free when possible.