Skip to main content
The TypeScript SDK wraps servers built with the official MCP TypeScript SDK or Mastra. It captures sessions and tool calls without changing how your server behaves.

Install

The SDK declares @modelcontextprotocol/sdk as a peer dependency. If your tools use Zod 4 raw-shape schemas, use MCP SDK 1.29 or later — 1.20 silently drops fields added to Zod 4 raw shapes.

Set your API key

The SDK reads your key from the environment:
Create a key in the dashboard, then add it to your deployment secrets. If the key is missing, the SDK quietly no-ops — your server keeps working, and no data is sent.

Wrap your server

If you build your server in a factory function, wrap the factory with createMcpAnalyticsServer. Every tool registered inside is instrumented automatically:
server.ts
That’s the whole integration. Deploy, and sessions appear in the dashboard within minutes.

Other server shapes

If you already have an McpServer instance and a list of tool definitions, instrument them in place:
If you handle tools/list and tools/call yourself, use the recorder directly:
Wrap a Mastra tool map with the dedicated adapter:
The adapter reads MCP request context from context.mcp.extra or context.requestContext.get("mcp.extra") automatically.
Running on serverless or stateless HTTP? See Stateless & serverless servers for session handling, and set delivery: "await" so events are sent before the function freezes.

Configuration

Pass options under the armature key:

Flush on shutdown

With background delivery, drain pending events before the process exits:

Troubleshooting

Fixed in current releases — update the SDK. Older versions crashed when a tool declared a Zod 4 raw-shape schema while the SDK injected its telemetry field with Zod 3.
Make sure @modelcontextprotocol/sdk is 1.29+. Version 1.20 silently drops fields the SDK adds to Zod 4 raw-shape schemas, so agents never see them.
Check that ANALYTICS_INGEST_API_KEY is set in the server’s environment (missing keys no-op silently by design) and add an onError handler to surface delivery failures.