@@ -4,6 +4,7 @@ import { isInitializeRequest, isJSONRPCError, isJSONRPCRequest, isJSONRPCRespons
4
4
import getRawBody from "raw-body" ;
5
5
import contentType from "content-type" ;
6
6
import { randomUUID } from "node:crypto" ;
7
+ import { AuthInfo } from "./auth/types.js" ;
7
8
8
9
const MAXIMUM_MESSAGE_SIZE = "4mb" ;
9
10
@@ -112,7 +113,7 @@ export class StreamableHTTPServerTransport implements Transport {
112
113
sessionId ?: string | undefined ;
113
114
onclose ?: ( ) => void ;
114
115
onerror ?: ( error : Error ) => void ;
115
- onmessage ?: ( message : JSONRPCMessage ) => void ;
116
+ onmessage ?: ( message : JSONRPCMessage , extra ?: { authInfo ?: AuthInfo } ) => void ;
116
117
117
118
constructor ( options : StreamableHTTPServerTransportOptions ) {
118
119
this . sessionIdGenerator = options . sessionIdGenerator ;
@@ -286,7 +287,7 @@ export class StreamableHTTPServerTransport implements Transport {
286
287
/**
287
288
* Handles POST requests containing JSON-RPC messages
288
289
*/
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 > {
290
291
try {
291
292
// Validate the Accept header
292
293
const acceptHeader = req . headers . accept ;
@@ -316,6 +317,8 @@ export class StreamableHTTPServerTransport implements Transport {
316
317
return ;
317
318
}
318
319
320
+ const authInfo : AuthInfo | undefined = req . auth ;
321
+
319
322
let rawMessage ;
320
323
if ( parsedBody !== undefined ) {
321
324
rawMessage = parsedBody ;
@@ -392,7 +395,7 @@ export class StreamableHTTPServerTransport implements Transport {
392
395
393
396
// handle each message
394
397
for ( const message of messages ) {
395
- this . onmessage ?.( message ) ;
398
+ this . onmessage ?.( message , { authInfo } ) ;
396
399
}
397
400
} else if ( hasRequests ) {
398
401
// The default behavior is to use SSE streaming
@@ -427,7 +430,7 @@ export class StreamableHTTPServerTransport implements Transport {
427
430
428
431
// handle each message
429
432
for ( const message of messages ) {
430
- this . onmessage ?.( message ) ;
433
+ this . onmessage ?.( message , { authInfo } ) ;
431
434
}
432
435
// The server SHOULD NOT close the SSE stream before sending all JSON-RPC responses
433
436
// This will be handled by the send() method when responses are ready
0 commit comments