Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .sampo/changesets/mcp-interface-server-events.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
pypi/posthog: patch
---

Set `$mcp_interface` to `mcp` on events from MCP servers.
7 changes: 5 additions & 2 deletions posthog/mcp/_posthog_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ def build_posthog_capture_events(


def _build_capture_event(event: Event) -> PostHogCaptureEvent:
properties: Dict[str, Any] = {_P.SOURCE: POSTHOG_MCP_ANALYTICS_SOURCE}
properties: Dict[str, Any] = {
_P.INTERFACE: "mcp",
_P.SOURCE: POSTHOG_MCP_ANALYTICS_SOURCE,
}
_add_session_id(event, properties)
_add_conversation_id(event, properties)
_add_person_processing(event, properties)
Expand Down Expand Up @@ -260,7 +263,7 @@ def _add_server_build(event: Event, properties: Dict[str, Any]) -> None:


def _build_exception_event(event: Event) -> PostHogCaptureEvent:
properties: Dict[str, Any] = {}
properties: Dict[str, Any] = {_P.INTERFACE: "mcp"}
_add_session_id(event, properties)
_add_conversation_id(event, properties)
_add_person_processing(event, properties)
Expand Down
1 change: 1 addition & 0 deletions posthog/mcp/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class PostHogMCPAnalyticsProperty:
FEEDBACK_TASK_COMPLETED = "$mcp_feedback_task_completed"
FEEDBACK_TOOL = "$mcp_feedback_tool"
FEEDBACK_TYPE = "$mcp_feedback_type"
INTERFACE = "$mcp_interface"
IS_ERROR = "$mcp_is_error"
INTENT = "$mcp_intent"
INTENT_SOURCE = "$mcp_intent_source"
Expand Down
2 changes: 2 additions & 0 deletions posthog/test/mcp/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,7 @@ def test_build_tool_call_event_properties():
props = capture["properties"]
assert capture["event"] == PostHogMCPAnalyticsEvent.TOOL_CALL
assert capture["distinct_id"] == "ses_abc"
assert props[PostHogMCPAnalyticsProperty.INTERFACE] == "mcp"
assert props[PostHogMCPAnalyticsProperty.SOURCE] == POSTHOG_MCP_ANALYTICS_SOURCE
assert props[PostHogMCPAnalyticsProperty.TOOL_NAME] == "search_events"
assert props[PostHogMCPAnalyticsProperty.TOOL_CATEGORY] == "Logs"
Expand Down Expand Up @@ -912,6 +913,7 @@ def test_protocol_version_on_primary_and_exception_events():
# Both the primary $mcp_tool_call and the $exception sibling carry it.
assert len(captures) == 2
for capture in captures:
assert capture["properties"][PostHogMCPAnalyticsProperty.INTERFACE] == "mcp"
assert (
capture["properties"][PostHogMCPAnalyticsProperty.PROTOCOL_VERSION]
== "2025-06-18"
Expand Down
1 change: 1 addition & 0 deletions references/public_api_snapshot.txt
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,7 @@ attribute posthog.mcp.constants.PostHogMCPAnalyticsProperty.INPUT_ALIASES_USED =
attribute posthog.mcp.constants.PostHogMCPAnalyticsProperty.INPUT_KEYS = '$mcp_input_keys'
attribute posthog.mcp.constants.PostHogMCPAnalyticsProperty.INTENT = '$mcp_intent'
attribute posthog.mcp.constants.PostHogMCPAnalyticsProperty.INTENT_SOURCE = '$mcp_intent_source'
attribute posthog.mcp.constants.PostHogMCPAnalyticsProperty.INTERFACE = '$mcp_interface'
attribute posthog.mcp.constants.PostHogMCPAnalyticsProperty.IS_ERROR = '$mcp_is_error'
attribute posthog.mcp.constants.PostHogMCPAnalyticsProperty.LISTED_TOOL_NAMES = '$mcp_listed_tool_names'
attribute posthog.mcp.constants.PostHogMCPAnalyticsProperty.LLM_MODEL = '$mcp_llm_model'
Expand Down
Loading