Skip to content

Persist Mcp-Session-Id Across Streamable HTTP Sessions in MCPToolset #2059

@abprime

Description

@abprime

** Please make sure you read the contribution guide and file the issues in the right place. **
Contribution guide.

Describe the bug
When using MCPToolset with StreamableHTTPConnectionParams (Streamable HTTP transport), the ADK does not persist the Mcp-Session-Id header returned by the MCP server on the first Initialize handshake. As a result, every new tool invocation re-triggers the authentication flow and returns a fresh login URL instead of reusing the existing session.

To Reproduce
Steps to reproduce the behavior:

  1. Install the ADK package:
pip install google-adk
  1. Use the following agent definition:
from google.adk.agent import Agent
from google.adk.tools.mcp_tool.mcp_toolset import MCPToolset, StreamableHTTPConnectionParams
from your_visualization_module import visualization_agent

root_agent = Agent(
    model="gemini-2.5-flash",
    name="root_agent",
    description="A helpful assistant for user questions.",
    instruction="You are a helpful assistant. Please help the user to the best of your knowledge",
    tools=[
        MCPToolset(
            connection_params=StreamableHTTPConnectionParams(
                url="http://mcp.fi.money:8080/mcp/stream",
            ),
        ),
    ],
)

Run a simple query that triggers the first tool call

response1 = await root_agent.run("fetch bank transactions")

Run a second query in the same process

response2 = await root_agent.run("fetch bank transactions again")

  1. Observe that on each run, the MCP server returns a login URL instead of reusing the session ID.

Expected behavior
After the MCP server returns a Mcp-Session-Id header on the initial handshake, the ADK should automatically store that session ID and include it on all subsequent Initialize or tool calls over the same transport, avoiding repeated auth prompts.

Screenshots
N/A

Desktop (please complete the following information):
• OS: [e.g. Ubuntu 22.04 LTS] - MacOS 15.5 (24F74)
• Python version (python -V): Python 3.11.8
• ADK version (pip show google-adk): 1.6.1

Model Information:
• Model invoked by the agent - "gemini-2.5-flash".

Additional context
ADK’s documentation mentions helpers for auth and key storage but does not provide an out-of-the-box solution for persisting Mcp-Session-Id on Streamable HTTP transports. Implementing this in the ADK core would streamline authentication flows in stateful MCP deployments.
https://modelcontextprotocol.io/specification/2025-06-18/basic/transports#session-management

Metadata

Metadata

Assignees

Labels

bot triaged[Bot] This issue is triaged by ADK botmcp[Component] Issues about MCP supporttools[Component] This issue is related to tools

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions