MCPcat allows you to identify users and associate their sessions with specific user information. This lets you to track usage patterns, understand user behavior, and provide personalized experiences. User identification happens automatically when a tool is invoked. In stateful mode (the default), this happens once on the first tool call and persists for the session. In stateless mode, it runs on every request since there is no persistent session.Documentation Index
Fetch the complete documentation index at: https://docs.mcpcat.io/llms.txt
Use this file to discover all available pages before exploring further.
Basic Implementation
To identify users, provide anidentify callback function when tracking your MCP server. The simplest approach is to pull the user ID directly from the tool call arguments:
User Identity Object
The identify function should return aUserIdentity object with the following structure:
Common Patterns
Token-Based Authentication
Extract user information from authentication tokens:API Key Identification
Identify users based on API keys:MCP Authentication
For servers using MCP’s built-in authentication:Error Handling
Handle identification failures gracefully:Function Parameters
The identify function receives parameters that vary between the TypeScript, Python, and Go SDKs:The request structure follows the MCP (Model Context Protocol) specification. The specific types and fields available depend on your SDK:
- TypeScript: Uses the MCP TypeScript SDK
- Python: Uses the MCP Python SDK
- Go: Uses the official Go MCP SDK or mark3labs/mcp-go
request
The MCP request object following the JSON-RPC format:TypeScript: extra
The MCP RequestHandlerExtra object providing additional context:Python: context
The MCP RequestContext object providing session and client information:In stateless mode,
context.session still exists but represents the per-request context rather than a long-lived session. The clientInfo fields are extracted from HTTP headers on each request.Python Authentication Access: In Python MCP servers, authentication tokens are accessed via the
get_access_token() function from mcp.server.auth.middleware.auth_context, not through the context parameter. This is different from the TypeScript SDK where auth info is available in the extra parameter.Go: ctx and req
The Go SDK identify function receivescontext.Context and *mcp.CallToolRequest:
Go Authentication Access: In Go MCP servers, authentication information is typically extracted from the
context.Context parameter. The exact method depends on your authentication middleware and MCP library.Common Usage Patterns
Important Considerations
Stateful servers (default): The identify function is called once per session on the first tool invocation. This minimizes overhead while ensuring consistent user tracking throughout the session.Stateless servers: The identify function is called on every request since there is no persistent session. Keep your identify function lightweight — avoid expensive API calls or database lookups if possible. Without identification, stateless events cannot be grouped into sessions.
Anonymous Sessions
If you don’t provide an identify function or if it returnsnull, sessions will be tracked anonymously. This is useful for:
- Public APIs where user identification isn’t required
- Development and testing environments
- Respecting user privacy preferences