Documentation
¶
Overview ¶
Package posthogmcp instruments servers built with the official MCP Go SDK and emits PostHog's canonical MCP analytics events.
Portions of this file are derived from agentcathq/agentcat-typescript-sdk (formerly MCPCat/mcpcat-typescript-sdk), licensed under the MIT License.
Index ¶
Constants ¶
const ( EventCustom = "$mcp_custom" EventException = "$exception" EventIdentify = "$identify" EventInitialize = "$mcp_initialize" EventMissingCapability = "$mcp_missing_capability" EventPromptGet = "$mcp_prompt_get" EventPromptsList = "$mcp_prompts_list" EventResourceRead = "$mcp_resource_read" EventResourcesList = "$mcp_resources_list" EventToolCall = "$mcp_tool_call" EventToolsList = "$mcp_tools_list" )
const ( PropertyClientName = "$mcp_client_name" PropertyAnonDistinctID = "$anon_distinct_id" PropertyClientUserAgent = "$mcp_client_user_agent" PropertyClientVersion = "$mcp_client_version" PropertyConversationID = "$mcp_conversation_id" PropertyDurationMS = "$mcp_duration_ms" PropertyErrorMessage = "$mcp_error_message" PropertyErrorType = "$mcp_error_type" PropertyIsError = "$mcp_is_error" PropertyIntent = "$mcp_intent" PropertyIntentSource = "$mcp_intent_source" PropertyListedToolNames = "$mcp_listed_tool_names" PropertyParameters = "$mcp_parameters" PropertyProtocolVersion = "$mcp_protocol_version" PropertyResourceName = "$mcp_resource_name" PropertyResponse = "$mcp_response" PropertyServerName = "$mcp_server_name" PropertyServerVersion = "$mcp_server_version" PropertySessionID = "$session_id" PropertySource = "$mcp_source" PropertyToolCategory = "$mcp_tool_category" PropertyToolDescription = "$mcp_tool_description" PropertyToolName = "$mcp_tool_name" PropertyVendorClient = "$mcp_vendor_client" )
const ( Source = "posthog_mcp_analytics" SDKLanguage = "go" Version = "0.1.0" DefaultMissingCapabilityToolName = "get_more_tools" )
const DefaultContextDescription = `` /* 532-byte string literal not displayed */
const DefaultConversationIDDescription = "" /* 180-byte string literal not displayed */
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Analytics ¶
type Analytics struct {
// contains filtered or unexported fields
}
Analytics is a concurrency-safe MCP analytics middleware and custom capture handle.
func New ¶
func New(client posthog.EnqueueClient, options *Options) *Analytics
New constructs analytics. A nil client produces disabled pass-through instrumentation.
func (*Analytics) Capture ¶
func (a *Analytics) Capture(ctx context.Context, name string, properties map[string]any) (err error)
Capture records a custom event. Disabled analytics treats capture as a no-op.
func (*Analytics) Middleware ¶
func (a *Analytics) Middleware() mcp.Middleware
Middleware returns receiving middleware for mcp.Server.AddReceivingMiddleware.
type BeforeSendFunc ¶
BeforeSendFunc can modify or drop an event immediately before enqueue.
type Event ¶
type Event struct {
UUID string
Event string
DistinctID string
Timestamp time.Time
Properties posthog.Properties
Groups posthog.Groups
}
Event is the mutable event shape supplied to BeforeSend.
type EventPropertiesFunc ¶
EventPropertiesFunc supplies properties attached to every automatic event.
type IdentifyFunc ¶
IdentifyFunc resolves the identity associated with an MCP request.
type Identity ¶
type Identity struct {
DistinctID string
Properties posthog.Properties
Groups posthog.Groups
}
Identity is the resolved PostHog identity for one MCP caller.
type IntentFallbackFunc ¶
IntentFallbackFunc infers user intent when no analytics-owned context is supplied.
type Options ¶
type Options struct {
Logger *slog.Logger
Identify IdentifyFunc
IntentFallback IntentFallbackFunc
EventProperties EventPropertiesFunc
BeforeSend BeforeSendFunc
DisableContextInjection bool
ContextDescription string
ReportMissing bool
MissingCapabilityToolName string
EnableConversationID bool
DisableExceptionAutocapture bool
}
Options configures MCP analytics behavior.