11import { jest } from '@jest/globals' ;
22import { Request , Response } from 'express' ;
3- import { JSONRPCMessage , JSONRPCResponse } from '@modelcontextprotocol/sdk/types.js' ;
3+ import { JSONRPCMessage } from '@modelcontextprotocol/sdk/types.js' ;
44import { MockRedisClient , setRedisClient } from '../redis.js' ;
55import { handleStreamableHTTP } from './shttp.js' ;
66import { AuthInfo } from '@modelcontextprotocol/sdk/server/auth/types.js' ;
77// import { randomUUID } from 'crypto'; // Currently unused but may be needed for future tests
88import { shutdownSession } from '../services/redisTransport.js' ;
99
10+ // Type for MCP initialization response
11+ interface MCPInitResponse {
12+ jsonrpc : string ;
13+ id : string | number ;
14+ result ?: {
15+ _meta ?: {
16+ sessionId ?: string ;
17+ } ;
18+ [ key : string ] : unknown ;
19+ } ;
20+ }
21+
1022describe ( 'Streamable HTTP Handler Integration Tests' , ( ) => {
1123 let mockRedis : MockRedisClient ;
1224 let mockReq : Partial < Request > ;
@@ -238,7 +250,7 @@ describe('Streamable HTTP Handler Integration Tests', () => {
238250 let sessionId : string | undefined ;
239251
240252 if ( jsonCalls . length > 0 ) {
241- const response = jsonCalls [ 0 ] [ 0 ] as JSONRPCResponse ;
253+ const response = jsonCalls [ 0 ] [ 0 ] as MCPInitResponse ;
242254 if ( response ?. result ?. _meta ?. sessionId ) {
243255 sessionId = response . result . _meta . sessionId ;
244256 }
@@ -252,7 +264,7 @@ describe('Streamable HTTP Handler Integration Tests', () => {
252264 try {
253265 // SSE data format: "data: {...}\n\n"
254266 const jsonStr = data . replace ( / ^ d a t a : / , '' ) . trim ( ) ;
255- const parsed = JSON . parse ( jsonStr ) as JSONRPCResponse ;
267+ const parsed = JSON . parse ( jsonStr ) as MCPInitResponse ;
256268 if ( parsed ?. result ?. _meta ?. sessionId ) {
257269 sessionId = parsed . result . _meta . sessionId ;
258270 }
@@ -342,7 +354,7 @@ describe('Streamable HTTP Handler Integration Tests', () => {
342354 // Check JSON responses
343355 const jsonCalls = ( mockRes . json as jest . Mock ) . mock . calls ;
344356 if ( jsonCalls . length > 0 ) {
345- const response = jsonCalls [ 0 ] [ 0 ] as JSONRPCResponse ;
357+ const response = jsonCalls [ 0 ] [ 0 ] as MCPInitResponse ;
346358 if ( response ?. result ?. _meta ?. sessionId ) {
347359 sessionId = response . result . _meta . sessionId ;
348360 }
@@ -355,7 +367,7 @@ describe('Streamable HTTP Handler Integration Tests', () => {
355367 if ( typeof data === 'string' && data . includes ( 'sessionId' ) ) {
356368 try {
357369 const jsonStr = data . replace ( / ^ d a t a : / , '' ) . trim ( ) ;
358- const parsed = JSON . parse ( jsonStr ) as JSONRPCResponse ;
370+ const parsed = JSON . parse ( jsonStr ) as MCPInitResponse ;
359371 if ( parsed ?. result ?. _meta ?. sessionId ) {
360372 sessionId = parsed . result . _meta . sessionId ;
361373 }
@@ -442,7 +454,7 @@ describe('Streamable HTTP Handler Integration Tests', () => {
442454 // Check JSON responses
443455 const jsonCalls = ( mockRes . json as jest . Mock ) . mock . calls ;
444456 if ( jsonCalls . length > 0 ) {
445- const response = jsonCalls [ 0 ] [ 0 ] as JSONRPCResponse ;
457+ const response = jsonCalls [ 0 ] [ 0 ] as MCPInitResponse ;
446458 if ( response ?. result ?. _meta ?. sessionId ) {
447459 actualSessionId = response . result . _meta . sessionId ;
448460 }
@@ -455,7 +467,7 @@ describe('Streamable HTTP Handler Integration Tests', () => {
455467 if ( typeof data === 'string' && data . includes ( 'sessionId' ) ) {
456468 try {
457469 const jsonStr = data . replace ( / ^ d a t a : / , '' ) . trim ( ) ;
458- const parsed = JSON . parse ( jsonStr ) ;
470+ const parsed = JSON . parse ( jsonStr ) as MCPInitResponse ;
459471 if ( parsed ?. result ?. _meta ?. sessionId ) {
460472 actualSessionId = parsed . result . _meta . sessionId ;
461473 }
0 commit comments