withWaniwani(server) instruments an MCP server so every tool call emits a tool.called event with duration, status, input, and output. One line, no changes inside your tool handlers.
Usage
server/src/index.ts
client option, withWaniwani creates one internally via waniwani(), which reads WANIWANI_API_KEY from the environment.
What gets tracked
Every tool invocation produces atool.called event containing:
| Field | Description |
|---|---|
name | Registered tool name |
type | Category derived from the toolType option |
durationMs | Handler execution time |
status | "ok" or "error" |
errorMessage | Present when the handler threw or returned isError |
input | Tool arguments |
output | Handler response |
clientName | MCP client name (for example chatgpt, claude) |
clientVersion | MCP client version |
sessionId | Correlated from _meta (see Sessions) |
{ isError: true }) are tracked and then re-thrown or returned unchanged, so your tool’s error contract is preserved.
Options
The client used for tracking. Defaults to
waniwani(), which picks up WANIWANI_API_KEY from the environment.Classify tools into dashboard buckets:
"pricing", "product_info", "availability", "support", or "other". Accepts a literal or a function that maps a tool name to a type.Extra fields merged into every
tool.called event. Use this to tag deployments, tenants, or releases.Force a flush after every tool call. Turn this on in serverless runtimes where the process may be frozen between invocations. Leave it off for long-running Node processes.
Inject a short-lived widget tracking token into tool responses under
_meta.waniwani, so browser widgets can post events directly to WaniWani without a proxy route. Leave enabled unless you need to disable token minting.Callback for non-fatal tracking errors. Tracking failures never block tool execution; use this callback when you want visibility into them.
Custom events inside tools
For anything beyondtool.called, call client.track() from inside a handler. Pass meta: extra._meta so the event is linked to the active MCP session.
Also supported
- Session-scoped client in flows. Inside a flow node,
ctx.waniwaniis a scoped client that auto-attaches session correlation, so you can callctx.waniwani.track({ event, properties })without passingmeta. - Widget metadata forwarding. Widget
_metadeclared on a tool definition (Skybridge’sregisterWidget, rawui/resourceUri, OpenAI’sopenai/outputTemplate) is copied onto each tool result, so chat UIs that only see tool results can still render widgets.