@@ -8,17 +8,17 @@ import { z } from "zod";
8
8
import { AuthInfo } from "./auth/types.js" ;
9
9
10
10
async function getFreePort ( ) {
11
- return new Promise ( res => {
12
- const srv = netCreateServer ( ) ;
13
- srv . listen ( 0 , ( ) => {
14
- const address = srv . address ( ) !
15
- if ( typeof address === "string" ) {
16
- throw new Error ( "Unexpected address type: " + typeof address ) ;
17
- }
18
- const port = ( address as AddressInfo ) . port ;
19
- srv . close ( ( err ) => res ( port ) )
20
- } ) ;
21
- } )
11
+ return new Promise ( res => {
12
+ const srv = netCreateServer ( ) ;
13
+ srv . listen ( 0 , ( ) => {
14
+ const address = srv . address ( ) !
15
+ if ( typeof address === "string" ) {
16
+ throw new Error ( "Unexpected address type: " + typeof address ) ;
17
+ }
18
+ const port = ( address as AddressInfo ) . port ;
19
+ srv . close ( ( _err ) => res ( port ) )
20
+ } ) ;
21
+ } )
22
22
}
23
23
24
24
/**
@@ -377,7 +377,7 @@ describe("StreamableHTTPServerTransport", () => {
377
377
return { content : [ { type : "text" , text : `Hello, ${ name } !` } , { type : "text" , text : `${ JSON . stringify ( requestInfo ) } ` } ] } ;
378
378
}
379
379
) ;
380
-
380
+
381
381
const toolCallMessage : JSONRPCMessage = {
382
382
jsonrpc : "2.0" ,
383
383
method : "tools/call" ,
@@ -828,7 +828,7 @@ describe("StreamableHTTPServerTransport", () => {
828
828
829
829
// Send request with matching protocol version
830
830
const response = await sendPostRequest ( baseUrl , TEST_MESSAGES . toolsList , sessionId ) ;
831
-
831
+
832
832
expect ( response . status ) . toBe ( 200 ) ;
833
833
} ) ;
834
834
@@ -846,7 +846,7 @@ describe("StreamableHTTPServerTransport", () => {
846
846
} ,
847
847
body : JSON . stringify ( TEST_MESSAGES . toolsList ) ,
848
848
} ) ;
849
-
849
+
850
850
expect ( response . status ) . toBe ( 200 ) ;
851
851
} ) ;
852
852
@@ -864,21 +864,21 @@ describe("StreamableHTTPServerTransport", () => {
864
864
} ,
865
865
body : JSON . stringify ( TEST_MESSAGES . toolsList ) ,
866
866
} ) ;
867
-
867
+
868
868
expect ( response . status ) . toBe ( 400 ) ;
869
869
const errorData = await response . json ( ) ;
870
870
expectErrorResponse ( errorData , - 32000 , / B a d R e q u e s t : U n s u p p o r t e d p r o t o c o l v e r s i o n \( s u p p o r t e d v e r s i o n s : .+ \) / ) ;
871
871
} ) ;
872
872
873
873
it ( "should accept when protocol version differs from negotiated version" , async ( ) => {
874
874
sessionId = await initializeServer ( ) ;
875
-
875
+
876
876
// Spy on console.warn to verify warning is logged
877
877
const warnSpy = jest . spyOn ( console , 'warn' ) . mockImplementation ( ) ;
878
878
879
879
// Send request with different but supported protocol version
880
880
const response = await fetch ( baseUrl , {
881
- method : "POST" ,
881
+ method : "POST" ,
882
882
headers : {
883
883
"Content-Type" : "application/json" ,
884
884
Accept : "application/json, text/event-stream" ,
@@ -887,10 +887,10 @@ describe("StreamableHTTPServerTransport", () => {
887
887
} ,
888
888
body : JSON . stringify ( TEST_MESSAGES . toolsList ) ,
889
889
} ) ;
890
-
890
+
891
891
// Request should still succeed
892
892
expect ( response . status ) . toBe ( 200 ) ;
893
-
893
+
894
894
warnSpy . mockRestore ( ) ;
895
895
} ) ;
896
896
@@ -906,7 +906,7 @@ describe("StreamableHTTPServerTransport", () => {
906
906
"mcp-protocol-version" : "invalid-version" ,
907
907
} ,
908
908
} ) ;
909
-
909
+
910
910
expect ( response . status ) . toBe ( 400 ) ;
911
911
const errorData = await response . json ( ) ;
912
912
expectErrorResponse ( errorData , - 32000 , / B a d R e q u e s t : U n s u p p o r t e d p r o t o c o l v e r s i o n \( s u p p o r t e d v e r s i o n s : .+ \) / ) ;
@@ -923,7 +923,7 @@ describe("StreamableHTTPServerTransport", () => {
923
923
"mcp-protocol-version" : "invalid-version" ,
924
924
} ,
925
925
} ) ;
926
-
926
+
927
927
expect ( response . status ) . toBe ( 400 ) ;
928
928
const errorData = await response . json ( ) ;
929
929
expectErrorResponse ( errorData , - 32000 , / B a d R e q u e s t : U n s u p p o r t e d p r o t o c o l v e r s i o n \( s u p p o r t e d v e r s i o n s : .+ \) / ) ;
@@ -965,12 +965,12 @@ describe("StreamableHTTPServerTransport with AuthInfo", () => {
965
965
method : "tools/call" ,
966
966
params : {
967
967
name : "profile" ,
968
- arguments : { active : true } ,
968
+ arguments : { active : true } ,
969
969
} ,
970
970
id : "call-1" ,
971
971
} ;
972
972
973
- const response = await sendPostRequest ( baseUrl , toolCallMessage , sessionId , { 'authorization' : 'Bearer test-token' } ) ;
973
+ const response = await sendPostRequest ( baseUrl , toolCallMessage , sessionId , { 'authorization' : 'Bearer test-token' } ) ;
974
974
expect ( response . status ) . toBe ( 200 ) ;
975
975
976
976
const text = await readSSEEvent ( response ) ;
@@ -992,7 +992,7 @@ describe("StreamableHTTPServerTransport with AuthInfo", () => {
992
992
id : "call-1" ,
993
993
} ) ;
994
994
} ) ;
995
-
995
+
996
996
it ( "should calls tool without authInfo when it is optional" , async ( ) => {
997
997
sessionId = await initializeServer ( ) ;
998
998
@@ -1001,7 +1001,7 @@ describe("StreamableHTTPServerTransport with AuthInfo", () => {
1001
1001
method : "tools/call" ,
1002
1002
params : {
1003
1003
name : "profile" ,
1004
- arguments : { active : false } ,
1004
+ arguments : { active : false } ,
1005
1005
} ,
1006
1006
id : "call-1" ,
1007
1007
} ;
@@ -1485,7 +1485,7 @@ describe("StreamableHTTPServerTransport in stateless mode", () => {
1485
1485
// Open first SSE stream
1486
1486
const stream1 = await fetch ( baseUrl , {
1487
1487
method : "GET" ,
1488
- headers : {
1488
+ headers : {
1489
1489
Accept : "text/event-stream" ,
1490
1490
"mcp-protocol-version" : "2025-03-26"
1491
1491
} ,
@@ -1495,7 +1495,7 @@ describe("StreamableHTTPServerTransport in stateless mode", () => {
1495
1495
// Open second SSE stream - should still be rejected, stateless mode still only allows one
1496
1496
const stream2 = await fetch ( baseUrl , {
1497
1497
method : "GET" ,
1498
- headers : {
1498
+ headers : {
1499
1499
Accept : "text/event-stream" ,
1500
1500
"mcp-protocol-version" : "2025-03-26"
1501
1501
} ,
0 commit comments