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