@@ -4,6 +4,7 @@ import { isInitializeRequest, isJSONRPCError, isJSONRPCRequest, isJSONRPCRespons
44import getRawBody from "raw-body" ;
55import contentType from "content-type" ;
66import { randomUUID } from "node:crypto" ;
7+ import { AuthInfo } from "./auth/types.js" ;
78
89const MAXIMUM_MESSAGE_SIZE = "4mb" ;
910
@@ -112,7 +113,7 @@ export class StreamableHTTPServerTransport implements Transport {
112113 sessionId ?: string | undefined ;
113114 onclose ?: ( ) => void ;
114115 onerror ?: ( error : Error ) => void ;
115- onmessage ?: ( message : JSONRPCMessage ) => void ;
116+ onmessage ?: ( message : JSONRPCMessage , extra ?: { authInfo ?: AuthInfo } ) => void ;
116117
117118 constructor ( options : StreamableHTTPServerTransportOptions ) {
118119 this . sessionIdGenerator = options . sessionIdGenerator ;
@@ -286,7 +287,7 @@ export class StreamableHTTPServerTransport implements Transport {
286287 /**
287288 * Handles POST requests containing JSON-RPC messages
288289 */
289- private async handlePostRequest ( req : IncomingMessage , res : ServerResponse , parsedBody ?: unknown ) : Promise < void > {
290+ private async handlePostRequest ( req : IncomingMessage & { auth ?: AuthInfo } , res : ServerResponse , parsedBody ?: unknown ) : Promise < void > {
290291 try {
291292 // Validate the Accept header
292293 const acceptHeader = req . headers . accept ;
@@ -316,6 +317,8 @@ export class StreamableHTTPServerTransport implements Transport {
316317 return ;
317318 }
318319
320+ const authInfo : AuthInfo | undefined = req . auth ;
321+
319322 let rawMessage ;
320323 if ( parsedBody !== undefined ) {
321324 rawMessage = parsedBody ;
@@ -392,7 +395,7 @@ export class StreamableHTTPServerTransport implements Transport {
392395
393396 // handle each message
394397 for ( const message of messages ) {
395- this . onmessage ?.( message ) ;
398+ this . onmessage ?.( message , { authInfo } ) ;
396399 }
397400 } else if ( hasRequests ) {
398401 // The default behavior is to use SSE streaming
@@ -427,7 +430,7 @@ export class StreamableHTTPServerTransport implements Transport {
427430
428431 // handle each message
429432 for ( const message of messages ) {
430- this . onmessage ?.( message ) ;
433+ this . onmessage ?.( message , { authInfo } ) ;
431434 }
432435 // The server SHOULD NOT close the SSE stream before sending all JSON-RPC responses
433436 // This will be handled by the send() method when responses are ready
0 commit comments