Skip to content

feat(client): add explicit session_id support for Streamable HTTP resumption#2327

Open
mrutunjay-kinagi wants to merge 5 commits intomodelcontextprotocol:mainfrom
mrutunjay-kinagi:fix-2116-session-resumption-api
Open

feat(client): add explicit session_id support for Streamable HTTP resumption#2327
mrutunjay-kinagi wants to merge 5 commits intomodelcontextprotocol:mainfrom
mrutunjay-kinagi:fix-2116-session-resumption-api

Conversation

@mrutunjay-kinagi
Copy link

@mrutunjay-kinagi mrutunjay-kinagi commented Mar 21, 2026

Summary

Adds first-class support for reusing a previously issued mcp-session-id on the Python client side.

Note: this follows the same high-level design as the C# implementation for session resumption in modelcontextprotocol/csharp-sdk (#946, implemented by #1029):

  • transport-level known session IDs
  • explicit client resume flow that skips initialize
  • caller control over session ownership/termination behavior

Closes #2116

Changes

  • streamable_http_client(...) accepts session_id: str | None and seeds transport state with it.
  • StreamableHTTPTransport accepts optional initial session_id.
  • URL Client now supports:
    • streamable_http_session_id
    • streamable_http_terminate_on_close
    • streamable_http_initialize_result
  • Added Client.resume_session(...) explicit resume constructor.
  • Added ClientSession.resume(...) to apply previously negotiated initialization data and skip the initialize handshake.
  • streamable_http_client(...) now starts GET stream immediately when resuming with a known session ID.
  • StreamableHttpParameters supports session_id and forwards it in ClientSessionGroup.

Validation

  • .venv/bin/pytest -q tests/client/test_client.py -k "streamable_http or resume_session or requires_session_id"
  • .venv/bin/pytest -q tests/client/test_session_group.py -k "establish_session_parameterized"
  • .venv/bin/pytest -q tests/shared/test_streamable_http.py -k "seeded_session_id_header"

@mrutunjay-kinagi
Copy link
Author

mrutunjay-kinagi commented Mar 21, 2026

Follow-up on latest CI for commit dbddc8b:

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support MCP client session resumption (sessionId reuse) in Python SDK

1 participant