1
1
import { jest } from '@jest/globals' ;
2
2
import { Request , Response } from 'express' ;
3
- import { JSONRPCMessage , JSONRPCResponse } from '@modelcontextprotocol/sdk/types.js' ;
3
+ import { JSONRPCMessage } from '@modelcontextprotocol/sdk/types.js' ;
4
4
import { MockRedisClient , setRedisClient } from '../redis.js' ;
5
5
import { handleStreamableHTTP } from './shttp.js' ;
6
6
import { AuthInfo } from '@modelcontextprotocol/sdk/server/auth/types.js' ;
7
7
// import { randomUUID } from 'crypto'; // Currently unused but may be needed for future tests
8
8
import { shutdownSession } from '../services/redisTransport.js' ;
9
9
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
+
10
22
describe ( 'Streamable HTTP Handler Integration Tests' , ( ) => {
11
23
let mockRedis : MockRedisClient ;
12
24
let mockReq : Partial < Request > ;
@@ -238,7 +250,7 @@ describe('Streamable HTTP Handler Integration Tests', () => {
238
250
let sessionId : string | undefined ;
239
251
240
252
if ( jsonCalls . length > 0 ) {
241
- const response = jsonCalls [ 0 ] [ 0 ] as JSONRPCResponse ;
253
+ const response = jsonCalls [ 0 ] [ 0 ] as MCPInitResponse ;
242
254
if ( response ?. result ?. _meta ?. sessionId ) {
243
255
sessionId = response . result . _meta . sessionId ;
244
256
}
@@ -252,7 +264,7 @@ describe('Streamable HTTP Handler Integration Tests', () => {
252
264
try {
253
265
// SSE data format: "data: {...}\n\n"
254
266
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 ;
256
268
if ( parsed ?. result ?. _meta ?. sessionId ) {
257
269
sessionId = parsed . result . _meta . sessionId ;
258
270
}
@@ -342,7 +354,7 @@ describe('Streamable HTTP Handler Integration Tests', () => {
342
354
// Check JSON responses
343
355
const jsonCalls = ( mockRes . json as jest . Mock ) . mock . calls ;
344
356
if ( jsonCalls . length > 0 ) {
345
- const response = jsonCalls [ 0 ] [ 0 ] as JSONRPCResponse ;
357
+ const response = jsonCalls [ 0 ] [ 0 ] as MCPInitResponse ;
346
358
if ( response ?. result ?. _meta ?. sessionId ) {
347
359
sessionId = response . result . _meta . sessionId ;
348
360
}
@@ -355,7 +367,7 @@ describe('Streamable HTTP Handler Integration Tests', () => {
355
367
if ( typeof data === 'string' && data . includes ( 'sessionId' ) ) {
356
368
try {
357
369
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 ;
359
371
if ( parsed ?. result ?. _meta ?. sessionId ) {
360
372
sessionId = parsed . result . _meta . sessionId ;
361
373
}
@@ -442,7 +454,7 @@ describe('Streamable HTTP Handler Integration Tests', () => {
442
454
// Check JSON responses
443
455
const jsonCalls = ( mockRes . json as jest . Mock ) . mock . calls ;
444
456
if ( jsonCalls . length > 0 ) {
445
- const response = jsonCalls [ 0 ] [ 0 ] as JSONRPCResponse ;
457
+ const response = jsonCalls [ 0 ] [ 0 ] as MCPInitResponse ;
446
458
if ( response ?. result ?. _meta ?. sessionId ) {
447
459
actualSessionId = response . result . _meta . sessionId ;
448
460
}
@@ -455,7 +467,7 @@ describe('Streamable HTTP Handler Integration Tests', () => {
455
467
if ( typeof data === 'string' && data . includes ( 'sessionId' ) ) {
456
468
try {
457
469
const jsonStr = data . replace ( / ^ d a t a : / , '' ) . trim ( ) ;
458
- const parsed = JSON . parse ( jsonStr ) ;
470
+ const parsed = JSON . parse ( jsonStr ) as MCPInitResponse ;
459
471
if ( parsed ?. result ?. _meta ?. sessionId ) {
460
472
actualSessionId = parsed . result . _meta . sessionId ;
461
473
}
0 commit comments