@@ -23,6 +23,7 @@ import {
23
23
ServerCapabilities ,
24
24
} from "../types.js" ;
25
25
import { Transport , TransportSendOptions } from "./transport.js" ;
26
+ import { AuthInfo } from "../server/auth/types.js" ;
26
27
27
28
/**
28
29
* Callback for progress notifications.
@@ -104,6 +105,11 @@ export type RequestHandlerExtra<SendRequestT extends Request,
104
105
*/
105
106
signal : AbortSignal ;
106
107
108
+ /**
109
+ * Information about a validated access token, provided to request handlers.
110
+ */
111
+ authInfo ?: AuthInfo ;
112
+
107
113
/**
108
114
* The session ID from the transport, if available.
109
115
*/
@@ -269,11 +275,11 @@ export abstract class Protocol<
269
275
this . _onerror ( error ) ;
270
276
} ;
271
277
272
- this . _transport . onmessage = ( message ) => {
278
+ this . _transport . onmessage = ( message , extra ) => {
273
279
if ( isJSONRPCResponse ( message ) || isJSONRPCError ( message ) ) {
274
280
this . _onresponse ( message ) ;
275
281
} else if ( isJSONRPCRequest ( message ) ) {
276
- this . _onrequest ( message ) ;
282
+ this . _onrequest ( message , extra ) ;
277
283
} else if ( isJSONRPCNotification ( message ) ) {
278
284
this . _onnotification ( message ) ;
279
285
} else {
@@ -321,7 +327,7 @@ export abstract class Protocol<
321
327
) ;
322
328
}
323
329
324
- private _onrequest ( request : JSONRPCRequest ) : void {
330
+ private _onrequest ( request : JSONRPCRequest , extra ?: { authInfo ?: AuthInfo } ) : void {
325
331
const handler =
326
332
this . _requestHandlers . get ( request . method ) ?? this . fallbackRequestHandler ;
327
333
@@ -346,20 +352,20 @@ export abstract class Protocol<
346
352
const abortController = new AbortController ( ) ;
347
353
this . _requestHandlerAbortControllers . set ( request . id , abortController ) ;
348
354
349
- // Create extra object with both abort signal and sessionId from transport
350
- const extra : RequestHandlerExtra < SendRequestT , SendNotificationT > = {
355
+ const fullExtra : RequestHandlerExtra < SendRequestT , SendNotificationT > = {
351
356
signal : abortController . signal ,
352
357
sessionId : this . _transport ?. sessionId ,
353
358
sendNotification :
354
359
( notification ) =>
355
360
this . notification ( notification , { relatedRequestId : request . id } ) ,
356
361
sendRequest : ( r , resultSchema , options ?) =>
357
- this . request ( r , resultSchema , { ...options , relatedRequestId : request . id } )
362
+ this . request ( r , resultSchema , { ...options , relatedRequestId : request . id } ) ,
363
+ authInfo : extra ?. authInfo ,
358
364
} ;
359
365
360
366
// Starting with Promise.resolve() puts any synchronous errors into the monad as well.
361
367
Promise . resolve ( )
362
- . then ( ( ) => handler ( request , extra ) )
368
+ . then ( ( ) => handler ( request , fullExtra ) )
363
369
. then (
364
370
( result ) => {
365
371
if ( abortController . signal . aborted ) {
0 commit comments