You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(mcp): support MCP Python SDK v2 and the 2026-07-28 spec revision
instrument() now works on mcp 1.x and 2.x:
- New _instrument_v2 adapters: the high-level MCPServer (renamed FastMCP)
wraps ToolManager.call_tool — the seam every dispatch routes through —
and the low-level Server wraps the string-keyed handler registry through
the public add_request_handler/get_request_handler API, late
registrations included (the posthog-js#4449 lesson). Strip-vs-leave
policy per entry point matches the 1.x pair: the high-level path strips
injected context/conversation_id (v2 validates against the function
signature), the raw low-level path leaves them optional in the schema.
- _compatibility probes are import-tolerant and shape-based (posthog-js
ADR-0005): the old module-level `from mcp.server.fastmcp import ...`
raised ImportError straight out of instrument() on mcp>=2, crashing the
host app. Unsupported servers now degrade to a logged no-op handle.
- Conversation-anchored sessions (posthog-js ADR-0004): with
enable_conversation_id, $session_id is derived deterministically from
the agent-echoed conversation_id — the only correlation that survives
2026-07-28's per-request instances. Byte-for-byte parity with
@posthog/mcp (new export derive_session_id_from_conversation), the
minted-shape (uuidv7) guard so invented handles can't merge unrelated
callers, lowercased echoes, and the prompt-back riding errored results
so a first-call failure keeps the conversation together. Applies to the
1.x adapters too — anchoring is not era-gated.
- Dual-shape attribute reads (isError/is_error, inputSchema/input_schema,
clientInfo/client_info); captured payloads dump by_alias so both majors
emit the camelCase wire shape.
- Version advisory widened to mcp>=1.26,<3.
No new runtime dependencies; mcp stays a lazily-imported peer dependency.
jlowin's fastmcp keeps the 1.x seams (it pins mcp<2).
Generated-By: PostHog Code
Task-Id: ebafcb71-b03b-443d-b40c-d527ed4a04f4
feat(mcp): support the MCP Python SDK 2.x and the 2026-07-28 spec revision. `instrument()` now wraps `mcp.server.mcpserver.MCPServer` (the renamed FastMCP) and the v2 low-level `Server` (constructor-injected handlers, string-keyed registry, late `add_request_handler` registrations included), capturing tool calls, tools/list, errors, intent, client identity, and `$mcp_protocol_version` on both protocol eras — SDK 1.x paths are unchanged. Conversation-anchored sessions land as the cross-pod correlation for the stateless era (parity with `@posthog/mcp`): with `enable_conversation_id`, `$session_id` is derived deterministically from the agent-echoed `conversation_id` (new export `derive_session_id_from_conversation`), only handles the SDK could have minted (uuidv7) anchor, and the prompt-back now rides errored results too so a first-call failure keeps the conversation together. `instrument()` also no longer crashes on an unsupported or unrecognized MCP SDK — it degrades to a logged no-op.
0 commit comments