@@ -23,6 +23,7 @@ import {
2323 ServerCapabilities ,
2424} from "../types.js" ;
2525import { Transport } from "./transport.js" ;
26+ import { AuthInfo } from "../server/auth/types.js" ;
2627
2728/**
2829 * Callback for progress notifications.
@@ -109,6 +110,11 @@ export type RequestHandlerExtra<SendRequestT extends Request,
109110 */
110111 signal : AbortSignal ;
111112
113+ /**
114+ * Information about a validated access token, provided to request handlers.
115+ */
116+ authInfo ?: AuthInfo ;
117+
112118 /**
113119 * The session ID from the transport, if available.
114120 */
@@ -274,11 +280,11 @@ export abstract class Protocol<
274280 this . _onerror ( error ) ;
275281 } ;
276282
277- this . _transport . onmessage = ( message ) => {
283+ this . _transport . onmessage = ( message , extra ) => {
278284 if ( isJSONRPCResponse ( message ) || isJSONRPCError ( message ) ) {
279285 this . _onresponse ( message ) ;
280286 } else if ( isJSONRPCRequest ( message ) ) {
281- this . _onrequest ( message ) ;
287+ this . _onrequest ( message , extra ) ;
282288 } else if ( isJSONRPCNotification ( message ) ) {
283289 this . _onnotification ( message ) ;
284290 } else {
@@ -326,7 +332,7 @@ export abstract class Protocol<
326332 ) ;
327333 }
328334
329- private _onrequest ( request : JSONRPCRequest ) : void {
335+ private _onrequest ( request : JSONRPCRequest , extra ?: { authInfo ?: AuthInfo } ) : void {
330336 const handler =
331337 this . _requestHandlers . get ( request . method ) ?? this . fallbackRequestHandler ;
332338
@@ -351,20 +357,20 @@ export abstract class Protocol<
351357 const abortController = new AbortController ( ) ;
352358 this . _requestHandlerAbortControllers . set ( request . id , abortController ) ;
353359
354- // Create extra object with both abort signal and sessionId from transport
355- const extra : RequestHandlerExtra < SendRequestT , SendNotificationT > = {
360+ const fullExtra : RequestHandlerExtra < SendRequestT , SendNotificationT > = {
356361 signal : abortController . signal ,
357362 sessionId : this . _transport ?. sessionId ,
358363 sendNotification :
359364 ( notification ) =>
360365 this . notification ( notification , { relatedRequestId : request . id } ) ,
361366 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 ,
363369 } ;
364370
365371 // Starting with Promise.resolve() puts any synchronous errors into the monad as well.
366372 Promise . resolve ( )
367- . then ( ( ) => handler ( request , extra ) )
373+ . then ( ( ) => handler ( request , fullExtra ) )
368374 . then (
369375 ( result ) => {
370376 if ( abortController . signal . aborted ) {
0 commit comments