feat: add configuration for transparent session re-init#760
feat: add configuration for transparent session re-init#760glicht wants to merge 4 commits intomodelcontextprotocol:mainfrom
Conversation
|
I originally added to ci.yml also running tests without the So I reverted this addition. I've opened a separate PR for running the non-local tests here. |
| allow_stateless: true, | ||
| auth_header: None, | ||
| custom_headers: HashMap::new(), | ||
| enable_reinit_on_expired_session: false, |
There was a problem hiding this comment.
The MCP specification states:
When a client receives HTTP 404 in response to a request containing an
Mcp-Session-Id, it MUST start a new session by sending a newInitializeRequestwithout a session ID attached.
https://spec.modelcontextprotocol.io/specification/2025-11-25/basic/transports/#session-management
I'm afraid that if we set enable_reinit_on_expired_session to false, the transport becomes spec-non-compliant out of the box.
Previously, the behavior was to always try to re-initialize transparently. Setting it to false is also a silent breaking change for existing users who upgrade without changing their configuration.
I recommend setting it to true to comply with the spec and maintain backward compatibility. Users who want to opt out of automatic re-initialization can explicitly set it to false.
| enable_reinit_on_expired_session: false, | |
| enable_reinit_on_expired_session: true, |
| /// | ||
| /// This recovery is best-effort and bounded to a single attempt. If recovery fails, | ||
| /// the original failure path is preserved and the error is returned to the caller. | ||
| pub enable_reinit_on_expired_session: bool, |
There was a problem hiding this comment.
for consistency with the existing style
| pub enable_reinit_on_expired_session: bool, | |
| pub reinit_on_expired_session: bool, |
I've updated following your comments. |
Motivation and Context
Providing control if to enable transparent session re-init. Added to
StreamableHttpClientTransportConfiga new field:enable_reinit_on_expired_sessionto control if to do transparent session re-init.How Has This Been Tested?
Added a unit test:
test_session_expired_error_when_reinit_disabledand updated current unit test:test_transparent_reinitialization_on_session_expiry.New config option is documented as part of the docs for
StreamableHttpClientTransportConfig.Breaking Changes
No
Types of changes
Checklist
Additional context
Closes #755