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