-
Notifications
You must be signed in to change notification settings - Fork 1k
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
+94
−17
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
ihrpr
approved these changes
Jul 3, 2025
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
SSEClientTransport
andStreamableHTTPClientTransport
classes by enabling the injection of a customfetch
implementation. 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
fetch
option toSSEClientTransport
andStreamableHTTPClientTransport
constructors, allowing consumers to provide their own customfetch
implementation for network requests.fetch
implementation is now utilized for all internal network operations within these transports, including initial SSE connections (GET), sending messages (POST), and session termination (DELETE).FetchLike
type definition insrc/shared/transport.ts
to ensure consistent typing for customfetch
functions across the codebase.fetch
implementation, specifically ensuring proper authentication header propagation for various request types.Changelog
SSEClientTransport
correctly utilizes a customfetch
implementation for both initial connection and subsequent POST requests, ensuring proper header propagation.FetchLike
type fromsrc/shared/transport.ts
.fetch
option toSSEClientTransportOptions
and a corresponding private_fetch
property.fetch
calls within_startOrAuth()
andsend()
methods to use the provided customfetch
or fall back to the globalfetch
.??
) forfetch
fallback logic as per review suggestions.StartSSEOptions
interface for improved type safety in tests.StreamableHTTPClientTransport
uses the customfetch
implementation for all its network operations, including authentication.FetchLike
type fromsrc/shared/transport.ts
.StartSSEOptions
interface.fetch
option toStreamableHTTPClientTransportOptions
and a corresponding private_fetch
property._startOrAuthSse()
,send()
, andterminate()
methods to use the customfetch
implementation for their respective network requests.??
) forfetch
fallback logic as per review suggestions.FetchLike
type, standardizing the signature for customfetch
functions 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