11import { IncomingMessage , ServerResponse } from "node:http" ;
22import { Transport } from "../shared/transport.js" ;
3- import { isInitializeRequest , isJSONRPCRequest , isJSONRPCResponse , JSONRPCMessage , JSONRPCMessageSchema , RequestId } from "../types.js" ;
3+ import { isInitializeRequest , isJSONRPCError , isJSONRPCRequest , isJSONRPCResponse , JSONRPCMessage , JSONRPCMessageSchema , RequestId } from "../types.js" ;
44import getRawBody from "raw-body" ;
55import contentType from "content-type" ;
66import { randomUUID } from "node:crypto" ;
@@ -415,7 +415,7 @@ export class StreamableHTTPServerTransport implements Transport {
415415 // Store the response for this request to send messages back through this connection
416416 // We need to track by request ID to maintain the connection
417417 for ( const message of messages ) {
418- if ( 'method' in message && 'id' in message ) {
418+ if ( isJSONRPCRequest ( message ) ) {
419419 this . _streamMapping . set ( streamId , res ) ;
420420 this . _requestToStreamMapping . set ( message . id , streamId ) ;
421421 }
@@ -535,7 +535,7 @@ export class StreamableHTTPServerTransport implements Transport {
535535
536536 async send ( message : JSONRPCMessage , options ?: { relatedRequestId ?: RequestId } ) : Promise < void > {
537537 let requestId = options ?. relatedRequestId ;
538- if ( 'result' in message || 'error' in message ) {
538+ if ( isJSONRPCResponse ( message ) || isJSONRPCError ( message ) ) {
539539 // If the message is a response, use the request ID from the message
540540 requestId = message . id ;
541541 }
@@ -545,7 +545,7 @@ export class StreamableHTTPServerTransport implements Transport {
545545 // Those will be sent via dedicated response SSE streams
546546 if ( requestId === undefined ) {
547547 // For standalone SSE streams, we can only send requests and notifications
548- if ( 'result' in message || 'error' in message ) {
548+ if ( isJSONRPCResponse ( message ) || isJSONRPCError ( message ) ) {
549549 throw new Error ( "Cannot send a response on a standalone SSE stream unless resuming a previous client request" ) ;
550550 }
551551 const standaloneSse = this . _streamMapping . get ( this . _standaloneSseStreamId )
0 commit comments