feat: add custom reconnection scheduler for non-persistent environments#1177
Open
CHOIJEWON wants to merge 2 commits intomodelcontextprotocol:mainfrom
Open
feat: add custom reconnection scheduler for non-persistent environments#1177CHOIJEWON wants to merge 2 commits intomodelcontextprotocol:mainfrom
CHOIJEWON wants to merge 2 commits intomodelcontextprotocol:mainfrom
Conversation
Resolves modelcontextprotocol#1162 Adds support for custom reconnection scheduling to StreamableHTTPClientTransport, enabling proper reconnection handling in non-persistent environments like serverless functions, mobile apps, and desktop applications. Changes: - Add ReconnectionScheduler type and econnectionScheduler option to transport - Refactor _scheduleReconnection to support custom scheduling logic - Maintain backward compatibility with default setTimeout-based scheduling - Add comprehensive test coverage for custom scheduler scenarios - Add detailed documentation with practical examples for: - Serverless environments (immediate and deferred reconnection) - Mobile apps (platform-specific background scheduling) - Desktop apps (power management and sleep/wake handling) The custom scheduler receives three parameters: - reconnect: callback to initiate reconnection - delay: suggested delay in milliseconds - attemptCount: current reconnection attempt count When no custom scheduler is provided, the default setTimeout behavior is preserved, ensuring full backward compatibility
commit: |
Author
|
Sorry for tagging you — I know you’re busy. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #1162
Summary
Adds support for custom reconnection scheduling to
StreamableHTTPClientTransport, enabling proper reconnection handling in non-persistent environments like serverless functions, mobile apps, and desktop applications wheresetTimeoutis insufficient or unavailable.Motivation and Context
As discussed in #1162 and the review feedback from PR #1129, the current
_scheduleReconnectionmethod relies onsetTimeout, which doesn't work well for:This PR implements the custom scheduler approach (option 2 from the original issue), providing maximum flexibility while maintaining full backward compatibility.
How Has This Been Tested?
src/client/streamableHttp.test.ts: Added comprehensive test suite with 4 new test cases:Breaking Changes
None. This is a fully backward-compatible addition:
reconnectionScheduleris not provided, the transport uses the defaultsetTimeout-based schedulerTypes of changes
Checklist
Review Notes
This is one of my early contributions to the project. I've followed the existing patterns and conventions to the best of my ability,
but I'm very open to feedback on:
Thank you for taking the time to review 🙌