4e68bad199
`to_mcp_server` keeps one ADK session per MCP connection, so successive tool calls on that connection form a single conversation. It keyed that map on `ctx.session`. That key is correct on MCP SDK 1.x, where the server builds one session object per connection. It is wrong on 2.x: the server builds a fresh `ServerSession` for every inbound request and holds the connection on the session's private `_connection`. The key would change on every call, so every tool call would start a new conversation. Nothing raises. The agent just forgets. Route the key through `_connection_key`, which reads `_connection` when the SDK provides it and falls back to the session when it does not. That gives one key per connection on both versions, and leaves 1.x behaviour unchanged. The fallback degrades to one session per request on purpose. It must not fall back to an object shared by all connections, because separate clients would then share one conversation. The private attribute is a stopgap. SDK 2.x already defines a public `mcp.server.context.Context.connection`, but the server does not hand that class to tool functions yet, so a tool's `Context` has no public route to its connection. Co-authored-by: Kathy Wu <wukathy@google.com> PiperOrigin-RevId: 967462559