-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat: add closeSSEStream callback to RequestHandlerExtra #1166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
commit: |
pcarleton
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm 1 nit on example
da2e98c to
3a58ea1
Compare
src/server/streamableHttp.ts
Outdated
| const stream = this._streamMapping.get(streamId); | ||
| if (stream) { | ||
| // If a custom retry interval is provided, send it before closing | ||
| if (retryInterval !== undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this cause problems for the client?
If the "event" field is missing, the SSE spec says that it should be treated as a "message" event.
|
What do you think about putting all these |
Address findleyr's feedback to decouple tool code from transport: - Add CloseSSEStreamOptions type for per-invocation retry intervals - Add closeSSEStream callback to MessageExtraInfo and RequestHandlerExtra - Callback only provided when eventStore is configured - Support custom retry interval via options.retryInterval - Update ssePollingExample to use the new callback API Tools can now close SSE streams directly via extra.closeSSEStream() without needing to track or access transports explicitly.
Address review feedback: sending `retry: N\n\n` could trigger SSE event dispatch behavior in some client implementations. Using a single `\n` ensures the retry field is processed without potentially dispatching an empty event.
Remove the optional retryInterval parameter from closeSSEStream callback for simplicity. The transport's default retry interval (from priming events) is sufficient. This aligns with Python SDK.
a37d53d to
47d0ad1
Compare
Probably a good idea 🤔 wary of refactoring right now for backwards compatibility, but could be something to put on the list for v2 what do you think? |
Summary
Adds
extra.closeSSEStreamcallback toRequestHandlerExtra, addressing findleyr's feedback on #1129.This decouples tool code from the transport - tools can now close SSE streams without needing to track or access transports explicitly.
Changes
CloseSSEStreamOptionstype with optionalretryIntervalfieldMessageExtraInfowith optionalcloseSSEStreamcallbackcloseSSEStreamtoRequestHandlerExtraeventStoreis configuredNew API
Dependencies
This PR depends on #1129 (SEP-1699 SSE polling) being merged first.
Test plan