Skip to content

feat(mcp): read Claude, Cursor and OpenAI hosted connector conversation ids - #1315

Open
lucasheriques wants to merge 1 commit into
lucas/mcp-client-meta-sessionfrom
lucas/mcp-client-conversation-rows
Open

lucasheriques wants to merge 1 commit into
lucas/mcp-client-meta-sessionfrom
lucas/mcp-client-conversation-rows

Conversation

@lucasheriques

@lucasheriques lucasheriques commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Why

MCP servers listed in the ChatGPT and Claude directories must turn off the injected conversation_id argument. Their sessions then survive only if the SDK reads the client's own conversation id. On PostHog's own MCP server, openai-mcp/1.0.0 sends openai/session on every call but misses the ChatGPT-only rule, Claude.ai sends com.anthropic/session on most calls, and Cursor sends gen_ai.conversation.id on nearly all of them.

What

Three rows join the client conversation table, matching sdk-specs "Session identity" (PostHog/sdk-specs#261). First recognizing row wins, rules ignore case:

# Client _meta key Id Recognized when Handle
1 ChatGPT openai/session printable ChatGPT User-Agent none
2 Other OpenAI (new) openai/session printable UA starts openai-mcp/ fallback
3 Codex sessionId UUID unchanged fallback
4 VS Code vscode.conversationId UUID unchanged fallback
5 Claude (new) com.anthropic/session printable UA Claude-User or claude-code/, or name Anthropic/ClaudeAI / claude-code fallback
6 Cursor (new) gen_ai.conversation.id printable UA Cursor/, or name Cursor / cursor-vscode fallback

"Printable" is 1 to 128 ASCII characters 0x20-0x7E, the same rule as ChatGPT's. The new rows keep the conversation_id handle, so a call without a usable id falls back to it.

Behavior change for an existing server: an openai-mcp/1.0.0 (Codex) caller (or any non-ChatGPT openai-mcp/ UA) that sends openai/session now gets $session_id from it with $mcp_session_source: client_metadata. Before, it fell through to the handle.

One regrouping follows from the spec's design: an openai-mcp/ caller whose client name is codex-mcp-client and that sends only sessionId no longer reads it, since openai-mcp/ matches row 2 first. Those requests carry openai/session on almost every call.

Pre-PR gate

Two adversaries (Opus and Sonnet) checked the spec table row for row over live HTTP on the official, fastmcp and lowlevel servers, under mcp 1.x and 2.x. They also covered handshake, session token, _meta clientInfo, stdio, the manual PostHogMCP API and tools/list advertising. No verified findings.

Testing

TDD: extended #1193's parameterized tables first (29 new cases failing), then added the rows.

  • Recognition, including openai-mcp/1.0.0 (Codex) hitting row 2 even with client name codex-mcp-client, and Claude-User-Agent/1.0 not matching.
  • Id shapes per new row, the spec's derivation vectors (incl. the 128-character boundary), end-to-end calls per new client by UA and by _meta client name, and fallback to the handle for empty, too long, non-ASCII, non-string, absent, and the other client's key.
  • uv run --no-sync pytest posthog/test/mcp: 1024 passed, 11 skipped. Ruff clean.

Stacked on #1193.

…on ids

Adds three rows to the client conversation table, matching sdk-specs
"Session identity" (PostHog/sdk-specs#261), first recognizing row wins:
- openai/session from any other openai-mcp/ User-Agent (incl. Codex's
  hosted connector), after the ChatGPT row; keeps the handle fallback.
- com.anthropic/session for UA Claude-User or claude-code/, or client
  name Anthropic/ClaudeAI / claude-code; printable id, keeps the handle.
- gen_ai.conversation.id for UA Cursor/ or client name Cursor /
  cursor-vscode; printable id, keeps the handle.

Directory-listed servers must turn off the injected conversation_id,
so these clients' sessions only survive if the SDK reads their own id.

Tested: extended the existing parameterized tables with the spec's
recognition cases, id shapes, derivation vectors (incl. the 128-char
boundary) and fallback cases.
  uv run --no-sync pytest posthog/test/mcp -> 1014 passed, 11 skipped
  ruff format/check clean
@lucasheriques
lucasheriques marked this pull request as ready for review November 28, 2026 23:53
@lucasheriques
lucasheriques requested a review from a team as a code owner November 28, 2026 23:53
@veria-ai

veria-ai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

PR overview

No security issues were found in this pull request.

Reviews

@github-actions

Copy link
Copy Markdown
Contributor

SDK performance: posthog-python

Benchmarks completed. No changes flagged for review.

Flags require at least a 5% change in the median and all six pairs agreeing on direction. This is a noise filter, not proof of a performance change or a CI gate.

View all results
Test Measurement Before PR With PR Change Assessment
Capture and deliver events (32-byte payload, burst)
Shard: capture
Managed heap after settling — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​; head:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Managed heap after settling — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​; head:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​
Capture and deliver events (32-byte payload, steady)
Shard: capture
Managed heap after settling — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​; head:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Managed heap after settling — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​; head:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​
Queue an event (32-byte payload)
Shard: capture
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​; head:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​
Queue an event (32-byte payload)
Shard: capture
Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​; head:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​
Queue an event (4,096-byte payload)
Shard: capture
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​; head:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​
Queue an event (4,096-byte payload)
Shard: capture
Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​; head:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Managed heap after settling — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​; head:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​
Refresh 1,000 flag definitions
Shard: flags-memory
Managed heap after settling — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​; head:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​
Capture and deliver events (32-byte payload, burst)
Shard: capture
Allocated memory per operation 133.67 KiB/op 133.67 KiB/op <0.1% less memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Allocations per operation 1,345.51 count/op 1,345.51 count/op <0.1% fewer Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Time per operation 77.96 µs/op 77.53 µs/op 0.6% less time Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Idle process memory (RSS) 37.56 MiB 37.61 MiB 0.1% more memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Observed peak process memory (RSS) 40.01 MiB 40.07 MiB 0.1% more memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Process memory after settling (RSS) 40.01 MiB 40.07 MiB 0.1% more memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Process CPU time per operation 79.53 µs/op 80.6 µs/op 1.4% more time Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Lifetime peak process memory (RSS) 40.57 MiB 40.57 MiB No observed change Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Allocated memory per operation 185.75 KiB/op 185.75 KiB/op No observed change Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Allocations per operation 1,337.51 count/op 1,337.51 count/op <0.1% more Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Time per operation 101.95 µs/op 102.05 µs/op <0.1% more time Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Idle process memory (RSS) 41.22 MiB 41.21 MiB <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Observed peak process memory (RSS) 47.01 MiB 47 MiB <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Process memory after settling (RSS) 47.01 MiB 47 MiB <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Process CPU time per operation 99.55 µs/op 99.69 µs/op 0.1% more time Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Lifetime peak process memory (RSS) 51.44 MiB 51.44 MiB No observed change Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Allocated memory per operation 138.73 KiB/op 138.73 KiB/op <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Allocations per operation 1,390.28 count/op 1,390.31 count/op <0.1% more Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Time per operation 92.23 µs/op 92.52 µs/op 0.3% more time Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Idle process memory (RSS) 37.55 MiB 37.55 MiB <0.1% less memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Observed peak process memory (RSS) 37.73 MiB 37.71 MiB <0.1% less memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Process memory after settling (RSS) 37.73 MiB 37.71 MiB <0.1% less memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Process CPU time per operation 93.11 µs/op 93.24 µs/op 0.1% more time Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Lifetime peak process memory (RSS) 40.57 MiB 40.57 MiB No observed change Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Allocated memory per operation 190.9 KiB/op 190.9 KiB/op <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Allocations per operation 1,382.19 count/op 1,382.19 count/op <0.1% fewer Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Time per operation 108.32 µs/op 107.67 µs/op 0.6% less time Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Idle process memory (RSS) 41.07 MiB 41.13 MiB 0.2% more memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Observed peak process memory (RSS) 41.53 MiB 41.57 MiB 0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Process memory after settling (RSS) 41.13 MiB 41.18 MiB 0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Process CPU time per operation 103.37 µs/op 104.85 µs/op 1.4% more time Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Lifetime peak process memory (RSS) 41.47 MiB 41.53 MiB 0.1% more memory Not flagged
Queue an event (32-byte payload)
Shard: capture
Caller-thread CPU time per operation 57.18 µs/op 57.12 µs/op <0.1% less time Not flagged
Queue an event (32-byte payload)
Shard: capture
Time per operation 57.17 µs/op 57.12 µs/op <0.1% less time Not flagged
Queue an event (4,096-byte payload)
Shard: capture
Caller-thread CPU time per operation 58.04 µs/op 57.57 µs/op 0.8% less time Not flagged
Queue an event (4,096-byte payload)
Shard: capture
Time per operation 58.03 µs/op 57.61 µs/op 0.7% less time Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Allocated memory per operation 233.85 KiB/op 233.85 KiB/op No observed change Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Allocations per operation 2,352.93 count/op 2,352.93 count/op No observed change Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Time per operation 94.96 µs/op 94.67 µs/op 0.3% less time Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Process CPU time per operation 94.95 µs/op 94.68 µs/op 0.3% less time Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Allocated memory per operation 2.25 MiB/op 2.25 MiB/op No observed change Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Allocations per operation 23,148.75 count/op 23,148.75 count/op No observed change Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Time per operation 927.47 µs/op 926.24 µs/op 0.1% less time Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Process CPU time per operation 927.54 µs/op 926.26 µs/op 0.1% less time Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Allocated memory per operation 22.45 MiB/op 22.45 MiB/op No observed change Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Allocations per operation 231,005.5 count/op 231,005.5 count/op No observed change Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Time per operation 9.44 ms/op 9.24 ms/op 2.1% less time Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Process CPU time per operation 9.44 ms/op 9.24 ms/op 2.1% less time Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Idle process memory (RSS) 43.96 MiB 43.96 MiB <0.1% more memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Observed peak process memory (RSS) 44.28 MiB 44.3 MiB <0.1% more memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Process memory after settling (RSS) 44.28 MiB 44.3 MiB <0.1% more memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Lifetime peak process memory (RSS) 44.08 MiB 44.02 MiB 0.1% less memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Idle process memory (RSS) 43.1 MiB 43.02 MiB 0.2% less memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Observed peak process memory (RSS) 43.11 MiB 43.03 MiB 0.2% less memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Process memory after settling (RSS) 43.11 MiB 43.03 MiB 0.2% less memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Lifetime peak process memory (RSS) 43.21 MiB 42.89 MiB 0.7% less memory Not flagged
Evaluate one boolean flag
Shard: flags-single
Allocated memory per operation 15.74 KiB/op 15.74 KiB/op No observed change Not flagged
Evaluate one boolean flag
Shard: flags-single
Allocations per operation 162.77 count/op 162.77 count/op No observed change Not flagged
Evaluate one boolean flag
Shard: flags-single
Time per operation 8.23 µs/op 8.15 µs/op 1% less time Not flagged
Evaluate one boolean flag
Shard: flags-single
Process CPU time per operation 8.23 µs/op 8.15 µs/op 1% less time Not flagged
Evaluate a cohort-filtered flag
Shard: flags-single
Allocated memory per operation 25.28 KiB/op 25.28 KiB/op No observed change Not flagged
Evaluate a cohort-filtered flag
Shard: flags-single
Allocations per operation 245.28 count/op 245.28 count/op No observed change Not flagged
Evaluate a cohort-filtered flag
Shard: flags-single
Time per operation 11.61 µs/op 11.59 µs/op 0.2% less time Not flagged
Evaluate a cohort-filtered flag
Shard: flags-single
Process CPU time per operation 11.61 µs/op 11.59 µs/op 0.2% less time Not flagged
Evaluate a flag (early match)
Shard: flags-single
Allocated memory per operation 41.36 KiB/op 41.36 KiB/op No observed change Not flagged
Evaluate a flag (early match)
Shard: flags-single
Allocations per operation 401.77 count/op 401.77 count/op No observed change Not flagged
Evaluate a flag (early match)
Shard: flags-single
Time per operation 16.81 µs/op 16.82 µs/op <0.1% more time Not flagged
Evaluate a flag (early match)
Shard: flags-single
Process CPU time per operation 16.81 µs/op 16.81 µs/op <0.1% more time Not flagged
Evaluate a flag (late match)
Shard: flags-single
Allocated memory per operation 63.34 KiB/op 63.34 KiB/op No observed change Not flagged
Evaluate a flag (late match)
Shard: flags-single
Allocations per operation 608.27 count/op 608.27 count/op No observed change Not flagged
Evaluate a flag (late match)
Shard: flags-single
Time per operation 24.22 µs/op 24.08 µs/op 0.6% less time Not flagged
Evaluate a flag (late match)
Shard: flags-single
Process CPU time per operation 24.22 µs/op 24.08 µs/op 0.6% less time Not flagged
Evaluate a flag (no match)
Shard: flags-single
Allocated memory per operation 61.97 KiB/op 61.97 KiB/op No observed change Not flagged
Evaluate a flag (no match)
Shard: flags-single
Allocations per operation 591.77 count/op 591.77 count/op No observed change Not flagged
Evaluate a flag (no match)
Shard: flags-single
Time per operation 22.79 µs/op 22.69 µs/op 0.4% less time Not flagged
Evaluate a flag (no match)
Shard: flags-single
Process CPU time per operation 22.79 µs/op 22.69 µs/op 0.4% less time Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Allocated memory per operation 19.38 KiB/op 19.38 KiB/op No observed change Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Allocations per operation 195.27 count/op 195.27 count/op No observed change Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Time per operation 9.35 µs/op 9.27 µs/op 0.9% less time Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Process CPU time per operation 9.35 µs/op 9.27 µs/op 0.9% less time Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Allocated memory per operation 21.01 KiB/op 21.01 KiB/op No observed change Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Allocations per operation 200.77 count/op 200.77 count/op No observed change Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Time per operation 9.96 µs/op 9.85 µs/op 1.1% less time Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Process CPU time per operation 9.96 µs/op 9.85 µs/op 1.1% less time Not flagged
Evaluate a rollout flag
Shard: flags-single
Allocated memory per operation 14.89 KiB/op 14.89 KiB/op No observed change Not flagged
Evaluate a rollout flag
Shard: flags-single
Allocations per operation 152.77 count/op 152.77 count/op No observed change Not flagged
Evaluate a rollout flag
Shard: flags-single
Time per operation 7.68 µs/op 7.72 µs/op 0.5% more time Not flagged
Evaluate a rollout flag
Shard: flags-single
Process CPU time per operation 7.68 µs/op 7.72 µs/op 0.5% more time Not flagged
Evaluate a multivariate flag
Shard: flags-single
Allocated memory per operation 15.9 KiB/op 15.9 KiB/op No observed change Not flagged
Evaluate a multivariate flag
Shard: flags-single
Allocations per operation 166.77 count/op 166.77 count/op No observed change Not flagged
Evaluate a multivariate flag
Shard: flags-single
Time per operation 8.5 µs/op 8.54 µs/op 0.5% more time Not flagged
Evaluate a multivariate flag
Shard: flags-single
Process CPU time per operation 8.5 µs/op 8.54 µs/op 0.5% more time Not flagged

Values are medians of paired measurements. Not flagged does not mean unchanged. Unavailable means a measurement could not be provided, not zero. Estimated allocation measurements retain their instrumentation uncertainty. RSS measures the whole process, not just SDK allocations; observed peaks are sampled checkpoints. Paired ranges in the diagnostics describe variability, not confidence intervals.

Each shard uses its own runner; compare Before PR against With PR within a row, not across shards.

Compared 421d148c7b88e76e4e5da3907bc39202543704a7 → 58a457444551ca906a9aa333f4afec0159809a7c.

Full report and diagnostics

102 metric rows; 102 rows shown in all results. Omitted or shortened data remain in comparison.json, including per-runner environments, resource limits, measurement methods, samples and checkpoints.

@lucasheriques

Copy link
Copy Markdown
Contributor Author

@PostHog review

@posthog

posthog Bot commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

@lucasheriques PostHog Review is reviewing this pull request.

@posthog posthog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

PostHog Review · Standard · reviewed 58a4574: no findings.

This branch has not been deployed

No deployments
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.

1 participant