Repository navigation
feat(mcp): add event_options to MCP capture calls and instrument - #1206
Merged
Merged
Conversation
The PostHogMCP capture_* methods and McpAnalytics.capture take a keyword-only event_options argument, and MCPAnalyticsOptions gains an event_options callback, called for the same events as event_properties. Per-call options win over the callback's key by key, and an event without an identity still always sends process_person_profile: False. A non-dict value is logged and ignored. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Covers the per-call argument and the callback, why context options set inside a tool handler miss $mcp_tool_call, copying options in MCP before_send, and the options vs event_options split on PostHogMCP. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
marandaneto
approved these changes
Nov 9, 2026
marandaneto
left a comment
Member
There was a problem hiding this comment.
The code looks good; no qualifying findings. Verdict: correct.
* feat(celery): propagate context options to workers Publish context options in an X-POSTHOG-CONTEXT-OPTIONS task header, next to the tags header, and set them as context options on the worker before the task started event. propagate_context=False sends none. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs(celery): point eager tasks to explicit PostHog headers Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat(ai): take capture options in the AI integrations (#1208) * feat(ai): take capture options in the AI integrations Every AI wrapper method that takes posthog_properties also takes posthog_options, and the Gemini clients take it as a per-client default. LangChain's CallbackHandler and PostHogMiddleware, and the OpenAI Agents and Claude Agent SDK instrument() and processors, take options=. LangChain also reads posthog_options from run metadata. The wrappers never pass posthog_options to the provider. The options are sent as the event's own options, below the personless process_person_profile: False. A value that is not a dict is logged and ignored, and no options argument is passed when none are set. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(ai): send LangChain exception events with the run's options Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs(migration): simplify the 8.0 checklist and MCP hook note Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(ai): pass exception options as a typed keyword Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.
💡 Motivation and Context
MCP events had no way to carry capture options: the MCP capture methods took no options, and
instrument()had no hook for them. This addsevent_options, named so it does not clash with the existinginstrument(..., options=MCPAnalyticsOptions).Stacked on #1202.
PostHogMCP.capture_tool_call,capture_initialize,capture_tools_list,capture_missing_capability,capture_feedbackandMcpAnalytics.capturetake a keyword-onlyevent_optionsdict.MCPAnalyticsOptions.event_options(added last, so positional construction still works) is a(request, extra)callback, sync or async, called for the same auto-captured events asevent_properties, including the$exceptionsibling.process_person_profile: False.PostHogMCP.capture()keeps the core client'soptions=. The docstrings, migration guide and MCP README say which takes which.$mcp_tool_call, copyingoptionsin MCPbefore_send), and the MCP README gets an Event options section.💚 How did you test it?
New parameterized tests cover per-call options on every capture method, the callback on every auto-capture call site (sync and async, identified and anonymous), the precedence rules, non-dict and raising callbacks,
before_sendseeing the merged options, and the v1 wire payload. They fail without the source change and pass with it. The MCP suite andtest_client.pypass on mcp 1.30 and mcp 2.3. ruff, mypy and the public API check pass. The full suite has three fork tests that also fail on macOS without this change.📝 Checklist
If releasing new changes
sampo addto generate a changeset file (minor changeset written by hand)🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Claude Code, Claude Opus 5.5. The API name and precedence were set by the maintainer. Through the public API, per-call options and the callback never apply to the same event today: the callback runs only for auto-captured events, and per-call options exist only on the capture methods. The builder still merges them in the agreed order, and a pipeline test covers it.
🤖 Generated with Claude Code