@@ -23,6 +23,7 @@ import {
2323 ServerCapabilities ,
2424} from "../types.js" ;
2525import { Transport , TransportSendOptions } from "./transport.js" ;
26+ import { AuthInfo } from "../server/auth/types.js" ;
2627
2728/**
2829 * Callback for progress notifications.
@@ -104,6 +105,11 @@ export type RequestHandlerExtra<SendRequestT extends Request,
104105 */
105106 signal : AbortSignal ;
106107
108+ /**
109+ * Information about a validated access token, provided to request handlers.
110+ */
111+ authInfo ?: AuthInfo ;
112+
107113 /**
108114 * The session ID from the transport, if available.
109115 */
@@ -269,11 +275,11 @@ export abstract class Protocol<
269275 this . _onerror ( error ) ;
270276 } ;
271277
272- this . _transport . onmessage = ( message ) => {
278+ this . _transport . onmessage = ( message , extra ) => {
273279 if ( isJSONRPCResponse ( message ) || isJSONRPCError ( message ) ) {
274280 this . _onresponse ( message ) ;
275281 } else if ( isJSONRPCRequest ( message ) ) {
276- this . _onrequest ( message ) ;
282+ this . _onrequest ( message , extra ) ;
277283 } else if ( isJSONRPCNotification ( message ) ) {
278284 this . _onnotification ( message ) ;
279285 } else {
@@ -321,7 +327,7 @@ export abstract class Protocol<
321327 ) ;
322328 }
323329
324- private _onrequest ( request : JSONRPCRequest ) : void {
330+ private _onrequest ( request : JSONRPCRequest , extra ?: { authInfo ?: AuthInfo } ) : void {
325331 const handler =
326332 this . _requestHandlers . get ( request . method ) ?? this . fallbackRequestHandler ;
327333
@@ -346,20 +352,20 @@ export abstract class Protocol<
346352 const abortController = new AbortController ( ) ;
347353 this . _requestHandlerAbortControllers . set ( request . id , abortController ) ;
348354
349- // Create extra object with both abort signal and sessionId from transport
350- const extra : RequestHandlerExtra < SendRequestT , SendNotificationT > = {
355+ const fullExtra : RequestHandlerExtra < SendRequestT , SendNotificationT > = {
351356 signal : abortController . signal ,
352357 sessionId : this . _transport ?. sessionId ,
353358 sendNotification :
354359 ( notification ) =>
355360 this . notification ( notification , { relatedRequestId : request . id } ) ,
356361 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 ,
358364 } ;
359365
360366 // Starting with Promise.resolve() puts any synchronous errors into the monad as well.
361367 Promise . resolve ( )
362- . then ( ( ) => handler ( request , extra ) )
368+ . then ( ( ) => handler ( request , fullExtra ) )
363369 . then (
364370 ( result ) => {
365371 if ( abortController . signal . aborted ) {
0 commit comments