@@ -21,6 +21,9 @@ import { Transport } from "../shared/transport.js";
2121import { Server } from "../server/index.js" ;
2222import { InMemoryTransport } from "../inMemory.js" ;
2323
24+ /***
25+ * Test: Initialize with Matching Protocol Version
26+ */
2427test ( "should initialize with matching protocol version" , async ( ) => {
2528 const clientTransport : Transport = {
2629 start : jest . fn ( ) . mockResolvedValue ( undefined ) ,
@@ -76,6 +79,9 @@ test("should initialize with matching protocol version", async () => {
7679 expect ( client . getInstructions ( ) ) . toEqual ( "test instructions" ) ;
7780} ) ;
7881
82+ /***
83+ * Test: Initialize with Supported Older Protocol Version
84+ */
7985test ( "should initialize with supported older protocol version" , async ( ) => {
8086 const OLD_VERSION = SUPPORTED_PROTOCOL_VERSIONS [ 1 ] ;
8187 const clientTransport : Transport = {
@@ -124,6 +130,9 @@ test("should initialize with supported older protocol version", async () => {
124130 expect ( client . getInstructions ( ) ) . toBeUndefined ( ) ;
125131} ) ;
126132
133+ /***
134+ * Test: Reject Unsupported Protocol Version
135+ */
127136test ( "should reject unsupported protocol version" , async ( ) => {
128137 const clientTransport : Transport = {
129138 start : jest . fn ( ) . mockResolvedValue ( undefined ) ,
@@ -166,6 +175,9 @@ test("should reject unsupported protocol version", async () => {
166175 expect ( clientTransport . close ) . toHaveBeenCalled ( ) ;
167176} ) ;
168177
178+ /***
179+ * Test: Connect New Client to Old Supported Server Version
180+ */
169181test ( "should connect new client to old, supported server version" , async ( ) => {
170182 const OLD_VERSION = SUPPORTED_PROTOCOL_VERSIONS [ 1 ] ;
171183 const server = new Server (
@@ -229,6 +241,9 @@ test("should connect new client to old, supported server version", async () => {
229241 } ) ;
230242} ) ;
231243
244+ /***
245+ * Test: Version Negotiation with Old Client and Newer Server
246+ */
232247test ( "should negotiate version when client is old, and newer server supports its version" , async ( ) => {
233248 const OLD_VERSION = SUPPORTED_PROTOCOL_VERSIONS [ 1 ] ;
234249 const server = new Server (
@@ -292,6 +307,9 @@ test("should negotiate version when client is old, and newer server supports its
292307 } ) ;
293308} ) ;
294309
310+ /***
311+ * Test: Throw when Old Client and Server Version Mismatch
312+ */
295313test ( "should throw when client is old, and server doesn't support its version" , async ( ) => {
296314 const OLD_VERSION = SUPPORTED_PROTOCOL_VERSIONS [ 1 ] ;
297315 const FUTURE_VERSION = "FUTURE_VERSION" ;
@@ -354,6 +372,9 @@ test("should throw when client is old, and server doesn't support its version",
354372
355373} ) ;
356374
375+ /***
376+ * Test: Respect Server Capabilities
377+ */
357378test ( "should respect server capabilities" , async ( ) => {
358379 const server = new Server (
359380 {
@@ -434,6 +455,9 @@ test("should respect server capabilities", async () => {
434455 ) . rejects . toThrow ( "Server does not support completions" ) ;
435456} ) ;
436457
458+ /***
459+ * Test: Respect Client Notification Capabilities
460+ */
437461test ( "should respect client notification capabilities" , async ( ) => {
438462 const server = new Server (
439463 {
@@ -490,6 +514,9 @@ test("should respect client notification capabilities", async () => {
490514 ) ;
491515} ) ;
492516
517+ /***
518+ * Test: Respect Server Notification Capabilities
519+ */
493520test ( "should respect server notification capabilities" , async ( ) => {
494521 const server = new Server (
495522 {
@@ -536,6 +563,9 @@ test("should respect server notification capabilities", async () => {
536563 ) ;
537564} ) ;
538565
566+ /***
567+ * Test: Only Allow setRequestHandler for Declared Capabilities
568+ */
539569test ( "should only allow setRequestHandler for declared capabilities" , ( ) => {
540570 const client = new Client (
541571 {
@@ -567,9 +597,10 @@ test("should only allow setRequestHandler for declared capabilities", () => {
567597 } ) . toThrow ( "Client does not support roots capability" ) ;
568598} ) ;
569599
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+ */
573604test ( "should typecheck" , ( ) => {
574605 const GetWeatherRequestSchema = RequestSchema . extend ( {
575606 method : z . literal ( "weather/get" ) ,
@@ -646,6 +677,9 @@ test("should typecheck", () => {
646677 } ) ;
647678} ) ;
648679
680+ /***
681+ * Test: Handle Client Cancelling a Request
682+ */
649683test ( "should handle client cancelling a request" , async ( ) => {
650684 const server = new Server (
651685 {
@@ -701,6 +735,9 @@ test("should handle client cancelling a request", async () => {
701735 await expect ( listResourcesPromise ) . rejects . toBe ( "Cancelled by test" ) ;
702736} ) ;
703737
738+ /***
739+ * Test: Handle Request Timeout
740+ */
704741test ( "should handle request timeout" , async ( ) => {
705742 const server = new Server (
706743 {
@@ -757,6 +794,9 @@ test("should handle request timeout", async () => {
757794} ) ;
758795
759796describe ( 'outputSchema validation' , ( ) => {
797+ /***
798+ * Test: Validate structuredContent Against outputSchema
799+ */
760800 test ( 'should validate structuredContent against outputSchema' , async ( ) => {
761801 const server = new Server ( {
762802 name : 'test-server' ,
@@ -828,6 +868,9 @@ describe('outputSchema validation', () => {
828868 expect ( result . structuredContent ) . toEqual ( { result : 'success' , count : 42 } ) ;
829869 } ) ;
830870
871+ /***
872+ * Test: Throw Error when structuredContent Does Not Match Schema
873+ */
831874 test ( 'should throw error when structuredContent does not match schema' , async ( ) => {
832875 const server = new Server ( {
833876 name : 'test-server' ,
@@ -901,6 +944,9 @@ describe('outputSchema validation', () => {
901944 ) ;
902945 } ) ;
903946
947+ /***
948+ * Test: Throw Error when Tool with outputSchema Returns No structuredContent
949+ */
904950 test ( 'should throw error when tool with outputSchema returns no structuredContent' , async ( ) => {
905951 const server = new Server ( {
906952 name : 'test-server' ,
@@ -972,6 +1018,9 @@ describe('outputSchema validation', () => {
9721018 ) ;
9731019 } ) ;
9741020
1021+ /***
1022+ * Test: Handle Tools Without outputSchema Normally
1023+ */
9751024 test ( 'should handle tools without outputSchema normally' , async ( ) => {
9761025 const server = new Server ( {
9771026 name : 'test-server' ,
@@ -1036,6 +1085,9 @@ describe('outputSchema validation', () => {
10361085 expect ( result . content ) . toEqual ( [ { type : 'text' , text : 'Normal response' } ] ) ;
10371086 } ) ;
10381087
1088+ /***
1089+ * Test: Handle Complex JSON Schema Validation
1090+ */
10391091 test ( 'should handle complex JSON schema validation' , async ( ) => {
10401092 const server = new Server ( {
10411093 name : 'test-server' ,
@@ -1131,6 +1183,9 @@ describe('outputSchema validation', () => {
11311183 expect ( structuredContent . age ) . toBe ( 30 ) ;
11321184 } ) ;
11331185
1186+ /***
1187+ * Test: Fail Validation with Additional Properties When Not Allowed
1188+ */
11341189 test ( 'should fail validation with additional properties when not allowed' , async ( ) => {
11351190 const server = new Server ( {
11361191 name : 'test-server' ,
@@ -1206,6 +1261,9 @@ describe('outputSchema validation', () => {
12061261 ) ;
12071262 } ) ;
12081263
1264+ /***
1265+ * Test: Throw Error when Tool Without outputSchema Returns structuredContent
1266+ */
12091267 test ( 'should throw error when tool without outputSchema returns structuredContent' , async ( ) => {
12101268 const server = new Server ( {
12111269 name : 'test-server' ,
0 commit comments