Skip to content

Commit 1593929

Browse files
committed
Fix streamable HTTP to handle error responses
Handle both success (JSONRPCResultResponse) and error (JSONRPCErrorResponse) responses for: - Setting receivedResponse flag to prevent unnecessary reconnection - ID remapping during stream resumption Previously only success responses were handled, which could cause: 1. Unnecessary reconnection attempts after receiving an error response 2. Incorrect request/response correlation during stream resumption This aligns with the Python SDK and Swift SDK implementations.
1 parent 5ce4b5e commit 1593929

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

packages/client/src/client/streamableHttp.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { FetchLike, JSONRPCMessage, Transport } from '@modelcontextprotocol
44
import {
55
createFetchWithInit,
66
isInitializedNotification,
7+
isJSONRPCErrorResponse,
78
isJSONRPCRequest,
89
isJSONRPCResultResponse,
910
JSONRPCMessageSchema,
@@ -361,7 +362,8 @@ export class StreamableHTTPClientTransport implements Transport {
361362
if (!event.event || event.event === 'message') {
362363
try {
363364
const message = JSONRPCMessageSchema.parse(JSON.parse(event.data));
364-
if (isJSONRPCResultResponse(message)) {
365+
// Handle both success AND error responses for completion detection and ID remapping
366+
if (isJSONRPCResultResponse(message) || isJSONRPCErrorResponse(message)) {
365367
// Mark that we received a response - no need to reconnect for this request
366368
receivedResponse = true;
367369
if (replayMessageId !== undefined) {

0 commit comments

Comments
 (0)