From 36f86c26570c8e8154ca8e78bf8d13bad9afd623 Mon Sep 17 00:00:00 2001 From: Jerome Date: Thu, 10 Jul 2025 17:29:42 +0100 Subject: [PATCH] Fix TypeScript errors with proper typing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add MCPInitResponse interface for test responses - Replace 'any' types with proper interface - Remove unused JSONRPCResponse import - Maintain type safety while fixing build errors 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/handlers/shttp.integration.test.ts | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/handlers/shttp.integration.test.ts b/src/handlers/shttp.integration.test.ts index 8ffea82..b345d28 100644 --- a/src/handlers/shttp.integration.test.ts +++ b/src/handlers/shttp.integration.test.ts @@ -1,12 +1,24 @@ import { jest } from '@jest/globals'; import { Request, Response } from 'express'; -import { JSONRPCMessage, JSONRPCResponse } from '@modelcontextprotocol/sdk/types.js'; +import { JSONRPCMessage } from '@modelcontextprotocol/sdk/types.js'; import { MockRedisClient, setRedisClient } from '../redis.js'; import { handleStreamableHTTP } from './shttp.js'; import { AuthInfo } from '@modelcontextprotocol/sdk/server/auth/types.js'; // import { randomUUID } from 'crypto'; // Currently unused but may be needed for future tests import { shutdownSession } from '../services/redisTransport.js'; +// Type for MCP initialization response +interface MCPInitResponse { + jsonrpc: string; + id: string | number; + result?: { + _meta?: { + sessionId?: string; + }; + [key: string]: unknown; + }; +} + describe('Streamable HTTP Handler Integration Tests', () => { let mockRedis: MockRedisClient; let mockReq: Partial; @@ -238,7 +250,7 @@ describe('Streamable HTTP Handler Integration Tests', () => { let sessionId: string | undefined; if (jsonCalls.length > 0) { - const response = jsonCalls[0][0] as JSONRPCResponse; + const response = jsonCalls[0][0] as MCPInitResponse; if (response?.result?._meta?.sessionId) { sessionId = response.result._meta.sessionId; } @@ -252,7 +264,7 @@ describe('Streamable HTTP Handler Integration Tests', () => { try { // SSE data format: "data: {...}\n\n" const jsonStr = data.replace(/^data: /, '').trim(); - const parsed = JSON.parse(jsonStr) as JSONRPCResponse; + const parsed = JSON.parse(jsonStr) as MCPInitResponse; if (parsed?.result?._meta?.sessionId) { sessionId = parsed.result._meta.sessionId; } @@ -342,7 +354,7 @@ describe('Streamable HTTP Handler Integration Tests', () => { // Check JSON responses const jsonCalls = (mockRes.json as jest.Mock).mock.calls; if (jsonCalls.length > 0) { - const response = jsonCalls[0][0] as JSONRPCResponse; + const response = jsonCalls[0][0] as MCPInitResponse; if (response?.result?._meta?.sessionId) { sessionId = response.result._meta.sessionId; } @@ -355,7 +367,7 @@ describe('Streamable HTTP Handler Integration Tests', () => { if (typeof data === 'string' && data.includes('sessionId')) { try { const jsonStr = data.replace(/^data: /, '').trim(); - const parsed = JSON.parse(jsonStr) as JSONRPCResponse; + const parsed = JSON.parse(jsonStr) as MCPInitResponse; if (parsed?.result?._meta?.sessionId) { sessionId = parsed.result._meta.sessionId; } @@ -442,7 +454,7 @@ describe('Streamable HTTP Handler Integration Tests', () => { // Check JSON responses const jsonCalls = (mockRes.json as jest.Mock).mock.calls; if (jsonCalls.length > 0) { - const response = jsonCalls[0][0] as JSONRPCResponse; + const response = jsonCalls[0][0] as MCPInitResponse; if (response?.result?._meta?.sessionId) { actualSessionId = response.result._meta.sessionId; } @@ -455,7 +467,7 @@ describe('Streamable HTTP Handler Integration Tests', () => { if (typeof data === 'string' && data.includes('sessionId')) { try { const jsonStr = data.replace(/^data: /, '').trim(); - const parsed = JSON.parse(jsonStr); + const parsed = JSON.parse(jsonStr) as MCPInitResponse; if (parsed?.result?._meta?.sessionId) { actualSessionId = parsed.result._meta.sessionId; }