@@ -476,6 +476,37 @@ describe("StreamableHTTPClientTransport", () => {
476476 expect ( global . fetch ) . toHaveBeenCalledTimes ( 2 ) ;
477477 } ) ;
478478
479+ it ( "should always send specified custom headers (Headers class)" , async ( ) => {
480+ const requestInit = {
481+ headers : new Headers ( {
482+ "X-Custom-Header" : "CustomValue"
483+ } )
484+ } ;
485+ transport = new StreamableHTTPClientTransport ( new URL ( "http://localhost:1234/mcp" ) , {
486+ requestInit : requestInit
487+ } ) ;
488+
489+ let actualReqInit : RequestInit = { } ;
490+
491+ ( ( global . fetch as jest . Mock ) ) . mockImplementation (
492+ async ( _url , reqInit ) => {
493+ actualReqInit = reqInit ;
494+ return new Response ( null , { status : 200 , headers : { "content-type" : "text/event-stream" } } ) ;
495+ }
496+ ) ;
497+
498+ await transport . start ( ) ;
499+
500+ await transport [ "_startOrAuthSse" ] ( { } ) ;
501+ expect ( ( actualReqInit . headers as Headers ) . get ( "x-custom-header" ) ) . toBe ( "CustomValue" ) ;
502+
503+ ( requestInit . headers as Headers ) . set ( "X-Custom-Header" , "SecondCustomValue" ) ;
504+
505+ await transport . send ( { jsonrpc : "2.0" , method : "test" , params : { } } as JSONRPCMessage ) ;
506+ expect ( ( actualReqInit . headers as Headers ) . get ( "x-custom-header" ) ) . toBe ( "SecondCustomValue" ) ;
507+
508+ expect ( global . fetch ) . toHaveBeenCalledTimes ( 2 ) ;
509+ } ) ;
479510
480511 it ( "should have exponential backoff with configurable maxRetries" , ( ) => {
481512 // This test verifies the maxRetries and backoff calculation directly
0 commit comments