Skip to main content
The smallest possible end-to-end example: one tool, full instrumentation, graceful shutdown, no safety check.

server.ts

Run

What this demonstrates

Auto span on every call

Each call to calculate-bmi produces a tools/call calculate-bmi span with full attribute set.

Error attributes

The RangeError on bad input sets error.type, error.message, and mcp.operation.success: false.

Auto metrics

mcp.server.operation.duration and mcp.server.operation.count record automatically.

Graceful shutdown

SIGINT / SIGTERM trigger telemetry.shutdown() so the final metric batch flushes.

Trying error attribution

Send heightM: 0 and you’ll see a span with status ERROR and these attributes:
The duration histogram is still recorded with mcp.operation.success: false, which is what you want for error-rate alerts.