Skip to main content

Overview

Integrate MCPcat with PostHog for product analytics. Events are sent as capture events via the PostHog /batch API, giving you full visibility into MCP tool usage within your existing PostHog dashboards.

Prerequisites

  1. A PostHog project with an API key (starts with phc_...)
  2. Your PostHog host URL (default: https://us.i.posthog.com)

Configuration

mcpcat.track(server, null, {
  exporters: {
    posthog: {
      type: "posthog",
      apiKey: process.env.POSTHOG_API_KEY,
      host: "https://us.i.posthog.com"
    }
  }
})

Configuration Fields

FieldTypeRequiredDescription
api_key / apiKeystringYesYour PostHog project API key (starts with phc_...)
hoststringNoPostHog host URL (default: https://us.i.posthog.com). Use https://eu.i.posthog.com for EU, or your own URL for self-hosted.

Field Mapping

Event Names

MCPcat events are sent as PostHog capture events. Standard MCP event types are mapped to PostHog-friendly names. Any unmapped event types fall back to replacing colons and slashes with underscores.
MCP Event TypePostHog Event Name
mcp:tools/callmcp_tool_call
mcp:tools/listmcp_tools_list
mcp:initializemcp_initialize
mcp:resources/readmcp_resource_read
mcp:resources/listmcp_resources_list
mcp:prompts/getmcp_prompt_get
mcp:prompts/listmcp_prompts_list

Distinct ID

PostHog’s distinct_id is set using the following priority:
  1. Identified user ID — if the user was identified via the identify callback
  2. Session ID — falls back to the MCPcat session ID
  3. "anonymous" — if neither is available

Event Properties

Each event includes the following properties:
PropertyDescription
$session_idMCPcat session ID
resource_nameResource or tool name
tool_nameTool name (only for tool call events)
duration_msEvent duration in milliseconds
server_nameMCP server name
server_versionMCP server version
client_nameAI client name (e.g., “Claude Desktop”)
client_versionAI client version
project_idMCPcat project ID
user_intentAgent’s stated intent for the tool call
is_errorWhether the event was an error
parametersRequest parameters
responseTool response data

Person Properties

When a user is identified, PostHog person properties are set via $set:
  • name — the identified user’s name
  • Any additional fields from identifyActorData are merged in

Error Events

When is_error is true, MCPcat sends two events to PostHog:
  1. Regular capture event — the standard event with all properties above
  2. $exception event — a native PostHog exception event with:
PropertyDescription
$exception_messageError message
$exception_typeError type or class
$exception_stacktraceStack trace (when available)
$exception_source"backend" — marks this as a server error
This ensures errors appear in PostHog’s native error tracking and can trigger alerts.