@@ -21,6 +21,9 @@ import { Transport } from "../shared/transport.js";
21
21
import { Server } from "../server/index.js" ;
22
22
import { InMemoryTransport } from "../inMemory.js" ;
23
23
24
+ /***
25
+ * Test: Initialize with Matching Protocol Version
26
+ */
24
27
test ( "should initialize with matching protocol version" , async ( ) => {
25
28
const clientTransport : Transport = {
26
29
start : jest . fn ( ) . mockResolvedValue ( undefined ) ,
@@ -76,6 +79,9 @@ test("should initialize with matching protocol version", async () => {
76
79
expect ( client . getInstructions ( ) ) . toEqual ( "test instructions" ) ;
77
80
} ) ;
78
81
82
+ /***
83
+ * Test: Initialize with Supported Older Protocol Version
84
+ */
79
85
test ( "should initialize with supported older protocol version" , async ( ) => {
80
86
const OLD_VERSION = SUPPORTED_PROTOCOL_VERSIONS [ 1 ] ;
81
87
const clientTransport : Transport = {
@@ -124,6 +130,9 @@ test("should initialize with supported older protocol version", async () => {
124
130
expect ( client . getInstructions ( ) ) . toBeUndefined ( ) ;
125
131
} ) ;
126
132
133
+ /***
134
+ * Test: Reject Unsupported Protocol Version
135
+ */
127
136
test ( "should reject unsupported protocol version" , async ( ) => {
128
137
const clientTransport : Transport = {
129
138
start : jest . fn ( ) . mockResolvedValue ( undefined ) ,
@@ -166,6 +175,9 @@ test("should reject unsupported protocol version", async () => {
166
175
expect ( clientTransport . close ) . toHaveBeenCalled ( ) ;
167
176
} ) ;
168
177
178
+ /***
179
+ * Test: Connect New Client to Old Supported Server Version
180
+ */
169
181
test ( "should connect new client to old, supported server version" , async ( ) => {
170
182
const OLD_VERSION = SUPPORTED_PROTOCOL_VERSIONS [ 1 ] ;
171
183
const server = new Server (
@@ -229,6 +241,9 @@ test("should connect new client to old, supported server version", async () => {
229
241
} ) ;
230
242
} ) ;
231
243
244
+ /***
245
+ * Test: Version Negotiation with Old Client and Newer Server
246
+ */
232
247
test ( "should negotiate version when client is old, and newer server supports its version" , async ( ) => {
233
248
const OLD_VERSION = SUPPORTED_PROTOCOL_VERSIONS [ 1 ] ;
234
249
const server = new Server (
@@ -292,6 +307,9 @@ test("should negotiate version when client is old, and newer server supports its
292
307
} ) ;
293
308
} ) ;
294
309
310
+ /***
311
+ * Test: Throw when Old Client and Server Version Mismatch
312
+ */
295
313
test ( "should throw when client is old, and server doesn't support its version" , async ( ) => {
296
314
const OLD_VERSION = SUPPORTED_PROTOCOL_VERSIONS [ 1 ] ;
297
315
const FUTURE_VERSION = "FUTURE_VERSION" ;
@@ -354,6 +372,9 @@ test("should throw when client is old, and server doesn't support its version",
354
372
355
373
} ) ;
356
374
375
+ /***
376
+ * Test: Respect Server Capabilities
377
+ */
357
378
test ( "should respect server capabilities" , async ( ) => {
358
379
const server = new Server (
359
380
{
@@ -434,6 +455,9 @@ test("should respect server capabilities", async () => {
434
455
) . rejects . toThrow ( "Server does not support completions" ) ;
435
456
} ) ;
436
457
458
+ /***
459
+ * Test: Respect Client Notification Capabilities
460
+ */
437
461
test ( "should respect client notification capabilities" , async ( ) => {
438
462
const server = new Server (
439
463
{
@@ -490,6 +514,9 @@ test("should respect client notification capabilities", async () => {
490
514
) ;
491
515
} ) ;
492
516
517
+ /***
518
+ * Test: Respect Server Notification Capabilities
519
+ */
493
520
test ( "should respect server notification capabilities" , async ( ) => {
494
521
const server = new Server (
495
522
{
@@ -536,6 +563,9 @@ test("should respect server notification capabilities", async () => {
536
563
) ;
537
564
} ) ;
538
565
566
+ /***
567
+ * Test: Only Allow setRequestHandler for Declared Capabilities
568
+ */
539
569
test ( "should only allow setRequestHandler for declared capabilities" , ( ) => {
540
570
const client = new Client (
541
571
{
@@ -567,9 +597,10 @@ test("should only allow setRequestHandler for declared capabilities", () => {
567
597
} ) . toThrow ( "Client does not support roots capability" ) ;
568
598
} ) ;
569
599
570
- /*
571
- Test that custom request/notification/result schemas can be used with the Client class.
572
- */
600
+ /***
601
+ * Test: Type Checking
602
+ * Test that custom request/notification/result schemas can be used with the Client class.
603
+ */
573
604
test ( "should typecheck" , ( ) => {
574
605
const GetWeatherRequestSchema = RequestSchema . extend ( {
575
606
method : z . literal ( "weather/get" ) ,
@@ -646,6 +677,9 @@ test("should typecheck", () => {
646
677
} ) ;
647
678
} ) ;
648
679
680
+ /***
681
+ * Test: Handle Client Cancelling a Request
682
+ */
649
683
test ( "should handle client cancelling a request" , async ( ) => {
650
684
const server = new Server (
651
685
{
@@ -701,6 +735,9 @@ test("should handle client cancelling a request", async () => {
701
735
await expect ( listResourcesPromise ) . rejects . toBe ( "Cancelled by test" ) ;
702
736
} ) ;
703
737
738
+ /***
739
+ * Test: Handle Request Timeout
740
+ */
704
741
test ( "should handle request timeout" , async ( ) => {
705
742
const server = new Server (
706
743
{
@@ -757,6 +794,9 @@ test("should handle request timeout", async () => {
757
794
} ) ;
758
795
759
796
describe ( 'outputSchema validation' , ( ) => {
797
+ /***
798
+ * Test: Validate structuredContent Against outputSchema
799
+ */
760
800
test ( 'should validate structuredContent against outputSchema' , async ( ) => {
761
801
const server = new Server ( {
762
802
name : 'test-server' ,
@@ -828,6 +868,9 @@ describe('outputSchema validation', () => {
828
868
expect ( result . structuredContent ) . toEqual ( { result : 'success' , count : 42 } ) ;
829
869
} ) ;
830
870
871
+ /***
872
+ * Test: Throw Error when structuredContent Does Not Match Schema
873
+ */
831
874
test ( 'should throw error when structuredContent does not match schema' , async ( ) => {
832
875
const server = new Server ( {
833
876
name : 'test-server' ,
@@ -901,6 +944,9 @@ describe('outputSchema validation', () => {
901
944
) ;
902
945
} ) ;
903
946
947
+ /***
948
+ * Test: Throw Error when Tool with outputSchema Returns No structuredContent
949
+ */
904
950
test ( 'should throw error when tool with outputSchema returns no structuredContent' , async ( ) => {
905
951
const server = new Server ( {
906
952
name : 'test-server' ,
@@ -972,6 +1018,9 @@ describe('outputSchema validation', () => {
972
1018
) ;
973
1019
} ) ;
974
1020
1021
+ /***
1022
+ * Test: Handle Tools Without outputSchema Normally
1023
+ */
975
1024
test ( 'should handle tools without outputSchema normally' , async ( ) => {
976
1025
const server = new Server ( {
977
1026
name : 'test-server' ,
@@ -1036,6 +1085,9 @@ describe('outputSchema validation', () => {
1036
1085
expect ( result . content ) . toEqual ( [ { type : 'text' , text : 'Normal response' } ] ) ;
1037
1086
} ) ;
1038
1087
1088
+ /***
1089
+ * Test: Handle Complex JSON Schema Validation
1090
+ */
1039
1091
test ( 'should handle complex JSON schema validation' , async ( ) => {
1040
1092
const server = new Server ( {
1041
1093
name : 'test-server' ,
@@ -1131,6 +1183,9 @@ describe('outputSchema validation', () => {
1131
1183
expect ( structuredContent . age ) . toBe ( 30 ) ;
1132
1184
} ) ;
1133
1185
1186
+ /***
1187
+ * Test: Fail Validation with Additional Properties When Not Allowed
1188
+ */
1134
1189
test ( 'should fail validation with additional properties when not allowed' , async ( ) => {
1135
1190
const server = new Server ( {
1136
1191
name : 'test-server' ,
@@ -1206,6 +1261,9 @@ describe('outputSchema validation', () => {
1206
1261
) ;
1207
1262
} ) ;
1208
1263
1264
+ /***
1265
+ * Test: Throw Error when Tool Without outputSchema Returns structuredContent
1266
+ */
1209
1267
test ( 'should throw error when tool without outputSchema returns structuredContent' , async ( ) => {
1210
1268
const server = new Server ( {
1211
1269
name : 'test-server' ,
0 commit comments