Skip to content

McpToolset never recovers from a Streamable HTTP session loss when the server's 404 carries a JSON-RPC error #8499

In review

Description

@Koobi33

🔴 Required Information

Describe the Bug:
After a Streamable HTTP MCP server restarts (or evicts a session), an agent using McpToolset loses all its MCP tools for good. Every turn the model is told "The tools you can call are: none".

_is_session_terminated_error (src/google/adk/tools/mcp_tool/mcp_session_manager.py) only recognises the error the 2.x SDK makes up when a 404 has no usable body: INVALID_REQUEST with the exact message "Session terminated". When the server's 404 carries a JSON-RPC error, the 2.x SDK passes that error through instead (mcp/client/streamable_http.py, the non-2xx branch). Both common servers do that: the python-sdk server answers -32600 "Session not found", TypeScript SDK servers answer -32001 "Session not found". Neither matches, so the stale pooled session is never discarded and list_tools keeps failing on it.

Steps to Reproduce:

  1. pip install google-adk
  2. Save https://github.com/Koobi33/seams-lab/blob/main/repro/adk-session-not-found/repro.py and run python repro.py. It starts a python-sdk Streamable HTTP server, runs an LlmAgent with a scripted model (no API key) and an McpToolset, restarts the server on the same URL, and asks the agent again.

Expected Behavior:
ADK discards the session the server no longer holds, opens a new one, and the tool call works.

Observed Behavior:

before restart: {'content': [{'type': 'text', 'text': 'hello'}], 'structuredContent': {'result': 'hello'}, 'isError': False}
after restart #1: {'error': 'Invoking `echo()` failed as no tool with that name is available. The tools you can call are: none. ...'}
after restart #2: {'error': 'Invoking `echo()` failed as no tool with that name is available. The tools you can call are: none. ...'}

The underlying error is MCPError(code=-32600, message='Session not found'), and _is_session_terminated_error returns False for it.

Environment Details:

  • ADK Library Version (pip show google-adk): 2.15.1, also main 60cef52
  • Desktop OS: macOS
  • Python Version (python -V): 3.14
  • mcp: 2.3.0

Model Information:

  • Are you using LiteLLM: No
  • Which model is being used: N/A (scripted BaseLlm in the repro)

🟡 Optional Information

Regression:
The detection added for #6822 matches only the SDK's own fallback message, so it works with servers whose 404 has no JSON-RPC body.

Activity

  1. chelsealong commented on Dec 3, 2026

    @chelsealong
    Contributor

    May I work on this issue (#8499: McpToolset never recovers from a Streamable HTTP session loss when the server's 404 carries a JSON-RPC error) and, if I can reproduce it, submit a focused fix with regression coverage? Please let me know if someone is already handling it or if you would prefer a different approach. I would use Codex assistance and disclose that in any PR.

  2. surajksharma07 commented on Dec 4, 2026

    @surajksharma07
    Collaborator

    @Koobi33 I can reproduce it on 2.14.1, 2.15.0 and 2.16.0 with mcp 2.3.0. mcp 1.x still recovers fine since the SDK sends its own "Session terminated" there.

    As a workaround until #8500 lands, I wrapped mcp_session_manager._reports_session_terminated to also accept -32600/-32001 when the message says the session is not found, terminated or expired. That got the tools back after a restart for me. Pinning mcp<2 also works.

    Could you give that a try on your side? Ideally test it against a TypeScript SDK server too (the -32001 case) and confirm it holds up before we push #8500 for review.

    @chelsealong since the reporter already has a PR up for this, it'd be great to review that one rather than open a second.

  3. Koobi33 commented on Dec 4, 2026

    @Koobi33
    Author

    Checked #8500 against a TypeScript SDK server: stateful Streamable HTTP that answers the old session id with 404 and {"code": -32001, "message": "Session not found"}. With mcp 2.3.0, after a server restart the toolset opens a new session and the next calls succeed, 2 of 2 runs. google-adk 2.16.0 from PyPI on the same setup stays dead: every call after the restart fails.

    The python-sdk case (-32600) is the repro in the issue, and the unit tests in #8500 cover both codes.

  4. surajksharma07 commented on Dec 4, 2026

    @surajksharma07
    Collaborator

    Thanks @Koobi33 for checking the TypeScript server, and @its-amann, good catch on the false positives. That applies to the workaround I posted above too. It matched "session" anywhere in the message, so anyone using it should switch to the whole-match version from 7e4ead6.

    I tried 7e4ead6 here with mcp 2.3.0. After a server restart the toolset reconnects on both restarts (2.16.0 stays on "Session not found"). All 5 session-loss spellings match. "Browser session not found for tab 3" and "expired session cookie" no longer do. The mcp_tool tests show 509 passed on mcp 1.26. With mcp 2.3.0 the only 3 failures also fail on main so nothing new. It still merges cleanly on current main.

    I'll flag #8500 for maintainer review so the 2 pending workflows can run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions