Repository navigation
feat(mcp): read Claude, Cursor and OpenAI hosted connector conversation ids - #1315
lucasheriques wants to merge 1 commit into
Conversation
…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
PR overviewNo security issues were found in this pull request. Reviews
|
SDK performance: posthog-pythonBenchmarks 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
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 102 metric rows; 102 rows shown in all results. Omitted or shortened data remain in |
|
@PostHog review |
|
@lucasheriques PostHog Review is reviewing this pull request. |
Why
MCP servers listed in the ChatGPT and Claude directories must turn off the injected
conversation_idargument. 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.0sendsopenai/sessionon every call but misses the ChatGPT-only rule, Claude.ai sendscom.anthropic/sessionon most calls, and Cursor sendsgen_ai.conversation.idon 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:
_metakeyopenai/sessionUser-Agentopenai/sessionopenai-mcp/sessionIdvscode.conversationIdcom.anthropic/sessionClaude-Userorclaude-code/, or nameAnthropic/ClaudeAI/claude-codegen_ai.conversation.idCursor/, or nameCursor/cursor-vscode"Printable" is 1 to 128 ASCII characters 0x20-0x7E, the same rule as ChatGPT's. The new rows keep the
conversation_idhandle, 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-ChatGPTopenai-mcp/UA) that sendsopenai/sessionnow gets$session_idfrom 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 iscodex-mcp-clientand that sends onlysessionIdno longer reads it, sinceopenai-mcp/matches row 2 first. Those requests carryopenai/sessionon 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,
_metaclientInfo, stdio, the manualPostHogMCPAPI andtools/listadvertising. No verified findings.Testing
TDD: extended #1193's parameterized tables first (29 new cases failing), then added the rows.
openai-mcp/1.0.0 (Codex)hitting row 2 even with client namecodex-mcp-client, andClaude-User-Agent/1.0not matching._metaclient 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.