MCP analytics
Contents
@posthog/mcp is a TypeScript SDK for instrumenting Model Context Protocol (MCP) servers with PostHog analytics. It's published on npm as a 0.1.x release while we build it in public. The API, event names, properties, and tracing behavior may change before the SDK reaches 1.0. Don't depend on it for production reporting yet. Today, only TypeScript MCP servers are supported — a Python SDK is on the roadmap.
MCP analytics helps you understand how AI agents actually use the MCP server you ship: which tools get called, how often, what intent the agent had, where calls are failing, what tools the agent asked for but you don't offer yet, and how individual sessions flow end to end.
The SDK wraps your existing MCP server and emits PostHog events on every tool call, resource read, prompt fetch, and initialize handshake. You can keep using whatever tooling you already have on top of PostHog — insights, dashboards, alerts, error tracking — without any additional ingestion plumbing.
There isn't an "MCP analytics" scene in PostHog yet. Today you query and visualize MCP events through the surfaces you already use: Product analytics for trends and funnels, the SQL editor for ad-hoc HogQL, Dashboards for at-a-glance views, and Error tracking for $exception events. A purpose-built UI is on the roadmap — when it ships, the events on this page won't change shape.
What you can answer
- Which tools is each MCP client calling, and how often?
- What is the agent actually trying to do (
$mcp_intent)? - Which tools are advertised in
tools/listresponses but never get called? - What's the error rate and p95 latency of a given tool?
- Did an agent hit
get_more_toolsbecause the right capability didn't exist? - How does a single MCP session unfold across tool calls?
{/ TODO: ProductScreenshot of an MCP analytics dashboard showing tool call volume, error rate, latency, and intent samples /}
How it works
instrument(server, posthog, options?) patches your MCP server's request handlers and returns an analytics handle. The posthog client (a posthog-node instance) is a required positional argument. When the agent calls a tool, the SDK:
- Builds a structured event with the tool name, parameters, response, duration, and error state.
- Runs the payload through sanitization (image/audio/binary stubs, sensitive-key masking), truncation, and your optional
beforeSendhook. - Sends it to PostHog via the
posthog-nodeclient you pass in, batched and flushed by that client.
Your tool handlers are untouched. The only payload change the agent sees is an optional injected context argument (see Capturing agent intent) and an optional injected conversation_id argument (see Conversation IDs).
Quick install
That's the minimum. With this in place, every tools/call, tools/list, initialize, resources/read, and prompts/get request emits a PostHog event prefixed with $mcp_*.
Where to go next
- Getting started — the guided onboarding flow
- Installation — full setup, server type variants, BYO PostHog client
- Custom servers —
PostHogMCPfor hono/edge dispatchers with no server object to wrap - Capturing agent intent — the
contextargument andintentFallback - Conversation IDs — stitching multi-turn conversations together
- Identifying users — attaching events to your own users
- Missing capability tracking — the
get_more_toolsvirtual tool - Custom events and metadata —
analytics.capture()andeventProperties - Privacy and redaction — what's sanitized automatically, customer redaction hook
- Event and property reference — every event the SDK emits and what's on it
- Sample queries — HogQL recipes for the most common dashboards
Building in public
The SDK source lives in the posthog-js monorepo alongside the rest of PostHog's JavaScript and TypeScript SDKs. Issues, PRs, and feedback are welcome. We started from a duplicated copy of the MIT-licensed MCPcat TypeScript SDK — the event schema, identity model, and feature surface have since diverged.