feat(mcp): Track report_user_action from MCP separately if it's from the wizard#49196
Merged
feat(mcp): Track report_user_action from MCP separately if it's from the wizard#49196
report_user_action from MCP separately if it's from the wizard#49196Conversation
…ution When an MCP client identifies itself with a user agent containing "posthog/foo" (e.g. "posthog/wizard"), extract this identifier and append it to the MCP server's outgoing user agent string, producing e.g. "posthog/mcp-server; version: 1.0.0; for posthog/wizard". Also adds WIZARD to the EventSource enum and detects "posthog/wizard" in get_event_source, checked before the MCP check since the forwarded UA contains both strings. https://claude.ai/code/session_01AJEWnwWhZPuugRrFz9MgQ1
Contributor
There was a problem hiding this comment.
Pull request overview
This PR implements client identifier tracking to enable source attribution for requests from different MCP clients (e.g., PostHog Wizard). The system extracts client identifiers from incoming User-Agent headers and forwards them in outgoing API requests.
Changes:
- Added client identifier extraction from User-Agent headers and propagation through request context
- Updated User-Agent headers in outgoing API requests to include the originating client identifier
- Added WIZARD event source classification in the Python event tracking system
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| services/mcp/src/mcp.ts | Added clientIdentifier to RequestProperties type and ApiClient configuration |
| services/mcp/src/lib/constants.ts | Created getUserAgent() function to format User-Agent with optional client identifier |
| services/mcp/src/index.ts | Implemented regex extraction of client identifier from incoming User-Agent header |
| services/mcp/src/api/fetcher.ts | Updated to use getUserAgent() function with client identifier in API requests |
| services/mcp/src/api/client.ts | Updated ApiConfig type and User-Agent header construction to support client identifier |
| posthog/event_usage.py | Added WIZARD event source enum value and detection logic in get_event_source() |
Comments suppressed due to low confidence (2)
services/mcp/src/index.ts:208
- The regex pattern
/posthog\/(\S+)/will match and capture everything after 'posthog/' until the first whitespace, which could include unwanted characters like semicolons, commas, or version numbers. For example, 'posthog/wizard;version:1.0' would capture 'wizard;version:1.0'. Consider using/posthog\/([a-z0-9-]+)/ito capture only alphanumeric characters and hyphens, which is more appropriate for identifier matching.
const clientIdentifierMatch = clientUserAgent.match(/posthog\/(\S+)/)
services/mcp/src/index.ts:209
- Using
clientIdentifierMatch[0]returns the entire matched string (e.g., 'posthog/wizard'), but you're capturing a group with parentheses. If you want just the identifier part without the 'posthog/' prefix, useclientIdentifierMatch[1]to access the first capture group. If you want to keep 'posthog/' in the identifier, the capturing group is unnecessary.
const clientIdentifierMatch = clientUserAgent.match(/posthog\/(\S+)/)
const clientIdentifier = clientIdentifierMatch ? clientIdentifierMatch[0] : undefined
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
|
🎭 Playwright report · View test results →
These issues are not necessarily caused by your changes. |
…es error - Regex now uses [\w-]+ (alphanumeric, underscore, hyphen) instead of \S+ to avoid capturing stray punctuation from user agent strings. - Add explicit `| undefined` to ApiConfig.clientIdentifier to satisfy exactOptionalPropertyTypes. https://claude.ai/code/session_01AJEWnwWhZPuugRrFz9MgQ1
report_user_action from MCP separately if it's from the wizard
vdekrijger
approved these changes
Feb 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
See PostHog/wizard#291
Problem
We need to track which client is making requests to the MCP server (e.g., PostHog Wizard) for better source attribution and analytics. Currently, we extract the client identifier from the User-Agent header but don't forward it in outgoing API requests.
Changes
posthog/fooidentifier from incoming User-Agent headers in the MCP request handlerposthog/mcp-server; for posthog/wizard)WIZARDevent source to the Python event tracking system to properly categorize requests from PostHog Wizardget_event_source()to detect and classify wizard requests based on User-AgentHow did you test this code?
The changes are straightforward data flow modifications:
Existing tests should continue to pass as this is additive functionality that doesn't break existing behavior.
Publish to changelog?
No
https://claude.ai/code/session_01AJEWnwWhZPuugRrFz9MgQ1