Skip to content

Commit 36f86c2

Browse files
Fix TypeScript errors with proper typing
- 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 <[email protected]>
1 parent c6f3f40 commit 36f86c2

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/handlers/shttp.integration.test.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
import { jest } from '@jest/globals';
22
import { Request, Response } from 'express';
3-
import { JSONRPCMessage, JSONRPCResponse } from '@modelcontextprotocol/sdk/types.js';
3+
import { JSONRPCMessage } from '@modelcontextprotocol/sdk/types.js';
44
import { MockRedisClient, setRedisClient } from '../redis.js';
55
import { handleStreamableHTTP } from './shttp.js';
66
import { AuthInfo } from '@modelcontextprotocol/sdk/server/auth/types.js';
77
// import { randomUUID } from 'crypto'; // Currently unused but may be needed for future tests
88
import { 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+
1022
describe('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(/^data: /, '').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(/^data: /, '').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(/^data: /, '').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

Comments
 (0)