Identifying users
By default, the SDK attributes events to a generated session ID (ses_…), not to a person. Use identify to associate calls with a person.
How attribution works
For each event, the SDK picks distinct_id in this order:
- The distinct ID returned by your
identifycallback, if it returned an identity. - The MCP session id (
ses_…). - The literal string
"anonymous".
Before identify returns a user, events use the session ID. Later events use the user ID. See Events before identification for what happens to the earlier events.
Anonymous sessions and person profiles
Events for sessions with no resolved identity are sent with person processing turned off. This keeps anonymous MCP sessions from each creating a person profile (which would inflate your person count and billing). Once identify resolves an identity for a session, person processing stays on and the events create/update that user's profile as normal.
Configure identify
identify (WithIdentity in Go) is a callback that returns an identity or nothing. It runs on each request. In TypeScript, Python, and Ruby, identify can also be a static identity instead of a callback, and the SDK caches the result per session.
Each example reads the request headers its own way. See your language's installation page for details. In TypeScript and Python, use getRequestHeaders or get_request_headers. Reading extra directly can return nothing, and every call goes anonymous.
An identity has three fields, named in each language's style:
- The distinct ID becomes the event's
distinct_id. - Person properties are written to
$set, such as name, email, or plan.$setupdates the person profile but isn't kept on the stored event, so query these as person properties. - Groups, a map of group type to group key, are added to every event as
$groups.
The TypeScript, Python, Go, and Rust SDKs don't send a standalone $identify event. The Ruby SDK still sends one when the identity for a session changes.
Events before identification
An MCP session can emit events before authentication completes. For example, $mcp_initialize may occur before you identify the user. These events keep the session ID as distinct_id, without a person profile.
No SDK sets $anon_distinct_id, so PostHog doesn't merge these earlier events into the person. Resolve identity as early as you can, ideally on the first request of the session, so all of a session's events reach the person.
When not to call identify
- Internal tools without per-user auth. If your MCP server doesn't authenticate end users (e.g. a single-tenant internal server behind a VPN), leave
identifyunset. Session-scoped attribution is fine. - Bots and crawlers. Returning a junk identity for unauthenticated traffic dilutes your person count. Return
nullfor traffic you can't identify. Those events stay session-scoped. In every SDK except Go and Rust, if an earlier request in the same session was identified, the SDK keeps that identity.
Querying by identified user
Once identification is wired up, anything that filters on person.properties.* or groups by distinct_id works as expected:





