analytics

package
v1.20.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 27, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package analytics implements PostHog MCP Analytics event capture for the PipeOps MCP server (Go). Official @posthog/mcp is TS/Python-only; we emit the same $mcp_* wire contract so project dashboards (e.g. project 15061) work without a language rewrite.

See https://posthog.com/docs/mcp-analytics/events

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseGlobal

func CloseGlobal() error

CloseGlobal closes the process-wide client.

func NewSessionID

func NewSessionID() string

NewSessionID mints a ses_<32hex> id matching the TS SDK shape.

func SessionIDFromMCP

func SessionIDFromMCP(raw string) string

SessionIDFromMCP normalizes an MCP protocol session id into analytics form.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client captures MCP protocol events into PostHog.

func Get

func Get() *Client

Get returns the process-wide client (may be disabled/no-op).

func InitFromEnv

func InitFromEnv() (*Client, error)

InitFromEnv configures the process-wide analytics client. Enabled when POSTHOG_API_KEY or POSTHOG_PROJECT_API_KEY is set (unless POSTHOG_MCP_ANALYTICS=false).

Env:

  • POSTHOG_API_KEY / POSTHOG_PROJECT_API_KEY — project API key (phc_…)
  • POSTHOG_HOST — https://us.i.posthog.com or https://eu.i.posthog.com
  • POSTHOG_PROJECT_ID — optional (e.g. 15061) stamped on events for filtering
  • POSTHOG_MCP_ANALYTICS — set to "false"/"0"/"off" to disable even with a key

func (*Client) CaptureInitialize

func (c *Client) CaptureInitialize(sessionID, clientName, clientVersion, protocolVersion, distinctID string)

CaptureInitialize records $mcp_initialize.

func (*Client) CaptureToolCall

func (c *Client) CaptureToolCall(ev ToolCallEvent)

CaptureToolCall records $mcp_tool_call (and optional $exception sibling).

func (*Client) CaptureToolsList

func (c *Client) CaptureToolsList(sessionID, clientName, clientVersion, protocolVersion, distinctID string, toolNames []string)

CaptureToolsList records $mcp_tools_list.

func (*Client) Close

func (c *Client) Close() error

Close flushes and shuts down the PostHog client.

func (*Client) Enabled

func (c *Client) Enabled() bool

Enabled reports whether events will be sent.

type ToolCallEvent

type ToolCallEvent struct {
	SessionID       string
	ClientName      string
	ClientVersion   string
	ProtocolVersion string
	DistinctID      string
	ToolName        string
	ToolDescription string
	Parameters      map[string]interface{}
	Response        interface{}
	DurationMs      int64
	IsError         bool
	ErrorMessage    string
	Intent          string
	IntentSource    string // "context_parameter" | "inferred"
}

ToolCallEvent is the payload for a tools/call capture.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL