@@ -99,7 +99,7 @@ describe("StreamableHTTPServerTransport", () => {
9999
100100 await transport . handleRequest ( req , mockResponse ) ;
101101
102- expect ( mockResponse . writeHead ) . toHaveBeenCalledWith ( 404 , { } ) ;
102+ expect ( mockResponse . writeHead ) . toHaveBeenCalledWith ( 404 ) ;
103103 // check if the error response is a valid JSON-RPC error format
104104 expect ( mockResponse . end ) . toHaveBeenCalledWith ( expect . stringContaining ( '"jsonrpc":"2.0"' ) ) ;
105105 expect ( mockResponse . end ) . toHaveBeenCalledWith ( expect . stringContaining ( '"error"' ) ) ;
@@ -116,7 +116,7 @@ describe("StreamableHTTPServerTransport", () => {
116116
117117 await transport . handleRequest ( req , mockResponse ) ;
118118
119- expect ( mockResponse . writeHead ) . toHaveBeenCalledWith ( 400 , { } ) ;
119+ expect ( mockResponse . writeHead ) . toHaveBeenCalledWith ( 400 ) ;
120120 expect ( mockResponse . end ) . toHaveBeenCalledWith ( expect . stringContaining ( '"jsonrpc":"2.0"' ) ) ;
121121 expect ( mockResponse . end ) . toHaveBeenCalledWith ( expect . stringContaining ( '"message":"Bad Request: Mcp-Session-Id header is required"' ) ) ;
122122 } ) ;
@@ -842,135 +842,4 @@ describe("StreamableHTTPServerTransport", () => {
842842 expect ( onMessageMock ) . not . toHaveBeenCalledWith ( requestBodyMessage ) ;
843843 } ) ;
844844 } ) ;
845-
846- describe ( "Custom Headers" , ( ) => {
847- const customHeaders = {
848- "X-Custom-Header" : "custom-value" ,
849- "X-API-Version" : "1.0" ,
850- "Access-Control-Allow-Origin" : "*"
851- } ;
852-
853- let transportWithHeaders : StreamableHTTPServerTransport ;
854- let mockResponse : jest . Mocked < ServerResponse > ;
855-
856- beforeEach ( ( ) => {
857- transportWithHeaders = new StreamableHTTPServerTransport ( { sessionId : randomUUID ( ) , customHeaders } ) ;
858- mockResponse = createMockResponse ( ) ;
859- } ) ;
860-
861- it ( "should include custom headers in SSE response" , async ( ) => {
862- const req = createMockRequest ( {
863- method : "POST" ,
864- headers : {
865- "content-type" : "application/json" ,
866- accept : "application/json, text/event-stream" ,
867- "mcp-session-id" : transportWithHeaders . sessionId
868- } ,
869- body : JSON . stringify ( {
870- jsonrpc : "2.0" ,
871- method : "test" ,
872- params : { } ,
873- id : "test-headers-id"
874- } )
875- } ) ;
876-
877- await transportWithHeaders . handleRequest ( req , mockResponse ) ;
878-
879- expect ( mockResponse . writeHead ) . toHaveBeenCalledWith (
880- 200 ,
881- expect . objectContaining ( {
882- ...customHeaders ,
883- "Content-Type" : "text/event-stream" ,
884- "Cache-Control" : "no-cache" ,
885- "Connection" : "keep-alive" ,
886- "mcp-session-id" : transportWithHeaders . sessionId
887- } )
888- ) ;
889- } ) ;
890-
891- it ( "should include custom headers in error responses" , async ( ) => {
892- const req = createMockRequest ( {
893- method : "GET" ,
894- headers : {
895- accept : "application/json, text/event-stream" ,
896- "mcp-session-id" : "invalid-session-id"
897- } ,
898- } ) ;
899-
900- await transportWithHeaders . handleRequest ( req , mockResponse ) ;
901-
902- expect ( mockResponse . writeHead ) . toHaveBeenCalledWith (
903- 404 ,
904- expect . objectContaining ( customHeaders )
905- ) ;
906- } ) ;
907-
908- it ( "should not override essential headers with custom headers" , async ( ) => {
909- const transportWithConflictingHeaders = new StreamableHTTPServerTransport ( {
910- sessionId : randomUUID ( ) ,
911- customHeaders : {
912- "Content-Type" : "text/plain" ,
913- "X-Custom-Header" : "custom-value"
914- }
915- } ) ;
916-
917- const req = createMockRequest ( {
918- method : "POST" ,
919- headers : {
920- "content-type" : "application/json" ,
921- accept : "application/json, text/event-stream" ,
922- "mcp-session-id" : transportWithConflictingHeaders . sessionId
923- } ,
924- body : JSON . stringify ( {
925- jsonrpc : "2.0" ,
926- method : "test" ,
927- params : { } ,
928- id : "test-conflict-id"
929- } )
930- } ) ;
931-
932- await transportWithConflictingHeaders . handleRequest ( req , mockResponse ) ;
933-
934- expect ( mockResponse . writeHead ) . toHaveBeenCalledWith (
935- 200 ,
936- expect . objectContaining ( {
937- "Content-Type" : "text/event-stream" ,
938- "X-Custom-Header" : "custom-value"
939- } )
940- ) ;
941- } ) ;
942-
943- it ( "should work with empty custom headers" , async ( ) => {
944- const transportWithoutHeaders = new StreamableHTTPServerTransport ( {
945- sessionId : randomUUID ( ) ,
946- } ) ;
947-
948- const req = createMockRequest ( {
949- method : "POST" ,
950- headers : {
951- "content-type" : "application/json" ,
952- accept : "application/json, text/event-stream" ,
953- "mcp-session-id" : transportWithoutHeaders . sessionId
954- } ,
955- body : JSON . stringify ( {
956- jsonrpc : "2.0" ,
957- method : "test" ,
958- params : { } ,
959- id : "test-empty-headers-id"
960- } )
961- } ) ;
962-
963- await transportWithoutHeaders . handleRequest ( req , mockResponse ) ;
964-
965- expect ( mockResponse . writeHead ) . toHaveBeenCalledWith (
966- 200 ,
967- expect . objectContaining ( {
968- "Content-Type" : "text/event-stream" ,
969- "Cache-Control" : "no-cache" ,
970- "Connection" : "keep-alive" ,
971- "mcp-session-id" : transportWithoutHeaders . sessionId
972- } )
973- ) ;
974- } ) ;
975- } ) ;
976845} ) ;
0 commit comments