Skip to content

MCPToolset creates a new mcp-session-id for each invocation #4277

@ashubham

Description

@ashubham

🔴 Required Information

Describe the Bug:
When an MCPToolSet is used as a tool to an Agent. A new mcp-session-id is created for each invocation. This is because the mcp-session-id returned from the MCP initialization is not persisted in the state for reuse.

Steps to Reproduce:

  1. Create a test MCP server, which just logs the mcp-session-id header for each incoming request/operation.

  2. Create a new Agent using the above MCP server.

agent = Agent(
  model=""
  name=""
  tools=[
    new MCPToolset(
      connection_params=StreamableHTTPConnectionParams(
          url=url,
          timeout=timeout,
      )
    )
  ]
)
  1. Run the ADK playground and send messages to the agent, the agent does a list/tool for each invocation, also it does not reuse the mcp-session-id sent by the server in the previous response.

Expected Behavior:
As per the MCP spec, the MCP server can send an mcp-session-id in the response of initialization request. That mcp-session-id can be used for subsequent requests to maintain stateful servers.

Observed Behavior:
For each turn/invocation, the agent reinitializes the MCP client and creates a new mcp-session-id.

Environment Details:

  • ADK Library Version (pip show google-adk): 1.21.0
  • Desktop OS:** Mac
  • Python Version (python -V): 3.11

Model Information:

  • Are you using LiteLLM: No
  • Which model is being used: gemini-2.5-flash

🟡 Optional Information

Providing this information greatly speeds up the resolution process.

Regression:
No

How often has this issue occurred?:

  • Always (100%)

Metadata

Metadata

Assignees

No one assigned

    Labels

    mcp[Component] Issues about MCP supporttools[Component] This issue is related to tools

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions