Repository navigation
Conversation
…arams and update session initialization logic
|
@hangfei @seanzhou1023 |
| ) | ||
| await session.initialize() | ||
|
|
||
| initialize = True |
There was a problem hiding this comment.
how does skipping initialize preserve the header ?
when codes reach here, user should already been authenticated, you won't be able to skip the auth by adding logic here if there were additional auth required.
client = self._create_client(merged_headers)
above should contain the auth token in merged_headers
|
@abprime thank you so much for the fix :) Could you explain or add comments how your fix preserve the Mcp-Session-Id header ? you mentioned that However the codes you modified is already after the authentication flow got triggered, how does that prevent triggering the authentication flow ? BTW the authentication flow is triggered in BaseAuthenticatedTool ( which MCPTool inherits from ) , by the time below codes are invoked : the credentials are already there and access tokens are put into the headers , which means the auth flow is already done. |
|
Hi @seanzhou1023 — I’m trying to confirm whether the team is aware of (and planning to address) a session-continuity issue I’m observing with ADK + Streamable HTTP. Summary
Observed behavior
Expected (per Streamable HTTP semantics)
Why this matters
What would help
If I’ve misunderstood the intended model or if there’s an existing mechanism to access and persist |
Fix MCP Session Persistence Across StreamableHTTP Sessions
Summary
This PR fixes issue #2059 by adding an
auto_initializeparameter toStreamableHTTPConnectionParamsthat controls MCP session initialization and enables session persistence across tool invocations.Problem
When using
MCPToolsetwithStreamableHTTPConnectionParams, the ADK was not persisting theMcp-Session-Idheader returned by the MCP server on the first Initialize handshake. This caused every new tool invocation to re-trigger the authentication flow and return a fresh login URL instead of reusing the existing session.Solution
The fix introduces an
auto_initializeparameter toStreamableHTTPConnectionParamsthat:True(maintains backward compatibility)True: Automatically initializes the session and re-initializes across tool invocations, if there is a disconnection (adk webguaranteed to happen because of agent reloading)False: Skips automatic initialization, allowing manual control over session lifecycle. Pass custom mcp-session-id (initialised outside the agent context)This approach is similar to the LangGraph MCP implementation and follows the MCP Specification for Session Management.
Changes Made
1. Enhanced StreamableHTTPConnectionParams
auto_initialize: bool = Trueparameter to control session initialization2. Updated Session Initialization Logic
MCPSessionManager.create_session()to check theauto_initializeparametersession.initialize()whenauto_initialize=Truefor StreamableHTTP connectionsUsage Example
Testing
Backward Compatibility
This change is fully backward compatible:
auto_initialize=Trueis the default valueRelated Links
Checklist