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/mcpSet 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
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:
export default defineConfig({
analytics: posthog(),
});Verify events
pnpm devCall 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
| Field | Description |
|---|---|
apiKey | PostHog project API key. Falls back to POSTHOG_KEY or POSTHOG_PROJECT_API_KEY |
host | PostHog ingest host. Falls back to POSTHOG_HOST |
client | Custom PostHog client for tests |
context | Include MCP context in events (default true) |
enableExceptionAutocapture | Capture server exceptions (default true) |
beforeSend | Filter or mutate events before capture |
eventProperties | Extra properties per event |
identify | Override 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:
analytics: posthog({ apiKey: process.env.POSTHOG_PROJECT_API_KEY });Other config fields: Package exports.