Skip to content

Add is_reconnection field to mcp_session_started event#137

Open
korenaren wants to merge 1 commit intoansible:mainfrom
korenaren:korenaren/add-is-reconnection-field
Open

Add is_reconnection field to mcp_session_started event#137
korenaren wants to merge 1 commit intoansible:mainfrom
korenaren:korenaren/add-is-reconnection-field

Conversation

@korenaren
Copy link

Summary

  • Adds is_reconnection boolean field to mcp_session_started telemetry events
  • Tracks recent users by user_unique_id at the AnalyticsService level with a 1-hour reconnection window
  • Same user starting a new session within the window → is_reconnection: true; otherwise false
  • Stale entries cleaned up during existing periodic status reporting (every 30 min)
  • Validation plugin updated to accept the new optional boolean field

Fixes AAP-67154 — the 10:1 ratio of mcp_session_started to mcp_tool_called events is caused by reconnection churn and toolset multiplier effects. This field lets Amplitude filter out reconnection noise without changing session timeout or routing behavior.

Test plan

  • All 230 existing tests pass (npx vitest run)
  • 4 new reconnection detection tests (first session, repeat session, different tokens, expired window)
  • 4 new validation plugin tests (true, false, omitted, non-boolean rejected)

🤖 Generated with Claude Code

Track whether a session is a reconnection by checking if the same
user_unique_id had a session within a 1-hour window. This lets
Amplitude filter out reconnection noise from the 10:1 session-to-tool
ratio (AAP-67154).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
const lastSeen = this.recentUsers.get(userUniqueId);
const isReconnection =
lastSeen !== undefined && now - lastSeen < this.RECONNECTION_WINDOW;
this.recentUsers.set(userUniqueId, now);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depending on the toolset, pne singe user can be connected multiple times. In the situation where the user connect to several toolsets, isReconnect will be true for all but the first connection.

Also, we can have the situation where a user is using two different MCP clients at the same time, eg VSCode and Claude Code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants