Skip to content

Commit 22d4881

Browse files
corvid-agentclaude
andcommitted
fix: call onerror for silently swallowed transport errors
Nested try/catch blocks in WebStandardStreamableHTTPServerTransport's handlePostRequest were returning error responses without invoking the onerror callback, making transport errors invisible to consumers. Fixes: - JSON parsing errors (req.json() failures) now call onerror - JSON-RPC message validation errors now call onerror - writeSSEEvent failures now call onerror instead of silently returning false Closes #1395 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 42b3359 commit 22d4881

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@modelcontextprotocol/server': patch
3+
---
4+
5+
Call `onerror` callback for transport errors that were previously silently swallowed. Nested try/catch blocks in `handlePostRequest` for JSON parsing and JSON-RPC validation now invoke `onerror` before returning error responses. The `writeSSEEvent` method also reports errors via `onerror` instead of silently returning `false`.

packages/server/src/server/streamableHttp.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,8 @@ export class WebStandardStreamableHTTPServerTransport implements Transport {
569569
eventData += `data: ${JSON.stringify(message)}\n\n`;
570570
controller.enqueue(encoder.encode(eventData));
571571
return true;
572-
} catch {
572+
} catch (error) {
573+
this.onerror?.(error as Error);
573574
return false;
574575
}
575576
}
@@ -627,7 +628,8 @@ export class WebStandardStreamableHTTPServerTransport implements Transport {
627628
if (options?.parsedBody === undefined) {
628629
try {
629630
rawMessage = await req.json();
630-
} catch {
631+
} catch (error) {
632+
this.onerror?.(error as Error);
631633
return this.createJsonErrorResponse(400, -32_700, 'Parse error: Invalid JSON');
632634
}
633635
} else {
@@ -641,7 +643,8 @@ export class WebStandardStreamableHTTPServerTransport implements Transport {
641643
messages = Array.isArray(rawMessage)
642644
? rawMessage.map(msg => JSONRPCMessageSchema.parse(msg))
643645
: [JSONRPCMessageSchema.parse(rawMessage)];
644-
} catch {
646+
} catch (error) {
647+
this.onerror?.(error as Error);
645648
return this.createJsonErrorResponse(400, -32_700, 'Parse error: Invalid JSON-RPC message');
646649
}
647650

0 commit comments

Comments
 (0)