diff --git a/src/server/streamableHttp.ts b/src/server/streamableHttp.ts index ab1131f63..219cb00cf 100644 --- a/src/server/streamableHttp.ts +++ b/src/server/streamableHttp.ts @@ -873,7 +873,7 @@ export class StreamableHTTPServerTransport implements Transport { let requestId = options?.relatedRequestId; if (isJSONRPCResultResponse(message) || isJSONRPCErrorResponse(message)) { // If the message is a response, use the request ID from the message - requestId = message.id; + requestId = message.id ?? undefined; } // Check if this message should be sent on the standalone SSE stream (no request ID) diff --git a/src/spec.types.ts b/src/spec.types.ts index 07a1cceff..3ee9880a8 100644 --- a/src/spec.types.ts +++ b/src/spec.types.ts @@ -169,7 +169,7 @@ export interface JSONRPCResultResponse { */ export interface JSONRPCErrorResponse { jsonrpc: typeof JSONRPC_VERSION; - id?: RequestId; + id: RequestId | null; error: Error; } diff --git a/src/types.ts b/src/types.ts index dc0c22353..e0cced52b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -198,7 +198,7 @@ export enum ErrorCode { export const JSONRPCErrorResponseSchema = z .object({ jsonrpc: z.literal(JSONRPC_VERSION), - id: RequestIdSchema.optional(), + id: RequestIdSchema.nullable(), error: z.object({ /** * The error type that occurred.