Go MCP Analytics installation
The Go SDK is in beta. It has the same defaults as the other SDKs, but captures fewer events and has fewer optional features. See Limits.
posthogmcpsdk instruments servers built on the official Go MCP SDK (github.com/modelcontextprotocol/go-sdk) v1.6.1 or later. Use go-sdk v1.8.0 or later in your own go.mod to serve protocol 2026-07-28 and input_required rounds. It ships in the posthog-go repository as its own module, so your app only depends on the MCP SDK if it uses this package.
You need Go 1.25+, posthogmcpsdk v2.0.0 or later, and a PostHog project token. Using a server that isn't built on go-sdk? See Custom dispatchers.
The wizard installs the package and adds posthogmcpsdk.Instrument for you. To install by hand, follow the steps below.
- 1
Install the package
RequiredTerminalEarlier releases lack some options and events on this page.
- 2
Wrap your server
RequiredCall
posthogmcpsdk.Instrumentonce, before the server accepts requests:GoWithServerInfoadds your server's name and version to each event. - 3
Close the client on shutdown
Requiredposthog-gosends events in batches.client.Close()sends queued events, so make sure it runs before the process exits. Thedeferabove does this whenmainreturns. If you stop the process from a signal handler, callclient.Close()there. - 4
Check your first events
RequiredConnect an agent to your server and call a tool. Then open the activity feed and filter for
event = $mcp_tool_call. See the event reference for every property.
Identify the caller
Use WithIdentity to attach a person and groups to each call. go-sdk gives you the HTTP headers and any verified OAuth token in req.Extra:
An error from the resolver doesn't change the MCP response. The SDK sends the event without identity and reports the error to your WithErrorHandler.
Sessions
Every event has a $session_id. See session resolution. Stateless HTTP has no transport session, so the SDK uses conversation IDs. A client that ignores the handle gets a new session per request, so use WithIdentity to group those calls by user.
Configuration
| Option | Default | What it does |
|---|---|---|
WithServerInfo(name, version) | – | Adds the server name and version to each event. |
WithContextParameter(bool) | true | Adds a required context argument to capture agent intent. The SDK removes it before your handler and go-sdk's input validation run. |
WithCaptureModel(bool) | true | Captures the calling model from client metadata, or from a required llm_model argument the SDK adds. |
WithConversationID(bool) | true | Adds an optional conversation_id argument to group calls across requests. When it mints a handle, it appends a last {"conversation_id": ...} text block to the result. |
WithIntentFallback(fallback) | – | func(ctx, req) (string, error). Supplies intent, with $mcp_intent_source "inferred", when the agent sends no context. The agent's own context always wins. |
WithIdentity(resolver) | – | Maps a call to a person and groups. See Identify the caller. |
WithProperties(resolver) | – | Adds properties to each $mcp_tool_call and its $exception. The resolver also receives the result and the handler's error. |
WithEventOptions(resolver) | – | Sets event options on each $mcp_tool_call and its $exception. |
WithMissingCapabilityTool(name) | off | Adds the get_more_tools virtual tool. Agents call it to report a capability your server lacks. The call sends $mcp_missing_capability, not $mcp_tool_call. An empty name uses get_more_tools. |
WithCaptureParameters(bool) | true | Captures the tool arguments as $mcp_parameters. |
WithCaptureResponses(bool) | true | Captures the tool result as $mcp_response. A failed call's error text is captured either way. |
WithErrorHandler(handler) | no-op | Receives instrumentation errors. Its errors and panics never change the MCP response. |
To stop the $exception event for failed calls, pass posthogmcp.WithExceptionAutocapture(false) to posthogmcp.New. To change or drop events before they're sent, use BeforeSend in your posthog.Config. See Privacy.
The adapter's WithErrorHandler default is a no-op, but the posthog-go client logs to stderr by default. Set Config.Logger to change that.
A tool that declares its own context, llm_model, or conversation_id argument keeps it. Schemas built from $ref, allOf, anyOf, or oneOf, and schemas with a non-object type or non-object properties, get no added arguments.
Event options
Set event options, such as cookieless_mode or process_person_profile, with WithEventOptions. Its resolver returns posthog.Options for each $mcp_tool_call and its $exception:
Report missing capabilities
Add WithMissingCapabilityTool to give agents a get_more_tools tool to report what your server lacks. The option is off by default.
A server that registers no tools must still declare the tools capability. Without it, clients never list tools and never see get_more_tools:
Middleware order
Receiving middleware you add before Instrument runs inside the measured duration, and middleware you add after it runs outside. To place it yourself, install both halves of NewMiddleware:
Custom dispatchers
For a server that isn't built on go-sdk, use the posthogmcp package directly. CaptureToolCall builds the same $mcp_tool_call event, with the same redaction and size limits:
A call with neither SessionID nor ConversationID gets a new ses_ plus UUIDv7 session, and distinct_id falls back to it. Pass a stable SessionID or ConversationID to group calls. ToolCall also takes ConversationID, LLMModel with LLMModelSource, ClientUserAgent, VendorClient, ErrorType, and EventOptions for event options. EventContext takes EventOptions for the other events.
This path has no prepare steps. You strip any injected arguments and manage sessions and conversation handles yourself. If Intent comes from an argument, remove it from Parameters.
Three more methods capture calls that are not tool calls:
Limits
The Go SDK doesn't yet have:
$mcp_tools_list,$mcp_initialize, resource, and prompt events- Task handling





