Observability

PostHog

Instrument MCP tool calls with PostHog through bitmcp/analytics/posthog.

Use this when you want tool-call analytics in PostHog. bitmcp wires the official @posthog/mcp instrumentation into your MCP server. Nothing is sent unless you add posthog() to config.

Install peer dependencies

pnpm add posthog-node @posthog/mcp

Set environment variables

POSTHOG_PROJECT_API_KEY=phc_...

Optional: POSTHOG_HOST for self-hosted PostHog. bitmcp also reads POSTHOG_KEY if the project API key is stored under that name.

Configure bitmcp

bitmcp.config.ts
import { defineConfig } from "bitmcp";
import { posthog } from "bitmcp/analytics/posthog";

export default defineConfig({
  analytics: posthog({
    apiKey: process.env.POSTHOG_PROJECT_API_KEY,
  }),
});

Or rely on env resolution with no options:

bitmcp.config.ts
export default defineConfig({
  analytics: posthog(),
});

Verify events

pnpm dev

Call a tool from the preview or an MCP client. Confirm tool-call events appear in PostHog.

bitmcp does not phone home. Analytics runs only when you configure a plugin. No telemetry is enabled by default.

Reference

What gets instrumented

posthog() uses @posthog/mcp to capture MCP server activity, including tool calls. When OAuth is enabled, the default identify hook uses ctx.user.id as the distinct id. Otherwise events use a request-scoped anonymous id, not a session cookie.

Options

FieldDescription
apiKeyPostHog project API key. Falls back to POSTHOG_KEY or POSTHOG_PROJECT_API_KEY
hostPostHog ingest host. Falls back to POSTHOG_HOST
clientCustom PostHog client for tests
contextInclude MCP context in events (default true)
enableExceptionAutocaptureCapture server exceptions (default true)
beforeSendFilter or mutate events before capture
eventPropertiesExtra properties per event
identifyOverride distinct id resolution

See bitmcp/analytics/posthog types for the full surface.

Config placement

analytics accepts one plugin or an array. PostHog is the built-in adapter today:

bitmcp.config.ts
analytics: posthog({ apiKey: process.env.POSTHOG_PROJECT_API_KEY });

Other config fields: Package exports.