@@ -217,11 +217,11 @@ test("should connect new client to old, supported server version", async () => {
217217 const [ clientTransport , serverTransport ] =
218218 InMemoryTransport . createLinkedPair ( ) ;
219219
220+ // Client initialization automatically uses LATEST_PROTOCOL_VERSION in the current SDK
220221 const client = new Client (
221222 {
222223 name : "new client" ,
223224 version : "1.0" ,
224- protocolVersion : LATEST_PROTOCOL_VERSION ,
225225 } ,
226226 {
227227 capabilities : {
@@ -287,7 +287,6 @@ test("should negotiate version when client is old, and newer server supports its
287287 {
288288 name : "old client" ,
289289 version : "1.0" ,
290- protocolVersion : OLD_VERSION ,
291290 } ,
292291 {
293292 capabilities : {
@@ -297,6 +296,17 @@ test("should negotiate version when client is old, and newer server supports its
297296 } ,
298297 ) ;
299298
299+ // Mock the request method to simulate an old client sending OLD_VERSION
300+ const originalRequest = client . request . bind ( client ) ;
301+ client . request = jest . fn ( async ( request , schema , options ) => {
302+ // If this is the initialize request, modify the protocol version to simulate old client
303+ if ( request . method === "initialize" && request . params ) {
304+ request . params . protocolVersion = OLD_VERSION ;
305+ }
306+ // Call the original request method with the potentially modified request
307+ return originalRequest ( request , schema , options ) ;
308+ } ) ;
309+
300310 await Promise . all ( [
301311 client . connect ( clientTransport ) ,
302312 server . connect ( serverTransport ) ,
@@ -350,11 +360,13 @@ test("should throw when client is old, and server doesn't support its version",
350360 const [ clientTransport , serverTransport ] =
351361 InMemoryTransport . createLinkedPair ( ) ;
352362
363+ // Client uses LATEST_PROTOCOL_VERSION by default, which is sufficient for this test
364+ // The error occurs because the server returns FUTURE_VERSION (unsupported),
365+ // not because of the client's version. Any client version would fail here.
353366 const client = new Client (
354367 {
355368 name : "old client" ,
356369 version : "1.0" ,
357- protocolVersion : OLD_VERSION ,
358370 } ,
359371 {
360372 capabilities : {
@@ -880,6 +892,7 @@ describe('outputSchema validation', () => {
880892 server . setRequestHandler ( CallToolRequestSchema , async ( request ) => {
881893 if ( request . params . name === 'test-tool' ) {
882894 return {
895+ content : [ ] , // Required field for CallToolResult
883896 structuredContent : { result : 'success' , count : 42 } ,
884897 } ;
885898 }
@@ -903,7 +916,11 @@ describe('outputSchema validation', () => {
903916
904917 // Call the tool - should validate successfully
905918 const result = await client . callTool ( { name : 'test-tool' } ) ;
906- expect ( result . structuredContent ) . toEqual ( { result : 'success' , count : 42 } ) ;
919+ // Type narrowing: check if structuredContent exists before accessing
920+ expect ( 'structuredContent' in result ) . toBe ( true ) ;
921+ if ( 'structuredContent' in result ) {
922+ expect ( result . structuredContent ) . toEqual ( { result : 'success' , count : 42 } ) ;
923+ }
907924 } ) ;
908925
909926 /***
@@ -955,6 +972,7 @@ describe('outputSchema validation', () => {
955972 if ( request . params . name === 'test-tool' ) {
956973 // Return invalid structured content (count is string instead of number)
957974 return {
975+ content : [ ] , // Required field for CallToolResult
958976 structuredContent : { result : 'success' , count : 'not a number' } ,
959977 } ;
960978 }
@@ -1120,7 +1138,11 @@ describe('outputSchema validation', () => {
11201138
11211139 // Call the tool - should work normally without validation
11221140 const result = await client . callTool ( { name : 'test-tool' } ) ;
1123- expect ( result . content ) . toEqual ( [ { type : 'text' , text : 'Normal response' } ] ) ;
1141+ // Type narrowing: check if content exists before accessing
1142+ expect ( 'content' in result ) . toBe ( true ) ;
1143+ if ( 'content' in result ) {
1144+ expect ( result . content ) . toEqual ( [ { type : 'text' , text : 'Normal response' } ] ) ;
1145+ }
11241146 } ) ;
11251147
11261148 /***
@@ -1184,6 +1206,7 @@ describe('outputSchema validation', () => {
11841206 server . setRequestHandler ( CallToolRequestSchema , async ( request ) => {
11851207 if ( request . params . name === 'complex-tool' ) {
11861208 return {
1209+ content : [ ] , // Required field for CallToolResult
11871210 structuredContent : {
11881211 name : 'John Doe' ,
11891212 age : 30 ,
@@ -1215,10 +1238,14 @@ describe('outputSchema validation', () => {
12151238
12161239 // Call the tool - should validate successfully
12171240 const result = await client . callTool ( { name : 'complex-tool' } ) ;
1218- expect ( result . structuredContent ) . toBeDefined ( ) ;
1219- const structuredContent = result . structuredContent as { name : string ; age : number } ;
1220- expect ( structuredContent . name ) . toBe ( 'John Doe' ) ;
1221- expect ( structuredContent . age ) . toBe ( 30 ) ;
1241+ // Type narrowing: check if structuredContent exists before accessing
1242+ expect ( 'structuredContent' in result ) . toBe ( true ) ;
1243+ if ( 'structuredContent' in result ) {
1244+ expect ( result . structuredContent ) . toBeDefined ( ) ;
1245+ const structuredContent = result . structuredContent as { name : string ; age : number } ;
1246+ expect ( structuredContent . name ) . toBe ( 'John Doe' ) ;
1247+ expect ( structuredContent . age ) . toBe ( 30 ) ;
1248+ }
12221249 } ) ;
12231250
12241251 /***
@@ -1269,6 +1296,7 @@ describe('outputSchema validation', () => {
12691296 if ( request . params . name === 'strict-tool' ) {
12701297 // Return structured content with extra property
12711298 return {
1299+ content : [ ] , // Required field for CallToolResult
12721300 structuredContent : {
12731301 name : 'John' ,
12741302 extraField : 'not allowed' ,
0 commit comments