@@ -73,7 +73,7 @@ describe("StreamableHTTPServerTransport", () => {
73
73
method : "POST" ,
74
74
headers : {
75
75
"content-type" : "application/json" ,
76
- "accept" : "application/json" ,
76
+ "accept" : "application/json, text/event-stream " ,
77
77
} ,
78
78
body : JSON . stringify ( initializeMessage ) ,
79
79
} ) ;
@@ -93,7 +93,7 @@ describe("StreamableHTTPServerTransport", () => {
93
93
method : "GET" ,
94
94
headers : {
95
95
"mcp-session-id" : "invalid-session-id" ,
96
- "accept" : "text/event-stream"
96
+ "accept" : "application/json, text/event-stream"
97
97
} ,
98
98
} ) ;
99
99
@@ -109,7 +109,7 @@ describe("StreamableHTTPServerTransport", () => {
109
109
const req = createMockRequest ( {
110
110
method : "GET" ,
111
111
headers : {
112
- accept : "text/event-stream" ,
112
+ accept : "application/json, text/event-stream" ,
113
113
// No mcp-session-id header
114
114
} ,
115
115
} ) ;
@@ -143,7 +143,7 @@ describe("StreamableHTTPServerTransport", () => {
143
143
method : "POST" ,
144
144
headers : {
145
145
"content-type" : "application/json" ,
146
- "accept" : "application/json" ,
146
+ "accept" : "application/json, text/event-stream " ,
147
147
} ,
148
148
body : JSON . stringify ( message ) ,
149
149
} ) ;
@@ -161,7 +161,7 @@ describe("StreamableHTTPServerTransport", () => {
161
161
method : "POST" ,
162
162
headers : {
163
163
"content-type" : "application/json" ,
164
- "accept" : "application/json" ,
164
+ "accept" : "application/json, text/event-stream " ,
165
165
"mcp-session-id" : "invalid-session-id" , // This would cause a 404 in stateful mode
166
166
} ,
167
167
body : JSON . stringify ( {
@@ -195,7 +195,7 @@ describe("StreamableHTTPServerTransport", () => {
195
195
method : "POST" ,
196
196
headers : {
197
197
"content-type" : "application/json" ,
198
- "accept" : "application/json" ,
198
+ "accept" : "application/json, text/event-stream " ,
199
199
"mcp-session-id" : "non-existent-session-id" , // This would be rejected in stateful mode
200
200
} ,
201
201
body : JSON . stringify ( message ) ,
@@ -216,7 +216,7 @@ describe("StreamableHTTPServerTransport", () => {
216
216
method : "POST" ,
217
217
headers : {
218
218
"content-type" : "application/json" ,
219
- accept : "text/event-stream" ,
219
+ accept : "application/json, text/event-stream" ,
220
220
} ,
221
221
body : JSON . stringify ( {
222
222
jsonrpc : "2.0" ,
@@ -242,7 +242,7 @@ describe("StreamableHTTPServerTransport", () => {
242
242
method : "POST" ,
243
243
headers : {
244
244
"content-type" : "application/json" ,
245
- accept : "text/event-stream" ,
245
+ accept : "application/json, text/event-stream" ,
246
246
"mcp-session-id" : "some-random-session-id" ,
247
247
} ,
248
248
body : JSON . stringify ( {
@@ -264,7 +264,7 @@ describe("StreamableHTTPServerTransport", () => {
264
264
) ;
265
265
} ) ;
266
266
267
- it ( "should handle initialization requests properly in statefull mode" , async ( ) => {
267
+ it ( "should handle initialization requests properly in stateful mode" , async ( ) => {
268
268
// Initialize message that would typically be sent during initialization
269
269
const initializeMessage : JSONRPCMessage = {
270
270
jsonrpc : "2.0" ,
@@ -281,7 +281,7 @@ describe("StreamableHTTPServerTransport", () => {
281
281
method : "POST" ,
282
282
headers : {
283
283
"content-type" : "application/json" ,
284
- "accept" : "application/json" ,
284
+ "accept" : "application/json, text/event-stream " ,
285
285
} ,
286
286
body : JSON . stringify ( initializeMessage ) ,
287
287
} ) ;
@@ -314,7 +314,7 @@ describe("StreamableHTTPServerTransport", () => {
314
314
method : "POST" ,
315
315
headers : {
316
316
"content-type" : "application/json" ,
317
- "accept" : "application/json" ,
317
+ "accept" : "application/json, text/event-stream " ,
318
318
} ,
319
319
body : JSON . stringify ( initializeMessage ) ,
320
320
} ) ;
@@ -333,7 +333,7 @@ describe("StreamableHTTPServerTransport", () => {
333
333
const req = createMockRequest ( {
334
334
method : "GET" ,
335
335
headers : {
336
- "accept" : "text/event-stream" ,
336
+ "accept" : "application/json, text/event-stream" ,
337
337
"mcp-session-id" : transport . sessionId ,
338
338
} ,
339
339
} ) ;
@@ -380,7 +380,7 @@ describe("StreamableHTTPServerTransport", () => {
380
380
method : "POST" ,
381
381
headers : {
382
382
"content-type" : "application/json" ,
383
- "accept" : "text/event-stream" ,
383
+ "accept" : "application/json, text/event-stream" ,
384
384
} ,
385
385
body : JSON . stringify ( message ) ,
386
386
} ) ;
@@ -394,7 +394,7 @@ describe("StreamableHTTPServerTransport", () => {
394
394
expect ( mockResponse . writeHead ) . toHaveBeenCalledWith (
395
395
200 ,
396
396
expect . objectContaining ( {
397
- "Content-Type " : "text/event-stream" ,
397
+ "mcp-session-id " : transport . sessionId ,
398
398
} )
399
399
) ;
400
400
} ) ;
@@ -435,7 +435,7 @@ describe("StreamableHTTPServerTransport", () => {
435
435
method : "POST" ,
436
436
headers : {
437
437
"content-type" : "application/json" ,
438
- "accept" : "application/json" ,
438
+ "accept" : "application/json, text/event-stream " ,
439
439
"mcp-session-id" : transport . sessionId ,
440
440
} ,
441
441
body : JSON . stringify ( batchMessages ) ,
@@ -488,7 +488,7 @@ describe("StreamableHTTPServerTransport", () => {
488
488
method : "POST" ,
489
489
headers : {
490
490
"content-type" : "text/plain" ,
491
- "accept" : "application/json" ,
491
+ "accept" : "application/json, text/event-stream " ,
492
492
"mcp-session-id" : transport . sessionId ,
493
493
} ,
494
494
body : "test" ,
@@ -532,7 +532,7 @@ describe("StreamableHTTPServerTransport", () => {
532
532
method : "POST" ,
533
533
headers : {
534
534
"content-type" : "application/json" ,
535
- "accept" : "text/event-stream" ,
535
+ "accept" : "application/json, text/event-stream" ,
536
536
"mcp-session-id" : transport . sessionId
537
537
} ,
538
538
body : JSON . stringify ( requestMessage )
@@ -571,7 +571,7 @@ describe("StreamableHTTPServerTransport", () => {
571
571
method : "POST" ,
572
572
headers : {
573
573
"content-type" : "application/json" ,
574
- "accept" : "text/event-stream" ,
574
+ "accept" : "application/json, text/event-stream" ,
575
575
"mcp-session-id" : transport . sessionId
576
576
} ,
577
577
body : JSON . stringify ( requestMessage )
@@ -620,7 +620,7 @@ describe("StreamableHTTPServerTransport", () => {
620
620
method : "POST" ,
621
621
headers : {
622
622
"content-type" : "application/json" ,
623
- "accept" : "text/event-stream" ,
623
+ "accept" : "application/json, text/event-stream" ,
624
624
"mcp-session-id" : transport . sessionId
625
625
} ,
626
626
body : JSON . stringify ( requestMessage1 ) ,
@@ -639,7 +639,7 @@ describe("StreamableHTTPServerTransport", () => {
639
639
method : "POST" ,
640
640
headers : {
641
641
"content-type" : "application/json" ,
642
- "accept" : "text/event-stream" ,
642
+ "accept" : "application/json, text/event-stream" ,
643
643
"mcp-session-id" : transport . sessionId
644
644
} ,
645
645
body : JSON . stringify ( requestMessage2 ) ,
@@ -691,7 +691,7 @@ describe("StreamableHTTPServerTransport", () => {
691
691
method : "POST" ,
692
692
headers : {
693
693
"content-type" : "application/json" ,
694
- "accept" : "application/json" ,
694
+ "accept" : "application/json, text/event-stream " ,
695
695
} ,
696
696
body : "invalid json" ,
697
697
} ) ;
@@ -712,7 +712,7 @@ describe("StreamableHTTPServerTransport", () => {
712
712
method : "POST" ,
713
713
headers : {
714
714
"content-type" : "application/json" ,
715
- "accept" : "application/json" ,
715
+ "accept" : "application/json, text/event-stream " ,
716
716
} ,
717
717
body : JSON . stringify ( { invalid : "message" } ) ,
718
718
} ) ;
@@ -745,7 +745,7 @@ describe("StreamableHTTPServerTransport", () => {
745
745
method : "POST" ,
746
746
headers : {
747
747
"content-type" : "application/json" ,
748
- "accept" : "application/json" ,
748
+ "accept" : "application/json, text/event-stream " ,
749
749
} ,
750
750
// No body provided here - it will be passed as parsedBody
751
751
} ) ;
@@ -761,7 +761,7 @@ describe("StreamableHTTPServerTransport", () => {
761
761
expect ( mockResponse . writeHead ) . toHaveBeenCalledWith (
762
762
200 ,
763
763
expect . objectContaining ( {
764
- "Content-Type " : "application/json" ,
764
+ "mcp-session-id " : transport . sessionId ,
765
765
} )
766
766
) ;
767
767
} ) ;
@@ -787,7 +787,7 @@ describe("StreamableHTTPServerTransport", () => {
787
787
method : "POST" ,
788
788
headers : {
789
789
"content-type" : "application/json" ,
790
- "accept" : "text/event-stream" ,
790
+ "accept" : "application/json, text/event-stream" ,
791
791
"mcp-session-id" : transport . sessionId ,
792
792
} ,
793
793
// No body provided here - it will be passed as parsedBody
@@ -825,7 +825,7 @@ describe("StreamableHTTPServerTransport", () => {
825
825
method : "POST" ,
826
826
headers : {
827
827
"content-type" : "application/json" ,
828
- "accept" : "application/json" ,
828
+ "accept" : "application/json, text/event-stream " ,
829
829
"mcp-session-id" : transport . sessionId ,
830
830
} ,
831
831
body : JSON . stringify ( requestBodyMessage ) ,
@@ -863,7 +863,7 @@ describe("StreamableHTTPServerTransport", () => {
863
863
method : "POST" ,
864
864
headers : {
865
865
"content-type" : "application/json" ,
866
- accept : "text/event-stream" ,
866
+ accept : "application/json, text/event-stream" ,
867
867
"mcp-session-id" : transportWithHeaders . sessionId
868
868
} ,
869
869
body : JSON . stringify ( {
@@ -888,41 +888,11 @@ describe("StreamableHTTPServerTransport", () => {
888
888
) ;
889
889
} ) ;
890
890
891
- it ( "should include custom headers in JSON response" , async ( ) => {
892
- const message : JSONRPCMessage = {
893
- jsonrpc : "2.0" ,
894
- method : "test" ,
895
- params : { } ,
896
- id : 1 ,
897
- } ;
898
-
899
- const req = createMockRequest ( {
900
- method : "POST" ,
901
- headers : {
902
- "content-type" : "application/json" ,
903
- "accept" : "application/json" ,
904
- "mcp-session-id" : transportWithHeaders . sessionId
905
- } ,
906
- body : JSON . stringify ( message ) ,
907
- } ) ;
908
-
909
- await transportWithHeaders . handleRequest ( req , mockResponse ) ;
910
-
911
- expect ( mockResponse . writeHead ) . toHaveBeenCalledWith (
912
- 200 ,
913
- expect . objectContaining ( {
914
- ...customHeaders ,
915
- "Content-Type" : "application/json" ,
916
- "mcp-session-id" : transportWithHeaders . sessionId
917
- } )
918
- ) ;
919
- } ) ;
920
-
921
891
it ( "should include custom headers in error responses" , async ( ) => {
922
892
const req = createMockRequest ( {
923
893
method : "GET" ,
924
894
headers : {
925
- accept : "text/event-stream" ,
895
+ accept : "application/json, text/event-stream" ,
926
896
"mcp-session-id" : "invalid-session-id"
927
897
} ,
928
898
} ) ;
@@ -948,7 +918,7 @@ describe("StreamableHTTPServerTransport", () => {
948
918
method : "POST" ,
949
919
headers : {
950
920
"content-type" : "application/json" ,
951
- accept : "text/event-stream" ,
921
+ accept : "application/json, text/event-stream" ,
952
922
"mcp-session-id" : transportWithConflictingHeaders . sessionId
953
923
} ,
954
924
body : JSON . stringify ( {
@@ -979,7 +949,7 @@ describe("StreamableHTTPServerTransport", () => {
979
949
method : "POST" ,
980
950
headers : {
981
951
"content-type" : "application/json" ,
982
- accept : "text/event-stream" ,
952
+ accept : "application/json, text/event-stream" ,
983
953
"mcp-session-id" : transportWithoutHeaders . sessionId
984
954
} ,
985
955
body : JSON . stringify ( {
0 commit comments