-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Allow custom fetch in SSEClientTransport and StreamableHTTPClientTransport #721
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
Merged
Conversation
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
nullish coalescing operator ?? instead of the logical OR operator || to handle the case where this?._eventSourceInit?.fetch or this._fetch might be null or undefined but not falsy Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
nullish coalescing operator ?? instead of the logical OR operator || to handle the case where this?._eventSourceInit?.fetch or this._fetch might be null or undefined but not falsy Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
nullish coalescing operator ?? instead of the logical OR operator || to handle the case where this?._eventSourceInit?.fetch or this._fetch might be null or undefined but not falsy Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
nullish coalescing operator ?? instead of the logical OR operator || to handle the case where this?._eventSourceInit?.fetch or this._fetch might be null or undefined but not falsy Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
nullish coalescing operator ?? instead of the logical OR operator || to handle the case where this?._eventSourceInit?.fetch or this._fetch might be null or undefined but not falsy Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
- More specific expectations in test "uses custom fetch implementation from options" * In sse.ts - Import FetchLike from transport.ts * In steramableHttp.ts - Import FetchLike from transport.ts - Export StartSSEOptions interface for testing * In streamableHttp.test.ts - import StartSSEOptions from streamableHttp.ts - use StartSSEOptions instead of any in test "uses custom fetch implementation" * In transport.ts - Add FetchLike function type
…ablehttp.ts-and-sse.ts Add custom fetch support to transports
This was referenced Jul 1, 2025
Member
Author
ihrpr
approved these changes
Jul 3, 2025
Contributor
ihrpr
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.
Thank you
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.
Summary of Changes
This pull request significantly enhances the flexibility of the
SSEClientTransportandStreamableHTTPClientTransportclasses by enabling the injection of a customfetchimplementation. This change empowers users to exert fine-grained control over network requests, facilitating advanced use cases such as custom authentication flows or specialized request handling, thereby improving the adaptability of the transport layer.Highlights
fetchoption toSSEClientTransportandStreamableHTTPClientTransportconstructors, allowing consumers to provide their own customfetchimplementation for network requests.fetchimplementation is now utilized for all internal network operations within these transports, including initial SSE connections (GET), sending messages (POST), and session termination (DELETE).FetchLiketype definition insrc/shared/transport.tsto ensure consistent typing for customfetchfunctions across the codebase.fetchimplementation, specifically ensuring proper authentication header propagation for various request types.Changelog
SSEClientTransportcorrectly utilizes a customfetchimplementation for both initial connection and subsequent POST requests, ensuring proper header propagation.FetchLiketype fromsrc/shared/transport.ts.fetchoption toSSEClientTransportOptionsand a corresponding private_fetchproperty.fetchcalls within_startOrAuth()andsend()methods to use the provided customfetchor fall back to the globalfetch.??) forfetchfallback logic as per review suggestions.StartSSEOptionsinterface for improved type safety in tests.StreamableHTTPClientTransportuses the customfetchimplementation for all its network operations, including authentication.FetchLiketype fromsrc/shared/transport.ts.StartSSEOptionsinterface.fetchoption toStreamableHTTPClientTransportOptionsand a corresponding private_fetchproperty._startOrAuthSse(),send(), andterminate()methods to use the customfetchimplementation for their respective network requests.??) forfetchfallback logic as per review suggestions.FetchLiketype, standardizing the signature for customfetchfunctions across the codebase.Motivation and Context
Picks up on the work started in abandoned PR #296, refining the implementation, extending it to include StreamableHttp in addition to SSE, and adds tests for both.
The ultimate motivation is in the requirement by a pending PR in the Inspector project, which seeks to bridge the WWW-Authenticate header returned by an MCP server back to the Inspector client within the Inspector proxy. This makes use of the custom fetch function to capture the header.
How Has This Been Tested?
New unit tests.
Breaking Changes
Nope.
Types of changes
Checklist
Additional context
Fixes #476